]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/util/logger.c
Replace relevant direct seteuid() calls with calls to (un)become_root()
[netatalk.git] / libatalk / util / logger.c
index a7cdd2c12a402ecd8bd8d89a199ff4dd92b4cce2..c8a2a0a8acd2845c43bfbd088e81b7a496855a1b 100644 (file)
@@ -1,3 +1,4 @@
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -31,8 +32,7 @@ Netatalk 2001 (c)
 
 #include <atalk/util.h>
 #include <atalk/logger.h>
-
-#define OPEN_LOGS_AS_UID 0
+#include <atalk/unix.h>
 
 #define COUNT_ARRAY(array) (sizeof((array))/sizeof((array)[0]))
 
@@ -256,8 +256,6 @@ static void log_init(void)
 
 static void log_setup(const char *filename, enum loglevels loglevel, enum logtypes logtype)
 {
-    uid_t process_uid;
-
     if (loglevel == 0) {
         /* Disable */
         if (type_configs[logtype].set) {
@@ -321,21 +319,11 @@ static void log_setup(const char *filename, enum loglevels loglevel, enum logtyp
         free(tmp);
 
     } else {
-        process_uid = geteuid();
-        if (process_uid) {
-            if (seteuid(OPEN_LOGS_AS_UID) == -1) {
-                process_uid = 0;
-            }
-        }
+        become_root();
         type_configs[logtype].fd = open(filename,
                                         O_CREAT | O_WRONLY | O_APPEND,
                                         S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-        if (process_uid) {
-            if (seteuid(process_uid) == -1) {
-                LOG(log_error, logtype_logger, "can't seteuid back %s", strerror(errno));
-                exit(EXITERR_SYS);
-            }
-        }
+        become_root();
     }
 
     /* Check for error opening/creating logfile */