]> code.citadel.org Git - citadel.git/blobdiff - webcit/webserver.c
* port our setuid function from citserver to webcit; -u can now specify the UID...
[citadel.git] / webcit / webserver.c
index 67642f58d8f6e376f8b05e2a703400f5fe3c3ca2..c70419b3be0d405c982abfbf537168a50109ca49 100644 (file)
@@ -5,7 +5,7 @@
  * waiting on the specified port for incoming HTTP connections.  When a
  * connection is established, it calls context_loop() from context_loop.c.
  *
- * Copyright (c) 1996-2009 by the citadel.org developers.
+ * Copyright (c) 1996-2010 by the citadel.org developers.
  * This program is released under the terms of the GNU General Public License v3.
  *
  */
@@ -36,6 +36,7 @@ extern pthread_key_t MyConKey;
 extern int ig_tcp_server(char *ip_addr, int port_number, int queue_len);
 extern int ig_uds_server(char *sockpath, int queue_len);
 
+extern void drop_root(uid_t UID);
 
 char ctdl_key_dir[PATH_MAX]=SSL_DIR;
 char file_crpt_file_key[PATH_MAX]="";
@@ -315,6 +316,7 @@ webcit_calc_dirs_n_files(int relh, const char *basedir, int home, char *webcitdi
  */
 int main(int argc, char **argv)
 {
+       uid_t UID = -1;
        size_t basesize = 2;            /* how big should strbufs be on creation? */
        pthread_t SessThread;           /* Thread descriptor */
        pthread_attr_t attr;            /* Thread attributes */
@@ -355,11 +357,14 @@ int main(int argc, char **argv)
 
        /* Parse command line */
 #ifdef HAVE_OPENSSL
-       while ((a = getopt(argc, argv, "h:i:p:t:T:B:x:dD:G:cfsS:Z")) != EOF)
+       while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:dD:G:cfsS:Z")) != EOF)
 #else
-       while ((a = getopt(argc, argv, "h:i:p:t:T:B:x:dD:G:cfZ")) != EOF)
+       while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:dD:G:cfZ")) != EOF)
 #endif
                switch (a) {
+               case 'u':
+                       UID = atol(optarg);
+                       break;
                case 'h':
                        hdir = strdup(optarg);
                        relh=hdir[0]!='/';
@@ -475,7 +480,7 @@ int main(int argc, char **argv)
 
        /* Tell 'em who's in da house */
        lprintf(1, PACKAGE_STRING "\n");
-       lprintf(1, "Copyright (C) 1996-2009 by the Citadel development team.\n"
+       lprintf(1, "Copyright (C) 1996-2010 by the Citadel development team.\n"
                "This software is distributed under the terms of the "
                "GNU General Public License.\n\n"
        );
@@ -580,6 +585,7 @@ int main(int argc, char **argv)
                init_ssl();
        }
 #endif
+       drop_root(UID);
 
        /* Start a few initial worker threads */
        for (i = 0; i < (MIN_WORKER_THREADS); ++i) {