17 #include "sysdep_decls.h"
21 #include "dynloader.h"
30 extern struct config config;
35 * Aliasing for network mail.
36 * (Error messages have been commented out, because this is a server.)
38 int alias(char *name) /* process alias and routing info for mail */
42 char aaa[300],bbb[300];
44 fp=fopen("network/mail.aliases","r");
45 if (fp==NULL) fp=fopen("/dev/null","r");
46 if (fp==NULL) return(M_ERROR);
47 GNA: strcpy(aaa,""); strcpy(bbb,"");
70 if (strcasecmp(name,aaa)) goto GNA;
73 lprintf(7, "Mail is being forwarded to %s\n", name);
75 DETYPE: /* determine local or remote type, see citadel.h */
76 for (a=0; a<strlen(name); ++a) if (name[a]=='!') return(M_INTERNET);
77 for (a=0; a<strlen(name); ++a)
79 for (b=a; b<strlen(name); ++b)
80 if (name[b]=='.') return(M_INTERNET);
81 b=0; for (a=0; a<strlen(name); ++a) if (name[a]=='@') ++b;
83 lprintf(7, "Too many @'s in address\n");
87 for (a=0; a<strlen(name); ++a)
88 if (name[a]=='@') strcpy(bbb,&name[a+1]);
89 while (bbb[0]==32) strcpy(bbb,&bbb[1]);
90 fp = fopen("network/mail.sysinfo","r");
91 if (fp==NULL) return(M_ERROR);
94 } while ((a>=0)&&(strcasecmp(aaa,bbb)));
96 if (!strncmp(aaa,"use ",4)) {
102 if (!strncmp(aaa,"uum",3)) {
104 for (a=0; a<strlen(bbb); ++a) {
105 if (bbb[a]=='@') bbb[a]=0;
106 if (bbb[a]==' ') bbb[a]='_';
108 while(bbb[strlen(bbb)-1]=='_') bbb[strlen(bbb)-1]=0;
109 sprintf(name,&aaa[4],bbb);
112 if (!strncmp(aaa,"bin",3)) {
113 strcpy(aaa,name); strcpy(bbb,name);
114 while (aaa[strlen(aaa)-1]!='@') aaa[strlen(aaa)-1]=0;
115 aaa[strlen(aaa)-1]=0;
116 while (aaa[strlen(aaa)-1]==' ') aaa[strlen(aaa)-1]=0;
117 while (bbb[0]!='@') strcpy(bbb,&bbb[1]);
119 while (bbb[0]==' ') strcpy(bbb,&bbb[1]);
120 sprintf(name,"%s @%s",aaa,bbb);
132 fp=fopen("citadel.control","r");
133 fread((char *)&CitControl,sizeof(struct CitControl),1,fp);
138 * cmd_msgs() - get list of message #'s in this room
140 void cmd_msgs(char *cmdbuf)
148 extract(which,cmdbuf,0);
152 if (!strncasecmp(which,"OLD",3)) mode = MSGS_OLD;
153 if (!strncasecmp(which,"NEW",3)) mode = MSGS_NEW;
154 if (!strncasecmp(which,"FIRST",5)) {
156 cm_howmany = extract_int(cmdbuf,1);
158 if (!strncasecmp(which,"LAST",4)) {
160 cm_howmany = extract_int(cmdbuf,1);
162 if (!strncasecmp(which,"GT",2)) {
164 cm_gt = extract_long(cmdbuf,1);
167 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
168 cprintf("%d not logged in\n",ERROR+NOT_LOGGED_IN);
171 if (CC->curr_rm < 0) {
172 cprintf("%d no room\n",ERROR);
176 get_msglist(CC->curr_rm);
177 getuser(&CC->usersupp,CC->curr_user);
178 cprintf("%d %d messages...\n",LISTING_FOLLOWS, CC->num_msgs);
179 if (CC->num_msgs != 0) {
180 for (a=0; a<(CC->num_msgs); ++a)
181 if ((MessageFromList(a) >=0)
185 || ((mode==MSGS_OLD) && (MessageFromList(a) <= CC->usersupp.lastseen[CC->curr_rm]))
186 || ((mode==MSGS_NEW) && (MessageFromList(a) > CC->usersupp.lastseen[CC->curr_rm]))
187 || ((mode==MSGS_NEW) && (MessageFromList(a) >= CC->usersupp.lastseen[CC->curr_rm])
188 && (CC->usersupp.flags & US_LASTOLD))
189 || ((mode==MSGS_LAST)&& (a>=(CC->num_msgs-cm_howmany)))
190 || ((mode==MSGS_FIRST)&&(a<cm_howmany))
191 || ((mode==MSGS_GT) && (MessageFromList(a) > cm_gt))
195 cprintf("%ld\n", MessageFromList(a));
204 * help_subst() - support routine for help file viewer
206 void help_subst(char *strbuf, char *source, char *dest)
211 while (p=pattern2(strbuf,source), (p>=0)) {
212 strcpy(workbuf,&strbuf[p+strlen(source)]);
213 strcpy(&strbuf[p],dest);
214 strcat(strbuf,workbuf);
219 void do_help_subst(char *buffer)
223 help_subst(buffer,"^nodename",config.c_nodename);
224 help_subst(buffer,"^humannode",config.c_humannode);
225 help_subst(buffer,"^fqdn",config.c_fqdn);
226 help_subst(buffer,"^username",CC->usersupp.fullname);
227 sprintf(buf2,"%ld",CC->usersupp.usernum);
228 help_subst(buffer,"^usernum",buf2);
229 help_subst(buffer,"^sysadm",config.c_sysadm);
230 help_subst(buffer,"^variantname",CITADEL);
231 sprintf(buf2,"%d",config.c_maxsessions);
232 help_subst(buffer,"^maxsessions",buf2);
238 * memfmout() - Citadel text formatter and paginator.
239 * Although the original purpose of this routine was to format
240 * text to the reader's screen width, all we're really using it
241 * for here is to format text out to 80 columns before sending it
242 * to the client. The client software may reformat it again.
244 void memfmout(int width, char *mptr, char subst)
245 /* screen width to use */
246 /* where are we going to get our text from? */
247 /* nonzero if we should use hypertext mode */
254 strcpy(aaa,""); old=255;
256 c=1; /* c is the current pos */
259 while (ch=*mptr, ((ch!=0) && (strlen(buffer)<126) )) {
261 buffer[strlen(buffer)+1] = 0;
262 buffer[strlen(buffer)] = ch;
265 if (buffer[0]=='^') do_help_subst(buffer);
267 buffer[strlen(buffer)+1] = 0;
269 strcpy(buffer,&buffer[1]);
276 if (ch<=0) goto FMTEND;
278 if ( ((ch==13)||(ch==10)) && (old!=13) && (old!=10) ) ch=32;
279 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
283 if (ch>126) goto FMTA;
286 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
287 { cprintf("\n%s",aaa); c=strlen(aaa); aaa[0]=0;
289 b=strlen(aaa); aaa[b]=ch; aaa[b+1]=0; }
291 if ((strlen(aaa)+c)>(width-5)) {
295 cprintf("%s ",aaa); ++c; c=c+strlen(aaa);
299 if ((ch==13)||(ch==10)) {
307 FMTEND: cprintf("\n");
312 * get a message off disk.
315 void output_message(char *msgid, int mode,
316 int headers_only, int desired_section) {
320 CIT_UBYTE format_type,anon_flag;
324 char boundary[256]; /* attachment boundary */
325 char current_section = 0; /* section currently being parsed */
326 int has_attachments = 0;
328 struct cdbdata *dmsgtext;
331 /* buffers needed for RFC822 translation */
340 strcpy(boundary, "");
341 msg_num = atol(msgid);
344 if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
345 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
348 if (CC->curr_rm < 0) {
349 cprintf("%d No room selected.\n",ERROR);
353 /* We used to need to check in the current room's message list
354 * to determine where the message's disk position. We no longer need
355 * to do this, but we do it anyway as a security measure, in order to
356 * prevent rogue clients from reading messages not in the current room.
360 if (CC->num_msgs > 0) {
361 for (a=0; a<CC->num_msgs; ++a) {
362 if (MessageFromList(a) == msg_num) {
369 cprintf("%d Message %ld is not in this room.\n",
375 dmsgtext = cdb_fetch(CDB_MSGMAIN, &msg_num, sizeof(long));
377 if (dmsgtext == NULL) {
378 cprintf("%d Can't find message %ld\n", ERROR+INTERNAL_ERROR);
382 msg_len = (long) dmsgtext->len;
383 mptr = dmsgtext->ptr;
384 lprintf(9, "Returned message length is %ld\n", msg_len);
386 /* this loop spews out the whole message if we're doing raw format */
387 if (mode == MT_RAW) {
388 cprintf("%d %ld\n", BINARY_FOLLOWS, msg_len);
389 client_write(dmsgtext->ptr, (int) msg_len);
394 /* Otherwise, we'll start parsing it field by field... */
397 cprintf("%d Illegal message format on disk\n",
398 ERROR+INTERNAL_ERROR);
404 format_type = *mptr++;
406 /* now for the user-mode message reading loops */
407 cprintf("%d Message %ld:\n",LISTING_FOLLOWS,msg_num);
409 if (mode == MT_CITADEL) cprintf("type=%d\n",format_type);
411 if ( (anon_flag == MES_ANON) && (mode == MT_CITADEL) ) {
412 cprintf("nhdr=yes\n");
415 /* begin header processing loop for Citadel message format */
417 if (mode == MT_CITADEL) while(ch = *mptr++, (ch!='M' && ch!=0)) {
420 buf[strlen(buf)+1] = 0;
422 buf[strlen(buf)] = rch;
426 PerformUserHooks(buf, (-1L), EVT_OUTPUTMSG);
427 if (anon_flag==MES_ANON) cprintf("from=****");
428 else if (anon_flag==MES_AN2) cprintf("from=anonymous");
429 else cprintf("from=%s",buf);
430 if ((is_room_aide()) && ((anon_flag == MES_ANON)
431 || (anon_flag == MES_AN2)))
432 cprintf(" [%s]",buf);
437 sprintf(boundary, "--%s", buf);
439 else if (ch=='P') cprintf("path=%s\n",buf);
440 else if (ch=='U') cprintf("subj=%s\n",buf);
441 else if (ch=='I') cprintf("msgn=%s\n",buf);
442 else if (ch=='H') cprintf("hnod=%s\n",buf);
443 else if (ch=='O') cprintf("room=%s\n",buf);
444 else if (ch=='N') cprintf("node=%s\n",buf);
445 else if (ch=='R') cprintf("rcpt=%s\n",buf);
446 else if (ch=='T') cprintf("time=%s\n",buf);
447 /* else cprintf("fld%c=%s\n",ch,buf); */
450 /* begin header processing loop for RFC822 transfer format */
454 strcpy(snode, NODENAME);
455 strcpy(lnode, HUMANNODE);
456 if (mode == MT_RFC822) while(ch = *mptr++, (ch!='M' && ch!=0)) {
459 buf[strlen(buf)+1] = 0;
461 buf[strlen(buf)] = rch;
464 if (ch=='A') strcpy(luser, buf);
466 cprintf("Path: %s\n",buf);
467 for (a=0; a<strlen(buf); ++a) {
469 strcpy(buf,&buf[a+1]);
475 else if (ch=='U') cprintf("Subject: %s\n",buf);
476 else if (ch=='I') strcpy(mid, buf);
477 else if (ch=='H') strcpy(lnode, buf);
478 else if (ch=='O') cprintf("X-Citadel-Room: %s\n",buf);
479 else if (ch=='N') strcpy(snode, buf);
480 else if (ch=='R') cprintf("To: %s\n",buf);
483 cprintf("Date: %s", asctime(localtime(&xtime)));
487 if (mode == MT_RFC822) {
488 if (!strcasecmp(snode, NODENAME)) {
491 cprintf("Message-ID: <%s@%s>\n", mid, snode);
492 PerformUserHooks(luser, (-1L), EVT_OUTPUTMSG);
493 cprintf("From: %s@%s (%s)\n",
494 suser, snode, luser);
495 cprintf("Organization: %s\n", lnode);
498 /* end header processing loop ... at this point, we're in the text */
501 cprintf("text\n*** ?Message truncated\n000\n");
507 /* give 'em a length */
509 while(ch = *mptr++, ch>0) {
512 cprintf("mlen=%ld\n", msg_len);
518 /* signify start of msg text */
519 if (mode == MT_CITADEL) cprintf("text\n");
520 if (mode == MT_RFC822) cprintf("\n");
522 /* If the format type on disk is 1 (fixed-format), then we want
523 * everything to be output completely literally ... regardless of
524 * what message transfer format is in use.
526 if (format_type == 1) {
528 while(ch = *mptr++, ch>0) {
529 if (ch == 13) ch = 10;
530 if ( (ch == 10) || (strlen(buf)>250) ) {
531 if (has_attachments) if (!strncmp(buf, boundary, strlen(boundary))) {
534 if (current_section == desired_section) {
535 if ( (has_attachments == 0) || (strncmp(buf, boundary, strlen(boundary)))) {
536 cprintf("%s\n", buf);
542 buf[strlen(buf)+1] = 0;
543 buf[strlen(buf)] = ch;
546 if (strlen(buf)>0) cprintf("%s\n", buf);
548 /* If the message on disk is format 0 (Citadel vari-format), we
549 * output using the formatter at 80 columns. This is the final output
550 * form if the transfer format is RFC822, but if the transfer format
551 * is Citadel proprietary, it'll still work, because the indentation
552 * for new paragraphs is correct and the client will reformat the
553 * message to the reader's screen width.
555 if (format_type == 0) {
567 * display a message (mode 0 - Citadel proprietary)
569 void cmd_msg0(char *cmdbuf)
572 int headers_only = 0;
573 int desired_section = 0;
575 extract(msgid,cmdbuf,0);
576 headers_only = extract_int(cmdbuf, 1);
577 desired_section = extract_int(cmdbuf, 2);
579 output_message(msgid,MT_CITADEL, headers_only, desired_section);
584 * display a message (mode 2 - RFC822)
586 void cmd_msg2(char *cmdbuf)
589 int headers_only = 0;
591 extract(msgid,cmdbuf,0);
592 headers_only = extract_int(cmdbuf,1);
594 output_message(msgid,MT_RFC822,headers_only,0);
598 * display a message (mode 3 - IGnet raw format - internal programs only)
600 void cmd_msg3(char *cmdbuf)
603 int headers_only = 0;
605 if (CC->internal_pgm == 0) {
606 cprintf("%d This command is for internal programs only.\n",
611 extract(msgid,cmdbuf,0);
612 headers_only = extract_int(cmdbuf,1);
614 output_message(msgid,MT_RAW,headers_only,0);
620 * Message base operation to send a message to the master file
621 * (returns new message number)
623 long send_message(char *message_in_memory, /* pointer to buffer */
624 size_t message_length, /* length of buffer */
625 int generate_id) { /* 1 to generate an I field */
629 /* Get a new message number */
630 newmsgid = get_new_message_number();
632 /* Write our little bundle of joy into the message base */
634 lprintf(9, "Storing message %ld\n", newmsgid);
635 begin_critical_section(S_MSGMAIN);
636 if ( cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long),
637 message_in_memory, message_length) < 0 ) {
638 lprintf(2, "Can't store message\n");
639 end_critical_section(S_MSGMAIN);
642 end_critical_section(S_MSGMAIN);
644 /* Finally, return the pointers */
653 void loadtroom(void) {
654 struct quickroom qrbuf;
658 /* first try to locate the twit room */
659 for (a=0; a<MAXROOMS; ++a) {
661 if (!strcasecmp(qrbuf.QRname,config.c_twitroom)) {
667 /* if not found, try to create it - put it in the last slot */
668 twitroom = get_free_room_slot(-1);
670 newflags = create_room(twitroom,config.c_twitroom,0,"",0);
674 /* as a last resort, point to Aide> */
680 * this is a simple file copy routine.
682 void copy_file(char *from, char *to)
688 if (ffp==NULL) return;
694 while (a=getc(ffp), a>=0) {
705 * message base operation to save a message and install its pointers
707 void save_message(char *mtmp, /* file containing proper message */
708 char *rec, /* Recipient (if mail) */
709 char mtsflag, /* 0 for normal, 1 to force Aide> room */
710 int mailtype, /* local or remote type, see citadel.h */
711 int generate_id) /* set to 1 to generate an 'I' field */
713 struct usersupp tempUS;
716 struct cdbdata *cdbmb;
720 char *message_in_memory;
725 /* Measure the message */
726 lprintf(9, "Measuring the message\n");
727 stat(mtmp, &statbuf);
728 templen = statbuf.st_size;
730 /* Now read it into memory */
731 lprintf(9, "Allocating %ld bytes\n", templen);
732 message_in_memory = (char *) malloc(templen);
733 if (message_in_memory == NULL) {
734 lprintf(2, "Can't allocate memory to save message!\n");
738 lprintf(9, "Reading it into memory\n");
739 fp = fopen(mtmp, "rb");
740 fread(message_in_memory, templen, 1, fp);
743 newmsgid = send_message(message_in_memory, templen, generate_id);
744 free(message_in_memory);
745 if (newmsgid <= 0L) return;
748 /* If the user is a twit, move to the twit room for posting... */
749 if (TWITDETECT) if (CC->usersupp.axlevel==2) {
750 if (twitroom<0) loadtroom();
752 CC->curr_rm=twitroom;
755 /* ...or if this message is destined for Aide> then go there. */
761 /* This call to usergoto() changes rooms if necessary. It also
762 * causes the latest message list to be read into memory.
764 usergoto(CC->curr_rm,0);
766 /* Store the message pointer, but NOT for sent mail! */
767 if (CC->curr_rm != 1) {
769 /* read in the quickroom record, obtaining a lock... */
770 lgetroom(&CC->quickroom,CC->curr_rm);
771 get_msglist(CC->curr_rm);
773 /* FIX here's where we have to to message expiry!! */
775 /* Now add the new message */
776 CC->num_msgs = CC->num_msgs + 1;
777 CC->msglist = realloc(CC->msglist,
778 ((CC->num_msgs) * sizeof(long)) );
779 if (CC->msglist == NULL) {
780 lprintf(3, "ERROR can't realloc message list!\n");
782 SetMessageInList(CC->num_msgs - 1, newmsgid);
784 /* Write it back to disk. */
785 put_msglist(CC->curr_rm);
787 /* update quickroom */
788 CC->quickroom.QRhighest = newmsgid;
789 lputroom(&CC->quickroom,CC->curr_rm);
792 /* Bump this user's messages posted counter. Also, if the user is a
793 * twit, give them access to the twit room.
795 lgetuser(&CC->usersupp,CC->curr_user);
796 CC->usersupp.posted = CC->usersupp.posted + 1;
797 if (CC->curr_rm==twitroom) {
798 CC->usersupp.generation[twitroom] = CC->quickroom.QRgen;
800 lputuser(&CC->usersupp, CC->curr_user);
802 /* If mail, there's still more to do, if not, skip it. */
803 if ((CC->curr_rm!=1)||(mtsflag)) goto ENTFIN;
805 /* Network mail - send a copy to the network program. */
806 if (mailtype!=M_LOCAL) {
807 sprintf(aaa,"./network/spoolin/nm.%d",getpid());
809 system("exec nohup ./netproc >/dev/null 2>&1 &");
812 /* Local mail - put a copy in the recipient's mailbox. */
813 /* FIX here's where we have to handle expiry, stuffed boxes, etc. */
814 if (mailtype == M_LOCAL) {
815 if (lgetuser(&tempUS,rec)==0) {
817 cdbmb = cdb_fetch(CDB_MAILBOXES,
818 &tempUS.usernum, sizeof(long));
820 memcpy(dmailbox, cdbmb->ptr, cdbmb->len);
821 dnum_mails = cdbmb->len / sizeof(long);
830 if (dmailbox == NULL) {
831 dmailbox = malloc(sizeof(long) * dnum_mails);
834 dmailbox = realloc(dmailbox,
835 sizeof(long) * dnum_mails);
838 dmailbox[dnum_mails - 1] = newmsgid;
839 cdb_store(CDB_MAILBOXES, &tempUS.usernum, sizeof(long),
840 dmailbox, (dnum_mails * sizeof(long)) );
841 lputuser(&tempUS,rec);
846 /* If we've posted in a room other than the current room, then we
847 * have to now go back to the current room...
849 ENTFIN: if (hold_rm!=(-1)) {
852 unlink(mtmp); /* delete the temporary file */
857 * Generate an administrative message and post it in the Aide> room.
859 void aide_message(char *text)
865 fp=fopen(CC->temp,"wb");
866 fprintf(fp,"%c%c%c",255,MES_NORMAL,0);
867 fprintf(fp,"Psysop%c",0);
868 fprintf(fp,"T%ld%c",now,0);
869 fprintf(fp,"ACitadel%c",0);
870 fprintf(fp,"OAide%c",0);
871 fprintf(fp,"N%s%c",NODENAME,0);
872 fprintf(fp,"M%s\n%c",text,0);
874 save_message(CC->temp,"",1,M_LOCAL,1);
875 syslog(LOG_NOTICE,text);
881 * Build a binary message to be saved on disk.
884 char *filename, /* temporary file name */
885 struct usersupp *author, /* author's usersupp structure */
886 char *recipient, /* NULL if it's not mail */
887 char *room, /* room where it's going */
888 int type, /* see MES_ types in header file */
889 int net_type, /* see MES_ types in header file */
890 int format_type, /* local or remote (see citadel.h) */
891 char *fake_name, /* who we're masquerading as */
892 char *boundary) { /* boundary (if exist attachments) */
900 /* Don't confuse the poor folks if it's not routed mail. */
901 strcpy(dest_node, "");
903 /* If net_type is M_BINARY, split out the destination node. */
904 if (net_type == M_BINARY) {
905 strcpy(dest_node,NODENAME);
906 for (a=0; a<strlen(recipient); ++a) {
907 if (recipient[a]=='@') {
909 strcpy(dest_node,&recipient[a+1]);
914 /* if net_type is M_INTERNET, set the dest node to 'internet' */
915 if (net_type == M_INTERNET) {
916 strcpy(dest_node,"internet");
919 while (isspace(recipient[strlen(recipient)-1]))
920 recipient[strlen(recipient)-1] = 0;
923 fp=fopen(filename,"w");
925 putc(type,fp); /* Normal or anonymous, see MES_ flags */
926 putc(format_type,fp); /* Formatted or unformatted */
927 fprintf(fp,"Pcit%ld%c",author->usernum,0); /* path */
928 fprintf(fp,"T%ld%c",now,0); /* date/time */
930 fprintf(fp,"A%s%c",fake_name,0);
932 fprintf(fp,"A%s%c",author->fullname,0); /* author */
933 fprintf(fp,"O%s%c",CC->quickroom.QRname,0); /* room */
934 fprintf(fp,"N%s%c",NODENAME,0); /* nodename */
935 fprintf(fp,"H%s%c",HUMANNODE,0); /* human nodename */
937 if (recipient[0]!=0) fprintf(fp, "R%s%c", recipient, 0);
938 if (dest_node[0]!=0) fprintf(fp, "D%s%c", dest_node, 0);
939 if (boundary[0]!=0) fprintf(fp, "Z%s%c", boundary, 0);
943 while (client_gets(buf), strcmp(buf,"000"))
945 fprintf(fp,"%s\n",buf);
947 syslog(LOG_INFO, "Closing message");
957 * message entry - mode 0 (normal) <bc>
959 void cmd_ent0(char *entargs)
965 char newusername[256]; /* <bc> */
970 struct usersupp tempUS;
973 post = extract_int(entargs,0);
974 extract(recipient,entargs,1);
975 anon_flag = extract_int(entargs,2);
976 format_type = extract_int(entargs,3);
977 extract(boundary, entargs, 5);
979 /* first check to make sure the request is valid. */
981 if (!(CC->logged_in)) {
982 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
985 if (CC->curr_rm < 0) {
986 cprintf("%d No room selected.\n",ERROR);
989 if ((CC->usersupp.axlevel<2)&&(CC->curr_rm!=1)) {
990 cprintf("%d Need to be validated to enter (except in Mail> to sysop)\n",
991 ERROR+HIGHER_ACCESS_REQUIRED);
994 if ((CC->usersupp.axlevel<4)&&(CC->quickroom.QRflags&QR_NETWORK)) {
995 cprintf("%d Need net privileges to enter here.\n",
996 ERROR+HIGHER_ACCESS_REQUIRED);
999 if ((CC->usersupp.axlevel<6)&&(CC->quickroom.QRflags&QR_READONLY)) {
1000 cprintf("%d Sorry, this is a read-only room.\n",
1001 ERROR+HIGHER_ACCESS_REQUIRED);
1008 if (post==2) { /* <bc> */
1009 if (CC->usersupp.axlevel<6)
1011 cprintf("%d\nYou don't have sufficient permission to do an aide post.\n", ERROR+HIGHER_ACCESS_REQUIRED);
1014 extract(newusername,entargs,4);
1015 bzero(CC->fake_postname, 32);
1016 strcpy(CC->fake_postname, newusername);
1017 cprintf("%d Ok\n",OK);
1021 CC->cs_flags |= CS_POSTING;
1024 if (CC->curr_rm==1) {
1025 if (CC->usersupp.axlevel>=2) {
1026 strcpy(buf,recipient);
1028 else strcpy(buf,"sysop");
1029 lprintf(9, "aliasing...\n");
1030 e=alias(buf); /* alias and mail type */
1031 lprintf(9,"...type is %d\n", e);
1032 if ((buf[0]==0) || (e==M_ERROR)) {
1033 cprintf("%d Unknown address - cannot send message.\n",
1034 ERROR+NO_SUCH_USER);
1037 if ((e!=M_LOCAL)&&(CC->usersupp.axlevel<4)) {
1038 cprintf("%d Net privileges required for network mail.\n",
1039 ERROR+HIGHER_ACCESS_REQUIRED);
1042 if ((RESTRICT_INTERNET==1)&&(e==M_INTERNET)
1043 &&((CC->usersupp.flags&US_INTERNET)==0)
1044 &&(!CC->internal_pgm) ) {
1045 cprintf("%d You don't have access to Internet mail.\n",
1046 ERROR+HIGHER_ACCESS_REQUIRED);
1049 if (!strcasecmp(buf,"sysop")) {
1053 if (e!=M_LOCAL) goto SKFALL; /* don't search local file */
1054 if (!strcasecmp(buf,CC->usersupp.fullname)) {
1055 cprintf("%d Can't send mail to yourself!\n",
1056 ERROR+NO_SUCH_USER);
1060 /* Check to make sure the user exists; also get the correct
1061 * upper/lower casing of the name.
1063 lprintf(9, "checking validity of %s\n", buf);
1064 a = getuser(&tempUS,buf);
1065 lprintf(9, "getuser() returned %d\n", a);
1067 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
1070 strcpy(buf,tempUS.fullname);
1073 SKFALL: b=MES_NORMAL;
1074 if (CC->quickroom.QRflags&QR_ANONONLY) b=MES_ANON;
1075 if (CC->quickroom.QRflags&QR_ANON2) {
1076 if (anon_flag==1) b=MES_AN2;
1078 if (CC->curr_rm!=1) buf[0]=0;
1080 /* If we're only checking the validity of the request, return
1081 * success without creating the message.
1084 cprintf("%d %s\n",OK,buf);
1088 cprintf("%d send message\n",SEND_LISTING);
1089 if (CC->fake_postname[0])
1090 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_postname, boundary);
1092 if (CC->fake_username[0])
1093 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, CC->fake_username, boundary);
1095 make_message(CC->temp,&CC->usersupp,buf,CC->quickroom.QRname,b,e,format_type, "", boundary);
1096 save_message(CC->temp,buf,mtsflag,e,1);
1097 CC->fake_postname[0]='\0';
1104 * message entry - mode 3 (raw)
1106 void cmd_ent3(char *entargs)
1111 struct usersupp tempUS;
1116 if (CC->internal_pgm == 0) {
1117 cprintf("%d This command is for internal programs only.\n",
1122 if (CC->curr_rm < 0) {
1123 cprintf("%d No room selected.\n",ERROR);
1127 if (CC->curr_rm == 1) { /* If we're in Mail, check the recipient */
1128 extract(recp, entargs, 1);
1129 lprintf(9, "aliasing...\n");
1130 e=alias(recp); /* alias and mail type */
1131 lprintf(9,"...type is %d\n", e);
1132 if ((buf[0]==0) || (e==M_ERROR)) {
1133 cprintf("%d Unknown address - cannot send message.\n",
1134 ERROR+NO_SUCH_USER);
1138 a = getuser(&tempUS,recp);
1140 cprintf("%d No such user.\n", ERROR+NO_SUCH_USER);
1146 /* At this point, message has been approved. */
1147 if (extract_int(entargs, 0) == 0) {
1148 cprintf("%d OK to send\n", OK);
1152 /* open a temp file to hold the message */
1153 fp = fopen(CC->temp, "wb");
1155 cprintf("%d Cannot open %s: %s\n",
1156 ERROR + INTERNAL_ERROR,
1157 CC->temp, strerror(errno) );
1161 msglen = extract_long(entargs, 2);
1162 cprintf("%d %ld\n", SEND_BINARY, msglen);
1163 while(msglen > 0L) {
1164 bloklen = ((msglen >= 255L) ? 255 : msglen);
1165 client_read(buf, (int)bloklen );
1166 fwrite(buf, (int)bloklen, 1, fp);
1167 msglen = msglen - bloklen;
1171 save_message(CC->temp, recp, 0, e, 0);
1176 * Delete message from current room
1178 void cmd_dele(char *delstr)
1183 getuser(&CC->usersupp,CC->curr_user);
1184 if ((CC->usersupp.axlevel < 6)
1185 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1186 cprintf("%d Higher access required.\n",
1187 ERROR+HIGHER_ACCESS_REQUIRED);
1191 delnum = atol(delstr);
1192 if (CC->curr_rm==1) {
1193 cprintf("%d Can't delete mail.\n",ERROR);
1197 /* get room records, obtaining a lock... */
1198 lgetroom(&CC->quickroom,CC->curr_rm);
1199 get_msglist(CC->curr_rm);
1202 if (CC->num_msgs > 0) for (a=0; a<(CC->num_msgs); ++a) {
1203 if (MessageFromList(a) == delnum) {
1204 SetMessageInList(a, 0L);
1209 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1210 CC->quickroom.QRhighest = MessageFromList(CC->num_msgs - 1);
1212 put_msglist(CC->curr_rm);
1213 lputroom(&CC->quickroom,CC->curr_rm);
1215 cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
1216 cprintf("%d Message deleted.\n",OK);
1218 else cprintf("%d No message %ld.\n",ERROR,delnum);
1223 * move a message to another room
1225 void cmd_move(char *args)
1231 struct quickroom qtemp;
1233 struct cdbdata *cdbtarg;
1237 num = extract_long(args,0);
1238 extract(targ,args,1);
1240 if (CC->curr_rm < 0) {
1241 cprintf("%d no room\n",ERROR);
1245 getuser(&CC->usersupp,CC->curr_user);
1246 if ((CC->usersupp.axlevel < 6)
1247 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
1248 cprintf("%d Higher access required.\n",
1249 ERROR+HIGHER_ACCESS_REQUIRED);
1254 for (a=0; a<MAXROOMS; ++a) {
1256 if (!strcasecmp(qtemp.QRname,targ)) {
1261 if (targ_slot < 0) {
1262 cprintf("%d '%s' does not exist.\n",ERROR,targ);
1266 /* yank the message out of the current room... */
1267 lgetroom(&CC->quickroom,CC->curr_rm);
1268 get_msglist(CC->curr_rm);
1271 for (a=0; a<(CC->num_msgs); ++a) {
1272 if (MessageFromList(a) == num) {
1274 SetMessageInList(a, 0L);
1278 CC->num_msgs = sort_msglist(CC->msglist, CC->num_msgs);
1279 put_msglist(CC->curr_rm);
1280 CC->quickroom.QRhighest = MessageFromList((CC->num_msgs)-1);
1282 lputroom(&CC->quickroom,CC->curr_rm);
1284 cprintf("%d msg %ld does not exist.\n",ERROR,num);
1288 /* put the message into the target room */
1289 lgetroom(&qtemp,targ_slot);
1290 cdbtarg = cdb_fetch(CDB_MSGLISTS, &targ_slot, sizeof(int));
1291 if (cdbtarg != NULL) {
1292 targmsgs = malloc(cdbtarg->len);
1293 memcpy(targmsgs, cdbtarg->ptr, cdbtarg->len);
1294 targ_count = cdbtarg->len / sizeof(long);
1303 targmsgs = realloc(targmsgs, ((CC->num_msgs) * sizeof(long)));
1304 targmsgs[targ_count - 1] = num;
1305 targ_count = sort_msglist(targmsgs, targ_count);
1306 qtemp.QRhighest = targmsgs[targ_count - 1];
1307 cdb_store(CDB_MSGLISTS, &targ_slot, sizeof(int),
1308 targmsgs, targ_count * sizeof(long));
1310 lputroom(&qtemp,targ_slot);
1311 cprintf("%d ok\n",OK);