]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/util/volinfo.c
Merge master
[netatalk.git] / libatalk / util / volinfo.c
index 103a420b90b6756c3db35cf4804c293805eb61c4..52360b1ece0330089386c5383f9cc619c74403e3 100644 (file)
@@ -21,7 +21,8 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-
+#include <unistd.h>
+#include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
@@ -463,6 +464,7 @@ int closevolinfo(struct volinfo *volinfo)
  */
 int savevolinfo(const struct vol *vol, const char *Cnid_srv, const char *Cnid_port)
 {
+    uid_t process_uid;
     char buf[16348];
     char item[MAXPATHLEN];
     int fd;
@@ -475,11 +477,31 @@ int savevolinfo(const struct vol *vol, const char *Cnid_srv, const char *Cnid_po
     strlcat (item, "/.AppleDesktop/", sizeof(item));
     strlcat (item, VOLINFOFILE, sizeof(item));
 
-    if ((fd = open( item, O_RDWR | O_CREAT , 0666)) <0 ) {
-        LOG(log_debug, logtype_afpd,"Error opening %s: %s", item, strerror(errno));
+    process_uid = geteuid();
+    if (process_uid) {
+        if (seteuid(0) == -1) {
+            process_uid = 0;
+        }
+    }
+
+    if ((fd = open(item, O_RDWR | O_CREAT , 0666)) <0 ) {
+        LOG(log_debug, logtype_default,"Error opening %s: %s", item, strerror(errno));
+        if (process_uid) {
+            if (seteuid(process_uid) == -1) {
+                LOG(log_error, logtype_default, "can't seteuid back %s", strerror(errno));
+                exit(EXITERR_SYS);
+            }
+        }
         return (-1);
     }
 
+    if (process_uid) {
+        if (seteuid(process_uid) == -1) {
+            LOG(log_error, logtype_default, "can't seteuid back %s", strerror(errno));
+            exit(EXITERR_SYS);
+        }
+    }
+
     /* try to get a lock */
     lock.l_start  = 0;
     lock.l_whence = SEEK_SET;
@@ -491,7 +513,7 @@ int savevolinfo(const struct vol *vol, const char *Cnid_srv, const char *Cnid_po
             /* ignore, other process already writing the file */
             return 0;
         } else {
-            LOG(log_error, logtype_cnid, "savevoloptions: cannot get lock: %s", strerror(errno));
+            LOG(log_error, logtype_default, "savevoloptions: cannot get lock: %s", strerror(errno));
             return (-1);
         }
     }
@@ -571,9 +593,9 @@ int savevolinfo(const struct vol *vol, const char *Cnid_srv, const char *Cnid_po
     strlcat(buf, item, sizeof(buf));
 
     if (strlen(buf) >= sizeof(buf)-1)
-        LOG(log_debug, logtype_afpd,"Error writing .volinfo file: buffer too small, %s", buf);
+        LOG(log_debug, logtype_default, "Error writing .volinfo file: buffer too small, %s", buf);
    if (write( fd, buf, strlen(buf)) < 0 || ftruncate(fd, strlen(buf)) < 0 ) {
-       LOG(log_debug, logtype_afpd,"Error writing .volinfo file: %s", strerror(errno));
+       LOG(log_debug, logtype_default, "Error writing .volinfo file: %s", strerror(errno));
    }
 
    lock.l_type = F_UNLCK;