]> arthur.barton.de Git - netatalk.git/commitdiff
Test for EAs and ad_convert as root
authorFrank Lahm <franklahm@googlemail.com>
Wed, 7 Mar 2012 10:52:57 +0000 (11:52 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 7 Mar 2012 10:52:57 +0000 (11:52 +0100)
libatalk/adouble/ad_open.c
libatalk/util/netatalk_conf.c
libatalk/util/unix.c

index d4e84fd21ce21c0b3cfc9bc2b5bbb6f1c3ab64dd..ff2a980238b98cc53dbe2de0bec532cb86fb8434 100644 (file)
@@ -1955,9 +1955,9 @@ int ad_convert(const char *path, const struct stat *sp, const struct vol *vol)
     LOG(log_debug, logtype_default,"ad_conv_v22ea_hf(\"%s\"): deleting adouble:v2 file: \"%s\"",
         path, fullpathname(adpath));
 
-//    become_root();
+    become_root();
     EC_ZERO_LOG( unlink(adpath) );
-//    unbecome_root();
+    unbecome_root();
 
 EC_CLEANUP:
     LOG(log_debug, logtype_default,"ad_convert(\"%s\"): END: %d", fullpathname(path), ret);
index 314750e26cb27d301e22b8683e1a2a864e92a8a4..7d6031cb87f39753790d3c61d19bdb128866dbce 100644 (file)
@@ -176,7 +176,7 @@ static int do_check_ea_support(const struct vol *vol)
 
     mktemp(eaname);
 
-//    become_root();
+    become_root();
 
     if ((sys_setxattr(vol->v_path, eaname, eacontent, 4, 0)) == 0) {
         sys_removexattr(vol->v_path, eaname);
@@ -187,7 +187,7 @@ static int do_check_ea_support(const struct vol *vol)
         haseas = 0;
     }
 
-//    unbecome_root();
+    unbecome_root();
 
     return haseas;
 }
index 5b0da03c5087e6f710b1d11a5a0717431efeb5b6..7d66fb615360dbc39efdc29a9e9733300e4ab2d9 100644 (file)
@@ -97,18 +97,25 @@ int daemonize(int nochdir, int noclose)
 
 static uid_t saved_uid = -1;
 
+/*
+ * seteuid(0) and back, if either fails and panic != 0 we PANIC
+ */
 void become_root(void)
 {
-    saved_uid = geteuid();
-    if (seteuid(0) != 0)
-        AFP_PANIC("Can't seteuid(0)");
+    if (getuid() == 0) {
+        saved_uid = geteuid();
+        if (seteuid(0) != 0)
+            AFP_PANIC("Can't seteuid(0)");
+    }
 }
 
 void unbecome_root(void)
 {
-    if (saved_uid == -1 || seteuid(saved_uid) < 0)
-        AFP_PANIC("Can't seteuid back");
-    saved_uid = -1;
+    if (getuid() == 0) {
+        if (saved_uid == -1 || seteuid(saved_uid) < 0)
+            AFP_PANIC("Can't seteuid back");
+        saved_uid = -1;
+    }
 }
 
 /*!