summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-28 17:51:30 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-28 17:51:30 -0700
commitfc11a0cd29e974ae458982f6550108d79a40433e (patch)
treed8cdfc560845dd5ca87d58c62080522b4763fe2d
parentfbc4f5a54be00ef1de26c0d2551c85295663ddfd (diff)
downloadranpwd.git.old-fc11a0cd29e974ae458982f6550108d79a40433e.tar.gz
ranpwd.git.old-fc11a0cd29e974ae458982f6550108d79a40433e.tar.xz
ranpwd.git.old-fc11a0cd29e974ae458982f6550108d79a40433e.zip
UUID: handle length saner
For the UUID mode, simply make length a count.
-rw-r--r--ranpwd.116
-rw-r--r--ranpwd.c49
2 files changed, 36 insertions, 29 deletions
diff --git a/ranpwd.1 b/ranpwd.1
index 5d681d3..a68e071 100644
--- a/ranpwd.1
+++ b/ranpwd.1
@@ -65,21 +65,27 @@ Generate a bit string (for Bynar sabotage teams.)
.I "\-i", "\-\-ip"
Generate a random IP suffix (normally used with a
.I 169.254.
-prefix). The first octet cannot be 0 or 255. The default is two octets.
+prefix). The first octet cannot be 0 or 255. Length is given in
+octets; the default is two octets.
.TP
.I "\-m", "\-\-mac-address"
Generate a random MAC address. The first octet must have the
-multicast bit clear, and the local bit set. The default is six
-octets.
+multicast bit clear, and the local bit set. Length is given in
+octets; the default is six octets.
.TP
.I "\-M", "\-\-mac-address \-\-upper"
-Generate an upper case MAC address.
+Generate an upper case random MAC address. The first octet must have the
+multicast bit clear, and the local bit set. Length is given in
+octets; the default is six octets.
.TP
.I "\-g", "\-\-uuid", "\-\-guid"
-Generate a random Universally Unique Identifier (UUID).
+Generate a random Universally Unique Identifier (UUID). Length is
+given in the number of UUIDs to output; the default is one UUID.
.TP
.I "\-g", "\-\-uuid \-\-upper", "\-\-guid \-\-upper"
Generate an upper case random Universally Unique Identifier (UUID).
+Length is given in the number of UUIDs to output; the default is one
+UUID.
.TP
.I "\-s", "\-\-secure"
On systems which have
diff --git a/ranpwd.c b/ranpwd.c
index 7834b6f..f402cd2 100644
--- a/ranpwd.c
+++ b/ranpwd.c
@@ -188,6 +188,7 @@ static void output_random(enum output_type type, int nchar, int decor)
{
int i;
unsigned char ch;
+ unsigned char buf[16];
int ichar = nchar;
while (nchar) {
@@ -322,29 +323,29 @@ static void output_random(enum output_type type, int nchar, int decor)
case ty_uuid:
case ty_uuuid:
- getrandom(&ch, 1);
- switch ((ichar-nchar) & 15) {
- case 0:
- if (ichar != nchar)
- putchar(' ');
- break;
- case 4:
- case 10:
- putchar('-');
- break;
- case 6:
- ch = (ch & 0x0f) | 0x40; /* Version number */
- putchar('-');
- break;
- case 8:
- ch = (ch & 0x3f) | 0x80; /* By spec */
- putchar('-');
- break;
- default:
- break;
+ getrandom(buf, 16);
+ for (i = 0; i < 16; i++) {
+ ch = buf[i];
+ switch (i) {
+ case 4:
+ case 10:
+ putchar('-');
+ break;
+ case 6:
+ ch = (ch & 0x0f) | 0x40; /* Version number */
+ putchar('-');
+ break;
+ case 8:
+ ch = (ch & 0x3f) | 0x80; /* By spec */
+ putchar('-');
+ break;
+ default:
+ break;
+ }
+ printf(type == ty_uuuid ? "%02X" : "%02x", ch);
}
- printf(type == ty_uuuid ? "%02X" : "%02x", ch);
- nchar--;
+ if (--nchar)
+ putchar(' ');
break;
}
}
@@ -415,11 +416,11 @@ int main(int argc, char *argv[])
break;
case 'g': /* UUID/GUID */
type = ty_uuid;
- nchar = 16;
+ nchar = 1;
break;
case 'G': /* UUID/GUID */
type = ty_uuuid;
- nchar = 16;
+ nchar = 1;
break;
case 's': /* Use /dev/random, not /dev/urandom */
secure_source = 1;