]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/volume.c
Merge branch-2-1
[netatalk.git] / etc / afpd / volume.c
index cfa2ea0a67ed93fe95d652dcb484d93de3971631..bf90e9a6008997bde965d3dd053c6a8c945ffe71 100644 (file)
@@ -77,6 +77,10 @@ extern int afprun(int root, char *cmd, int *outfd);
 #endif /* BYTE_ORDER == BIG_ENDIAN */
 #endif /* ! NO_LARGE_VOL_SUPPORT */
 
+#ifndef UUID_PRINTABLE_STRING_LENGTH
+#define UUID_PRINTABLE_STRING_LENGTH 37
+#endif
+
 static struct vol *Volumes = NULL;
 static u_int16_t    lastvid = 0;
 static char     *Trash = "\02\024Network Trash Folder";
@@ -857,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'",
@@ -2644,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 */
@@ -2683,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);
@@ -2694,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;
@@ -2702,12 +2715,8 @@ char *get_uuid(const AFPObj *obj, const char *volname)
     fseek(fp, 0L, SEEK_END);
     if(ftell(fp) == 0) {                     /* size = 0 */
         fprintf(fp, "# DON'T TOUCH NOR COPY THOUGHTLESSLY!\n");
-        fprintf(fp, "# This file is auto-generated by afpd.\n");
-        fprintf(fp, "# \n");
-        fprintf(fp, "# This file stores UUIDs for all volumes, either auto-generated ones\n");
-        fprintf(fp, "# or the value from AppleVolumes.default:uuid\n");
-        fprintf(fp, "# \n");
-        fprintf(fp, "# If both values differ, the one from AppleVolumes.default is used.\n\n");
+        fprintf(fp, "# This file is auto-generated by afpd\n");
+        fprintf(fp, "# and stores UUIDs for TM volumes.\n\n");
     } else {
         fseek(fp, -1L, SEEK_END);
         if(fgetc(fp) != '\n') fputc('\n', fp); /* last char is \n? */
@@ -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);