4 * Server functions which perform operations on room objects.
21 #include "sysdep_decls.h"
25 #include "citserver.h"
29 struct floor *floorcache[MAXFLOORS];
32 * Generic routine for determining user access to rooms
34 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
39 /* for internal programs, always do everything */
40 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
41 return (UA_KNOWN | UA_GOTOALLOWED);
43 /* For mailbox rooms, only allow access to the owner */
44 if (roombuf->QRflags & QR_MAILBOX) {
45 if (userbuf->usernum != atol(roombuf->QRname)) {
49 /* Locate any applicable user/room relationships */
50 CtdlGetRelationship(&vbuf, userbuf, roombuf);
52 /* Force the properties of the Aide room */
53 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
54 if (userbuf->axlevel >= 6) {
55 retval = UA_KNOWN | UA_GOTOALLOWED;
61 /* For mailboxes, we skip all the access stuff (and we've
62 * already checked by this point that the mailbox belongs
65 if (roombuf->QRflags & QR_MAILBOX) {
66 retval = UA_KNOWN | UA_GOTOALLOWED;
69 /* If this is a public room, it's accessible... */
70 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
71 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
73 /* If this is a preferred users only room, check access level */
74 if (roombuf->QRflags & QR_PREFONLY) {
75 if (userbuf->axlevel < 5) {
76 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
79 /* For private rooms, check the generation number matchups */
80 if (roombuf->QRflags & QR_PRIVATE) {
82 /* An explicit match means the user belongs in this room */
83 if (vbuf.v_flags & V_ACCESS) {
84 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
86 /* Otherwise, check if this is a guess-name or passworded
87 * room. If it is, a goto may at least be attempted
89 else if ((roombuf->QRflags & QR_PRIVATE)
90 || (roombuf->QRflags & QR_PASSWORDED)) {
91 retval = retval & ~UA_KNOWN;
92 retval = retval | UA_GOTOALLOWED;
95 /* Check to see if the user has forgotten this room */
96 if (vbuf.v_flags & V_FORGET) {
97 retval = retval & ~UA_KNOWN;
98 retval = retval | UA_ZAPPED;
100 /* If user is explicitly locked out of this room, deny everything */
101 if (vbuf.v_flags & V_LOCKOUT) {
102 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
105 /* Aides get access to everything */
106 if (userbuf->axlevel >= 6) {
107 if (vbuf.v_flags & V_FORGET) {
108 retval = retval | UA_GOTOALLOWED;
111 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
115 NEWMSG: /* By the way, we also check for the presence of new messages */
116 if ((roombuf->QRhighest) > (vbuf.v_lastseen)) {
117 retval = retval | UA_HASNEWMSGS;
123 * Self-checking stuff for a room record read into memory
125 void room_sanity_check(struct quickroom *qrbuf)
127 /* Mailbox rooms are always on the lowest floor */
128 if (qrbuf->QRflags & QR_MAILBOX) {
131 /* Listing order of 0 is illegal except for base rooms */
132 if (qrbuf->QRorder == 0)
133 if (!is_noneditable(qrbuf))
139 * getroom() - retrieve room data from disk
141 int getroom(struct quickroom *qrbuf, char *room_name)
143 struct cdbdata *cdbqr;
144 char lowercase_name[ROOMNAMELEN];
145 char personal_lowercase_name[ROOMNAMELEN];
148 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
149 lowercase_name[a] = tolower(room_name[a]);
151 lowercase_name[a] = 0;
153 memset(qrbuf, 0, sizeof(struct quickroom));
155 /* First, try the public namespace */
156 cdbqr = cdb_fetch(CDB_QUICKROOM,
157 lowercase_name, strlen(lowercase_name));
159 /* If that didn't work, try the user's personal namespace */
161 sprintf(personal_lowercase_name, "%010ld.%s",
162 CC->usersupp.usernum, lowercase_name);
163 cdbqr = cdb_fetch(CDB_QUICKROOM,
164 personal_lowercase_name,
165 strlen(personal_lowercase_name));
168 memcpy(qrbuf, cdbqr->ptr,
169 ((cdbqr->len > sizeof(struct quickroom)) ?
170 sizeof(struct quickroom) : cdbqr->len));
173 room_sanity_check(qrbuf);
182 * lgetroom() - same as getroom() but locks the record (if supported)
184 int lgetroom(struct quickroom *qrbuf, char *room_name)
187 retval = getroom(qrbuf, room_name);
188 if (retval == 0) begin_critical_section(S_QUICKROOM);
194 * b_putroom() - back end to putroom() and b_deleteroom()
195 * (if the supplied buffer is NULL, delete the room record)
197 void b_putroom(struct quickroom *qrbuf, char *room_name)
199 char lowercase_name[ROOMNAMELEN];
202 for (a = 0; a <= strlen(room_name); ++a) {
203 lowercase_name[a] = tolower(room_name[a]);
207 cdb_delete(CDB_QUICKROOM,
208 lowercase_name, strlen(lowercase_name));
210 time(&qrbuf->QRmtime);
211 cdb_store(CDB_QUICKROOM,
212 lowercase_name, strlen(lowercase_name),
213 qrbuf, sizeof(struct quickroom));
219 * putroom() - store room data to disk
221 void putroom(struct quickroom *qrbuf) {
222 b_putroom(qrbuf, qrbuf->QRname);
227 * b_deleteroom() - delete a room record from disk
229 void b_deleteroom(char *room_name) {
230 b_putroom(NULL, room_name);
236 * lputroom() - same as putroom() but unlocks the record (if supported)
238 void lputroom(struct quickroom *qrbuf)
242 end_critical_section(S_QUICKROOM);
246 /****************************************************************************/
249 * getfloor() - retrieve floor data from disk
251 void getfloor(struct floor *flbuf, int floor_num)
253 struct cdbdata *cdbfl;
255 memset(flbuf, 0, sizeof(struct floor));
256 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
258 memcpy(flbuf, cdbfl->ptr,
259 ((cdbfl->len > sizeof(struct floor)) ?
260 sizeof(struct floor) : cdbfl->len));
263 if (floor_num == 0) {
264 strcpy(flbuf->f_name, "Main Floor");
265 flbuf->f_flags = F_INUSE;
266 flbuf->f_ref_count = 3;
273 * lgetfloor() - same as getfloor() but locks the record (if supported)
275 void lgetfloor(struct floor *flbuf, int floor_num)
278 begin_critical_section(S_FLOORTAB);
279 getfloor(flbuf, floor_num);
284 * cgetfloor() - Get floor record from *cache* (loads from disk if needed)
286 * This is strictly a performance hack.
288 struct floor *cgetfloor(int floor_num) {
289 static int initialized = 0;
292 if (initialized == 0) {
293 for (i=0; i<MAXFLOORS; ++i) {
294 floorcache[floor_num] = NULL;
299 if (floorcache[floor_num] == NULL) {
300 floorcache[floor_num] = mallok(sizeof(struct floor));
301 getfloor(floorcache[floor_num], floor_num);
304 return(floorcache[floor_num]);
310 * putfloor() - store floor data on disk
312 void putfloor(struct floor *flbuf, int floor_num)
314 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
315 flbuf, sizeof(struct floor));
317 /* If we've cached this, clear it out, 'cuz it's WRONG now! */
318 if (floorcache[floor_num] != NULL) {
319 phree(floorcache[floor_num]);
320 floorcache[floor_num] = NULL;
326 * lputfloor() - same as putfloor() but unlocks the record (if supported)
328 void lputfloor(struct floor *flbuf, int floor_num)
331 putfloor(flbuf, floor_num);
332 end_critical_section(S_FLOORTAB);
338 * Traverse the room file...
340 void ForEachRoom(void (*CallBack) (struct quickroom *EachRoom, void *out_data),
343 struct quickroom qrbuf;
344 struct cdbdata *cdbqr;
346 cdb_begin_transaction();
347 cdb_rewind(CDB_QUICKROOM);
349 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
350 memset(&qrbuf, 0, sizeof(struct quickroom));
351 memcpy(&qrbuf, cdbqr->ptr,
352 ((cdbqr->len > sizeof(struct quickroom)) ?
353 sizeof(struct quickroom) : cdbqr->len));
355 room_sanity_check(&qrbuf);
356 if (qrbuf.QRflags & QR_INUSE)
357 (*CallBack)(&qrbuf, in_data);
359 cdb_end_transaction();
364 * delete_msglist() - delete room message pointers
366 void delete_msglist(struct quickroom *whichroom)
368 struct cdbdata *cdbml;
370 /* Make sure the msglist we're deleting actually exists, otherwise
371 * gdbm will complain when we try to delete an invalid record
373 cdbml = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
377 /* Go ahead and delete it */
378 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
386 * sort message pointers
387 * (returns new msg count)
389 int sort_msglist(long listptrs[], int oldcount)
400 for (a = numitems - 2; a >= 0; --a) {
401 for (b = 0; b <= a; ++b) {
402 if (listptrs[b] > (listptrs[b + 1])) {
404 hold2 = listptrs[b + 1];
406 listptrs[b + 1] = hold1;
411 /* and yank any nulls */
412 while ((numitems > 0) && (listptrs[0] == 0L)) {
413 memcpy(&listptrs[0], &listptrs[1],
414 (sizeof(long) * (numitems - 1)));
423 * Determine whether a given room is non-editable.
425 int is_noneditable(struct quickroom *qrbuf)
428 /* Lobby> and Aide> are non-editable */
429 if (!strcasecmp(qrbuf->QRname, BASEROOM))
431 else if (!strcasecmp(qrbuf->QRname, AIDEROOM))
434 /* Mail> rooms are also non-editable */
435 else if ( (qrbuf->QRflags & QR_MAILBOX)
436 && (!strcasecmp(&qrbuf->QRname[11], MAILROOM)) )
439 /* Everything else is editable */
447 * Back-back-end for all room listing commands
449 void list_roomname(struct quickroom *qrbuf)
451 char truncated_roomname[ROOMNAMELEN];
453 /* For mailbox rooms, chop off the owner prefix */
454 if (qrbuf->QRflags & QR_MAILBOX) {
455 strcpy(truncated_roomname, qrbuf->QRname);
456 strcpy(truncated_roomname, &truncated_roomname[11]);
457 cprintf("%s", truncated_roomname);
459 /* For all other rooms, just display the name in its entirety */
461 cprintf("%s", qrbuf->QRname);
464 /* ...and now the other parameters */
465 cprintf("|%u|%d|%d\n",
467 (int) qrbuf->QRfloor,
468 (int) qrbuf->QRorder);
473 * cmd_lrms() - List all accessible rooms, known or forgotten
475 void cmd_lrms_backend(struct quickroom *qrbuf, void *data)
477 int FloorBeingSearched = (-1);
478 FloorBeingSearched = *(int *)data;
480 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
481 & (UA_KNOWN | UA_ZAPPED)))
482 && ((qrbuf->QRfloor == (FloorBeingSearched))
483 || ((FloorBeingSearched) < 0)))
484 list_roomname(qrbuf);
487 void cmd_lrms(char *argbuf)
489 int FloorBeingSearched = (-1);
490 if (strlen(argbuf) > 0)
491 FloorBeingSearched = extract_int(argbuf, 0);
493 if (CtdlAccessCheck(ac_logged_in)) return;
495 if (getuser(&CC->usersupp, CC->curr_user)) {
496 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
499 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
501 ForEachRoom(cmd_lrms_backend, &FloorBeingSearched);
508 * cmd_lkra() - List all known rooms
510 void cmd_lkra_backend(struct quickroom *qrbuf, void *data)
512 int FloorBeingSearched = (-1);
513 FloorBeingSearched = *(int *)data;
515 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
517 && ((qrbuf->QRfloor == (FloorBeingSearched))
518 || ((FloorBeingSearched) < 0)))
519 list_roomname(qrbuf);
522 void cmd_lkra(char *argbuf)
524 int FloorBeingSearched = (-1);
525 if (strlen(argbuf) > 0)
526 FloorBeingSearched = extract_int(argbuf, 0);
528 if (CtdlAccessCheck(ac_logged_in)) return;
530 if (getuser(&CC->usersupp, CC->curr_user)) {
531 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
534 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
536 ForEachRoom(cmd_lkra_backend, &FloorBeingSearched);
543 * cmd_lkrn() - List all known rooms with new messages
545 void cmd_lkrn_backend(struct quickroom *qrbuf, void *data)
548 int FloorBeingSearched = (-1);
549 FloorBeingSearched = *(int *)data;
551 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
553 && (ra & UA_HASNEWMSGS)
554 && ((qrbuf->QRfloor == (FloorBeingSearched))
555 || ((FloorBeingSearched) < 0)))
556 list_roomname(qrbuf);
559 void cmd_lkrn(char *argbuf)
561 int FloorBeingSearched = (-1);
562 if (strlen(argbuf) > 0)
563 FloorBeingSearched = extract_int(argbuf, 0);
565 if (CtdlAccessCheck(ac_logged_in)) return;
567 if (getuser(&CC->usersupp, CC->curr_user)) {
568 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
571 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
573 ForEachRoom(cmd_lkrn_backend, &FloorBeingSearched);
580 * cmd_lkro() - List all known rooms
582 void cmd_lkro_backend(struct quickroom *qrbuf, void *data)
585 int FloorBeingSearched = (-1);
586 FloorBeingSearched = *(int *)data;
588 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
590 && ((ra & UA_HASNEWMSGS) == 0)
591 && ((qrbuf->QRfloor == (FloorBeingSearched))
592 || ((FloorBeingSearched) < 0)))
593 list_roomname(qrbuf);
596 void cmd_lkro(char *argbuf)
598 int FloorBeingSearched = (-1);
599 if (strlen(argbuf) > 0)
600 FloorBeingSearched = extract_int(argbuf, 0);
602 if (CtdlAccessCheck(ac_logged_in)) return;
604 if (getuser(&CC->usersupp, CC->curr_user)) {
605 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
608 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
610 ForEachRoom(cmd_lkro_backend, &FloorBeingSearched);
617 * cmd_lzrm() - List all forgotten rooms
619 void cmd_lzrm_backend(struct quickroom *qrbuf, void *data)
622 int FloorBeingSearched = (-1);
623 FloorBeingSearched = *(int *)data;
625 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
626 if ((ra & UA_GOTOALLOWED)
628 && ((qrbuf->QRfloor == (FloorBeingSearched))
629 || ((FloorBeingSearched) < 0)))
630 list_roomname(qrbuf);
633 void cmd_lzrm(char *argbuf)
635 int FloorBeingSearched = (-1);
636 if (strlen(argbuf) > 0)
637 FloorBeingSearched = extract_int(argbuf, 0);
639 if (CtdlAccessCheck(ac_logged_in)) return;
641 if (getuser(&CC->usersupp, CC->curr_user)) {
642 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
645 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
647 ForEachRoom(cmd_lzrm_backend, &FloorBeingSearched);
653 void usergoto(char *where, int display_result, int *retmsgs, int *retnew)
656 int new_messages = 0;
657 int total_messages = 0;
661 int newmailcount = 0;
663 char truncated_roomname[ROOMNAMELEN];
664 struct cdbdata *cdbfr;
665 long *msglist = NULL;
668 strcpy(CC->quickroom.QRname, where);
669 getroom(&CC->quickroom, where);
671 lgetuser(&CC->usersupp, CC->curr_user);
672 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
674 /* Know the room ... but not if it's the page log room */
675 if (strcasecmp(where, config.c_logpages)) {
676 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
677 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
679 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
680 lputuser(&CC->usersupp);
682 /* check for new mail */
683 newmailcount = NewMailCount();
685 /* set info to 1 if the user needs to read the room's info file */
686 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
690 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
692 msglist = mallok(cdbfr->len);
693 memcpy(msglist, cdbfr->ptr, cdbfr->len);
694 num_msgs = cdbfr->len / sizeof(long);
698 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
699 if (msglist[a] > 0L) {
701 if (msglist[a] > vbuf.v_lastseen) {
707 if (msglist != NULL) phree(msglist);
709 if (CC->quickroom.QRflags & QR_MAILBOX)
714 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
715 || (CC->usersupp.axlevel >= 6))
720 strcpy(truncated_roomname, CC->quickroom.QRname);
721 if (CC->quickroom.QRflags & QR_MAILBOX) {
722 strcpy(truncated_roomname, &truncated_roomname[11]);
725 if (retmsgs != NULL) *retmsgs = total_messages;
726 if (retnew != NULL) *retnew = new_messages;
727 lprintf(9, "<%s> %d new of %d total messages\n",
728 CC->quickroom.QRname, new_messages, total_messages);
731 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
732 OK, CtdlCheckExpress(),
734 new_messages, total_messages,
735 info, CC->quickroom.QRflags,
736 CC->quickroom.QRhighest,
738 rmailflag, raideflag, newmailcount,
739 CC->quickroom.QRfloor);
745 * cmd_goto() - goto a new room
747 void cmd_goto(char *gargs)
749 struct quickroom QRscratch;
753 char augmented_roomname[SIZ];
757 if (CtdlAccessCheck(ac_logged_in)) return;
759 extract(towhere, gargs, 0);
760 extract(password, gargs, 1);
762 getuser(&CC->usersupp, CC->curr_user);
764 if (!strcasecmp(towhere, "_BASEROOM_"))
765 strcpy(towhere, BASEROOM);
767 if (!strcasecmp(towhere, "_MAIL_"))
768 strcpy(towhere, MAILROOM);
770 if (!strcasecmp(towhere, "_BITBUCKET_"))
771 strcpy(towhere, config.c_twitroom);
774 /* First try a regular match */
775 c = getroom(&QRscratch, towhere);
777 /* Then try a mailbox name match */
779 MailboxName(augmented_roomname, &CC->usersupp, towhere);
780 c = getroom(&QRscratch, augmented_roomname);
782 strcpy(towhere, augmented_roomname);
785 /* And if the room was found... */
788 /* let internal programs go directly to any room */
789 if (CC->internal_pgm) {
790 usergoto(towhere, 1, NULL, NULL);
794 /* See if there is an existing user/room relationship */
795 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
797 /* normal clients have to pass through security */
798 if (ra & UA_GOTOALLOWED)
802 if ((QRscratch.QRflags & QR_PASSWORDED) &&
803 ((ra & UA_KNOWN) == 0) &&
804 (strcasecmp(QRscratch.QRpasswd, password))
806 cprintf("%d wrong or missing passwd\n",
807 ERROR + PASSWORD_REQUIRED);
809 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
810 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
811 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
812 ((ra & UA_KNOWN) == 0)) {
815 usergoto(towhere, 1, NULL, NULL);
821 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
827 struct usersupp temp;
828 struct cdbdata *cdbus;
830 cdb_begin_transaction();
831 getuser(&CC->usersupp, CC->curr_user);
832 if (CtdlAccessCheck(ac_room_aide)) return;
834 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
835 cdb_rewind(CDB_USERSUPP);
836 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
837 memset(&temp, 0, sizeof temp);
838 memcpy(&temp, cdbus->ptr, sizeof temp);
841 if ((CC->quickroom.QRflags & QR_INUSE)
842 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
844 cprintf("%s\n", temp.fullname);
846 cdb_end_transaction();
852 * RDIR command for room directory
862 if (CtdlAccessCheck(ac_logged_in)) return;
864 getroom(&CC->quickroom, CC->quickroom.QRname);
865 getuser(&CC->usersupp, CC->curr_user);
867 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
868 cprintf("%d not here.\n", ERROR + NOT_HERE);
871 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
872 && (CC->usersupp.axlevel < 6)
873 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
874 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
877 cprintf("%d %s|%s/files/%s\n",
878 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
880 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
881 BBSDIR, CC->quickroom.QRdirname, CC->temp);
884 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
885 fd = fopen(buf, "r");
887 fd = fopen("/dev/null", "r");
889 ls = fopen(CC->temp, "r");
890 while (fgets(flnm, sizeof flnm, ls) != NULL) {
891 flnm[strlen(flnm) - 1] = 0;
892 if (strcasecmp(flnm, "filedir")) {
893 sprintf(buf, "%s/files/%s/%s",
894 BBSDIR, CC->quickroom.QRdirname, flnm);
898 while ((fgets(buf, sizeof buf, fd) != NULL)
899 && (strlen(comment) == 0)) {
900 buf[strlen(buf) - 1] = 0;
901 if ((!strncasecmp(buf, flnm, strlen(flnm)))
902 && (buf[strlen(flnm)] == ' '))
904 &buf[strlen(flnm) + 1],
907 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
918 * get room parameters (aide or room aide command)
922 if (CtdlAccessCheck(ac_room_aide)) return;
925 if (is_noneditable(&CC->quickroom)) {
926 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
931 getroom(&CC->quickroom, CC->quickroom.QRname);
932 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
933 OK, CtdlCheckExpress(),
934 CC->quickroom.QRname,
935 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
936 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
937 CC->quickroom.QRflags,
938 (int) CC->quickroom.QRfloor,
939 (int) CC->quickroom.QRorder);
944 * set room parameters (aide or room aide command)
946 void cmd_setr(char *args)
951 char old_name[ROOMNAMELEN];
956 if (CtdlAccessCheck(ac_room_aide)) return;
958 if (is_noneditable(&CC->quickroom)) {
963 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
969 if (num_parms(args) >= 6) {
970 fl = cgetfloor(extract_int(args, 5));
971 if ((fl->f_flags & F_INUSE) == 0) {
972 cprintf("%d Invalid floor number.\n",
973 ERROR + INVALID_FLOOR_OPERATION);
977 if (num_parms(args) >= 7) {
978 new_order = extract_int(args, 6);
984 lgetroom(&CC->quickroom, CC->quickroom.QRname);
986 /* Non-editable base rooms can't be renamed */
987 strcpy(old_name, CC->quickroom.QRname);
989 extract(buf, args, 0);
990 buf[ROOMNAMELEN] = 0;
991 safestrncpy(CC->quickroom.QRname, buf,
992 sizeof CC->quickroom.QRname);
995 extract(buf, args, 1);
997 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
998 extract(buf, args, 2);
1000 safestrncpy(CC->quickroom.QRdirname, buf,
1001 sizeof CC->quickroom.QRdirname);
1002 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
1003 if (num_parms(args) >= 7)
1004 CC->quickroom.QRorder = (char) new_order;
1006 /* Clean up a client boo-boo: if the client set the room to
1007 * guess-name or passworded, ensure that the private flag is
1010 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1011 || (CC->quickroom.QRflags & QR_PASSWORDED))
1012 CC->quickroom.QRflags |= QR_PRIVATE;
1014 /* Kick everyone out if the client requested it (by changing the
1015 * room's generation number)
1017 if (extract_int(args, 4)) {
1018 time(&CC->quickroom.QRgen);
1020 old_floor = CC->quickroom.QRfloor;
1021 if (num_parms(args) >= 6) {
1022 CC->quickroom.QRfloor = extract_int(args, 5);
1024 /* Write the room record back to disk */
1025 lputroom(&CC->quickroom);
1027 /* If the room name changed, then there are now two room records,
1028 * so we have to delete the old one.
1030 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1031 b_deleteroom(old_name);
1033 /* adjust the floor reference counts */
1034 lgetfloor(&flbuf, old_floor);
1035 --flbuf.f_ref_count;
1036 lputfloor(&flbuf, old_floor);
1037 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1038 ++flbuf.f_ref_count;
1039 lputfloor(&flbuf, CC->quickroom.QRfloor);
1041 /* create a room directory if necessary */
1042 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1044 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1045 CC->quickroom.QRdirname);
1048 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1050 cprintf("%d Ok\n", OK);
1056 * get the name of the room aide for this room
1060 struct usersupp usbuf;
1062 if (CtdlAccessCheck(ac_logged_in)) return;
1064 if (is_noneditable(&CC->quickroom)) {
1065 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1068 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1069 cprintf("%d %s\n", OK, usbuf.fullname);
1071 cprintf("%d \n", OK);
1077 * set the room aide for this room
1079 void cmd_seta(char *new_ra)
1081 struct usersupp usbuf;
1086 if (CtdlAccessCheck(ac_room_aide)) return;
1088 if (getuser(&usbuf, new_ra) != 0) {
1091 newu = usbuf.usernum;
1094 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1096 if (CC->quickroom.QRroomaide != newu) {
1099 CC->quickroom.QRroomaide = newu;
1100 lputroom(&CC->quickroom);
1103 * We have to post the change notice _after_ writing changes to
1104 * the room table, otherwise it would deadlock!
1106 if (post_notice == 1) {
1107 sprintf(buf, "%s is now room aide for %s>\n",
1108 usbuf.fullname, CC->quickroom.QRname);
1111 cprintf("%d Ok\n", OK);
1115 * Generate an associated file name for a room
1117 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1119 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1123 * retrieve info file for this room
1131 assoc_file_name(filename, &CC->quickroom, "info");
1132 info_fp = fopen(filename, "r");
1134 if (info_fp == NULL) {
1135 cprintf("%d No info file.\n", ERROR);
1138 cprintf("%d Info:\n", LISTING_FOLLOWS);
1139 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1140 if (strlen(buf) > 0)
1141 buf[strlen(buf) - 1] = 0;
1142 cprintf("%s\n", buf);
1149 * Back end processing to delete a room and everything associated with it
1151 void delete_room(struct quickroom *qrbuf)
1156 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1158 /* Delete the info file */
1159 assoc_file_name(filename, qrbuf, "info");
1162 /* Delete the image file */
1163 assoc_file_name(filename, qrbuf, "images");
1166 /* Delete the room's network config file */
1167 assoc_file_name(filename, qrbuf, "netconfigs");
1170 /* Delete the messages in the room
1171 * (Careful: this opens an S_QUICKROOM critical section!)
1173 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1175 /* Flag the room record as not in use */
1176 lgetroom(qrbuf, qrbuf->QRname);
1180 /* then decrement the reference count for the floor */
1181 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1182 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1183 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1185 /* Delete the room record from the database! */
1186 b_deleteroom(qrbuf->QRname);
1191 * aide command: kill the current room
1193 void cmd_kill(char *argbuf)
1196 char deleted_room_name[ROOMNAMELEN];
1199 kill_ok = extract_int(argbuf, 0);
1201 if (CtdlAccessCheck(ac_room_aide)) return;
1203 if (is_noneditable(&CC->quickroom)) {
1204 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1208 strcpy(deleted_room_name, CC->quickroom.QRname);
1209 delete_room(&CC->quickroom); /* Do the dirty work */
1210 usergoto(BASEROOM, 0, NULL, NULL); /* Return to the Lobby */
1212 /* tell the world what we did */
1213 sprintf(aaa, "%s> killed by %s\n",
1214 deleted_room_name, CC->curr_user);
1216 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1218 cprintf("%d ok to delete.\n", OK);
1224 * Internal code to create a new room (returns room flags)
1226 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only,
1227 * 4=mailbox, 5=mailbox, but caller supplies namespace
1229 unsigned create_room(char *new_room_name,
1231 char *new_room_pass,
1236 struct quickroom qrbuf;
1240 lprintf(9, "create_room(%s)\n", new_room_name);
1241 if (getroom(&qrbuf, new_room_name) == 0) {
1242 lprintf(9, "%s already exists.\n", new_room_name);
1243 return (0); /* already exists */
1247 memset(&qrbuf, 0, sizeof(struct quickroom));
1248 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1249 qrbuf.QRflags = QR_INUSE;
1250 if (new_room_type > 0)
1251 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1252 if (new_room_type == 1)
1253 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1254 if (new_room_type == 2)
1255 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1256 if ( (new_room_type == 4) || (new_room_type == 5) )
1257 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1259 /* If the user is requesting a personal room, set up the room
1260 * name accordingly (prepend the user number)
1262 if (new_room_type == 4) {
1263 MailboxName(qrbuf.QRname, &CC->usersupp, new_room_name);
1266 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1269 /* If the room is private, and the system administrator has elected
1270 * to automatically grant room aide privileges, do so now; otherwise,
1271 * set the room aide to undefined.
1273 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1274 qrbuf.QRroomaide = CC->usersupp.usernum;
1276 qrbuf.QRroomaide = (-1L);
1280 * If the caller is only interested in testing whether this will work,
1281 * return now without creating the room.
1283 if (!really_create) return (qrbuf.QRflags);
1285 /* cdb_begin_transaction(); commented out because a transaction
1286 is already open when creating __CtdlSMTPspoolout__ while
1287 initializing serv_smtp.c
1290 qrbuf.QRnumber = get_new_room_number();
1291 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1292 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1293 qrbuf.QRfloor = new_room_floor;
1295 /* save what we just did... */
1298 /* bump the reference count on whatever floor the room is on */
1299 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1300 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1301 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1303 /* be sure not to kick the creator out of the room! */
1304 lgetuser(&CC->usersupp, CC->curr_user);
1305 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1306 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1307 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1308 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1309 lputuser(&CC->usersupp);
1311 /* resume our happy day */
1312 /* cdb_end_transaction(); */
1313 return (qrbuf.QRflags);
1320 void cmd_cre8(char *args)
1323 char new_room_name[SIZ];
1325 char new_room_pass[SIZ];
1329 struct quickroom qrbuf;
1332 cre8_ok = extract_int(args, 0);
1333 extract(new_room_name, args, 1);
1334 new_room_name[ROOMNAMELEN - 1] = 0;
1335 new_room_type = extract_int(args, 2);
1336 extract(new_room_pass, args, 3);
1337 new_room_pass[9] = 0;
1340 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1341 cprintf("%d Invalid room name.\n", ERROR);
1345 if (!strcasecmp(new_room_name, MAILROOM)) {
1346 cprintf("%d '%s' already exists.\n",
1347 ERROR + ALREADY_EXISTS, new_room_name);
1351 if (num_parms(args) >= 5) {
1352 fl = cgetfloor(extract_int(args, 4));
1353 if ((fl->f_flags & F_INUSE) == 0) {
1354 cprintf("%d Invalid floor number.\n",
1355 ERROR + INVALID_FLOOR_OPERATION);
1358 new_room_floor = extract_int(args, 4);
1362 if (CtdlAccessCheck(ac_logged_in)) return;
1364 if (CC->usersupp.axlevel < config.c_createax) {
1365 cprintf("%d You need higher access to create rooms.\n",
1366 ERROR + HIGHER_ACCESS_REQUIRED);
1370 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1371 cprintf("%d Ok to create rooms.\n", OK);
1375 if ((new_room_type < 0) || (new_room_type > 4)) {
1376 cprintf("%d Invalid room type.\n", ERROR);
1380 /* Check to make sure the requested room name doesn't already exist */
1381 newflags = create_room(new_room_name,
1382 new_room_type, new_room_pass, new_room_floor, 0);
1383 if (newflags == 0) {
1384 cprintf("%d '%s' already exists.\n",
1385 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1390 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1394 /* If we reach this point, the room needs to be created. */
1396 newflags = create_room(new_room_name,
1397 new_room_type, new_room_pass, new_room_floor, 1);
1399 /* post a message in Aide> describing the new room */
1400 safestrncpy(aaa, new_room_name, sizeof aaa);
1401 strcat(aaa, "> created by ");
1402 strcat(aaa, CC->usersupp.fullname);
1403 if (newflags & QR_MAILBOX)
1404 strcat(aaa, " [personal]");
1405 else if (newflags & QR_PRIVATE)
1406 strcat(aaa, " [private]");
1407 if (newflags & QR_GUESSNAME)
1408 strcat(aaa, "[guessname] ");
1409 if (newflags & QR_PASSWORDED) {
1410 strcat(aaa, "\n Password: ");
1411 strcat(aaa, new_room_pass);
1416 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1421 void cmd_einf(char *ok)
1422 { /* enter info file for current room */
1424 char infofilename[SIZ];
1427 if (CtdlAccessCheck(ac_room_aide)) return;
1429 if (atoi(ok) == 0) {
1430 cprintf("%d Ok.\n", OK);
1433 assoc_file_name(infofilename, &CC->quickroom, "info");
1434 lprintf(9, "opening\n");
1435 fp = fopen(infofilename, "w");
1436 lprintf(9, "checking\n");
1438 cprintf("%d Cannot open %s: %s\n",
1439 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1442 cprintf("%d Send info...\n", SEND_LISTING);
1446 if (strcmp(buf, "000"))
1447 fprintf(fp, "%s\n", buf);
1448 } while (strcmp(buf, "000"));
1451 /* now update the room index so people will see our new info */
1452 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1453 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1454 lputroom(&CC->quickroom);
1459 * cmd_lflr() - List all known floors
1466 if (CtdlAccessCheck(ac_logged_in)) return;
1468 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1470 for (a = 0; a < MAXFLOORS; ++a) {
1471 getfloor(&flbuf, a);
1472 if (flbuf.f_flags & F_INUSE) {
1473 cprintf("%d|%s|%d\n",
1485 * create a new floor
1487 void cmd_cflr(char *argbuf)
1489 char new_floor_name[SIZ];
1492 int free_slot = (-1);
1495 extract(new_floor_name, argbuf, 0);
1496 cflr_ok = extract_int(argbuf, 1);
1499 if (CtdlAccessCheck(ac_aide)) return;
1501 for (a = 0; a < MAXFLOORS; ++a) {
1502 getfloor(&flbuf, a);
1504 /* note any free slots while we're scanning... */
1505 if (((flbuf.f_flags & F_INUSE) == 0)
1509 /* check to see if it already exists */
1510 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1511 && (flbuf.f_flags & F_INUSE)) {
1512 cprintf("%d Floor '%s' already exists.\n",
1513 ERROR + ALREADY_EXISTS,
1519 if (free_slot < 0) {
1520 cprintf("%d There is no space available for a new floor.\n",
1521 ERROR + INVALID_FLOOR_OPERATION);
1525 cprintf("%d ok to create...\n", OK);
1528 lgetfloor(&flbuf, free_slot);
1529 flbuf.f_flags = F_INUSE;
1530 flbuf.f_ref_count = 0;
1531 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1532 lputfloor(&flbuf, free_slot);
1533 cprintf("%d %d\n", OK, free_slot);
1541 void cmd_kflr(char *argbuf)
1544 int floor_to_delete;
1548 floor_to_delete = extract_int(argbuf, 0);
1549 kflr_ok = extract_int(argbuf, 1);
1551 if (CtdlAccessCheck(ac_aide)) return;
1553 lgetfloor(&flbuf, floor_to_delete);
1556 if ((flbuf.f_flags & F_INUSE) == 0) {
1557 cprintf("%d Floor %d not in use.\n",
1558 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1561 if (flbuf.f_ref_count != 0) {
1562 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1563 ERROR + INVALID_FLOOR_OPERATION,
1568 cprintf("%d Ok\n", OK);
1570 cprintf("%d Ok to delete...\n", OK);
1577 if ((delete_ok == 1) && (kflr_ok == 1))
1579 lputfloor(&flbuf, floor_to_delete);
1585 void cmd_eflr(char *argbuf)
1591 np = num_parms(argbuf);
1593 cprintf("%d Usage error.\n", ERROR);
1597 if (CtdlAccessCheck(ac_aide)) return;
1599 floor_num = extract_int(argbuf, 0);
1600 lgetfloor(&flbuf, floor_num);
1601 if ((flbuf.f_flags & F_INUSE) == 0) {
1602 lputfloor(&flbuf, floor_num);
1603 cprintf("%d Floor %d is not in use.\n",
1604 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1608 extract(flbuf.f_name, argbuf, 1);
1609 lputfloor(&flbuf, floor_num);
1611 cprintf("%d Ok\n", OK);