From: Frank Lahm Date: Mon, 6 Dec 2010 12:05:08 +0000 (+0100) Subject: Remove dependency on libuuid, use own code X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;h=088f8c044eae0a2e77576ae09bc9cf93e3deb08b;p=netatalk.git Remove dependency on libuuid, use own code --- diff --git a/configure.in b/configure.in index ec3a24fd..98d045d7 100644 --- a/configure.in +++ b/configure.in @@ -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 from libuuid required for TimeMachine])) - dnl --------------------- last minute substitutions AC_SUBST(LIBS) diff --git a/etc/afpd/catsearch.c b/etc/afpd/catsearch.c index 819e04b8..aee1b8f1 100644 --- a/etc/afpd/catsearch.c +++ b/etc/afpd/catsearch.c @@ -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; diff --git a/etc/afpd/status.c b/etc/afpd/status.c index bcdca483..d4247829 100644 --- a/etc/afpd/status.c +++ b/etc/afpd/status.c @@ -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"); diff --git a/etc/afpd/volume.c b/etc/afpd/volume.c index c8570a7e..479923f2 100644 --- a/etc/afpd/volume.c +++ b/etc/afpd/volume.c @@ -36,8 +36,6 @@ char *strchr (), *strrchr (); #include #include -#include - #include #include #include @@ -46,7 +44,8 @@ char *strchr (), *strrchr (); #include #include #include -#include +#include + #ifdef CNID_DB #include #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); diff --git a/include/atalk/util.h b/include/atalk/util.h index d6209ed9..63da2935 100644 --- a/include/atalk/util.h +++ b/include/atalk/util.h @@ -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 */ diff --git a/libatalk/util/unix.c b/libatalk/util/unix.c index 1c131ad5..9e71fcb4 100644 --- a/libatalk/util/unix.c +++ b/libatalk/util/unix.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include @@ -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; +}