--- sbbs/src/sbbs3/postmsg.cpp 2018/04/24 16:41:23 1.1 +++ sbbs/src/sbbs3/postmsg.cpp 2018/04/24 16:43:29 1.1.1.2 @@ -2,13 +2,13 @@ /* Synchronet user create/post public message routine */ -/* $Id: postmsg.cpp,v 1.1 2018/04/24 16:41:23 root Exp $ */ +/* $Id: postmsg.cpp,v 1.1.1.2 2018/04/24 16:43:29 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -37,7 +37,9 @@ #include "sbbs.h" -static char* program_id(char* pid) +/****************************************************************************/ +/****************************************************************************/ +extern "C" char* DLLCALL msg_program_id(char* pid) { char compiler[64]; @@ -65,11 +67,14 @@ bool sbbs_t::postmsg(uint subnum, smbmsg char touser[64]; char from[64]; char pid[128]; - ushort xlat,msgattr; + char* editor=NULL; + uint16_t xlat; + ushort msgattr; int i,j,x,file,storage; ulong length,offset,crc=0xffffffff; FILE* instream; smbmsg_t msg; + uint reason; if(remsg) { sprintf(title,"%.*s",LEN_TITLE,remsg->subj); @@ -85,7 +90,7 @@ bool sbbs_t::postmsg(uint subnum, smbmsg SAFECOPY(touser,from); msgattr=(ushort)(remsg->hdr.attr&MSG_PRIVATE); sprintf(top,text[RegardingByToOn],title,from,remsg->to - ,timestr((time_t *)&remsg->hdr.when_written.time) + ,timestr(remsg->hdr.when_written.time) ,smb_zonestr(remsg->hdr.when_written.zone,NULL)); } else { title[0]=0; @@ -95,22 +100,9 @@ bool sbbs_t::postmsg(uint subnum, smbmsg } /* Security checks */ - if(!chk_ar(cfg.sub[subnum]->post_ar,&useron)) { - bputs(text[CantPostOnSub]); - return(false); - } - if(useron.rest&FLAG('P')) { - bputs(text[R_Post]); - return(false); - } - if((cfg.sub[subnum]->misc&(SUB_QNET|SUB_FIDO|SUB_PNET|SUB_INET)) - && (useron.rest&FLAG('N'))) { - bputs(text[CantPostOnSub]); - return(false); - } - if(useron.ptoday>=cfg.level_postsperday[useron.level]) { - bputs(text[TooManyPostsToday]); - return(false); + if(!can_user_post(&cfg,subnum,&useron,&client,&reason)) { + bputs(text[reason]); + return false; } bprintf(text[Posting],cfg.grp[cfg.sub[subnum]->grp]->sname,cfg.sub[subnum]->lname); @@ -143,7 +135,7 @@ bool sbbs_t::postmsg(uint subnum, smbmsg if(stricmp(touser,"ALL") && !(cfg.sub[subnum]->misc&(SUB_PNET|SUB_FIDO|SUB_QNET|SUB_INET|SUB_ANON))) { if(cfg.sub[subnum]->misc&SUB_NAME) { - if(!userdatdupe(useron.number,U_NAME,LEN_NAME,touser,0)) { + if(!userdatdupe(useron.number,U_NAME,LEN_NAME,touser)) { bputs(text[UnknownUser]); return(false); } @@ -176,7 +168,7 @@ bool sbbs_t::postmsg(uint subnum, smbmsg && !noyes(text[AnonymousQ]))) msgattr|=MSG_ANONYMOUS; - if(cfg.sub[subnum]->mod_ar[0] && chk_ar(cfg.sub[subnum]->mod_ar,&useron)) + if(cfg.sub[subnum]->mod_ar[0] && chk_ar(cfg.sub[subnum]->mod_ar,&useron,&client)) msgattr|=MSG_MODERATED; if(cfg.sub[subnum]->misc&SUB_SYSPERM && sub_op(subnum)) @@ -192,8 +184,8 @@ bool sbbs_t::postmsg(uint subnum, smbmsg bputs(text[UsingRealName]); msg_tmp_fname(useron.xedit, str, sizeof(str)); - if(!writemsg(str,top,title,wm_mode,subnum,touser) - || (long)(length=flength(str))<1) { /* Bugfix Aug-20-2003: Reject negative length */ + if(!writemsg(str,top,title,wm_mode,subnum,touser,&editor) + || (long)(length=(long)flength(str))<1) { /* Bugfix Aug-20-2003: Reject negative length */ bputs(text[Aborted]); return(false); } @@ -304,6 +296,18 @@ bool sbbs_t::postmsg(uint subnum, smbmsg fclose(instream); crc=~crc; + if(cfg.sub[subnum]->maxcrcs) { + i=smb_addcrc(&smb,crc); + if(i) { + smb_freemsgdat(&smb,offset,length,1); + smb_close(&smb); + smb_stack(&smb,SMB_STACK_POP); + attr(cfg.color[clr_err]); + bputs(text[CantPostMsg]); + return(false); + } + } + memset(&msg,0,sizeof(smbmsg_t)); msg.hdr.version=smb_ver(); msg.hdr.attr=msgattr; @@ -312,17 +316,6 @@ bool sbbs_t::postmsg(uint subnum, smbmsg msg.hdr.number=smb.status.last_msg+1; /* this *should* be the new message number */ - smb_hfield_str(&msg,FIDOPID,program_id(pid)); - - /* Generate default (RFC822) message-id (always) */ - SAFECOPY(msg_id,get_msgid(&cfg,subnum,&msg)); - smb_hfield_str(&msg,RFC822MSGID,msg_id); - - /* Generate FTN (FTS-9) MSGID */ - if(cfg.sub[subnum]->misc&SUB_FIDO) { - SAFECOPY(msg_id,ftn_msgid(cfg.sub[subnum],&msg)); - smb_hfield_str(&msg,FIDOMSGID,msg_id); - } if(remsg) { msg.hdr.thread_back=remsg->hdr.number; /* needed for threading backward */ @@ -336,39 +329,41 @@ bool sbbs_t::postmsg(uint subnum, smbmsg smb_hfield_str(&msg,FIDOREPLYID,remsg->ftn_msgid); if((i=smb_updatethread(&smb, remsg, smb.status.last_msg+1))!=SMB_SUCCESS) - errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); - } - - - if(cfg.sub[subnum]->maxcrcs) { - i=smb_addcrc(&smb,crc); - if(i) { - smb_freemsgdat(&smb,offset,length,1); - smb_close(&smb); - smb_stack(&smb,SMB_STACK_POP); - attr(cfg.color[clr_err]); - bputs("Duplicate message!\r\n"); - return(false); - } + errormsg(WHERE,"updating thread",smb.file,i,smb.last_error); } msg.hdr.offset=offset; smb_hfield_str(&msg,RECIPIENT,touser); - strlwr(touser); SAFECOPY(str,cfg.sub[subnum]->misc&SUB_NAME ? useron.name : useron.alias); smb_hfield_str(&msg,SENDER,str); - strlwr(str); sprintf(str,"%u",useron.number); smb_hfield_str(&msg,SENDEREXT,str); /* Security logging */ msg_client_hfields(&msg,&client); + smb_hfield_str(&msg,SENDERSERVER,startup->host_name); smb_hfield_str(&msg,SUBJECT,title); + /* Generate default (RFC822) message-id (always) */ + get_msgid(&cfg,subnum,&msg,msg_id,sizeof(msg_id)); + smb_hfield_str(&msg,RFC822MSGID,msg_id); + + /* Generate FTN (FTS-9) MSGID */ + if(cfg.sub[subnum]->misc&SUB_FIDO) { + ftn_msgid(cfg.sub[subnum],&msg,msg_id,sizeof(msg_id)); + smb_hfield_str(&msg,FIDOMSGID,msg_id); + } + + /* Generate FidoNet Program Identifier */ + smb_hfield_str(&msg,FIDOPID,msg_program_id(pid)); + + if(editor!=NULL) + smb_hfield_str(&msg,SMB_EDITOR,editor); + smb_dfield(&msg,TEXT_BODY,length); i=smb_addmsghdr(&smb,&msg,storage); // calls smb_unlocksmbhdr() @@ -413,28 +408,37 @@ extern "C" void DLLCALL signal_sub_sem(s extern "C" int DLLCALL msg_client_hfields(smbmsg_t* msg, client_t* client) { - int i; + int i; + char port[16]; + char date[64]; if(client==NULL) return(-1); + if(client->user!=NULL && (i=smb_hfield_str(msg,SENDERUSERID,client->user))!=SMB_SUCCESS) + return(i); + if((i=smb_hfield_str(msg,SENDERTIME,xpDateTime_to_isoDateTimeStr(gmtime_to_xpDateTime(client->time) + ,/* separators: */"","","", /* precision: */0 + ,date,sizeof(date))))!=SMB_SUCCESS) + return(i); if((i=smb_hfield_str(msg,SENDERIPADDR,client->addr))!=SMB_SUCCESS) return(i); if((i=smb_hfield_str(msg,SENDERHOSTNAME,client->host))!=SMB_SUCCESS) return(i); - if((i=smb_hfield_str(msg,SENDERPROTOCOL,client->protocol))!=SMB_SUCCESS) + if(client->protocol!=NULL && (i=smb_hfield_str(msg,SENDERPROTOCOL,client->protocol))!=SMB_SUCCESS) return(i); - return smb_hfield(msg,SENDERPORT,sizeof(client->port),&client->port); + SAFEPRINTF(port,"%u",client->port); + return smb_hfield_str(msg,SENDERPORT,port); } -extern "C" int DLLCALL savemsg(scfg_t* cfg, smb_t* smb, smbmsg_t* msg, client_t* client, char* msgbuf) +extern "C" int DLLCALL savemsg(scfg_t* cfg, smb_t* smb, smbmsg_t* msg, client_t* client, const char* server, char* msgbuf) { char pid[128]; char msg_id[256]; ushort xlat=XLAT_NONE; int i; int storage=SMB_SELFPACK; - long dupechk_hashes=SMB_HASH_SOURCE_ALL; + long dupechk_hashes=SMB_HASH_SOURCE_DUPE; if(msg==NULL) return(SMB_FAILURE); @@ -461,6 +465,21 @@ extern "C" int DLLCALL savemsg(scfg_t* c if(smb->subnum==INVALID_SUB) { /* e-mail */ + /* exception here during recycle: + + sbbs.dll!savemsg(scfg_t * cfg, smb_t * smb, smbmsg_t * msg, client_t * client, char * msgbuf) Line 473 + 0xf bytes C++ + sbbs.dll!js_save_msg(JSContext * cx, JSObject * obj, unsigned int argc, long * argv, long * rval) Line 1519 + 0x25 bytes C + js32.dll!js_Invoke(JSContext * cx, unsigned int argc, unsigned int flags) Line 1375 + 0x17 bytes C + js32.dll!js_Interpret(JSContext * cx, unsigned char * pc, long * result) Line 3944 + 0xf bytes C + js32.dll!js_Execute(JSContext * cx, JSObject * chain, JSScript * script, JSStackFrame * down, unsigned int flags, long * result) Line 1633 + 0x13 bytes C + js32.dll!JS_ExecuteScript(JSContext * cx, JSObject * obj, JSScript * script, long * rval) Line 4188 + 0x19 bytes C + sbbs.dll!sbbs_t::js_execfile(const char * cmd, const char * startup_dir) Line 686 + 0x27 bytes C++ + sbbs.dll!sbbs_t::external(const char * cmdline, long mode, const char * startup_dir) Line 413 + 0x1e bytes C++ + sbbs.dll!event_thread(void * arg) Line 2745 + 0x71 bytes C++ + + apparently the event_thread is sharing an scfg_t* with another thread! */ + + smb->status.max_crcs=cfg->mail_maxcrcs; smb->status.max_age=cfg->mail_maxage; smb->status.max_msgs=0; /* unlimited */ @@ -508,25 +527,28 @@ extern "C" int DLLCALL savemsg(scfg_t* c if(client!=NULL) msg_client_hfields(msg,client); - - /* Generate FidoNet Program Identifier */ - if(msg->ftn_pid==NULL) - smb_hfield_str(msg,FIDOPID,program_id(pid)); + if(server!=NULL) + smb_hfield_str(msg,SENDERSERVER,server); /* Generate RFC-822 Message-id */ if(msg->id==NULL) { - SAFECOPY(msg_id,get_msgid(cfg,smb->subnum,msg)); + get_msgid(cfg,smb->subnum,msg,msg_id,sizeof(msg_id)); smb_hfield_str(msg,RFC822MSGID,msg_id); } /* Generate FidoNet MSGID (for FidoNet sub-boards) */ if(smb->subnum!=INVALID_SUB && cfg->sub[smb->subnum]->misc&SUB_FIDO && msg->ftn_msgid==NULL) { - SAFECOPY(msg_id,ftn_msgid(cfg->sub[smb->subnum],msg)); + ftn_msgid(cfg->sub[smb->subnum],msg,msg_id,sizeof(msg_id)); smb_hfield_str(msg,FIDOMSGID,msg_id); } - if((i=smb_addmsg(smb,msg,storage,dupechk_hashes,xlat,(uchar*)msgbuf,NULL))==SMB_SUCCESS) + /* Generate FidoNet Program Identifier */ + if(msg->ftn_pid==NULL) + smb_hfield_str(msg,FIDOPID,msg_program_id(pid)); + + if((i=smb_addmsg(smb,msg,storage,dupechk_hashes,xlat,(uchar*)msgbuf,NULL))==SMB_SUCCESS + && msg->to!=NULL /* no recipient means no header created at this stage */) signal_sub_sem(cfg,smb->subnum); return(i);