]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/ngircd.c
Always cloak client hostname, if needed
[ngircd-alex.git] / src / ngircd / ngircd.c
index ec2462aeb1d38abd7dc98ad1555c223c794bfb79..8a93bcb00839a796b262b890d12b373d662ccf56 100644 (file)
@@ -255,11 +255,11 @@ main(int argc, const char *argv[])
                NGIRCd_SignalRestart = false;
                NGIRCd_SignalQuit = false;
 
-               Random_Init();
-
                /* Initialize modules, part I */
                Log_Init(!NGIRCd_NoDaemon);
+               Random_Init();
                Conf_Init();
+               Log_ReInit();
 
                /* Initialize the "main program": chroot environment, user and
                 * group ID, ... */
@@ -498,7 +498,8 @@ Pidfile_Create(pid_t pid)
 
        len = snprintf(pidbuf, sizeof pidbuf, "%ld\n", (long)pid);
        if (len < 0 || len >= (int)sizeof pidbuf) {
-               Log( LOG_ERR, "Error converting pid");
+               Log(LOG_ERR, "Error converting pid");
+               close(pidfd);
                return;
        }
        
@@ -642,12 +643,10 @@ NGIRCd_Init(bool NGIRCd_NoDaemon)
                }
 
                if (chroot(Conf_Chroot) != 0) {
-                       if (errno != EPERM) {
-                               Log(LOG_ERR,
-                                   "Can't change root directory to \"%s\": %s",
-                                   Conf_Chroot, strerror(errno));
-                               goto out;
-                       }
+                       Log(LOG_ERR,
+                           "Can't change root directory to \"%s\": %s",
+                           Conf_Chroot, strerror(errno));
+                       goto out;
                } else {
                        chrooted = true;
                        Log(LOG_INFO,
@@ -658,10 +657,10 @@ NGIRCd_Init(bool NGIRCd_NoDaemon)
 
        /* Check user ID */
        if (Conf_UID == 0) {
+               pwd = getpwuid(0);
                Log(LOG_INFO,
-                   "ServerUID must not be 0, using \"nobody\" instead.",
-                   Conf_UID);
-
+                   "ServerUID must not be %s(0), using \"nobody\" instead.",
+                   pwd ? pwd->pw_name : "?");
                if (!NGIRCd_getNobodyID(&Conf_UID, &Conf_GID)) {
                        Log(LOG_WARNING,
                            "Could not get user/group ID of user \"nobody\": %s",
@@ -674,8 +673,10 @@ NGIRCd_Init(bool NGIRCd_NoDaemon)
        if (getgid() != Conf_GID) {
                if (setgid(Conf_GID) != 0) {
                        real_errno = errno;
-                       Log(LOG_ERR, "Can't change group ID to %u: %s",
-                           Conf_GID, strerror(errno));
+                       grp = getgrgid(Conf_GID);
+                       Log(LOG_ERR, "Can't change group ID to %s(%u): %s",
+                           grp ? grp->gr_name : "?", Conf_GID,
+                           strerror(errno));
                        if (real_errno != EPERM) 
                                goto out;
                }
@@ -685,8 +686,10 @@ NGIRCd_Init(bool NGIRCd_NoDaemon)
        if (getuid() != Conf_UID) {
                if (setuid(Conf_UID) != 0) {
                        real_errno = errno;
-                       Log(LOG_ERR, "Can't change user ID to %u: %s",
-                           Conf_UID, strerror(errno));
+                       pwd = getpwuid(Conf_UID);
+                       Log(LOG_ERR, "Can't change user ID to %s(%u): %s",
+                           pwd ? pwd->pw_name : "?", Conf_UID,
+                           strerror(errno));
                        if (real_errno != EPERM)
                                goto out;
                }