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 * makeuserkey() - convert a username into the format used as a database key
59 * (it's just the username converted into lower case)
61 static inline void makeuserkey(char *key, char *username) {
64 len = strlen(username);
65 for (i=0; i<=len; ++i) {
66 key[i] = tolower(username[i]);
72 * getuser() - retrieve named user into supplied buffer.
73 * returns 0 on success
75 int getuser(struct ctdluser *usbuf, char name[])
78 char usernamekey[USERNAME_SIZE];
79 char sysuser_name[USERNAME_SIZE];
80 struct cdbdata *cdbus;
81 int using_sysuser = 0;
83 memset(usbuf, 0, sizeof(struct ctdluser));
85 #ifdef ENABLE_AUTOLOGIN
86 if (CtdlAssociateSystemUser(sysuser_name, name) == 0) {
92 makeuserkey(usernamekey, sysuser_name);
95 makeuserkey(usernamekey, name);
98 cdbus = cdb_fetch(CDB_USERS, usernamekey, strlen(usernamekey));
99 if (cdbus == NULL) { /* user not found */
102 memcpy(usbuf, cdbus->ptr,
103 ((cdbus->len > sizeof(struct ctdluser)) ?
104 sizeof(struct ctdluser) : cdbus->len));
112 * lgetuser() - same as getuser() but locks the record
114 int lgetuser(struct ctdluser *usbuf, char *name)
118 retcode = getuser(usbuf, name);
120 begin_critical_section(S_USERS);
127 * putuser() - write user buffer into the correct place on disk
129 void putuser(struct ctdluser *usbuf)
131 char usernamekey[USERNAME_SIZE];
133 makeuserkey(usernamekey, usbuf->fullname);
135 usbuf->version = REV_LEVEL;
137 usernamekey, strlen(usernamekey),
138 usbuf, sizeof(struct ctdluser));
144 * lputuser() - same as putuser() but locks the record
146 void lputuser(struct ctdluser *usbuf)
149 end_critical_section(S_USERS);
153 * Index-generating function used by Ctdl[Get|Set]Relationship
155 int GenerateRelationshipIndex(char *IndexBuf,
167 TheIndex.iRoomID = RoomID;
168 TheIndex.iRoomGen = RoomGen;
169 TheIndex.iUserID = UserID;
171 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
172 return (sizeof(TheIndex));
178 * Back end for CtdlSetRelationship()
180 void put_visit(struct visit *newvisit)
185 /* Generate an index */
186 IndexLen = GenerateRelationshipIndex(IndexBuf,
189 newvisit->v_usernum);
191 /* Store the record */
192 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
193 newvisit, sizeof(struct visit)
201 * Define a relationship between a user and a room
203 void CtdlSetRelationship(struct visit *newvisit,
204 struct ctdluser *rel_user,
205 struct ctdlroom *rel_room)
209 /* We don't use these in Citadel because they're implicit by the
210 * index, but they must be present if the database is exported.
212 newvisit->v_roomnum = rel_room->QRnumber;
213 newvisit->v_roomgen = rel_room->QRgen;
214 newvisit->v_usernum = rel_user->usernum;
220 * Locate a relationship between a user and a room
222 void CtdlGetRelationship(struct visit *vbuf,
223 struct ctdluser *rel_user,
224 struct ctdlroom *rel_room)
229 struct cdbdata *cdbvisit;
231 /* Generate an index */
232 IndexLen = GenerateRelationshipIndex(IndexBuf,
237 /* Clear out the buffer */
238 memset(vbuf, 0, sizeof(struct visit));
240 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
241 if (cdbvisit != NULL) {
242 memcpy(vbuf, cdbvisit->ptr,
243 ((cdbvisit->len > sizeof(struct visit)) ?
244 sizeof(struct visit) : cdbvisit->len));
248 /* If this is the first time the user has seen this room,
249 * set the view to be the default for the room.
251 vbuf->v_view = rel_room->QRdefaultview;
254 /* Set v_seen if necessary */
255 if (vbuf->v_seen[0] == 0) {
256 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
261 void MailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
263 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
268 * Is the user currently logged in an Aide?
272 if (CC->user.axlevel >= 6)
280 * Is the user currently logged in an Aide *or* the room aide for this room?
282 int is_room_aide(void)
285 if (!CC->logged_in) {
289 if ((CC->user.axlevel >= 6)
290 || (CC->room.QRroomaide == CC->user.usernum)) {
298 * getuserbynumber() - get user by number
299 * returns 0 if user was found
301 * WARNING: don't use this function unless you absolutely have to. It does
302 * a sequential search and therefore is computationally expensive.
304 int getuserbynumber(struct ctdluser *usbuf, long int number)
306 struct cdbdata *cdbus;
308 cdb_rewind(CDB_USERS);
310 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
311 memset(usbuf, 0, sizeof(struct ctdluser));
312 memcpy(usbuf, cdbus->ptr,
313 ((cdbus->len > sizeof(struct ctdluser)) ?
314 sizeof(struct ctdluser) : cdbus->len));
316 if (usbuf->usernum == number) {
317 cdb_close_cursor(CDB_USERS);
326 * See if we can translate a system login name (i.e. from /etc/passwd)
327 * to a Citadel screen name. Returns 0 if one is found.
329 int CtdlAssociateSystemUser(char *screenname, char *loginname) {
333 p = (struct passwd *) getpwnam(loginname);
335 strcpy(screenname, p->pw_gecos);
336 for (a = 0; a < strlen(screenname); ++a) {
337 if (screenname[a] == ',') {
349 * Back end for cmd_user() and its ilk
351 int CtdlLoginExistingUser(char *trythisname)
355 struct recptypes *valid = NULL;
357 if (trythisname == NULL) return login_not_found;
358 safestrncpy(username, trythisname, sizeof username);
361 if ((CC->logged_in)) {
362 return login_already_logged_in;
365 /* First, try to log in as if the supplied name is a display name */
366 found_user = getuser(&CC->user, username);
368 /* If that didn't work, try to log in as if the supplied name
369 * is an e-mail address
371 if (found_user != 0) {
372 valid = validate_recipients(trythisname);
374 if (valid->num_local == 1) {
375 found_user = getuser(&CC->user,
382 /* Did we find something? */
383 if (found_user == 0) {
384 if (((CC->nologin)) && (CC->user.axlevel < 6)) {
385 return login_too_many_users;
387 safestrncpy(CC->curr_user, CC->user.fullname,
388 sizeof CC->curr_user);
392 return login_not_found;
400 void cmd_user(char *cmdbuf)
405 extract(username, cmdbuf, 0);
408 a = CtdlLoginExistingUser(username);
410 case login_already_logged_in:
411 cprintf("%d Already logged in.\n", ERROR);
413 case login_too_many_users:
415 "Too many users are already online "
417 ERROR + MAX_SESSIONS_EXCEEDED,
418 config.c_nodename, config.c_maxsessions);
421 cprintf("%d Password required for %s\n",
422 MORE_DATA, CC->curr_user);
424 case login_not_found:
425 cprintf("%d %s not found.\n", ERROR, username);
427 cprintf("%d Internal error\n", ERROR);
434 * session startup code which is common to both cmd_pass() and cmd_newu()
436 void session_startup(void)
440 syslog(LOG_NOTICE, "session %d: user <%s> logged in",
441 CC->cs_pid, CC->curr_user);
443 lgetuser(&CC->user, CC->curr_user);
444 ++(CC->user.timescalled);
445 CC->previous_login = CC->user.lastcall;
446 time(&CC->user.lastcall);
448 /* If this user's name is the name of the system administrator
449 * (as specified in setup), automatically assign access level 6.
451 if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
452 CC->user.axlevel = 6;
457 * Populate CC->cs_inet_email with a default address. This will be
458 * overwritten with the user's directory address, if one exists, when
459 * the vCard module's login hook runs.
461 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
462 CC->user.fullname, config.c_fqdn);
463 for (i=0; i<strlen(CC->cs_inet_email); ++i) {
464 if (isspace(CC->cs_inet_email[i])) {
465 CC->cs_inet_email[i] = '_';
469 /* Create any personal rooms required by the system.
470 * (Technically, MAILROOM should be there already, but just in case...)
472 create_room(MAILROOM, 4, "", 0, 1, 0);
473 create_room(SENTITEMS, 4, "", 0, 1, 0);
475 /* Run any startup routines registered by loadable modules */
476 PerformSessionHooks(EVT_LOGIN);
478 /* Enter the lobby */
479 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
483 void logged_in_response(void)
485 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
486 CIT_OK, CC->user.fullname, CC->user.axlevel,
487 CC->user.timescalled, CC->user.posted,
488 CC->user.flags, CC->user.usernum,
495 * misc things to be taken care of when a user is logged out
497 void logout(struct CitContext *who)
502 * If there is a download in progress, abort it.
504 if (who->download_fp != NULL) {
505 fclose(who->download_fp);
506 who->download_fp = NULL;
510 * If there is an upload in progress, abort it.
512 if (who->upload_fp != NULL) {
517 * If we were talking to a network node, we're not anymore...
519 if (strlen(who->net_node) > 0) {
520 network_talking_to(who->net_node, NTT_REMOVE);
523 /* Do modular stuff... */
524 PerformSessionHooks(EVT_LOGOUT);
529 * an alternate version of validpw() which executes `chkpwd' instead of
530 * verifying the password directly
532 static int validpw(uid_t uid, const char *pass)
535 int status, pipev[2];
539 lprintf(1, "pipe failed (%s): denying autologin access for "
540 "uid %ld\n", strerror(errno), (long)uid);
543 switch (pid = fork()) {
545 lprintf(1, "fork failed (%s): denying autologin access for "
546 "uid %ld\n", strerror(errno), (long)uid);
553 if (dup2(pipev[0], 0) == -1) {
559 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
560 perror(BBSDIR "/chkpwd");
566 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
567 write(pipev[1], pass, strlen(pass));
568 write(pipev[1], "\n", 1);
571 while (waitpid(pid, &status, 0) == -1)
572 if (errno != EINTR) {
573 lprintf(1, "waitpid failed (%s): denying autologin "
574 "access for uid %ld\n",
575 strerror(errno), (long)uid);
578 if (WIFEXITED(status) && !WEXITSTATUS(status))
592 int CtdlTryPassword(char *password)
596 if ((CC->logged_in)) {
597 lprintf(5, "CtdlTryPassword: already logged in\n");
598 return pass_already_logged_in;
600 if (!strcmp(CC->curr_user, NLI)) {
601 lprintf(5, "CtdlTryPassword: no user selected\n");
604 if (getuser(&CC->user, CC->curr_user)) {
605 lprintf(5, "CtdlTryPassword: internal error\n");
606 return pass_internal_error;
608 if (password == NULL) {
609 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
610 return pass_wrong_password;
615 #ifdef ENABLE_AUTOLOGIN
616 /* A uid of BBSUID or -1 indicates that this user exists only in
617 * Citadel, not in the underlying operating system.
619 if ( (CC->user.uid == BBSUID) || (CC->user.uid == (-1)) ) {
621 strproc(CC->user.password);
622 code = strcasecmp(CC->user.password, password);
624 /* Any other uid means we have to check the system password database */
626 if (validpw(CC->user.uid, password)) {
628 lgetuser(&CC->user, CC->curr_user);
629 safestrncpy(CC->user.password, password,
630 sizeof CC->user.password);
635 #else /* ENABLE_AUTOLOGIN */
637 strproc(CC->user.password);
638 code = strcasecmp(CC->user.password, password);
640 #endif /* ENABLE_AUTOLOGIN */
646 lprintf(3, "Bad password specified for <%s>\n", CC->curr_user);
647 return pass_wrong_password;
652 void cmd_pass(char *buf)
657 extract(password, buf, 0);
658 a = CtdlTryPassword(password);
661 case pass_already_logged_in:
662 cprintf("%d Already logged in.\n", ERROR);
665 cprintf("%d You must send a name with USER first.\n",
668 case pass_wrong_password:
669 cprintf("%d Wrong password.\n", ERROR);
672 logged_in_response();
674 cprintf("%d Can't find user record!\n",
675 ERROR + INTERNAL_ERROR);
682 * Delete a user record *and* all of its related resources.
684 int purge_user(char pname[])
687 struct ctdluser usbuf;
688 char usernamekey[USERNAME_SIZE];
689 struct CitContext *ccptr;
690 int user_is_logged_in = 0;
692 makeuserkey(usernamekey, pname);
694 if (getuser(&usbuf, pname) != 0) {
695 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
696 return (ERROR + NO_SUCH_USER);
698 /* Don't delete a user who is currently logged in. Instead, just
699 * set the access level to 0, and let the account get swept up
700 * during the next purge.
702 user_is_logged_in = 0;
703 begin_critical_section(S_SESSION_TABLE);
704 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
705 if (ccptr->user.usernum == usbuf.usernum) {
706 user_is_logged_in = 1;
709 end_critical_section(S_SESSION_TABLE);
710 if (user_is_logged_in == 1) {
711 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
716 lprintf(5, "Deleting user <%s>\n", pname);
718 /* Perform any purge functions registered by server extensions */
719 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
721 /* delete any existing user/room relationships */
722 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
724 /* delete the userlog entry */
725 cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
727 /* remove the user's bio file */
728 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
731 /* remove the user's picture */
732 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
740 * create_user() - back end processing to create a new user
742 * Set 'newusername' to the desired account name.
743 * Set 'become_user' to nonzero if this is self-service account creation and we want
744 * to actually log in as the user we just created, otherwise set it to 0.
746 int create_user(char *newusername, int become_user)
748 struct ctdluser usbuf;
749 struct ctdlroom qrbuf;
750 struct passwd *p = NULL;
752 char mailboxname[ROOMNAMELEN];
755 safestrncpy(username, newusername, sizeof username);
758 #ifdef ENABLE_AUTOLOGIN
759 p = (struct passwd *) getpwnam(username);
761 extract_token(username, p->pw_gecos, 0, ',');
770 if (!getuser(&usbuf, username)) {
771 return (ERROR + ALREADY_EXISTS);
774 /* Go ahead and initialize a new user record */
775 memset(&usbuf, 0, sizeof(struct ctdluser));
776 safestrncpy(usbuf.fullname, username, sizeof usbuf.fullname);
777 strcpy(usbuf.password, "");
780 /* These are the default flags on new accounts */
781 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
783 usbuf.timescalled = 0;
785 usbuf.axlevel = config.c_initax;
786 usbuf.USscreenwidth = 80;
787 usbuf.USscreenheight = 24;
788 usbuf.lastcall = time(NULL);
790 /* fetch a new user number */
791 usbuf.usernum = get_new_user_number();
793 /* The very first user created on the system will always be an Aide */
794 if (usbuf.usernum == 1L) {
798 /* add user to userlog */
802 * Give the user a private mailbox and a configuration room.
803 * Make the latter an invisible system room.
805 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
806 create_room(mailboxname, 5, "", 0, 1, 1);
808 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
809 create_room(mailboxname, 5, "", 0, 1, 1);
810 if (lgetroom(&qrbuf, mailboxname) == 0) {
811 qrbuf.QRflags2 |= QR2_SYSTEM;
815 /* Everything below this line can be bypassed if administratively
816 creating a user, instead of doing self-service account creation
820 /* Now become the user we just created */
821 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
822 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
825 /* Check to make sure we're still who we think we are */
826 if (getuser(&CC->user, CC->curr_user)) {
827 return (ERROR + INTERNAL_ERROR);
831 lprintf(3, "New user <%s> created\n", username);
839 * cmd_newu() - create a new user account and log in as that user
841 void cmd_newu(char *cmdbuf)
846 if (config.c_disable_newu) {
847 cprintf("%d Self-service user account creation "
848 "is disabled on this system.\n", ERROR);
853 cprintf("%d Already logged in.\n", ERROR);
857 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
858 ERROR + MAX_SESSIONS_EXCEEDED,
859 config.c_nodename, config.c_maxsessions);
861 extract(username, cmdbuf, 0);
865 if (strlen(username) == 0) {
866 cprintf("%d You must supply a user name.\n", ERROR);
870 if ((!strcasecmp(username, "bbs")) ||
871 (!strcasecmp(username, "new")) ||
872 (!strcasecmp(username, "."))) {
873 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
877 a = create_user(username, 1);
881 logged_in_response();
882 } else if (a == ERROR + ALREADY_EXISTS) {
883 cprintf("%d '%s' already exists.\n",
884 ERROR + ALREADY_EXISTS, username);
886 } else if (a == ERROR + INTERNAL_ERROR) {
887 cprintf("%d Internal error - user record disappeared?\n",
888 ERROR + INTERNAL_ERROR);
891 cprintf("%d unknown error\n", ERROR);
900 void cmd_setp(char *new_pw)
902 if (CtdlAccessCheck(ac_logged_in)) {
905 if ( (CC->user.uid != BBSUID) && (CC->user.uid != (-1)) ) {
906 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
910 if (strlen(new_pw) == 0) {
911 cprintf("%d Password unchanged.\n", CIT_OK);
914 lgetuser(&CC->user, CC->curr_user);
915 safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
917 cprintf("%d Password changed.\n", CIT_OK);
918 lprintf(3, "Password changed for user <%s>\n", CC->curr_user);
919 PerformSessionHooks(EVT_SETPASS);
924 * cmd_creu() - administratively create a new user account (do not log in to it)
926 void cmd_creu(char *cmdbuf)
931 if (CtdlAccessCheck(ac_aide)) {
935 extract(username, cmdbuf, 0);
939 if (strlen(username) == 0) {
940 cprintf("%d You must supply a user name.\n", ERROR);
944 a = create_user(username, 0);
947 cprintf("%d ok\n", CIT_OK);
949 } else if (a == ERROR + ALREADY_EXISTS) {
950 cprintf("%d '%s' already exists.\n",
951 ERROR + ALREADY_EXISTS, username);
954 cprintf("%d An error occured creating the user account.\n", ERROR);
961 * get user parameters
966 if (CtdlAccessCheck(ac_logged_in))
969 getuser(&CC->user, CC->curr_user);
970 cprintf("%d %d|%d|%d|\n",
972 CC->user.USscreenwidth,
973 CC->user.USscreenheight,
974 (CC->user.flags & US_USER_SET)
979 * set user parameters
981 void cmd_setu(char *new_parms)
983 if (CtdlAccessCheck(ac_logged_in))
986 if (num_parms(new_parms) < 3) {
987 cprintf("%d Usage error.\n", ERROR);
990 lgetuser(&CC->user, CC->curr_user);
991 CC->user.USscreenwidth = extract_int(new_parms, 0);
992 CC->user.USscreenheight = extract_int(new_parms, 1);
993 CC->user.flags = CC->user.flags & (~US_USER_SET);
994 CC->user.flags = CC->user.flags |
995 (extract_int(new_parms, 2) & US_USER_SET);
998 cprintf("%d Ok\n", CIT_OK);
1002 * set last read pointer
1004 void cmd_slrp(char *new_ptr)
1008 struct visit original_vbuf;
1010 if (CtdlAccessCheck(ac_logged_in)) {
1014 if (!strncasecmp(new_ptr, "highest", 7)) {
1015 newlr = CC->room.QRhighest;
1017 newlr = atol(new_ptr);
1020 lgetuser(&CC->user, CC->curr_user);
1022 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1023 memcpy(&original_vbuf, &vbuf, sizeof(struct visit));
1024 vbuf.v_lastseen = newlr;
1025 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1027 /* Only rewrite the record if it changed */
1028 if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
1029 || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
1030 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1033 lputuser(&CC->user);
1034 cprintf("%d %ld\n", CIT_OK, newlr);
1038 void cmd_seen(char *argbuf) {
1039 long target_msgnum = 0L;
1040 int target_setting = 0;
1042 if (CtdlAccessCheck(ac_logged_in)) {
1046 if (num_parms(argbuf) != 2) {
1047 cprintf("%d Invalid parameters\n", ERROR);
1051 target_msgnum = extract_long(argbuf, 0);
1052 target_setting = extract_int(argbuf, 1);
1054 CtdlSetSeen(target_msgnum, target_setting);
1055 cprintf("%d OK\n", CIT_OK);
1059 void cmd_gtsn(char *argbuf) {
1062 if (CtdlAccessCheck(ac_logged_in)) {
1067 cprintf("%d %s\n", CIT_OK, buf);
1073 * INVT and KICK commands
1075 void cmd_invt_kick(char *iuser, int op)
1077 { /* 1 = invite, 0 = kick out */
1078 struct ctdluser USscratch;
1083 * These commands are only allowed by aides, room aides,
1084 * and room namespace owners
1087 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1088 /* access granted */
1091 cprintf("%d Higher access or room ownership required.\n",
1092 ERROR + HIGHER_ACCESS_REQUIRED);
1096 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1098 cprintf("%d Can't add/remove users from this room.\n",
1103 if (lgetuser(&USscratch, iuser) != 0) {
1104 cprintf("%d No such user.\n", ERROR);
1107 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1110 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1111 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1114 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1115 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1117 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1119 lputuser(&USscratch);
1121 /* post a message in Aide> saying what we just did */
1122 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1124 ((op == 1) ? "invited to" : "kicked out of"),
1129 cprintf("%d %s %s %s.\n",
1131 ((op == 1) ? "invited to" : "kicked out of"),
1138 * Forget (Zap) the current room (API call)
1139 * Returns 0 on success
1141 int CtdlForgetThisRoom(void) {
1144 /* On some systems, Aides are not allowed to forget rooms */
1145 if (is_aide() && (config.c_aide_zap == 0)
1146 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1150 lgetuser(&CC->user, CC->curr_user);
1151 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1153 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1154 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1156 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1157 lputuser(&CC->user);
1159 /* Return to the Lobby, so we don't end up in an undefined room */
1160 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1167 * forget (Zap) the current room
1172 if (CtdlAccessCheck(ac_logged_in)) {
1176 if (CtdlForgetThisRoom() == 0) {
1177 cprintf("%d Ok\n", CIT_OK);
1180 cprintf("%d You may not forget this room.\n", ERROR);
1185 * Get Next Unregistered User
1189 struct cdbdata *cdbus;
1190 struct ctdluser usbuf;
1192 if (CtdlAccessCheck(ac_aide)) {
1196 if ((CitControl.MMflags & MM_VALID) == 0) {
1197 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1201 /* There are unvalidated users. Traverse the user database,
1202 * and return the first user we find that needs validation.
1204 cdb_rewind(CDB_USERS);
1205 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1206 memset(&usbuf, 0, sizeof(struct ctdluser));
1207 memcpy(&usbuf, cdbus->ptr,
1208 ((cdbus->len > sizeof(struct ctdluser)) ?
1209 sizeof(struct ctdluser) : cdbus->len));
1211 if ((usbuf.flags & US_NEEDVALID)
1212 && (usbuf.axlevel > 0)) {
1213 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1214 cdb_close_cursor(CDB_USERS);
1219 /* If we get to this point, there are no more unvalidated users.
1220 * Therefore we clear the "users need validation" flag.
1223 begin_critical_section(S_CONTROL);
1225 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1227 end_critical_section(S_CONTROL);
1228 cprintf("%d *** End of registration.\n", CIT_OK);
1237 void cmd_vali(char *v_args)
1241 struct ctdluser userbuf;
1243 extract(user, v_args, 0);
1244 newax = extract_int(v_args, 1);
1246 if (CtdlAccessCheck(ac_aide)) {
1250 if (lgetuser(&userbuf, user) != 0) {
1251 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1255 userbuf.axlevel = newax;
1256 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1260 /* If the access level was set to zero, delete the user */
1262 if (purge_user(user) == 0) {
1263 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1267 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1273 * Traverse the user file...
1275 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1278 struct ctdluser usbuf;
1279 struct cdbdata *cdbus;
1281 cdb_rewind(CDB_USERS);
1283 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1284 memset(&usbuf, 0, sizeof(struct ctdluser));
1285 memcpy(&usbuf, cdbus->ptr,
1286 ((cdbus->len > sizeof(struct ctdluser)) ?
1287 sizeof(struct ctdluser) : cdbus->len));
1289 (*CallBack) (&usbuf, in_data);
1295 * List one user (this works with cmd_list)
1297 void ListThisUser(struct ctdluser *usbuf, void *data)
1299 if (usbuf->axlevel > 0) {
1300 if ((CC->user.axlevel >= 6)
1301 || ((usbuf->flags & US_UNLISTED) == 0)
1302 || ((CC->internal_pgm))) {
1303 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1307 (long)usbuf->lastcall,
1310 if (CC->user.axlevel >= 6)
1311 cprintf("%s", usbuf->password);
1322 cprintf("%d \n", LISTING_FOLLOWS);
1323 ForEachUser(ListThisUser, NULL);
1331 * assorted info we need to check at login
1339 if (CtdlAccessCheck(ac_logged_in)) {
1343 getuser(&CC->user, CC->curr_user); /* no lock is needed here */
1344 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1347 if (CC->user.axlevel >= 6) {
1349 if (CitControl.MMflags & MM_VALID)
1353 /* check for mail */
1354 mail = InitialMailCheck();
1356 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1361 * check to see if a user exists
1363 void cmd_qusr(char *who)
1365 struct ctdluser usbuf;
1367 if (getuser(&usbuf, who) == 0) {
1368 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1370 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1376 * Administrative Get User Parameters
1378 void cmd_agup(char *cmdbuf)
1380 struct ctdluser usbuf;
1381 char requested_user[SIZ];
1383 if (CtdlAccessCheck(ac_aide)) {
1387 extract(requested_user, cmdbuf, 0);
1388 if (getuser(&usbuf, requested_user) != 0) {
1389 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1392 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1399 (int) usbuf.axlevel,
1401 (long)usbuf.lastcall,
1408 * Administrative Set User Parameters
1410 void cmd_asup(char *cmdbuf)
1412 struct ctdluser usbuf;
1413 char requested_user[SIZ];
1419 if (CtdlAccessCheck(ac_aide))
1422 extract(requested_user, cmdbuf, 0);
1423 if (lgetuser(&usbuf, requested_user) != 0) {
1424 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1427 np = num_parms(cmdbuf);
1429 extract(usbuf.password, cmdbuf, 1);
1431 usbuf.flags = extract_int(cmdbuf, 2);
1433 usbuf.timescalled = extract_int(cmdbuf, 3);
1435 usbuf.posted = extract_int(cmdbuf, 4);
1437 newax = extract_int(cmdbuf, 5);
1438 if ((newax >= 0) && (newax <= 6)) {
1439 usbuf.axlevel = extract_int(cmdbuf, 5);
1443 usbuf.lastcall = extract_long(cmdbuf, 7);
1446 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1449 if (usbuf.axlevel == 0) {
1450 if (purge_user(requested_user) == 0) {
1456 sprintf(notify, "User <%s> deleted by %s\n",
1457 usbuf.fullname, CC->user.fullname);
1458 aide_message(notify);
1461 cprintf("%d Ok", CIT_OK);
1463 cprintf(" (%s deleted)", requested_user);
1470 * Check to see if the user who we just sent mail to is logged in. If yes,
1471 * bump the 'new mail' counter for their session. That enables them to
1472 * receive a new mail notification without having to hit the database.
1474 void BumpNewMailCounter(long which_user) {
1475 struct CitContext *ptr;
1477 begin_critical_section(S_SESSION_TABLE);
1479 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1480 if (ptr->user.usernum == which_user) {
1485 end_critical_section(S_SESSION_TABLE);
1490 * Count the number of new mail messages the user has
1494 int num_newmsgs = 0;
1496 num_newmsgs = CC->newmail;
1499 return (num_newmsgs);
1504 * Count the number of new mail messages the user has
1506 int InitialMailCheck()
1508 int num_newmsgs = 0;
1510 char mailboxname[ROOMNAMELEN];
1511 struct ctdlroom mailbox;
1513 struct cdbdata *cdbfr;
1514 long *msglist = NULL;
1517 MailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1518 if (getroom(&mailbox, mailboxname) != 0)
1520 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1522 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1524 if (cdbfr != NULL) {
1525 msglist = mallok(cdbfr->len);
1526 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1527 num_msgs = cdbfr->len / sizeof(long);
1531 for (a = 0; a < num_msgs; ++a) {
1532 if (msglist[a] > 0L) {
1533 if (msglist[a] > vbuf.v_lastseen) {
1538 if (msglist != NULL)
1541 return (num_newmsgs);
1547 * Set the preferred view for the current user/room combination
1549 void cmd_view(char *cmdbuf) {
1553 if (CtdlAccessCheck(ac_logged_in)) {
1557 requested_view = extract_int(cmdbuf, 0);
1559 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1560 vbuf.v_view = requested_view;
1561 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1563 cprintf("%d ok\n", CIT_OK);