19 #include "sysdep_decls.h"
23 #include "serv_chat.h"
24 #include "citserver.h"
29 * Generic routine for determining user access to rooms
31 int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
36 /* for internal programs, always do everything */
37 if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
38 return (UA_KNOWN | UA_GOTOALLOWED);
40 /* For mailbox rooms, only allow access to the owner */
41 if (roombuf->QRflags & QR_MAILBOX) {
42 if (userbuf->usernum != atol(roombuf->QRname)) {
46 /* Locate any applicable user/room relationships */
47 CtdlGetRelationship(&vbuf, userbuf, roombuf);
49 /* Force the properties of the Aide room */
50 if (!strcasecmp(roombuf->QRname, AIDEROOM)) {
51 if (userbuf->axlevel >= 6) {
52 retval = UA_KNOWN | UA_GOTOALLOWED;
58 /* For mailboxes, we skip all the access stuff (and we've
59 * already checked by this point that the mailbox belongs
62 if (roombuf->QRflags & QR_MAILBOX) {
63 retval = UA_KNOWN | UA_GOTOALLOWED;
66 /* If this is a public room, it's accessible... */
67 if ((roombuf->QRflags & QR_PRIVATE) == 0) {
68 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
70 /* If this is a preferred users only room, check access level */
71 if (roombuf->QRflags & QR_PREFONLY) {
72 if (userbuf->axlevel < 5) {
73 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
76 /* For private rooms, check the generation number matchups */
77 if (roombuf->QRflags & QR_PRIVATE) {
79 /* An explicit match means the user belongs in this room */
80 if (vbuf.v_flags & V_ACCESS) {
81 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
83 /* Otherwise, check if this is a guess-name or passworded
84 * room. If it is, a goto may at least be attempted
86 else if ((roombuf->QRflags & QR_PRIVATE)
87 || (roombuf->QRflags & QR_PASSWORDED)) {
88 retval = retval & ~UA_KNOWN;
89 retval = retval | UA_GOTOALLOWED;
92 /* Check to see if the user has forgotten this room */
93 if (vbuf.v_flags & V_FORGET) {
94 retval = retval & ~UA_KNOWN;
95 retval = retval | UA_ZAPPED;
97 /* If user is explicitly locked out of this room, deny everything */
98 if (vbuf.v_flags & V_LOCKOUT) {
99 retval = retval & ~UA_KNOWN & ~UA_GOTOALLOWED;
101 /* Aides get access to everything */
102 if (userbuf->axlevel >= 6) {
103 retval = retval | UA_KNOWN | UA_GOTOALLOWED;
104 retval = retval & ~UA_ZAPPED;
106 NEWMSG: /* By the way, we also check for the presence of new messages */
107 if ((roombuf->QRhighest) > (vbuf.v_lastseen)) {
108 retval = retval | UA_HASNEWMSGS;
114 * Self-checking stuff for a room record read into memory
116 void room_sanity_check(struct quickroom *qrbuf)
118 /* Mailbox rooms are always on the lowest floor */
119 if (qrbuf->QRflags & QR_MAILBOX) {
122 /* Listing order of 0 is illegal except for base rooms */
123 if (qrbuf->QRorder == 0)
124 if (!is_noneditable(qrbuf))
130 * getroom() - retrieve room data from disk
132 int getroom(struct quickroom *qrbuf, char *room_name)
134 struct cdbdata *cdbqr;
135 char lowercase_name[ROOMNAMELEN];
136 char personal_lowercase_name[ROOMNAMELEN];
139 for (a = 0; room_name[a] && a < sizeof lowercase_name - 1; ++a) {
140 lowercase_name[a] = tolower(room_name[a]);
142 lowercase_name[a] = 0;
144 memset(qrbuf, 0, sizeof(struct quickroom));
146 /* First, try the public namespace */
147 cdbqr = cdb_fetch(CDB_QUICKROOM,
148 lowercase_name, strlen(lowercase_name));
150 /* If that didn't work, try the user's personal namespace */
152 sprintf(personal_lowercase_name, "%010ld.%s",
153 CC->usersupp.usernum, lowercase_name);
154 cdbqr = cdb_fetch(CDB_QUICKROOM,
155 personal_lowercase_name,
156 strlen(personal_lowercase_name));
159 memcpy(qrbuf, cdbqr->ptr,
160 ((cdbqr->len > sizeof(struct quickroom)) ?
161 sizeof(struct quickroom) : cdbqr->len));
164 room_sanity_check(qrbuf);
173 * lgetroom() - same as getroom() but locks the record (if supported)
175 int lgetroom(struct quickroom *qrbuf, char *room_name)
177 begin_critical_section(S_QUICKROOM);
178 return (getroom(qrbuf, room_name));
183 * b_putroom() - back end to putroom() and b_deleteroom()
184 * (if the supplied buffer is NULL, delete the room record)
186 void b_putroom(struct quickroom *qrbuf, char *room_name)
188 char lowercase_name[ROOMNAMELEN];
191 for (a = 0; a <= strlen(room_name); ++a) {
192 lowercase_name[a] = tolower(room_name[a]);
196 cdb_delete(CDB_QUICKROOM,
197 lowercase_name, strlen(lowercase_name));
199 time(&qrbuf->QRmtime);
200 cdb_store(CDB_QUICKROOM,
201 lowercase_name, strlen(lowercase_name),
202 qrbuf, sizeof(struct quickroom));
208 * putroom() - store room data to disk
210 void putroom(struct quickroom *qrbuf) {
211 b_putroom(qrbuf, qrbuf->QRname);
216 * b_deleteroom() - delete a room record from disk
218 void b_deleteroom(char *room_name) {
219 b_putroom(NULL, room_name);
225 * lputroom() - same as putroom() but unlocks the record (if supported)
227 void lputroom(struct quickroom *qrbuf)
231 end_critical_section(S_QUICKROOM);
235 /****************************************************************************/
238 * getfloor() - retrieve floor data from disk
240 void getfloor(struct floor *flbuf, int floor_num)
242 struct cdbdata *cdbfl;
244 memset(flbuf, 0, sizeof(struct floor));
245 cdbfl = cdb_fetch(CDB_FLOORTAB, &floor_num, sizeof(int));
247 memcpy(flbuf, cdbfl->ptr,
248 ((cdbfl->len > sizeof(struct floor)) ?
249 sizeof(struct floor) : cdbfl->len));
252 if (floor_num == 0) {
253 strcpy(flbuf->f_name, "Main Floor");
254 flbuf->f_flags = F_INUSE;
255 flbuf->f_ref_count = 3;
262 * lgetfloor() - same as getfloor() but locks the record (if supported)
264 void lgetfloor(struct floor *flbuf, int floor_num)
267 begin_critical_section(S_FLOORTAB);
268 getfloor(flbuf, floor_num);
273 * putfloor() - store floor data on disk
275 void putfloor(struct floor *flbuf, int floor_num)
277 cdb_store(CDB_FLOORTAB, &floor_num, sizeof(int),
278 flbuf, sizeof(struct floor));
283 * lputfloor() - same as putfloor() but unlocks the record (if supported)
285 void lputfloor(struct floor *flbuf, int floor_num)
288 putfloor(flbuf, floor_num);
289 end_critical_section(S_FLOORTAB);
295 * Traverse the room file...
297 void ForEachRoom(void (*CallBack) (struct quickroom * EachRoom))
299 struct quickroom qrbuf;
300 struct cdbdata *cdbqr;
302 cdb_rewind(CDB_QUICKROOM);
304 while (cdbqr = cdb_next_item(CDB_QUICKROOM), cdbqr != NULL) {
305 memset(&qrbuf, 0, sizeof(struct quickroom));
306 memcpy(&qrbuf, cdbqr->ptr,
307 ((cdbqr->len > sizeof(struct quickroom)) ?
308 sizeof(struct quickroom) : cdbqr->len));
310 room_sanity_check(&qrbuf);
311 if (qrbuf.QRflags & QR_INUSE)
312 (*CallBack) (&qrbuf);
318 * delete_msglist() - delete room message pointers
319 * FIX - this really should check first to make sure there's actually a
320 * msglist to delete. As things stand now, calling this function on
321 * a room which has never been posted in will result in a message
322 * like "gdbm: illegal data" (no big deal, but could use fixing).
324 void delete_msglist(struct quickroom *whichroom)
327 cdb_delete(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
332 * Add a message number to a room's message list.
334 * This function returns the highest message number present in the room after
335 * the add operation is performed - which is not necessarily the message
338 long AddMessageToRoom(struct quickroom *whichroom, long newmsgid)
340 struct cdbdata *cdbfr;
343 long highest_msg = 0L;
345 lprintf(9, "AddMessageToRoom(%s, %ld)\n", whichroom->QRname, newmsgid);
346 cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
351 msglist = mallok(cdbfr->len);
353 lprintf(3, "ERROR malloc msglist!\n");
354 num_msgs = cdbfr->len / sizeof(long);
355 memcpy(msglist, cdbfr->ptr, cdbfr->len);
359 /* Now add the new message */
361 msglist = reallok(msglist,
362 (num_msgs * sizeof(long)));
364 if (msglist == NULL) {
365 lprintf(3, "ERROR: can't realloc message list!\n");
367 msglist[num_msgs - 1] = newmsgid;
369 /* Sort the message list, so all the msgid's are in order */
370 num_msgs = sort_msglist(msglist, num_msgs);
372 /* Determine the highest message number */
373 highest_msg = msglist[num_msgs - 1];
375 /* Write it back to disk. */
376 cdb_store(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long),
377 msglist, num_msgs * sizeof(long));
379 /* And finally, free up the memory we used. */
381 return (highest_msg);
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)
477 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
478 & (UA_KNOWN | UA_ZAPPED)))
479 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
480 || ((CC->FloorBeingSearched) < 0)))
481 list_roomname(qrbuf);
484 void cmd_lrms(char *argbuf)
486 CC->FloorBeingSearched = (-1);
487 if (strlen(argbuf) > 0)
488 CC->FloorBeingSearched = extract_int(argbuf, 0);
490 if (!(CC->logged_in)) {
491 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
494 if (getuser(&CC->usersupp, CC->curr_user)) {
495 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
498 cprintf("%d Accessible rooms:\n", LISTING_FOLLOWS);
500 ForEachRoom(cmd_lrms_backend);
507 * cmd_lkra() - List all known rooms
509 void cmd_lkra_backend(struct quickroom *qrbuf)
511 if (((CtdlRoomAccess(qrbuf, &CC->usersupp)
513 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
514 || ((CC->FloorBeingSearched) < 0)))
515 list_roomname(qrbuf);
518 void cmd_lkra(char *argbuf)
520 CC->FloorBeingSearched = (-1);
521 if (strlen(argbuf) > 0)
522 CC->FloorBeingSearched = extract_int(argbuf, 0);
524 if (!(CC->logged_in)) {
525 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
528 if (getuser(&CC->usersupp, CC->curr_user)) {
529 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
532 cprintf("%d Known rooms:\n", LISTING_FOLLOWS);
534 ForEachRoom(cmd_lkra_backend);
541 * cmd_lkrn() - List all known rooms with new messages
543 void cmd_lkrn_backend(struct quickroom *qrbuf)
547 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
549 && (ra & UA_HASNEWMSGS)
550 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
551 || ((CC->FloorBeingSearched) < 0)))
552 list_roomname(qrbuf);
555 void cmd_lkrn(char *argbuf)
557 CC->FloorBeingSearched = (-1);
558 if (strlen(argbuf) > 0)
559 CC->FloorBeingSearched = extract_int(argbuf, 0);
561 if (!(CC->logged_in)) {
562 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
565 if (getuser(&CC->usersupp, CC->curr_user)) {
566 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
569 cprintf("%d Rooms w/ new msgs:\n", LISTING_FOLLOWS);
571 ForEachRoom(cmd_lkrn_backend);
578 * cmd_lkro() - List all known rooms
580 void cmd_lkro_backend(struct quickroom *qrbuf)
584 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
586 && ((ra & UA_HASNEWMSGS) == 0)
587 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
588 || ((CC->FloorBeingSearched) < 0)))
589 list_roomname(qrbuf);
592 void cmd_lkro(char *argbuf)
594 CC->FloorBeingSearched = (-1);
595 if (strlen(argbuf) > 0)
596 CC->FloorBeingSearched = extract_int(argbuf, 0);
598 if (!(CC->logged_in)) {
599 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
602 if (getuser(&CC->usersupp, CC->curr_user)) {
603 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
606 cprintf("%d Rooms w/o new msgs:\n", LISTING_FOLLOWS);
608 ForEachRoom(cmd_lkro_backend);
615 * cmd_lzrm() - List all forgotten rooms
617 void cmd_lzrm_backend(struct quickroom *qrbuf)
621 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
622 if ((ra & UA_GOTOALLOWED)
624 && ((qrbuf->QRfloor == (CC->FloorBeingSearched))
625 || ((CC->FloorBeingSearched) < 0)))
626 list_roomname(qrbuf);
629 void cmd_lzrm(char *argbuf)
631 CC->FloorBeingSearched = (-1);
632 if (strlen(argbuf) > 0)
633 CC->FloorBeingSearched = extract_int(argbuf, 0);
635 if (!(CC->logged_in)) {
636 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
639 if (getuser(&CC->usersupp, CC->curr_user)) {
640 cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR);
643 cprintf("%d Zapped rooms:\n", LISTING_FOLLOWS);
645 ForEachRoom(cmd_lzrm_backend);
651 void usergoto(char *where, int display_result)
654 int new_messages = 0;
655 int total_messages = 0;
659 int newmailcount = 0;
661 char truncated_roomname[ROOMNAMELEN];
662 struct cdbdata *cdbfr;
663 long *msglist = NULL;
666 strcpy(CC->quickroom.QRname, where);
667 getroom(&CC->quickroom, where);
669 lgetuser(&CC->usersupp, CC->curr_user);
670 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
672 /* Know the room ... but not if it's the page log room */
673 if (strcasecmp(where, config.c_logpages)) {
674 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
675 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
677 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
678 lputuser(&CC->usersupp);
680 /* check for new mail */
681 newmailcount = NewMailCount();
683 /* set info to 1 if the user needs to read the room's info file */
684 if (CC->quickroom.QRinfo > vbuf.v_lastseen)
688 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->quickroom.QRnumber, sizeof(long));
690 msglist = mallok(cdbfr->len);
691 memcpy(msglist, cdbfr->ptr, cdbfr->len);
692 num_msgs = cdbfr->len / sizeof(long);
696 if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
697 if (msglist[a] > 0L) {
699 if (msglist[a] > vbuf.v_lastseen) {
705 if (msglist != NULL) phree(msglist);
707 if (CC->quickroom.QRflags & QR_MAILBOX)
712 if ((CC->quickroom.QRroomaide == CC->usersupp.usernum)
713 || (CC->usersupp.axlevel >= 6))
718 strcpy(truncated_roomname, CC->quickroom.QRname);
719 if (CC->quickroom.QRflags & QR_MAILBOX) {
720 strcpy(truncated_roomname, &truncated_roomname[11]);
724 cprintf("%d%c%s|%d|%d|%d|%d|%ld|%ld|%d|%d|%d|%d\n",
727 new_messages, total_messages,
728 info, CC->quickroom.QRflags,
729 CC->quickroom.QRhighest,
731 rmailflag, raideflag, newmailcount,
732 CC->quickroom.QRfloor);
734 set_wtmpsupp_to_current_room();
739 * cmd_goto() - goto a new room
741 void cmd_goto(char *gargs)
743 struct quickroom QRscratch;
747 char augmented_roomname[256];
751 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
752 cprintf("%d not logged in\n", ERROR + NOT_LOGGED_IN);
756 extract(towhere, gargs, 0);
757 extract(password, gargs, 1);
759 getuser(&CC->usersupp, CC->curr_user);
761 if (!strcasecmp(towhere, "_BASEROOM_"))
762 strcpy(towhere, BASEROOM);
764 if (!strcasecmp(towhere, "_MAIL_"))
765 strcpy(towhere, MAILROOM);
767 if (!strcasecmp(towhere, "_BITBUCKET_"))
768 strcpy(towhere, config.c_twitroom);
771 /* First try a regular match */
772 c = getroom(&QRscratch, towhere);
774 /* Then try a mailbox name match */
776 MailboxName(augmented_roomname, &CC->usersupp, towhere);
777 c = getroom(&QRscratch, augmented_roomname);
779 strcpy(towhere, augmented_roomname);
782 /* And if the room was found... */
785 /* let internal programs go directly to any room */
786 if (CC->internal_pgm) {
787 usergoto(towhere, 1);
791 /* See if there is an existing user/room relationship */
792 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
794 /* normal clients have to pass through security */
795 if (ra & UA_GOTOALLOWED)
799 if ((QRscratch.QRflags & QR_PASSWORDED) &&
800 ((ra & UA_KNOWN) == 0) &&
801 (strcasecmp(QRscratch.QRpasswd, password))
803 cprintf("%d wrong or missing passwd\n",
804 ERROR + PASSWORD_REQUIRED);
806 } else if ((QRscratch.QRflags & QR_PRIVATE) &&
807 ((QRscratch.QRflags & QR_PASSWORDED) == 0) &&
808 ((QRscratch.QRflags & QR_GUESSNAME) == 0) &&
809 ((ra & UA_KNOWN) == 0)) {
812 usergoto(towhere, 1);
818 NOPE: cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere);
824 struct usersupp temp;
825 struct cdbdata *cdbus;
827 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
828 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
831 getuser(&CC->usersupp, CC->curr_user);
833 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
834 cprintf("%d Higher access required.\n",
835 ERROR + HIGHER_ACCESS_REQUIRED);
838 cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
839 cdb_rewind(CDB_USERSUPP);
840 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
841 memset(&temp, 0, sizeof(struct usersupp));
842 memcpy(&temp, cdbus->ptr, cdbus->len);
845 if ((CC->quickroom.QRflags & QR_INUSE)
846 && (CtdlRoomAccess(&CC->quickroom, &temp) & UA_KNOWN)
848 cprintf("%s\n", temp.fullname);
855 * RDIR command for room directory
865 if (!(CC->logged_in)) {
866 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
869 getroom(&CC->quickroom, CC->quickroom.QRname);
870 getuser(&CC->usersupp, CC->curr_user);
872 if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
873 cprintf("%d not here.\n", ERROR + NOT_HERE);
876 if (((CC->quickroom.QRflags & QR_VISDIR) == 0)
877 && (CC->usersupp.axlevel < 6)
878 && (CC->usersupp.usernum != CC->quickroom.QRroomaide)) {
879 cprintf("%d not here.\n", ERROR + HIGHER_ACCESS_REQUIRED);
882 cprintf("%d %s|%s/files/%s\n",
883 LISTING_FOLLOWS, config.c_fqdn, BBSDIR, CC->quickroom.QRdirname);
885 sprintf(buf, "ls %s/files/%s >%s 2> /dev/null",
886 BBSDIR, CC->quickroom.QRdirname, CC->temp);
889 sprintf(buf, "%s/files/%s/filedir", BBSDIR, CC->quickroom.QRdirname);
890 fd = fopen(buf, "r");
892 fd = fopen("/dev/null", "r");
894 ls = fopen(CC->temp, "r");
895 while (fgets(flnm, 256, ls) != NULL) {
896 flnm[strlen(flnm) - 1] = 0;
897 if (strcasecmp(flnm, "filedir")) {
898 sprintf(buf, "%s/files/%s/%s",
899 BBSDIR, CC->quickroom.QRdirname, flnm);
903 while ((fgets(buf, 256, fd) != NULL)
904 && (strlen(comment) == 0)) {
905 buf[strlen(buf) - 1] = 0;
906 if ((!strncasecmp(buf, flnm, strlen(flnm)))
907 && (buf[strlen(flnm)] == ' '))
909 &buf[strlen(flnm) + 1], 255);
911 cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
922 * get room parameters (aide or room aide command)
926 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
927 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
930 if ((!is_room_aide()) && (!(CC->internal_pgm))) {
931 cprintf("%d Higher access required.\n",
932 ERROR + HIGHER_ACCESS_REQUIRED);
935 if (is_noneditable(&CC->quickroom)) {
936 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
939 getroom(&CC->quickroom, CC->quickroom.QRname);
940 cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
942 CC->quickroom.QRname,
943 ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
944 ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
945 CC->quickroom.QRflags,
946 (int) CC->quickroom.QRfloor,
947 (int) CC->quickroom.QRorder);
952 * set room parameters (aide or room aide command)
954 void cmd_setr(char *args)
958 char old_name[ROOMNAMELEN];
962 if (!(CC->logged_in)) {
963 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
966 if (!is_room_aide()) {
967 cprintf("%d Higher access required.\n",
968 ERROR + HIGHER_ACCESS_REQUIRED);
971 if (is_noneditable(&CC->quickroom)) {
972 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
975 if (num_parms(args) >= 6) {
976 getfloor(&flbuf, extract_int(args, 5));
977 if ((flbuf.f_flags & F_INUSE) == 0) {
978 cprintf("%d Invalid floor number.\n",
979 ERROR + INVALID_FLOOR_OPERATION);
983 if (num_parms(args) >= 7) {
984 new_order = extract_int(args, 6);
990 lgetroom(&CC->quickroom, CC->quickroom.QRname);
991 strcpy(old_name, CC->quickroom.QRname);
992 extract(buf, args, 0);
993 buf[ROOMNAMELEN] = 0;
994 strncpy(CC->quickroom.QRname, buf, ROOMNAMELEN - 1);
995 extract(buf, args, 1);
997 strncpy(CC->quickroom.QRpasswd, buf, 9);
998 extract(buf, args, 2);
1000 strncpy(CC->quickroom.QRdirname, buf, 19);
1001 CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
1002 if (num_parms(args) >= 7)
1003 CC->quickroom.QRorder = (char) new_order;
1005 /* Clean up a client boo-boo: if the client set the room to
1006 * guess-name or passworded, ensure that the private flag is
1009 if ((CC->quickroom.QRflags & QR_GUESSNAME)
1010 || (CC->quickroom.QRflags & QR_PASSWORDED))
1011 CC->quickroom.QRflags |= QR_PRIVATE;
1013 /* Kick everyone out if the client requested it (by changing the
1014 * room's generation number)
1016 if (extract_int(args, 4)) {
1017 time(&CC->quickroom.QRgen);
1019 old_floor = CC->quickroom.QRfloor;
1020 if (num_parms(args) >= 6) {
1021 CC->quickroom.QRfloor = extract_int(args, 5);
1023 /* Write the room record back to disk */
1024 lputroom(&CC->quickroom);
1026 /* If the room name changed, then there are now two room records,
1027 * so we have to delete the old one.
1029 if (strcasecmp(CC->quickroom.QRname, old_name)) {
1030 b_deleteroom(old_name);
1032 /* adjust the floor reference counts */
1033 lgetfloor(&flbuf, old_floor);
1034 --flbuf.f_ref_count;
1035 lputfloor(&flbuf, old_floor);
1036 lgetfloor(&flbuf, CC->quickroom.QRfloor);
1037 ++flbuf.f_ref_count;
1038 lputfloor(&flbuf, CC->quickroom.QRfloor);
1040 /* create a room directory if necessary */
1041 if (CC->quickroom.QRflags & QR_DIRECTORY) {
1043 "mkdir ./files/%s </dev/null >/dev/null 2>/dev/null",
1044 CC->quickroom.QRdirname);
1047 sprintf(buf, "%s> edited by %s", CC->quickroom.QRname, CC->curr_user);
1049 cprintf("%d Ok\n", OK);
1055 * get the name of the room aide for this room
1059 struct usersupp usbuf;
1061 if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
1062 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1065 if (is_noneditable(&CC->quickroom)) {
1066 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1069 if (getuserbynumber(&usbuf, CC->quickroom.QRroomaide) == 0) {
1070 cprintf("%d %s\n", OK, usbuf.fullname);
1072 cprintf("%d \n", OK);
1078 * set the room aide for this room
1080 void cmd_seta(char *new_ra)
1082 struct usersupp usbuf;
1087 if (!(CC->logged_in)) {
1088 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1091 if (!is_room_aide()) {
1092 cprintf("%d Higher access required.\n",
1093 ERROR + HIGHER_ACCESS_REQUIRED);
1096 if (getuser(&usbuf, new_ra) != 0) {
1099 newu = usbuf.usernum;
1102 lgetroom(&CC->quickroom, CC->quickroom.QRname);
1104 if (CC->quickroom.QRroomaide != newu) {
1107 CC->quickroom.QRroomaide = newu;
1108 lputroom(&CC->quickroom);
1111 * We have to post the change notice _after_ writing changes to
1112 * the room table, otherwise it would deadlock!
1114 if (post_notice == 1) {
1115 sprintf(buf, "%s is now room aide for %s>",
1116 usbuf.fullname, CC->quickroom.QRname);
1119 cprintf("%d Ok\n", OK);
1123 * Generate an associated file name for a room
1125 void assoc_file_name(char *buf, struct quickroom *qrbuf, char *prefix)
1127 sprintf(buf, "./%s/%ld", prefix, qrbuf->QRnumber);
1131 * retrieve info file for this room
1139 assoc_file_name(filename, &CC->quickroom, "info");
1140 info_fp = fopen(filename, "r");
1142 if (info_fp == NULL) {
1143 cprintf("%d No info file.\n", ERROR);
1146 cprintf("%d Info:\n", LISTING_FOLLOWS);
1147 while (fgets(buf, 256, info_fp) != NULL) {
1148 if (strlen(buf) > 0)
1149 buf[strlen(buf) - 1] = 0;
1150 cprintf("%s\n", buf);
1157 * Back end processing to delete a room and everything associated with it
1159 void delete_room(struct quickroom *qrbuf)
1164 lprintf(9, "Deleting room <%s>\n", qrbuf->QRname);
1166 /* Delete the info file */
1167 assoc_file_name(filename, qrbuf, "info");
1170 /* Delete the image file */
1171 assoc_file_name(filename, qrbuf, "images");
1174 /* Delete the messages in the room
1175 * (Careful: this opens an S_QUICKROOM critical section!)
1177 CtdlDeleteMessages(qrbuf->QRname, 0L, NULL);
1179 /* Flag the room record as not in use */
1180 lgetroom(qrbuf, qrbuf->QRname);
1184 /* then decrement the reference count for the floor */
1185 lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
1186 flbuf.f_ref_count = flbuf.f_ref_count - 1;
1187 lputfloor(&flbuf, (int) (qrbuf->QRfloor));
1189 /* Delete the room record from the database! */
1190 b_deleteroom(qrbuf->QRname);
1195 * aide command: kill the current room
1197 void cmd_kill(char *argbuf)
1200 char deleted_room_name[ROOMNAMELEN];
1203 kill_ok = extract_int(argbuf, 0);
1205 if (!(CC->logged_in)) {
1206 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1209 if (!is_room_aide()) {
1210 cprintf("%d Higher access required.\n",
1211 ERROR + HIGHER_ACCESS_REQUIRED);
1214 if (is_noneditable(&CC->quickroom)) {
1215 cprintf("%d Can't edit this room.\n", ERROR + NOT_HERE);
1219 strcpy(deleted_room_name, CC->quickroom.QRname);
1220 delete_room(&CC->quickroom); /* Do the dirty work */
1221 usergoto(BASEROOM, 0); /* Return to the Lobby */
1223 /* tell the world what we did */
1224 sprintf(aaa, "%s> killed by %s",
1225 deleted_room_name, CC->curr_user);
1227 cprintf("%d '%s' deleted.\n", OK, deleted_room_name);
1229 cprintf("%d ok to delete.\n", OK);
1235 * Internal code to create a new room (returns room flags)
1237 * Room types: 0=public, 1=guessname, 2=passworded, 3=inv-only, 4=mailbox
1239 unsigned create_room(char *new_room_name,
1241 char *new_room_pass,
1245 struct quickroom qrbuf;
1249 if (getroom(&qrbuf, new_room_name) == 0)
1250 return (0); /* already exists */
1252 memset(&qrbuf, 0, sizeof(struct quickroom));
1253 strncpy(qrbuf.QRname, new_room_name, ROOMNAMELEN);
1254 strncpy(qrbuf.QRpasswd, new_room_pass, 9);
1255 qrbuf.QRflags = QR_INUSE;
1256 qrbuf.QRnumber = get_new_room_number();
1257 if (new_room_type > 0)
1258 qrbuf.QRflags = (qrbuf.QRflags | QR_PRIVATE);
1259 if (new_room_type == 1)
1260 qrbuf.QRflags = (qrbuf.QRflags | QR_GUESSNAME);
1261 if (new_room_type == 2)
1262 qrbuf.QRflags = (qrbuf.QRflags | QR_PASSWORDED);
1263 if (new_room_type == 4)
1264 qrbuf.QRflags = (qrbuf.QRflags | QR_MAILBOX);
1266 /* If the room is private, and the system administrator has elected
1267 * to automatically grant room aide privileges, do so now; otherwise,
1268 * set the room aide to undefined.
1270 if ((qrbuf.QRflags & QR_PRIVATE) && (CREATAIDE == 1)) {
1271 qrbuf.QRroomaide = CC->usersupp.usernum;
1273 qrbuf.QRroomaide = (-1L);
1276 qrbuf.QRhighest = 0L; /* No messages in this room yet */
1277 time(&qrbuf.QRgen); /* Use a timestamp as the generation number */
1278 qrbuf.QRfloor = new_room_floor;
1280 /* save what we just did... */
1283 /* bump the reference count on whatever floor the room is on */
1284 lgetfloor(&flbuf, (int) qrbuf.QRfloor);
1285 flbuf.f_ref_count = flbuf.f_ref_count + 1;
1286 lputfloor(&flbuf, (int) qrbuf.QRfloor);
1288 /* be sure not to kick the creator out of the room! */
1289 lgetuser(&CC->usersupp, CC->curr_user);
1290 CtdlGetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1291 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1292 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1293 CtdlSetRelationship(&vbuf, &CC->usersupp, &qrbuf);
1294 lputuser(&CC->usersupp);
1296 /* resume our happy day */
1297 return (qrbuf.QRflags);
1304 void cmd_cre8(char *args)
1307 char new_room_name[256];
1309 char new_room_pass[256];
1313 struct quickroom qrbuf;
1316 cre8_ok = extract_int(args, 0);
1317 extract(new_room_name, args, 1);
1318 new_room_name[ROOMNAMELEN - 1] = 0;
1319 new_room_type = extract_int(args, 2);
1320 extract(new_room_pass, args, 3);
1321 new_room_pass[9] = 0;
1324 if ((strlen(new_room_name) == 0) && (cre8_ok == 1)) {
1325 cprintf("%d Invalid room name.\n", ERROR);
1329 if (!strcasecmp(new_room_name, MAILROOM)) {
1330 cprintf("%d '%s' already exists.\n",
1331 ERROR + ALREADY_EXISTS, new_room_name);
1335 if (num_parms(args) >= 5) {
1336 getfloor(&flbuf, extract_int(args, 4));
1337 if ((flbuf.f_flags & F_INUSE) == 0) {
1338 cprintf("%d Invalid floor number.\n",
1339 ERROR + INVALID_FLOOR_OPERATION);
1342 new_room_floor = extract_int(args, 4);
1346 if (!(CC->logged_in)) {
1347 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1351 if (CC->usersupp.axlevel < config.c_createax) {
1352 cprintf("%d You need higher access to create rooms.\n",
1353 ERROR + HIGHER_ACCESS_REQUIRED);
1357 if ((strlen(new_room_name) == 0) && (cre8_ok == 0)) {
1358 cprintf("%d Ok to create rooms.\n", OK);
1362 if ((new_room_type < 0) || (new_room_type > 4)) {
1363 cprintf("%d Invalid room type.\n", ERROR);
1367 /* If the user is requesting a personal room, set up the room
1368 * name accordingly (prepend the user number)
1370 if (new_room_type == 4) {
1371 sprintf(aaa, "%010ld.%s",
1372 CC->usersupp.usernum, new_room_name);
1373 strcpy(new_room_name, aaa);
1376 /* Check to make sure the requested room name doesn't already exist */
1377 if (getroom(&qrbuf, new_room_name) == 0) {
1378 cprintf("%d '%s' already exists.\n",
1379 ERROR + ALREADY_EXISTS, qrbuf.QRname);
1384 cprintf("%d OK to create '%s'\n", OK, new_room_name);
1388 newflags = create_room(new_room_name,
1389 new_room_type, new_room_pass, new_room_floor);
1391 /* post a message in Aide> describing the new room */
1392 strncpy(aaa, new_room_name, 255);
1393 strcat(aaa, "> created by ");
1394 strcat(aaa, CC->usersupp.fullname);
1395 if (newflags & QR_MAILBOX)
1396 strcat(aaa, " [personal]");
1397 else if (newflags & QR_PRIVATE)
1398 strcat(aaa, " [private]");
1399 if (newflags & QR_GUESSNAME)
1400 strcat(aaa, "[guessname] ");
1401 if (newflags & QR_PASSWORDED) {
1402 strcat(aaa, "\n Password: ");
1403 strcat(aaa, new_room_pass);
1407 cprintf("%d '%s' has been created.\n", OK, qrbuf.QRname);
1412 void cmd_einf(char *ok)
1413 { /* enter info file for current room */
1415 char infofilename[256];
1418 if (!(CC->logged_in)) {
1419 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1422 if (!is_room_aide()) {
1423 cprintf("%d Higher access required.\n",
1424 ERROR + HIGHER_ACCESS_REQUIRED);
1427 if (atoi(ok) == 0) {
1428 cprintf("%d Ok.\n", OK);
1431 assoc_file_name(infofilename, &CC->quickroom, "info");
1432 lprintf(9, "opening\n");
1433 fp = fopen(infofilename, "w");
1434 lprintf(9, "checking\n");
1436 cprintf("%d Cannot open %s: %s\n",
1437 ERROR + INTERNAL_ERROR, infofilename, strerror(errno));
1440 cprintf("%d Send info...\n", SEND_LISTING);
1444 if (strcmp(buf, "000"))
1445 fprintf(fp, "%s\n", buf);
1446 } while (strcmp(buf, "000"));
1449 /* now update the room index so people will see our new info */
1450 lgetroom(&CC->quickroom, CC->quickroom.QRname); /* lock so no one steps on us */
1451 CC->quickroom.QRinfo = CC->quickroom.QRhighest + 1L;
1452 lputroom(&CC->quickroom);
1457 * cmd_lflr() - List all known floors
1464 if (!(CC->logged_in)) {
1465 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1468 /* if (getuser(&CC->usersupp,CC->curr_user)) {
1469 cprintf("%d Can't locate user!\n",ERROR+INTERNAL_ERROR);
1474 cprintf("%d Known floors:\n", LISTING_FOLLOWS);
1476 for (a = 0; a < MAXFLOORS; ++a) {
1477 getfloor(&flbuf, a);
1478 if (flbuf.f_flags & F_INUSE) {
1479 cprintf("%d|%s|%d\n",
1491 * create a new floor
1493 void cmd_cflr(char *argbuf)
1495 char new_floor_name[256];
1498 int free_slot = (-1);
1501 extract(new_floor_name, argbuf, 0);
1502 cflr_ok = extract_int(argbuf, 1);
1505 if (!(CC->logged_in)) {
1506 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1509 if (CC->usersupp.axlevel < 6) {
1510 cprintf("%d You need higher access to create rooms.\n",
1511 ERROR + HIGHER_ACCESS_REQUIRED);
1514 for (a = 0; a < MAXFLOORS; ++a) {
1515 getfloor(&flbuf, a);
1517 /* note any free slots while we're scanning... */
1518 if (((flbuf.f_flags & F_INUSE) == 0)
1522 /* check to see if it already exists */
1523 if ((!strcasecmp(flbuf.f_name, new_floor_name))
1524 && (flbuf.f_flags & F_INUSE)) {
1525 cprintf("%d Floor '%s' already exists.\n",
1526 ERROR + ALREADY_EXISTS,
1532 if (free_slot < 0) {
1533 cprintf("%d There is no space available for a new floor.\n",
1534 ERROR + INVALID_FLOOR_OPERATION);
1538 cprintf("%d ok to create...\n", OK);
1541 lgetfloor(&flbuf, free_slot);
1542 flbuf.f_flags = F_INUSE;
1543 flbuf.f_ref_count = 0;
1544 strncpy(flbuf.f_name, new_floor_name, 255);
1545 lputfloor(&flbuf, free_slot);
1546 cprintf("%d %d\n", OK, free_slot);
1554 void cmd_kflr(char *argbuf)
1557 int floor_to_delete;
1561 floor_to_delete = extract_int(argbuf, 0);
1562 kflr_ok = extract_int(argbuf, 1);
1565 if (!(CC->logged_in)) {
1566 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1569 if (CC->usersupp.axlevel < 6) {
1570 cprintf("%d You need higher access to delete floors.\n",
1571 ERROR + HIGHER_ACCESS_REQUIRED);
1574 lgetfloor(&flbuf, floor_to_delete);
1577 if ((flbuf.f_flags & F_INUSE) == 0) {
1578 cprintf("%d Floor %d not in use.\n",
1579 ERROR + INVALID_FLOOR_OPERATION, floor_to_delete);
1582 if (flbuf.f_ref_count != 0) {
1583 cprintf("%d Cannot delete; floor contains %d rooms.\n",
1584 ERROR + INVALID_FLOOR_OPERATION,
1589 cprintf("%d Ok\n", OK);
1591 cprintf("%d Ok to delete...\n", OK);
1598 if ((delete_ok == 1) && (kflr_ok == 1))
1600 lputfloor(&flbuf, floor_to_delete);
1606 void cmd_eflr(char *argbuf)
1612 np = num_parms(argbuf);
1614 cprintf("%d Usage error.\n", ERROR);
1617 if (!(CC->logged_in)) {
1618 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
1621 if (CC->usersupp.axlevel < 6) {
1622 cprintf("%d You need higher access to edit floors.\n",
1623 ERROR + HIGHER_ACCESS_REQUIRED);
1626 floor_num = extract_int(argbuf, 0);
1627 lgetfloor(&flbuf, floor_num);
1628 if ((flbuf.f_flags & F_INUSE) == 0) {
1629 lputfloor(&flbuf, floor_num);
1630 cprintf("%d Floor %d is not in use.\n",
1631 ERROR + INVALID_FLOOR_OPERATION, floor_num);
1635 extract(flbuf.f_name, argbuf, 1);
1636 lputfloor(&flbuf, floor_num);
1638 cprintf("%d Ok\n", OK);