From df9cfa890ae9bae4eea546f3f1ae51fafdcf3295 Mon Sep 17 00:00:00 2001 From: Stu Mark Date: Thu, 22 Feb 2001 18:22:39 +0000 Subject: [PATCH] Mostly made changes to allow client_gets to handle reading a buffer larger than SIZ. This required changes all over the place. Most of the changes in source were just putting an i in front of the cmdbuf variable name for the purpose of having the compiler point out to me everything that I had to fix. Sorry if this is bothersome, but I know I fixed every last one of them. I tried to follow functionality to see where the bigger buffer might cause a problem dealing with a smaller buffer. In most cases this was in the extract function and lprintf. extract is now limited to one token being of max size SIZ. Lprintf now does a pre-printf to size the buffer it's going to need to print. If this is a performance problem then we'll have to rewrite lprintf. Also added getmem, freemem, reallocmem to the debugging version of the mallok/phree reallok functions. They basically just check for memory overruns upon freeing the memory. I figured it couldn't hurt and I thought you might find it useful. added 2 vars to the citsession to hold the dynamic buffer for input per session. gets freed on session close, so their should be no memory leak. there's a couple of places where I left source in with that are commented out. This is just for reference so you can see what I did. remove them if you find them annoying (ex: oldclient_gets()) fiddled with the control file reader to use the new buffer thing too had to change to make it read right. for example, clients_gets used to read into the buffer, now it gets string copies out. hmmm.. there may be overruns there, let me check that. One thing I'd like to say is that I couldnt' test everything because I don't know how to get everything to run, but I changed everything in the same manner and I tested some of it, so I think the other changes should be fine. Let me know if you see a problem. --- citadel/ChangeLog | 35 +++++ citadel/citserver.c | 318 ++++++++++++++++++++-------------------- citadel/control.c | 67 ++++----- citadel/msgbase.c | 32 ++-- citadel/room_ops.c | 10 +- citadel/serv_bio.c | 11 +- citadel/serv_chat.c | 7 +- citadel/serv_imap.c | 25 ++-- citadel/serv_network.c | 11 +- citadel/serv_pop3.c | 57 ++++--- citadel/serv_smtp.c | 54 +++---- citadel/serv_vandelay.c | 219 +++++++++++++-------------- citadel/serv_vcard.c | 24 +-- citadel/server.h | 4 + citadel/sysdep.c | 156 +++++++++++++++++++- citadel/sysdep_decls.h | 2 +- citadel/tools.c | 10 +- 17 files changed, 621 insertions(+), 421 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 8ee274f9b..573bce5f6 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,38 @@ $Log$ + Revision 573.97 2001/02/22 18:22:38 nixo + Mostly made changes to allow client_gets to handle reading a buffer + larger than SIZ. This required changes all over the place. + Most of the changes in source were just putting an i in front of the + cmdbuf variable name for the purpose of having the compiler point out + to me everything that I had to fix. Sorry if this is bothersome, but + I know I fixed every last one of them. + I tried to follow functionality to see where the bigger buffer might + cause a problem dealing with a smaller buffer. In most cases this was + in the extract function and lprintf. + extract is now limited to one token being of max size SIZ. Lprintf now + does a pre-printf to size the buffer it's going to need to print. If + this is a performance problem then we'll have to rewrite lprintf. + Also added getmem, freemem, reallocmem to the debugging version of + the mallok/phree reallok functions. They basically just check for + memory overruns upon freeing the memory. I figured it couldn't hurt + and I thought you might find it useful. + added 2 vars to the citsession to hold the dynamic buffer for input + per session. gets freed on session close, so their should be no + memory leak. + there's a couple of places where I left source in with that are + commented out. This is just for reference so you can see what I did. + remove them if you find them annoying (ex: oldclient_gets()) + fiddled with the control file reader to use the new buffer thing too + had to change to make it read right. + for example, clients_gets used to read into the buffer, now + it gets string copies out. + hmmm.. there may be overruns there, let me check that. + + One thing I'd like to say is that I couldnt' test everything because + I don't know how to get everything to run, but I changed everything + in the same manner and I tested some of it, so I think the other + changes should be fine. Let me know if you see a problem. + Revision 573.96 2001/02/21 05:44:44 ajc * Wrote the "citlogin" wrapper, so Citadel client can run directly without having to login as bbs first. @@ -2432,3 +2466,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/citserver.c b/citadel/citserver.c index d63c092cf..25f1eb0f2 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -197,6 +197,10 @@ void RemoveContext (struct CitContext *con) lprintf(7, "Closing socket %d\n", con->client_socket); close(con->client_socket); + /* stu 2/7/2001 free up mem used by reader */ + if (con->readbuf != NULL) + phree(con->readbuf); + /* This is where we used to check for scheduled shutdowns. */ /* Free up the memory used by this context */ @@ -519,6 +523,7 @@ void cmd_emsg(char *mname) FILE *mfp; char targ[SIZ]; char buf[SIZ]; + char *ibuf; char *dirs[2]; int a; @@ -549,8 +554,8 @@ void cmd_emsg(char *mname) } cprintf("%d %s\n", SEND_LISTING, targ); - while (client_gets(buf), strcmp(buf, "000")) { - fprintf(mfp, "%s\n", buf); + while (client_gets(&ibuf), strcmp(ibuf, "000")) { + fprintf(mfp, "%s\n", ibuf); } fclose(mfp); @@ -838,366 +843,367 @@ void citproto_begin_session() { * This loop recognizes all server commands. */ void do_command_loop(void) { - char cmdbuf[SIZ]; +/* char cmdbuf[SIZ]; stu */ + char *icmdbuf; time(&CC->lastcmd); - memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */ - if (client_gets(cmdbuf) < 1) { +/* memset(cmdbuf, 0, sizeof cmdbuf); */ /* Clear it, just in case */ + if (client_gets(&icmdbuf) < 1) { lprintf(3, "Client socket is broken. Ending session.\n"); CC->kill_me = 1; return; } - lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, cmdbuf); + lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, icmdbuf); /* * Let other clients see the last command we executed, and * update the idle time, but not NOOP, PEXP, or GEXP. */ - if ( (strncasecmp(cmdbuf, "NOOP", 4)) - && (strncasecmp(cmdbuf, "PEXP", 4)) - && (strncasecmp(cmdbuf, "GEXP", 4)) ) { + if ( (strncasecmp(icmdbuf, "NOOP", 4)) + && (strncasecmp(icmdbuf, "PEXP", 4)) + && (strncasecmp(icmdbuf, "GEXP", 4)) ) { strcpy(CC->lastcmdname, " "); - safestrncpy(CC->lastcmdname, cmdbuf, + safestrncpy(CC->lastcmdname, icmdbuf, sizeof(CC->lastcmdname) ); time(&CC->lastidle); } - if ((strncasecmp(cmdbuf, "ENT0", 4)) - && (strncasecmp(cmdbuf, "MESG", 4)) - && (strncasecmp(cmdbuf, "MSGS", 4))) + if ((strncasecmp(icmdbuf, "ENT0", 4)) + && (strncasecmp(icmdbuf, "MESG", 4)) + && (strncasecmp(icmdbuf, "MSGS", 4))) { CC->cs_flags &= ~CS_POSTING; } - if (!strncasecmp(cmdbuf,"NOOP",4)) { + if (!strncasecmp(icmdbuf,"NOOP",4)) { cprintf("%d%cok\n",OK,CtdlCheckExpress()); } - else if (!strncasecmp(cmdbuf,"QUIT",4)) { + else if (!strncasecmp(icmdbuf,"QUIT",4)) { cprintf("%d Goodbye.\n",OK); CC->kill_me = 1; } - else if (!strncasecmp(cmdbuf,"ASYN",4)) { - cmd_asyn(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"ASYN",4)) { + cmd_asyn(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"LOUT",4)) { + else if (!strncasecmp(icmdbuf,"LOUT",4)) { if (CC->logged_in) logout(CC); cprintf("%d logged out.\n",OK); } - else if (!strncasecmp(cmdbuf,"USER",4)) { - cmd_user(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"USER",4)) { + cmd_user(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"PASS",4)) { - cmd_pass(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"PASS",4)) { + cmd_pass(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"NEWU",4)) { - cmd_newu(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"NEWU",4)) { + cmd_newu(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"SETP",4)) { - cmd_setp(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"SETP",4)) { + cmd_setp(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"LRMS",4)) { - cmd_lrms(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"LRMS",4)) { + cmd_lrms(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"LKRA",4)) { - cmd_lkra(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"LKRA",4)) { + cmd_lkra(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"LKRN",4)) { - cmd_lkrn(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"LKRN",4)) { + cmd_lkrn(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"LKRO",4)) { - cmd_lkro(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"LKRO",4)) { + cmd_lkro(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"LZRM",4)) { - cmd_lzrm(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"LZRM",4)) { + cmd_lzrm(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"GETU",4)) { + else if (!strncasecmp(icmdbuf,"GETU",4)) { cmd_getu(); } - else if (!strncasecmp(cmdbuf,"SETU",4)) { - cmd_setu(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"SETU",4)) { + cmd_setu(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"GOTO",4)) { - cmd_goto(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"GOTO",4)) { + cmd_goto(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"MSGS",4)) { - cmd_msgs(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"MSGS",4)) { + cmd_msgs(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"WHOK",4)) { + else if (!strncasecmp(icmdbuf,"WHOK",4)) { cmd_whok(); } - else if (!strncasecmp(cmdbuf,"RDIR",4)) { + else if (!strncasecmp(icmdbuf,"RDIR",4)) { cmd_rdir(); } - else if (!strncasecmp(cmdbuf,"MSG0",4)) { - cmd_msg0(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"MSG0",4)) { + cmd_msg0(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"MSG2",4)) { - cmd_msg2(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"MSG2",4)) { + cmd_msg2(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"MSG3",4)) { - cmd_msg3(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"MSG3",4)) { + cmd_msg3(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"MSG4",4)) { - cmd_msg4(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"MSG4",4)) { + cmd_msg4(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"OPNA",4)) { - cmd_opna(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"OPNA",4)) { + cmd_opna(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"INFO",4)) { + else if (!strncasecmp(icmdbuf,"INFO",4)) { cmd_info(); } - else if (!strncasecmp(cmdbuf,"SLRP",4)) { - cmd_slrp(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"SLRP",4)) { + cmd_slrp(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"INVT",4)) { - cmd_invt_kick(&cmdbuf[5],1); + else if (!strncasecmp(icmdbuf,"INVT",4)) { + cmd_invt_kick(&icmdbuf[5],1); } - else if (!strncasecmp(cmdbuf,"KICK",4)) { - cmd_invt_kick(&cmdbuf[5],0); + else if (!strncasecmp(icmdbuf,"KICK",4)) { + cmd_invt_kick(&icmdbuf[5],0); } - else if (!strncasecmp(cmdbuf,"GETR",4)) { + else if (!strncasecmp(icmdbuf,"GETR",4)) { cmd_getr(); } - else if (!strncasecmp(cmdbuf,"SETR",4)) { - cmd_setr(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"SETR",4)) { + cmd_setr(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"GETA",4)) { + else if (!strncasecmp(icmdbuf,"GETA",4)) { cmd_geta(); } - else if (!strncasecmp(cmdbuf,"SETA",4)) { - cmd_seta(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"SETA",4)) { + cmd_seta(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"ENT0",4)) { - cmd_ent0(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"ENT0",4)) { + cmd_ent0(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"ENT3",4)) { - cmd_ent3(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"ENT3",4)) { + cmd_ent3(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"RINF",4)) { + else if (!strncasecmp(icmdbuf,"RINF",4)) { cmd_rinf(); } - else if (!strncasecmp(cmdbuf,"DELE",4)) { - cmd_dele(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"DELE",4)) { + cmd_dele(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"KILL",4)) { - cmd_kill(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"KILL",4)) { + cmd_kill(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"CRE8",4)) { - cmd_cre8(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"CRE8",4)) { + cmd_cre8(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"MOVE",4)) { - cmd_move(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"MOVE",4)) { + cmd_move(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"FORG",4)) { + else if (!strncasecmp(icmdbuf,"FORG",4)) { cmd_forg(); } - else if (!strncasecmp(cmdbuf,"MESG",4)) { - cmd_mesg(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"MESG",4)) { + cmd_mesg(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"EMSG",4)) { - cmd_emsg(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"EMSG",4)) { + cmd_emsg(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"GNUR",4)) { + else if (!strncasecmp(icmdbuf,"GNUR",4)) { cmd_gnur(); } - else if (!strncasecmp(cmdbuf,"VALI",4)) { - cmd_vali(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"VALI",4)) { + cmd_vali(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"EINF",4)) { - cmd_einf(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"EINF",4)) { + cmd_einf(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"LIST",4)) { + else if (!strncasecmp(icmdbuf,"LIST",4)) { cmd_list(); } - else if (!strncasecmp(cmdbuf,"CHEK",4)) { + else if (!strncasecmp(icmdbuf,"CHEK",4)) { cmd_chek(); } - else if (!strncasecmp(cmdbuf,"DELF",4)) { - cmd_delf(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"DELF",4)) { + cmd_delf(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"MOVF",4)) { - cmd_movf(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"MOVF",4)) { + cmd_movf(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"NETF",4)) { - cmd_netf(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"NETF",4)) { + cmd_netf(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"OPEN",4)) { - cmd_open(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"OPEN",4)) { + cmd_open(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"CLOS",4)) { + else if (!strncasecmp(icmdbuf,"CLOS",4)) { cmd_clos(); } - else if (!strncasecmp(cmdbuf,"UOPN",4)) { - cmd_uopn(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"UOPN",4)) { + cmd_uopn(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"UCLS",4)) { - cmd_ucls(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"UCLS",4)) { + cmd_ucls(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"READ",4)) { - cmd_read(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"READ",4)) { + cmd_read(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"WRIT",4)) { - cmd_writ(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"WRIT",4)) { + cmd_writ(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"QUSR",4)) { - cmd_qusr(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"QUSR",4)) { + cmd_qusr(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"ECHO",4)) { - cmd_echo(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"ECHO",4)) { + cmd_echo(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"OIMG",4)) { - cmd_oimg(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"OIMG",4)) { + cmd_oimg(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"MORE",4)) { + else if (!strncasecmp(icmdbuf,"MORE",4)) { cmd_more(); } - else if (!strncasecmp(cmdbuf,"NETP",4)) { - cmd_netp(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"NETP",4)) { + cmd_netp(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"NDOP",4)) { - cmd_ndop(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"NDOP",4)) { + cmd_ndop(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"NUOP",4)) { - cmd_nuop(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"NUOP",4)) { + cmd_nuop(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"LFLR",4)) { + else if (!strncasecmp(icmdbuf,"LFLR",4)) { cmd_lflr(); } - else if (!strncasecmp(cmdbuf,"CFLR",4)) { - cmd_cflr(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"CFLR",4)) { + cmd_cflr(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"KFLR",4)) { - cmd_kflr(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"KFLR",4)) { + cmd_kflr(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"EFLR",4)) { - cmd_eflr(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"EFLR",4)) { + cmd_eflr(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"IDEN",4)) { - cmd_iden(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"IDEN",4)) { + cmd_iden(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"IPGM",4)) { - cmd_ipgm(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"IPGM",4)) { + cmd_ipgm(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"TERM",4)) { - cmd_term(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"TERM",4)) { + cmd_term(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf,"DOWN",4)) { + else if (!strncasecmp(icmdbuf,"DOWN",4)) { cmd_down(); } - else if (!strncasecmp(cmdbuf,"SCDN",4)) { - cmd_scdn(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf,"SCDN",4)) { + cmd_scdn(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "NSET", 4)) { - cmd_nset(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "NSET", 4)) { + cmd_nset(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "UIMG", 4)) { - cmd_uimg(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "UIMG", 4)) { + cmd_uimg(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "TIME", 4)) { + else if (!strncasecmp(icmdbuf, "TIME", 4)) { cmd_time(); } - else if (!strncasecmp(cmdbuf, "AGUP", 4)) { - cmd_agup(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "AGUP", 4)) { + cmd_agup(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "ASUP", 4)) { - cmd_asup(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "ASUP", 4)) { + cmd_asup(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "GPEX", 4)) { - cmd_gpex(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "GPEX", 4)) { + cmd_gpex(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "SPEX", 4)) { - cmd_spex(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "SPEX", 4)) { + cmd_spex(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "CONF", 4)) { - cmd_conf(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "CONF", 4)) { + cmd_conf(&icmdbuf[5]); } #ifdef DEBUG_MEMORY_LEAKS - else if (!strncasecmp(cmdbuf, "LEAK", 4)) { + else if (!strncasecmp(icmdbuf, "LEAK", 4)) { dump_tracked(); } #endif - else if (!DLoader_Exec_Cmd(cmdbuf)) + else if (!DLoader_Exec_Cmd(icmdbuf)) { cprintf("%d Unrecognized or unsupported command.\n", ERROR); diff --git a/citadel/control.c b/citadel/control.c index dd056611b..524a0e465 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -127,7 +127,7 @@ long get_new_room_number(void) { */ void cmd_conf(char *argbuf) { char cmd[SIZ]; - char buf[SIZ]; + char *ibuf; int a; char *confptr; char confname[SIZ]; @@ -178,92 +178,93 @@ void cmd_conf(char *argbuf) { } else if (!strcasecmp(cmd, "SET")) { + char buf[SIZ]; cprintf("%d Send configuration...\n", SEND_LISTING); a = 0; - while (client_gets(buf), strcmp(buf, "000")) { + while (client_gets(&ibuf), strcmp(ibuf, "000")) { switch(a) { - case 0: safestrncpy(config.c_nodename, buf, + case 0: safestrncpy(config.c_nodename, ibuf, sizeof config.c_nodename); break; - case 1: safestrncpy(config.c_fqdn, buf, + case 1: safestrncpy(config.c_fqdn, ibuf, sizeof config.c_fqdn); break; - case 2: safestrncpy(config.c_humannode, buf, + case 2: safestrncpy(config.c_humannode, ibuf, sizeof config.c_humannode); break; - case 3: safestrncpy(config.c_phonenum, buf, + case 3: safestrncpy(config.c_phonenum, ibuf, sizeof config.c_phonenum); break; - case 4: config.c_creataide = atoi(buf); + case 4: config.c_creataide = atoi(ibuf); break; - case 5: config.c_sleeping = atoi(buf); + case 5: config.c_sleeping = atoi(ibuf); break; - case 6: config.c_initax = atoi(buf); + case 6: config.c_initax = atoi(ibuf); if (config.c_initax < 1) config.c_initax = 1; if (config.c_initax > 6) config.c_initax = 6; break; - case 7: config.c_regiscall = atoi(buf); + case 7: config.c_regiscall = atoi(ibuf); if (config.c_regiscall != 0) config.c_regiscall = 1; break; - case 8: config.c_twitdetect = atoi(buf); + case 8: config.c_twitdetect = atoi(ibuf); if (config.c_twitdetect != 0) config.c_twitdetect = 1; break; - case 9: safestrncpy(config.c_twitroom, buf, + case 9: safestrncpy(config.c_twitroom, ibuf, sizeof config.c_twitroom); break; - case 10: safestrncpy(config.c_moreprompt, buf, + case 10: safestrncpy(config.c_moreprompt, ibuf, sizeof config.c_moreprompt); break; - case 11: config.c_restrict = atoi(buf); + case 11: config.c_restrict = atoi(ibuf); if (config.c_restrict != 0) config.c_restrict = 1; break; - case 12: safestrncpy(config.c_bbs_city, buf, + case 12: safestrncpy(config.c_bbs_city, ibuf, sizeof config.c_bbs_city); break; - case 13: safestrncpy(config.c_sysadm, buf, + case 13: safestrncpy(config.c_sysadm, ibuf, sizeof config.c_sysadm); break; - case 14: config.c_maxsessions = atoi(buf); + case 14: config.c_maxsessions = atoi(ibuf); if (config.c_maxsessions < 1) config.c_maxsessions = 1; break; - case 15: safestrncpy(config.c_net_password, buf, + case 15: safestrncpy(config.c_net_password, ibuf, sizeof config.c_net_password); break; - case 16: config.c_userpurge = atoi(buf); + case 16: config.c_userpurge = atoi(ibuf); break; - case 17: config.c_roompurge = atoi(buf); + case 17: config.c_roompurge = atoi(ibuf); break; - case 18: safestrncpy(config.c_logpages, buf, + case 18: safestrncpy(config.c_logpages, ibuf, sizeof config.c_logpages); break; - case 19: config.c_createax = atoi(buf); + case 19: config.c_createax = atoi(ibuf); if (config.c_createax < 1) config.c_createax = 1; if (config.c_createax > 6) config.c_createax = 6; break; - case 20: if (atoi(buf) >= 8192) - config.c_maxmsglen = atoi(buf); + case 20: if (atoi(ibuf) >= 8192) + config.c_maxmsglen = atoi(ibuf); break; - case 21: if (atoi(buf) >= 2) - config.c_min_workers = atoi(buf); - case 22: if (atoi(buf) >= config.c_min_workers) - config.c_max_workers = atoi(buf); - case 23: config.c_pop3_port = atoi(buf); + case 21: if (atoi(ibuf) >= 2) + config.c_min_workers = atoi(ibuf); + case 22: if (atoi(ibuf) >= config.c_min_workers) + config.c_max_workers = atoi(ibuf); + case 23: config.c_pop3_port = atoi(ibuf); break; - case 24: config.c_smtp_port = atoi(buf); + case 24: config.c_smtp_port = atoi(ibuf); break; - case 25: config.c_default_filter = atoi(buf); + case 25: config.c_default_filter = atoi(ibuf); break; - case 26: config.c_aide_zap = atoi(buf); + case 26: config.c_aide_zap = atoi(ibuf); if (config.c_aide_zap != 0) config.c_aide_zap = 1; break; - case 27: config.c_imap_port = atoi(buf); + case 27: config.c_imap_port = atoi(ibuf); break; } ++a; diff --git a/citadel/msgbase.c b/citadel/msgbase.c index b2e8ced83..d00da6491 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -386,7 +386,7 @@ void cmd_msgs(char *cmdbuf) { int mode = 0; char which[SIZ]; - char buf[SIZ]; + char *ibuf; char tfield[SIZ]; char tvalue[SIZ]; int cm_ref = 0; @@ -394,7 +394,7 @@ void cmd_msgs(char *cmdbuf) int with_template = 0; struct CtdlMessage *template = NULL; - extract(which, cmdbuf, 0); + extract(which, cmdbuf, 0); /* extract makes sure we don't overrun */ cm_ref = extract_int(cmdbuf, 1); with_template = extract_int(cmdbuf, 2); @@ -422,9 +422,9 @@ void cmd_msgs(char *cmdbuf) template = (struct CtdlMessage *) mallok(sizeof(struct CtdlMessage)); memset(template, 0, sizeof(struct CtdlMessage)); - while(client_gets(buf), strcmp(buf,"000")) { - extract(tfield, buf, 0); - extract(tvalue, buf, 1); + while(client_gets(&ibuf), strcmp(ibuf,"000")) { + extract(tfield, ibuf, 0); + extract(tvalue, ibuf, 1); for (i='A'; i<='Z'; ++i) if (msgkeys[i]!=NULL) { if (!strcasecmp(tfield, msgkeys[i])) { template->cm_fields[i] = @@ -1835,7 +1835,7 @@ char *CtdlReadMessageBody(char *terminator, /* token signalling EOT */ char *exist /* if non-null, append to it; exist is ALWAYS freed */ ) { - char buf[SIZ]; + char *ibuf; int linelen; size_t message_len = 0; size_t buffer_len = 0; @@ -1850,7 +1850,7 @@ char *CtdlReadMessageBody(char *terminator, /* token signalling EOT */ if (m == NULL) phree(exist); } if (m == NULL) { - while ( (client_gets(buf)>0) && strcmp(buf, terminator) ) ;; + while ( (client_gets(&ibuf)>0) && strcmp(ibuf, terminator) ) ;; return(NULL); } else { buffer_len = 4096; @@ -1858,21 +1858,21 @@ char *CtdlReadMessageBody(char *terminator, /* token signalling EOT */ message_len = 0; } /* read in the lines of message text one by one */ - while ( (client_gets(buf)>0) && strcmp(buf, terminator) ) { + while ( (client_gets(&ibuf)>0) && strcmp(ibuf, terminator) ) { /* strip trailing newline type stuff */ - if (buf[strlen(buf)-1]==10) buf[strlen(buf)-1]=0; - if (buf[strlen(buf)-1]==13) buf[strlen(buf)-1]=0; + if (ibuf[strlen(ibuf)-1]==10) ibuf[strlen(ibuf)-1]=0; + if (ibuf[strlen(ibuf)-1]==13) ibuf[strlen(ibuf)-1]=0; - linelen = strlen(buf); + linelen = strlen(ibuf); /* augment the buffer if we have to */ if ((message_len + linelen + 2) > buffer_len) { lprintf(9, "realloking\n"); ptr = reallok(m, (buffer_len * 2) ); if (ptr == NULL) { /* flush if can't allocate */ - while ( (client_gets(buf)>0) && - strcmp(buf, terminator)) ;; + while ( (client_gets(&ibuf)>0) && + strcmp(ibuf, terminator)) ;; return(m); } else { buffer_len = (buffer_len * 2); @@ -1885,15 +1885,15 @@ char *CtdlReadMessageBody(char *terminator, /* token signalling EOT */ * because that would involve traversing the entire message * after each line, and this function needs to run fast. */ - strcpy(&m[message_len], buf); + strcpy(&m[message_len], ibuf); m[message_len + linelen] = '\n'; m[message_len + linelen + 1] = 0; message_len = message_len + linelen + 1; /* if we've hit the max msg length, flush the rest */ if (message_len >= maxlen) { - while ( (client_gets(buf)>0) - && strcmp(buf, terminator)) ;; + while ( (client_gets(&ibuf)>0) + && strcmp(ibuf, terminator)) ;; return(m); } } diff --git a/citadel/room_ops.c b/citadel/room_ops.c index d7ba6a6e5..448aa62c9 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -1418,7 +1418,7 @@ void cmd_einf(char *ok) { /* enter info file for current room */ FILE *fp; char infofilename[SIZ]; - char buf[SIZ]; + char *ibuf; if (CtdlAccessCheck(ac_room_aide)) return; @@ -1438,10 +1438,10 @@ void cmd_einf(char *ok) cprintf("%d Send info...\n", SEND_LISTING); do { - client_gets(buf); - if (strcmp(buf, "000")) - fprintf(fp, "%s\n", buf); - } while (strcmp(buf, "000")); + client_gets(&ibuf); + if (strcmp(ibuf, "000")) + fprintf(fp, "%s\n", ibuf); + } while (strcmp(ibuf, "000")); fclose(fp); /* now update the room index so people will see our new info */ diff --git a/citadel/serv_bio.c b/citadel/serv_bio.c index 18bf3b920..513d0b3c3 100644 --- a/citadel/serv_bio.c +++ b/citadel/serv_bio.c @@ -42,7 +42,8 @@ * enter user bio */ void cmd_ebio(char *cmdbuf) { - char buf[SIZ]; + char cbuf[SIZ]; + char *ibuf; FILE *fp; if (!(CC->logged_in)) { @@ -50,15 +51,15 @@ void cmd_ebio(char *cmdbuf) { return; } - sprintf(buf,"./bio/%ld",CC->usersupp.usernum); - fp = fopen(buf,"w"); + sprintf(cbuf,"./bio/%ld",CC->usersupp.usernum); + fp = fopen(cbuf,"w"); if (fp == NULL) { cprintf("%d Cannot create file\n",ERROR); return; } cprintf("%d \n",SEND_LISTING); - while(client_gets(buf), strcmp(buf,"000")) { - fprintf(fp,"%s\n",buf); + while(client_gets(&ibuf), strcmp(ibuf,"000")) { + fprintf(fp,"%s\n",ibuf); } fclose(fp); } diff --git a/citadel/serv_chat.c b/citadel/serv_chat.c index 03473dd97..4be79b1f1 100644 --- a/citadel/serv_chat.c +++ b/citadel/serv_chat.c @@ -613,6 +613,7 @@ void cmd_sexp(char *argbuf) char x_msg[SIZ]; char *lun; /* */ char *x_big_msgbuf = NULL; + char *ix_msg; if ((!(CC->logged_in)) && (!(CC->internal_pgm))) { cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN); @@ -649,13 +650,13 @@ void cmd_sexp(char *argbuf) SEND_LISTING, message_sent); x_big_msgbuf = mallok(SIZ); memset(x_big_msgbuf, 0, SIZ); - while (client_gets(x_msg), strcmp(x_msg, "000")) { + while (client_gets(&ix_msg), strcmp(ix_msg, "000")) { x_big_msgbuf = reallok(x_big_msgbuf, - strlen(x_big_msgbuf) + strlen(x_msg) + 4); + strlen(x_big_msgbuf) + strlen(ix_msg) + 4); if (strlen(x_big_msgbuf) > 0) if (x_big_msgbuf[strlen(x_big_msgbuf)] != '\n') strcat(x_big_msgbuf, "\n"); - strcat(x_big_msgbuf, x_msg); + strcat(x_big_msgbuf, ix_msg); } PerformXmsgHooks(lun, x_user, x_big_msgbuf); phree(x_big_msgbuf); diff --git a/citadel/serv_imap.c b/citadel/serv_imap.c index 341f96703..ff90b82d3 100644 --- a/citadel/serv_imap.c +++ b/citadel/serv_imap.c @@ -613,34 +613,37 @@ void imap_status(int num_parms, char *parms[]) { * Main command loop for IMAP sessions. */ void imap_command_loop(void) { - char cmdbuf[SIZ]; + char *icmdbuf; char *parms[SIZ]; int num_parms; time(&CC->lastcmd); - memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */ - if (client_gets(cmdbuf) < 1) { + if (client_gets(&icmdbuf) < 1) { lprintf(3, "IMAP socket is broken. Ending session.\r\n"); CC->kill_me = 1; return; } - lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, cmdbuf); - while (strlen(cmdbuf) < 5) strcat(cmdbuf, " "); + lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, icmdbuf); + while (strlen(icmdbuf) < 5) strcat(icmdbuf, " "); /* strip off l/t whitespace and CRLF */ - if (cmdbuf[strlen(cmdbuf)-1]=='\n') cmdbuf[strlen(cmdbuf)-1]=0; - if (cmdbuf[strlen(cmdbuf)-1]=='\r') cmdbuf[strlen(cmdbuf)-1]=0; - striplt(cmdbuf); + if (icmdbuf[strlen(icmdbuf)-1]=='\n') icmdbuf[strlen(icmdbuf)-1]=0; + if (icmdbuf[strlen(icmdbuf)-1]=='\r') icmdbuf[strlen(icmdbuf)-1]=0; + striplt(icmdbuf); /* If we're in the middle of a multi-line command, handle that */ if (IMAP->authstate == imap_as_expecting_username) { - imap_auth_login_user(cmdbuf); + if (strlen(icmdbuf) >= SIZ) /* I'm going to impose some kinda limit here */ + *(icmdbuf+SIZ) = '\0'; /* because ialu uses SIZ */ + imap_auth_login_user(icmdbuf); return; } if (IMAP->authstate == imap_as_expecting_password) { - imap_auth_login_pass(cmdbuf); + if (strlen(icmdbuf) >= SIZ) + *(icmdbuf+SIZ) = '\0'; + imap_auth_login_pass(icmdbuf); return; } @@ -660,7 +663,7 @@ void imap_command_loop(void) { /* Now for the command set. */ /* Grab the tag, command, and parameters. Check syntax. */ - num_parms = imap_parameterize(parms, cmdbuf); + num_parms = imap_parameterize(parms, icmdbuf); if (num_parms < 2) { cprintf("BAD syntax error\r\n"); } diff --git a/citadel/serv_network.c b/citadel/serv_network.c index 9f7382bb2..d5cdc5d7a 100644 --- a/citadel/serv_network.c +++ b/citadel/serv_network.c @@ -65,7 +65,8 @@ void cmd_gnet(char *argbuf) { void cmd_snet(char *argbuf) { char tempfilename[SIZ]; char filename[SIZ]; - char buf[SIZ]; + char cbuf[SIZ]; + char *ibuf; FILE *fp; if (CtdlAccessCheck(ac_room_aide)) return; @@ -81,8 +82,8 @@ void cmd_snet(char *argbuf) { } cprintf("%d %s\n", SEND_LISTING, tempfilename); - while (client_gets(buf), strcmp(buf, "000")) { - fprintf(fp, "%s\n", buf); + while (client_gets(&ibuf), strcmp(ibuf, "000")) { + fprintf(fp, "%s\n", ibuf); } fclose(fp); @@ -91,8 +92,8 @@ void cmd_snet(char *argbuf) { * different filesystems) */ unlink(filename); - snprintf(buf, sizeof buf, "/bin/mv %s %s", tempfilename, filename); - system(buf); + snprintf(cbuf, sizeof cbuf, "/bin/mv %s %s", tempfilename, filename); + system(cbuf); } diff --git a/citadel/serv_pop3.c b/citadel/serv_pop3.c index df53f197f..229e42cf0 100644 --- a/citadel/serv_pop3.c +++ b/citadel/serv_pop3.c @@ -525,76 +525,75 @@ void pop3_uidl(char *argbuf) { * Main command loop for POP3 sessions. */ void pop3_command_loop(void) { - char cmdbuf[SIZ]; + char *icmdbuf; time(&CC->lastcmd); - memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */ - if (client_gets(cmdbuf) < 1) { + if (client_gets(&icmdbuf) < 1) { lprintf(3, "POP3 socket is broken. Ending session.\r\n"); CC->kill_me = 1; return; } - lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, cmdbuf); - while (strlen(cmdbuf) < 5) strcat(cmdbuf, " "); + lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, icmdbuf); + while (strlen(icmdbuf) < 5) strcat(icmdbuf, " "); - if (!strncasecmp(cmdbuf, "NOOP", 4)) { + if (!strncasecmp(icmdbuf, "NOOP", 4)) { cprintf("+OK No operation.\r\n"); } - else if (!strncasecmp(cmdbuf, "QUIT", 4)) { + else if (!strncasecmp(icmdbuf, "QUIT", 4)) { cprintf("+OK Goodbye...\r\n"); pop3_update(); CC->kill_me = 1; return; } - else if (!strncasecmp(cmdbuf, "USER", 4)) { - pop3_user(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "USER", 4)) { + pop3_user(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "PASS", 4)) { - pop3_pass(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "PASS", 4)) { + pop3_pass(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "APOP", 4)) + else if (!strncasecmp(icmdbuf, "APOP", 4)) { - pop3_apop(&cmdbuf[5]); + pop3_apop(&icmdbuf[5]); } else if (!CC->logged_in) { cprintf("-ERR Not logged in.\r\n"); } - else if (!strncasecmp(cmdbuf, "LIST", 4)) { - pop3_list(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "LIST", 4)) { + pop3_list(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "STAT", 4)) { - pop3_stat(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "STAT", 4)) { + pop3_stat(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "RETR", 4)) { - pop3_retr(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "RETR", 4)) { + pop3_retr(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "DELE", 4)) { - pop3_dele(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "DELE", 4)) { + pop3_dele(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "RSET", 4)) { - pop3_rset(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "RSET", 4)) { + pop3_rset(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "UIDL", 4)) { - pop3_uidl(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "UIDL", 4)) { + pop3_uidl(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "TOP", 3)) { - pop3_top(&cmdbuf[4]); + else if (!strncasecmp(icmdbuf, "TOP", 3)) { + pop3_top(&icmdbuf[4]); } - else if (!strncasecmp(cmdbuf, "LAST", 4)) { - pop3_last(&cmdbuf[4]); + else if (!strncasecmp(icmdbuf, "LAST", 4)) { + pop3_last(&icmdbuf[4]); } else { diff --git a/citadel/serv_smtp.c b/citadel/serv_smtp.c index 1e54b7f07..41ea53757 100644 --- a/citadel/serv_smtp.c +++ b/citadel/serv_smtp.c @@ -688,74 +688,76 @@ void smtp_data(void) { * Main command loop for SMTP sessions. */ void smtp_command_loop(void) { - char cmdbuf[SIZ]; + char *icmdbuf; time(&CC->lastcmd); - memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */ - if (client_gets(cmdbuf) < 1) { + if (client_gets(&icmdbuf) < 1) { lprintf(3, "SMTP socket is broken. Ending session.\n"); CC->kill_me = 1; return; } - lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, cmdbuf); - while (strlen(cmdbuf) < 5) strcat(cmdbuf, " "); + /* Rather than fix the dynamic buffer a zillion places in here... */ + if (strlen(icmdbuf) >= SIZ) + *(icmdbuf+SIZ)= '\0'; /* no SMTP command should be this big */ + lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, icmdbuf); + while (strlen(icmdbuf) < 5) strcat(icmdbuf, " "); if (SMTP->command_state == smtp_user) { - smtp_get_user(cmdbuf); + smtp_get_user(icmdbuf); } else if (SMTP->command_state == smtp_password) { - smtp_get_pass(cmdbuf); + smtp_get_pass(icmdbuf); } - else if (!strncasecmp(cmdbuf, "AUTH", 4)) { - smtp_auth(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "AUTH", 4)) { + smtp_auth(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "DATA", 4)) { + else if (!strncasecmp(icmdbuf, "DATA", 4)) { smtp_data(); } - else if (!strncasecmp(cmdbuf, "EHLO", 4)) { - smtp_hello(&cmdbuf[5], 1); + else if (!strncasecmp(icmdbuf, "EHLO", 4)) { + smtp_hello(&icmdbuf[5], 1); } - else if (!strncasecmp(cmdbuf, "EXPN", 4)) { - smtp_expn(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "EXPN", 4)) { + smtp_expn(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "HELO", 4)) { - smtp_hello(&cmdbuf[5], 0); + else if (!strncasecmp(icmdbuf, "HELO", 4)) { + smtp_hello(&icmdbuf[5], 0); } - else if (!strncasecmp(cmdbuf, "HELP", 4)) { + else if (!strncasecmp(icmdbuf, "HELP", 4)) { smtp_help(); } - else if (!strncasecmp(cmdbuf, "MAIL", 4)) { - smtp_mail(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "MAIL", 4)) { + smtp_mail(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "NOOP", 4)) { + else if (!strncasecmp(icmdbuf, "NOOP", 4)) { cprintf("250 This command successfully did nothing.\r\n"); } - else if (!strncasecmp(cmdbuf, "QUIT", 4)) { + else if (!strncasecmp(icmdbuf, "QUIT", 4)) { cprintf("221 Goodbye...\r\n"); CC->kill_me = 1; return; } - else if (!strncasecmp(cmdbuf, "RCPT", 4)) { - smtp_rcpt(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "RCPT", 4)) { + smtp_rcpt(&icmdbuf[5]); } - else if (!strncasecmp(cmdbuf, "RSET", 4)) { + else if (!strncasecmp(icmdbuf, "RSET", 4)) { smtp_rset(); } - else if (!strncasecmp(cmdbuf, "VRFY", 4)) { - smtp_vrfy(&cmdbuf[5]); + else if (!strncasecmp(icmdbuf, "VRFY", 4)) { + smtp_vrfy(&icmdbuf[5]); } else { diff --git a/citadel/serv_vandelay.c b/citadel/serv_vandelay.c index f54e9d704..897bdb5a5 100644 --- a/citadel/serv_vandelay.c +++ b/citadel/serv_vandelay.c @@ -291,45 +291,45 @@ void artv_do_export(void) { void artv_import_config(void) { - char buf[SIZ]; + char *ibuf; lprintf(9, "Importing config file\n"); - client_gets(config.c_nodename); + client_gets(&ibuf); strcpy(config.c_nodename, ibuf); lprintf(9, "c_nodename = %s\n", config.c_nodename); - client_gets(config.c_fqdn); - client_gets(config.c_humannode); - client_gets(config.c_phonenum); - client_gets(buf); config.c_bbsuid = atoi(buf); - client_gets(buf); config.c_creataide = atoi(buf); - client_gets(buf); config.c_sleeping = atoi(buf); - client_gets(buf); config.c_initax = atoi(buf); - client_gets(buf); config.c_regiscall = atoi(buf); - client_gets(buf); config.c_twitdetect = atoi(buf); - client_gets(config.c_twitroom); - client_gets(config.c_moreprompt); - client_gets(buf); config.c_restrict = atoi(buf); - client_gets(buf); config.c_msgbase = atol(buf); - client_gets(config.c_bbs_city); - client_gets(config.c_sysadm); + client_gets(&ibuf); strcpy (config.c_fqdn, ibuf); + client_gets(&ibuf); strcpy (config.c_humannode, ibuf); + client_gets(&ibuf); strcpy (config.c_phonenum, ibuf); + client_gets(&ibuf); config.c_bbsuid = atoi(ibuf); + client_gets(&ibuf); config.c_creataide = atoi(ibuf); + client_gets(&ibuf); config.c_sleeping = atoi(ibuf); + client_gets(&ibuf); config.c_initax = atoi(ibuf); + client_gets(&ibuf); config.c_regiscall = atoi(ibuf); + client_gets(&ibuf); config.c_twitdetect = atoi(ibuf); + client_gets(&ibuf); strcpy(config.c_twitroom, ibuf); + client_gets(&ibuf); strcpy(config.c_moreprompt, ibuf); + client_gets(&ibuf); config.c_restrict = atoi(ibuf); + client_gets(&ibuf); config.c_msgbase = atol(ibuf); + client_gets(&ibuf); strcpy(config.c_bbs_city, ibuf); + client_gets(&ibuf); strcpy(config.c_sysadm, ibuf); lprintf(9, "c_sysadm = %s\n", config.c_sysadm); - client_gets(config.c_bucket_dir); - client_gets(buf); config.c_setup_level = atoi(buf); - client_gets(buf); config.c_maxsessions = atoi(buf); - client_gets(config.c_net_password); - client_gets(buf); config.c_port_number = atoi(buf); - client_gets(buf); config.c_ipgm_secret = atoi(buf); - client_gets(buf); config.c_ep.expire_mode = atoi(buf); - client_gets(buf); config.c_ep.expire_value = atoi(buf); - client_gets(buf); config.c_userpurge = atoi(buf); - client_gets(buf); config.c_roompurge = atoi(buf); - client_gets(config.c_logpages); - client_gets(buf); config.c_createax = atoi(buf); - client_gets(buf); config.c_maxmsglen = atol(buf); - client_gets(buf); config.c_min_workers = atoi(buf); - client_gets(buf); config.c_max_workers = atoi(buf); - client_gets(buf); config.c_pop3_port = atoi(buf); - client_gets(buf); config.c_smtp_port = atoi(buf); - client_gets(buf); config.c_default_filter = atoi(buf); + client_gets(&ibuf); strcpy(config.c_bucket_dir, ibuf); + client_gets(&ibuf); config.c_setup_level = atoi(ibuf); + client_gets(&ibuf); config.c_maxsessions = atoi(ibuf); + client_gets(&ibuf); strcpy(config.c_net_password, ibuf); + client_gets(&ibuf); config.c_port_number = atoi(ibuf); + client_gets(&ibuf); config.c_ipgm_secret = atoi(ibuf); + client_gets(&ibuf); config.c_ep.expire_mode = atoi(ibuf); + client_gets(&ibuf); config.c_ep.expire_value = atoi(ibuf); + client_gets(&ibuf); config.c_userpurge = atoi(ibuf); + client_gets(&ibuf); config.c_roompurge = atoi(ibuf); + client_gets(&ibuf); strcpy(config.c_logpages, ibuf); + client_gets(&ibuf); config.c_createax = atoi(ibuf); + client_gets(&ibuf); config.c_maxmsglen = atol(ibuf); + client_gets(&ibuf); config.c_min_workers = atoi(ibuf); + client_gets(&ibuf); config.c_max_workers = atoi(ibuf); + client_gets(&ibuf); config.c_pop3_port = atoi(ibuf); + client_gets(&ibuf); config.c_smtp_port = atoi(ibuf); + client_gets(&ibuf); config.c_default_filter = atoi(ibuf); put_config(); lprintf(7, "Imported config file\n"); } @@ -337,67 +337,67 @@ void artv_import_config(void) { void artv_import_control(void) { - char buf[SIZ]; + char *ibuf; lprintf(9, "Importing control file\n"); - client_gets(buf); CitControl.MMhighest = atol(buf); - client_gets(buf); CitControl.MMflags = atoi(buf); - client_gets(buf); CitControl.MMnextuser = atol(buf); - client_gets(buf); CitControl.MMnextroom = atol(buf); - client_gets(buf); CitControl.version = atoi(buf); + client_gets(&ibuf); CitControl.MMhighest = atol(ibuf); + client_gets(&ibuf); CitControl.MMflags = atoi(ibuf); + client_gets(&ibuf); CitControl.MMnextuser = atol(ibuf); + client_gets(&ibuf); CitControl.MMnextroom = atol(ibuf); + client_gets(&ibuf); CitControl.version = atoi(ibuf); put_control(); lprintf(7, "Imported control file\n"); } void artv_import_user(void) { - char buf[SIZ]; + char *ibuf; struct usersupp usbuf; - client_gets(buf); usbuf.version = atoi(buf); - client_gets(buf); usbuf.uid = atoi(buf); - client_gets(usbuf.password); - client_gets(buf); usbuf.flags = atoi(buf); - client_gets(buf); usbuf.timescalled = atol(buf); - client_gets(buf); usbuf.posted = atol(buf); - client_gets(buf); usbuf.axlevel = atoi(buf); - client_gets(buf); usbuf.usernum = atol(buf); - client_gets(buf); usbuf.lastcall = atol(buf); - client_gets(buf); usbuf.USuserpurge = atoi(buf); - client_gets(usbuf.fullname); - client_gets(buf); usbuf.USscreenwidth = atoi(buf); - client_gets(buf); usbuf.USscreenheight = atoi(buf); - client_gets(buf); usbuf.moderation_filter = atoi(buf); + client_gets(&ibuf); usbuf.version = atoi(ibuf); + client_gets(&ibuf); usbuf.uid = atoi(ibuf); + client_gets(&ibuf); strcpy(usbuf.password, ibuf); + client_gets(&ibuf); usbuf.flags = atoi(ibuf); + client_gets(&ibuf); usbuf.timescalled = atol(ibuf); + client_gets(&ibuf); usbuf.posted = atol(ibuf); + client_gets(&ibuf); usbuf.axlevel = atoi(ibuf); + client_gets(&ibuf); usbuf.usernum = atol(ibuf); + client_gets(&ibuf); usbuf.lastcall = atol(ibuf); + client_gets(&ibuf); usbuf.USuserpurge = atoi(ibuf); + client_gets(&ibuf); strcpy(usbuf.fullname, ibuf); + client_gets(&ibuf); usbuf.USscreenwidth = atoi(ibuf); + client_gets(&ibuf); usbuf.USscreenheight = atoi(ibuf); + client_gets(&ibuf); usbuf.moderation_filter = atoi(ibuf); putuser(&usbuf); } void artv_import_room(void) { - char buf[SIZ]; + char *ibuf; struct quickroom qrbuf; long msgnum; int msgcount = 0; - client_gets(qrbuf.QRname); - client_gets(qrbuf.QRpasswd); - client_gets(buf); qrbuf.QRroomaide = atol(buf); - client_gets(buf); qrbuf.QRhighest = atol(buf); - client_gets(buf); qrbuf.QRgen = atol(buf); - client_gets(buf); qrbuf.QRflags = atoi(buf); - client_gets(qrbuf.QRdirname); - client_gets(buf); qrbuf.QRinfo = atol(buf); - client_gets(buf); qrbuf.QRfloor = atoi(buf); - client_gets(buf); qrbuf.QRmtime = atol(buf); - client_gets(buf); qrbuf.QRep.expire_mode = atoi(buf); - client_gets(buf); qrbuf.QRep.expire_value = atoi(buf); - client_gets(buf); qrbuf.QRnumber = atol(buf); - client_gets(buf); qrbuf.QRorder = atoi(buf); + client_gets(&ibuf); strcpy(qrbuf.QRname, ibuf); + client_gets(&ibuf); strcpy(qrbuf.QRpasswd, ibuf); + client_gets(&ibuf); qrbuf.QRroomaide = atol(ibuf); + client_gets(&ibuf); qrbuf.QRhighest = atol(ibuf); + client_gets(&ibuf); qrbuf.QRgen = atol(ibuf); + client_gets(&ibuf); qrbuf.QRflags = atoi(ibuf); + client_gets(&ibuf); strcpy(qrbuf.QRdirname, ibuf); + client_gets(&ibuf); qrbuf.QRinfo = atol(ibuf); + client_gets(&ibuf); qrbuf.QRfloor = atoi(ibuf); + client_gets(&ibuf); qrbuf.QRmtime = atol(ibuf); + client_gets(&ibuf); qrbuf.QRep.expire_mode = atoi(ibuf); + client_gets(&ibuf); qrbuf.QRep.expire_value = atoi(ibuf); + client_gets(&ibuf); qrbuf.QRnumber = atol(ibuf); + client_gets(&ibuf); qrbuf.QRorder = atoi(ibuf); putroom(&qrbuf); lprintf(7, "Imported room <%s>\n", qrbuf.QRname); /* format of message list export is all message numbers output * one per line terminated by a 0. */ - while (client_gets(buf), msgnum = atol(buf), msgnum > 0) { + while (client_gets(&ibuf), msgnum = atol(ibuf), msgnum > 0) { CtdlSaveMsgPointerInRoom(qrbuf.QRname, msgnum, 0); ++msgcount; } @@ -408,14 +408,14 @@ void artv_import_room(void) { void artv_import_floor(void) { struct floor flbuf; int i; - char buf[SIZ]; - - client_gets(buf); i = atoi(buf); - client_gets(buf); flbuf.f_flags = atoi(buf); - client_gets(flbuf.f_name); - client_gets(buf); flbuf.f_ref_count = atoi(buf); - client_gets(buf); flbuf.f_ep.expire_mode = atoi(buf); - client_gets(buf); flbuf.f_ep.expire_value = atoi(buf); + char *ibuf; + + client_gets(&ibuf); i = atoi(ibuf); + client_gets(&ibuf); flbuf.f_flags = atoi(ibuf); + client_gets(&ibuf); strcpy(flbuf.f_name, ibuf); + client_gets(&ibuf); flbuf.f_ref_count = atoi(ibuf); + client_gets(&ibuf); flbuf.f_ep.expire_mode = atoi(ibuf); + client_gets(&ibuf); flbuf.f_ep.expire_value = atoi(ibuf); putfloor(&flbuf, i); lprintf(7, "Imported floor #%d (%s)\n", i, flbuf.f_name); } @@ -425,13 +425,13 @@ void artv_import_floor(void) { */ void artv_import_visit(void) { struct visit vbuf; - char buf[SIZ]; + char *ibuf; - client_gets(buf); vbuf.v_roomnum = atol(buf); - client_gets(buf); vbuf.v_roomgen = atol(buf); - client_gets(buf); vbuf.v_usernum = atol(buf); - client_gets(buf); vbuf.v_lastseen = atol(buf); - client_gets(buf); vbuf.v_flags = atoi(buf); + client_gets(&ibuf); vbuf.v_roomnum = atol(ibuf); + client_gets(&ibuf); vbuf.v_roomgen = atol(ibuf); + client_gets(&ibuf); vbuf.v_usernum = atol(ibuf); + client_gets(&ibuf); vbuf.v_lastseen = atol(ibuf); + client_gets(&ibuf); vbuf.v_flags = atoi(ibuf); put_visit(&vbuf); lprintf(7, "Imported visit %ld/%ld/%ld\n", vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum); @@ -444,16 +444,17 @@ void artv_import_message(void) { long msgnum; int msglen; FILE *fp; + char *ibuf; char buf[SIZ]; char tempfile[SIZ]; char *mbuf; memset(&smi, 0, sizeof(struct SuppMsgInfo)); - client_gets(buf); msgnum = atol(buf); + client_gets(&ibuf); msgnum = atol(ibuf); smi.smi_msgnum = msgnum; - client_gets(buf); smi.smi_refcount = atoi(buf); - client_gets(smi.smi_content_type); - client_gets(buf); smi.smi_mod = atoi(buf); + client_gets(&ibuf); smi.smi_refcount = atoi(ibuf); + client_gets(&ibuf); strcpy(smi.smi_content_type, ibuf); + client_gets(&ibuf); smi.smi_mod = atoi(ibuf); lprintf(7, "message #%ld\n", msgnum); @@ -461,7 +462,7 @@ void artv_import_message(void) { strcpy(tempfile, tmpnam(NULL)); sprintf(buf, "./base64 -d >%s", tempfile); fp = popen(buf, "w"); - while (client_gets(buf), strcasecmp(buf, END_OF_MESSAGE)) { + while (client_gets(&ibuf), strcasecmp(ibuf, END_OF_MESSAGE)) { fprintf(fp, "%s\n", buf); } fclose(fp); @@ -489,41 +490,41 @@ void artv_import_message(void) { void artv_do_import(void) { - char buf[SIZ]; - char s_version[SIZ]; + char *ibuf; + char *is_version; int version; cprintf("%d sock it to me\n", SEND_LISTING); - while (client_gets(buf), strcmp(buf, "000")) { + while (client_gets(&ibuf), strcmp(ibuf, "000")) { - lprintf(9, "import keyword: <%s>\n", buf); + lprintf(9, "import keyword: <%s>\n", ibuf); - if (!strcasecmp(buf, "version")) { - client_gets(s_version); - version = atoi(s_version); + if (!strcasecmp(ibuf, "version")) { + client_gets(&is_version); + version = atoi(is_version); if ((version < REV_MIN) || (version > REV_LEVEL)) { lprintf(7, "Version mismatch - aborting\n"); break; } } - else if (!strcasecmp(buf, "config")) artv_import_config(); - else if (!strcasecmp(buf, "control")) artv_import_control(); - else if (!strcasecmp(buf, "user")) artv_import_user(); - else if (!strcasecmp(buf, "room")) artv_import_room(); - else if (!strcasecmp(buf, "floor")) artv_import_floor(); - else if (!strcasecmp(buf, "visit")) artv_import_visit(); - else if (!strcasecmp(buf, "message")) artv_import_message(); + else if (!strcasecmp(ibuf, "config")) artv_import_config(); + else if (!strcasecmp(ibuf, "control")) artv_import_control(); + else if (!strcasecmp(ibuf, "user")) artv_import_user(); + else if (!strcasecmp(ibuf, "room")) artv_import_room(); + else if (!strcasecmp(ibuf, "floor")) artv_import_floor(); + else if (!strcasecmp(ibuf, "visit")) artv_import_visit(); + else if (!strcasecmp(ibuf, "message")) artv_import_message(); else break; } - lprintf(7, "Invalid keyword <%s>. Flushing input.\n", buf); - while (client_gets(buf), strcmp(buf, "000")) ;; + lprintf(7, "Invalid keyword <%s>. Flushing input.\n", ibuf); + while (client_gets(&ibuf), strcmp(ibuf, "000")) ;; } void cmd_artv(char *cmdbuf) { - char cmd[SIZ]; + char cmd[SIZ]; static int is_running = 0; if (CtdlAccessCheck(ac_aide)) return; /* FIXME should be intpgm */ @@ -537,7 +538,7 @@ void cmd_artv(char *cmdbuf) { strcpy(artv_tempfilename1, tmpnam(NULL)); strcpy(artv_tempfilename2, tmpnam(NULL)); - extract(cmd, cmdbuf, 0); + extract(cmd, cmdbuf, 0); /* this is limited to SIZ */ if (!strcasecmp(cmd, "export")) artv_do_export(); else if (!strcasecmp(cmd, "import")) artv_do_import(); else cprintf("%d illegal command\n", ERROR); diff --git a/citadel/serv_vcard.c b/citadel/serv_vcard.c index 07d93c6f7..01fe7ea2f 100644 --- a/citadel/serv_vcard.c +++ b/citadel/serv_vcard.c @@ -276,7 +276,7 @@ void vcard_write_user(struct usersupp *u, struct vCard *v) { */ void cmd_regi(char *argbuf) { int a,b,c; - char buf[SIZ]; + char *ibuf; struct vCard *my_vcard; char tmpaddr[SIZ]; @@ -300,23 +300,23 @@ void cmd_regi(char *argbuf) { cprintf("%d Send registration...\n", SEND_LISTING); a=0; - while (client_gets(buf), strcmp(buf,"000")) { - if (a==0) vcard_set_prop(my_vcard, "n", buf); - if (a==1) strcpy(tmpaddr,buf); - if (a==2) strcpy(tmpcity,buf); - if (a==3) strcpy(tmpstate,buf); + while (client_gets(&ibuf), strcmp(ibuf,"000")) { + if (a==0) vcard_set_prop(my_vcard, "n", ibuf); + if (a==1) strcpy(tmpaddr,ibuf); + if (a==2) strcpy(tmpcity,ibuf); + if (a==3) strcpy(tmpstate,ibuf); if (a==4) { - for (c=0; c='0')&&(buf[c]<='9')) { + for (c=0; c='0')&&(ibuf[c]<='9')) { b=strlen(tmpzip); - tmpzip[b]=buf[c]; + tmpzip[b]=ibuf[c]; tmpzip[b+1]=0; } } } - if (a==5) vcard_set_prop(my_vcard, "tel;home", buf); - if (a==6) vcard_set_prop(my_vcard, "email;internet", buf); - if (a==7) strcpy(tmpcountry, buf); + if (a==5) vcard_set_prop(my_vcard, "tel;home", ibuf); + if (a==6) vcard_set_prop(my_vcard, "email;internet", ibuf); + if (a==7) strcpy(tmpcountry, ibuf); ++a; } sprintf(tmpaddress, ";;%s;%s;%s;%s;%s", diff --git a/citadel/server.h b/citadel/server.h index 33ceef4a4..803e5b72e 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -109,6 +109,10 @@ struct CitContext { char fake_hostname[25]; /* Fake hostname */ char fake_roomname[ROOMNAMELEN]; /* Fake roomname */ + /* Dynamic input buffer size. stu 2/7/2001 */ + char *readbuf; + long readbuf_alloc; + /* Dynamically allocated session data */ struct CtdlSessData *FirstSessData; }; diff --git a/citadel/sysdep.c b/citadel/sysdep.c index cc40a208e..ad9d0f820 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -89,10 +89,37 @@ static pthread_t initial_thread; /* tid for main() thread */ * Note: the variable "buf" below needs to be large enough to handle any * log data sent through this function. BE CAREFUL! */ + +static int /* I stole this from snprintf.c because it might not get configed in */ +neededalso (const char *fmt, va_list argp) +{ + static FILE *sink = NULL; + + /* ok, there's a small race here that could result in the sink being + * opened more than once if we're threaded, but I'd rather ignore it than + * spend cycles synchronizing :-) */ + + if (sink == NULL) + { + if ((sink = fopen("/dev/null", "w")) == NULL) + { + perror("/dev/null"); + exit(1); + } + } + + return vfprintf(sink, fmt, argp); +} + void lprintf(int loglevel, const char *format, ...) { va_list arg_ptr; - char buf[4096]; + char *buf; + /* stu We'll worry about speed later if it's a problem. */ + va_start(arg_ptr, format); + buf = mallok(neededalso(format, arg_ptr)+1); + va_end(arg_ptr); + va_start(arg_ptr, format); vsprintf(buf, format, arg_ptr); va_end(arg_ptr); @@ -116,23 +143,76 @@ void lprintf(int loglevel, const char *format, ...) { } PerformLogHooks(loglevel, buf); + phree(buf); } #ifdef DEBUG_MEMORY_LEAKS + +/* These functions presume a long is 32 bits. */ + +void *getmem (long m) + { + /* must zero out data */ + char *z; + char *zf; + + z = malloc(m+8); /* make room for size and "CITX" */ + zf = z + m+6; + + /* store check info */ + memcpy (z, &m, 4); /* copy the long in */ + memcpy (z+m+4, "CITX", 4); /* my over run check bytes */ + + return z + 4; + } + +void freemem (void *m) + { + /* check to see if we overran */ + long sz; + + memcpy (&sz, m-4, 4); /* get long back */ + + if (memcmp (m + sz, "CITX", 4) != 0) + { + lprintf(3, "DANGER! Memory overrun!\n", "", "", ""); + } + free(m - 4); // nobody tells me these things + } + +void *reallocmem(void *m, ULONG newsize) + { + /* check to see if we overran */ + ULONG sz; + char *ret; + + memcpy (&sz, m-4, 4); /* get long back */ + + if (memcmp (m + sz, "CITX", 4) != 0) + lprintf(3, "DANGER! Memory overrun!\n", "", "", ""); + + /* just like malloc */ + ret = (char *)realloc (m-4, newsize+8); + memcpy (ret, &newsize, 4); /* copy the long in */ + memcpy (ret + newsize + 4, "CITX", 4); /* my over run check bytes */ + + return (ret + 4); + } + void *tracked_malloc(size_t tsize, char *tfile, int tline) { void *ptr; struct TheHeap *hptr; - ptr = malloc(tsize); + ptr = getmem(tsize); /* stu, thought you might like this for debugging */ if (ptr == NULL) { lprintf(3, "DANGER! mallok(%d) at %s:%d failed!\n", tsize, tfile, tline); return(NULL); } - hptr = (struct TheHeap *) malloc(sizeof(struct TheHeap)); + hptr = (struct TheHeap *) getmem(sizeof(struct TheHeap)); strcpy(hptr->h_file, tfile); hptr->h_line = tline; hptr->next = heap; @@ -156,7 +236,7 @@ void tracked_free(void *ptr) { if (heap->h_ptr == ptr) { hptr = heap->next; - free(heap); + freemem(heap); heap = hptr; } else { @@ -164,19 +244,19 @@ void tracked_free(void *ptr) { if (hptr->next->h_ptr == ptr) { freeme = hptr->next; hptr->next = hptr->next->next; - free(freeme); + freemem(freeme); } } } - free(ptr); + freemem(ptr); } void *tracked_realloc(void *ptr, size_t size) { void *newptr; struct TheHeap *hptr; - newptr = realloc(ptr, size); + newptr = reallocmem(ptr, size); for (hptr=heap; hptr!=NULL; hptr=hptr->next) { if (hptr->h_ptr == ptr) hptr->h_ptr = newptr; @@ -545,7 +625,67 @@ int client_read(char *buf, int bytes) * (This is implemented in terms of client_read() and could be * justifiably moved out of sysdep.c) */ -int client_gets(char *buf) + +/* stu 2/7/2001. Rigging this to do dynamic allocating to recieve + random length commands. The memory is held by the session. The + pointer returned to the caller is for reading only for they do + not know how big it is. The context owns the buffer. Thus there + is one per session, gets cleaned up in remove_session or something + like that. Not going for killer speed here since this isn't really + a bottleneck function. */ + +int client_gets(char **retbuf) +{ + int i, retval; + + /* Read one character at a time. */ + char *b = CC->readbuf; + int sz = CC->readbuf_alloc; + if (b == NULL) /* first time in? */ + { + b = mallok(SIZ+1); /* start with something */ + sz = SIZ; + } + else + { + /* take this out if you prefer not wasting the time. */ + if (sz > (SIZ*2)) /* if it went up, don't put at min */ + { + b = reallok(b, SIZ*2+1); /* resize down */ + sz = SIZ*2; + } + } + *b = '\0'; /* in case we bail early */ + i = 0; + while (1) + { + retval = client_read(b+i, 1); + if (retval != 1 || b[i] == '\n') + break; + i++; + if (i >= sz) + { + sz *= 2; /* resize up */ + b = reallok(b, sz+1); + } + } + + /* Strip the trailing newline and any trailing nonprintables (cr's) */ + *(b+i) = '\0'; + while ((strlen(b)>0)&&(!isprint(*(b+strlen(b)-1)))) + *(b+strlen(b)-1) = '\0'; + if (retval < 0) + strcpy(b, "000"); + + CC->readbuf = b; /* faster if we do it once at the end */ + CC->readbuf_alloc = sz; + + + *retbuf = b; + return(retval); +} + +int oldclient_gets(char *buf) { int i, retval; diff --git a/citadel/sysdep_decls.h b/citadel/sysdep_decls.h index 1398f30b0..87784ce78 100644 --- a/citadel/sysdep_decls.h +++ b/citadel/sysdep_decls.h @@ -12,7 +12,7 @@ void client_write (char *buf, int nbytes); void cprintf (const char *format, ...); int client_read_to (char *buf, int bytes, int timeout); int client_read (char *buf, int bytes); -int client_gets (char *buf); +int client_gets (char **buf); void sysdep_master_cleanup (void); void kill_session (int session_to_kill); void *sd_context_loop (struct CitContext *con); diff --git a/citadel/tools.c b/citadel/tools.c index 4a5ee52c7..b2a88d927 100644 --- a/citadel/tools.c +++ b/citadel/tools.c @@ -75,6 +75,10 @@ void extract_token(char *dest, char *source, int parmnum, char separator) int len; int curr_parm; + /* Stu. Fixed this to deal with the possibility that somebody's + going to send a token bigger than SIZ, which is possible + with a bigger input buffer. */ + strcpy(dest,""); len = 0; curr_parm = 0; @@ -88,8 +92,10 @@ void extract_token(char *dest, char *source, int parmnum, char separator) ++curr_parm; } else if (curr_parm == parmnum) { - dest[len+1] = 0; - dest[len++] = source[i]; + if (len < SIZ) { /* stu 2/8/2001 */ + dest[len+1] = 0; + dest[len++] = source[i]; + } } } } -- 2.39.2