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 (is_msg_in_mset(vbuf.v_seen, roombuf->QRhighest) == 0) {
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 (is_msg_in_mset(vbuf.v_seen, msglist[a]) == 0) {
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)) &&
805 (CC->usersupp.axlevel < 6)
807 cprintf("%d wrong or missing passwd\n",
808 ERROR + PASSWORD_REQUIRED);
810 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
811 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
812 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
813 ((ra & UA_KNOWN) == 0) &&
814 (CC->usersupp.axlevel < 6)
818 usergoto(towhere, 1, NULL, NULL);
824 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
830 struct usersupp temp;
831 struct cdbdata *cdbus;
833 cdb_begin_transaction();
834 getuser(&CC->usersupp, CC->curr_user);
835 if (CtdlAccessCheck(ac_room_aide)) return;
837 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
838 cdb_rewind(CDB_USERSUPP);
839 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
840 memset(&temp, 0, sizeof temp);
841 memcpy(&temp, cdbus->ptr, sizeof temp);
844 if ((CC->quickroom.QRflags & QR_INUSE)
845 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
847 cprintf("%s\n", temp.fullname);
849 cdb_end_transaction();
855 * RDIR command for room directory
865 if (CtdlAccessCheck(ac_logged_in)) return;
867 getroom(&CC->quickroom, CC->quickroom.QRname);
868 getuser(&CC->usersupp, CC->curr_user);
870 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
871 cprintf("%d not here.\n", ERROR + NOT_HERE);
874 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
875 && (CC->usersupp.axlevel < 6)
876 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
877 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
880 cprintf("%d %s|%s/files/%s\n",
881 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
883 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
884 BBSDIR, CC->quickroom.QRdirname, CC->temp);
887 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
888 fd = fopen(buf, "r");
890 fd = fopen("/dev/null", "r");
892 ls = fopen(CC->temp, "r");
893 while (fgets(flnm, sizeof flnm, ls) != NULL) {
894 flnm[strlen(flnm) - 1] = 0;
895 if (strcasecmp(flnm, "filedir")) {
896 sprintf(buf, "%s/files/%s/%s",
897 BBSDIR, CC->quickroom.QRdirname, flnm);
901 while ((fgets(buf, sizeof buf, fd) != NULL)
902 && (strlen(comment) == 0)) {
903 buf[strlen(buf) - 1] = 0;
904 if ((!strncasecmp(buf, flnm, strlen(flnm)))
905 && (buf[strlen(flnm)] == ' '))
907 &buf[strlen(flnm) + 1],
910 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
921 * get room parameters (aide or room aide command)
925 if (CtdlAccessCheck(ac_room_aide)) return;
928 if (is_noneditable(&CC->quickroom)) {
929 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
934 getroom(&CC->quickroom, CC->quickroom.QRname);
935 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
936 OK, CtdlCheckExpress(),
937 CC->quickroom.QRname,
938 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
939 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
940 CC->quickroom.QRflags,
941 (int) CC->quickroom.QRfloor,
942 (int) CC->quickroom.QRorder);
947 * set room parameters (aide or room aide command)
949 void cmd_setr(char *args)
954 char old_name[ROOMNAMELEN];
959 if (CtdlAccessCheck(ac_room_aide)) return;
961 if (is_noneditable(&CC->quickroom)) {
966 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
972 if (num_parms(args) >= 6) {
973 fl = cgetfloor(extract_int(args, 5));
974 if ((fl->f_flags & F_INUSE) == 0) {
975 cprintf("%d Invalid floor number.\n",
976 ERROR + INVALID_FLOOR_OPERATION);
980 if (num_parms(args) >= 7) {
981 new_order = extract_int(args, 6);
987 lgetroom(&CC->quickroom, CC->quickroom.QRname);
989 /* Non-editable base rooms can't be renamed */
990 strcpy(old_name, CC->quickroom.QRname);
992 extract(buf, args, 0);
993 buf[ROOMNAMELEN] = 0;
994 safestrncpy(CC->quickroom.QRname, buf,
995 sizeof CC->quickroom.QRname);
998 extract(buf, args, 1);
1000 safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
1001 extract(buf, args, 2);
1003 safestrncpy(CC->quickroom.QRdirname, buf,
1004 sizeof CC->quickroom.QRdirname);
1005 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
1006 if (num_parms(args) >= 7)
1007 CC->quickroom.QRorder = (char) new_order;
1009 /* Clean up a client boo-boo: if the client set the room to
1010 * guess-name or passworded, ensure that the private flag is
1013 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1014 || (CC->quickroom.QRflags & QR_PASSWORDED))
1015 CC->quickroom.QRflags |= QR_PRIVATE;
1017 /* Kick everyone out if the client requested it (by changing the
1018 * room's generation number)
1020 if (extract_int(args, 4)) {
1021 time(&CC->quickroom.QRgen);
1023 old_floor = CC->quickroom.QRfloor;
1024 if (num_parms(args) >= 6) {
1025 CC->quickroom.QRfloor = extract_int(args, 5);
1027 /* Write the room record back to disk */
1028 lputroom(&CC->quickroom);
1030 /* If the room name changed, then there are now two room records,
1031 * so we have to delete the old one.
1033 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1034 b_deleteroom(old_name);
1036 /* adjust the floor reference counts */
1037 lgetfloor(&flbuf, old_floor);
1038 --flbuf.f_ref_count;
1039 lputfloor(&flbuf, old_floor);
1040 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1041 ++flbuf.f_ref_count;
1042 lputfloor(&flbuf, CC->quickroom.QRfloor);
1044 /* create a room directory if necessary */
1045 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1047 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1048 CC->quickroom.QRdirname);
1051 sprintf(buf, "%s> edited by %s\n", CC->quickroom.QRname, CC->curr_user);
1053 cprintf("%d Ok\n", OK);
1059 * get the name of the room aide for this room
1063 struct usersupp usbuf;
1065 if (CtdlAccessCheck(ac_logged_in)) return;
1067 if (is_noneditable(&CC->quickroom)) {
1068 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1071 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1072 cprintf("%d %s\n", OK, usbuf.fullname);
1074 cprintf("%d \n", OK);
1080 * set the room aide for this room
1082 void cmd_seta(char *new_ra)
1084 struct usersupp usbuf;
1089 if (CtdlAccessCheck(ac_room_aide)) return;
1091 if (getuser(&usbuf, new_ra) != 0) {
1094 newu = usbuf.usernum;
1097 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1099 if (CC->quickroom.QRroomaide != newu) {
1102 CC->quickroom.QRroomaide = newu;
1103 lputroom(&CC->quickroom);
1106 * We have to post the change notice _after_ writing changes to
1107 * the room table, otherwise it would deadlock!
1109 if (post_notice == 1) {
1110 sprintf(buf, "%s is now room aide for %s>\n",
1111 usbuf.fullname, CC->quickroom.QRname);
1114 cprintf("%d Ok\n", OK);
1118 * Generate an associated file name for a room
1120 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1122 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1126 * retrieve info file for this room
1134 assoc_file_name(filename, &CC->quickroom, "info");
1135 info_fp = fopen(filename, "r");
1137 if (info_fp == NULL) {
1138 cprintf("%d No info file.\n", ERROR);
1141 cprintf("%d Info:\n", LISTING_FOLLOWS);
1142 while (fgets(buf, sizeof buf, info_fp) != NULL) {
1143 if (strlen(buf) > 0)
1144 buf[strlen(buf) - 1] = 0;
1145 cprintf("%s\n", buf);
1152 * Back end processing to delete a room and everything associated with it
1154 void delete_room(struct quickroom *qrbuf)
1159 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1161 /* Delete the info file */
1162 assoc_file_name(filename, qrbuf, "info");
1165 /* Delete the image file */
1166 assoc_file_name(filename, qrbuf, "images");
1169 /* Delete the room's network config file */
1170 assoc_file_name(filename, qrbuf, "netconfigs");
1173 /* Delete the messages in the room
1174 * (Careful: this opens an S_QUICKROOM critical section!)
1176 CtdlDeleteMessages(qrbuf->QRname, 0L, "");
1178 /* Flag the room record as not in use */
1179 lgetroom(qrbuf, qrbuf->QRname);
1183 /* then decrement the reference count for the floor */
1184 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1185 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1186 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1188 /* Delete the room record from the database! */
1189 b_deleteroom(qrbuf->QRname);
1195 * Check access control for deleting a room
1197 int CtdlDoIHavePermissionToDeleteThisRoom(struct quickroom *qr) {
1199 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1203 if (is_noneditable(qr)) {
1208 * For mailboxes, check stuff
1210 if (qr->QRflags & QR_MAILBOX) {
1212 if (strlen(qr->QRname) < 12) return(0); /* bad name */
1214 if (atol(qr->QRname) != CC->usersupp.usernum) {
1215 return(0); /* not my room */
1218 /* Can't delete your Mail> room */
1219 if (!strcasecmp(&qr->QRname[12], MAILROOM)) return(0);
1221 /* Otherwise it's ok */
1226 * For normal rooms, just check for aide or room aide status.
1229 return(is_room_aide());
1232 /* Should never get to this point, but to keep the compiler quiet... */
1237 * aide command: kill the current room
1239 void cmd_kill(char *argbuf)
1242 char deleted_room_name[ROOMNAMELEN];
1245 kill_ok = extract_int(argbuf, 0);
1247 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->quickroom) == 0) {
1248 cprintf("%d Can't delete this room.\n", ERROR + NOT_HERE);
1252 strcpy(deleted_room_name, CC->quickroom.QRname);
1253 delete_room(&CC->quickroom); /* Do the dirty work */
1254 usergoto(BASEROOM, 0, NULL, NULL); /* Return to the Lobby */
1256 /* tell the world what we did */
1257 sprintf(aaa, "%s> killed by %s\n",
1258 deleted_room_name, CC->curr_user);
1260 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1262 cprintf("%d ok to delete.\n", OK);
1268 * Internal code to create a new room (returns room flags)
1270 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only,
1271 * 4=mailbox, 5=mailbox, but caller supplies namespace
1273 unsigned create_room(char *new_room_name,
1275 char *new_room_pass,
1280 struct quickroom qrbuf;
1284 lprintf(9, "create_room(%s)\n", new_room_name);
1285 if (getroom(&qrbuf, new_room_name) == 0) {
1286 lprintf(9, "%s already exists.\n", new_room_name);
1287 return (0); /* already exists */
1291 memset(&qrbuf, 0, sizeof(struct quickroom));
1292 safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
1293 qrbuf.QRflags = QR_INUSE;
1294 if (new_room_type > 0)
1295 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1296 if (new_room_type == 1)
1297 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1298 if (new_room_type == 2)
1299 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1300 if ( (new_room_type == 4) || (new_room_type == 5) )
1301 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1303 /* If the user is requesting a personal room, set up the room
1304 * name accordingly (prepend the user number)
1306 if (new_room_type == 4) {
1307 MailboxName(qrbuf.QRname, &CC->usersupp, new_room_name);
1310 safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
1313 /* If the room is private, and the system administrator has elected
1314 * to automatically grant room aide privileges, do so now; otherwise,
1315 * set the room aide to undefined.
1317 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1318 qrbuf.QRroomaide = CC->usersupp.usernum;
1320 qrbuf.QRroomaide = (-1L);
1324 * If the caller is only interested in testing whether this will work,
1325 * return now without creating the room.
1327 if (!really_create) return (qrbuf.QRflags);
1329 /* cdb_begin_transaction(); commented out because a transaction
1330 is already open when creating __CtdlSMTPspoolout__ while
1331 initializing serv_smtp.c
1334 qrbuf.QRnumber = get_new_room_number();
1335 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1336 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1337 qrbuf.QRfloor = new_room_floor;
1339 /* save what we just did... */
1342 /* bump the reference count on whatever floor the room is on */
1343 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1344 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1345 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1347 /* be sure not to kick the creator out of the room! */
1348 lgetuser(&CC->usersupp, CC->curr_user);
1349 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1350 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1351 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1352 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1353 lputuser(&CC->usersupp);
1355 /* resume our happy day */
1356 /* cdb_end_transaction(); */
1357 return (qrbuf.QRflags);
1364 void cmd_cre8(char *args)
1367 char new_room_name[SIZ];
1369 char new_room_pass[SIZ];
1373 struct quickroom qrbuf;
1376 cre8_ok = extract_int(args, 0);
1377 extract(new_room_name, args, 1);
1378 new_room_name[ROOMNAMELEN - 1] = 0;
1379 new_room_type = extract_int(args, 2);
1380 extract(new_room_pass, args, 3);
1381 new_room_pass[9] = 0;
1384 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1385 cprintf("%d Invalid room name.\n", ERROR);
1389 if (!strcasecmp(new_room_name, MAILROOM)) {
1390 cprintf("%d '%s' already exists.\n",
1391 ERROR + ALREADY_EXISTS, new_room_name);
1395 if (num_parms(args) >= 5) {
1396 fl = cgetfloor(extract_int(args, 4));
1397 if ((fl->f_flags & F_INUSE) == 0) {
1398 cprintf("%d Invalid floor number.\n",
1399 ERROR + INVALID_FLOOR_OPERATION);
1402 new_room_floor = extract_int(args, 4);
1406 if (CtdlAccessCheck(ac_logged_in)) return;
1408 if (CC->usersupp.axlevel < config.c_createax) {
1409 cprintf("%d You need higher access to create rooms.\n",
1410 ERROR + HIGHER_ACCESS_REQUIRED);
1414 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1415 cprintf("%d Ok to create rooms.\n", OK);
1419 if ((new_room_type < 0) || (new_room_type > 4)) {
1420 cprintf("%d Invalid room type.\n", ERROR);
1424 /* Check to make sure the requested room name doesn't already exist */
1425 newflags = create_room(new_room_name,
1426 new_room_type, new_room_pass, new_room_floor, 0);
1427 if (newflags == 0) {
1428 cprintf("%d '%s' already exists.\n",
1429 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1434 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1438 /* If we reach this point, the room needs to be created. */
1440 newflags = create_room(new_room_name,
1441 new_room_type, new_room_pass, new_room_floor, 1);
1443 /* post a message in Aide> describing the new room */
1444 safestrncpy(aaa, new_room_name, sizeof aaa);
1445 strcat(aaa, "> created by ");
1446 strcat(aaa, CC->usersupp.fullname);
1447 if (newflags & QR_MAILBOX)
1448 strcat(aaa, " [personal]");
1449 else if (newflags & QR_PRIVATE)
1450 strcat(aaa, " [private]");
1451 if (newflags & QR_GUESSNAME)
1452 strcat(aaa, "[guessname] ");
1453 if (newflags & QR_PASSWORDED) {
1454 strcat(aaa, "\n Password: ");
1455 strcat(aaa, new_room_pass);
1460 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1465 void cmd_einf(char *ok)
1466 { /* enter info file for current room */
1468 char infofilename[SIZ];
1471 if (CtdlAccessCheck(ac_room_aide)) return;
1473 if (atoi(ok) == 0) {
1474 cprintf("%d Ok.\n", OK);
1477 assoc_file_name(infofilename, &CC->quickroom, "info");
1478 lprintf(9, "opening\n");
1479 fp = fopen(infofilename, "w");
1480 lprintf(9, "checking\n");
1482 cprintf("%d Cannot open %s: %s\n",
1483 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1486 cprintf("%d Send info...\n", SEND_LISTING);
1490 if (strcmp(buf, "000"))
1491 fprintf(fp, "%s\n", buf);
1492 } while (strcmp(buf, "000"));
1495 /* now update the room index so people will see our new info */
1496 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1497 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1498 lputroom(&CC->quickroom);
1503 * cmd_lflr() - List all known floors
1510 if (CtdlAccessCheck(ac_logged_in)) return;
1512 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1514 for (a = 0; a < MAXFLOORS; ++a) {
1515 getfloor(&flbuf, a);
1516 if (flbuf.f_flags & F_INUSE) {
1517 cprintf("%d|%s|%d\n",
1529 * create a new floor
1531 void cmd_cflr(char *argbuf)
1533 char new_floor_name[SIZ];
1536 int free_slot = (-1);
1539 extract(new_floor_name, argbuf, 0);
1540 cflr_ok = extract_int(argbuf, 1);
1543 if (CtdlAccessCheck(ac_aide)) return;
1545 for (a = 0; a < MAXFLOORS; ++a) {
1546 getfloor(&flbuf, a);
1548 /* note any free slots while we're scanning... */
1549 if (((flbuf.f_flags & F_INUSE) == 0)
1553 /* check to see if it already exists */
1554 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1555 && (flbuf.f_flags & F_INUSE)) {
1556 cprintf("%d Floor '%s' already exists.\n",
1557 ERROR + ALREADY_EXISTS,
1563 if (free_slot < 0) {
1564 cprintf("%d There is no space available for a new floor.\n",
1565 ERROR + INVALID_FLOOR_OPERATION);
1569 cprintf("%d ok to create...\n", OK);
1572 lgetfloor(&flbuf, free_slot);
1573 flbuf.f_flags = F_INUSE;
1574 flbuf.f_ref_count = 0;
1575 safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
1576 lputfloor(&flbuf, free_slot);
1577 cprintf("%d %d\n", OK, free_slot);
1585 void cmd_kflr(char *argbuf)
1588 int floor_to_delete;
1592 floor_to_delete = extract_int(argbuf, 0);
1593 kflr_ok = extract_int(argbuf, 1);
1595 if (CtdlAccessCheck(ac_aide)) return;
1597 lgetfloor(&flbuf, floor_to_delete);
1600 if ((flbuf.f_flags & F_INUSE) == 0) {
1601 cprintf("%d Floor %d not in use.\n",
1602 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1605 if (flbuf.f_ref_count != 0) {
1606 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1607 ERROR + INVALID_FLOOR_OPERATION,
1612 cprintf("%d Ok\n", OK);
1614 cprintf("%d Ok to delete...\n", OK);
1621 if ((delete_ok == 1) && (kflr_ok == 1))
1623 lputfloor(&flbuf, floor_to_delete);
1629 void cmd_eflr(char *argbuf)
1635 np = num_parms(argbuf);
1637 cprintf("%d Usage error.\n", ERROR);
1641 if (CtdlAccessCheck(ac_aide)) return;
1643 floor_num = extract_int(argbuf, 0);
1644 lgetfloor(&flbuf, floor_num);
1645 if ((flbuf.f_flags & F_INUSE) == 0) {
1646 lputfloor(&flbuf, floor_num);
1647 cprintf("%d Floor %d is not in use.\n",
1648 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1652 extract(flbuf.f_name, argbuf, 1);
1653 lputfloor(&flbuf, floor_num);
1655 cprintf("%d Ok\n", OK);