]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/volume.c
Merge from branch-2-1
[netatalk.git] / etc / afpd / volume.c
index fa627599a3bccfae98f929b325a37e5a1c7a928f..bf90e9a6008997bde965d3dd053c6a8c945ffe71 100644 (file)
@@ -861,9 +861,8 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
     if (volume->v_flags & AFPVOL_TM) {
         char *uuid = get_uuid(obj, volume->v_localname);
         if (!uuid) {
-            LOG(log_error, logtype_afpd, "Volume '%s': couldn't get UUID, disabling TM support",
+            LOG(log_error, logtype_afpd, "Volume '%s': couldn't get UUID",
                 volume->v_localname);
-            volume->v_flags &= ~AFPVOL_TM;
         } else {
             volume->v_uuid = uuid;
             LOG(log_debug, logtype_afpd, "Volume '%s': UUID '%s'",
@@ -2648,16 +2647,11 @@ void unload_volumes_and_extmap(void)
  */
 char *get_uuid(const AFPObj *obj, const char *volname)
 {
-    struct stat st;
-
-    char *usersign;
-    int fd, i;
-    struct stat tmpstat;
     char *volname_conf;
-    int header = 0;
     char buf[1024], uuid[UUID_PRINTABLE_STRING_LENGTH], *p;
-    FILE *fp, *randomp;
-    size_t len;
+    FILE *fp;
+    struct stat tmpstat;
+    int fd;
     
     if ((fp = fopen(obj->options.uuidconf, "r")) != NULL) {  /* read open? */
         /* scan in the conf file */
@@ -2687,6 +2681,8 @@ char *get_uuid(const AFPObj *obj, const char *volname)
                 p++;
 
             if (sscanf(p, "%36s", uuid) == 1 ) {
+                for (int i=0; uuid[i]; i++)
+                    uuid[i] = toupper(uuid[i]);
                 LOG(log_debug, logtype_afpd, "get_uuid('%s'): UUID: '%s'", volname, uuid);
                 fclose(fp);
                 return strdup(uuid);
@@ -2698,7 +2694,20 @@ char *get_uuid(const AFPObj *obj, const char *volname)
         fclose(fp);
 
     /*  not found or no file, reopen in append mode */
-    if ((fp = fopen(obj->options.uuidconf, "a+")) == NULL) {
+
+    if (stat(obj->options.uuidconf, &tmpstat)) {                /* no file */
+        if (( fd = creat(obj->options.uuidconf, 0644 )) < 0 ) {
+            LOG(log_error, logtype_atalkd, "ERROR: Cannot create %s (%s).",
+                obj->options.uuidconf, strerror(errno));
+            return NULL;
+        }
+        if (( fp = fdopen( fd, "w" )) == NULL ) {
+            LOG(log_error, logtype_atalkd, "ERROR: Cannot fdopen %s (%s).",
+                obj->options.uuidconf, strerror(errno));
+            close(fd);
+            return NULL;
+        }
+    } else if ((fp = fopen(obj->options.uuidconf, "a+")) == NULL) { /* not found */
         LOG(log_error, logtype_afpd, "Cannot create or append to %s (%s).",
             obj->options.uuidconf, strerror(errno));
         return NULL;
@@ -2717,6 +2726,8 @@ char *get_uuid(const AFPObj *obj, const char *volname)
     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);