All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] uuidgen: fail if uuidd isn't running
@ 2011-06-16 13:59 Ludwig Nussel
  2011-06-16 13:59 ` [PATCH 2/4] uuid: implement uuid_generate_random_safe Ludwig Nussel
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Ludwig Nussel @ 2011-06-16 13:59 UTC (permalink / raw)
  To: util-linux; +Cc: Ludwig Nussel

time bases uuids are not safe if uuidd is not running.
Add option --force to generate a uuid in this case nevertheless.
---
 misc-utils/uuidgen.c |   51 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c
index 3cf6ec9..b83b124 100644
--- a/misc-utils/uuidgen.c
+++ b/misc-utils/uuidgen.c
@@ -10,34 +10,43 @@
  */
 
 #include <stdio.h>
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
-#ifdef HAVE_GETOPT_H
 #include <getopt.h>
-#else
-extern int getopt(int argc, char * const argv[], const char *optstring);
-extern char *optarg;
-extern int optind;
-#endif
 
 #include "uuid.h"
 #include "nls.h"
+#include "c.h"
 
 #define DO_TYPE_TIME	1
 #define DO_TYPE_RANDOM	2
 
-static void usage(const char *progname)
+static const struct option long_options[] = {
+	{ "time",      0, NULL, 't' },
+	{ "random",    0, NULL, 'r' },
+	{ "force",     0, NULL, 128 },
+	{ "help",      0, NULL, 'h' },
+	{ 0, 0, 0, 0 }
+};
+
+static void usage(int ex)
 {
-	fprintf(stderr, _("Usage: %s [-r] [-t]\n"), progname);
-	exit(1);
+	printf(_("Usage: %s [options]\n"
+		"  -r, --random     Generate a random-based UUID\n"
+		"  -t, --time       Generate a time-based UUID\n"
+		"      --force      print uuid even if it's potentially weak\n"
+		"  -h, --help       Display this text\n"),
+		program_invocation_short_name);
+	exit(ex);
 }
 
+
+
 int
 main (int argc, char *argv[])
 {
 	int    c;
 	int    do_type = 0;
+	int    force = 0;
 	char   str[37];
 	uuid_t uu;
 
@@ -45,21 +54,31 @@ main (int argc, char *argv[])
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
-	while ((c = getopt (argc, argv, "tr")) != EOF)
+	while ((c = getopt_long(argc, argv, "rth", long_options, NULL)) != EOF ) {
 		switch (c) {
-		case 't':
-			do_type = DO_TYPE_TIME;
+		case 'h':
+			usage(0);
 			break;
 		case 'r':
 			do_type = DO_TYPE_RANDOM;
 			break;
+		case 't':
+			do_type = DO_TYPE_TIME;
+			break;
+		case 128:
+			force = 1;
+			break;
 		default:
-			usage(argv[0]);
+			usage(1);
 		}
+	}
 
 	switch (do_type) {
 	case DO_TYPE_TIME:
-		uuid_generate_time(uu);
+		if (uuid_generate_time_safe(uu) && !force) {
+			fprintf(stderr, _("uuidd not running or not operational.\n"));
+			exit(1);
+		}
 		break;
 	case DO_TYPE_RANDOM:
 		uuid_generate_random(uu);
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-06-20 12:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-16 13:59 [PATCH 1/4] uuidgen: fail if uuidd isn't running Ludwig Nussel
2011-06-16 13:59 ` [PATCH 2/4] uuid: implement uuid_generate_random_safe Ludwig Nussel
2011-06-16 15:54   ` Karel Zak
2011-06-17  2:15   ` Ted Ts'o
2011-06-17  7:37     ` Ludwig Nussel
2011-06-20 11:45       ` Theodore Tso
2011-06-16 13:59 ` [PATCH 3/4] uuid: use new functions by default Ludwig Nussel
2011-06-20 10:35   ` Karel Zak
2011-06-16 13:59 ` [PATCH 4/4] update manpage Ludwig Nussel
2011-06-16 15:38 ` [PATCH 1/4] uuidgen: fail if uuidd isn't running Karel Zak
2011-06-17  2:07 ` Ted Ts'o
2011-06-20 10:45   ` Karel Zak
2011-06-20 12:18     ` Ludwig Nussel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.