Steven Dake wrote:
The reread until entropy is available patch was already merged into
trunk. Your add_options patch is welcome to be merged, but doesn't
apply cleanly on top of trunk.
Could you rebase it from trunk? To get trunk:
svn co http://svn.fedorahosted.org/svn/corosync/trunk
Regards
-steve
Fixed patch attached.
Tell me if you want any additional change.
Piter Punk
--- trunk/tools/corosync-keygen.c 2009-08-24 02:38:32.000000000 -0300
+++ new/tools/corosync-keygen.c 2009-08-24 02:28:44.000000000 -0300
@@ -46,13 +46,65 @@
#define KEYFILE COROSYSCONFDIR "/authkey"
-int main (void) {
+static void usage_do (void)
+{
+ printf ("\ncorosync-keygen [-r|-u] [-f]\n\n");
+ printf ("Corosync Cluster Engine Authentication key generator.\n");
+ printf ("\nOptions:\n");
+ printf ("\t-u\tUse /dev/urandom as entropy source (default).\n");
+ printf ("\t-r\tUse /dev/random as entropy source.\n");
+ printf ("\t-f\tForce " KEYFILE " overwrite.\n\n");
+}
+
+int main (int argc, char *argv[]) {
+ const char *options = "urfh";
+ char *entropysource = "/dev/urandom";
+ unsigned char key[128];
int authkey_fd;
int random_fd;
- unsigned char key[128];
+ int opt;
+ int force = 0;
+ int esrc = 0;
+ int urnd = 1;
ssize_t res;
ssize_t bytes_read;
+ if (argc > 1) {
+ while ( (opt = getopt(argc, argv, options)) != -1 ) {
+ switch (opt) {
+ case 'f':
+ force = 1;
+ break;
+ case 'u':
+ if (!esrc) {
+ entropysource = "/dev/urandom";
+ urnd = 1;
+ esrc = 1;
+ } else {
+ usage_do();
+ printf("ERROR: -u conflicts
with -r.\n");
+ exit (1);
+ }
+ break;
+ case 'r':
+ if (!esrc) {
+ entropysource = "/dev/random";
+ urnd = 0;
+ esrc = 1;
+ } else {
+ usage_do();
+ printf("ERROR: -r conflicts
with -u.\n");
+ exit (1);
+ }
+ break;
+ default:
+ usage_do();
+ exit (1);
+ break;
+ }
+ }
+ }
+
printf ("Corosync Cluster Engine Authentication key generator.\n");
if (geteuid() != 0) {
printf ("Error: Authorization key must be generated as root
user.\n");
@@ -64,12 +116,20 @@
exit (errno);
}
}
+ if ((fopen (KEYFILE, "r")) && (force == 0)) {
+ printf ("Key file " KEYFILE " already exists.\n");
+ printf ("If you want a new key, remove "KEYFILE" or use -f
option.\n");
+ exit (1);
+ }
- printf ("Gathering %lu bits for key from /dev/random.\n", (unsigned
long)(sizeof (key) * 8));
- printf ("Press keys on your keyboard to generate entropy.\n");
- random_fd = open ("/dev/random", O_RDONLY);
+ printf ("Gathering %lu bits for key from %s.\n", (unsigned long)(sizeof
(key) * 8),entropysource);
+ random_fd = open (entropysource, O_RDONLY);
if (random_fd == -1) {
- perror ("Is /dev/random present? Opening /dev/random");
+ if (urnd) {
+ perror ("Is /dev/urandom present? Opening
/dev/urandom");
+ } else {
+ perror ("Is /dev/random present? Opening /dev/random");
+ }
exit (errno);
}
@@ -81,7 +141,11 @@
retry_read:
res = read (random_fd, &key[bytes_read], sizeof (key) - bytes_read);
if (res == -1) {
- perror ("Could not read /dev/random");
+ if (urnd) {
+ perror ("Could not read /dev/urandom");
+ } else {
+ perror ("Could not read /dev/random");
+ }
exit (errno);
}
bytes_read += res;
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais