]> arthur.barton.de Git - netatalk.git/commitdiff
use seteuid(0) and back in savevolinfo
authorFrank Lahm <franklahm@googlemail.com>
Mon, 4 Jul 2011 10:40:41 +0000 (12:40 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Mon, 4 Jul 2011 10:40:41 +0000 (12:40 +0200)
libatalk/util/volinfo.c

index 62afbc6559b490aa0d6c62a76380bc170aefe0c5..6ccd47c4d57cd08e79e02d7579efe91c2bca78a3 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>
@@ -475,6 +476,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;
@@ -487,11 +489,25 @@ 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_error, logtype_afpd,"Error opening %s: %s", item, strerror(errno));
         return (-1);
     }
 
+    if (process_uid) {
+        if (seteuid(process_uid) == -1) {
+            LOG(log_error, logtype_logger, "can't seteuid back %s", strerror(errno));
+            exit(EXITERR_SYS);
+        }
+    }
+
     /* try to get a lock */
     lock.l_start  = 0;
     lock.l_whence = SEEK_SET;