4 * Server functions which perform operations on user objects.
21 #include <sys/types.h>
24 #if TIME_WITH_SYS_TIME
25 # include <sys/time.h>
29 # include <sys/time.h>
45 #include "serv_extensions.h"
46 #include "sysdep_decls.h"
55 #include "citserver.h"
59 * getuser() - retrieve named user into supplied buffer.
60 * returns 0 on success
62 int getuser(struct usersupp *usbuf, char name[])
65 char lowercase_name[USERNAME_SIZE];
66 char sysuser_name[USERNAME_SIZE];
68 struct cdbdata *cdbus;
69 int using_sysuser = 0;
71 memset(usbuf, 0, sizeof(struct usersupp));
73 #ifdef ENABLE_AUTOLOGIN
74 if (CtdlAssociateSystemUser(sysuser_name, name) == 0) {
80 for (a = 0; a <= strlen(sysuser_name); ++a) {
81 lowercase_name[a] = tolower(sysuser_name[a]);
85 for (a = 0; a <= strlen(name); ++a) {
86 if (a < sizeof(lowercase_name))
87 lowercase_name[a] = tolower(name[a]);
90 lowercase_name[sizeof(lowercase_name) - 1] = 0;
92 cdbus = cdb_fetch(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
93 if (cdbus == NULL) { /* user not found */
96 memcpy(usbuf, cdbus->ptr,
97 ((cdbus->len > sizeof(struct usersupp)) ?
98 sizeof(struct usersupp) : cdbus->len));
106 * lgetuser() - same as getuser() but locks the record
108 int lgetuser(struct usersupp *usbuf, char *name)
112 retcode = getuser(usbuf, name);
114 begin_critical_section(S_USERSUPP);
121 * putuser() - write user buffer into the correct place on disk
123 void putuser(struct usersupp *usbuf)
125 char lowercase_name[USERNAME_SIZE];
128 for (a = 0; a <= strlen(usbuf->fullname); ++a) {
129 if (a < sizeof(lowercase_name))
130 lowercase_name[a] = tolower(usbuf->fullname[a]);
132 lowercase_name[sizeof(lowercase_name) - 1] = 0;
134 usbuf->version = REV_LEVEL;
135 cdb_store(CDB_USERSUPP,
136 lowercase_name, strlen(lowercase_name),
137 usbuf, sizeof(struct usersupp));
143 * lputuser() - same as putuser() but locks the record
145 void lputuser(struct usersupp *usbuf)
148 end_critical_section(S_USERSUPP);
152 * Index-generating function used by Ctdl[Get|Set]Relationship
154 int GenerateRelationshipIndex(char *IndexBuf,
166 TheIndex.iRoomID = RoomID;
167 TheIndex.iRoomGen = RoomGen;
168 TheIndex.iUserID = UserID;
170 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
171 return (sizeof(TheIndex));
177 * Back end for CtdlSetRelationship()
179 void put_visit(struct visit *newvisit)
184 /* Generate an index */
185 IndexLen = GenerateRelationshipIndex(IndexBuf,
188 newvisit->v_usernum);
190 /* Store the record */
191 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
192 newvisit, sizeof(struct visit)
200 * Define a relationship between a user and a room
202 void CtdlSetRelationship(struct visit *newvisit,
203 struct usersupp *rel_user,
204 struct quickroom *rel_room)
208 /* We don't use these in Citadel because they're implicit by the
209 * index, but they must be present if the database is exported.
211 newvisit->v_roomnum = rel_room->QRnumber;
212 newvisit->v_roomgen = rel_room->QRgen;
213 newvisit->v_usernum = rel_user->usernum;
219 * Locate a relationship between a user and a room
221 void CtdlGetRelationship(struct visit *vbuf,
222 struct usersupp *rel_user,
223 struct quickroom *rel_room)
228 struct cdbdata *cdbvisit;
230 /* Generate an index */
231 IndexLen = GenerateRelationshipIndex(IndexBuf,
236 /* Clear out the buffer */
237 memset(vbuf, 0, sizeof(struct visit));
239 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
240 if (cdbvisit != NULL) {
241 memcpy(vbuf, cdbvisit->ptr,
242 ((cdbvisit->len > sizeof(struct visit)) ?
243 sizeof(struct visit) : cdbvisit->len));
247 /* If this is the first time the user has seen this room,
248 * set the view to be the default for the room.
250 vbuf->v_view = rel_room->QRdefaultview;
253 /* Set v_seen if necessary */
254 if (vbuf->v_seen[0] == 0) {
255 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
260 void MailboxName(char *buf, size_t n, const struct usersupp *who, const char *prefix)
262 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
267 * Is the user currently logged in an Aide?
271 if (CC->usersupp.axlevel >= 6)
279 * Is the user currently logged in an Aide *or* the room aide for this room?
281 int is_room_aide(void)
284 if (!CC->logged_in) {
288 if ((CC->usersupp.axlevel >= 6)
289 || (CC->quickroom.QRroomaide == CC->usersupp.usernum)) {
297 * getuserbynumber() - get user by number
298 * returns 0 if user was found
300 * WARNING: don't use this function unless you absolutely have to. It does
301 * a sequential search and therefore is computationally expensive.
303 int getuserbynumber(struct usersupp *usbuf, long int number)
305 struct cdbdata *cdbus;
307 cdb_rewind(CDB_USERSUPP);
309 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
310 memset(usbuf, 0, sizeof(struct usersupp));
311 memcpy(usbuf, cdbus->ptr,
312 ((cdbus->len > sizeof(struct usersupp)) ?
313 sizeof(struct usersupp) : cdbus->len));
315 if (usbuf->usernum == number) {
316 cdb_close_cursor(CDB_USERSUPP);
325 * See if we can translate a system login name (i.e. from /etc/passwd)
326 * to a Citadel screen name. Returns 0 if one is found.
328 int CtdlAssociateSystemUser(char *screenname, char *loginname) {
332 p = (struct passwd *) getpwnam(loginname);
334 strcpy(screenname, p->pw_gecos);
335 for (a = 0; a < strlen(screenname); ++a) {
336 if (screenname[a] == ',') {
348 * Back end for cmd_user() and its ilk
350 int CtdlLoginExistingUser(char *trythisname)
355 if (trythisname == NULL) return login_not_found;
356 safestrncpy(username, trythisname, sizeof username);
359 if ((CC->logged_in)) {
360 return login_already_logged_in;
363 found_user = getuser(&CC->usersupp, username);
365 if (found_user == 0) {
366 if (((CC->nologin)) && (CC->usersupp.axlevel < 6)) {
367 return login_too_many_users;
369 strcpy(CC->curr_user, CC->usersupp.fullname);
373 return login_not_found;
381 void cmd_user(char *cmdbuf)
386 extract(username, cmdbuf, 0);
390 a = CtdlLoginExistingUser(username);
392 case login_already_logged_in:
393 cprintf("%d Already logged in.\n", ERROR);
395 case login_too_many_users:
397 "Too many users are already online "
399 ERROR + MAX_SESSIONS_EXCEEDED,
400 config.c_nodename, config.c_maxsessions);
403 cprintf("%d Password required for %s\n",
404 MORE_DATA, CC->curr_user);
406 case login_not_found:
407 cprintf("%d %s not found.\n", ERROR, username);
409 cprintf("%d Internal error\n", ERROR);
416 * session startup code which is common to both cmd_pass() and cmd_newu()
418 void session_startup(void)
422 syslog(LOG_NOTICE, "session %d: user <%s> logged in",
423 CC->cs_pid, CC->curr_user);
425 lgetuser(&CC->usersupp, CC->curr_user);
426 ++(CC->usersupp.timescalled);
427 time(&CC->usersupp.lastcall);
429 /* If this user's name is the name of the system administrator
430 * (as specified in setup), automatically assign access level 6.
432 if (!strcasecmp(CC->usersupp.fullname, config.c_sysadm)) {
433 CC->usersupp.axlevel = 6;
435 lputuser(&CC->usersupp);
438 * Populate CC->cs_inet_email with a default address. This will be
439 * overwritten with the user's directory address, if one exists, when
440 * the vCard module's login hook runs.
442 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
443 CC->usersupp.fullname, config.c_fqdn);
444 for (i=0; i<strlen(CC->cs_inet_email); ++i) {
445 if (isspace(CC->cs_inet_email[i])) {
446 CC->cs_inet_email[i] = '_';
450 /* Create any personal rooms required by the system.
451 * (Technically, MAILROOM should be there already, but just in case...)
453 create_room(MAILROOM, 4, "", 0, 1, 0);
454 create_room(SENTITEMS, 4, "", 0, 1, 0);
456 /* Run any startup routines registered by loadable modules */
457 PerformSessionHooks(EVT_LOGIN);
459 /* Enter the lobby */
460 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
462 /* Record this login in the Citadel log */
463 rec_log(CL_LOGIN, CC->curr_user);
467 void logged_in_response(void)
469 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
470 CIT_OK, CC->usersupp.fullname, CC->usersupp.axlevel,
471 CC->usersupp.timescalled, CC->usersupp.posted,
472 CC->usersupp.flags, CC->usersupp.usernum,
473 CC->usersupp.lastcall);
479 * misc things to be taken care of when a user is logged out
481 void logout(struct CitContext *who)
486 * If there is a download in progress, abort it.
488 if (who->download_fp != NULL) {
489 fclose(who->download_fp);
490 who->download_fp = NULL;
494 * If there is an upload in progress, abort it.
496 if (who->upload_fp != NULL) {
501 * If we were talking to a network node, we're not anymore...
503 if (strlen(who->net_node) > 0) {
504 network_talking_to(who->net_node, NTT_REMOVE);
507 /* Do modular stuff... */
508 PerformSessionHooks(EVT_LOGOUT);
513 * an alternate version of validpw() which executes `chkpwd' instead of
514 * verifying the password directly
516 static int validpw(uid_t uid, const char *pass)
519 int status, pipev[2];
523 lprintf(1, "pipe failed (%s): denying autologin access for "
524 "uid %ld\n", strerror(errno), (long)uid);
527 switch (pid = fork()) {
529 lprintf(1, "fork failed (%s): denying autologin access for "
530 "uid %ld\n", strerror(errno), (long)uid);
537 if (dup2(pipev[0], 0) == -1) {
543 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
544 perror(BBSDIR "/chkpwd");
550 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
551 write(pipev[1], pass, strlen(pass));
552 write(pipev[1], "\n", 1);
555 while (waitpid(pid, &status, 0) == -1)
556 if (errno != EINTR) {
557 lprintf(1, "waitpid failed (%s): denying autologin "
558 "access for uid %ld\n",
559 strerror(errno), (long)uid);
562 if (WIFEXITED(status) && !WEXITSTATUS(status))
576 int CtdlTryPassword(char *password)
580 if ((CC->logged_in)) {
581 lprintf(5, "CtdlTryPassword: already logged in\n");
582 return pass_already_logged_in;
584 if (!strcmp(CC->curr_user, NLI)) {
585 lprintf(5, "CtdlTryPassword: no user selected\n");
588 if (getuser(&CC->usersupp, CC->curr_user)) {
589 lprintf(5, "CtdlTryPassword: internal error\n");
590 return pass_internal_error;
592 if (password == NULL) {
593 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
594 return pass_wrong_password;
599 #ifdef ENABLE_AUTOLOGIN
600 if (CC->usersupp.uid == BBSUID) {
602 strproc(CC->usersupp.password);
603 code = strcasecmp(CC->usersupp.password, password);
606 if (validpw(CC->usersupp.uid, password)) {
608 lgetuser(&CC->usersupp, CC->curr_user);
609 safestrncpy(CC->usersupp.password, password,
610 sizeof CC->usersupp.password);
611 lputuser(&CC->usersupp);
615 #else /* ENABLE_AUTOLOGIN */
617 strproc(CC->usersupp.password);
618 code = strcasecmp(CC->usersupp.password, password);
620 #endif /* ENABLE_AUTOLOGIN */
626 rec_log(CL_BADPW, CC->curr_user);
627 return pass_wrong_password;
632 void cmd_pass(char *buf)
637 extract(password, buf, 0);
638 a = CtdlTryPassword(password);
641 case pass_already_logged_in:
642 cprintf("%d Already logged in.\n", ERROR);
645 cprintf("%d You must send a name with USER first.\n",
648 case pass_wrong_password:
649 cprintf("%d Wrong password.\n", ERROR);
652 logged_in_response();
654 cprintf("%d Can't find user record!\n",
655 ERROR + INTERNAL_ERROR);
662 * Delete a user record *and* all of its related resources.
664 int purge_user(char pname[])
667 struct usersupp usbuf;
668 char lowercase_name[USERNAME_SIZE];
670 struct CitContext *ccptr;
671 int user_is_logged_in = 0;
673 for (a = 0; a <= strlen(pname); ++a) {
674 lowercase_name[a] = tolower(pname[a]);
677 if (getuser(&usbuf, pname) != 0) {
678 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
679 return (ERROR + NO_SUCH_USER);
681 /* Don't delete a user who is currently logged in. Instead, just
682 * set the access level to 0, and let the account get swept up
683 * during the next purge.
685 user_is_logged_in = 0;
686 begin_critical_section(S_SESSION_TABLE);
687 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
688 if (ccptr->usersupp.usernum == usbuf.usernum) {
689 user_is_logged_in = 1;
692 end_critical_section(S_SESSION_TABLE);
693 if (user_is_logged_in == 1) {
694 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
699 lprintf(5, "Deleting user <%s>\n", pname);
701 /* Perform any purge functions registered by server extensions */
702 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
704 /* delete any existing user/room relationships */
705 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
707 /* delete the userlog entry */
708 cdb_delete(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
710 /* remove the user's bio file */
711 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
714 /* remove the user's picture */
715 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
723 * create_user() - back end processing to create a new user
725 * Set 'newusername' to the desired account name.
726 * Set 'become_user' to nonzero if this is self-service account creation and we want
727 * to actually log in as the user we just created, otherwise set it to 0.
729 int create_user(char *newusername, int become_user)
731 struct usersupp usbuf;
732 struct quickroom qrbuf;
733 struct passwd *p = NULL;
735 char mailboxname[ROOMNAMELEN];
738 strcpy(username, newusername);
741 #ifdef ENABLE_AUTOLOGIN
742 p = (struct passwd *) getpwnam(username);
744 extract_token(username, p->pw_gecos, 0, ',');
753 if (!getuser(&usbuf, username)) {
754 return (ERROR + ALREADY_EXISTS);
757 /* Go ahead and initialize a new user record */
758 memset(&usbuf, 0, sizeof(struct usersupp));
759 strcpy(usbuf.fullname, username);
760 strcpy(usbuf.password, "");
763 /* These are the default flags on new accounts */
764 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
766 usbuf.timescalled = 0;
768 usbuf.axlevel = config.c_initax;
769 usbuf.USscreenwidth = 80;
770 usbuf.USscreenheight = 24;
771 usbuf.lastcall = time(NULL);
773 /* fetch a new user number */
774 usbuf.usernum = get_new_user_number();
776 /* The very first user created on the system will always be an Aide */
777 if (usbuf.usernum == 1L) {
781 /* add user to userlog */
785 * Give the user a private mailbox and a configuration room.
786 * Make the latter an invisible system room.
788 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
789 create_room(mailboxname, 5, "", 0, 1, 1);
791 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
792 create_room(mailboxname, 5, "", 0, 1, 1);
793 if (lgetroom(&qrbuf, USERCONFIGROOM) == 0) {
794 qrbuf.QRflags2 |= QR2_SYSTEM;
798 /* Everything below this line can be bypassed if administratively
799 creating a user, instead of doing self-service account creation
803 /* Now become the user we just created */
804 memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
805 strcpy(CC->curr_user, username);
808 /* Check to make sure we're still who we think we are */
809 if (getuser(&CC->usersupp, CC->curr_user)) {
810 return (ERROR + INTERNAL_ERROR);
813 rec_log(CL_NEWUSER, CC->curr_user);
823 * cmd_newu() - create a new user account and log in as that user
825 void cmd_newu(char *cmdbuf)
830 if (config.c_disable_newu) {
831 cprintf("%d Self-service user account creation "
832 "is disabled on this system.\n", ERROR);
837 cprintf("%d Already logged in.\n", ERROR);
841 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
842 ERROR + MAX_SESSIONS_EXCEEDED,
843 config.c_nodename, config.c_maxsessions);
845 extract(username, cmdbuf, 0);
849 if (strlen(username) == 0) {
850 cprintf("%d You must supply a user name.\n", ERROR);
854 if ((!strcasecmp(username, "bbs")) ||
855 (!strcasecmp(username, "new")) ||
856 (!strcasecmp(username, "."))) {
857 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
861 a = create_user(username, 1);
865 logged_in_response();
866 } else if (a == ERROR + ALREADY_EXISTS) {
867 cprintf("%d '%s' already exists.\n",
868 ERROR + ALREADY_EXISTS, username);
870 } else if (a == ERROR + INTERNAL_ERROR) {
871 cprintf("%d Internal error - user record disappeared?\n",
872 ERROR + INTERNAL_ERROR);
875 cprintf("%d unknown error\n", ERROR);
877 rec_log(CL_NEWUSER, CC->curr_user);
885 void cmd_setp(char *new_pw)
887 if (CtdlAccessCheck(ac_logged_in)) {
891 if (CC->usersupp.uid != BBSUID) {
892 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
896 if (strlen(new_pw) == 0) {
897 cprintf("%d Password unchanged.\n", CIT_OK);
900 lgetuser(&CC->usersupp, CC->curr_user);
901 strcpy(CC->usersupp.password, new_pw);
902 lputuser(&CC->usersupp);
903 cprintf("%d Password changed.\n", CIT_OK);
904 rec_log(CL_PWCHANGE, CC->curr_user);
905 PerformSessionHooks(EVT_SETPASS);
910 * cmd_creu() - administratively create a new user account (do not log in to it)
912 void cmd_creu(char *cmdbuf)
917 if (CtdlAccessCheck(ac_aide)) {
921 extract(username, cmdbuf, 0);
925 if (strlen(username) == 0) {
926 cprintf("%d You must supply a user name.\n", ERROR);
930 a = create_user(username, 0);
933 cprintf("%d ok\n", CIT_OK);
935 } else if (a == ERROR + ALREADY_EXISTS) {
936 cprintf("%d '%s' already exists.\n",
937 ERROR + ALREADY_EXISTS, username);
940 cprintf("%d An error occured creating the user account.\n", ERROR);
942 rec_log(CL_NEWUSER, username);
948 * get user parameters
953 if (CtdlAccessCheck(ac_logged_in))
956 getuser(&CC->usersupp, CC->curr_user);
957 cprintf("%d %d|%d|%d|\n",
959 CC->usersupp.USscreenwidth,
960 CC->usersupp.USscreenheight,
961 (CC->usersupp.flags & US_USER_SET)
966 * set user parameters
968 void cmd_setu(char *new_parms)
970 if (CtdlAccessCheck(ac_logged_in))
973 if (num_parms(new_parms) < 3) {
974 cprintf("%d Usage error.\n", ERROR);
977 lgetuser(&CC->usersupp, CC->curr_user);
978 CC->usersupp.USscreenwidth = extract_int(new_parms, 0);
979 CC->usersupp.USscreenheight = extract_int(new_parms, 1);
980 CC->usersupp.flags = CC->usersupp.flags & (~US_USER_SET);
981 CC->usersupp.flags = CC->usersupp.flags |
982 (extract_int(new_parms, 2) & US_USER_SET);
984 lputuser(&CC->usersupp);
985 cprintf("%d Ok\n", CIT_OK);
989 * set last read pointer
991 void cmd_slrp(char *new_ptr)
996 if (CtdlAccessCheck(ac_logged_in)) {
1000 if (!strncasecmp(new_ptr, "highest", 7)) {
1001 newlr = CC->quickroom.QRhighest;
1003 newlr = atol(new_ptr);
1006 lgetuser(&CC->usersupp, CC->curr_user);
1008 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1009 vbuf.v_lastseen = newlr;
1010 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1011 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1013 lputuser(&CC->usersupp);
1014 cprintf("%d %ld\n", CIT_OK, newlr);
1018 void cmd_seen(char *argbuf) {
1019 long target_msgnum = 0L;
1020 int target_setting = 0;
1022 if (CtdlAccessCheck(ac_logged_in)) {
1026 if (num_parms(argbuf) != 2) {
1027 cprintf("%d Invalid parameters\n", ERROR);
1031 target_msgnum = extract_long(argbuf, 0);
1032 target_setting = extract_int(argbuf, 1);
1034 CtdlSetSeen(target_msgnum, target_setting);
1035 cprintf("%d OK\n", CIT_OK);
1039 void cmd_gtsn(char *argbuf) {
1042 if (CtdlAccessCheck(ac_logged_in)) {
1047 cprintf("%d %s\n", CIT_OK, buf);
1053 * INVT and KICK commands
1055 void cmd_invt_kick(char *iuser, int op)
1057 { /* 1 = invite, 0 = kick out */
1058 struct usersupp USscratch;
1063 * These commands are only allowed by aides, room aides,
1064 * and room namespace owners
1067 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
1068 /* access granted */
1071 cprintf("%d Higher access or room ownership required.\n",
1072 ERROR + HIGHER_ACCESS_REQUIRED);
1076 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1078 cprintf("%d Can't add/remove users from this room.\n",
1083 if (lgetuser(&USscratch, iuser) != 0) {
1084 cprintf("%d No such user.\n", ERROR);
1087 CtdlGetRelationship(&vbuf, &USscratch, &CC->quickroom);
1090 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1091 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1094 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1095 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1097 CtdlSetRelationship(&vbuf, &USscratch, &CC->quickroom);
1099 lputuser(&USscratch);
1101 /* post a message in Aide> saying what we just did */
1102 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1104 ((op == 1) ? "invited to" : "kicked out of"),
1105 CC->quickroom.QRname,
1106 CC->usersupp.fullname);
1109 cprintf("%d %s %s %s.\n",
1111 ((op == 1) ? "invited to" : "kicked out of"),
1112 CC->quickroom.QRname);
1118 * Forget (Zap) the current room (API call)
1119 * Returns 0 on success
1121 int CtdlForgetThisRoom(void) {
1124 /* On some systems, Aides are not allowed to forget rooms */
1125 if (is_aide() && (config.c_aide_zap == 0)
1126 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0) ) {
1130 lgetuser(&CC->usersupp, CC->curr_user);
1131 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1133 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1134 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1136 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1137 lputuser(&CC->usersupp);
1139 /* Return to the Lobby, so we don't end up in an undefined room */
1140 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1147 * forget (Zap) the current room
1152 if (CtdlAccessCheck(ac_logged_in)) {
1156 if (CtdlForgetThisRoom() == 0) {
1157 cprintf("%d Ok\n", CIT_OK);
1160 cprintf("%d You may not forget this room.\n", ERROR);
1165 * Get Next Unregistered User
1169 struct cdbdata *cdbus;
1170 struct usersupp usbuf;
1172 if (CtdlAccessCheck(ac_aide)) {
1176 if ((CitControl.MMflags & MM_VALID) == 0) {
1177 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1181 /* There are unvalidated users. Traverse the usersupp database,
1182 * and return the first user we find that needs validation.
1184 cdb_rewind(CDB_USERSUPP);
1185 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1186 memset(&usbuf, 0, sizeof(struct usersupp));
1187 memcpy(&usbuf, cdbus->ptr,
1188 ((cdbus->len > sizeof(struct usersupp)) ?
1189 sizeof(struct usersupp) : cdbus->len));
1191 if ((usbuf.flags & US_NEEDVALID)
1192 && (usbuf.axlevel > 0)) {
1193 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1194 cdb_close_cursor(CDB_USERSUPP);
1199 /* If we get to this point, there are no more unvalidated users.
1200 * Therefore we clear the "users need validation" flag.
1203 begin_critical_section(S_CONTROL);
1205 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1207 end_critical_section(S_CONTROL);
1208 cprintf("%d *** End of registration.\n", CIT_OK);
1217 void cmd_vali(char *v_args)
1221 struct usersupp userbuf;
1223 extract(user, v_args, 0);
1224 newax = extract_int(v_args, 1);
1226 if (CtdlAccessCheck(ac_aide)) {
1230 if (lgetuser(&userbuf, user) != 0) {
1231 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1235 userbuf.axlevel = newax;
1236 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1240 /* If the access level was set to zero, delete the user */
1242 if (purge_user(user) == 0) {
1243 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1247 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1253 * Traverse the user file...
1255 void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
1258 struct usersupp usbuf;
1259 struct cdbdata *cdbus;
1261 cdb_rewind(CDB_USERSUPP);
1263 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1264 memset(&usbuf, 0, sizeof(struct usersupp));
1265 memcpy(&usbuf, cdbus->ptr,
1266 ((cdbus->len > sizeof(struct usersupp)) ?
1267 sizeof(struct usersupp) : cdbus->len));
1269 (*CallBack) (&usbuf, in_data);
1275 * List one user (this works with cmd_list)
1277 void ListThisUser(struct usersupp *usbuf, void *data)
1279 if (usbuf->axlevel > 0) {
1280 if ((CC->usersupp.axlevel >= 6)
1281 || ((usbuf->flags & US_UNLISTED) == 0)
1282 || ((CC->internal_pgm))) {
1283 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1287 (long)usbuf->lastcall,
1290 if (CC->usersupp.axlevel >= 6)
1291 cprintf("%s", usbuf->password);
1302 cprintf("%d \n", LISTING_FOLLOWS);
1303 ForEachUser(ListThisUser, NULL);
1311 * assorted info we need to check at login
1319 if (CtdlAccessCheck(ac_logged_in)) {
1323 getuser(&CC->usersupp, CC->curr_user); /* no lock is needed here */
1324 if ((REGISCALL != 0) && ((CC->usersupp.flags & US_REGIS) == 0))
1327 if (CC->usersupp.axlevel >= 6) {
1329 if (CitControl.MMflags & MM_VALID)
1333 /* check for mail */
1334 mail = InitialMailCheck();
1336 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1341 * check to see if a user exists
1343 void cmd_qusr(char *who)
1345 struct usersupp usbuf;
1347 if (getuser(&usbuf, who) == 0) {
1348 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1350 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1356 * Administrative Get User Parameters
1358 void cmd_agup(char *cmdbuf)
1360 struct usersupp usbuf;
1361 char requested_user[SIZ];
1363 if (CtdlAccessCheck(ac_aide)) {
1367 extract(requested_user, cmdbuf, 0);
1368 if (getuser(&usbuf, requested_user) != 0) {
1369 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1372 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1379 (int) usbuf.axlevel,
1381 (long)usbuf.lastcall,
1388 * Administrative Set User Parameters
1390 void cmd_asup(char *cmdbuf)
1392 struct usersupp usbuf;
1393 char requested_user[SIZ];
1399 if (CtdlAccessCheck(ac_aide))
1402 extract(requested_user, cmdbuf, 0);
1403 if (lgetuser(&usbuf, requested_user) != 0) {
1404 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1407 np = num_parms(cmdbuf);
1409 extract(usbuf.password, cmdbuf, 1);
1411 usbuf.flags = extract_int(cmdbuf, 2);
1413 usbuf.timescalled = extract_int(cmdbuf, 3);
1415 usbuf.posted = extract_int(cmdbuf, 4);
1417 newax = extract_int(cmdbuf, 5);
1418 if ((newax >= 0) && (newax <= 6)) {
1419 usbuf.axlevel = extract_int(cmdbuf, 5);
1423 usbuf.lastcall = extract_long(cmdbuf, 7);
1426 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1429 if (usbuf.axlevel == 0) {
1430 if (purge_user(requested_user) == 0) {
1436 sprintf(notify, "User <%s> deleted by %s\n",
1437 usbuf.fullname, CC->usersupp.fullname);
1438 aide_message(notify);
1441 cprintf("%d Ok", CIT_OK);
1443 cprintf(" (%s deleted)", requested_user);
1450 * Check to see if the user who we just sent mail to is logged in. If yes,
1451 * bump the 'new mail' counter for their session. That enables them to
1452 * receive a new mail notification without having to hit the database.
1454 void BumpNewMailCounter(long which_user) {
1455 struct CitContext *ptr;
1457 begin_critical_section(S_SESSION_TABLE);
1459 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1460 if (ptr->usersupp.usernum == which_user) {
1465 end_critical_section(S_SESSION_TABLE);
1470 * Count the number of new mail messages the user has
1474 int num_newmsgs = 0;
1476 num_newmsgs = CC->newmail;
1479 return (num_newmsgs);
1484 * Count the number of new mail messages the user has
1486 int InitialMailCheck()
1488 int num_newmsgs = 0;
1490 char mailboxname[ROOMNAMELEN];
1491 struct quickroom mailbox;
1493 struct cdbdata *cdbfr;
1494 long *msglist = NULL;
1497 MailboxName(mailboxname, sizeof mailboxname, &CC->usersupp, MAILROOM);
1498 if (getroom(&mailbox, mailboxname) != 0)
1500 CtdlGetRelationship(&vbuf, &CC->usersupp, &mailbox);
1502 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1504 if (cdbfr != NULL) {
1505 msglist = mallok(cdbfr->len);
1506 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1507 num_msgs = cdbfr->len / sizeof(long);
1511 for (a = 0; a < num_msgs; ++a) {
1512 if (msglist[a] > 0L) {
1513 if (msglist[a] > vbuf.v_lastseen) {
1518 if (msglist != NULL)
1521 return (num_newmsgs);
1527 * Set the preferred view for the current user/room combination
1529 void cmd_view(char *cmdbuf) {
1533 if (CtdlAccessCheck(ac_logged_in)) {
1537 requested_view = extract_int(cmdbuf, 0);
1539 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1540 vbuf.v_view = requested_view;
1541 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1543 cprintf("%d ok\n", CIT_OK);