diff --git a/src/sbbs3/ftpsrvr.c b/src/sbbs3/ftpsrvr.c index eacf8f0a426e05b6f063d135d98b3fa180ea63c7..a4569df7b56b9a531394fb60cee4c6c881370dbb 100644 --- a/src/sbbs3/ftpsrvr.c +++ b/src/sbbs3/ftpsrvr.c @@ -211,11 +211,13 @@ static void client_off(SOCKET sock) startup->client_on(FALSE,sock,NULL,FALSE); } -static void thread_up(void) +static void thread_up(BOOL setuid) { thread_count++; if(startup!=NULL && startup->thread_up!=NULL) startup->thread_up(TRUE); + if(setuid && startup!=NULL && startup->setuid!=NULL) + startup->setuid(); } static void thread_down(void) @@ -1360,7 +1362,7 @@ static void send_thread(void* arg) *xfer.inprogress=FALSE; return; } - thread_up(); + thread_up(TRUE /* setuid */); #if defined(_DEBUG) && defined(SOCKET_DEBUG_SENDTHREAD) socket_debug[xfer.ctrl_sock]|=SOCKET_DEBUG_SENDTHREAD; @@ -1571,7 +1573,7 @@ static void receive_thread(void* arg) return; } - thread_up(); + thread_up(TRUE /* setuid */); *xfer.aborted=FALSE; if(xfer.filepos || startup->options&FTP_OPT_DEBUG_DATA) @@ -2251,7 +2253,7 @@ static void ctrl_thread(void* arg) JSObject* js_ftp; #endif - thread_up(); + thread_up(TRUE /* setuid */); lastactive=time(NULL); @@ -4323,7 +4325,7 @@ void DLLCALL ftp_server(void* arg) recycle_server=TRUE; do { - thread_up(); + thread_up(FALSE /* setuid */); status("Initializing"); @@ -4465,6 +4467,9 @@ void DLLCALL ftp_server(void* arg) return; } + if(startup->setuid!=NULL) + startup->setuid(); + /* signal caller that we've started up successfully */ if(startup->started!=NULL) startup->started(); diff --git a/src/sbbs3/ftpsrvr.h b/src/sbbs3/ftpsrvr.h index 6637c3cf0c11c0e54db6e1d0c97d5f6957e7fba9..2107279094fec91a1953cb78064a4221d9bf04dd 100644 --- a/src/sbbs3/ftpsrvr.h +++ b/src/sbbs3/ftpsrvr.h @@ -69,7 +69,7 @@ typedef struct { void (*thread_up)(BOOL up); void (*socket_open)(BOOL open); void (*client_on)(BOOL on, int sock, client_t*, BOOL update); - void (*reserved_fptr4)(void); + BOOL (*setuid)(void); void (*reserved_fptr3)(void); void (*reserved_fptr2)(void); void (*reserved_fptr1)(void); diff --git a/src/sbbs3/mailsrvr.c b/src/sbbs3/mailsrvr.c index eac7066d26eee534950969f4f73400fda67e14fe..0a0467cd1acd720e984d48f2aeb84dae99bb9946 100644 --- a/src/sbbs3/mailsrvr.c +++ b/src/sbbs3/mailsrvr.c @@ -166,11 +166,13 @@ static void client_off(SOCKET sock) startup->client_on(FALSE,sock,NULL,FALSE); } -static void thread_up(void) +static void thread_up(BOOL setuid) { thread_count++; if(startup!=NULL && startup->thread_up!=NULL) startup->thread_up(TRUE); + if(setuid && startup!=NULL && startup->setuid!=NULL) + startup->setuid(); } static void thread_down(void) @@ -558,7 +560,7 @@ static void pop3_thread(void* arg) mail_t* mail; pop3_t pop3=*(pop3_t*)arg; - thread_up(); + thread_up(TRUE /* setuid */); free(arg); @@ -1180,7 +1182,7 @@ static void smtp_thread(void* arg) } cmd = SMTP_CMD_NONE; - thread_up(); + thread_up(TRUE /* setuid */); free(arg); @@ -2345,7 +2347,7 @@ static void sendmail_thread(void* arg) sendmail_running=TRUE; - thread_up(); + thread_up(TRUE /* setuid */); lprintf("0000 SendMail thread started"); @@ -2749,7 +2751,7 @@ void DLLCALL mail_server(void* arg) if(startup->max_delivery_attempts==0) startup->max_delivery_attempts=50; if(startup->max_inactivity==0) startup->max_inactivity=120; /* seconds */ - thread_up(); + thread_up(FALSE /* setuid */); status("Initializing"); @@ -2928,6 +2930,9 @@ void DLLCALL mail_server(void* arg) } } + if(startup->setuid!=NULL) + startup->setuid(); + /* signal caller that we've started up successfully */ if(startup->started!=NULL) startup->started(); diff --git a/src/sbbs3/mailsrvr.h b/src/sbbs3/mailsrvr.h index e4ed345edf5f7328d46177ab0c843a43a5b4eaba..b32b969c27afb22fb98731d877bc7755be8e92bf 100644 --- a/src/sbbs3/mailsrvr.h +++ b/src/sbbs3/mailsrvr.h @@ -71,7 +71,7 @@ typedef struct { void (*thread_up)(BOOL up); void (*socket_open)(BOOL open); void (*client_on)(BOOL on, int sock, client_t*, BOOL update); - void (*reserved_fptr4)(void); + BOOL (*setuid)(void); void (*reserved_fptr3)(void); void (*reserved_fptr2)(void); void (*reserved_fptr1)(void); diff --git a/src/sbbs3/main.cpp b/src/sbbs3/main.cpp index 43071c49c12b49d94d881773ec432338bd86598f..fb0fe300393447d941a5b630e97a7027bd0494c4 100644 --- a/src/sbbs3/main.cpp +++ b/src/sbbs3/main.cpp @@ -115,11 +115,13 @@ static void client_off(SOCKET sock) startup->client_on(FALSE,sock,NULL,FALSE); } -static void thread_up() +static void thread_up(BOOL setuid) { thread_count++; if(startup!=NULL && startup->thread_up!=NULL) startup->thread_up(TRUE); + if(setuid && startup!=NULL && startup->setuid!=NULL) + startup->setuid(); } static void thread_down() @@ -700,7 +702,7 @@ void input_thread(void *arg) sbbs_t* sbbs = (sbbs_t*) arg; struct timeval tv; - thread_up(); + thread_up(TRUE /* setuid */); #ifdef _DEBUG lprintf("Node %d input thread started",sbbs->cfg.node_num); @@ -842,7 +844,7 @@ void output_thread(void* arg) fd_set socket_set; struct timeval tv; - thread_up(); + thread_up(TRUE /* setuid */); if(sbbs->cfg.node_num) sprintf(node,"Node %d",sbbs->cfg.node_num); @@ -975,7 +977,7 @@ void event_thread(void* arg) srand(clock()); /* Seed random number generator */ sbbs_random(10); /* Throw away first number */ - thread_up(); + thread_up(TRUE /* setuid */); #ifdef JAVASCRIPT if(!(startup->options&BBS_OPT_NO_JAVASCRIPT)) { @@ -2596,7 +2598,7 @@ void node_thread(void* arg) sbbs_t* sbbs = (sbbs_t*) arg; update_clients(); - thread_up(); + thread_up(TRUE /* setuid */); srand(clock()); /* Seed random number generator */ sbbs_random(10); /* Throw away first number */ @@ -3008,7 +3010,7 @@ void DLLCALL bbs_thread(void* arg) if(startup->js_max_bytes==0) startup->js_max_bytes=JAVASCRIPT_MAX_BYTES; #endif - thread_up(); + thread_up(FALSE /* setuid */); status("Initializing"); @@ -3280,6 +3282,9 @@ void DLLCALL bbs_thread(void* arg) lprintf("RLogin server listening on port %d",startup->rlogin_port); } + if(startup->setuid!=NULL) + startup->setuid(); + /* signal caller that we've started up successfully */ if(startup->started!=NULL) startup->started(); diff --git a/src/sbbs3/sbbscon.c b/src/sbbs3/sbbscon.c index 156a5bad68efe88a6f2e8c89ce6dc696c874170f..03aea3a1081b4b9d52e29b61b569e57b9cd7685b 100644 --- a/src/sbbs3/sbbscon.c +++ b/src/sbbs3/sbbscon.c @@ -141,13 +141,8 @@ static void thread_up(BOOL up) } pthread_mutex_lock(&mutex); - if(up) { + if(up) thread_count++; -#ifdef __unix__ - do_setuid(); -#endif - } - else if(thread_count>0) thread_count--; pthread_mutex_unlock(&mutex); @@ -429,6 +424,9 @@ int main(int argc, char** argv) bbs_startup.thread_up=thread_up; bbs_startup.socket_open=socket_open; bbs_startup.client_on=client_on; +#ifdef __unix__ + bbs_startup.setuid=do_setuid; +#endif /* These callbacks haven't been created yet bbs_startup.status=bbs_status; bbs_startup.clients=bbs_clients; @@ -445,6 +443,9 @@ int main(int argc, char** argv) ftp_startup.socket_open=socket_open; ftp_startup.client_on=client_on; ftp_startup.options=FTP_OPT_INDEX_FILE|FTP_OPT_ALLOW_QWK; +#ifdef __unix__ + ftp_startup.setuid=do_setuid; +#endif strcpy(ftp_startup.index_file_name,"00index"); strcpy(ftp_startup.ctrl_dir,ctrl_dir); @@ -458,6 +459,9 @@ int main(int argc, char** argv) mail_startup.socket_open=socket_open; mail_startup.client_on=client_on; mail_startup.options|=MAIL_OPT_ALLOW_POP3; +#ifdef __unix__ + mail_startup.setuid=do_setuid; +#endif /* Spam filtering */ mail_startup.options|=MAIL_OPT_USE_RBL; /* Realtime Blackhole List */ mail_startup.options|=MAIL_OPT_USE_RSS; /* Relay Spam Stopper */ @@ -498,6 +502,9 @@ int main(int argc, char** argv) services_startup.thread_up=thread_up; services_startup.socket_open=socket_open; services_startup.client_on=client_on; +#ifdef __unix__ + services_startup.setuid=do_setuid; +#endif strcpy(services_startup.ctrl_dir,ctrl_dir); /* Process arguments */ diff --git a/src/sbbs3/services.c b/src/sbbs3/services.c index 340a4e80be4d36e990460f3d7cf3e43bfe1966eb..3730949d8c694da600bfc77da74e0ed278800799 100644 --- a/src/sbbs3/services.c +++ b/src/sbbs3/services.c @@ -167,10 +167,12 @@ static void client_off(SOCKET sock) startup->client_on(FALSE,sock,NULL,FALSE); } -static void thread_up(void) +static void thread_up(BOOL setuid) { if(startup!=NULL && startup->thread_up!=NULL) startup->thread_up(TRUE); + if(setuid && startup!=NULL && startup->setuid!=NULL) + startup->setuid(); } static void thread_down(void) @@ -592,7 +594,7 @@ static void js_service_thread(void* arg) lprintf("%04d %s JavaScript service thread started", socket, service->protocol); - thread_up(); + thread_up(TRUE /* setuid */); /* Host name lookup and filtering */ if(service->options&BBS_OPT_NO_HOST_LOOKUP @@ -762,7 +764,7 @@ static void native_service_thread(void* arg) lprintf("%04d %s service thread started", socket, service->protocol); - thread_up(); + thread_up(TRUE /* setuid */); /* Host name lookup and filtering */ if(service->options&BBS_OPT_NO_HOST_LOOKUP @@ -1004,7 +1006,7 @@ void DLLCALL services_thread(void* arg) /* Setup intelligent defaults */ if(startup->js_max_bytes==0) startup->js_max_bytes=JAVASCRIPT_MAX_BYTES; - thread_up(); + thread_up(FALSE /* setuid */); status("Initializing"); @@ -1110,6 +1112,9 @@ void DLLCALL services_thread(void* arg) service[i].socket=socket; } + if(startup->setuid!=NULL) + startup->setuid(); + /* signal caller that we've started up successfully */ if(startup->started!=NULL) startup->started(); diff --git a/src/sbbs3/services.h b/src/sbbs3/services.h index e8457426eec79cbf60ef2a5c914c0aceed054b05..6ab1ea915ea579e7b516c881d838ec015d538dbb 100644 --- a/src/sbbs3/services.h +++ b/src/sbbs3/services.h @@ -62,7 +62,7 @@ typedef struct { void (*thread_up)(BOOL up); void (*socket_open)(BOOL open); void (*client_on)(BOOL on, int sock, client_t*, BOOL update); - void (*reserved_fptr4)(void); + BOOL (*setuid)(void); void (*reserved_fptr3)(void); void (*reserved_fptr2)(void); void (*reserved_fptr1)(void); diff --git a/src/sbbs3/startup.h b/src/sbbs3/startup.h index 494ad11b6ebc449ce97abce9d4803a8752399c7b..21d8c86b2ac016edc8103db38724e1008cc2f02e 100644 --- a/src/sbbs3/startup.h +++ b/src/sbbs3/startup.h @@ -75,7 +75,7 @@ typedef struct { void (*thread_up)(BOOL up); void (*socket_open)(BOOL open); void (*client_on)(BOOL on, int sock, client_t*, BOOL update); - void (*reserved_fptr4)(void); + BOOL (*setuid)(void); // Set Unix uid for thread void (*reserved_fptr3)(void); void (*reserved_fptr2)(void); void (*reserved_fptr1)(void);