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"
54 #include "citserver.h"
58 * getuser() - retrieve named user into supplied buffer.
59 * returns 0 on success
61 int getuser(struct ctdluser *usbuf, char name[])
64 char lowercase_name[USERNAME_SIZE];
65 char sysuser_name[USERNAME_SIZE];
67 struct cdbdata *cdbus;
68 int using_sysuser = 0;
70 memset(usbuf, 0, sizeof(struct ctdluser));
72 #ifdef ENABLE_AUTOLOGIN
73 if (CtdlAssociateSystemUser(sysuser_name, name) == 0) {
79 for (a = 0; a <= strlen(sysuser_name); ++a) {
80 lowercase_name[a] = tolower(sysuser_name[a]);
84 for (a = 0; a <= strlen(name); ++a) {
85 if (a < sizeof(lowercase_name))
86 lowercase_name[a] = tolower(name[a]);
89 lowercase_name[sizeof(lowercase_name) - 1] = 0;
91 cdbus = cdb_fetch(CDB_USERS, lowercase_name, strlen(lowercase_name));
92 if (cdbus == NULL) { /* user not found */
95 memcpy(usbuf, cdbus->ptr,
96 ((cdbus->len > sizeof(struct ctdluser)) ?
97 sizeof(struct ctdluser) : cdbus->len));
105 * lgetuser() - same as getuser() but locks the record
107 int lgetuser(struct ctdluser *usbuf, char *name)
111 retcode = getuser(usbuf, name);
113 begin_critical_section(S_USERS);
120 * putuser() - write user buffer into the correct place on disk
122 void putuser(struct ctdluser *usbuf)
124 char lowercase_name[USERNAME_SIZE];
127 for (a = 0; a <= strlen(usbuf->fullname); ++a) {
128 if (a < sizeof(lowercase_name))
129 lowercase_name[a] = tolower(usbuf->fullname[a]);
131 lowercase_name[sizeof(lowercase_name) - 1] = 0;
133 usbuf->version = REV_LEVEL;
135 lowercase_name, strlen(lowercase_name),
136 usbuf, sizeof(struct ctdluser));
142 * lputuser() - same as putuser() but locks the record
144 void lputuser(struct ctdluser *usbuf)
147 end_critical_section(S_USERS);
151 * Index-generating function used by Ctdl[Get|Set]Relationship
153 int GenerateRelationshipIndex(char *IndexBuf,
165 TheIndex.iRoomID = RoomID;
166 TheIndex.iRoomGen = RoomGen;
167 TheIndex.iUserID = UserID;
169 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
170 return (sizeof(TheIndex));
176 * Back end for CtdlSetRelationship()
178 void put_visit(struct visit *newvisit)
183 /* Generate an index */
184 IndexLen = GenerateRelationshipIndex(IndexBuf,
187 newvisit->v_usernum);
189 /* Store the record */
190 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
191 newvisit, sizeof(struct visit)
199 * Define a relationship between a user and a room
201 void CtdlSetRelationship(struct visit *newvisit,
202 struct ctdluser *rel_user,
203 struct ctdlroom *rel_room)
207 /* We don't use these in Citadel because they're implicit by the
208 * index, but they must be present if the database is exported.
210 newvisit->v_roomnum = rel_room->QRnumber;
211 newvisit->v_roomgen = rel_room->QRgen;
212 newvisit->v_usernum = rel_user->usernum;
218 * Locate a relationship between a user and a room
220 void CtdlGetRelationship(struct visit *vbuf,
221 struct ctdluser *rel_user,
222 struct ctdlroom *rel_room)
227 struct cdbdata *cdbvisit;
229 /* Generate an index */
230 IndexLen = GenerateRelationshipIndex(IndexBuf,
235 /* Clear out the buffer */
236 memset(vbuf, 0, sizeof(struct visit));
238 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
239 if (cdbvisit != NULL) {
240 memcpy(vbuf, cdbvisit->ptr,
241 ((cdbvisit->len > sizeof(struct visit)) ?
242 sizeof(struct visit) : cdbvisit->len));
246 /* If this is the first time the user has seen this room,
247 * set the view to be the default for the room.
249 vbuf->v_view = rel_room->QRdefaultview;
252 /* Set v_seen if necessary */
253 if (vbuf->v_seen[0] == 0) {
254 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
259 void MailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
261 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
266 * Is the user currently logged in an Aide?
270 if (CC->user.axlevel >= 6)
278 * Is the user currently logged in an Aide *or* the room aide for this room?
280 int is_room_aide(void)
283 if (!CC->logged_in) {
287 if ((CC->user.axlevel >= 6)
288 || (CC->room.QRroomaide == CC->user.usernum)) {
296 * getuserbynumber() - get user by number
297 * returns 0 if user was found
299 * WARNING: don't use this function unless you absolutely have to. It does
300 * a sequential search and therefore is computationally expensive.
302 int getuserbynumber(struct ctdluser *usbuf, long int number)
304 struct cdbdata *cdbus;
306 cdb_rewind(CDB_USERS);
308 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
309 memset(usbuf, 0, sizeof(struct ctdluser));
310 memcpy(usbuf, cdbus->ptr,
311 ((cdbus->len > sizeof(struct ctdluser)) ?
312 sizeof(struct ctdluser) : cdbus->len));
314 if (usbuf->usernum == number) {
315 cdb_close_cursor(CDB_USERS);
324 * See if we can translate a system login name (i.e. from /etc/passwd)
325 * to a Citadel screen name. Returns 0 if one is found.
327 int CtdlAssociateSystemUser(char *screenname, char *loginname) {
331 p = (struct passwd *) getpwnam(loginname);
333 strcpy(screenname, p->pw_gecos);
334 for (a = 0; a < strlen(screenname); ++a) {
335 if (screenname[a] == ',') {
347 * Back end for cmd_user() and its ilk
349 int CtdlLoginExistingUser(char *trythisname)
354 if (trythisname == NULL) return login_not_found;
355 safestrncpy(username, trythisname, sizeof username);
358 if ((CC->logged_in)) {
359 return login_already_logged_in;
362 found_user = getuser(&CC->user, username);
364 if (found_user == 0) {
365 if (((CC->nologin)) && (CC->user.axlevel < 6)) {
366 return login_too_many_users;
368 safestrncpy(CC->curr_user, CC->user.fullname,
369 sizeof CC->curr_user);
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->user, CC->curr_user);
426 ++(CC->user.timescalled);
427 CC->previous_login = CC->user.lastcall;
428 time(&CC->user.lastcall);
430 /* If this user's name is the name of the system administrator
431 * (as specified in setup), automatically assign access level 6.
433 if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
434 CC->user.axlevel = 6;
439 * Populate CC->cs_inet_email with a default address. This will be
440 * overwritten with the user's directory address, if one exists, when
441 * the vCard module's login hook runs.
443 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
444 CC->user.fullname, config.c_fqdn);
445 for (i=0; i<strlen(CC->cs_inet_email); ++i) {
446 if (isspace(CC->cs_inet_email[i])) {
447 CC->cs_inet_email[i] = '_';
451 /* Create any personal rooms required by the system.
452 * (Technically, MAILROOM should be there already, but just in case...)
454 create_room(MAILROOM, 4, "", 0, 1, 0);
455 create_room(SENTITEMS, 4, "", 0, 1, 0);
457 /* Run any startup routines registered by loadable modules */
458 PerformSessionHooks(EVT_LOGIN);
460 /* Enter the lobby */
461 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
465 void logged_in_response(void)
467 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
468 CIT_OK, CC->user.fullname, CC->user.axlevel,
469 CC->user.timescalled, CC->user.posted,
470 CC->user.flags, CC->user.usernum,
477 * misc things to be taken care of when a user is logged out
479 void logout(struct CitContext *who)
484 * If there is a download in progress, abort it.
486 if (who->download_fp != NULL) {
487 fclose(who->download_fp);
488 who->download_fp = NULL;
492 * If there is an upload in progress, abort it.
494 if (who->upload_fp != NULL) {
499 * If we were talking to a network node, we're not anymore...
501 if (strlen(who->net_node) > 0) {
502 network_talking_to(who->net_node, NTT_REMOVE);
505 /* Do modular stuff... */
506 PerformSessionHooks(EVT_LOGOUT);
511 * an alternate version of validpw() which executes `chkpwd' instead of
512 * verifying the password directly
514 static int validpw(uid_t uid, const char *pass)
517 int status, pipev[2];
521 lprintf(1, "pipe failed (%s): denying autologin access for "
522 "uid %ld\n", strerror(errno), (long)uid);
525 switch (pid = fork()) {
527 lprintf(1, "fork failed (%s): denying autologin access for "
528 "uid %ld\n", strerror(errno), (long)uid);
535 if (dup2(pipev[0], 0) == -1) {
541 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
542 perror(BBSDIR "/chkpwd");
548 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
549 write(pipev[1], pass, strlen(pass));
550 write(pipev[1], "\n", 1);
553 while (waitpid(pid, &status, 0) == -1)
554 if (errno != EINTR) {
555 lprintf(1, "waitpid failed (%s): denying autologin "
556 "access for uid %ld\n",
557 strerror(errno), (long)uid);
560 if (WIFEXITED(status) && !WEXITSTATUS(status))
574 int CtdlTryPassword(char *password)
578 if ((CC->logged_in)) {
579 lprintf(5, "CtdlTryPassword: already logged in\n");
580 return pass_already_logged_in;
582 if (!strcmp(CC->curr_user, NLI)) {
583 lprintf(5, "CtdlTryPassword: no user selected\n");
586 if (getuser(&CC->user, CC->curr_user)) {
587 lprintf(5, "CtdlTryPassword: internal error\n");
588 return pass_internal_error;
590 if (password == NULL) {
591 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
592 return pass_wrong_password;
597 #ifdef ENABLE_AUTOLOGIN
598 /* A uid of BBSUID or -1 indicates that this user exists only in
599 * Citadel, not in the underlying operating system.
601 if ( (CC->user.uid == BBSUID) || (CC->user.uid == (-1)) ) {
603 strproc(CC->user.password);
604 code = strcasecmp(CC->user.password, password);
606 /* Any other uid means we have to check the system password database */
608 if (validpw(CC->user.uid, password)) {
610 lgetuser(&CC->user, CC->curr_user);
611 safestrncpy(CC->user.password, password,
612 sizeof CC->user.password);
617 #else /* ENABLE_AUTOLOGIN */
619 strproc(CC->user.password);
620 code = strcasecmp(CC->user.password, password);
622 #endif /* ENABLE_AUTOLOGIN */
628 lprintf(3, "Bad password specified for <%s>\n", CC->curr_user);
629 return pass_wrong_password;
634 void cmd_pass(char *buf)
639 extract(password, buf, 0);
640 a = CtdlTryPassword(password);
643 case pass_already_logged_in:
644 cprintf("%d Already logged in.\n", ERROR);
647 cprintf("%d You must send a name with USER first.\n",
650 case pass_wrong_password:
651 cprintf("%d Wrong password.\n", ERROR);
654 logged_in_response();
656 cprintf("%d Can't find user record!\n",
657 ERROR + INTERNAL_ERROR);
664 * Delete a user record *and* all of its related resources.
666 int purge_user(char pname[])
669 struct ctdluser usbuf;
670 char lowercase_name[USERNAME_SIZE];
672 struct CitContext *ccptr;
673 int user_is_logged_in = 0;
675 for (a = 0; a <= strlen(pname); ++a) {
676 lowercase_name[a] = tolower(pname[a]);
679 if (getuser(&usbuf, pname) != 0) {
680 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
681 return (ERROR + NO_SUCH_USER);
683 /* Don't delete a user who is currently logged in. Instead, just
684 * set the access level to 0, and let the account get swept up
685 * during the next purge.
687 user_is_logged_in = 0;
688 begin_critical_section(S_SESSION_TABLE);
689 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
690 if (ccptr->user.usernum == usbuf.usernum) {
691 user_is_logged_in = 1;
694 end_critical_section(S_SESSION_TABLE);
695 if (user_is_logged_in == 1) {
696 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
701 lprintf(5, "Deleting user <%s>\n", pname);
703 /* Perform any purge functions registered by server extensions */
704 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
706 /* delete any existing user/room relationships */
707 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
709 /* delete the userlog entry */
710 cdb_delete(CDB_USERS, lowercase_name, strlen(lowercase_name));
712 /* remove the user's bio file */
713 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
716 /* remove the user's picture */
717 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
725 * create_user() - back end processing to create a new user
727 * Set 'newusername' to the desired account name.
728 * Set 'become_user' to nonzero if this is self-service account creation and we want
729 * to actually log in as the user we just created, otherwise set it to 0.
731 int create_user(char *newusername, int become_user)
733 struct ctdluser usbuf;
734 struct ctdlroom qrbuf;
735 struct passwd *p = NULL;
737 char mailboxname[ROOMNAMELEN];
740 safestrncpy(username, newusername, sizeof username);
743 #ifdef ENABLE_AUTOLOGIN
744 p = (struct passwd *) getpwnam(username);
746 extract_token(username, p->pw_gecos, 0, ',');
755 if (!getuser(&usbuf, username)) {
756 return (ERROR + ALREADY_EXISTS);
759 /* Go ahead and initialize a new user record */
760 memset(&usbuf, 0, sizeof(struct ctdluser));
761 safestrncpy(usbuf.fullname, username, sizeof usbuf.fullname);
762 strcpy(usbuf.password, "");
765 /* These are the default flags on new accounts */
766 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
768 usbuf.timescalled = 0;
770 usbuf.axlevel = config.c_initax;
771 usbuf.USscreenwidth = 80;
772 usbuf.USscreenheight = 24;
773 usbuf.lastcall = time(NULL);
775 /* fetch a new user number */
776 usbuf.usernum = get_new_user_number();
778 /* The very first user created on the system will always be an Aide */
779 if (usbuf.usernum == 1L) {
783 /* add user to userlog */
787 * Give the user a private mailbox and a configuration room.
788 * Make the latter an invisible system room.
790 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
791 create_room(mailboxname, 5, "", 0, 1, 1);
793 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
794 create_room(mailboxname, 5, "", 0, 1, 1);
795 if (lgetroom(&qrbuf, mailboxname) == 0) {
796 qrbuf.QRflags2 |= QR2_SYSTEM;
800 /* Everything below this line can be bypassed if administratively
801 creating a user, instead of doing self-service account creation
805 /* Now become the user we just created */
806 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
807 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
810 /* Check to make sure we're still who we think we are */
811 if (getuser(&CC->user, CC->curr_user)) {
812 return (ERROR + INTERNAL_ERROR);
816 lprintf(3, "New user <%s> created\n", username);
824 * cmd_newu() - create a new user account and log in as that user
826 void cmd_newu(char *cmdbuf)
831 if (config.c_disable_newu) {
832 cprintf("%d Self-service user account creation "
833 "is disabled on this system.\n", ERROR);
838 cprintf("%d Already logged in.\n", ERROR);
842 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
843 ERROR + MAX_SESSIONS_EXCEEDED,
844 config.c_nodename, config.c_maxsessions);
846 extract(username, cmdbuf, 0);
850 if (strlen(username) == 0) {
851 cprintf("%d You must supply a user name.\n", ERROR);
855 if ((!strcasecmp(username, "bbs")) ||
856 (!strcasecmp(username, "new")) ||
857 (!strcasecmp(username, "."))) {
858 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
862 a = create_user(username, 1);
866 logged_in_response();
867 } else if (a == ERROR + ALREADY_EXISTS) {
868 cprintf("%d '%s' already exists.\n",
869 ERROR + ALREADY_EXISTS, username);
871 } else if (a == ERROR + INTERNAL_ERROR) {
872 cprintf("%d Internal error - user record disappeared?\n",
873 ERROR + INTERNAL_ERROR);
876 cprintf("%d unknown error\n", ERROR);
885 void cmd_setp(char *new_pw)
887 if (CtdlAccessCheck(ac_logged_in)) {
890 if ( (CC->user.uid != BBSUID) && (CC->user.uid != (-1)) ) {
891 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
895 if (strlen(new_pw) == 0) {
896 cprintf("%d Password unchanged.\n", CIT_OK);
899 lgetuser(&CC->user, CC->curr_user);
900 safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
902 cprintf("%d Password changed.\n", CIT_OK);
903 lprintf(3, "Password changed for user <%s>\n", CC->curr_user);
904 PerformSessionHooks(EVT_SETPASS);
909 * cmd_creu() - administratively create a new user account (do not log in to it)
911 void cmd_creu(char *cmdbuf)
916 if (CtdlAccessCheck(ac_aide)) {
920 extract(username, cmdbuf, 0);
924 if (strlen(username) == 0) {
925 cprintf("%d You must supply a user name.\n", ERROR);
929 a = create_user(username, 0);
932 cprintf("%d ok\n", CIT_OK);
934 } else if (a == ERROR + ALREADY_EXISTS) {
935 cprintf("%d '%s' already exists.\n",
936 ERROR + ALREADY_EXISTS, username);
939 cprintf("%d An error occured creating the user account.\n", ERROR);
946 * get user parameters
951 if (CtdlAccessCheck(ac_logged_in))
954 getuser(&CC->user, CC->curr_user);
955 cprintf("%d %d|%d|%d|\n",
957 CC->user.USscreenwidth,
958 CC->user.USscreenheight,
959 (CC->user.flags & US_USER_SET)
964 * set user parameters
966 void cmd_setu(char *new_parms)
968 if (CtdlAccessCheck(ac_logged_in))
971 if (num_parms(new_parms) < 3) {
972 cprintf("%d Usage error.\n", ERROR);
975 lgetuser(&CC->user, CC->curr_user);
976 CC->user.USscreenwidth = extract_int(new_parms, 0);
977 CC->user.USscreenheight = extract_int(new_parms, 1);
978 CC->user.flags = CC->user.flags & (~US_USER_SET);
979 CC->user.flags = CC->user.flags |
980 (extract_int(new_parms, 2) & US_USER_SET);
983 cprintf("%d Ok\n", CIT_OK);
987 * set last read pointer
989 void cmd_slrp(char *new_ptr)
994 if (CtdlAccessCheck(ac_logged_in)) {
998 if (!strncasecmp(new_ptr, "highest", 7)) {
999 newlr = CC->room.QRhighest;
1001 newlr = atol(new_ptr);
1004 lgetuser(&CC->user, CC->curr_user);
1006 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1007 vbuf.v_lastseen = newlr;
1008 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1009 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1011 lputuser(&CC->user);
1012 cprintf("%d %ld\n", CIT_OK, newlr);
1016 void cmd_seen(char *argbuf) {
1017 long target_msgnum = 0L;
1018 int target_setting = 0;
1020 if (CtdlAccessCheck(ac_logged_in)) {
1024 if (num_parms(argbuf) != 2) {
1025 cprintf("%d Invalid parameters\n", ERROR);
1029 target_msgnum = extract_long(argbuf, 0);
1030 target_setting = extract_int(argbuf, 1);
1032 CtdlSetSeen(target_msgnum, target_setting);
1033 cprintf("%d OK\n", CIT_OK);
1037 void cmd_gtsn(char *argbuf) {
1040 if (CtdlAccessCheck(ac_logged_in)) {
1045 cprintf("%d %s\n", CIT_OK, buf);
1051 * INVT and KICK commands
1053 void cmd_invt_kick(char *iuser, int op)
1055 { /* 1 = invite, 0 = kick out */
1056 struct ctdluser USscratch;
1061 * These commands are only allowed by aides, room aides,
1062 * and room namespace owners
1065 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1066 /* access granted */
1069 cprintf("%d Higher access or room ownership required.\n",
1070 ERROR + HIGHER_ACCESS_REQUIRED);
1074 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1076 cprintf("%d Can't add/remove users from this room.\n",
1081 if (lgetuser(&USscratch, iuser) != 0) {
1082 cprintf("%d No such user.\n", ERROR);
1085 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1088 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1089 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1092 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1093 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1095 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1097 lputuser(&USscratch);
1099 /* post a message in Aide> saying what we just did */
1100 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1102 ((op == 1) ? "invited to" : "kicked out of"),
1107 cprintf("%d %s %s %s.\n",
1109 ((op == 1) ? "invited to" : "kicked out of"),
1116 * Forget (Zap) the current room (API call)
1117 * Returns 0 on success
1119 int CtdlForgetThisRoom(void) {
1122 /* On some systems, Aides are not allowed to forget rooms */
1123 if (is_aide() && (config.c_aide_zap == 0)
1124 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1128 lgetuser(&CC->user, CC->curr_user);
1129 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1131 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1132 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1134 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1135 lputuser(&CC->user);
1137 /* Return to the Lobby, so we don't end up in an undefined room */
1138 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1145 * forget (Zap) the current room
1150 if (CtdlAccessCheck(ac_logged_in)) {
1154 if (CtdlForgetThisRoom() == 0) {
1155 cprintf("%d Ok\n", CIT_OK);
1158 cprintf("%d You may not forget this room.\n", ERROR);
1163 * Get Next Unregistered User
1167 struct cdbdata *cdbus;
1168 struct ctdluser usbuf;
1170 if (CtdlAccessCheck(ac_aide)) {
1174 if ((CitControl.MMflags & MM_VALID) == 0) {
1175 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1179 /* There are unvalidated users. Traverse the user database,
1180 * and return the first user we find that needs validation.
1182 cdb_rewind(CDB_USERS);
1183 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1184 memset(&usbuf, 0, sizeof(struct ctdluser));
1185 memcpy(&usbuf, cdbus->ptr,
1186 ((cdbus->len > sizeof(struct ctdluser)) ?
1187 sizeof(struct ctdluser) : cdbus->len));
1189 if ((usbuf.flags & US_NEEDVALID)
1190 && (usbuf.axlevel > 0)) {
1191 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1192 cdb_close_cursor(CDB_USERS);
1197 /* If we get to this point, there are no more unvalidated users.
1198 * Therefore we clear the "users need validation" flag.
1201 begin_critical_section(S_CONTROL);
1203 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1205 end_critical_section(S_CONTROL);
1206 cprintf("%d *** End of registration.\n", CIT_OK);
1215 void cmd_vali(char *v_args)
1219 struct ctdluser userbuf;
1221 extract(user, v_args, 0);
1222 newax = extract_int(v_args, 1);
1224 if (CtdlAccessCheck(ac_aide)) {
1228 if (lgetuser(&userbuf, user) != 0) {
1229 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1233 userbuf.axlevel = newax;
1234 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1238 /* If the access level was set to zero, delete the user */
1240 if (purge_user(user) == 0) {
1241 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1245 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1251 * Traverse the user file...
1253 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1256 struct ctdluser usbuf;
1257 struct cdbdata *cdbus;
1259 cdb_rewind(CDB_USERS);
1261 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1262 memset(&usbuf, 0, sizeof(struct ctdluser));
1263 memcpy(&usbuf, cdbus->ptr,
1264 ((cdbus->len > sizeof(struct ctdluser)) ?
1265 sizeof(struct ctdluser) : cdbus->len));
1267 (*CallBack) (&usbuf, in_data);
1273 * List one user (this works with cmd_list)
1275 void ListThisUser(struct ctdluser *usbuf, void *data)
1277 if (usbuf->axlevel > 0) {
1278 if ((CC->user.axlevel >= 6)
1279 || ((usbuf->flags & US_UNLISTED) == 0)
1280 || ((CC->internal_pgm))) {
1281 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1285 (long)usbuf->lastcall,
1288 if (CC->user.axlevel >= 6)
1289 cprintf("%s", usbuf->password);
1300 cprintf("%d \n", LISTING_FOLLOWS);
1301 ForEachUser(ListThisUser, NULL);
1309 * assorted info we need to check at login
1317 if (CtdlAccessCheck(ac_logged_in)) {
1321 getuser(&CC->user, CC->curr_user); /* no lock is needed here */
1322 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1325 if (CC->user.axlevel >= 6) {
1327 if (CitControl.MMflags & MM_VALID)
1331 /* check for mail */
1332 mail = InitialMailCheck();
1334 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1339 * check to see if a user exists
1341 void cmd_qusr(char *who)
1343 struct ctdluser usbuf;
1345 if (getuser(&usbuf, who) == 0) {
1346 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1348 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1354 * Administrative Get User Parameters
1356 void cmd_agup(char *cmdbuf)
1358 struct ctdluser usbuf;
1359 char requested_user[SIZ];
1361 if (CtdlAccessCheck(ac_aide)) {
1365 extract(requested_user, cmdbuf, 0);
1366 if (getuser(&usbuf, requested_user) != 0) {
1367 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1370 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1377 (int) usbuf.axlevel,
1379 (long)usbuf.lastcall,
1386 * Administrative Set User Parameters
1388 void cmd_asup(char *cmdbuf)
1390 struct ctdluser usbuf;
1391 char requested_user[SIZ];
1397 if (CtdlAccessCheck(ac_aide))
1400 extract(requested_user, cmdbuf, 0);
1401 if (lgetuser(&usbuf, requested_user) != 0) {
1402 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1405 np = num_parms(cmdbuf);
1407 extract(usbuf.password, cmdbuf, 1);
1409 usbuf.flags = extract_int(cmdbuf, 2);
1411 usbuf.timescalled = extract_int(cmdbuf, 3);
1413 usbuf.posted = extract_int(cmdbuf, 4);
1415 newax = extract_int(cmdbuf, 5);
1416 if ((newax >= 0) && (newax <= 6)) {
1417 usbuf.axlevel = extract_int(cmdbuf, 5);
1421 usbuf.lastcall = extract_long(cmdbuf, 7);
1424 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1427 if (usbuf.axlevel == 0) {
1428 if (purge_user(requested_user) == 0) {
1434 sprintf(notify, "User <%s> deleted by %s\n",
1435 usbuf.fullname, CC->user.fullname);
1436 aide_message(notify);
1439 cprintf("%d Ok", CIT_OK);
1441 cprintf(" (%s deleted)", requested_user);
1448 * Check to see if the user who we just sent mail to is logged in. If yes,
1449 * bump the 'new mail' counter for their session. That enables them to
1450 * receive a new mail notification without having to hit the database.
1452 void BumpNewMailCounter(long which_user) {
1453 struct CitContext *ptr;
1455 begin_critical_section(S_SESSION_TABLE);
1457 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1458 if (ptr->user.usernum == which_user) {
1463 end_critical_section(S_SESSION_TABLE);
1468 * Count the number of new mail messages the user has
1472 int num_newmsgs = 0;
1474 num_newmsgs = CC->newmail;
1477 return (num_newmsgs);
1482 * Count the number of new mail messages the user has
1484 int InitialMailCheck()
1486 int num_newmsgs = 0;
1488 char mailboxname[ROOMNAMELEN];
1489 struct ctdlroom mailbox;
1491 struct cdbdata *cdbfr;
1492 long *msglist = NULL;
1495 MailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1496 if (getroom(&mailbox, mailboxname) != 0)
1498 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1500 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1502 if (cdbfr != NULL) {
1503 msglist = mallok(cdbfr->len);
1504 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1505 num_msgs = cdbfr->len / sizeof(long);
1509 for (a = 0; a < num_msgs; ++a) {
1510 if (msglist[a] > 0L) {
1511 if (msglist[a] > vbuf.v_lastseen) {
1516 if (msglist != NULL)
1519 return (num_newmsgs);
1525 * Set the preferred view for the current user/room combination
1527 void cmd_view(char *cmdbuf) {
1531 if (CtdlAccessCheck(ac_logged_in)) {
1535 requested_view = extract_int(cmdbuf, 0);
1537 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1538 vbuf.v_view = requested_view;
1539 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1541 cprintf("%d ok\n", CIT_OK);