From ee853a68e6542a4cf3b880e75787a5931758ad59 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 28 Feb 2001 05:45:05 +0000 Subject: [PATCH] * Backed out the variable-length string changes. --- citadel/citserver.c | 318 ++++++++++++++++++++-------------------- citadel/control.c | 67 +++++---- citadel/imap_fetch.c | 36 ++--- citadel/imap_fetch.h | 1 - citadel/imap_search.c | 2 +- citadel/imap_store.c | 87 ++++------- citadel/msgbase.c | 32 ++-- citadel/room_ops.c | 10 +- citadel/serv_bio.c | 11 +- citadel/serv_chat.c | 7 +- citadel/serv_imap.c | 26 ++-- citadel/serv_imap.h | 6 +- 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 | 165 ++------------------- citadel/sysdep_decls.h | 2 +- citadel/tools.c | 10 +- 21 files changed, 473 insertions(+), 676 deletions(-) diff --git a/citadel/citserver.c b/citadel/citserver.c index 25f1eb0f2..d63c092cf 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -197,10 +197,6 @@ 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 */ @@ -523,7 +519,6 @@ void cmd_emsg(char *mname) FILE *mfp; char targ[SIZ]; char buf[SIZ]; - char *ibuf; char *dirs[2]; int a; @@ -554,8 +549,8 @@ void cmd_emsg(char *mname) } cprintf("%d %s\n", SEND_LISTING, targ); - while (client_gets(&ibuf), strcmp(ibuf, "000")) { - fprintf(mfp, "%s\n", ibuf); + while (client_gets(buf), strcmp(buf, "000")) { + fprintf(mfp, "%s\n", buf); } fclose(mfp); @@ -843,367 +838,366 @@ void citproto_begin_session() { * This loop recognizes all server commands. */ void do_command_loop(void) { -/* char cmdbuf[SIZ]; stu */ - char *icmdbuf; + char cmdbuf[SIZ]; time(&CC->lastcmd); -/* memset(cmdbuf, 0, sizeof cmdbuf); */ /* Clear it, just in case */ - if (client_gets(&icmdbuf) < 1) { + memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */ + if (client_gets(cmdbuf) < 1) { lprintf(3, "Client socket is broken. Ending session.\n"); CC->kill_me = 1; return; } - lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, icmdbuf); + lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, cmdbuf); /* * Let other clients see the last command we executed, and * update the idle time, but not NOOP, PEXP, or GEXP. */ - if ( (strncasecmp(icmdbuf, "NOOP", 4)) - && (strncasecmp(icmdbuf, "PEXP", 4)) - && (strncasecmp(icmdbuf, "GEXP", 4)) ) { + if ( (strncasecmp(cmdbuf, "NOOP", 4)) + && (strncasecmp(cmdbuf, "PEXP", 4)) + && (strncasecmp(cmdbuf, "GEXP", 4)) ) { strcpy(CC->lastcmdname, " "); - safestrncpy(CC->lastcmdname, icmdbuf, + safestrncpy(CC->lastcmdname, cmdbuf, sizeof(CC->lastcmdname) ); time(&CC->lastidle); } - if ((strncasecmp(icmdbuf, "ENT0", 4)) - && (strncasecmp(icmdbuf, "MESG", 4)) - && (strncasecmp(icmdbuf, "MSGS", 4))) + if ((strncasecmp(cmdbuf, "ENT0", 4)) + && (strncasecmp(cmdbuf, "MESG", 4)) + && (strncasecmp(cmdbuf, "MSGS", 4))) { CC->cs_flags &= ~CS_POSTING; } - if (!strncasecmp(icmdbuf,"NOOP",4)) { + if (!strncasecmp(cmdbuf,"NOOP",4)) { cprintf("%d%cok\n",OK,CtdlCheckExpress()); } - else if (!strncasecmp(icmdbuf,"QUIT",4)) { + else if (!strncasecmp(cmdbuf,"QUIT",4)) { cprintf("%d Goodbye.\n",OK); CC->kill_me = 1; } - else if (!strncasecmp(icmdbuf,"ASYN",4)) { - cmd_asyn(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"ASYN",4)) { + cmd_asyn(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"LOUT",4)) { + else if (!strncasecmp(cmdbuf,"LOUT",4)) { if (CC->logged_in) logout(CC); cprintf("%d logged out.\n",OK); } - else if (!strncasecmp(icmdbuf,"USER",4)) { - cmd_user(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"USER",4)) { + cmd_user(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"PASS",4)) { - cmd_pass(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"PASS",4)) { + cmd_pass(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"NEWU",4)) { - cmd_newu(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"NEWU",4)) { + cmd_newu(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"SETP",4)) { - cmd_setp(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"SETP",4)) { + cmd_setp(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"LRMS",4)) { - cmd_lrms(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"LRMS",4)) { + cmd_lrms(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"LKRA",4)) { - cmd_lkra(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"LKRA",4)) { + cmd_lkra(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"LKRN",4)) { - cmd_lkrn(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"LKRN",4)) { + cmd_lkrn(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"LKRO",4)) { - cmd_lkro(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"LKRO",4)) { + cmd_lkro(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"LZRM",4)) { - cmd_lzrm(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"LZRM",4)) { + cmd_lzrm(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"GETU",4)) { + else if (!strncasecmp(cmdbuf,"GETU",4)) { cmd_getu(); } - else if (!strncasecmp(icmdbuf,"SETU",4)) { - cmd_setu(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"SETU",4)) { + cmd_setu(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"GOTO",4)) { - cmd_goto(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"GOTO",4)) { + cmd_goto(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"MSGS",4)) { - cmd_msgs(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"MSGS",4)) { + cmd_msgs(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"WHOK",4)) { + else if (!strncasecmp(cmdbuf,"WHOK",4)) { cmd_whok(); } - else if (!strncasecmp(icmdbuf,"RDIR",4)) { + else if (!strncasecmp(cmdbuf,"RDIR",4)) { cmd_rdir(); } - else if (!strncasecmp(icmdbuf,"MSG0",4)) { - cmd_msg0(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"MSG0",4)) { + cmd_msg0(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"MSG2",4)) { - cmd_msg2(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"MSG2",4)) { + cmd_msg2(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"MSG3",4)) { - cmd_msg3(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"MSG3",4)) { + cmd_msg3(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"MSG4",4)) { - cmd_msg4(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"MSG4",4)) { + cmd_msg4(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"OPNA",4)) { - cmd_opna(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"OPNA",4)) { + cmd_opna(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"INFO",4)) { + else if (!strncasecmp(cmdbuf,"INFO",4)) { cmd_info(); } - else if (!strncasecmp(icmdbuf,"SLRP",4)) { - cmd_slrp(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"SLRP",4)) { + cmd_slrp(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"INVT",4)) { - cmd_invt_kick(&icmdbuf[5],1); + else if (!strncasecmp(cmdbuf,"INVT",4)) { + cmd_invt_kick(&cmdbuf[5],1); } - else if (!strncasecmp(icmdbuf,"KICK",4)) { - cmd_invt_kick(&icmdbuf[5],0); + else if (!strncasecmp(cmdbuf,"KICK",4)) { + cmd_invt_kick(&cmdbuf[5],0); } - else if (!strncasecmp(icmdbuf,"GETR",4)) { + else if (!strncasecmp(cmdbuf,"GETR",4)) { cmd_getr(); } - else if (!strncasecmp(icmdbuf,"SETR",4)) { - cmd_setr(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"SETR",4)) { + cmd_setr(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"GETA",4)) { + else if (!strncasecmp(cmdbuf,"GETA",4)) { cmd_geta(); } - else if (!strncasecmp(icmdbuf,"SETA",4)) { - cmd_seta(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"SETA",4)) { + cmd_seta(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"ENT0",4)) { - cmd_ent0(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"ENT0",4)) { + cmd_ent0(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"ENT3",4)) { - cmd_ent3(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"ENT3",4)) { + cmd_ent3(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"RINF",4)) { + else if (!strncasecmp(cmdbuf,"RINF",4)) { cmd_rinf(); } - else if (!strncasecmp(icmdbuf,"DELE",4)) { - cmd_dele(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"DELE",4)) { + cmd_dele(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"KILL",4)) { - cmd_kill(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"KILL",4)) { + cmd_kill(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"CRE8",4)) { - cmd_cre8(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"CRE8",4)) { + cmd_cre8(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"MOVE",4)) { - cmd_move(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"MOVE",4)) { + cmd_move(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"FORG",4)) { + else if (!strncasecmp(cmdbuf,"FORG",4)) { cmd_forg(); } - else if (!strncasecmp(icmdbuf,"MESG",4)) { - cmd_mesg(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"MESG",4)) { + cmd_mesg(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"EMSG",4)) { - cmd_emsg(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"EMSG",4)) { + cmd_emsg(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"GNUR",4)) { + else if (!strncasecmp(cmdbuf,"GNUR",4)) { cmd_gnur(); } - else if (!strncasecmp(icmdbuf,"VALI",4)) { - cmd_vali(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"VALI",4)) { + cmd_vali(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"EINF",4)) { - cmd_einf(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"EINF",4)) { + cmd_einf(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"LIST",4)) { + else if (!strncasecmp(cmdbuf,"LIST",4)) { cmd_list(); } - else if (!strncasecmp(icmdbuf,"CHEK",4)) { + else if (!strncasecmp(cmdbuf,"CHEK",4)) { cmd_chek(); } - else if (!strncasecmp(icmdbuf,"DELF",4)) { - cmd_delf(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"DELF",4)) { + cmd_delf(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"MOVF",4)) { - cmd_movf(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"MOVF",4)) { + cmd_movf(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"NETF",4)) { - cmd_netf(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"NETF",4)) { + cmd_netf(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"OPEN",4)) { - cmd_open(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"OPEN",4)) { + cmd_open(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"CLOS",4)) { + else if (!strncasecmp(cmdbuf,"CLOS",4)) { cmd_clos(); } - else if (!strncasecmp(icmdbuf,"UOPN",4)) { - cmd_uopn(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"UOPN",4)) { + cmd_uopn(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"UCLS",4)) { - cmd_ucls(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"UCLS",4)) { + cmd_ucls(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"READ",4)) { - cmd_read(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"READ",4)) { + cmd_read(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"WRIT",4)) { - cmd_writ(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"WRIT",4)) { + cmd_writ(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"QUSR",4)) { - cmd_qusr(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"QUSR",4)) { + cmd_qusr(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"ECHO",4)) { - cmd_echo(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"ECHO",4)) { + cmd_echo(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"OIMG",4)) { - cmd_oimg(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"OIMG",4)) { + cmd_oimg(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"MORE",4)) { + else if (!strncasecmp(cmdbuf,"MORE",4)) { cmd_more(); } - else if (!strncasecmp(icmdbuf,"NETP",4)) { - cmd_netp(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"NETP",4)) { + cmd_netp(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"NDOP",4)) { - cmd_ndop(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"NDOP",4)) { + cmd_ndop(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"NUOP",4)) { - cmd_nuop(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"NUOP",4)) { + cmd_nuop(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"LFLR",4)) { + else if (!strncasecmp(cmdbuf,"LFLR",4)) { cmd_lflr(); } - else if (!strncasecmp(icmdbuf,"CFLR",4)) { - cmd_cflr(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"CFLR",4)) { + cmd_cflr(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"KFLR",4)) { - cmd_kflr(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"KFLR",4)) { + cmd_kflr(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"EFLR",4)) { - cmd_eflr(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"EFLR",4)) { + cmd_eflr(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"IDEN",4)) { - cmd_iden(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"IDEN",4)) { + cmd_iden(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"IPGM",4)) { - cmd_ipgm(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"IPGM",4)) { + cmd_ipgm(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"TERM",4)) { - cmd_term(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"TERM",4)) { + cmd_term(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf,"DOWN",4)) { + else if (!strncasecmp(cmdbuf,"DOWN",4)) { cmd_down(); } - else if (!strncasecmp(icmdbuf,"SCDN",4)) { - cmd_scdn(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf,"SCDN",4)) { + cmd_scdn(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "NSET", 4)) { - cmd_nset(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "NSET", 4)) { + cmd_nset(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "UIMG", 4)) { - cmd_uimg(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "UIMG", 4)) { + cmd_uimg(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "TIME", 4)) { + else if (!strncasecmp(cmdbuf, "TIME", 4)) { cmd_time(); } - else if (!strncasecmp(icmdbuf, "AGUP", 4)) { - cmd_agup(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "AGUP", 4)) { + cmd_agup(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "ASUP", 4)) { - cmd_asup(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "ASUP", 4)) { + cmd_asup(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "GPEX", 4)) { - cmd_gpex(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "GPEX", 4)) { + cmd_gpex(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "SPEX", 4)) { - cmd_spex(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "SPEX", 4)) { + cmd_spex(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "CONF", 4)) { - cmd_conf(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "CONF", 4)) { + cmd_conf(&cmdbuf[5]); } #ifdef DEBUG_MEMORY_LEAKS - else if (!strncasecmp(icmdbuf, "LEAK", 4)) { + else if (!strncasecmp(cmdbuf, "LEAK", 4)) { dump_tracked(); } #endif - else if (!DLoader_Exec_Cmd(icmdbuf)) + else if (!DLoader_Exec_Cmd(cmdbuf)) { cprintf("%d Unrecognized or unsupported command.\n", ERROR); diff --git a/citadel/control.c b/citadel/control.c index 524a0e465..dd056611b 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 *ibuf; + char buf[SIZ]; int a; char *confptr; char confname[SIZ]; @@ -178,93 +178,92 @@ 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(&ibuf), strcmp(ibuf, "000")) { + while (client_gets(buf), strcmp(buf, "000")) { switch(a) { - case 0: safestrncpy(config.c_nodename, ibuf, + case 0: safestrncpy(config.c_nodename, buf, sizeof config.c_nodename); break; - case 1: safestrncpy(config.c_fqdn, ibuf, + case 1: safestrncpy(config.c_fqdn, buf, sizeof config.c_fqdn); break; - case 2: safestrncpy(config.c_humannode, ibuf, + case 2: safestrncpy(config.c_humannode, buf, sizeof config.c_humannode); break; - case 3: safestrncpy(config.c_phonenum, ibuf, + case 3: safestrncpy(config.c_phonenum, buf, sizeof config.c_phonenum); break; - case 4: config.c_creataide = atoi(ibuf); + case 4: config.c_creataide = atoi(buf); break; - case 5: config.c_sleeping = atoi(ibuf); + case 5: config.c_sleeping = atoi(buf); break; - case 6: config.c_initax = atoi(ibuf); + case 6: config.c_initax = atoi(buf); 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(ibuf); + case 7: config.c_regiscall = atoi(buf); if (config.c_regiscall != 0) config.c_regiscall = 1; break; - case 8: config.c_twitdetect = atoi(ibuf); + case 8: config.c_twitdetect = atoi(buf); if (config.c_twitdetect != 0) config.c_twitdetect = 1; break; - case 9: safestrncpy(config.c_twitroom, ibuf, + case 9: safestrncpy(config.c_twitroom, buf, sizeof config.c_twitroom); break; - case 10: safestrncpy(config.c_moreprompt, ibuf, + case 10: safestrncpy(config.c_moreprompt, buf, sizeof config.c_moreprompt); break; - case 11: config.c_restrict = atoi(ibuf); + case 11: config.c_restrict = atoi(buf); if (config.c_restrict != 0) config.c_restrict = 1; break; - case 12: safestrncpy(config.c_bbs_city, ibuf, + case 12: safestrncpy(config.c_bbs_city, buf, sizeof config.c_bbs_city); break; - case 13: safestrncpy(config.c_sysadm, ibuf, + case 13: safestrncpy(config.c_sysadm, buf, sizeof config.c_sysadm); break; - case 14: config.c_maxsessions = atoi(ibuf); + case 14: config.c_maxsessions = atoi(buf); if (config.c_maxsessions < 1) config.c_maxsessions = 1; break; - case 15: safestrncpy(config.c_net_password, ibuf, + case 15: safestrncpy(config.c_net_password, buf, sizeof config.c_net_password); break; - case 16: config.c_userpurge = atoi(ibuf); + case 16: config.c_userpurge = atoi(buf); break; - case 17: config.c_roompurge = atoi(ibuf); + case 17: config.c_roompurge = atoi(buf); break; - case 18: safestrncpy(config.c_logpages, ibuf, + case 18: safestrncpy(config.c_logpages, buf, sizeof config.c_logpages); break; - case 19: config.c_createax = atoi(ibuf); + case 19: config.c_createax = atoi(buf); if (config.c_createax < 1) config.c_createax = 1; if (config.c_createax > 6) config.c_createax = 6; break; - case 20: if (atoi(ibuf) >= 8192) - config.c_maxmsglen = atoi(ibuf); + case 20: if (atoi(buf) >= 8192) + config.c_maxmsglen = atoi(buf); break; - 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); + 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); break; - case 24: config.c_smtp_port = atoi(ibuf); + case 24: config.c_smtp_port = atoi(buf); break; - case 25: config.c_default_filter = atoi(ibuf); + case 25: config.c_default_filter = atoi(buf); break; - case 26: config.c_aide_zap = atoi(ibuf); + case 26: config.c_aide_zap = atoi(buf); if (config.c_aide_zap != 0) config.c_aide_zap = 1; break; - case 27: config.c_imap_port = atoi(ibuf); + case 27: config.c_imap_port = atoi(buf); break; } ++a; diff --git a/citadel/imap_fetch.c b/citadel/imap_fetch.c index cb306ba22..09a22bf15 100644 --- a/citadel/imap_fetch.c +++ b/citadel/imap_fetch.c @@ -49,20 +49,6 @@ struct imap_fetch_part { FILE *output_fp; }; - - -/* - * Output the flags associated with a message. Note that this function - * expects an index number in the array, *not* a sequence or uid number. - */ -void imap_output_flags(int num) { - cprintf("FLAGS ("); - if (IMAP->flags[num] & IMAP_DELETED) cprintf("\\Deleted"); - cprintf(")"); -} - - - /* * Individual field functions for imap_do_fetch_msg() ... */ @@ -73,6 +59,10 @@ void imap_fetch_uid(int seq) { cprintf("UID %ld", IMAP->msgids[seq-1]); } +void imap_fetch_flags(struct CtdlMessage *msg) { + cprintf("FLAGS ()"); /* FIXME do something here */ +} + void imap_fetch_internaldate(struct CtdlMessage *msg) { char buf[SIZ]; time_t msgdate; @@ -643,7 +633,7 @@ void imap_do_fetch_msg(int seq, struct CtdlMessage *msg, imap_fetch_envelope(IMAP->msgids[seq-1], msg); } else if (!strcasecmp(itemlist[i], "FLAGS")) { - imap_output_flags(seq-1); + imap_fetch_flags(msg); } else if (!strcasecmp(itemlist[i], "INTERNALDATE")) { imap_fetch_internaldate(msg); @@ -682,7 +672,7 @@ void imap_do_fetch(int num_items, char **itemlist) { if (IMAP->num_msgs > 0) for (i = 0; i < IMAP->num_msgs; ++i) - if (IMAP->flags[i] & IMAP_SELECTED) { + if (IMAP->flags[i] & IMAP_FETCHED) { msg = CtdlFetchMessage(IMAP->msgids[i]); if (msg != NULL) { imap_do_fetch_msg(i+1, msg, num_items, itemlist); @@ -823,14 +813,14 @@ int imap_extract_data_items(char **argv, char *items) { /* * One particularly hideous aspect of IMAP is that we have to allow the client * to specify arbitrary ranges and/or sets of messages to fetch. Citadel IMAP - * handles this by setting the IMAP_SELECTED flag for each message specified in + * handles this by setting the IMAP_FETCHED flag for each message specified in * the ranges/sets, then looping through the message array, outputting messages * with the flag set. We don't bother returning an error if an out-of-range * number is specified (we just return quietly) because any client braindead * enough to request a bogus message number isn't going to notice the * difference anyway. * - * This function clears out the IMAP_SELECTED bits, then sets that bit for each + * This function clears out the IMAP_FETCHED bits, then sets that bit for each * message included in the specified range. * * Set is_uid to 1 to fetch by UID instead of sequence number. @@ -854,10 +844,10 @@ void imap_pick_range(char *supplied_range, int is_uid) { } /* - * Clear out the IMAP_SELECTED flags for all messages. + * Clear out the IMAP_FETCHED flags for all messages. */ for (i = 0; i < IMAP->num_msgs; ++i) { - IMAP->flags[i] = IMAP->flags[i] & ~IMAP_SELECTED; + IMAP->flags[i] = IMAP->flags[i] & ~IMAP_FETCHED; } /* @@ -884,13 +874,13 @@ void imap_pick_range(char *supplied_range, int is_uid) { if ( (IMAP->msgids[i-1]>=lo) && (IMAP->msgids[i-1]<=hi)) { IMAP->flags[i-1] = - IMAP->flags[i-1] | IMAP_SELECTED; + IMAP->flags[i-1] | IMAP_FETCHED; } } else { /* fetch by uid */ if ( (i>=lo) && (i<=hi)) { IMAP->flags[i-1] = - IMAP->flags[i-1] | IMAP_SELECTED; + IMAP->flags[i-1] | IMAP_FETCHED; } } } @@ -902,7 +892,7 @@ void imap_pick_range(char *supplied_range, int is_uid) { for (i = 0; i < IMAP->num_msgs; ++i) { if (IMAP->flags[i] & IMAP_EXPUNGED) { lprintf(9, "eliminating %d because expunged\n", i); - IMAP->flags[i] = IMAP->flags[i] & ~IMAP_SELECTED; + IMAP->flags[i] = IMAP->flags[i] & ~IMAP_FETCHED; } } diff --git a/citadel/imap_fetch.h b/citadel/imap_fetch.h index fdc2a6a8c..b3f80dfc9 100644 --- a/citadel/imap_fetch.h +++ b/citadel/imap_fetch.h @@ -7,4 +7,3 @@ void imap_pick_range(char *range, int is_uid); void imap_fetch(int num_parms, char *parms[]); void imap_uidfetch(int num_parms, char *parms[]); int imap_extract_data_items(char **argv, char *items); -void imap_output_flags(int num); diff --git a/citadel/imap_search.c b/citadel/imap_search.c index fc40923ab..2ca9fb9af 100644 --- a/citadel/imap_search.c +++ b/citadel/imap_search.c @@ -82,7 +82,7 @@ void imap_do_search(int num_items, char **itemlist, int is_uid) { cprintf("* SEARCH "); if (IMAP->num_msgs > 0) for (i = 0; i < IMAP->num_msgs; ++i) - if (IMAP->flags[i] && IMAP_SELECTED) { + if (IMAP->flags[i] && IMAP_FETCHED) { msg = CtdlFetchMessage(IMAP->msgids[i]); if (msg != NULL) { imap_do_search_msg(i+1, msg, num_items, diff --git a/citadel/imap_store.c b/citadel/imap_store.c index 70fcdaff4..fd3c5aac5 100644 --- a/citadel/imap_store.c +++ b/citadel/imap_store.c @@ -42,46 +42,18 @@ #include "genstamp.h" + + + + /* * imap_do_store() calls imap_do_store_msg() to output the deta of an * individual message, once it has been successfully loaded from disk. */ -void imap_do_store_msg(int num, int num_items, char **itemlist) { - int i; - int flagbucket = 0; - - /* at this point it should be down to "item (flags)" */ - if (num_items < 2) return; +void imap_do_store_msg(int seq, struct CtdlMessage *msg, + int num_items, char **itemlist, int is_uid) { - /* put together the flag bucket */ - for (i=0; iflags[num] &= IMAP_INTERNAL_MASK; - IMAP->flags[num] |= flagbucket; - } - if (!strncasecmp(itemlist[0], "+FLAGS", 6)) { - IMAP->flags[num] |= flagbucket; - } - - if (!strncasecmp(itemlist[0], "-FLAGS", 6)) { - IMAP->flags[num] &= ~flagbucket; - } - - /* - * Tell the client what happen (someone set up us the bomb!) - */ - cprintf("* %d FETCH (", num+1); /* output sequence number */ - imap_output_flags(num); - cprintf(")\r\n"); } @@ -92,12 +64,19 @@ void imap_do_store_msg(int num, int num_items, char **itemlist) { */ void imap_do_store(int num_items, char **itemlist, int is_uid) { int i; - - if (IMAP->num_msgs > 0) { - for (i = 0; i < IMAP->num_msgs; ++i) { - if (IMAP->flags[i] && IMAP_SELECTED) { - imap_do_store_msg(i, num_items, itemlist); - } + struct CtdlMessage *msg; + + if (IMAP->num_msgs > 0) + for (i = 0; i < IMAP->num_msgs; ++i) + if (IMAP->flags[i] && IMAP_FETCHED) { + msg = CtdlFetchMessage(IMAP->msgids[i]); + if (msg != NULL) { + imap_do_store_msg(i+1, msg, num_items, + itemlist, is_uid); + CtdlFreeMessage(msg); + } + else { + lprintf(1, "IMAP STORE internal error\n"); } } } @@ -112,22 +91,19 @@ void imap_store(int num_parms, char *parms[]) { int num_items; int i; - if (num_parms < 4) { + if (num_parms < 3) { cprintf("%s BAD invalid parameters\r\n", parms[0]); return; } - if (imap_is_message_set(parms[2])) { - imap_pick_range(parms[2], 0); - } - else { - cprintf("%s BAD No message set specified to STORE\r\n", - parms[0]); - return; + for (i=1; icm_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 *ibuf; + char buf[SIZ]; 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(&ibuf)>0) && strcmp(ibuf, terminator) ) ;; + while ( (client_gets(buf)>0) && strcmp(buf, 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(&ibuf)>0) && strcmp(ibuf, terminator) ) { + while ( (client_gets(buf)>0) && strcmp(buf, terminator) ) { /* strip trailing newline type stuff */ - if (ibuf[strlen(ibuf)-1]==10) ibuf[strlen(ibuf)-1]=0; - if (ibuf[strlen(ibuf)-1]==13) ibuf[strlen(ibuf)-1]=0; + if (buf[strlen(buf)-1]==10) buf[strlen(buf)-1]=0; + if (buf[strlen(buf)-1]==13) buf[strlen(buf)-1]=0; - linelen = strlen(ibuf); + linelen = strlen(buf); /* 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(&ibuf)>0) && - strcmp(ibuf, terminator)) ;; + while ( (client_gets(buf)>0) && + strcmp(buf, 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], ibuf); + strcpy(&m[message_len], buf); 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(&ibuf)>0) - && strcmp(ibuf, terminator)) ;; + while ( (client_gets(buf)>0) + && strcmp(buf, terminator)) ;; return(m); } } diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 448aa62c9..d7ba6a6e5 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 *ibuf; + char buf[SIZ]; 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(&ibuf); - if (strcmp(ibuf, "000")) - fprintf(fp, "%s\n", ibuf); - } while (strcmp(ibuf, "000")); + client_gets(buf); + if (strcmp(buf, "000")) + fprintf(fp, "%s\n", buf); + } while (strcmp(buf, "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 513d0b3c3..18bf3b920 100644 --- a/citadel/serv_bio.c +++ b/citadel/serv_bio.c @@ -42,8 +42,7 @@ * enter user bio */ void cmd_ebio(char *cmdbuf) { - char cbuf[SIZ]; - char *ibuf; + char buf[SIZ]; FILE *fp; if (!(CC->logged_in)) { @@ -51,15 +50,15 @@ void cmd_ebio(char *cmdbuf) { return; } - sprintf(cbuf,"./bio/%ld",CC->usersupp.usernum); - fp = fopen(cbuf,"w"); + sprintf(buf,"./bio/%ld",CC->usersupp.usernum); + fp = fopen(buf,"w"); if (fp == NULL) { cprintf("%d Cannot create file\n",ERROR); return; } cprintf("%d \n",SEND_LISTING); - while(client_gets(&ibuf), strcmp(ibuf,"000")) { - fprintf(fp,"%s\n",ibuf); + while(client_gets(buf), strcmp(buf,"000")) { + fprintf(fp,"%s\n",buf); } fclose(fp); } diff --git a/citadel/serv_chat.c b/citadel/serv_chat.c index 4be79b1f1..03473dd97 100644 --- a/citadel/serv_chat.c +++ b/citadel/serv_chat.c @@ -613,7 +613,6 @@ 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); @@ -650,13 +649,13 @@ void cmd_sexp(char *argbuf) SEND_LISTING, message_sent); x_big_msgbuf = mallok(SIZ); memset(x_big_msgbuf, 0, SIZ); - while (client_gets(&ix_msg), strcmp(ix_msg, "000")) { + while (client_gets(x_msg), strcmp(x_msg, "000")) { x_big_msgbuf = reallok(x_big_msgbuf, - strlen(x_big_msgbuf) + strlen(ix_msg) + 4); + strlen(x_big_msgbuf) + strlen(x_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, ix_msg); + strcat(x_big_msgbuf, x_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 bf241aa90..341f96703 100644 --- a/citadel/serv_imap.c +++ b/citadel/serv_imap.c @@ -365,7 +365,6 @@ void imap_select(int num_parms, char *parms[]) { cprintf("* %d EXISTS\r\n", msgs); cprintf("* %d RECENT\r\n", new); cprintf("* OK [UIDVALIDITY 0] UIDs valid\r\n"); - cprintf("* FLAGS (\\Deleted)\r\n"); cprintf("%s OK [%s] %s completed\r\n", parms[0], (IMAP->readonly ? "READ-ONLY" : "READ-WRITE"), @@ -614,37 +613,34 @@ void imap_status(int num_parms, char *parms[]) { * Main command loop for IMAP sessions. */ void imap_command_loop(void) { - char *icmdbuf; + char cmdbuf[SIZ]; char *parms[SIZ]; int num_parms; time(&CC->lastcmd); - if (client_gets(&icmdbuf) < 1) { + memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */ + if (client_gets(cmdbuf) < 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, icmdbuf); - while (strlen(icmdbuf) < 5) strcat(icmdbuf, " "); + lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, cmdbuf); + while (strlen(cmdbuf) < 5) strcat(cmdbuf, " "); /* strip off l/t whitespace and CRLF */ - 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 (cmdbuf[strlen(cmdbuf)-1]=='\n') cmdbuf[strlen(cmdbuf)-1]=0; + if (cmdbuf[strlen(cmdbuf)-1]=='\r') cmdbuf[strlen(cmdbuf)-1]=0; + striplt(cmdbuf); /* If we're in the middle of a multi-line command, handle that */ if (IMAP->authstate == imap_as_expecting_username) { - 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); + imap_auth_login_user(cmdbuf); return; } if (IMAP->authstate == imap_as_expecting_password) { - if (strlen(icmdbuf) >= SIZ) - *(icmdbuf+SIZ) = '\0'; - imap_auth_login_pass(icmdbuf); + imap_auth_login_pass(cmdbuf); return; } @@ -664,7 +660,7 @@ void imap_command_loop(void) { /* Now for the command set. */ /* Grab the tag, command, and parameters. Check syntax. */ - num_parms = imap_parameterize(parms, icmdbuf); + num_parms = imap_parameterize(parms, cmdbuf); if (num_parms < 2) { cprintf("BAD syntax error\r\n"); } diff --git a/citadel/serv_imap.h b/citadel/serv_imap.h index 21b33ce00..8f651ae48 100644 --- a/citadel/serv_imap.h +++ b/citadel/serv_imap.h @@ -36,11 +36,7 @@ enum { #define IMAP_DELETED 4 #define IMAP_DRAFT 8 #define IMAP_SEEN 16 - -#define IMAP_SETABLE_MASK 0x1f -#define IMAP_INTERNAL_MASK (~IMAP_SETABLE_MASK) - -#define IMAP_SELECTED 32 /* internal */ +#define IMAP_FETCHED 32 /* internal */ #define IMAP_EXPUNGED 64 /* internal */ diff --git a/citadel/serv_network.c b/citadel/serv_network.c index d5cdc5d7a..9f7382bb2 100644 --- a/citadel/serv_network.c +++ b/citadel/serv_network.c @@ -65,8 +65,7 @@ void cmd_gnet(char *argbuf) { void cmd_snet(char *argbuf) { char tempfilename[SIZ]; char filename[SIZ]; - char cbuf[SIZ]; - char *ibuf; + char buf[SIZ]; FILE *fp; if (CtdlAccessCheck(ac_room_aide)) return; @@ -82,8 +81,8 @@ void cmd_snet(char *argbuf) { } cprintf("%d %s\n", SEND_LISTING, tempfilename); - while (client_gets(&ibuf), strcmp(ibuf, "000")) { - fprintf(fp, "%s\n", ibuf); + while (client_gets(buf), strcmp(buf, "000")) { + fprintf(fp, "%s\n", buf); } fclose(fp); @@ -92,8 +91,8 @@ void cmd_snet(char *argbuf) { * different filesystems) */ unlink(filename); - snprintf(cbuf, sizeof cbuf, "/bin/mv %s %s", tempfilename, filename); - system(cbuf); + snprintf(buf, sizeof buf, "/bin/mv %s %s", tempfilename, filename); + system(buf); } diff --git a/citadel/serv_pop3.c b/citadel/serv_pop3.c index 229e42cf0..df53f197f 100644 --- a/citadel/serv_pop3.c +++ b/citadel/serv_pop3.c @@ -525,75 +525,76 @@ void pop3_uidl(char *argbuf) { * Main command loop for POP3 sessions. */ void pop3_command_loop(void) { - char *icmdbuf; + char cmdbuf[SIZ]; time(&CC->lastcmd); - if (client_gets(&icmdbuf) < 1) { + memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */ + if (client_gets(cmdbuf) < 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, icmdbuf); - while (strlen(icmdbuf) < 5) strcat(icmdbuf, " "); + lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, cmdbuf); + while (strlen(cmdbuf) < 5) strcat(cmdbuf, " "); - if (!strncasecmp(icmdbuf, "NOOP", 4)) { + if (!strncasecmp(cmdbuf, "NOOP", 4)) { cprintf("+OK No operation.\r\n"); } - else if (!strncasecmp(icmdbuf, "QUIT", 4)) { + else if (!strncasecmp(cmdbuf, "QUIT", 4)) { cprintf("+OK Goodbye...\r\n"); pop3_update(); CC->kill_me = 1; return; } - else if (!strncasecmp(icmdbuf, "USER", 4)) { - pop3_user(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "USER", 4)) { + pop3_user(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "PASS", 4)) { - pop3_pass(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "PASS", 4)) { + pop3_pass(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "APOP", 4)) + else if (!strncasecmp(cmdbuf, "APOP", 4)) { - pop3_apop(&icmdbuf[5]); + pop3_apop(&cmdbuf[5]); } else if (!CC->logged_in) { cprintf("-ERR Not logged in.\r\n"); } - else if (!strncasecmp(icmdbuf, "LIST", 4)) { - pop3_list(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "LIST", 4)) { + pop3_list(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "STAT", 4)) { - pop3_stat(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "STAT", 4)) { + pop3_stat(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "RETR", 4)) { - pop3_retr(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "RETR", 4)) { + pop3_retr(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "DELE", 4)) { - pop3_dele(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "DELE", 4)) { + pop3_dele(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "RSET", 4)) { - pop3_rset(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "RSET", 4)) { + pop3_rset(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "UIDL", 4)) { - pop3_uidl(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "UIDL", 4)) { + pop3_uidl(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "TOP", 3)) { - pop3_top(&icmdbuf[4]); + else if (!strncasecmp(cmdbuf, "TOP", 3)) { + pop3_top(&cmdbuf[4]); } - else if (!strncasecmp(icmdbuf, "LAST", 4)) { - pop3_last(&icmdbuf[4]); + else if (!strncasecmp(cmdbuf, "LAST", 4)) { + pop3_last(&cmdbuf[4]); } else { diff --git a/citadel/serv_smtp.c b/citadel/serv_smtp.c index 41ea53757..1e54b7f07 100644 --- a/citadel/serv_smtp.c +++ b/citadel/serv_smtp.c @@ -688,76 +688,74 @@ void smtp_data(void) { * Main command loop for SMTP sessions. */ void smtp_command_loop(void) { - char *icmdbuf; + char cmdbuf[SIZ]; time(&CC->lastcmd); - if (client_gets(&icmdbuf) < 1) { + memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */ + if (client_gets(cmdbuf) < 1) { lprintf(3, "SMTP socket is broken. Ending session.\n"); CC->kill_me = 1; return; } - /* 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, " "); + lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, cmdbuf); + while (strlen(cmdbuf) < 5) strcat(cmdbuf, " "); if (SMTP->command_state == smtp_user) { - smtp_get_user(icmdbuf); + smtp_get_user(cmdbuf); } else if (SMTP->command_state == smtp_password) { - smtp_get_pass(icmdbuf); + smtp_get_pass(cmdbuf); } - else if (!strncasecmp(icmdbuf, "AUTH", 4)) { - smtp_auth(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "AUTH", 4)) { + smtp_auth(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "DATA", 4)) { + else if (!strncasecmp(cmdbuf, "DATA", 4)) { smtp_data(); } - else if (!strncasecmp(icmdbuf, "EHLO", 4)) { - smtp_hello(&icmdbuf[5], 1); + else if (!strncasecmp(cmdbuf, "EHLO", 4)) { + smtp_hello(&cmdbuf[5], 1); } - else if (!strncasecmp(icmdbuf, "EXPN", 4)) { - smtp_expn(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "EXPN", 4)) { + smtp_expn(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "HELO", 4)) { - smtp_hello(&icmdbuf[5], 0); + else if (!strncasecmp(cmdbuf, "HELO", 4)) { + smtp_hello(&cmdbuf[5], 0); } - else if (!strncasecmp(icmdbuf, "HELP", 4)) { + else if (!strncasecmp(cmdbuf, "HELP", 4)) { smtp_help(); } - else if (!strncasecmp(icmdbuf, "MAIL", 4)) { - smtp_mail(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "MAIL", 4)) { + smtp_mail(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "NOOP", 4)) { + else if (!strncasecmp(cmdbuf, "NOOP", 4)) { cprintf("250 This command successfully did nothing.\r\n"); } - else if (!strncasecmp(icmdbuf, "QUIT", 4)) { + else if (!strncasecmp(cmdbuf, "QUIT", 4)) { cprintf("221 Goodbye...\r\n"); CC->kill_me = 1; return; } - else if (!strncasecmp(icmdbuf, "RCPT", 4)) { - smtp_rcpt(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "RCPT", 4)) { + smtp_rcpt(&cmdbuf[5]); } - else if (!strncasecmp(icmdbuf, "RSET", 4)) { + else if (!strncasecmp(cmdbuf, "RSET", 4)) { smtp_rset(); } - else if (!strncasecmp(icmdbuf, "VRFY", 4)) { - smtp_vrfy(&icmdbuf[5]); + else if (!strncasecmp(cmdbuf, "VRFY", 4)) { + smtp_vrfy(&cmdbuf[5]); } else { diff --git a/citadel/serv_vandelay.c b/citadel/serv_vandelay.c index 897bdb5a5..f54e9d704 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 *ibuf; + char buf[SIZ]; lprintf(9, "Importing config file\n"); - client_gets(&ibuf); strcpy(config.c_nodename, ibuf); + client_gets(config.c_nodename); lprintf(9, "c_nodename = %s\n", config.c_nodename); - 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); + 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); lprintf(9, "c_sysadm = %s\n", config.c_sysadm); - 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); + 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); put_config(); lprintf(7, "Imported config file\n"); } @@ -337,67 +337,67 @@ void artv_import_config(void) { void artv_import_control(void) { - char *ibuf; + char buf[SIZ]; lprintf(9, "Importing control file\n"); - 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); + 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); put_control(); lprintf(7, "Imported control file\n"); } void artv_import_user(void) { - char *ibuf; + char buf[SIZ]; struct usersupp usbuf; - 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); + 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); putuser(&usbuf); } void artv_import_room(void) { - char *ibuf; + char buf[SIZ]; struct quickroom qrbuf; long msgnum; int msgcount = 0; - 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); + 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); 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(&ibuf), msgnum = atol(ibuf), msgnum > 0) { + while (client_gets(buf), msgnum = atol(buf), 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 *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); + 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); 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 *ibuf; + char buf[SIZ]; - 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); + 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); put_visit(&vbuf); lprintf(7, "Imported visit %ld/%ld/%ld\n", vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum); @@ -444,17 +444,16 @@ 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(&ibuf); msgnum = atol(ibuf); + client_gets(buf); msgnum = atol(buf); smi.smi_msgnum = msgnum; - 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); + client_gets(buf); smi.smi_refcount = atoi(buf); + client_gets(smi.smi_content_type); + client_gets(buf); smi.smi_mod = atoi(buf); lprintf(7, "message #%ld\n", msgnum); @@ -462,7 +461,7 @@ void artv_import_message(void) { strcpy(tempfile, tmpnam(NULL)); sprintf(buf, "./base64 -d >%s", tempfile); fp = popen(buf, "w"); - while (client_gets(&ibuf), strcasecmp(ibuf, END_OF_MESSAGE)) { + while (client_gets(buf), strcasecmp(buf, END_OF_MESSAGE)) { fprintf(fp, "%s\n", buf); } fclose(fp); @@ -490,41 +489,41 @@ void artv_import_message(void) { void artv_do_import(void) { - char *ibuf; - char *is_version; + char buf[SIZ]; + char s_version[SIZ]; int version; cprintf("%d sock it to me\n", SEND_LISTING); - while (client_gets(&ibuf), strcmp(ibuf, "000")) { + while (client_gets(buf), strcmp(buf, "000")) { - lprintf(9, "import keyword: <%s>\n", ibuf); + lprintf(9, "import keyword: <%s>\n", buf); - if (!strcasecmp(ibuf, "version")) { - client_gets(&is_version); - version = atoi(is_version); + if (!strcasecmp(buf, "version")) { + client_gets(s_version); + version = atoi(s_version); if ((version < REV_MIN) || (version > REV_LEVEL)) { lprintf(7, "Version mismatch - aborting\n"); break; } } - 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 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 break; } - lprintf(7, "Invalid keyword <%s>. Flushing input.\n", ibuf); - while (client_gets(&ibuf), strcmp(ibuf, "000")) ;; + lprintf(7, "Invalid keyword <%s>. Flushing input.\n", buf); + while (client_gets(buf), strcmp(buf, "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 */ @@ -538,7 +537,7 @@ void cmd_artv(char *cmdbuf) { strcpy(artv_tempfilename1, tmpnam(NULL)); strcpy(artv_tempfilename2, tmpnam(NULL)); - extract(cmd, cmdbuf, 0); /* this is limited to SIZ */ + extract(cmd, cmdbuf, 0); 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 01fe7ea2f..07d93c6f7 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 *ibuf; + char buf[SIZ]; 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(&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); + 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); if (a==4) { - for (c=0; c='0')&&(ibuf[c]<='9')) { + for (c=0; c='0')&&(buf[c]<='9')) { b=strlen(tmpzip); - tmpzip[b]=ibuf[c]; + tmpzip[b]=buf[c]; tmpzip[b+1]=0; } } } - 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); + 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); ++a; } sprintf(tmpaddress, ";;%s;%s;%s;%s;%s", diff --git a/citadel/server.h b/citadel/server.h index 803e5b72e..33ceef4a4 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -109,10 +109,6 @@ 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 31ec47272..9bf1b73a2 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -89,37 +89,10 @@ 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; + char buf[4096]; - /* 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); @@ -143,76 +116,23 @@ 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 = getmem(tsize); /* stu, thought you might like this for debugging */ + ptr = malloc(tsize); if (ptr == NULL) { lprintf(3, "DANGER! mallok(%d) at %s:%d failed!\n", tsize, tfile, tline); return(NULL); } - hptr = (struct TheHeap *) getmem(sizeof(struct TheHeap)); + hptr = (struct TheHeap *) malloc(sizeof(struct TheHeap)); strcpy(hptr->h_file, tfile); hptr->h_line = tline; hptr->next = heap; @@ -236,7 +156,7 @@ void tracked_free(void *ptr) { if (heap->h_ptr == ptr) { hptr = heap->next; - freemem(heap); + free(heap); heap = hptr; } else { @@ -244,19 +164,19 @@ void tracked_free(void *ptr) { if (hptr->next->h_ptr == ptr) { freeme = hptr->next; hptr->next = hptr->next->next; - freemem(freeme); + free(freeme); } } } - freemem(ptr); + free(ptr); } void *tracked_realloc(void *ptr, size_t size) { void *newptr; struct TheHeap *hptr; - newptr = reallocmem(ptr, size); + newptr = realloc(ptr, size); for (hptr=heap; hptr!=NULL; hptr=hptr->next) { if (hptr->h_ptr == ptr) hptr->h_ptr = newptr; @@ -525,6 +445,13 @@ void client_write(char *buf, int nbytes) int retval; int sock; + /* + * Yes, this is where we want this signal() call to be. Evidently the + * DB library is screwing with this binding and we don't want the + * server to crash, so we force this to be correct. + */ + signal(SIGPIPE, SIG_IGN); + if (CC->redirect_fp != NULL) { fwrite(buf, nbytes, 1, CC->redirect_fp); return; @@ -625,69 +552,7 @@ int client_read(char *buf, int bytes) * (This is implemented in terms of client_read() and could be * justifiably moved out of sysdep.c) */ - -/* 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; - if (i == 1024*1024) // set some obscene upper limit - 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 client_gets(char *buf) { int i, retval; diff --git a/citadel/sysdep_decls.h b/citadel/sysdep_decls.h index 87784ce78..1398f30b0 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 b2a88d927..4a5ee52c7 100644 --- a/citadel/tools.c +++ b/citadel/tools.c @@ -75,10 +75,6 @@ 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; @@ -92,10 +88,8 @@ void extract_token(char *dest, char *source, int parmnum, char separator) ++curr_parm; } else if (curr_parm == parmnum) { - if (len < SIZ) { /* stu 2/8/2001 */ - dest[len+1] = 0; - dest[len++] = source[i]; - } + dest[len+1] = 0; + dest[len++] = source[i]; } } } -- 2.39.2