]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/main.c
cnid_dbd only switch user if we are root.
[netatalk.git] / etc / cnid_dbd / main.c
index 52dc3cf4c4a3bb596a2850ac535c40a70ca1a750..c7b8cba6284326f3875dc36e2a665a57df0ae492 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * $Id: main.c,v 1.1.4.6 2003-12-12 19:27:57 didg Exp $
+ * $Id: main.c,v 1.1.4.10 2004-03-22 05:31:39 didg Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
- * All Rights Reserved.  See COPYRIGHT.
+ * All Rights Reserved.  See COPYING.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -195,15 +195,21 @@ int main(int argc, char *argv[])
     struct db_param *dbp;
     int err = 0;
     struct stat st;
-    int lockfd;
+    int lockfd, ctrlfd, clntfd;
     struct flock lock;
     char *dir;
-        
-    if (argc  != 2) {
+       
+    set_processname("cnid_dbd");
+    if (argc  != 4) {
         LOG(log_error, logtype_cnid, "main: not enough arguments");
         exit(1);
     }
+
     dir = argv[1];
+    ctrlfd = atoi(argv[2]);
+    clntfd = atoi(argv[3]);
+
     if (chdir(dir) < 0) {
         LOG(log_error, logtype_cnid, "chdir to %s failed: %s", dir, strerror(errno));
         exit(1);
@@ -212,13 +218,13 @@ int main(int argc, char *argv[])
         LOG(log_error, logtype_cnid, "error in stat for %s: %s", dir, strerror(errno));
         exit(1);
     }
-#if 0
-    LOG(log_info, logtype_cnid, "Setting uid/gid to %i/%i", st.st_uid, st.st_gid);
-    if (setegid(st.st_gid) < 0 || seteuid(st.st_uid) < 0) {
-        LOG(log_error, logtype_cnid, "uid/gid: %s", strerror(errno));
-        exit(1);
+    if (!getuid()) {
+        LOG(log_info, logtype_cnid, "Setting uid/gid to %i/%i", st.st_uid, st.st_gid);
+        if (setgid(st.st_gid) < 0 || setuid(st.st_uid) < 0) {
+            LOG(log_error, logtype_cnid, "uid/gid: %s", strerror(errno));
+            exit(1);
+        }
     }
-#endif    
     /* Before we do anything else, check if there is an instance of cnid_dbd
        running already and silently exit if yes. */
 
@@ -242,6 +248,7 @@ int main(int argc, char *argv[])
     }
     
     LOG(log_info, logtype_cnid, "Startup, DB dir %s", dir);
+    
     sv.sa_handler = sig_exit;
     sv.sa_flags = 0;
     sigemptyset(&sv.sa_mask);
@@ -290,7 +297,7 @@ int main(int argc, char *argv[])
     if (dbif_txn_commit() < 0)
        exit(6);
 #endif
-    if (comm_init(dbp) < 0) {
+    if (comm_init(dbp, ctrlfd, clntfd) < 0) {
         dbif_close();
         exit(3);
     }