2 * Server functions which perform operations on user objects.
14 #include <sys/types.h>
16 #ifdef HAVE_SYS_STAT_H
20 #if TIME_WITH_SYS_TIME
21 # include <sys/time.h>
25 # include <sys/time.h>
33 #include <libcitadel.h>
38 #include "sysdep_decls.h"
45 #include "citserver.h"
46 #include "citadel_dirs.h"
49 #include "citadel_ldap.h"
52 #include "ctdl_module.h"
54 ////#define CTDL_INLINE_USR INLINE
57 /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
58 int chkpwd_write_pipe[2];
59 int chkpwd_read_pipe[2];
64 * getuser() - retrieve named user into supplied buffer.
65 * returns 0 on success
67 int getuser(struct ctdluser *usbuf, char name[])
69 return CtdlGetUser(usbuf, name);
74 * CtdlGetUser() - retrieve named user into supplied buffer.
75 * returns 0 on success
77 int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len)
80 char usernamekey[USERNAME_SIZE];
81 struct cdbdata *cdbus;
84 memset(usbuf, 0, sizeof(struct ctdluser));
87 makeuserkey(usernamekey, name, len);
88 cdbus = cdb_fetch(CDB_USERS, usernamekey, strlen(usernamekey));
90 if (cdbus == NULL) { /* user not found */
94 memcpy(usbuf, cdbus->ptr,
95 ((cdbus->len > sizeof(struct ctdluser)) ?
96 sizeof(struct ctdluser) : cdbus->len));
104 int CtdlGetUser(struct ctdluser *usbuf, char *name)
106 return CtdlGetUserLen(usbuf, name, cutuserkey(name));
111 * CtdlGetUserLock() - same as getuser() but locks the record
113 int CtdlGetUserLock(struct ctdluser *usbuf, char *name)
117 retcode = CtdlGetUser(usbuf, name);
119 begin_critical_section(S_USERS);
126 * lgetuser() - same as getuser() but locks the record
128 int lgetuser(struct ctdluser *usbuf, char *name)
130 return CtdlGetUserLock(usbuf, name);
135 * CtdlPutUser() - write user buffer into the correct place on disk
137 void CtdlPutUser(struct ctdluser *usbuf)
139 char usernamekey[USERNAME_SIZE];
141 makeuserkey(usernamekey,
143 cutuserkey(usbuf->fullname));
145 usbuf->version = REV_LEVEL;
147 usernamekey, strlen(usernamekey),
148 usbuf, sizeof(struct ctdluser));
154 * putuser() - write user buffer into the correct place on disk
156 void putuser(struct ctdluser *usbuf)
163 * CtdlPutUserLock() - same as putuser() but locks the record
165 void CtdlPutUserLock(struct ctdluser *usbuf)
168 end_critical_section(S_USERS);
173 * lputuser() - same as putuser() but locks the record
175 void lputuser(struct ctdluser *usbuf)
177 CtdlPutUserLock(usbuf);
182 * rename_user() - this is tricky because the user's display name is the database key
184 * Returns 0 on success or nonzero if there was an error...
187 int rename_user(char *oldname, char *newname) {
188 int retcode = RENAMEUSER_OK;
189 struct ctdluser usbuf;
191 char oldnamekey[USERNAME_SIZE];
192 char newnamekey[USERNAME_SIZE];
194 /* Create the database keys... */
195 makeuserkey(oldnamekey, oldname, cutuserkey(oldname));
196 makeuserkey(newnamekey, newname, cutuserkey(newname));
198 /* Lock up and get going */
199 begin_critical_section(S_USERS);
201 /* We cannot rename a user who is currently logged in */
202 if (CtdlIsUserLoggedIn(oldname)) {
203 end_critical_section(S_USERS);
204 return RENAMEUSER_LOGGED_IN;
207 if (CtdlGetUser(&usbuf, newname) == 0) {
208 retcode = RENAMEUSER_ALREADY_EXISTS;
212 if (CtdlGetUser(&usbuf, oldname) != 0) {
213 retcode = RENAMEUSER_NOT_FOUND;
216 else { /* Sanity checks succeeded. Now rename the user. */
217 if (usbuf.usernum == 0)
219 CtdlLogPrintf (CTDL_DEBUG, "Can not rename user \"Citadel\".\n");
220 retcode = RENAMEUSER_NOT_FOUND;
222 CtdlLogPrintf(CTDL_DEBUG, "Renaming <%s> to <%s>\n", oldname, newname);
223 cdb_delete(CDB_USERS, oldnamekey, strlen(oldnamekey));
224 safestrncpy(usbuf.fullname, newname, sizeof usbuf.fullname);
226 cdb_store(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long),
227 usbuf.fullname, strlen(usbuf.fullname)+1 );
229 retcode = RENAMEUSER_OK;
235 end_critical_section(S_USERS);
242 * Index-generating function used by Ctdl[Get|Set]Relationship
244 int GenerateRelationshipIndex(char *IndexBuf,
256 TheIndex.iRoomID = RoomID;
257 TheIndex.iRoomGen = RoomGen;
258 TheIndex.iUserID = UserID;
260 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
261 return (sizeof(TheIndex));
267 * Back end for CtdlSetRelationship()
269 void put_visit(visit *newvisit)
274 memset (IndexBuf, 0, sizeof (IndexBuf));
275 /* Generate an index */
276 IndexLen = GenerateRelationshipIndex(IndexBuf,
279 newvisit->v_usernum);
281 /* Store the record */
282 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
283 newvisit, sizeof(visit)
291 * Define a relationship between a user and a room
293 void CtdlSetRelationship(visit *newvisit,
294 struct ctdluser *rel_user,
295 struct ctdlroom *rel_room)
299 /* We don't use these in Citadel because they're implicit by the
300 * index, but they must be present if the database is exported.
302 newvisit->v_roomnum = rel_room->QRnumber;
303 newvisit->v_roomgen = rel_room->QRgen;
304 newvisit->v_usernum = rel_user->usernum;
310 * Locate a relationship between a user and a room
312 void CtdlGetRelationship(visit *vbuf,
313 struct ctdluser *rel_user,
314 struct ctdlroom *rel_room)
319 struct cdbdata *cdbvisit;
321 /* Generate an index */
322 IndexLen = GenerateRelationshipIndex(IndexBuf,
327 /* Clear out the buffer */
328 memset(vbuf, 0, sizeof(visit));
330 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
331 if (cdbvisit != NULL) {
332 memcpy(vbuf, cdbvisit->ptr,
333 ((cdbvisit->len > sizeof(visit)) ?
334 sizeof(visit) : cdbvisit->len));
338 /* If this is the first time the user has seen this room,
339 * set the view to be the default for the room.
341 vbuf->v_view = rel_room->QRdefaultview;
344 /* Set v_seen if necessary */
345 if (vbuf->v_seen[0] == 0) {
346 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
351 void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
353 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
357 void MailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
359 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
364 * Is the user currently logged in an Aide?
368 if (CC->user.axlevel >= AxAideU)
376 * Is the user currently logged in an Aide *or* the room aide for this room?
378 int is_room_aide(void)
381 if (!CC->logged_in) {
385 if ((CC->user.axlevel >= AxAideU)
386 || (CC->room.QRroomaide == CC->user.usernum)) {
394 * CtdlGetUserByNumber() - get user by number
395 * returns 0 if user was found
397 * Note: fetching a user this way requires one additional database operation.
399 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number)
401 struct cdbdata *cdbun;
404 cdbun = cdb_fetch(CDB_USERSBYNUMBER, &number, sizeof(long));
406 CtdlLogPrintf(CTDL_INFO, "User %ld not found\n", number);
410 CtdlLogPrintf(CTDL_INFO, "User %ld maps to %s\n", number, cdbun->ptr);
411 r = CtdlGetUser(usbuf, cdbun->ptr);
417 * getuserbynumber() - get user by number
418 * returns 0 if user was found
420 * Note: fetching a user this way requires one additional database operation.
422 int getuserbynumber(struct ctdluser *usbuf, long number)
424 return CtdlGetUserByNumber(usbuf, number);
430 * Helper function for rebuild_usersbynumber()
432 void rebuild_ubn_for_user(struct ctdluser *usbuf, void *data) {
435 struct ubnlist *next;
436 char username[USERNAME_SIZE];
440 static struct ubnlist *u = NULL;
441 struct ubnlist *ptr = NULL;
443 /* Lazy programming here. Call this function as a ForEachUser backend
444 * in order to queue up the room names, or call it with a null user
445 * to make it do the processing.
448 ptr = (struct ubnlist *) malloc(sizeof (struct ubnlist));
449 if (ptr == NULL) return;
451 ptr->usernum = usbuf->usernum;
452 safestrncpy(ptr->username, usbuf->fullname, sizeof ptr->username);
459 CtdlLogPrintf(CTDL_DEBUG, "Rebuilding usersbynumber index %10ld : %s\n",
460 u->usernum, u->username);
461 cdb_store(CDB_USERSBYNUMBER, &u->usernum, sizeof(long), u->username, strlen(u->username)+1);
472 * Rebuild the users-by-number index
474 void rebuild_usersbynumber(void) {
475 cdb_trunc(CDB_USERSBYNUMBER); /* delete the old indices */
476 ForEachUser(rebuild_ubn_for_user, NULL); /* enumerate the users */
477 rebuild_ubn_for_user(NULL, NULL); /* and index them */
483 * getuserbyuid() - get user by system uid (for PAM mode authentication)
484 * returns 0 if user was found
486 * WARNING: don't use this function unless you absolutely have to. It does
487 * a sequential search and therefore is computationally expensive.
489 int getuserbyuid(struct ctdluser *usbuf, uid_t number)
491 struct cdbdata *cdbus;
493 cdb_rewind(CDB_USERS);
495 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
496 memset(usbuf, 0, sizeof(struct ctdluser));
497 memcpy(usbuf, cdbus->ptr,
498 ((cdbus->len > sizeof(struct ctdluser)) ?
499 sizeof(struct ctdluser) : cdbus->len));
501 if (usbuf->uid == number) {
502 cdb_close_cursor(CDB_USERS);
510 * Back end for cmd_user() and its ilk
512 * NOTE: "authname" should only be used if we are attempting to use the "master user" feature
514 int CtdlLoginExistingUser(char *authname, const char *trythisname)
520 CtdlLogPrintf(9, "CtdlLoginExistingUser(%s, %s)\n", authname, trythisname);
522 if ((CC->logged_in)) {
523 return login_already_logged_in;
526 if (trythisname == NULL) return login_not_found;
528 if (!strncasecmp(trythisname, "SYS_", 4))
530 CtdlLogPrintf(CTDL_DEBUG, "System user \"%s\" is not allowed to log in.\n", trythisname);
531 return login_not_found;
534 /* If a "master user" is defined, handle its authentication if specified */
536 if (strlen(config.c_master_user) > 0) if (strlen(config.c_master_pass) > 0) if (authname) {
537 if (!strcasecmp(authname, config.c_master_user)) {
542 /* Continue attempting user validation... */
543 safestrncpy(username, trythisname, sizeof (username));
545 len = cutuserkey(username);
547 if (IsEmptyStr(username)) {
548 return login_not_found;
551 if (config.c_auth_mode == AUTHMODE_HOST) {
556 struct passwd *tempPwdPtr;
559 CtdlLogPrintf(CTDL_DEBUG, "asking host about <%s>\n", username);
560 #ifdef HAVE_GETPWNAM_R
561 #ifdef SOLARIS_GETPWUID
562 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
563 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer);
564 #else // SOLARIS_GETPWUID
565 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
566 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
567 #endif // SOLARIS_GETPWUID
568 #else // HAVE_GETPWNAM_R
569 CtdlLogPrintf(CTDL_DEBUG, "SHOULD NEVER GET HERE!!!\n");
571 #endif // HAVE_GETPWNAM_R
572 if (tempPwdPtr == NULL) {
573 CtdlLogPrintf(CTDL_DEBUG, "no such user <%s>\n", username);
574 return login_not_found;
577 /* Locate the associated Citadel account.
578 * If not found, make one attempt to create it.
580 found_user = getuserbyuid(&CC->user, pd.pw_uid);
581 CtdlLogPrintf(CTDL_DEBUG, "found it: uid=%ld, gecos=%s here: %d\n",
582 (long)pd.pw_uid, pd.pw_gecos, found_user);
583 if (found_user != 0) {
584 len = cutuserkey(username);
585 create_user(username, len, 0);
586 found_user = getuserbyuid(&CC->user, pd.pw_uid);
592 else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
600 found_user = CtdlTryUserLDAP(username, ldap_dn, sizeof ldap_dn, ldap_cn, sizeof ldap_cn, &ldap_uid);
601 if (found_user != 0) {
602 return login_not_found;
605 found_user = getuserbyuid(&CC->user, ldap_uid);
606 if (found_user != 0) {
607 create_user(username, len, 0);
608 found_user = getuserbyuid(&CC->user, ldap_uid);
611 if (found_user == 0) {
612 if (CC->ldap_dn != NULL) free(CC->ldap_dn);
613 CC->ldap_dn = strdup(ldap_dn);
620 /* native auth mode */
622 struct recptypes *valid = NULL;
624 /* First, try to log in as if the supplied name is a display name */
625 found_user = CtdlGetUser(&CC->user, username);
627 /* If that didn't work, try to log in as if the supplied name
628 * is an e-mail address
630 if (found_user != 0) {
631 valid = validate_recipients(username, NULL, 0);
633 if (valid->num_local == 1) {
634 found_user = CtdlGetUser(&CC->user, valid->recp_local);
636 free_recipients(valid);
641 /* Did we find something? */
642 if (found_user == 0) {
643 if (((CC->nologin)) && (CC->user.axlevel < AxAideU)) {
644 return login_too_many_users;
646 safestrncpy(CC->curr_user, CC->user.fullname,
647 sizeof CC->curr_user);
651 return login_not_found;
659 void cmd_user(char *cmdbuf)
664 CtdlLogPrintf(CTDL_DEBUG, "cmd_user(%s)\n", cmdbuf);
665 extract_token(username, cmdbuf, 0, '|', sizeof username);
666 CtdlLogPrintf(CTDL_DEBUG, "username: %s\n", username);
668 CtdlLogPrintf(CTDL_DEBUG, "username: %s\n", username);
670 a = CtdlLoginExistingUser(NULL, username);
672 case login_already_logged_in:
673 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
675 case login_too_many_users:
677 "Too many users are already online "
679 ERROR + MAX_SESSIONS_EXCEEDED,
680 config.c_nodename, config.c_maxsessions);
683 cprintf("%d Password required for %s\n",
684 MORE_DATA, CC->curr_user);
686 case login_not_found:
687 cprintf("%d %s not found.\n", ERROR + NO_SUCH_USER, username);
690 cprintf("%d Internal error\n", ERROR + INTERNAL_ERROR);
697 * session startup code which is common to both cmd_pass() and cmd_newu()
702 CtdlLogPrintf(CTDL_NOTICE, "<%s> logged in\n", CC->curr_user);
704 CtdlGetUserLock(&CC->user, CC->curr_user);
705 ++(CC->user.timescalled);
706 CC->previous_login = CC->user.lastcall;
707 time(&CC->user.lastcall);
709 /* If this user's name is the name of the system administrator
710 * (as specified in setup), automatically assign access level 6.
712 if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
713 CC->user.axlevel = AxAideU;
716 /* If we're authenticating off the host system, automatically give
717 * root the highest level of access.
719 if (config.c_auth_mode == AUTHMODE_HOST) {
720 if (CC->user.uid == 0) {
721 CC->user.axlevel = AxAideU;
725 CtdlPutUserLock(&CC->user);
728 * Populate CC->cs_inet_email with a default address. This will be
729 * overwritten with the user's directory address, if one exists, when
730 * the vCard module's login hook runs.
732 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
733 CC->user.fullname, config.c_fqdn);
734 convert_spaces_to_underscores(CC->cs_inet_email);
736 /* Create any personal rooms required by the system.
737 * (Technically, MAILROOM should be there already, but just in case...)
739 CtdlCreateRoom(MAILROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
740 CtdlCreateRoom(SENTITEMS, 4, "", 0, 1, 0, VIEW_MAILBOX);
741 CtdlCreateRoom(USERTRASHROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
742 /* CtdlCreateRoom(USERDRAFTROOM, 4, "", 0, 1, 0, VIEW_MAILBOX); temporarily disabled for 7.60 */
744 /* Run any startup routines registered by loadable modules */
745 PerformSessionHooks(EVT_LOGIN);
747 /* Enter the lobby */
748 CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
752 void logged_in_response(void)
754 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
755 CIT_OK, CC->user.fullname, CC->user.axlevel,
756 CC->user.timescalled, CC->user.posted,
757 CC->user.flags, CC->user.usernum,
764 * misc things to be taken care of when a user is logged out
772 void CtdlUserLogout(void)
774 CitContext *CCC = MyContext();
776 * If there is a download in progress, abort it.
778 if (CCC->download_fp != NULL) {
779 fclose(CCC->download_fp);
780 CCC->download_fp = NULL;
784 * If there is an upload in progress, abort it.
786 if (CCC->upload_fp != NULL) {
791 * If we were talking to a network node, we're not anymore...
793 if (!IsEmptyStr(CCC->net_node)) {
794 network_talking_to(CCC->net_node, NTT_REMOVE);
797 /* Run any hooks registered by modules... */
798 PerformSessionHooks(EVT_LOGOUT);
801 * Clear out some session data. Most likely, the CitContext for this
802 * session is about to get nuked when the session disconnects, but
803 * since it's possible to log in again without reconnecting, we cannot
804 * make that assumption.
806 strcpy(CCC->fake_username, "");
807 strcpy(CCC->fake_hostname, "");
808 strcpy(CCC->fake_roomname, "");
811 /* Check to see if the user was deleted whilst logged in and purge them if necessary */
812 if ((CCC->user.axlevel == AxDeleted) && (CCC->user.usernum))
813 purge_user(CCC->user.fullname);
815 /* Free any output buffers */
820 * Validate a password on the host unix system by talking to the chkpwd daemon
822 static int validpw(uid_t uid, const char *pass)
827 if (IsEmptyStr(pass)) {
828 CtdlLogPrintf(CTDL_DEBUG, "refusing to check empty password for uid=%d using chkpwd...\n", uid);
832 CtdlLogPrintf(CTDL_DEBUG, "Validating password for uid=%d using chkpwd...\n", uid);
834 begin_critical_section(S_CHKPWD);
835 rv = write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
836 rv = write(chkpwd_write_pipe[1], pass, 256);
837 rv = read(chkpwd_read_pipe[0], buf, 4);
838 end_critical_section(S_CHKPWD);
840 if (!strncmp(buf, "PASS", 4)) {
841 CtdlLogPrintf(CTDL_DEBUG, "...pass\n");
845 CtdlLogPrintf(CTDL_DEBUG, "...fail\n");
850 * Start up the chkpwd daemon so validpw() has something to talk to
852 void start_chkpwd_daemon(void) {
854 struct stat filestats;
857 CtdlLogPrintf(CTDL_DEBUG, "Starting chkpwd daemon for host authentication mode\n");
859 if ((stat(file_chkpwd, &filestats)==-1) ||
860 (filestats.st_size==0)){
861 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd, strerror(errno));
864 if (pipe(chkpwd_write_pipe) != 0) {
865 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
868 if (pipe(chkpwd_read_pipe) != 0) {
869 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
874 if (chkpwd_pid < 0) {
875 CtdlLogPrintf(CTDL_EMERG, "Unable to fork chkpwd daemon: %s\n", strerror(errno));
878 if (chkpwd_pid == 0) {
879 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
880 dup2(chkpwd_write_pipe[0], 0);
881 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
882 dup2(chkpwd_read_pipe[1], 1);
883 CtdlLogPrintf(CTDL_DEBUG, "Now closing stuff\n");
884 for (i=2; i<256; ++i) close(i);
885 CtdlLogPrintf(CTDL_DEBUG, "Now calling execl(%s)\n", file_chkpwd);
886 execl(file_chkpwd, file_chkpwd, NULL);
887 CtdlLogPrintf(CTDL_EMERG, "Unable to exec chkpwd daemon: %s\n", strerror(errno));
894 int CtdlTryPassword(const char *password, long len)
898 if ((CC->logged_in)) {
899 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: already logged in\n");
900 return pass_already_logged_in;
902 if (!strcmp(CC->curr_user, NLI)) {
903 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: no user selected\n");
906 if (CtdlGetUser(&CC->user, CC->curr_user)) {
907 CtdlLogPrintf(CTDL_ERR, "CtdlTryPassword: internal error\n");
908 return pass_internal_error;
910 if (password == NULL) {
911 CtdlLogPrintf(CTDL_INFO, "CtdlTryPassword: NULL password string supplied\n");
912 return pass_wrong_password;
917 code = strcmp(password, config.c_master_pass);
920 else if (config.c_auth_mode == AUTHMODE_HOST) {
924 if (validpw(CC->user.uid, password)) {
928 * sooper-seekrit hack: populate the password field in the
929 * citadel database with the password that the user typed,
930 * if it's correct. This allows most sites to convert from
931 * host auth to native auth if they want to. If you think
932 * this is a security hazard, comment it out.
935 CtdlGetUserLock(&CC->user, CC->curr_user);
936 safestrncpy(CC->user.password, password, sizeof CC->user.password);
937 CtdlPutUserLock(&CC->user);
940 * (sooper-seekrit hack ends here)
950 else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
954 if ((CC->ldap_dn) && (!CtdlTryPasswordLDAP(CC->ldap_dn, password))) {
965 /* native auth mode */
968 pw = (char*) malloc(len + 1);
969 memcpy(pw, password, len + 1);
971 strproc(CC->user.password);
972 code = strcasecmp(CC->user.password, pw);
974 strproc(CC->user.password);
975 code = strcasecmp(CC->user.password, pw);
983 CtdlLogPrintf(CTDL_WARNING, "Bad password specified for <%s>\n", CC->curr_user);
984 return pass_wrong_password;
989 void cmd_pass(char *buf)
995 memset(password, 0, sizeof(password));
996 len = extract_token(password, buf, 0, '|', sizeof password);
997 a = CtdlTryPassword(password, len);
1000 case pass_already_logged_in:
1001 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1004 cprintf("%d You must send a name with USER first.\n",
1005 ERROR + USERNAME_REQUIRED);
1007 case pass_wrong_password:
1008 cprintf("%d Wrong password.\n", ERROR + PASSWORD_REQUIRED);
1011 logged_in_response();
1019 * Delete a user record *and* all of its related resources.
1021 int purge_user(char pname[])
1024 struct ctdluser usbuf;
1025 char usernamekey[USERNAME_SIZE];
1027 makeuserkey(usernamekey, pname, cutuserkey(pname));
1029 /* If the name is empty we can't find them in the DB any way so just return */
1030 if (IsEmptyStr(pname))
1031 return (ERROR + NO_SUCH_USER);
1033 if (CtdlGetUser(&usbuf, pname) != 0) {
1034 CtdlLogPrintf(CTDL_ERR, "Cannot purge user <%s> - not found\n", pname);
1035 return (ERROR + NO_SUCH_USER);
1037 /* Don't delete a user who is currently logged in. Instead, just
1038 * set the access level to 0, and let the account get swept up
1039 * during the next purge.
1041 if (CtdlIsUserLoggedInByNum(usbuf.usernum)) {
1042 CtdlLogPrintf(CTDL_WARNING, "User <%s> is logged in; not deleting.\n", pname);
1043 usbuf.axlevel = AxDeleted;
1044 CtdlPutUser(&usbuf);
1047 CtdlLogPrintf(CTDL_NOTICE, "Deleting user <%s>\n", pname);
1051 * This should all be wrapped in a S_USERS mutex.
1052 * Without the mutex the user could log in before we get to the next function
1053 * That would truly mess things up :-(
1054 * I would like to see the S_USERS start before the CtdlIsUserLoggedInByNum() above
1055 * and end after the user has been deleted from the database, below.
1056 * Question is should we enter the EVT_PURGEUSER whilst S_USERS is active?
1059 /* Perform any purge functions registered by server extensions */
1060 PerformUserHooks(&usbuf, EVT_PURGEUSER);
1062 /* delete any existing user/room relationships */
1063 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
1065 /* delete the users-by-number index record */
1066 cdb_delete(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long));
1068 /* delete the userlog entry */
1069 cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
1071 /* remove the user's bio file */
1079 /* remove the user's picture */
1091 int internal_create_user (const char *username, long len, struct ctdluser *usbuf, uid_t uid)
1093 if (!CtdlGetUserLen(usbuf, username, len)) {
1094 return (ERROR + ALREADY_EXISTS);
1097 /* Go ahead and initialize a new user record */
1098 memset(usbuf, 0, sizeof(struct ctdluser));
1099 safestrncpy(usbuf->fullname, username, sizeof usbuf->fullname);
1100 strcpy(usbuf->password, "");
1103 /* These are the default flags on new accounts */
1104 usbuf->flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
1106 usbuf->timescalled = 0;
1108 usbuf->axlevel = config.c_initax;
1109 usbuf->lastcall = time(NULL);
1111 /* fetch a new user number */
1112 usbuf->usernum = get_new_user_number();
1114 /* add user to the database */
1116 cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1);
1124 * create_user() - back end processing to create a new user
1126 * Set 'newusername' to the desired account name.
1127 * Set 'become_user' to nonzero if this is self-service account creation and we want
1128 * to actually log in as the user we just created, otherwise set it to 0.
1130 int create_user(const char *newusername, long len, int become_user)
1132 struct ctdluser usbuf;
1133 struct ctdlroom qrbuf;
1135 char mailboxname[ROOMNAMELEN];
1141 safestrncpy(username, newusername, sizeof username);
1145 if (config.c_auth_mode == AUTHMODE_HOST) {
1147 /* host auth mode */
1150 struct passwd *tempPwdPtr;
1151 char pwdbuffer[SIZ];
1153 #ifdef HAVE_GETPWNAM_R
1154 #ifdef SOLARIS_GETPWUID
1155 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer));
1156 #else // SOLARIS_GETPWUID
1157 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
1158 #endif // SOLARIS_GETPWUID
1159 #else // HAVE_GETPWNAM_R
1161 #endif // HAVE_GETPWNAM_R
1162 if (tempPwdPtr != NULL) {
1163 extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
1165 if (IsEmptyStr (username))
1167 safestrncpy(username, pd.pw_name, sizeof username);
1168 len = cutuserkey(username);
1172 return (ERROR + NO_SUCH_USER);
1177 if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
1178 if (CtdlTryUserLDAP(username, NULL, 0, username, sizeof username, &uid) != 0) {
1179 return(ERROR + NO_SUCH_USER);
1182 #endif /* HAVE_LDAP */
1184 if ((retval = internal_create_user(username, len, &usbuf, uid)) != 0)
1188 * Give the user a private mailbox and a configuration room.
1189 * Make the latter an invisible system room.
1191 CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
1192 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_MAILBOX);
1194 CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
1195 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_BBS);
1196 if (CtdlGetRoomLock(&qrbuf, mailboxname) == 0) {
1197 qrbuf.QRflags2 |= QR2_SYSTEM;
1198 CtdlPutRoomLock(&qrbuf);
1201 /* Perform any create functions registered by server extensions */
1202 PerformUserHooks(&usbuf, EVT_NEWUSER);
1204 /* Everything below this line can be bypassed if administratively
1205 * creating a user, instead of doing self-service account creation
1209 /* Now become the user we just created */
1210 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
1211 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
1214 /* Check to make sure we're still who we think we are */
1215 if (CtdlGetUser(&CC->user, CC->curr_user)) {
1216 return (ERROR + INTERNAL_ERROR);
1221 "New user account <%s> has been created, from host %s [%s].\n",
1226 CtdlAideMessage(buf, "User Creation Notice");
1227 CtdlLogPrintf(CTDL_NOTICE, "New user <%s> created\n", username);
1234 * cmd_newu() - create a new user account and log in as that user
1236 void cmd_newu(char *cmdbuf)
1242 if (config.c_auth_mode != AUTHMODE_NATIVE) {
1243 cprintf("%d This system does not use native mode authentication.\n",
1248 if (config.c_disable_newu) {
1249 cprintf("%d Self-service user account creation "
1250 "is disabled on this system.\n", ERROR + NOT_HERE);
1254 if (CC->logged_in) {
1255 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1259 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
1260 ERROR + MAX_SESSIONS_EXCEEDED,
1261 config.c_nodename, config.c_maxsessions);
1263 extract_token(username, cmdbuf, 0, '|', sizeof username);
1265 len = cutuserkey(username);
1267 if (IsEmptyStr(username)) {
1268 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1272 if ((!strcasecmp(username, "bbs")) ||
1273 (!strcasecmp(username, "new")) ||
1274 (!strcasecmp(username, "."))) {
1275 cprintf("%d '%s' is an invalid login name.\n", ERROR + ILLEGAL_VALUE, username);
1279 a = create_user(username, len, 1);
1282 logged_in_response();
1283 } else if (a == ERROR + ALREADY_EXISTS) {
1284 cprintf("%d '%s' already exists.\n",
1285 ERROR + ALREADY_EXISTS, username);
1287 } else if (a == ERROR + INTERNAL_ERROR) {
1288 cprintf("%d Internal error - user record disappeared?\n",
1289 ERROR + INTERNAL_ERROR);
1292 cprintf("%d unknown error\n", ERROR + INTERNAL_ERROR);
1298 * set password - back end api code
1300 void CtdlSetPassword(char *new_pw)
1302 CtdlGetUserLock(&CC->user, CC->curr_user);
1303 safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
1304 CtdlPutUserLock(&CC->user);
1305 CtdlLogPrintf(CTDL_INFO, "Password changed for user <%s>\n", CC->curr_user);
1306 PerformSessionHooks(EVT_SETPASS);
1311 * set password - citadel protocol implementation
1313 void cmd_setp(char *new_pw)
1315 int generate_random_password = 0;
1317 if (CtdlAccessCheck(ac_logged_in)) {
1320 if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
1321 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR + NOT_HERE);
1324 if (CC->is_master) {
1325 cprintf("%d The master prefix password cannot be changed with this command.\n",
1330 if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
1331 char random_password[17];
1332 generate_random_password = 1;
1333 snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random());
1334 CtdlSetPassword(random_password);
1335 cprintf("%d %s\n", CIT_OK, random_password);
1339 if (IsEmptyStr(new_pw)) {
1340 cprintf("%d Password unchanged.\n", CIT_OK);
1343 CtdlSetPassword(new_pw);
1344 cprintf("%d Password changed.\n", CIT_OK);
1350 * cmd_creu() - administratively create a new user account (do not log in to it)
1352 void cmd_creu(char *cmdbuf)
1358 struct ctdluser tmp;
1360 if (CtdlAccessCheck(ac_aide)) {
1364 extract_token(username, cmdbuf, 0, '|', sizeof username);
1365 extract_token(password, cmdbuf, 1, '|', sizeof password);
1366 ////username[25] = 0;
1370 len = cutuserkey(username);
1372 if (IsEmptyStr(username)) {
1373 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1377 a = create_user(username, len, 0);
1380 if (!IsEmptyStr(password)) {
1381 CtdlGetUserLock(&tmp, username);
1382 safestrncpy(tmp.password, password, sizeof(tmp.password));
1383 CtdlPutUserLock(&tmp);
1385 cprintf("%d User '%s' created %s.\n", CIT_OK, username,
1386 (!IsEmptyStr(password)) ? "and password set" :
1387 "with no password");
1389 } else if (a == ERROR + ALREADY_EXISTS) {
1390 cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username);
1392 } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
1393 cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
1394 ERROR + NO_SUCH_USER);
1397 cprintf("%d An error occurred creating the user account.\n", ERROR + INTERNAL_ERROR);
1404 * get user parameters
1406 void cmd_getu(char *cmdbuf)
1409 if (CtdlAccessCheck(ac_logged_in))
1412 CtdlGetUser(&CC->user, CC->curr_user);
1413 cprintf("%d 80|24|%d|\n",
1415 (CC->user.flags & US_USER_SET)
1420 * set user parameters
1422 void cmd_setu(char *new_parms)
1424 if (CtdlAccessCheck(ac_logged_in))
1427 if (num_parms(new_parms) < 3) {
1428 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1431 CtdlGetUserLock(&CC->user, CC->curr_user);
1432 CC->user.flags = CC->user.flags & (~US_USER_SET);
1433 CC->user.flags = CC->user.flags | (extract_int(new_parms, 2) & US_USER_SET);
1434 CtdlPutUserLock(&CC->user);
1435 cprintf("%d Ok\n", CIT_OK);
1439 * set last read pointer
1441 void cmd_slrp(char *new_ptr)
1445 visit original_vbuf;
1447 if (CtdlAccessCheck(ac_logged_in)) {
1451 if (!strncasecmp(new_ptr, "highest", 7)) {
1452 newlr = CC->room.QRhighest;
1454 newlr = atol(new_ptr);
1457 CtdlGetUserLock(&CC->user, CC->curr_user);
1459 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1460 memcpy(&original_vbuf, &vbuf, sizeof(visit));
1461 vbuf.v_lastseen = newlr;
1462 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1464 /* Only rewrite the record if it changed */
1465 if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
1466 || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
1467 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1470 CtdlPutUserLock(&CC->user);
1471 cprintf("%d %ld\n", CIT_OK, newlr);
1475 void cmd_seen(char *argbuf) {
1476 long target_msgnum = 0L;
1477 int target_setting = 0;
1479 if (CtdlAccessCheck(ac_logged_in)) {
1483 if (num_parms(argbuf) != 2) {
1484 cprintf("%d Invalid parameters\n", ERROR + ILLEGAL_VALUE);
1488 target_msgnum = extract_long(argbuf, 0);
1489 target_setting = extract_int(argbuf, 1);
1491 CtdlSetSeen(&target_msgnum, 1, target_setting,
1492 ctdlsetseen_seen, NULL, NULL);
1493 cprintf("%d OK\n", CIT_OK);
1497 void cmd_gtsn(char *argbuf) {
1500 if (CtdlAccessCheck(ac_logged_in)) {
1504 /* Learn about the user and room in question */
1505 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1507 cprintf("%d ", CIT_OK);
1508 client_write(vbuf.v_seen, strlen(vbuf.v_seen));
1509 client_write(HKEY("\n"));
1514 * API function for cmd_invt_kick() and anything else that needs to
1515 * invite or kick out a user to/from a room.
1517 * Set iuser to the name of the user, and op to 1=invite or 0=kick
1519 int CtdlInvtKick(char *iuser, int op) {
1520 struct ctdluser USscratch;
1524 if (CtdlGetUser(&USscratch, iuser) != 0) {
1528 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1530 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1531 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1534 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1535 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1537 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1539 /* post a message in Aide> saying what we just did */
1540 snprintf(bbb, sizeof bbb, "%s has been %s \"%s\" by %s.\n",
1542 ((op == 1) ? "invited to" : "kicked out of"),
1545 CtdlAideMessage(bbb,"User Admin Message");
1552 * INVT and KICK commands
1554 void cmd_invt_kick(char *iuser, int op) {
1557 * These commands are only allowed by aides, room aides,
1558 * and room namespace owners
1561 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1562 /* access granted */
1565 cprintf("%d Higher access or room ownership required.\n",
1566 ERROR + HIGHER_ACCESS_REQUIRED);
1570 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1572 cprintf("%d Can't add/remove users from this room.\n",
1577 if (CtdlInvtKick(iuser, op) != 0) {
1578 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1582 cprintf("%d %s %s %s.\n",
1584 ((op == 1) ? "invited to" : "kicked out of"),
1589 void cmd_invt(char *iuser) {cmd_invt_kick(iuser, 1);}
1590 void cmd_kick(char *iuser) {cmd_invt_kick(iuser, 0);}
1593 * Forget (Zap) the current room (API call)
1594 * Returns 0 on success
1596 int CtdlForgetThisRoom(void) {
1599 /* On some systems, Aides are not allowed to forget rooms */
1600 if (is_aide() && (config.c_aide_zap == 0)
1601 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1605 CtdlGetUserLock(&CC->user, CC->curr_user);
1606 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1608 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1609 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1611 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1612 CtdlPutUserLock(&CC->user);
1614 /* Return to the Lobby, so we don't end up in an undefined room */
1615 CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
1622 * forget (Zap) the current room
1624 void cmd_forg(char *argbuf)
1627 if (CtdlAccessCheck(ac_logged_in)) {
1631 if (CtdlForgetThisRoom() == 0) {
1632 cprintf("%d Ok\n", CIT_OK);
1635 cprintf("%d You may not forget this room.\n", ERROR + NOT_HERE);
1640 * Get Next Unregistered User
1642 void cmd_gnur(char *argbuf)
1644 struct cdbdata *cdbus;
1645 struct ctdluser usbuf;
1647 if (CtdlAccessCheck(ac_aide)) {
1651 if ((CitControl.MMflags & MM_VALID) == 0) {
1652 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1656 /* There are unvalidated users. Traverse the user database,
1657 * and return the first user we find that needs validation.
1659 cdb_rewind(CDB_USERS);
1660 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1661 memset(&usbuf, 0, sizeof(struct ctdluser));
1662 memcpy(&usbuf, cdbus->ptr,
1663 ((cdbus->len > sizeof(struct ctdluser)) ?
1664 sizeof(struct ctdluser) : cdbus->len));
1666 if ((usbuf.flags & US_NEEDVALID)
1667 && (usbuf.axlevel > AxDeleted)) {
1668 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1669 cdb_close_cursor(CDB_USERS);
1674 /* If we get to this point, there are no more unvalidated users.
1675 * Therefore we clear the "users need validation" flag.
1678 begin_critical_section(S_CONTROL);
1680 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1682 end_critical_section(S_CONTROL);
1683 cprintf("%d *** End of registration.\n", CIT_OK);
1692 void cmd_vali(char *v_args)
1696 struct ctdluser userbuf;
1698 extract_token(user, v_args, 0, '|', sizeof user);
1699 newax = extract_int(v_args, 1);
1701 if (CtdlAccessCheck(ac_aide) ||
1702 (newax > AxAideU) ||
1703 (newax < AxDeleted)) {
1707 if (CtdlGetUserLock(&userbuf, user) != 0) {
1708 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1712 userbuf.axlevel = newax;
1713 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1715 CtdlPutUserLock(&userbuf);
1717 /* If the access level was set to zero, delete the user */
1719 if (purge_user(user) == 0) {
1720 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1724 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1730 * Traverse the user file...
1732 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1735 struct ctdluser usbuf;
1736 struct cdbdata *cdbus;
1738 cdb_rewind(CDB_USERS);
1740 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1741 memset(&usbuf, 0, sizeof(struct ctdluser));
1742 memcpy(&usbuf, cdbus->ptr,
1743 ((cdbus->len > sizeof(struct ctdluser)) ?
1744 sizeof(struct ctdluser) : cdbus->len));
1746 (*CallBack) (&usbuf, in_data);
1752 * List one user (this works with cmd_list)
1754 void ListThisUser(struct ctdluser *usbuf, void *data)
1758 searchstring = (char *)data;
1759 if (bmstrcasestr(usbuf->fullname, searchstring) == NULL) {
1763 if (usbuf->axlevel > AxDeleted) {
1764 if ((CC->user.axlevel >= AxAideU)
1765 || ((usbuf->flags & US_UNLISTED) == 0)
1766 || ((CC->internal_pgm))) {
1767 cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
1771 (long)usbuf->lastcall,
1779 * List users (searchstring may be empty to list all users)
1781 void cmd_list(char *cmdbuf)
1783 char searchstring[256];
1784 extract_token(searchstring, cmdbuf, 0, '|', sizeof searchstring);
1785 striplt(searchstring);
1786 cprintf("%d \n", LISTING_FOLLOWS);
1787 ForEachUser(ListThisUser, (void *)searchstring );
1795 * assorted info we need to check at login
1797 void cmd_chek(char *argbuf)
1803 if (CtdlAccessCheck(ac_logged_in)) {
1807 CtdlGetUser(&CC->user, CC->curr_user); /* no lock is needed here */
1808 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1811 if (CC->user.axlevel >= AxAideU) {
1813 if (CitControl.MMflags & MM_VALID)
1817 /* check for mail */
1818 mail = InitialMailCheck();
1820 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1825 * check to see if a user exists
1827 void cmd_qusr(char *who)
1829 struct ctdluser usbuf;
1831 if (CtdlGetUser(&usbuf, who) == 0) {
1832 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1834 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1840 * Administrative Get User Parameters
1842 void cmd_agup(char *cmdbuf)
1844 struct ctdluser usbuf;
1845 char requested_user[128];
1847 if (CtdlAccessCheck(ac_aide)) {
1851 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1852 if (CtdlGetUser(&usbuf, requested_user) != 0) {
1853 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1856 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1863 (int) usbuf.axlevel,
1865 (long)usbuf.lastcall,
1872 * Administrative Set User Parameters
1874 void cmd_asup(char *cmdbuf)
1876 struct ctdluser usbuf;
1877 char requested_user[128];
1883 if (CtdlAccessCheck(ac_aide))
1886 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1887 if (CtdlGetUserLock(&usbuf, requested_user) != 0) {
1888 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1891 np = num_parms(cmdbuf);
1893 extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
1895 usbuf.flags = extract_int(cmdbuf, 2);
1897 usbuf.timescalled = extract_int(cmdbuf, 3);
1899 usbuf.posted = extract_int(cmdbuf, 4);
1901 newax = extract_int(cmdbuf, 5);
1902 if ((newax >= AxDeleted) && (newax <= AxAideU)) {
1903 usbuf.axlevel = newax;
1907 usbuf.lastcall = extract_long(cmdbuf, 7);
1910 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1912 CtdlPutUserLock(&usbuf);
1913 if (usbuf.axlevel == AxDeleted) {
1914 if (purge_user(requested_user) == 0) {
1920 snprintf(notify, SIZ,
1921 "User \"%s\" has been deleted by %s.\n",
1922 usbuf.fullname, CC->user.fullname);
1923 CtdlAideMessage(notify, "User Deletion Message");
1926 cprintf("%d Ok", CIT_OK);
1928 cprintf(" (%s deleted)", requested_user);
1935 * Count the number of new mail messages the user has
1939 int num_newmsgs = 0;
1941 num_newmsgs = CC->newmail;
1944 return (num_newmsgs);
1949 * Count the number of new mail messages the user has
1951 int InitialMailCheck()
1953 int num_newmsgs = 0;
1955 char mailboxname[ROOMNAMELEN];
1956 struct ctdlroom mailbox;
1958 struct cdbdata *cdbfr;
1959 long *msglist = NULL;
1962 CtdlMailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1963 if (CtdlGetRoom(&mailbox, mailboxname) != 0)
1965 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1967 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1969 if (cdbfr != NULL) {
1970 msglist = malloc(cdbfr->len);
1971 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1972 num_msgs = cdbfr->len / sizeof(long);
1976 for (a = 0; a < num_msgs; ++a) {
1977 if (msglist[a] > 0L) {
1978 if (msglist[a] > vbuf.v_lastseen) {
1983 if (msglist != NULL)
1986 return (num_newmsgs);
1992 * Set the preferred view for the current user/room combination
1994 void cmd_view(char *cmdbuf) {
1998 if (CtdlAccessCheck(ac_logged_in)) {
2002 requested_view = extract_int(cmdbuf, 0);
2004 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
2005 vbuf.v_view = requested_view;
2006 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
2008 cprintf("%d ok\n", CIT_OK);
2015 void cmd_renu(char *cmdbuf)
2018 char oldname[USERNAME_SIZE];
2019 char newname[USERNAME_SIZE];
2021 if (CtdlAccessCheck(ac_aide)) {
2025 extract_token(oldname, cmdbuf, 0, '|', sizeof oldname);
2026 extract_token(newname, cmdbuf, 1, '|', sizeof newname);
2028 retcode = rename_user(oldname, newname);
2031 cprintf("%d '%s' has been renamed to '%s'.\n", CIT_OK, oldname, newname);
2033 case RENAMEUSER_LOGGED_IN:
2034 cprintf("%d '%s' is currently logged in and cannot be renamed.\n",
2035 ERROR + ALREADY_LOGGED_IN , oldname);
2037 case RENAMEUSER_NOT_FOUND:
2038 cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, oldname);
2040 case RENAMEUSER_ALREADY_EXISTS:
2041 cprintf("%d A user named '%s' already exists.\n", ERROR + ALREADY_EXISTS, newname);
2045 cprintf("%d An unknown error occurred.\n", ERROR);
2050 /*****************************************************************************/
2051 /* MODULE INITIALIZATION STUFF */
2052 /*****************************************************************************/
2055 CTDL_MODULE_INIT(user_ops)
2058 CtdlRegisterProtoHook(cmd_user, "USER", "Autoconverted. TODO: document me.");
2059 CtdlRegisterProtoHook(cmd_pass, "PASS", "Autoconverted. TODO: document me.");
2060 CtdlRegisterProtoHook(cmd_creu, "CREU", "Autoconverted. TODO: document me.");
2061 CtdlRegisterProtoHook(cmd_setp, "SETP", "Autoconverted. TODO: document me.");
2062 CtdlRegisterProtoHook(cmd_getu, "GETU", "Autoconverted. TODO: document me.");
2063 CtdlRegisterProtoHook(cmd_setu, "SETU", "Autoconverted. TODO: document me.");
2064 CtdlRegisterProtoHook(cmd_slrp, "SLRP", "Autoconverted. TODO: document me.");
2065 CtdlRegisterProtoHook(cmd_invt, "INVT", "Autoconverted. TODO: document me.");
2066 CtdlRegisterProtoHook(cmd_kick, "KICK", "Autoconverted. TODO: document me.");
2067 CtdlRegisterProtoHook(cmd_forg, "FORG", "Autoconverted. TODO: document me.");
2068 CtdlRegisterProtoHook(cmd_gnur, "GNUR", "Autoconverted. TODO: document me.");
2069 CtdlRegisterProtoHook(cmd_vali, "VALI", "Autoconverted. TODO: document me.");
2070 CtdlRegisterProtoHook(cmd_list, "LIST", "Autoconverted. TODO: document me.");
2071 CtdlRegisterProtoHook(cmd_chek, "CHEK", "Autoconverted. TODO: document me.");
2072 CtdlRegisterProtoHook(cmd_qusr, "QUSR", "Autoconverted. TODO: document me.");
2073 CtdlRegisterProtoHook(cmd_agup, "AGUP", "Autoconverted. TODO: document me.");
2074 CtdlRegisterProtoHook(cmd_asup, "ASUP", "Autoconverted. TODO: document me.");
2075 CtdlRegisterProtoHook(cmd_seen, "SEEN", "Autoconverted. TODO: document me.");
2076 CtdlRegisterProtoHook(cmd_gtsn, "GTSN", "Autoconverted. TODO: document me.");
2077 CtdlRegisterProtoHook(cmd_view, "VIEW", "Autoconverted. TODO: document me.");
2078 CtdlRegisterProtoHook(cmd_renu, "RENU", "Autoconverted. TODO: document me.");
2079 CtdlRegisterProtoHook(cmd_newu, "NEWU", "Autoconverted. TODO: document me.");
2081 /* return our Subversion id for the Log */