4 * Server functions which perform operations on user objects.
20 #include <sys/types.h>
23 #if TIME_WITH_SYS_TIME
24 # include <sys/time.h>
28 # include <sys/time.h>
44 #include "dynloader.h"
45 #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 usersupp *usbuf, char name[])
64 char lowercase_name[32];
66 struct cdbdata *cdbus;
68 memset(usbuf, 0, sizeof(struct usersupp));
69 for (a = 0; a <= strlen(name); ++a) {
70 if (a < sizeof(lowercase_name))
71 lowercase_name[a] = tolower(name[a]);
73 lowercase_name[sizeof(lowercase_name) - 1] = 0;
75 cdbus = cdb_fetch(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
77 return (1); /* user not found */
79 memcpy(usbuf, cdbus->ptr,
80 ((cdbus->len > sizeof(struct usersupp)) ?
81 sizeof(struct usersupp) : cdbus->len));
84 if (usbuf->version < 573) {
85 CC->usersupp.moderation_filter = config.c_default_filter;
92 * lgetuser() - same as getuser() but locks the record
94 int lgetuser(struct usersupp *usbuf, char *name)
98 retcode = getuser(usbuf, name);
100 begin_critical_section(S_USERSUPP);
107 * putuser() - write user buffer into the correct place on disk
109 void putuser(struct usersupp *usbuf)
111 char lowercase_name[32];
114 for (a = 0; a <= strlen(usbuf->fullname); ++a) {
115 if (a < sizeof(lowercase_name))
116 lowercase_name[a] = tolower(usbuf->fullname[a]);
118 lowercase_name[sizeof(lowercase_name) - 1] = 0;
120 usbuf->version = REV_LEVEL;
121 cdb_store(CDB_USERSUPP,
122 lowercase_name, strlen(lowercase_name),
123 usbuf, sizeof(struct usersupp));
129 * lputuser() - same as putuser() but locks the record
131 void lputuser(struct usersupp *usbuf)
134 end_critical_section(S_USERSUPP);
138 * Index-generating function used by Ctdl[Get|Set]Relationship
140 int GenerateRelationshipIndex(char *IndexBuf,
152 TheIndex.iRoomID = RoomID;
153 TheIndex.iRoomGen = RoomGen;
154 TheIndex.iUserID = UserID;
156 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
157 return (sizeof(TheIndex));
163 * Back end for CtdlSetRelationship()
165 void put_visit(struct visit *newvisit)
170 /* Generate an index */
171 IndexLen = GenerateRelationshipIndex(IndexBuf,
174 newvisit->v_usernum);
176 /* Store the record */
177 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
178 newvisit, sizeof(struct visit)
186 * Define a relationship between a user and a room
188 void CtdlSetRelationship(struct visit *newvisit,
189 struct usersupp *rel_user,
190 struct quickroom *rel_room)
194 /* We don't use these in Citadel because they're implicit by the
195 * index, but they must be present if the database is exported.
197 newvisit->v_roomnum = rel_room->QRnumber;
198 newvisit->v_roomgen = rel_room->QRgen;
199 newvisit->v_usernum = rel_user->usernum;
205 * Locate a relationship between a user and a room
207 void CtdlGetRelationship(struct visit *vbuf,
208 struct usersupp *rel_user,
209 struct quickroom *rel_room)
214 struct cdbdata *cdbvisit;
216 /* Generate an index */
217 IndexLen = GenerateRelationshipIndex(IndexBuf,
222 /* Clear out the buffer */
223 memset(vbuf, 0, sizeof(struct visit));
225 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
226 if (cdbvisit != NULL) {
227 memcpy(vbuf, cdbvisit->ptr,
228 ((cdbvisit->len > sizeof(struct visit)) ?
229 sizeof(struct visit) : cdbvisit->len));
233 /* Set v_seen if necessary */
234 if (vbuf->v_seen[0] == 0) {
235 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
240 void MailboxName(char *buf, size_t n, const struct usersupp *who, const char *prefix)
242 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
247 * Is the user currently logged in an Aide?
251 if (CC->usersupp.axlevel >= 6)
259 * Is the user currently logged in an Aide *or* the room aide for this room?
261 int is_room_aide(void)
264 if (!CC->logged_in) {
268 if ((CC->usersupp.axlevel >= 6)
269 || (CC->quickroom.QRroomaide == CC->usersupp.usernum)) {
277 * getuserbynumber() - get user by number
278 * returns 0 if user was found
280 * WARNING: don't use this function unless you absolutely have to. It does
281 * a sequential search and therefore is computationally expensive.
283 int getuserbynumber(struct usersupp *usbuf, long int number)
285 struct cdbdata *cdbus;
287 cdb_rewind(CDB_USERSUPP);
289 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
290 memset(usbuf, 0, sizeof(struct usersupp));
291 memcpy(usbuf, cdbus->ptr,
292 ((cdbus->len > sizeof(struct usersupp)) ?
293 sizeof(struct usersupp) : cdbus->len));
295 if (usbuf->usernum == number) {
296 cdb_close_cursor(CDB_USERSUPP);
305 * Back end for cmd_user() and its ilk
307 int CtdlLoginExistingUser(char *trythisname)
315 if (trythisname == NULL) return login_not_found;
316 safestrncpy(username, trythisname, sizeof username);
319 if ((CC->logged_in)) {
320 return login_already_logged_in;
322 found_user = getuser(&CC->usersupp, username);
323 if (found_user != 0) {
324 p = (struct passwd *) getpwnam(username);
326 strcpy(autoname, p->pw_gecos);
327 for (a = 0; a < strlen(autoname); ++a)
328 if (autoname[a] == ',')
330 found_user = getuser(&CC->usersupp, autoname);
333 if (found_user == 0) {
334 if (((CC->nologin)) && (CC->usersupp.axlevel < 6)) {
335 return login_too_many_users;
337 strcpy(CC->curr_user, CC->usersupp.fullname);
341 return login_not_found;
349 void cmd_user(char *cmdbuf)
354 extract(username, cmdbuf, 0);
358 a = CtdlLoginExistingUser(username);
360 case login_already_logged_in:
361 cprintf("%d Already logged in.\n", ERROR);
363 case login_too_many_users:
365 "Too many users are already online "
367 ERROR + MAX_SESSIONS_EXCEEDED,
368 config.c_nodename, config.c_maxsessions);
371 cprintf("%d Password required for %s\n",
372 MORE_DATA, CC->curr_user);
374 case login_not_found:
375 cprintf("%d %s not found.\n", ERROR, username);
377 cprintf("%d Internal error\n", ERROR);
384 * session startup code which is common to both cmd_pass() and cmd_newu()
386 void session_startup(void)
388 syslog(LOG_NOTICE, "session %d: user <%s> logged in",
389 CC->cs_pid, CC->curr_user);
391 lgetuser(&CC->usersupp, CC->curr_user);
392 ++(CC->usersupp.timescalled);
393 time(&CC->usersupp.lastcall);
395 /* If this user's name is the name of the system administrator
396 * (as specified in setup), automatically assign access level 6.
398 if (!strcasecmp(CC->usersupp.fullname, config.c_sysadm)) {
399 CC->usersupp.axlevel = 6;
401 lputuser(&CC->usersupp);
403 /* Run any startup routines registered by loadable modules */
404 PerformSessionHooks(EVT_LOGIN);
406 /* Create any personal rooms required by the system */
407 create_room(SENTITEMS, 4, "", 0, 1);
409 /* Enter the lobby */
410 usergoto(BASEROOM, 0, NULL, NULL);
412 /* Record this login in the Citadel log */
413 rec_log(CL_LOGIN, CC->curr_user);
417 void logged_in_response(void)
419 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
420 CIT_OK, CC->usersupp.fullname, CC->usersupp.axlevel,
421 CC->usersupp.timescalled, CC->usersupp.posted,
422 CC->usersupp.flags, CC->usersupp.usernum,
423 CC->usersupp.lastcall);
429 * misc things to be taken care of when a user is logged out
431 void logout(struct CitContext *who)
436 * If there is a download in progress, abort it.
438 if (who->download_fp != NULL) {
439 fclose(who->download_fp);
440 who->download_fp = NULL;
444 * If there is an upload in progress, abort it.
446 if (who->upload_fp != NULL) {
451 * If we were talking to a network node, we're not anymore...
453 if (strlen(who->net_node) > 0) {
454 network_talking_to(who->net_node, NTT_REMOVE);
458 * Yes, we really need to free EVERY LAST BYTE we allocated.
460 if (who->cs_inet_email != NULL) {
461 phree(who->cs_inet_email);
462 who->cs_inet_email = NULL;
465 /* Do modular stuff... */
466 PerformSessionHooks(EVT_LOGOUT);
471 * an alternate version of validpw() which executes `chkpwd' instead of
472 * verifying the password directly
474 static int validpw(uid_t uid, const char *pass)
477 int status, pipev[2];
481 lprintf(1, "pipe failed (%s): denying autologin access for "
482 "uid %ld\n", strerror(errno), (long)uid);
485 switch (pid = fork()) {
487 lprintf(1, "fork failed (%s): denying autologin access for "
488 "uid %ld\n", strerror(errno), (long)uid);
495 if (dup2(pipev[0], 0) == -1) {
501 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
502 perror(BBSDIR "/chkpwd");
508 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
509 write(pipev[1], pass, strlen(pass));
510 write(pipev[1], "\n", 1);
513 while (waitpid(pid, &status, 0) == -1)
514 if (errno != EINTR) {
515 lprintf(1, "waitpid failed (%s): denying autologin "
516 "access for uid %ld\n",
517 strerror(errno), (long)uid);
520 if (WIFEXITED(status) && !WEXITSTATUS(status))
534 int CtdlTryPassword(char *password)
538 if ((CC->logged_in)) {
539 lprintf(5, "CtdlTryPassword: already logged in\n");
540 return pass_already_logged_in;
542 if (!strcmp(CC->curr_user, NLI)) {
543 lprintf(5, "CtdlTryPassword: no user selected\n");
546 if (getuser(&CC->usersupp, CC->curr_user)) {
547 lprintf(5, "CtdlTryPassword: internal error\n");
548 return pass_internal_error;
550 if (password == NULL) {
551 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
552 return pass_wrong_password;
555 if (CC->usersupp.uid == BBSUID) {
557 strproc(CC->usersupp.password);
558 code = strcasecmp(CC->usersupp.password, password);
560 #ifdef ENABLE_AUTOLOGIN
562 if (validpw(CC->usersupp.uid, password)) {
564 lgetuser(&CC->usersupp, CC->curr_user);
565 safestrncpy(CC->usersupp.password, password,
566 sizeof CC->usersupp.password);
567 lputuser(&CC->usersupp);
576 rec_log(CL_BADPW, CC->curr_user);
577 return pass_wrong_password;
582 void cmd_pass(char *buf)
587 extract(password, buf, 0);
588 a = CtdlTryPassword(password);
591 case pass_already_logged_in:
592 cprintf("%d Already logged in.\n", ERROR);
595 cprintf("%d You must send a name with USER first.\n",
598 case pass_wrong_password:
599 cprintf("%d Wrong password.\n", ERROR);
602 logged_in_response();
604 cprintf("%d Can't find user record!\n",
605 ERROR + INTERNAL_ERROR);
612 * Delete a user record *and* all of its related resources.
614 int purge_user(char pname[])
617 struct usersupp usbuf;
618 char lowercase_name[32];
620 struct CitContext *ccptr;
621 int user_is_logged_in = 0;
623 for (a = 0; a <= strlen(pname); ++a) {
624 lowercase_name[a] = tolower(pname[a]);
627 if (getuser(&usbuf, pname) != 0) {
628 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
629 return (ERROR + NO_SUCH_USER);
631 /* Don't delete a user who is currently logged in. Instead, just
632 * set the access level to 0, and let the account get swept up
633 * during the next purge.
635 user_is_logged_in = 0;
636 begin_critical_section(S_SESSION_TABLE);
637 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
638 if (ccptr->usersupp.usernum == usbuf.usernum) {
639 user_is_logged_in = 1;
642 end_critical_section(S_SESSION_TABLE);
643 if (user_is_logged_in == 1) {
644 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
649 lprintf(5, "Deleting user <%s>\n", pname);
651 /* Perform any purge functions registered by server extensions */
652 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
654 /* delete any existing user/room relationships */
655 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
657 /* delete the userlog entry */
658 cdb_delete(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
660 /* remove the user's bio file */
661 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
664 /* remove the user's picture */
665 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
673 * create_user() - back end processing to create a new user
675 * Set 'newusername' to the desired account name.
676 * Set 'become_user' to nonzero if this is self-service account creation and we want
677 * to actually log in as the user we just created, otherwise set it to 0.
679 int create_user(char *newusername, int become_user)
681 struct usersupp usbuf;
682 struct passwd *p = NULL;
684 char mailboxname[ROOMNAMELEN];
687 strcpy(username, newusername);
690 #ifdef ENABLE_AUTOLOGIN
691 p = (struct passwd *) getpwnam(username);
694 extract_token(username, p->pw_gecos, 0, ',');
700 if (!getuser(&usbuf, username)) {
701 return (ERROR + ALREADY_EXISTS);
704 /* Go ahead and initialize a new user record */
705 memset(&usbuf, 0, sizeof(struct usersupp));
706 strcpy(usbuf.fullname, username);
707 strcpy(usbuf.password, "");
710 /* These are the default flags on new accounts */
711 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
713 usbuf.timescalled = 0;
715 usbuf.axlevel = config.c_initax;
716 usbuf.USscreenwidth = 80;
717 usbuf.USscreenheight = 24;
718 usbuf.lastcall = time(NULL);
719 usbuf.moderation_filter = config.c_default_filter;
721 /* fetch a new user number */
722 usbuf.usernum = get_new_user_number();
724 /* The very first user created on the system will always be an Aide */
725 if (usbuf.usernum == 1L) {
729 /* add user to userlog */
732 /* give the user a private mailbox */
733 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
734 create_room(mailboxname, 5, "", 0, 1);
736 /*** Everything below this line can be bypassed if we are administratively
737 creating a user, instead of doing self-service account creation
741 /* Now become the user we just created */
742 memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
743 strcpy(CC->curr_user, username);
746 /* Check to make sure we're still who we think we are */
747 if (getuser(&CC->usersupp, CC->curr_user)) {
748 return (ERROR + INTERNAL_ERROR);
751 rec_log(CL_NEWUSER, CC->curr_user);
761 * cmd_newu() - create a new user account and log in as that user
763 void cmd_newu(char *cmdbuf)
768 if (config.c_disable_newu) {
769 cprintf("%d Self-service user account creation "
770 "is disabled on this system.\n", ERROR);
775 cprintf("%d Already logged in.\n", ERROR);
779 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
780 ERROR + MAX_SESSIONS_EXCEEDED,
781 config.c_nodename, config.c_maxsessions);
783 extract(username, cmdbuf, 0);
787 if (strlen(username) == 0) {
788 cprintf("%d You must supply a user name.\n", ERROR);
792 if ((!strcasecmp(username, "bbs")) ||
793 (!strcasecmp(username, "new")) ||
794 (!strcasecmp(username, "."))) {
795 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
799 a = create_user(username, 1);
803 logged_in_response();
804 } else if (a == ERROR + ALREADY_EXISTS) {
805 cprintf("%d '%s' already exists.\n",
806 ERROR + ALREADY_EXISTS, username);
808 } else if (a == ERROR + INTERNAL_ERROR) {
809 cprintf("%d Internal error - user record disappeared?\n",
810 ERROR + INTERNAL_ERROR);
813 cprintf("%d unknown error\n", ERROR);
815 rec_log(CL_NEWUSER, CC->curr_user);
823 void cmd_setp(char *new_pw)
825 if (CtdlAccessCheck(ac_logged_in)) {
829 if (CC->usersupp.uid != BBSUID) {
830 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
834 if (strlen(new_pw) == 0) {
835 cprintf("%d Password unchanged.\n", CIT_OK);
838 lgetuser(&CC->usersupp, CC->curr_user);
839 strcpy(CC->usersupp.password, new_pw);
840 lputuser(&CC->usersupp);
841 cprintf("%d Password changed.\n", CIT_OK);
842 rec_log(CL_PWCHANGE, CC->curr_user);
843 PerformSessionHooks(EVT_SETPASS);
848 * cmd_creu() - administratively create a new user account (do not log in to it)
850 void cmd_creu(char *cmdbuf)
855 if (CtdlAccessCheck(ac_aide)) {
859 extract(username, cmdbuf, 0);
863 if (strlen(username) == 0) {
864 cprintf("%d You must supply a user name.\n", ERROR);
868 a = create_user(username, 0);
871 cprintf("%d ok\n", CIT_OK);
873 } else if (a == ERROR + ALREADY_EXISTS) {
874 cprintf("%d '%s' already exists.\n",
875 ERROR + ALREADY_EXISTS, username);
878 cprintf("%d An error occured creating the user account.\n", ERROR);
880 rec_log(CL_NEWUSER, username);
886 * get user parameters
891 if (CtdlAccessCheck(ac_logged_in))
894 getuser(&CC->usersupp, CC->curr_user);
895 cprintf("%d %d|%d|%d|%d\n",
897 CC->usersupp.USscreenwidth,
898 CC->usersupp.USscreenheight,
899 (CC->usersupp.flags & US_USER_SET),
900 CC->usersupp.moderation_filter
905 * set user parameters
907 void cmd_setu(char *new_parms)
911 if (CtdlAccessCheck(ac_logged_in))
914 if (num_parms(new_parms) < 3) {
915 cprintf("%d Usage error.\n", ERROR);
918 lgetuser(&CC->usersupp, CC->curr_user);
919 CC->usersupp.USscreenwidth = extract_int(new_parms, 0);
920 CC->usersupp.USscreenheight = extract_int(new_parms, 1);
921 CC->usersupp.flags = CC->usersupp.flags & (~US_USER_SET);
922 CC->usersupp.flags = CC->usersupp.flags |
923 (extract_int(new_parms, 2) & US_USER_SET);
925 if (num_parms(new_parms) >= 4) {
926 new_mod = extract_int(new_parms, 3);
927 lprintf(9, "new_mod extracted to %d\n", new_mod);
929 /* Aides cannot set the filter level lower than -100 */
930 if (new_mod < (-100))
933 /* Normal users cannot set the filter level lower than -63 */
934 if ((new_mod < (-63)) && (CC->usersupp.axlevel < 6))
937 /* Nobody can set the filter level higher than +63 */
941 CC->usersupp.moderation_filter = new_mod;
942 lprintf(9, "new_mod processed to %d\n", new_mod);
944 lputuser(&CC->usersupp);
945 cprintf("%d Ok\n", CIT_OK);
949 * set last read pointer
951 void cmd_slrp(char *new_ptr)
956 if (CtdlAccessCheck(ac_logged_in)) {
960 if (!strncasecmp(new_ptr, "highest", 7)) {
961 newlr = CC->quickroom.QRhighest;
963 newlr = atol(new_ptr);
966 lgetuser(&CC->usersupp, CC->curr_user);
968 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
969 vbuf.v_lastseen = newlr;
970 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
971 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
973 lputuser(&CC->usersupp);
974 cprintf("%d %ld\n", CIT_OK, newlr);
978 void cmd_seen(char *argbuf) {
979 long target_msgnum = 0L;
980 int target_setting = 0;
982 if (CtdlAccessCheck(ac_logged_in)) {
986 if (num_parms(argbuf) != 2) {
987 cprintf("%d Invalid parameters\n", ERROR);
991 target_msgnum = extract_long(argbuf, 0);
992 target_setting = extract_int(argbuf, 1);
994 CtdlSetSeen(target_msgnum, target_setting);
995 cprintf("%d OK\n", CIT_OK);
1000 * INVT and KICK commands
1002 void cmd_invt_kick(char *iuser, int op)
1004 { /* 1 = invite, 0 = kick out */
1005 struct usersupp USscratch;
1010 * These commands are only allowed by aides, room aides,
1011 * and room namespace owners
1014 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
1015 /* access granted */
1019 cprintf("%d Higher access or room ownership required.\n",
1020 ERROR + HIGHER_ACCESS_REQUIRED);
1024 if (lgetuser(&USscratch, iuser) != 0) {
1025 cprintf("%d No such user.\n", ERROR);
1028 CtdlGetRelationship(&vbuf, &USscratch, &CC->quickroom);
1031 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1032 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1035 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1036 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1038 CtdlSetRelationship(&vbuf, &USscratch, &CC->quickroom);
1040 lputuser(&USscratch);
1042 /* post a message in Aide> saying what we just did */
1043 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1045 ((op == 1) ? "invited to" : "kicked out of"),
1046 CC->quickroom.QRname,
1047 CC->usersupp.fullname);
1050 cprintf("%d %s %s %s.\n",
1052 ((op == 1) ? "invited to" : "kicked out of"),
1053 CC->quickroom.QRname);
1059 * Forget (Zap) the current room (API call)
1060 * Returns 0 on success
1062 int CtdlForgetThisRoom(void) {
1065 /* On some systems, Aides are not allowed to forget rooms */
1066 if (is_aide() && (config.c_aide_zap == 0)
1067 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0) ) {
1071 lgetuser(&CC->usersupp, CC->curr_user);
1072 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1074 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1075 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1077 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1078 lputuser(&CC->usersupp);
1080 /* Return to the Lobby, so we don't end up in an undefined room */
1081 usergoto(BASEROOM, 0, NULL, NULL);
1088 * forget (Zap) the current room
1093 if (CtdlAccessCheck(ac_logged_in)) {
1097 if (CtdlForgetThisRoom() == 0) {
1098 cprintf("%d Ok\n", CIT_OK);
1101 cprintf("%d You may not forget this room.\n", ERROR);
1106 * Get Next Unregistered User
1110 struct cdbdata *cdbus;
1111 struct usersupp usbuf;
1113 if (CtdlAccessCheck(ac_aide)) {
1117 if ((CitControl.MMflags & MM_VALID) == 0) {
1118 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1122 /* There are unvalidated users. Traverse the usersupp database,
1123 * and return the first user we find that needs validation.
1125 cdb_rewind(CDB_USERSUPP);
1126 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1127 memset(&usbuf, 0, sizeof(struct usersupp));
1128 memcpy(&usbuf, cdbus->ptr,
1129 ((cdbus->len > sizeof(struct usersupp)) ?
1130 sizeof(struct usersupp) : cdbus->len));
1132 if ((usbuf.flags & US_NEEDVALID)
1133 && (usbuf.axlevel > 0)) {
1134 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1135 cdb_close_cursor(CDB_USERSUPP);
1140 /* If we get to this point, there are no more unvalidated users.
1141 * Therefore we clear the "users need validation" flag.
1144 begin_critical_section(S_CONTROL);
1146 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1148 end_critical_section(S_CONTROL);
1149 cprintf("%d *** End of registration.\n", CIT_OK);
1158 void cmd_vali(char *v_args)
1162 struct usersupp userbuf;
1164 extract(user, v_args, 0);
1165 newax = extract_int(v_args, 1);
1167 if (CtdlAccessCheck(ac_aide)) {
1171 if (lgetuser(&userbuf, user) != 0) {
1172 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1176 userbuf.axlevel = newax;
1177 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1181 /* If the access level was set to zero, delete the user */
1183 if (purge_user(user) == 0) {
1184 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1188 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1194 * Traverse the user file...
1196 void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
1199 struct usersupp usbuf;
1200 struct cdbdata *cdbus;
1202 cdb_rewind(CDB_USERSUPP);
1204 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1205 memset(&usbuf, 0, sizeof(struct usersupp));
1206 memcpy(&usbuf, cdbus->ptr,
1207 ((cdbus->len > sizeof(struct usersupp)) ?
1208 sizeof(struct usersupp) : cdbus->len));
1210 (*CallBack) (&usbuf, in_data);
1216 * List one user (this works with cmd_list)
1218 void ListThisUser(struct usersupp *usbuf, void *data)
1220 if (usbuf->axlevel > 0) {
1221 if ((CC->usersupp.axlevel >= 6)
1222 || ((usbuf->flags & US_UNLISTED) == 0)
1223 || ((CC->internal_pgm))) {
1224 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1228 (long)usbuf->lastcall,
1231 if (CC->usersupp.axlevel >= 6)
1232 cprintf("%s", usbuf->password);
1243 cprintf("%d \n", LISTING_FOLLOWS);
1244 ForEachUser(ListThisUser, NULL);
1252 * assorted info we need to check at login
1260 if (CtdlAccessCheck(ac_logged_in)) {
1264 getuser(&CC->usersupp, CC->curr_user); /* no lock is needed here */
1265 if ((REGISCALL != 0) && ((CC->usersupp.flags & US_REGIS) == 0))
1268 if (CC->usersupp.axlevel >= 6) {
1270 if (CitControl.MMflags & MM_VALID)
1274 /* check for mail */
1275 mail = NewMailCount();
1277 cprintf("%d %d|%d|%d\n", CIT_OK, mail, regis, vali);
1282 * check to see if a user exists
1284 void cmd_qusr(char *who)
1286 struct usersupp usbuf;
1288 if (getuser(&usbuf, who) == 0) {
1289 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1291 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1297 * Administrative Get User Parameters
1299 void cmd_agup(char *cmdbuf)
1301 struct usersupp usbuf;
1302 char requested_user[SIZ];
1304 if (CtdlAccessCheck(ac_aide)) {
1308 extract(requested_user, cmdbuf, 0);
1309 if (getuser(&usbuf, requested_user) != 0) {
1310 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1313 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1320 (int) usbuf.axlevel,
1322 (long)usbuf.lastcall,
1329 * Administrative Set User Parameters
1331 void cmd_asup(char *cmdbuf)
1333 struct usersupp usbuf;
1334 char requested_user[SIZ];
1339 if (CtdlAccessCheck(ac_aide))
1342 extract(requested_user, cmdbuf, 0);
1343 if (lgetuser(&usbuf, requested_user) != 0) {
1344 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1347 np = num_parms(cmdbuf);
1349 extract(usbuf.password, cmdbuf, 1);
1351 usbuf.flags = extract_int(cmdbuf, 2);
1353 usbuf.timescalled = extract_int(cmdbuf, 3);
1355 usbuf.posted = extract_int(cmdbuf, 4);
1357 newax = extract_int(cmdbuf, 5);
1358 if ((newax >= 0) && (newax <= 6)) {
1359 usbuf.axlevel = extract_int(cmdbuf, 5);
1363 usbuf.lastcall = extract_long(cmdbuf, 7);
1366 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1369 if (usbuf.axlevel == 0) {
1370 if (purge_user(requested_user) == 0) {
1374 cprintf("%d Ok", CIT_OK);
1376 cprintf(" (%s deleted)", requested_user);
1382 * Count the number of new mail messages the user has
1386 int num_newmsgs = 0;
1388 char mailboxname[ROOMNAMELEN];
1389 struct quickroom mailbox;
1391 struct cdbdata *cdbfr;
1392 long *msglist = NULL;
1395 MailboxName(mailboxname, sizeof mailboxname, &CC->usersupp, MAILROOM);
1396 if (getroom(&mailbox, mailboxname) != 0)
1398 CtdlGetRelationship(&vbuf, &CC->usersupp, &mailbox);
1400 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1402 if (cdbfr != NULL) {
1403 msglist = mallok(cdbfr->len);
1404 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1405 num_msgs = cdbfr->len / sizeof(long);
1409 for (a = 0; a < num_msgs; ++a) {
1410 if (msglist[a] > 0L) {
1411 if (msglist[a] > vbuf.v_lastseen) {
1416 if (msglist != NULL)
1419 return (num_newmsgs);