]> arthur.barton.de Git - netatalk.git/commitdiff
Remove dependency on libuuid, use own code
authorFrank Lahm <franklahm@googlemail.com>
Mon, 6 Dec 2010 12:05:08 +0000 (13:05 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Mon, 6 Dec 2010 12:05:08 +0000 (13:05 +0100)
configure.in
etc/afpd/catsearch.c
etc/afpd/status.c
etc/afpd/volume.c
include/atalk/util.h
libatalk/util/unix.c

index ec3a24fde37c898266d4b429edb268cee4fd25f3..98d045d7ff8215a74d02bae1168a9f1f1b710279 100644 (file)
@@ -1254,14 +1254,6 @@ fi
 dnl --------------------- Netatalk Webmin
 NETATALK_WEBMIN
 
-dnl --------------------- Check for libuuid which is required for TimeMachine
-AC_SEARCH_LIBS([uuid_generate],
-               [uuid], ,
-               AC_MSG_ERROR([missing library libuuid required for TimeMachine]))
-AC_CHECK_HEADER([uuid/uuid.h],
-                AC_DEFINE([HAVE_UUID], 1, [have libuuid]),
-                AC_MSG_ERROR([missing header <uuid/uuid.> from libuuid required for TimeMachine]))
-
 dnl --------------------- last minute substitutions
 
 AC_SUBST(LIBS)
index 819e04b8dba4523a0bf8657377e64e953fda00bc..aee1b8f1f510fbba190f33e2983d458d92f6756f 100644 (file)
@@ -754,8 +754,9 @@ static int catsearch_db(struct vol *vol,
             switch (errno) {
             case EACCES:
             case ELOOP:
-            case ENOENT:
                 goto next;
+            case ENOENT:
+                
             default:
                 result = AFPERR_MISC;
                 goto catsearch_end;
index bcdca483f38c5d5e3b6ca54fe3e4a533d7c62907..d4247829345d01a298e86baeafab64918c52d0de 100644 (file)
@@ -659,14 +659,14 @@ server_signature_auto:
                 options->sigconffile, strerror(errno));
             goto server_signature_random;
         }
-    } else {                                                          /* conf file don't exist */
+    } else { /* conf file don't exist */
         if (( fd = creat(options->sigconffile, 0644 )) < 0 ) {
-            LOG(log_error, logtype_atalkd, "ERROR: Cannot create %s (%s). Using one-time signature.",
+            LOG(log_error, logtype_atalkd, "Cannot create %s (%s). Using one-time signature.",
                 options->sigconffile, strerror(errno));
             goto server_signature_random;
         }
         if (( fp = fdopen( fd, "w" )) == NULL ) {
-            LOG(log_error, logtype_atalkd, "ERROR: Cannot fdopen %s (%s). Using one-time signature.",
+            LOG(log_error, logtype_atalkd, "Cannot fdopen %s (%s). Using one-time signature.",
                 options->sigconffile, strerror(errno));
             close(fd);
             goto server_signature_random;
@@ -678,41 +678,9 @@ server_signature_auto:
 server_signature_random:
     
     /* generate signature from random number */
-    if ((randomp = fopen("/dev/urandom", "r")) != NULL) {   /* generate from /dev/urandom */
-        for (i=0 ; i<16 ; i++) {
-            (options->signature)[i] = fgetc(randomp);
-        }
-        LOG(log_note, logtype_afpd,
-            "generate %s's signature %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X from /dev/urandom",
-            server_tmp,
-            (options->signature)[ 0], (options->signature)[ 1],
-            (options->signature)[ 2], (options->signature)[ 3],
-            (options->signature)[ 4], (options->signature)[ 5],
-            (options->signature)[ 6], (options->signature)[ 7],
-            (options->signature)[ 8], (options->signature)[ 9],
-            (options->signature)[10], (options->signature)[11],
-            (options->signature)[12], (options->signature)[13],
-            (options->signature)[14], (options->signature)[15]);
-        
-    } else {                                   /* genarate from random() because cannot open /dev/urandom */
-        srandom((unsigned int)time(NULL) + (unsigned int)options + (unsigned int)server_tmp);
-        for (i=0 ; i<16 ; i++) {
-            (options->signature)[i] = random() & 0xFF;
-        }
-        LOG(log_note, logtype_afpd,
-            "generate %s's signature %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X from random()",
-            server_tmp,
-            (options->signature)[ 0], (options->signature)[ 1],
-            (options->signature)[ 2], (options->signature)[ 3],
-            (options->signature)[ 4], (options->signature)[ 5],
-            (options->signature)[ 6], (options->signature)[ 7],
-            (options->signature)[ 8], (options->signature)[ 9],
-            (options->signature)[10], (options->signature)[11],
-            (options->signature)[12], (options->signature)[13],
-            (options->signature)[14], (options->signature)[15]);
-    }
+    randombytes(options->signature, 16);
 
-    if (fp && header) {                                     /* conf file is created or size=0 */
+    if (fp && header) { /* conf file is created or size=0 */
         fprintf(fp, "# DON'T TOUCH NOR COPY THOUGHTLESSLY!\n");
         fprintf(fp, "# This file is auto-generated by afpd.\n");
         fprintf(fp, "# \n");
index c8570a7edc086cb4e0aafef2452fa83290a04fa3..479923f246e46c70496878ed3c46c062772d9648 100644 (file)
@@ -36,8 +36,6 @@ char *strchr (), *strrchr ();
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
-#include <uuid/uuid.h>
-
 #include <atalk/asp.h>
 #include <atalk/dsi.h>
 #include <atalk/adouble.h>
@@ -46,7 +44,8 @@ char *strchr (), *strrchr ();
 #include <atalk/volinfo.h>
 #include <atalk/logger.h>
 #include <atalk/vfs.h>
-#include <atalk/ea.h>
+#include <atalk/uuid.h>
+
 #ifdef CNID_DB
 #include <atalk/cnid.h>
 #endif /* CNID_DB*/
@@ -2736,14 +2735,14 @@ char *get_uuid(const AFPObj *obj, const char *volname)
     }                    
     
     /* generate uuid and write to file */
-    uuid_t id;
-    uuid_generate(id);
-    uuid_unparse(id, uuid);
-    for (int i=0; uuid[i]; i++)
-        uuid[i] = toupper(uuid[i]);
-    LOG(log_debug, logtype_afpd, "get_uuid('%s'): generated UUID '%s'", volname, uuid);
-
-    fprintf(fp, "\"%s\"\t%36s\n", volname, uuid);
+    atalk_uuid_t id;
+    const char *cp;
+    randombytes((void *)id, 16);
+    cp = uuid_bin2string(id);
+
+    LOG(log_debug, logtype_afpd, "get_uuid('%s'): generated UUID '%s'", volname, cp);
+
+    fprintf(fp, "\"%s\"\t%36s\n", volname, cp);
     fclose(fp);
     
     return strdup(uuid);
index d6209ed93c86cf624ba3292c4cd98096cb3b8aab..63da2935df0733c74fceb9f31aee241b7c3f4cef 100644 (file)
@@ -140,5 +140,5 @@ extern int compare_ip(const struct sockaddr *sa1, const struct sockaddr *sa2);
 extern const char *getcwdpath(void);
 extern char *stripped_slashes_basename(char *p);
 extern int lchdir(const char *dir);
-
+extern void randombytes(void *buf, int n);
 #endif  /* _ATALK_UTIL_H */
index 1c131ad507c9712a4de3a18f8648795b89c950ef..9e71fcb4b71a3b7fd53479c4cebc2cef7cb3bb30 100644 (file)
@@ -30,6 +30,8 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <dirent.h>
+#include <sys/time.h>
+#include <time.h>
 
 #include <atalk/adouble.h>
 #include <atalk/ea.h>
@@ -148,3 +150,33 @@ int lchdir(const char *dir)
 
     return 0;
 }
+
+/*!
+ * Store n random bytes an buf
+ */
+void randombytes(void *buf, int n)
+{
+    char *p = (char *)buf;
+    int fd, i;
+    struct timeval tv;
+
+    if ((fd = open("/dev/urandom", O_RDONLY)) != -1) {
+        /* generate from /dev/urandom */
+        if (read(fd, buf, n) != n) {
+            close(fd);
+            fd = -1;
+        } else {
+            close(fd);
+            /* fd now != -1, so srandom wont be called below */
+        }
+    }
+
+    if (fd == -1) {
+        gettimeofday(&tv, NULL);
+        srandom((unsigned int)tv.tv_usec);
+        for (i=0 ; i < n ; i++)
+            p[i] = random() & 0xFF;
+    }
+
+    return;
+}