See ChangeLog for 1999-03-0[45] for details.
authorNathan Bryant <loanshark@uncensored.citadel.org>
Fri, 5 Mar 1999 16:48:25 +0000 (16:48 +0000)
committerNathan Bryant <loanshark@uncensored.citadel.org>
Fri, 5 Mar 1999 16:48:25 +0000 (16:48 +0000)
citadel/ChangeLog
citadel/config.c
citadel/setup.c
citadel/sysdep.c

index 07ae7746f67eac000286cd03743b1678029a8ff9..99b2434929b141bc10440a847737a9675977b056 100644 (file)
@@ -1,3 +1,13 @@
+1999-03-05 Nathan Bryant <bryant@cs.usm.maine.edu>
+       * sysdep.c: add undocumented -r flag to citserver to prevent it from
+         dropping root permissions.
+
+1999-03-04 Nathan Bryant <bryant@cs.usm.maine.edu>
+       * config.c: error checking in put_config()
+       * setup.c: chgrp files to the login group associated with BBSUID
+       * sysdep.c: copyright 1987-1999; drop root perms; load modules and call
+         master_startup() after dropping perms
+
 Wed Mar  3 00:00:55 EST 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Prevent buffer overruns in lowercase_name in [get|put]user()
        * client_chat.c: use citedit() for page composition
index 940e8beb3272237759a68a3e6172ba4c253ef156..4e2e5a271f8915fbe4113dba2770678978466f04 100644 (file)
@@ -60,7 +60,10 @@ void get_config(void) {
 void put_config(void) {
        FILE *cfp;
        
-       cfp = fopen("citadel.config", "rb+");
-       fwrite((char *)&config, sizeof(struct config), 1, cfp);
-       fclose(cfp);
+       if ((cfp = fopen("citadel.config", "rb+")) == NULL)
+               perror("citadel.config");
+       else {
+               fwrite((char *)&config, sizeof(struct config), 1, cfp);
+               fclose(cfp);
+               }
        }
index 38b47bbfe4d6abdc60fdfbf57f81e374869bcc3d..9ab1a5e487748fc6573ee66977ec31902c3fe8f6 100644 (file)
@@ -707,6 +707,7 @@ int main(int argc, char *argv[]) {
        struct utsname my_utsname;
        struct passwd *pw;
        struct hostent *he;
+       gid_t gid;
 
        /* set an invalid setup type */
        setup_type = (-1);
@@ -936,13 +937,18 @@ NEW_INST:
        check_services_entry();         /* Check /etc/services */
        check_inittab_entry();          /* Check /etc/inittab */
 
+       if ((pw = getpwuid(config.c_bbsuid)) == NULL)
+               gid = getgid();
+       else
+               gid = pw->pw_gid;
+
        progress("Setting file permissions", 0, 3);
-       chown(".", config.c_bbsuid, getgid());
+       chown(".", config.c_bbsuid, gid);
        progress("Setting file permissions", 1, 3);
-       chown("citadel.config", config.c_bbsuid, getgid());
+       chown("citadel.config", config.c_bbsuid, gid);
        progress("Setting file permissions", 2, 3);
-       sprintf(aaa, "find . -exec chown %d {} \\; 2>/dev/null",
-               config.c_bbsuid);
+       sprintf(aaa, "find . -exec chown %d:%d {} \\; 2>/dev/null",
+               config.c_bbsuid, gid);
        system(aaa);
        progress("Setting file permissions", 3, 3);
 
index ad4c59037f2a45f3ec679a4147a45af99ecea958..ccfb24660e990f5c3b70122dd217f6a1bc924a72 100644 (file)
@@ -778,6 +778,8 @@ int main(int argc, char **argv)
        char convbuf[128];
        fd_set readfds;
        struct timeval tv;
+       struct passwd *pw;
+       int drop_root_perms = 1;
         
        /* specify default port name and trace file */
        strcpy(tracefile, "");
@@ -811,6 +813,12 @@ int main(int argc, char **argv)
                        home_specified = 1;
                        }
 
+               /* -r tells the server not to drop root permissions. don't use
+                * this unless you know what you're doing. this should be
+                * removed in the next release if it proves unnecessary. */
+               else if (!strcmp(argv[a], "-r"))
+                       drop_root_perms = 0;
+
                /* any other parameter makes it crash and burn */
                else {
                        lprintf(1, "citserver: usage: ");
@@ -823,7 +831,7 @@ int main(int argc, char **argv)
 
        /* Tell 'em who's in da house */
        lprintf(1, "Multithreaded message server for %s\n", CITADEL);
-       lprintf(1, "Copyright (C) 1987-1998 by Art Cancro.  ");
+       lprintf(1, "Copyright (C) 1987-1999 by Art Cancro.  ");
        lprintf(1, "All rights reserved.\n\n");
 
        /* Initialize... */
@@ -833,13 +841,6 @@ int main(int argc, char **argv)
        lprintf(7, "Loading citadel.config\n");
        get_config();
 
-        lprintf(7, "Initializing loadable modules\n");
-        DLoader_Init("./modules");
-        lprintf(9, "Modules done initializing.\n");
-
-       /* Do non system dependent startup functions */
-       master_startup();
-
        /*
         * Bind the server to our favourite port.
         * There is no need to check for errors, because ig_tcp_server()
@@ -850,12 +851,30 @@ int main(int argc, char **argv)
        lprintf(7, "Listening on socket %d\n", msock);
 
        /*
-        * Now that we've bound the socket, change to the BBS user id
-       lprintf(7, "Changing uid to %d\n", BBSUID);
-       if (setuid(BBSUID) != 0) {
-               lprintf(3, "setuid() failed: %s", strerror(errno));
+        * Now that we've bound the socket, change to the BBS user id and its
+        * corresponding group id
+        */
+       if (drop_root_perms) {
+               if ((pw = getpwuid(BBSUID)) == NULL)
+                       lprintf(1, "getpwuid(%d): %s\n", BBSUID,
+                               strerror(errno));
+               else if (setgid(pw->pw_gid))
+                       lprintf(3, "setgid(%d): %s\n", pw->pw_gid,
+                               strerror(errno));
+               lprintf(7, "Changing uid to %d\n", BBSUID);
+               if (setuid(BBSUID) != 0) {
+                       lprintf(3, "setuid() failed: %s\n", strerror(errno));
+                       }
                }
+
+       lprintf(7, "Initializing loadable modules\n");
+       DLoader_Init("./modules");
+       lprintf(9, "Modules done initializing.\n");
+
+       /*
+        * Do non system dependent startup functions.
         */
+       master_startup();
 
        /* 
         * Endless loop.  Listen on the master socket.  When a connection