18 #include "sysdep_decls.h"
22 #include "dynloader.h"
32 extern struct config config;
36 * This function is self explanatory.
37 * (What can I say, I'm in a weird mood today...)
39 void remove_any_whitespace_to_the_left_or_right_of_at_symbol(char *name) {
42 for (i=0; i<strlen(name); ++i) if (name[i]=='@') {
43 if (i>0) if (isspace(name[i-1])) {
44 strcpy(&name[i-1], &name[i]);
47 while (isspace(name[i+1])) {
48 strcpy(&name[i+1], &name[i+2]);
55 * Aliasing for network mail.
56 * (Error messages have been commented out, because this is a server.)
58 int alias(char *name) /* process alias and routing info for mail */
62 char aaa[300],bbb[300];
64 lprintf(9, "alias() called for <%s>\n", name);
66 remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
68 fp=fopen("network/mail.aliases","r");
69 if (fp==NULL) fp=fopen("/dev/null","r");
70 if (fp==NULL) return(M_ERROR);
71 GNA: strcpy(aaa,""); strcpy(bbb,"");
94 if (strcasecmp(name,aaa)) goto GNA;
97 lprintf(7, "Mail is being forwarded to %s\n", name);
99 DETYPE: /* determine local or remote type, see citadel.h */
100 for (a=0; a<strlen(name); ++a) if (name[a]=='!') return(M_INTERNET);
101 for (a=0; a<strlen(name); ++a)
103 for (b=a; b<strlen(name); ++b)
104 if (name[b]=='.') return(M_INTERNET);
105 b=0; for (a=0; a<strlen(name); ++a) if (name[a]=='@') ++b;
107 lprintf(7, "Too many @'s in address\n");
111 for (a=0; a<strlen(name); ++a)
112 if (name[a]=='@') strcpy(bbb,&name[a+1]);
113 while (bbb[0]==32) strcpy(bbb,&bbb[1]);
114 fp = fopen("network/mail.sysinfo","r");
115 if (fp==NULL) return(M_ERROR);
118 } while ((a>=0)&&(strcasecmp(aaa,bbb)));
120 if (!strncmp(aaa,"use ",4)) {
126 if (!strncmp(aaa,"uum",3)) {
128 for (a=0; a<strlen(bbb); ++a) {
129 if (bbb[a]=='@') bbb[a]=0;
130 if (bbb[a]==' ') bbb[a]='_';
132 while(bbb[strlen(bbb)-1]=='_') bbb[strlen(bbb)-1]=0;
133 sprintf(name,&aaa[4],bbb);
136 if (!strncmp(aaa,"bin",3)) {
137 strcpy(aaa,name); strcpy(bbb,name);
138 while (aaa[strlen(aaa)-1]!='@') aaa[strlen(aaa)-1]=0;
139 aaa[strlen(aaa)-1]=0;
140 while (aaa[strlen(aaa)-1]==' ') aaa[strlen(aaa)-1]=0;
141 while (bbb[0]!='@') strcpy(bbb,&bbb[1]);
143 while (bbb[0]==' ') strcpy(bbb,&bbb[1]);
144 sprintf(name,"%s @%s",aaa,bbb);
156 fp=fopen("citadel.control","r");
157 fread((char *)&CitControl,sizeof(struct CitControl),1,fp);
162 * cmd_msgs() - get list of message #'s in this room
164 void cmd_msgs(char *cmdbuf)
173 extract(which,cmdbuf,0);
177 if (!strncasecmp(which,"OLD",3)) mode = MSGS_OLD;
178 if (!strncasecmp(which,"NEW",3)) mode = MSGS_NEW;
179 if (!strncasecmp(which,"FIRST",5)) {
181 cm_howmany = extract_int(cmdbuf,1);
183 if (!strncasecmp(which,"LAST",4)) {
185 cm_howmany = extract_int(cmdbuf,1);
187 if (!strncasecmp(which,"GT",2)) {
189 cm_gt = extract_long(cmdbuf,1);
192 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
193 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
197 get_msglist(&CC->quickroom);
198 getuser(&CC->usersupp,CC->curr_user);
199 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
201 cprintf("%d Message list...\n",LISTING_FOLLOWS);
202 if (CC->num_msgs != 0) {
203 for (a=0; a<(CC->num_msgs); ++a)
204 if ((MessageFromList(a) >=0)
208 || ((mode==MSGS_OLD) && (MessageFromList(a) <= vbuf.v_lastseen))
209 || ((mode==MSGS_NEW) && (MessageFromList(a) > vbuf.v_lastseen))
210 || ((mode==MSGS_NEW) && (MessageFromList(a) >= vbuf.v_lastseen)
211 && (CC->usersupp.flags & US_LASTOLD))
212 || ((mode==MSGS_LAST)&& (a>=(CC->num_msgs-cm_howmany)))
213 || ((mode==MSGS_FIRST)&&(a<cm_howmany))
214 || ((mode==MSGS_GT) && (MessageFromList(a) > cm_gt))
218 cprintf("%ld\n", MessageFromList(a));
227 * help_subst() - support routine for help file viewer
229 void help_subst(char *strbuf, char *source, char *dest)
234 while (p=pattern2(strbuf,source), (p>=0)) {
235 strcpy(workbuf,&strbuf[p+strlen(source)]);
236 strcpy(&strbuf[p],dest);
237 strcat(strbuf,workbuf);
242 void do_help_subst(char *buffer)
246 help_subst(buffer,"^nodename",config.c_nodename);
247 help_subst(buffer,"^humannode",config.c_humannode);
248 help_subst(buffer,"^fqdn",config.c_fqdn);
249 help_subst(buffer,"^username",CC->usersupp.fullname);
250 sprintf(buf2,"%ld",CC->usersupp.usernum);
251 help_subst(buffer,"^usernum",buf2);
252 help_subst(buffer,"^sysadm",config.c_sysadm);
253 help_subst(buffer,"^variantname",CITADEL);
254 sprintf(buf2,"%d",config.c_maxsessions);
255 help_subst(buffer,"^maxsessions",buf2);
261 * memfmout() - Citadel text formatter and paginator.
262 * Although the original purpose of this routine was to format
263 * text to the reader's screen width, all we're really using it
264 * for here is to format text out to 80 columns before sending it
265 * to the client. The client software may reformat it again.
267 void memfmout(int width, char *mptr, char subst)
268 /* screen width to use */
269 /* where are we going to get our text from? */
270 /* nonzero if we should use hypertext mode */
279 strcpy(aaa,""); old=255;
281 c=1; /* c is the current pos */
284 while (ch=*mptr, ((ch!=0) && (strlen(buffer)<126) )) {
286 buffer[strlen(buffer)+1] = 0;
287 buffer[strlen(buffer)] = ch;
290 if (buffer[0]=='^') do_help_subst(buffer);
292 buffer[strlen(buffer)+1] = 0;
294 strcpy(buffer,&buffer[1]);
301 if (ch<=0) goto FMTEND;
303 if ( ((ch==13)||(ch==10)) && (old!=13) && (old!=10) ) ch=32;
304 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
308 if (ch>126) goto FMTA;
311 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
312 { cprintf("\n%s",aaa); c=strlen(aaa); aaa[0]=0;
314 b=strlen(aaa); aaa[b]=ch; aaa[b+1]=0; }
316 if ((strlen(aaa)+c)>(width-5)) {
320 cprintf("%s ",aaa); ++c; c=c+strlen(aaa);
324 if ((ch==13)||(ch==10)) {
332 FMTEND: cprintf("\n");
337 * Get a message off disk. (return value is the message's timestamp)
340 time_t output_message(char *msgid, int mode,
341 int headers_only, int desired_section) {
345 CIT_UBYTE format_type,anon_flag;
350 struct cdbdata *dmsgtext;
353 /* buffers needed for RFC822 translation */
362 msg_num = atol(msgid);
365 if ((!(CC->logged_in))&&(!(CC->internal_pgm))&&(mode!=MT_DATE)) {
366 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
370 /* We used to need to check in the current room's message list
371 * to determine where the message's disk position. We no longer need
372 * to do this, but we do it anyway as a security measure, in order to
373 * prevent rogue clients from reading messages not in the current room.
377 if (CC->num_msgs > 0) {
378 for (a=0; a<CC->num_msgs; ++a) {
379 if (MessageFromList(a) == msg_num) {
387 cprintf("%d Message %ld is not in this room.\n",
393 dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
395 if (dmsgtext == NULL) {
397 cprintf("%d Can't find message %ld\n",
398 ERROR+INTERNAL_ERROR);
402 msg_len = (long) dmsgtext->len;
403 mptr = dmsgtext->ptr;
405 /* this loop spews out the whole message if we're doing raw format */
406 if (mode == MT_RAW) {
407 cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
408 client_write(dmsgtext->ptr, (int) msg_len);
413 /* Otherwise, we'll start parsing it field by field... */
416 cprintf("%d Illegal message format on disk\n",
417 ERROR+INTERNAL_ERROR);
423 format_type = *mptr++;
425 /* Are we just looking for the message date? */
426 if (mode == MT_DATE) while(ch = *mptr++, (ch!='M' && ch!=0)) {
429 buf[strlen(buf)+1] = 0;
431 buf[strlen(buf)] = rch;
442 /* now for the user-mode message reading loops */
443 cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
445 if (mode == MT_CITADEL) cprintf("type=%d\n", format_type);
447 if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
448 cprintf("nhdr=yes\n");
451 /* begin header processing loop for Citadel message format */
453 if (mode == MT_CITADEL) while(ch = *mptr++, (ch!='M' && ch!=0)) {
456 buf[strlen(buf)+1] = 0;
458 buf[strlen(buf)] = rch;
462 PerformUserHooks(buf, (-1L), EVT_OUTPUTMSG);
463 if (anon_flag==MES_ANON) cprintf("from=****");
464 else if (anon_flag==MES_AN2) cprintf("from=anonymous");
465 else cprintf("from=%s",buf);
466 if ((is_room_aide()) && ((anon_flag == MES_ANON)
467 || (anon_flag == MES_AN2)))
468 cprintf(" [%s]",buf);
471 else if (ch=='P') cprintf("path=%s\n",buf);
472 else if (ch=='U') cprintf("subj=%s\n",buf);
473 else if (ch=='I') cprintf("msgn=%s\n",buf);
474 else if (ch=='H') cprintf("hnod=%s\n",buf);
475 else if (ch=='O') cprintf("room=%s\n",buf);
476 else if (ch=='N') cprintf("node=%s\n",buf);
477 else if (ch=='R') cprintf("rcpt=%s\n",buf);
478 else if (ch=='T') cprintf("time=%s\n",buf);
479 /* else cprintf("fld%c=%s\n",ch,buf); */
482 /* begin header processing loop for RFC822 transfer format */
486 strcpy(snode, NODENAME);
487 strcpy(lnode, HUMANNODE);
488 if (mode == MT_RFC822) while(ch = *mptr++, (ch!='M' && ch!=0)) {
491 buf[strlen(buf)+1] = 0;
493 buf[strlen(buf)] = rch;
496 if (ch=='A') strcpy(luser, buf);
498 cprintf("Path: %s\n",buf);
499 for (a=0; a<strlen(buf); ++a) {
501 strcpy(buf,&buf[a+1]);
507 else if (ch=='U') cprintf("Subject: %s\n",buf);
508 else if (ch=='I') strcpy(mid, buf);
509 else if (ch=='H') strcpy(lnode, buf);
510 else if (ch=='O') cprintf("X-Citadel-Room: %s\n",buf);
511 else if (ch=='N') strcpy(snode, buf);
512 else if (ch=='R') cprintf("To: %s\n",buf);
515 cprintf("Date: %s", asctime(localtime(&xtime)));
519 if (mode == MT_RFC822) {
520 if (!strcasecmp(snode, NODENAME)) {
523 cprintf("Message-ID: <%s@%s>\n", mid, snode);
524 PerformUserHooks(luser, (-1L), EVT_OUTPUTMSG);
525 cprintf("From: %s@%s (%s)\n",
526 suser, snode, luser);
527 cprintf("Organization: %s\n", lnode);
530 /* end header processing loop ... at this point, we're in the text */
533 cprintf("text\n*** ?Message truncated\n000\n");
539 /* give 'em a length */
541 while(ch = *mptr++, ch>0) {
544 cprintf("mlen=%ld\n", msg_len);
550 /* signify start of msg text */
551 if (mode == MT_CITADEL) cprintf("text\n");
552 if (mode == MT_RFC822) cprintf("\n");
554 /* If the format type on disk is 1 (fixed-format), then we want
555 * everything to be output completely literally ... regardless of
556 * what message transfer format is in use. Format type 4 is
557 * temporarily being output this way as well.
559 if ( (format_type == 1) || (format_type == 4)) {
561 while(ch = *mptr++, ch>0) {
562 if (ch == 13) ch = 10;
563 if ( (ch == 10) || (strlen(buf)>250) ) {
564 cprintf("%s\n", buf);
568 buf[strlen(buf)+1] = 0;
569 buf[strlen(buf)] = ch;
572 if (strlen(buf)>0) cprintf("%s\n", buf);
574 /* If the message on disk is format 0 (Citadel vari-format), we
575 * output using the formatter at 80 columns. This is the final output
576 * form if the transfer format is RFC822, but if the transfer format
577 * is Citadel proprietary, it'll still work, because the indentation
578 * for new paragraphs is correct and the client will reformat the
579 * message to the reader's screen width.
581 if (format_type == 0) {
594 * display a message (mode 0 - Citadel proprietary)
596 void cmd_msg0(char *cmdbuf)
599 int headers_only = 0;
600 int desired_section = 0;
602 extract(msgid,cmdbuf,0);
603 headers_only = extract_int(cmdbuf, 1);
604 desired_section = extract_int(cmdbuf, 2);
606 output_message(msgid, MT_CITADEL, headers_only, desired_section);
612 * display a message (mode 2 - RFC822)
614 void cmd_msg2(char *cmdbuf)
617 int headers_only = 0;
619 extract(msgid,cmdbuf,0);
620 headers_only = extract_int(cmdbuf,1);
622 output_message(msgid,MT_RFC822,headers_only,0);
626 * display a message (mode 3 - IGnet raw format - internal programs only)
628 void cmd_msg3(char *cmdbuf)
631 int headers_only = 0;
633 if (CC->internal_pgm == 0) {
634 cprintf("%d This command is for internal programs only.\n",
639 extract(msgid,cmdbuf,0);
640 headers_only = extract_int(cmdbuf,1);
642 output_message(msgid,MT_RAW,headers_only,0);
648 * Message base operation to send a message to the master file
649 * (returns new message number)
651 long send_message(char *message_in_memory, /* pointer to buffer */
652 size_t message_length, /* length of buffer */
653 int generate_id) { /* 1 to generate an I field */
656 char *actual_message;
657 size_t actual_length;
661 /* Get a new message number */
662 newmsgid = get_new_message_number();
665 sprintf(msgidbuf, "I%ld", newmsgid);
666 actual_length = message_length + strlen(msgidbuf) + 1;
667 actual_message = mallok(actual_length);
668 memcpy(actual_message, message_in_memory, 3);
669 memcpy(&actual_message[3], msgidbuf, (strlen(msgidbuf)+1) );
670 memcpy(&actual_message[strlen(msgidbuf)+4],
671 &message_in_memory[3], message_length - 3);
675 actual_message = message_in_memory;
676 actual_length = message_length;
679 /* Write our little bundle of joy into the message base */
680 begin_critical_section(S_MSGMAIN);
681 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
682 actual_message, actual_length) < 0 ) {
683 lprintf(2, "Can't store message\n");
689 end_critical_section(S_MSGMAIN);
692 phree(actual_message);
695 /* Finally, return the pointers */
702 * this is a simple file copy routine.
704 void copy_file(char *from, char *to)
710 if (ffp==NULL) return;
716 while (a=getc(ffp), a>=0) {
727 * message base operation to save a message and install its pointers
729 void save_message(char *mtmp, /* file containing proper message */
730 char *rec, /* Recipient (if mail) */
731 char *force_room, /* if non-zero length, force a room */
732 int mailtype, /* local or remote type, see citadel.h */
733 int generate_id) /* set to 1 to generate an 'I' field */
736 char hold_rm[ROOMNAMELEN];
737 char actual_rm[ROOMNAMELEN];
740 char *message_in_memory;
744 struct usersupp userbuf;
746 static int seqnum = 0;
748 lprintf(9, "save_message(%s,%s,%s,%d,%d)\n",
749 mtmp, rec, force_room, mailtype, generate_id);
751 /* Strip non-printable characters out of the recipient name */
752 strcpy(recipient, rec);
753 for (a=0; a<strlen(recipient); ++a)
754 if (!isprint(recipient[a]))
755 strcpy(&recipient[a], &recipient[a+1]);
757 /* Measure the message */
758 stat(mtmp, &statbuf);
759 templen = statbuf.st_size;
761 /* Now read it into memory */
762 message_in_memory = (char *) mallok(templen);
763 if (message_in_memory == NULL) {
764 lprintf(2, "Can't allocate memory to save message!\n");
768 fp = fopen(mtmp, "rb");
769 fread(message_in_memory, templen, 1, fp);
772 newmsgid = send_message(message_in_memory, templen, generate_id);
773 phree(message_in_memory);
774 if (newmsgid <= 0L) return;
776 strcpy(actual_rm, CC->quickroom.QRname);
779 /* If the user is a twit, move to the twit room for posting... */
780 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
781 strcpy(hold_rm, actual_rm);
782 strcpy(actual_rm, config.c_twitroom);
785 /* ...or if this is a private message, go to the target mailbox. */
786 if (strlen(recipient) > 0) {
787 /* mailtype = alias(recipient); */
788 if (mailtype == M_LOCAL) {
789 if (getuser(&userbuf, recipient)!=0) {
790 /* User not found, goto Aide */
791 strcpy(force_room, AIDEROOM);
794 strcpy(hold_rm, actual_rm);
795 MailboxName(actual_rm, &userbuf, MAILROOM);
800 /* ...or if this message is destined for Aide> then go there. */
801 if (strlen(force_room) > 0) {
802 strcpy(hold_rm, actual_rm);
803 strcpy(actual_rm, force_room);
806 /* This call to usergoto() changes rooms if necessary. It also
807 * causes the latest message list to be read into memory.
809 usergoto(actual_rm, 0);
811 /* read in the quickroom record, obtaining a lock... */
812 lgetroom(&CC->quickroom, actual_rm);
814 /* Fix an obscure bug */
815 if (!strcasecmp(CC->quickroom.QRname, AIDEROOM)) {
816 CC->quickroom.QRflags = CC->quickroom.QRflags & ~QR_MAILBOX;
819 /* Add the message pointer to the room */
820 CC->quickroom.QRhighest = AddMessageToRoom(&CC->quickroom, newmsgid);
822 /* update quickroom */
823 lputroom(&CC->quickroom, actual_rm);
825 /* Network mail - send a copy to the network program. */
826 if ( (strlen(recipient)>0) && (mailtype != M_LOCAL) ) {
827 sprintf(aaa,"./network/spoolin/netmail.%04x.%04x.%04x",
828 getpid(), CC->cs_pid, ++seqnum);
830 system("exec nohup ./netproc -i >/dev/null 2>&1 &");
833 /* Bump this user's messages posted counter. */
834 lgetuser(&CC->usersupp, CC->curr_user);
835 CC->usersupp.posted = CC->usersupp.posted + 1;
836 lputuser(&CC->usersupp, CC->curr_user);
838 /* If we've posted in a room other than the current room, then we
839 * have to now go back to the current room...
841 if (strlen(hold_rm) > 0) {
842 usergoto(hold_rm, 0);
844 unlink(mtmp); /* delete the temporary file */
849 * Generate an administrative message and post it in the Aide> room.
851 void aide_message(char *text)
855 fp=fopen(CC->temp,"wb");
856 fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
857 fprintf(fp,"Psysop%c",0);
858 fprintf(fp,"T%ld%c", time(NULL), 0);
859 fprintf(fp,"ACitadel%c",0);
860 fprintf(fp,"OAide%c",0);
861 fprintf(fp,"N%s%c",NODENAME,0);
862 fprintf(fp,"M%s\n%c",text,0);
864 save_message(CC->temp,"",AIDEROOM,M_LOCAL,1);
865 syslog(LOG_NOTICE,text);
871 * Build a binary message to be saved on disk.
874 char *filename, /* temporary file name */
875 struct usersupp *author, /* author's usersupp structure */
876 char *recipient, /* NULL if it's not mail */
877 char *room, /* room where it's going */
878 int type, /* see MES_ types in header file */
879 int net_type, /* see MES_ types in header file */
880 int format_type, /* local or remote (see citadel.h) */
881 char *fake_name) { /* who we're masquerading as */
889 /* Don't confuse the poor folks if it's not routed mail. */
890 strcpy(dest_node, "");
893 /* If net_type is M_BINARY, split out the destination node. */
894 if (net_type == M_BINARY) {
895 strcpy(dest_node,NODENAME);
896 for (a=0; a<strlen(recipient); ++a) {
897 if (recipient[a]=='@') {
899 strcpy(dest_node,&recipient[a+1]);
904 /* if net_type is M_INTERNET, set the dest node to 'internet' */
905 if (net_type == M_INTERNET) {
906 strcpy(dest_node,"internet");
909 while (isspace(recipient[strlen(recipient)-1]))
910 recipient[strlen(recipient)-1] = 0;
913 fp=fopen(filename,"w");
915 putc(type,fp); /* Normal or anonymous, see MES_ flags */
916 putc(format_type,fp); /* Formatted or unformatted */
917 fprintf(fp,"Pcit%ld%c",author->usernum,0); /* path */
918 fprintf(fp,"T%ld%c",now,0); /* date/time */
920 fprintf(fp,"A%s%c",fake_name,0);
922 fprintf(fp,"A%s%c",author->fullname,0); /* author */
924 if (CC->quickroom.QRflags & QR_MAILBOX) { /* room */
925 fprintf(fp,"O%s%c", &CC->quickroom.QRname[11], 0);
928 fprintf(fp,"O%s%c",CC->quickroom.QRname,0);
931 fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
932 fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
934 if (recipient[0]!=0) fprintf(fp, "R%s%c", recipient, 0);
935 if (dest_node[0]!=0) fprintf(fp, "D%s%c", dest_node, 0);
939 while (client_gets(buf), strcmp(buf,"000"))
941 fprintf(fp,"%s\n",buf);
943 syslog(LOG_INFO, "Closing message");
953 * message entry - mode 0 (normal) <bc>
955 void cmd_ent0(char *entargs)
961 char newusername[256]; /* <bc> */
966 struct usersupp tempUS;
969 post = extract_int(entargs,0);
970 extract(recipient,entargs,1);
971 anon_flag = extract_int(entargs,2);
972 format_type = extract_int(entargs,3);
974 /* first check to make sure the request is valid. */
976 if (!(CC->logged_in)) {
977 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
980 if ((CC->usersupp.axlevel<2)&&((CC->quickroom.QRflags&QR_MAILBOX)==0)) {
981 cprintf("%d Need to be validated to enter ",
982 ERROR+HIGHER_ACCESS_REQUIRED);
983 cprintf("(except in %s> to sysop)\n", MAILROOM);
986 if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
987 cprintf("%d Need net privileges to enter here.\n",
988 ERROR+HIGHER_ACCESS_REQUIRED);
991 if ((CC->usersupp.axlevel<6)&&(CC->quickroom.QRflags&QR_READONLY)) {
992 cprintf("%d Sorry, this is a read-only room.\n",
993 ERROR+HIGHER_ACCESS_REQUIRED);
1000 if (post==2) { /* <bc> */
1001 if (CC->usersupp.axlevel<6)
1003 cprintf("%d You don't have permission to do an aide post.\n",
1004 ERROR+HIGHER_ACCESS_REQUIRED);
1007 extract(newusername,entargs,4);
1008 bzero(CC->fake_postname, 32);
1009 strcpy(CC->fake_postname, newusername);
1010 cprintf("%d Ok\n",OK);
1014 CC->cs_flags |= CS_POSTING;
1017 if (CC->quickroom.QRflags & QR_MAILBOX) {
1018 if (CC->usersupp.axlevel>=2) {
1019 strcpy(buf,recipient);
1021 else strcpy(buf,"sysop");
1022 e=alias(buf); /* alias and mail type */
1023 if ((buf[0]==0) || (e==M_ERROR)) {
1024 cprintf("%d Unknown address - cannot send message.\n",
1025 ERROR+NO_SUCH_USER);
1028 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
1029 cprintf("%d Net privileges required for network mail.\n",
1030 ERROR+HIGHER_ACCESS_REQUIRED);
1033 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
1034 &&((CC->usersupp.flags&US_INTERNET)==0)
1035 &&(!CC->internal_pgm) ) {
1036 cprintf("%d You don't have access to Internet mail.\n",
1037 ERROR+HIGHER_ACCESS_REQUIRED);
1040 if (!strcasecmp(buf,"sysop")) {
1044 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
1045 if (!strcasecmp(buf,CC->usersupp.fullname)) {
1046 cprintf("%d Can't send mail to yourself!\n",
1047 ERROR+NO_SUCH_USER);
1051 /* Check to make sure the user exists; also get the correct
1052 * upper/lower casing of the name.
1054 a = getuser(&tempUS,buf);
1056 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1059 strcpy(buf,tempUS.fullname);
1062 SKFALL: b=MES_NORMAL;
1063 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1064 if (CC->quickroom.QRflags&QR_ANONOPT) {
1065 if (anon_flag==1) b=MES_AN2;
1067 if ((CC->quickroom.QRflags & QR_MAILBOX) == 0) buf[0]=0;
1069 /* If we're only checking the validity of the request, return
1070 * success without creating the message.
1073 cprintf("%d %s\n",OK,buf);
1077 cprintf("%d send message\n",SEND_LISTING);
1078 if (CC->fake_postname[0])
1079 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname);
1081 if (CC->fake_username[0])
1082 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username);
1084 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "");
1085 save_message(CC->temp,buf, (mtsflag ? AIDEROOM : ""), e,1);
1086 CC->fake_postname[0]='\0';
1093 * message entry - mode 3 (raw)
1095 void cmd_ent3(char *entargs)
1101 struct usersupp tempUS;
1106 if (CC->internal_pgm == 0) {
1107 cprintf("%d This command is for internal programs only.\n",
1112 /* See if there's a recipient, but make sure it's a real one */
1113 extract(recp, entargs, 1);
1114 for (a=0; a<strlen(recp); ++a)
1115 if (!isprint(recp[a]))
1116 strcpy(&recp[a], &recp[a+1]);
1117 while (isspace(recp[0])) strcpy(recp, &recp[1]);
1118 while (isspace(recp[strlen(recp)-1])) recp[strlen(recp)-1] = 0;
1120 /* If we're in Mail, check the recipient */
1121 if (strlen(recp) > 0) {
1122 e=alias(recp); /* alias and mail type */
1123 if ((recp[0]==0) || (e==M_ERROR)) {
1124 cprintf("%d Unknown address - cannot send message.\n",
1125 ERROR+NO_SUCH_USER);
1129 a = getuser(&tempUS,recp);
1131 cprintf("%d No such user.\n",
1132 ERROR+NO_SUCH_USER);
1138 /* At this point, message has been approved. */
1139 if (extract_int(entargs, 0) == 0) {
1140 cprintf("%d OK to send\n", OK);
1144 /* open a temp file to hold the message */
1145 fp = fopen(CC->temp, "wb");
1147 cprintf("%d Cannot open %s: %s\n",
1148 ERROR + INTERNAL_ERROR,
1149 CC->temp, strerror(errno) );
1153 msglen = extract_long(entargs, 2);
1154 cprintf("%d %ld\n", SEND_BINARY, msglen);
1155 while(msglen > 0L) {
1156 bloklen = ((msglen >= 255L) ? 255 : msglen);
1157 client_read(buf, (int)bloklen );
1158 fwrite(buf, (int)bloklen, 1, fp);
1159 msglen = msglen - bloklen;
1163 save_message(CC->temp, recp, "", e, 0);
1168 * Delete message from current room
1170 void cmd_dele(char *delstr)
1175 getuser(&CC->usersupp,CC->curr_user);
1176 if ((CC->usersupp.axlevel < 6)
1177 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)
1178 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0)) {
1179 cprintf("%d Higher access required.\n",
1180 ERROR+HIGHER_ACCESS_REQUIRED);
1184 delnum = extract_long(delstr, 0);
1186 /* get room records, obtaining a lock... */
1187 lgetroom(&CC->quickroom,CC->quickroom.QRname);
1188 get_msglist(&CC->quickroom);
1191 if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
1192 if (MessageFromList(a) == delnum) {
1193 SetMessageInList(a, 0L);
1198 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1199 CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
1201 put_msglist(&CC->quickroom);
1202 lputroom(&CC->quickroom,CC->quickroom.QRname);
1204 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1205 cprintf("%d Message deleted.\n",OK);
1207 else cprintf("%d No message %ld.\n",ERROR,delnum);
1212 * move a message to another room
1214 void cmd_move(char *args)
1219 struct quickroom qtemp;
1222 num = extract_long(args,0);
1223 extract(targ,args,1);
1225 getuser(&CC->usersupp,CC->curr_user);
1226 if ((CC->usersupp.axlevel < 6)
1227 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1228 cprintf("%d Higher access required.\n",
1229 ERROR+HIGHER_ACCESS_REQUIRED);
1233 if (getroom(&qtemp, targ) != 0) {
1234 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1238 /* yank the message out of the current room... */
1239 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1240 get_msglist(&CC->quickroom);
1243 for (a=0; a<(CC->num_msgs); ++a) {
1244 if (MessageFromList(a) == num) {
1246 SetMessageInList(a, 0L);
1250 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1251 put_msglist(&CC->quickroom);
1252 CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
1254 lputroom(&CC->quickroom,CC->quickroom.QRname);
1256 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1260 /* put the message into the target room */
1261 lgetroom(&qtemp, targ);
1262 qtemp.QRhighest = AddMessageToRoom(&qtemp, num);
1263 lputroom(&qtemp, targ);
1265 cprintf("%d Message moved.\n", OK);