chiark / gitweb /
Cheer up linux compiler
[disorder] / lib / user.c
index ec01a339bc6a7259294b07d9b98d8d51ce426672..100da166ab62c93ff1641623d19bb208ea6b782f 100644 (file)
@@ -2,27 +2,24 @@
  * This file is part of DisOrder
  * Copyright (C) 2005, 2007 Richard Kettlewell
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 /** @file lib/user.c
  * @brief Jukebox user management
  */
 
-#include <config.h>
-#include "types.h"
+#include "common.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -45,21 +42,30 @@ void become_mortal(void) {
   
   if(config->user) {
     if(!(pw = getpwnam(config->user)))
-      fatal(0, "cannot find user %s", config->user);
+      disorder_fatal(0, "cannot find user %s", config->user);
     if(pw->pw_uid != getuid()) {
       if(initgroups(config->user, pw->pw_gid))
-       fatal(errno, "error calling initgroups");
-      if(setgid(pw->pw_gid) < 0) fatal(errno, "error calling setgid");
-      if(setuid(pw->pw_uid) < 0) fatal(errno, "error calling setgid");
-      info("changed to user %s (uid %lu)", config->user, (unsigned long)getuid());
+       disorder_fatal(errno, "error calling initgroups");
+      if(setgid(pw->pw_gid) < 0)
+        disorder_fatal(errno, "error calling setgid");
+      if(setuid(pw->pw_uid) < 0)
+        disorder_fatal(errno, "error calling setgid");
+      disorder_info("changed to user %s (uid %lu)",
+                    config->user, (unsigned long)getuid());
     }
     /* sanity checks */
-    if(getuid() != pw->pw_uid) fatal(0, "wrong real uid");
-    if(geteuid() != pw->pw_uid) fatal(0, "wrong effective uid");
-    if(getgid() != pw->pw_gid) fatal(0, "wrong real gid");
-    if(getegid() != pw->pw_gid) fatal(0, "wrong effective gid");
-    if(setuid(0) != -1) fatal(0, "setuid(0) unexpectedly succeeded");
-    if(seteuid(0) != -1) fatal(0, "seteuid(0) unexpectedly succeeded");
+    if(getuid() != pw->pw_uid)
+      disorder_fatal(0, "wrong real uid");
+    if(geteuid() != pw->pw_uid)
+      disorder_fatal(0, "wrong effective uid");
+    if(getgid() != pw->pw_gid)
+      disorder_fatal(0, "wrong real gid");
+    if(getegid() != pw->pw_gid)
+      disorder_fatal(0, "wrong effective gid");
+    if(setuid(0) != -1)
+      disorder_fatal(0, "setuid(0) unexpectedly succeeded");
+    if(seteuid(0) != -1)
+      disorder_fatal(0, "seteuid(0) unexpectedly succeeded");
   }
 }
 
@@ -87,13 +93,13 @@ void make_home(void) {
     }
     /* create the directory itself */
     if(mkdir(config->home, 02755) < 0)
-      fatal(errno, "error creating %s", config->home);
+      disorder_fatal(errno, "error creating %s", config->home);
     /* make sure it has the right ownership */
     if(config->user) {
       if(!(pw = getpwnam(config->user)))
-        fatal(0, "cannot find user %s", config->user);
+        disorder_fatal(0, "cannot find user %s", config->user);
       if(chown(config->home, pw->pw_uid, pw->pw_gid) < 0)
-        fatal(errno, "error chowning %s", config->home);
+        disorder_fatal(errno, "error chowning %s", config->home);
     }
   }
 }