4 * Server functions which perform operations on user objects.
17 #include <sys/types.h>
19 #ifdef HAVE_SYS_STAT_H
23 #if TIME_WITH_SYS_TIME
24 # include <sys/time.h>
28 # include <sys/time.h>
36 #include <libcitadel.h>
41 #include "sysdep_decls.h"
48 #include "citserver.h"
49 #include "citadel_dirs.h"
52 #include "citadel_ldap.h"
55 #include "ctdl_module.h"
57 ////#define CTDL_INLINE_USR INLINE
60 /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
61 int chkpwd_write_pipe[2];
62 int chkpwd_read_pipe[2];
67 * getuser() - retrieve named user into supplied buffer.
68 * returns 0 on success
70 int getuser(struct ctdluser *usbuf, char name[])
72 return CtdlGetUser(usbuf, name);
77 * CtdlGetUser() - retrieve named user into supplied buffer.
78 * returns 0 on success
80 int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len)
83 char usernamekey[USERNAME_SIZE];
84 struct cdbdata *cdbus;
87 memset(usbuf, 0, sizeof(struct ctdluser));
90 makeuserkey(usernamekey, name, len);
91 cdbus = cdb_fetch(CDB_USERS, usernamekey, strlen(usernamekey));
93 if (cdbus == NULL) { /* user not found */
97 memcpy(usbuf, cdbus->ptr,
98 ((cdbus->len > sizeof(struct ctdluser)) ?
99 sizeof(struct ctdluser) : cdbus->len));
107 int CtdlGetUser(struct ctdluser *usbuf, char *name)
109 return CtdlGetUserLen(usbuf, name, cutuserkey(name));
114 * CtdlGetUserLock() - same as getuser() but locks the record
116 int CtdlGetUserLock(struct ctdluser *usbuf, char *name)
120 retcode = CtdlGetUser(usbuf, name);
122 begin_critical_section(S_USERS);
129 * lgetuser() - same as getuser() but locks the record
131 int lgetuser(struct ctdluser *usbuf, char *name)
133 return CtdlGetUserLock(usbuf, name);
138 * CtdlPutUser() - write user buffer into the correct place on disk
140 void CtdlPutUser(struct ctdluser *usbuf)
142 char usernamekey[USERNAME_SIZE];
144 makeuserkey(usernamekey,
146 cutuserkey(usbuf->fullname));
148 usbuf->version = REV_LEVEL;
150 usernamekey, strlen(usernamekey),
151 usbuf, sizeof(struct ctdluser));
157 * putuser() - write user buffer into the correct place on disk
159 void putuser(struct ctdluser *usbuf)
166 * CtdlPutUserLock() - same as putuser() but locks the record
168 void CtdlPutUserLock(struct ctdluser *usbuf)
171 end_critical_section(S_USERS);
176 * lputuser() - same as putuser() but locks the record
178 void lputuser(struct ctdluser *usbuf)
180 CtdlPutUserLock(usbuf);
185 * rename_user() - this is tricky because the user's display name is the database key
187 * Returns 0 on success or nonzero if there was an error...
190 int rename_user(char *oldname, char *newname) {
191 int retcode = RENAMEUSER_OK;
192 struct ctdluser usbuf;
194 char oldnamekey[USERNAME_SIZE];
195 char newnamekey[USERNAME_SIZE];
197 /* Create the database keys... */
198 makeuserkey(oldnamekey, oldname, cutuserkey(oldname));
199 makeuserkey(newnamekey, newname, cutuserkey(newname));
201 /* Lock up and get going */
202 begin_critical_section(S_USERS);
204 /* We cannot rename a user who is currently logged in */
205 if (CtdlIsUserLoggedIn(oldname)) {
206 end_critical_section(S_USERS);
207 return RENAMEUSER_LOGGED_IN;
210 if (CtdlGetUser(&usbuf, newname) == 0) {
211 retcode = RENAMEUSER_ALREADY_EXISTS;
215 if (CtdlGetUser(&usbuf, oldname) != 0) {
216 retcode = RENAMEUSER_NOT_FOUND;
219 else { /* Sanity checks succeeded. Now rename the user. */
220 if (usbuf.usernum == 0)
222 CtdlLogPrintf (CTDL_DEBUG, "Can not rename user \"Citadel\".\n");
223 retcode = RENAMEUSER_NOT_FOUND;
225 CtdlLogPrintf(CTDL_DEBUG, "Renaming <%s> to <%s>\n", oldname, newname);
226 cdb_delete(CDB_USERS, oldnamekey, strlen(oldnamekey));
227 safestrncpy(usbuf.fullname, newname, sizeof usbuf.fullname);
229 cdb_store(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long),
230 usbuf.fullname, strlen(usbuf.fullname)+1 );
232 retcode = RENAMEUSER_OK;
238 end_critical_section(S_USERS);
245 * Index-generating function used by Ctdl[Get|Set]Relationship
247 int GenerateRelationshipIndex(char *IndexBuf,
259 TheIndex.iRoomID = RoomID;
260 TheIndex.iRoomGen = RoomGen;
261 TheIndex.iUserID = UserID;
263 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
264 return (sizeof(TheIndex));
270 * Back end for CtdlSetRelationship()
272 void put_visit(visit *newvisit)
277 memset (IndexBuf, 0, sizeof (IndexBuf));
278 /* Generate an index */
279 IndexLen = GenerateRelationshipIndex(IndexBuf,
282 newvisit->v_usernum);
284 /* Store the record */
285 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
286 newvisit, sizeof(visit)
294 * Define a relationship between a user and a room
296 void CtdlSetRelationship(visit *newvisit,
297 struct ctdluser *rel_user,
298 struct ctdlroom *rel_room)
302 /* We don't use these in Citadel because they're implicit by the
303 * index, but they must be present if the database is exported.
305 newvisit->v_roomnum = rel_room->QRnumber;
306 newvisit->v_roomgen = rel_room->QRgen;
307 newvisit->v_usernum = rel_user->usernum;
313 * Locate a relationship between a user and a room
315 void CtdlGetRelationship(visit *vbuf,
316 struct ctdluser *rel_user,
317 struct ctdlroom *rel_room)
322 struct cdbdata *cdbvisit;
324 /* Generate an index */
325 IndexLen = GenerateRelationshipIndex(IndexBuf,
330 /* Clear out the buffer */
331 memset(vbuf, 0, sizeof(visit));
333 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
334 if (cdbvisit != NULL) {
335 memcpy(vbuf, cdbvisit->ptr,
336 ((cdbvisit->len > sizeof(visit)) ?
337 sizeof(visit) : cdbvisit->len));
341 /* If this is the first time the user has seen this room,
342 * set the view to be the default for the room.
344 vbuf->v_view = rel_room->QRdefaultview;
347 /* Set v_seen if necessary */
348 if (vbuf->v_seen[0] == 0) {
349 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
354 void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
356 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
360 void MailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
362 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
367 * Is the user currently logged in an Aide?
371 if (CC->user.axlevel >= AxAideU)
379 * Is the user currently logged in an Aide *or* the room aide for this room?
381 int is_room_aide(void)
384 if (!CC->logged_in) {
388 if ((CC->user.axlevel >= AxAideU)
389 || (CC->room.QRroomaide == CC->user.usernum)) {
397 * CtdlGetUserByNumber() - get user by number
398 * returns 0 if user was found
400 * Note: fetching a user this way requires one additional database operation.
402 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number)
404 struct cdbdata *cdbun;
407 cdbun = cdb_fetch(CDB_USERSBYNUMBER, &number, sizeof(long));
409 CtdlLogPrintf(CTDL_INFO, "User %ld not found\n", number);
413 CtdlLogPrintf(CTDL_INFO, "User %ld maps to %s\n", number, cdbun->ptr);
414 r = CtdlGetUser(usbuf, cdbun->ptr);
420 * getuserbynumber() - get user by number
421 * returns 0 if user was found
423 * Note: fetching a user this way requires one additional database operation.
425 int getuserbynumber(struct ctdluser *usbuf, long number)
427 return CtdlGetUserByNumber(usbuf, number);
433 * Helper function for rebuild_usersbynumber()
435 void rebuild_ubn_for_user(struct ctdluser *usbuf, void *data) {
438 struct ubnlist *next;
439 char username[USERNAME_SIZE];
443 static struct ubnlist *u = NULL;
444 struct ubnlist *ptr = NULL;
446 /* Lazy programming here. Call this function as a ForEachUser backend
447 * in order to queue up the room names, or call it with a null user
448 * to make it do the processing.
451 ptr = (struct ubnlist *) malloc(sizeof (struct ubnlist));
452 if (ptr == NULL) return;
454 ptr->usernum = usbuf->usernum;
455 safestrncpy(ptr->username, usbuf->fullname, sizeof ptr->username);
462 CtdlLogPrintf(CTDL_DEBUG, "Rebuilding usersbynumber index %10ld : %s\n",
463 u->usernum, u->username);
464 cdb_store(CDB_USERSBYNUMBER, &u->usernum, sizeof(long), u->username, strlen(u->username)+1);
475 * Rebuild the users-by-number index
477 void rebuild_usersbynumber(void) {
478 cdb_trunc(CDB_USERSBYNUMBER); /* delete the old indices */
479 ForEachUser(rebuild_ubn_for_user, NULL); /* enumerate the users */
480 rebuild_ubn_for_user(NULL, NULL); /* and index them */
486 * getuserbyuid() - get user by system uid (for PAM mode authentication)
487 * returns 0 if user was found
489 * WARNING: don't use this function unless you absolutely have to. It does
490 * a sequential search and therefore is computationally expensive.
492 int getuserbyuid(struct ctdluser *usbuf, uid_t number)
494 struct cdbdata *cdbus;
496 cdb_rewind(CDB_USERS);
498 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
499 memset(usbuf, 0, sizeof(struct ctdluser));
500 memcpy(usbuf, cdbus->ptr,
501 ((cdbus->len > sizeof(struct ctdluser)) ?
502 sizeof(struct ctdluser) : cdbus->len));
504 if (usbuf->uid == number) {
505 cdb_close_cursor(CDB_USERS);
513 * Back end for cmd_user() and its ilk
515 * NOTE: "authname" should only be used if we are attempting to use the "master user" feature
517 int CtdlLoginExistingUser(char *authname, const char *trythisname)
523 CtdlLogPrintf(9, "CtdlLoginExistingUser(%s, %s)\n", authname, trythisname);
525 if ((CC->logged_in)) {
526 return login_already_logged_in;
529 if (trythisname == NULL) return login_not_found;
531 if (!strncasecmp(trythisname, "SYS_", 4))
533 CtdlLogPrintf(CTDL_DEBUG, "System user \"%s\" is not allowed to log in.\n", trythisname);
534 return login_not_found;
537 /* If a "master user" is defined, handle its authentication if specified */
539 if (strlen(config.c_master_user) > 0) if (strlen(config.c_master_pass) > 0) if (authname) {
540 if (!strcasecmp(authname, config.c_master_user)) {
545 /* Continue attempting user validation... */
546 safestrncpy(username, trythisname, sizeof (username));
548 len = cutuserkey(username);
550 if (IsEmptyStr(username)) {
551 return login_not_found;
554 if (config.c_auth_mode == AUTHMODE_HOST) {
559 struct passwd *tempPwdPtr;
562 CtdlLogPrintf(CTDL_DEBUG, "asking host about <%s>\n", username);
563 #ifdef HAVE_GETPWNAM_R
564 #ifdef SOLARIS_GETPWUID
565 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
566 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer);
567 #else // SOLARIS_GETPWUID
568 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
569 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
570 #endif // SOLARIS_GETPWUID
571 #else // HAVE_GETPWNAM_R
572 CtdlLogPrintf(CTDL_DEBUG, "SHOULD NEVER GET HERE!!!\n");
574 #endif // HAVE_GETPWNAM_R
575 if (tempPwdPtr == NULL) {
576 CtdlLogPrintf(CTDL_DEBUG, "no such user <%s>\n", username);
577 return login_not_found;
580 /* Locate the associated Citadel account.
581 * If not found, make one attempt to create it.
583 found_user = getuserbyuid(&CC->user, pd.pw_uid);
584 CtdlLogPrintf(CTDL_DEBUG, "found it: uid=%ld, gecos=%s here: %d\n",
585 (long)pd.pw_uid, pd.pw_gecos, found_user);
586 if (found_user != 0) {
587 len = cutuserkey(username);
588 create_user(username, len, 0);
589 found_user = getuserbyuid(&CC->user, pd.pw_uid);
595 else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
603 found_user = CtdlTryUserLDAP(username, ldap_dn, sizeof ldap_dn, ldap_cn, sizeof ldap_cn, &ldap_uid);
604 if (found_user != 0) {
605 return login_not_found;
608 found_user = getuserbyuid(&CC->user, ldap_uid);
609 if (found_user != 0) {
610 create_user(username, len, 0);
611 found_user = getuserbyuid(&CC->user, ldap_uid);
614 if (found_user == 0) {
615 if (CC->ldap_dn != NULL) free(CC->ldap_dn);
616 CC->ldap_dn = strdup(ldap_dn);
623 /* native auth mode */
625 struct recptypes *valid = NULL;
627 /* First, try to log in as if the supplied name is a display name */
628 found_user = CtdlGetUser(&CC->user, username);
630 /* If that didn't work, try to log in as if the supplied name
631 * is an e-mail address
633 if (found_user != 0) {
634 valid = validate_recipients(username, NULL, 0);
636 if (valid->num_local == 1) {
637 found_user = CtdlGetUser(&CC->user, valid->recp_local);
639 free_recipients(valid);
644 /* Did we find something? */
645 if (found_user == 0) {
646 if (((CC->nologin)) && (CC->user.axlevel < AxAideU)) {
647 return login_too_many_users;
649 safestrncpy(CC->curr_user, CC->user.fullname,
650 sizeof CC->curr_user);
654 return login_not_found;
662 void cmd_user(char *cmdbuf)
667 CtdlLogPrintf(CTDL_DEBUG, "cmd_user(%s)\n", cmdbuf);
668 extract_token(username, cmdbuf, 0, '|', sizeof username);
669 CtdlLogPrintf(CTDL_DEBUG, "username: %s\n", username);
671 CtdlLogPrintf(CTDL_DEBUG, "username: %s\n", username);
673 a = CtdlLoginExistingUser(NULL, username);
675 case login_already_logged_in:
676 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
678 case login_too_many_users:
680 "Too many users are already online "
682 ERROR + MAX_SESSIONS_EXCEEDED,
683 config.c_nodename, config.c_maxsessions);
686 cprintf("%d Password required for %s\n",
687 MORE_DATA, CC->curr_user);
689 case login_not_found:
690 cprintf("%d %s not found.\n", ERROR + NO_SUCH_USER, username);
693 cprintf("%d Internal error\n", ERROR + INTERNAL_ERROR);
700 * session startup code which is common to both cmd_pass() and cmd_newu()
705 CtdlLogPrintf(CTDL_NOTICE, "<%s> logged in\n", CC->curr_user);
707 CtdlGetUserLock(&CC->user, CC->curr_user);
708 ++(CC->user.timescalled);
709 CC->previous_login = CC->user.lastcall;
710 time(&CC->user.lastcall);
712 /* If this user's name is the name of the system administrator
713 * (as specified in setup), automatically assign access level 6.
715 if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
716 CC->user.axlevel = AxAideU;
719 /* If we're authenticating off the host system, automatically give
720 * root the highest level of access.
722 if (config.c_auth_mode == AUTHMODE_HOST) {
723 if (CC->user.uid == 0) {
724 CC->user.axlevel = AxAideU;
728 CtdlPutUserLock(&CC->user);
731 * Populate CC->cs_inet_email with a default address. This will be
732 * overwritten with the user's directory address, if one exists, when
733 * the vCard module's login hook runs.
735 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
736 CC->user.fullname, config.c_fqdn);
737 convert_spaces_to_underscores(CC->cs_inet_email);
739 /* Create any personal rooms required by the system.
740 * (Technically, MAILROOM should be there already, but just in case...)
742 CtdlCreateRoom(MAILROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
743 CtdlCreateRoom(SENTITEMS, 4, "", 0, 1, 0, VIEW_MAILBOX);
744 CtdlCreateRoom(USERTRASHROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
745 /* CtdlCreateRoom(USERDRAFTROOM, 4, "", 0, 1, 0, VIEW_MAILBOX); temporarily disabled for 7.60 */
747 /* Run any startup routines registered by loadable modules */
748 PerformSessionHooks(EVT_LOGIN);
750 /* Enter the lobby */
751 CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
755 void logged_in_response(void)
757 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
758 CIT_OK, CC->user.fullname, CC->user.axlevel,
759 CC->user.timescalled, CC->user.posted,
760 CC->user.flags, CC->user.usernum,
767 * misc things to be taken care of when a user is logged out
775 void CtdlUserLogout(void)
777 CitContext *CCC = CC; /* CachedCitContext - performance boost */
779 * If there is a download in progress, abort it.
781 if (CCC->download_fp != NULL) {
782 fclose(CCC->download_fp);
783 CCC->download_fp = NULL;
787 * If there is an upload in progress, abort it.
789 if (CCC->upload_fp != NULL) {
794 * If we were talking to a network node, we're not anymore...
796 if (!IsEmptyStr(CCC->net_node)) {
797 network_talking_to(CCC->net_node, NTT_REMOVE);
800 /* Run any hooks registered by modules... */
801 PerformSessionHooks(EVT_LOGOUT);
804 * Clear out some session data. Most likely, the CitContext for this
805 * session is about to get nuked when the session disconnects, but
806 * since it's possible to log in again without reconnecting, we cannot
807 * make that assumption.
809 strcpy(CCC->fake_username, "");
810 strcpy(CCC->fake_hostname, "");
811 strcpy(CCC->fake_roomname, "");
814 /* Check to see if the user was deleted whilst logged in and purge them if necessary */
815 if ((CCC->user.axlevel == AxDeleted) && (CCC->user.usernum))
816 purge_user(CCC->user.fullname);
818 /* Free any output buffers */
823 * Validate a password on the host unix system by talking to the chkpwd daemon
825 static int validpw(uid_t uid, const char *pass)
830 if (IsEmptyStr(pass)) {
831 CtdlLogPrintf(CTDL_DEBUG, "refusing to check empty password for uid=%d using chkpwd...\n", uid);
835 CtdlLogPrintf(CTDL_DEBUG, "Validating password for uid=%d using chkpwd...\n", uid);
837 begin_critical_section(S_CHKPWD);
838 rv = write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
839 rv = write(chkpwd_write_pipe[1], pass, 256);
840 rv = read(chkpwd_read_pipe[0], buf, 4);
841 end_critical_section(S_CHKPWD);
843 if (!strncmp(buf, "PASS", 4)) {
844 CtdlLogPrintf(CTDL_DEBUG, "...pass\n");
848 CtdlLogPrintf(CTDL_DEBUG, "...fail\n");
853 * Start up the chkpwd daemon so validpw() has something to talk to
855 void start_chkpwd_daemon(void) {
857 struct stat filestats;
860 CtdlLogPrintf(CTDL_DEBUG, "Starting chkpwd daemon for host authentication mode\n");
862 if ((stat(file_chkpwd, &filestats)==-1) ||
863 (filestats.st_size==0)){
864 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd, strerror(errno));
867 if (pipe(chkpwd_write_pipe) != 0) {
868 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
871 if (pipe(chkpwd_read_pipe) != 0) {
872 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
877 if (chkpwd_pid < 0) {
878 CtdlLogPrintf(CTDL_EMERG, "Unable to fork chkpwd daemon: %s\n", strerror(errno));
881 if (chkpwd_pid == 0) {
882 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
883 dup2(chkpwd_write_pipe[0], 0);
884 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
885 dup2(chkpwd_read_pipe[1], 1);
886 CtdlLogPrintf(CTDL_DEBUG, "Now closing stuff\n");
887 for (i=2; i<256; ++i) close(i);
888 CtdlLogPrintf(CTDL_DEBUG, "Now calling execl(%s)\n", file_chkpwd);
889 execl(file_chkpwd, file_chkpwd, NULL);
890 CtdlLogPrintf(CTDL_EMERG, "Unable to exec chkpwd daemon: %s\n", strerror(errno));
897 int CtdlTryPassword(const char *password, long len)
901 if ((CC->logged_in)) {
902 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: already logged in\n");
903 return pass_already_logged_in;
905 if (!strcmp(CC->curr_user, NLI)) {
906 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: no user selected\n");
909 if (CtdlGetUser(&CC->user, CC->curr_user)) {
910 CtdlLogPrintf(CTDL_ERR, "CtdlTryPassword: internal error\n");
911 return pass_internal_error;
913 if (password == NULL) {
914 CtdlLogPrintf(CTDL_INFO, "CtdlTryPassword: NULL password string supplied\n");
915 return pass_wrong_password;
920 code = strcmp(password, config.c_master_pass);
923 else if (config.c_auth_mode == AUTHMODE_HOST) {
927 if (validpw(CC->user.uid, password)) {
931 * sooper-seekrit hack: populate the password field in the
932 * citadel database with the password that the user typed,
933 * if it's correct. This allows most sites to convert from
934 * host auth to native auth if they want to. If you think
935 * this is a security hazard, comment it out.
938 CtdlGetUserLock(&CC->user, CC->curr_user);
939 safestrncpy(CC->user.password, password, sizeof CC->user.password);
940 CtdlPutUserLock(&CC->user);
943 * (sooper-seekrit hack ends here)
953 else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
957 if ((CC->ldap_dn) && (!CtdlTryPasswordLDAP(CC->ldap_dn, password))) {
968 /* native auth mode */
971 pw = (char*) malloc(len + 1);
972 memcpy(pw, password, len + 1);
974 strproc(CC->user.password);
975 code = strcasecmp(CC->user.password, pw);
977 strproc(CC->user.password);
978 code = strcasecmp(CC->user.password, pw);
986 CtdlLogPrintf(CTDL_WARNING, "Bad password specified for <%s>\n", CC->curr_user);
987 return pass_wrong_password;
992 void cmd_pass(char *buf)
998 memset(password, 0, sizeof(password));
999 len = extract_token(password, buf, 0, '|', sizeof password);
1000 a = CtdlTryPassword(password, len);
1003 case pass_already_logged_in:
1004 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1007 cprintf("%d You must send a name with USER first.\n",
1008 ERROR + USERNAME_REQUIRED);
1010 case pass_wrong_password:
1011 cprintf("%d Wrong password.\n", ERROR + PASSWORD_REQUIRED);
1014 logged_in_response();
1022 * Delete a user record *and* all of its related resources.
1024 int purge_user(char pname[])
1027 struct ctdluser usbuf;
1028 char usernamekey[USERNAME_SIZE];
1030 makeuserkey(usernamekey, pname, cutuserkey(pname));
1032 /* If the name is empty we can't find them in the DB any way so just return */
1033 if (IsEmptyStr(pname))
1034 return (ERROR + NO_SUCH_USER);
1036 if (CtdlGetUser(&usbuf, pname) != 0) {
1037 CtdlLogPrintf(CTDL_ERR, "Cannot purge user <%s> - not found\n", pname);
1038 return (ERROR + NO_SUCH_USER);
1040 /* Don't delete a user who is currently logged in. Instead, just
1041 * set the access level to 0, and let the account get swept up
1042 * during the next purge.
1044 if (CtdlIsUserLoggedInByNum(usbuf.usernum)) {
1045 CtdlLogPrintf(CTDL_WARNING, "User <%s> is logged in; not deleting.\n", pname);
1046 usbuf.axlevel = AxDeleted;
1047 CtdlPutUser(&usbuf);
1050 CtdlLogPrintf(CTDL_NOTICE, "Deleting user <%s>\n", pname);
1054 * This should all be wrapped in a S_USERS mutex.
1055 * Without the mutex the user could log in before we get to the next function
1056 * That would truly mess things up :-(
1057 * I would like to see the S_USERS start before the CtdlIsUserLoggedInByNum() above
1058 * and end after the user has been deleted from the database, below.
1059 * Question is should we enter the EVT_PURGEUSER whilst S_USERS is active?
1062 /* Perform any purge functions registered by server extensions */
1063 PerformUserHooks(&usbuf, EVT_PURGEUSER);
1065 /* delete any existing user/room relationships */
1066 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
1068 /* delete the users-by-number index record */
1069 cdb_delete(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long));
1071 /* delete the userlog entry */
1072 cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
1074 /* remove the user's bio file */
1082 /* remove the user's picture */
1094 int internal_create_user (const char *username, long len, struct ctdluser *usbuf, uid_t uid)
1096 if (!CtdlGetUserLen(usbuf, username, len)) {
1097 return (ERROR + ALREADY_EXISTS);
1100 /* Go ahead and initialize a new user record */
1101 memset(usbuf, 0, sizeof(struct ctdluser));
1102 safestrncpy(usbuf->fullname, username, sizeof usbuf->fullname);
1103 strcpy(usbuf->password, "");
1106 /* These are the default flags on new accounts */
1107 usbuf->flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
1109 usbuf->timescalled = 0;
1111 usbuf->axlevel = config.c_initax;
1112 usbuf->USscreenwidth = 80;
1113 usbuf->USscreenheight = 24;
1114 usbuf->lastcall = time(NULL);
1116 /* fetch a new user number */
1117 usbuf->usernum = get_new_user_number();
1119 /* add user to the database */
1121 cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1);
1129 * create_user() - back end processing to create a new user
1131 * Set 'newusername' to the desired account name.
1132 * Set 'become_user' to nonzero if this is self-service account creation and we want
1133 * to actually log in as the user we just created, otherwise set it to 0.
1135 int create_user(const char *newusername, long len, int become_user)
1137 struct ctdluser usbuf;
1138 struct ctdlroom qrbuf;
1140 char mailboxname[ROOMNAMELEN];
1146 safestrncpy(username, newusername, sizeof username);
1150 if (config.c_auth_mode == AUTHMODE_HOST) {
1152 /* host auth mode */
1155 struct passwd *tempPwdPtr;
1156 char pwdbuffer[SIZ];
1158 #ifdef HAVE_GETPWNAM_R
1159 #ifdef SOLARIS_GETPWUID
1160 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer));
1161 #else // SOLARIS_GETPWUID
1162 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
1163 #endif // SOLARIS_GETPWUID
1164 #else // HAVE_GETPWNAM_R
1166 #endif // HAVE_GETPWNAM_R
1167 if (tempPwdPtr != NULL) {
1168 extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
1170 if (IsEmptyStr (username))
1172 safestrncpy(username, pd.pw_name, sizeof username);
1173 len = cutuserkey(username);
1177 return (ERROR + NO_SUCH_USER);
1182 if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
1183 if (CtdlTryUserLDAP(username, NULL, 0, username, sizeof username, &uid) != 0) {
1184 return(ERROR + NO_SUCH_USER);
1187 #endif /* HAVE_LDAP */
1189 if ((retval = internal_create_user(username, len, &usbuf, uid)) != 0)
1193 * Give the user a private mailbox and a configuration room.
1194 * Make the latter an invisible system room.
1196 CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
1197 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_MAILBOX);
1199 CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
1200 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_BBS);
1201 if (CtdlGetRoomLock(&qrbuf, mailboxname) == 0) {
1202 qrbuf.QRflags2 |= QR2_SYSTEM;
1203 CtdlPutRoomLock(&qrbuf);
1206 /* Perform any create functions registered by server extensions */
1207 PerformUserHooks(&usbuf, EVT_NEWUSER);
1209 /* Everything below this line can be bypassed if administratively
1210 * creating a user, instead of doing self-service account creation
1214 /* Now become the user we just created */
1215 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
1216 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
1219 /* Check to make sure we're still who we think we are */
1220 if (CtdlGetUser(&CC->user, CC->curr_user)) {
1221 return (ERROR + INTERNAL_ERROR);
1226 "New user account <%s> has been created, from host %s [%s].\n",
1231 CtdlAideMessage(buf, "User Creation Notice");
1232 CtdlLogPrintf(CTDL_NOTICE, "New user <%s> created\n", username);
1239 * cmd_newu() - create a new user account and log in as that user
1241 void cmd_newu(char *cmdbuf)
1247 if (config.c_auth_mode != AUTHMODE_NATIVE) {
1248 cprintf("%d This system does not use native mode authentication.\n",
1253 if (config.c_disable_newu) {
1254 cprintf("%d Self-service user account creation "
1255 "is disabled on this system.\n", ERROR + NOT_HERE);
1259 if (CC->logged_in) {
1260 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1264 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
1265 ERROR + MAX_SESSIONS_EXCEEDED,
1266 config.c_nodename, config.c_maxsessions);
1268 extract_token(username, cmdbuf, 0, '|', sizeof username);
1270 len = cutuserkey(username);
1272 if (IsEmptyStr(username)) {
1273 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1277 if ((!strcasecmp(username, "bbs")) ||
1278 (!strcasecmp(username, "new")) ||
1279 (!strcasecmp(username, "."))) {
1280 cprintf("%d '%s' is an invalid login name.\n", ERROR + ILLEGAL_VALUE, username);
1284 a = create_user(username, len, 1);
1287 logged_in_response();
1288 } else if (a == ERROR + ALREADY_EXISTS) {
1289 cprintf("%d '%s' already exists.\n",
1290 ERROR + ALREADY_EXISTS, username);
1292 } else if (a == ERROR + INTERNAL_ERROR) {
1293 cprintf("%d Internal error - user record disappeared?\n",
1294 ERROR + INTERNAL_ERROR);
1297 cprintf("%d unknown error\n", ERROR + INTERNAL_ERROR);
1303 * set password - back end api code
1305 void CtdlSetPassword(char *new_pw)
1307 CtdlGetUserLock(&CC->user, CC->curr_user);
1308 safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
1309 CtdlPutUserLock(&CC->user);
1310 CtdlLogPrintf(CTDL_INFO, "Password changed for user <%s>\n", CC->curr_user);
1311 PerformSessionHooks(EVT_SETPASS);
1316 * set password - citadel protocol implementation
1318 void cmd_setp(char *new_pw)
1320 int generate_random_password = 0;
1322 if (CtdlAccessCheck(ac_logged_in)) {
1325 if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
1326 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR + NOT_HERE);
1329 if (CC->is_master) {
1330 cprintf("%d The master prefix password cannot be changed with this command.\n",
1335 if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
1336 char random_password[17];
1337 generate_random_password = 1;
1338 snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random());
1339 CtdlSetPassword(random_password);
1340 cprintf("%d %s\n", CIT_OK, random_password);
1344 if (IsEmptyStr(new_pw)) {
1345 cprintf("%d Password unchanged.\n", CIT_OK);
1348 CtdlSetPassword(new_pw);
1349 cprintf("%d Password changed.\n", CIT_OK);
1355 * cmd_creu() - administratively create a new user account (do not log in to it)
1357 void cmd_creu(char *cmdbuf)
1363 struct ctdluser tmp;
1365 if (CtdlAccessCheck(ac_aide)) {
1369 extract_token(username, cmdbuf, 0, '|', sizeof username);
1370 extract_token(password, cmdbuf, 1, '|', sizeof password);
1371 ////username[25] = 0;
1375 len = cutuserkey(username);
1377 if (IsEmptyStr(username)) {
1378 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1382 a = create_user(username, len, 0);
1385 if (!IsEmptyStr(password)) {
1386 CtdlGetUserLock(&tmp, username);
1387 safestrncpy(tmp.password, password, sizeof(tmp.password));
1388 CtdlPutUserLock(&tmp);
1390 cprintf("%d User '%s' created %s.\n", CIT_OK, username,
1391 (!IsEmptyStr(password)) ? "and password set" :
1392 "with no password");
1394 } else if (a == ERROR + ALREADY_EXISTS) {
1395 cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username);
1397 } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
1398 cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
1399 ERROR + NO_SUCH_USER);
1402 cprintf("%d An error occurred creating the user account.\n", ERROR + INTERNAL_ERROR);
1409 * get user parameters
1411 void cmd_getu(char *cmdbuf)
1414 if (CtdlAccessCheck(ac_logged_in))
1417 CtdlGetUser(&CC->user, CC->curr_user);
1418 cprintf("%d %d|%d|%d|\n",
1420 CC->user.USscreenwidth,
1421 CC->user.USscreenheight,
1422 (CC->user.flags & US_USER_SET)
1427 * set user parameters
1429 void cmd_setu(char *new_parms)
1431 if (CtdlAccessCheck(ac_logged_in))
1434 if (num_parms(new_parms) < 3) {
1435 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1438 CtdlGetUserLock(&CC->user, CC->curr_user);
1439 CC->user.USscreenwidth = extract_int(new_parms, 0);
1440 CC->user.USscreenheight = extract_int(new_parms, 1);
1441 CC->user.flags = CC->user.flags & (~US_USER_SET);
1442 CC->user.flags = CC->user.flags |
1443 (extract_int(new_parms, 2) & US_USER_SET);
1445 CtdlPutUserLock(&CC->user);
1446 cprintf("%d Ok\n", CIT_OK);
1450 * set last read pointer
1452 void cmd_slrp(char *new_ptr)
1456 visit original_vbuf;
1458 if (CtdlAccessCheck(ac_logged_in)) {
1462 if (!strncasecmp(new_ptr, "highest", 7)) {
1463 newlr = CC->room.QRhighest;
1465 newlr = atol(new_ptr);
1468 CtdlGetUserLock(&CC->user, CC->curr_user);
1470 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1471 memcpy(&original_vbuf, &vbuf, sizeof(visit));
1472 vbuf.v_lastseen = newlr;
1473 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1475 /* Only rewrite the record if it changed */
1476 if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
1477 || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
1478 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1481 CtdlPutUserLock(&CC->user);
1482 cprintf("%d %ld\n", CIT_OK, newlr);
1486 void cmd_seen(char *argbuf) {
1487 long target_msgnum = 0L;
1488 int target_setting = 0;
1490 if (CtdlAccessCheck(ac_logged_in)) {
1494 if (num_parms(argbuf) != 2) {
1495 cprintf("%d Invalid parameters\n", ERROR + ILLEGAL_VALUE);
1499 target_msgnum = extract_long(argbuf, 0);
1500 target_setting = extract_int(argbuf, 1);
1502 CtdlSetSeen(&target_msgnum, 1, target_setting,
1503 ctdlsetseen_seen, NULL, NULL);
1504 cprintf("%d OK\n", CIT_OK);
1508 void cmd_gtsn(char *argbuf) {
1511 if (CtdlAccessCheck(ac_logged_in)) {
1515 /* Learn about the user and room in question */
1516 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1518 cprintf("%d ", CIT_OK);
1519 client_write(vbuf.v_seen, strlen(vbuf.v_seen));
1520 client_write(HKEY("\n"));
1525 * API function for cmd_invt_kick() and anything else that needs to
1526 * invite or kick out a user to/from a room.
1528 * Set iuser to the name of the user, and op to 1=invite or 0=kick
1530 int CtdlInvtKick(char *iuser, int op) {
1531 struct ctdluser USscratch;
1535 if (CtdlGetUser(&USscratch, iuser) != 0) {
1539 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1541 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1542 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1545 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1546 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1548 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1550 /* post a message in Aide> saying what we just did */
1551 snprintf(bbb, sizeof bbb, "%s has been %s \"%s\" by %s.\n",
1553 ((op == 1) ? "invited to" : "kicked out of"),
1556 CtdlAideMessage(bbb,"User Admin Message");
1563 * INVT and KICK commands
1565 void cmd_invt_kick(char *iuser, int op) {
1568 * These commands are only allowed by aides, room aides,
1569 * and room namespace owners
1572 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1573 /* access granted */
1576 cprintf("%d Higher access or room ownership required.\n",
1577 ERROR + HIGHER_ACCESS_REQUIRED);
1581 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1583 cprintf("%d Can't add/remove users from this room.\n",
1588 if (CtdlInvtKick(iuser, op) != 0) {
1589 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1593 cprintf("%d %s %s %s.\n",
1595 ((op == 1) ? "invited to" : "kicked out of"),
1600 void cmd_invt(char *iuser) {cmd_invt_kick(iuser, 1);}
1601 void cmd_kick(char *iuser) {cmd_invt_kick(iuser, 0);}
1604 * Forget (Zap) the current room (API call)
1605 * Returns 0 on success
1607 int CtdlForgetThisRoom(void) {
1610 /* On some systems, Aides are not allowed to forget rooms */
1611 if (is_aide() && (config.c_aide_zap == 0)
1612 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1616 CtdlGetUserLock(&CC->user, CC->curr_user);
1617 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1619 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1620 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1622 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1623 CtdlPutUserLock(&CC->user);
1625 /* Return to the Lobby, so we don't end up in an undefined room */
1626 CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
1633 * forget (Zap) the current room
1635 void cmd_forg(char *argbuf)
1638 if (CtdlAccessCheck(ac_logged_in)) {
1642 if (CtdlForgetThisRoom() == 0) {
1643 cprintf("%d Ok\n", CIT_OK);
1646 cprintf("%d You may not forget this room.\n", ERROR + NOT_HERE);
1651 * Get Next Unregistered User
1653 void cmd_gnur(char *argbuf)
1655 struct cdbdata *cdbus;
1656 struct ctdluser usbuf;
1658 if (CtdlAccessCheck(ac_aide)) {
1662 if ((CitControl.MMflags & MM_VALID) == 0) {
1663 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1667 /* There are unvalidated users. Traverse the user database,
1668 * and return the first user we find that needs validation.
1670 cdb_rewind(CDB_USERS);
1671 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1672 memset(&usbuf, 0, sizeof(struct ctdluser));
1673 memcpy(&usbuf, cdbus->ptr,
1674 ((cdbus->len > sizeof(struct ctdluser)) ?
1675 sizeof(struct ctdluser) : cdbus->len));
1677 if ((usbuf.flags & US_NEEDVALID)
1678 && (usbuf.axlevel > AxDeleted)) {
1679 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1680 cdb_close_cursor(CDB_USERS);
1685 /* If we get to this point, there are no more unvalidated users.
1686 * Therefore we clear the "users need validation" flag.
1689 begin_critical_section(S_CONTROL);
1691 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1693 end_critical_section(S_CONTROL);
1694 cprintf("%d *** End of registration.\n", CIT_OK);
1703 void cmd_vali(char *v_args)
1707 struct ctdluser userbuf;
1709 extract_token(user, v_args, 0, '|', sizeof user);
1710 newax = extract_int(v_args, 1);
1712 if (CtdlAccessCheck(ac_aide) ||
1713 (newax > AxAideU) ||
1714 (newax < AxDeleted)) {
1718 if (CtdlGetUserLock(&userbuf, user) != 0) {
1719 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1723 userbuf.axlevel = newax;
1724 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1726 CtdlPutUserLock(&userbuf);
1728 /* If the access level was set to zero, delete the user */
1730 if (purge_user(user) == 0) {
1731 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1735 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1741 * Traverse the user file...
1743 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1746 struct ctdluser usbuf;
1747 struct cdbdata *cdbus;
1749 cdb_rewind(CDB_USERS);
1751 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1752 memset(&usbuf, 0, sizeof(struct ctdluser));
1753 memcpy(&usbuf, cdbus->ptr,
1754 ((cdbus->len > sizeof(struct ctdluser)) ?
1755 sizeof(struct ctdluser) : cdbus->len));
1757 (*CallBack) (&usbuf, in_data);
1763 * List one user (this works with cmd_list)
1765 void ListThisUser(struct ctdluser *usbuf, void *data)
1769 searchstring = (char *)data;
1770 if (bmstrcasestr(usbuf->fullname, searchstring) == NULL) {
1774 if (usbuf->axlevel > AxDeleted) {
1775 if ((CC->user.axlevel >= AxAideU)
1776 || ((usbuf->flags & US_UNLISTED) == 0)
1777 || ((CC->internal_pgm))) {
1778 cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
1782 (long)usbuf->lastcall,
1790 * List users (searchstring may be empty to list all users)
1792 void cmd_list(char *cmdbuf)
1794 char searchstring[256];
1795 extract_token(searchstring, cmdbuf, 0, '|', sizeof searchstring);
1796 striplt(searchstring);
1797 cprintf("%d \n", LISTING_FOLLOWS);
1798 ForEachUser(ListThisUser, (void *)searchstring );
1806 * assorted info we need to check at login
1808 void cmd_chek(char *argbuf)
1814 if (CtdlAccessCheck(ac_logged_in)) {
1818 CtdlGetUser(&CC->user, CC->curr_user); /* no lock is needed here */
1819 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1822 if (CC->user.axlevel >= AxAideU) {
1824 if (CitControl.MMflags & MM_VALID)
1828 /* check for mail */
1829 mail = InitialMailCheck();
1831 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1836 * check to see if a user exists
1838 void cmd_qusr(char *who)
1840 struct ctdluser usbuf;
1842 if (CtdlGetUser(&usbuf, who) == 0) {
1843 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1845 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1851 * Administrative Get User Parameters
1853 void cmd_agup(char *cmdbuf)
1855 struct ctdluser usbuf;
1856 char requested_user[128];
1858 if (CtdlAccessCheck(ac_aide)) {
1862 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1863 if (CtdlGetUser(&usbuf, requested_user) != 0) {
1864 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1867 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1874 (int) usbuf.axlevel,
1876 (long)usbuf.lastcall,
1883 * Administrative Set User Parameters
1885 void cmd_asup(char *cmdbuf)
1887 struct ctdluser usbuf;
1888 char requested_user[128];
1894 if (CtdlAccessCheck(ac_aide))
1897 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1898 if (CtdlGetUserLock(&usbuf, requested_user) != 0) {
1899 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1902 np = num_parms(cmdbuf);
1904 extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
1906 usbuf.flags = extract_int(cmdbuf, 2);
1908 usbuf.timescalled = extract_int(cmdbuf, 3);
1910 usbuf.posted = extract_int(cmdbuf, 4);
1912 newax = extract_int(cmdbuf, 5);
1913 if ((newax >= AxDeleted) && (newax <= AxAideU)) {
1914 usbuf.axlevel = newax;
1918 usbuf.lastcall = extract_long(cmdbuf, 7);
1921 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1923 CtdlPutUserLock(&usbuf);
1924 if (usbuf.axlevel == AxDeleted) {
1925 if (purge_user(requested_user) == 0) {
1931 snprintf(notify, SIZ,
1932 "User \"%s\" has been deleted by %s.\n",
1933 usbuf.fullname, CC->user.fullname);
1934 CtdlAideMessage(notify, "User Deletion Message");
1937 cprintf("%d Ok", CIT_OK);
1939 cprintf(" (%s deleted)", requested_user);
1946 * Count the number of new mail messages the user has
1950 int num_newmsgs = 0;
1952 num_newmsgs = CC->newmail;
1955 return (num_newmsgs);
1960 * Count the number of new mail messages the user has
1962 int InitialMailCheck()
1964 int num_newmsgs = 0;
1966 char mailboxname[ROOMNAMELEN];
1967 struct ctdlroom mailbox;
1969 struct cdbdata *cdbfr;
1970 long *msglist = NULL;
1973 CtdlMailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1974 if (CtdlGetRoom(&mailbox, mailboxname) != 0)
1976 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1978 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1980 if (cdbfr != NULL) {
1981 msglist = malloc(cdbfr->len);
1982 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1983 num_msgs = cdbfr->len / sizeof(long);
1987 for (a = 0; a < num_msgs; ++a) {
1988 if (msglist[a] > 0L) {
1989 if (msglist[a] > vbuf.v_lastseen) {
1994 if (msglist != NULL)
1997 return (num_newmsgs);
2003 * Set the preferred view for the current user/room combination
2005 void cmd_view(char *cmdbuf) {
2009 if (CtdlAccessCheck(ac_logged_in)) {
2013 requested_view = extract_int(cmdbuf, 0);
2015 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
2016 vbuf.v_view = requested_view;
2017 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
2019 cprintf("%d ok\n", CIT_OK);
2026 void cmd_renu(char *cmdbuf)
2029 char oldname[USERNAME_SIZE];
2030 char newname[USERNAME_SIZE];
2032 if (CtdlAccessCheck(ac_aide)) {
2036 extract_token(oldname, cmdbuf, 0, '|', sizeof oldname);
2037 extract_token(newname, cmdbuf, 1, '|', sizeof newname);
2039 retcode = rename_user(oldname, newname);
2042 cprintf("%d '%s' has been renamed to '%s'.\n", CIT_OK, oldname, newname);
2044 case RENAMEUSER_LOGGED_IN:
2045 cprintf("%d '%s' is currently logged in and cannot be renamed.\n",
2046 ERROR + ALREADY_LOGGED_IN , oldname);
2048 case RENAMEUSER_NOT_FOUND:
2049 cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, oldname);
2051 case RENAMEUSER_ALREADY_EXISTS:
2052 cprintf("%d A user named '%s' already exists.\n", ERROR + ALREADY_EXISTS, newname);
2056 cprintf("%d An unknown error occurred.\n", ERROR);
2061 /*****************************************************************************/
2062 /* MODULE INITIALIZATION STUFF */
2063 /*****************************************************************************/
2066 CTDL_MODULE_INIT(user_ops)
2069 CtdlRegisterProtoHook(cmd_user, "USER", "Autoconverted. TODO: document me.");
2070 CtdlRegisterProtoHook(cmd_pass, "PASS", "Autoconverted. TODO: document me.");
2071 CtdlRegisterProtoHook(cmd_creu, "CREU", "Autoconverted. TODO: document me.");
2072 CtdlRegisterProtoHook(cmd_setp, "SETP", "Autoconverted. TODO: document me.");
2073 CtdlRegisterProtoHook(cmd_getu, "GETU", "Autoconverted. TODO: document me.");
2074 CtdlRegisterProtoHook(cmd_setu, "SETU", "Autoconverted. TODO: document me.");
2075 CtdlRegisterProtoHook(cmd_slrp, "SLRP", "Autoconverted. TODO: document me.");
2076 CtdlRegisterProtoHook(cmd_invt, "INVT", "Autoconverted. TODO: document me.");
2077 CtdlRegisterProtoHook(cmd_kick, "KICK", "Autoconverted. TODO: document me.");
2078 CtdlRegisterProtoHook(cmd_forg, "FORG", "Autoconverted. TODO: document me.");
2079 CtdlRegisterProtoHook(cmd_gnur, "GNUR", "Autoconverted. TODO: document me.");
2080 CtdlRegisterProtoHook(cmd_vali, "VALI", "Autoconverted. TODO: document me.");
2081 CtdlRegisterProtoHook(cmd_list, "LIST", "Autoconverted. TODO: document me.");
2082 CtdlRegisterProtoHook(cmd_chek, "CHEK", "Autoconverted. TODO: document me.");
2083 CtdlRegisterProtoHook(cmd_qusr, "QUSR", "Autoconverted. TODO: document me.");
2084 CtdlRegisterProtoHook(cmd_agup, "AGUP", "Autoconverted. TODO: document me.");
2085 CtdlRegisterProtoHook(cmd_asup, "ASUP", "Autoconverted. TODO: document me.");
2086 CtdlRegisterProtoHook(cmd_seen, "SEEN", "Autoconverted. TODO: document me.");
2087 CtdlRegisterProtoHook(cmd_gtsn, "GTSN", "Autoconverted. TODO: document me.");
2088 CtdlRegisterProtoHook(cmd_view, "VIEW", "Autoconverted. TODO: document me.");
2089 CtdlRegisterProtoHook(cmd_renu, "RENU", "Autoconverted. TODO: document me.");
2090 CtdlRegisterProtoHook(cmd_newu, "NEWU", "Autoconverted. TODO: document me.");
2092 /* return our Subversion id for the Log */