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->USscreenwidth = 80;
1110 usbuf->USscreenheight = 24;
1111 usbuf->lastcall = time(NULL);
1113 /* fetch a new user number */
1114 usbuf->usernum = get_new_user_number();
1116 /* add user to the database */
1118 cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1);
1126 * create_user() - back end processing to create a new user
1128 * Set 'newusername' to the desired account name.
1129 * Set 'become_user' to nonzero if this is self-service account creation and we want
1130 * to actually log in as the user we just created, otherwise set it to 0.
1132 int create_user(const char *newusername, long len, int become_user)
1134 struct ctdluser usbuf;
1135 struct ctdlroom qrbuf;
1137 char mailboxname[ROOMNAMELEN];
1143 safestrncpy(username, newusername, sizeof username);
1147 if (config.c_auth_mode == AUTHMODE_HOST) {
1149 /* host auth mode */
1152 struct passwd *tempPwdPtr;
1153 char pwdbuffer[SIZ];
1155 #ifdef HAVE_GETPWNAM_R
1156 #ifdef SOLARIS_GETPWUID
1157 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer));
1158 #else // SOLARIS_GETPWUID
1159 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
1160 #endif // SOLARIS_GETPWUID
1161 #else // HAVE_GETPWNAM_R
1163 #endif // HAVE_GETPWNAM_R
1164 if (tempPwdPtr != NULL) {
1165 extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
1167 if (IsEmptyStr (username))
1169 safestrncpy(username, pd.pw_name, sizeof username);
1170 len = cutuserkey(username);
1174 return (ERROR + NO_SUCH_USER);
1179 if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
1180 if (CtdlTryUserLDAP(username, NULL, 0, username, sizeof username, &uid) != 0) {
1181 return(ERROR + NO_SUCH_USER);
1184 #endif /* HAVE_LDAP */
1186 if ((retval = internal_create_user(username, len, &usbuf, uid)) != 0)
1190 * Give the user a private mailbox and a configuration room.
1191 * Make the latter an invisible system room.
1193 CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
1194 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_MAILBOX);
1196 CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
1197 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_BBS);
1198 if (CtdlGetRoomLock(&qrbuf, mailboxname) == 0) {
1199 qrbuf.QRflags2 |= QR2_SYSTEM;
1200 CtdlPutRoomLock(&qrbuf);
1203 /* Perform any create functions registered by server extensions */
1204 PerformUserHooks(&usbuf, EVT_NEWUSER);
1206 /* Everything below this line can be bypassed if administratively
1207 * creating a user, instead of doing self-service account creation
1211 /* Now become the user we just created */
1212 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
1213 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
1216 /* Check to make sure we're still who we think we are */
1217 if (CtdlGetUser(&CC->user, CC->curr_user)) {
1218 return (ERROR + INTERNAL_ERROR);
1223 "New user account <%s> has been created, from host %s [%s].\n",
1228 CtdlAideMessage(buf, "User Creation Notice");
1229 CtdlLogPrintf(CTDL_NOTICE, "New user <%s> created\n", username);
1236 * cmd_newu() - create a new user account and log in as that user
1238 void cmd_newu(char *cmdbuf)
1244 if (config.c_auth_mode != AUTHMODE_NATIVE) {
1245 cprintf("%d This system does not use native mode authentication.\n",
1250 if (config.c_disable_newu) {
1251 cprintf("%d Self-service user account creation "
1252 "is disabled on this system.\n", ERROR + NOT_HERE);
1256 if (CC->logged_in) {
1257 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1261 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
1262 ERROR + MAX_SESSIONS_EXCEEDED,
1263 config.c_nodename, config.c_maxsessions);
1265 extract_token(username, cmdbuf, 0, '|', sizeof username);
1267 len = cutuserkey(username);
1269 if (IsEmptyStr(username)) {
1270 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1274 if ((!strcasecmp(username, "bbs")) ||
1275 (!strcasecmp(username, "new")) ||
1276 (!strcasecmp(username, "."))) {
1277 cprintf("%d '%s' is an invalid login name.\n", ERROR + ILLEGAL_VALUE, username);
1281 a = create_user(username, len, 1);
1284 logged_in_response();
1285 } else if (a == ERROR + ALREADY_EXISTS) {
1286 cprintf("%d '%s' already exists.\n",
1287 ERROR + ALREADY_EXISTS, username);
1289 } else if (a == ERROR + INTERNAL_ERROR) {
1290 cprintf("%d Internal error - user record disappeared?\n",
1291 ERROR + INTERNAL_ERROR);
1294 cprintf("%d unknown error\n", ERROR + INTERNAL_ERROR);
1300 * set password - back end api code
1302 void CtdlSetPassword(char *new_pw)
1304 CtdlGetUserLock(&CC->user, CC->curr_user);
1305 safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
1306 CtdlPutUserLock(&CC->user);
1307 CtdlLogPrintf(CTDL_INFO, "Password changed for user <%s>\n", CC->curr_user);
1308 PerformSessionHooks(EVT_SETPASS);
1313 * set password - citadel protocol implementation
1315 void cmd_setp(char *new_pw)
1317 int generate_random_password = 0;
1319 if (CtdlAccessCheck(ac_logged_in)) {
1322 if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
1323 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR + NOT_HERE);
1326 if (CC->is_master) {
1327 cprintf("%d The master prefix password cannot be changed with this command.\n",
1332 if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
1333 char random_password[17];
1334 generate_random_password = 1;
1335 snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random());
1336 CtdlSetPassword(random_password);
1337 cprintf("%d %s\n", CIT_OK, random_password);
1341 if (IsEmptyStr(new_pw)) {
1342 cprintf("%d Password unchanged.\n", CIT_OK);
1345 CtdlSetPassword(new_pw);
1346 cprintf("%d Password changed.\n", CIT_OK);
1352 * cmd_creu() - administratively create a new user account (do not log in to it)
1354 void cmd_creu(char *cmdbuf)
1360 struct ctdluser tmp;
1362 if (CtdlAccessCheck(ac_aide)) {
1366 extract_token(username, cmdbuf, 0, '|', sizeof username);
1367 extract_token(password, cmdbuf, 1, '|', sizeof password);
1368 ////username[25] = 0;
1372 len = cutuserkey(username);
1374 if (IsEmptyStr(username)) {
1375 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1379 a = create_user(username, len, 0);
1382 if (!IsEmptyStr(password)) {
1383 CtdlGetUserLock(&tmp, username);
1384 safestrncpy(tmp.password, password, sizeof(tmp.password));
1385 CtdlPutUserLock(&tmp);
1387 cprintf("%d User '%s' created %s.\n", CIT_OK, username,
1388 (!IsEmptyStr(password)) ? "and password set" :
1389 "with no password");
1391 } else if (a == ERROR + ALREADY_EXISTS) {
1392 cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username);
1394 } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
1395 cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
1396 ERROR + NO_SUCH_USER);
1399 cprintf("%d An error occurred creating the user account.\n", ERROR + INTERNAL_ERROR);
1406 * get user parameters
1408 void cmd_getu(char *cmdbuf)
1411 if (CtdlAccessCheck(ac_logged_in))
1414 CtdlGetUser(&CC->user, CC->curr_user);
1415 cprintf("%d %d|%d|%d|\n",
1417 CC->user.USscreenwidth,
1418 CC->user.USscreenheight,
1419 (CC->user.flags & US_USER_SET)
1424 * set user parameters
1426 void cmd_setu(char *new_parms)
1428 if (CtdlAccessCheck(ac_logged_in))
1431 if (num_parms(new_parms) < 3) {
1432 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1435 CtdlGetUserLock(&CC->user, CC->curr_user);
1436 CC->user.USscreenwidth = extract_int(new_parms, 0);
1437 CC->user.USscreenheight = extract_int(new_parms, 1);
1438 CC->user.flags = CC->user.flags & (~US_USER_SET);
1439 CC->user.flags = CC->user.flags |
1440 (extract_int(new_parms, 2) & US_USER_SET);
1442 CtdlPutUserLock(&CC->user);
1443 cprintf("%d Ok\n", CIT_OK);
1447 * set last read pointer
1449 void cmd_slrp(char *new_ptr)
1453 visit original_vbuf;
1455 if (CtdlAccessCheck(ac_logged_in)) {
1459 if (!strncasecmp(new_ptr, "highest", 7)) {
1460 newlr = CC->room.QRhighest;
1462 newlr = atol(new_ptr);
1465 CtdlGetUserLock(&CC->user, CC->curr_user);
1467 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1468 memcpy(&original_vbuf, &vbuf, sizeof(visit));
1469 vbuf.v_lastseen = newlr;
1470 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1472 /* Only rewrite the record if it changed */
1473 if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
1474 || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
1475 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1478 CtdlPutUserLock(&CC->user);
1479 cprintf("%d %ld\n", CIT_OK, newlr);
1483 void cmd_seen(char *argbuf) {
1484 long target_msgnum = 0L;
1485 int target_setting = 0;
1487 if (CtdlAccessCheck(ac_logged_in)) {
1491 if (num_parms(argbuf) != 2) {
1492 cprintf("%d Invalid parameters\n", ERROR + ILLEGAL_VALUE);
1496 target_msgnum = extract_long(argbuf, 0);
1497 target_setting = extract_int(argbuf, 1);
1499 CtdlSetSeen(&target_msgnum, 1, target_setting,
1500 ctdlsetseen_seen, NULL, NULL);
1501 cprintf("%d OK\n", CIT_OK);
1505 void cmd_gtsn(char *argbuf) {
1508 if (CtdlAccessCheck(ac_logged_in)) {
1512 /* Learn about the user and room in question */
1513 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1515 cprintf("%d ", CIT_OK);
1516 client_write(vbuf.v_seen, strlen(vbuf.v_seen));
1517 client_write(HKEY("\n"));
1522 * API function for cmd_invt_kick() and anything else that needs to
1523 * invite or kick out a user to/from a room.
1525 * Set iuser to the name of the user, and op to 1=invite or 0=kick
1527 int CtdlInvtKick(char *iuser, int op) {
1528 struct ctdluser USscratch;
1532 if (CtdlGetUser(&USscratch, iuser) != 0) {
1536 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1538 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1539 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1542 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1543 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1545 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1547 /* post a message in Aide> saying what we just did */
1548 snprintf(bbb, sizeof bbb, "%s has been %s \"%s\" by %s.\n",
1550 ((op == 1) ? "invited to" : "kicked out of"),
1553 CtdlAideMessage(bbb,"User Admin Message");
1560 * INVT and KICK commands
1562 void cmd_invt_kick(char *iuser, int op) {
1565 * These commands are only allowed by aides, room aides,
1566 * and room namespace owners
1569 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1570 /* access granted */
1573 cprintf("%d Higher access or room ownership required.\n",
1574 ERROR + HIGHER_ACCESS_REQUIRED);
1578 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1580 cprintf("%d Can't add/remove users from this room.\n",
1585 if (CtdlInvtKick(iuser, op) != 0) {
1586 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1590 cprintf("%d %s %s %s.\n",
1592 ((op == 1) ? "invited to" : "kicked out of"),
1597 void cmd_invt(char *iuser) {cmd_invt_kick(iuser, 1);}
1598 void cmd_kick(char *iuser) {cmd_invt_kick(iuser, 0);}
1601 * Forget (Zap) the current room (API call)
1602 * Returns 0 on success
1604 int CtdlForgetThisRoom(void) {
1607 /* On some systems, Aides are not allowed to forget rooms */
1608 if (is_aide() && (config.c_aide_zap == 0)
1609 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1613 CtdlGetUserLock(&CC->user, CC->curr_user);
1614 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1616 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1617 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1619 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1620 CtdlPutUserLock(&CC->user);
1622 /* Return to the Lobby, so we don't end up in an undefined room */
1623 CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
1630 * forget (Zap) the current room
1632 void cmd_forg(char *argbuf)
1635 if (CtdlAccessCheck(ac_logged_in)) {
1639 if (CtdlForgetThisRoom() == 0) {
1640 cprintf("%d Ok\n", CIT_OK);
1643 cprintf("%d You may not forget this room.\n", ERROR + NOT_HERE);
1648 * Get Next Unregistered User
1650 void cmd_gnur(char *argbuf)
1652 struct cdbdata *cdbus;
1653 struct ctdluser usbuf;
1655 if (CtdlAccessCheck(ac_aide)) {
1659 if ((CitControl.MMflags & MM_VALID) == 0) {
1660 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1664 /* There are unvalidated users. Traverse the user database,
1665 * and return the first user we find that needs validation.
1667 cdb_rewind(CDB_USERS);
1668 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1669 memset(&usbuf, 0, sizeof(struct ctdluser));
1670 memcpy(&usbuf, cdbus->ptr,
1671 ((cdbus->len > sizeof(struct ctdluser)) ?
1672 sizeof(struct ctdluser) : cdbus->len));
1674 if ((usbuf.flags & US_NEEDVALID)
1675 && (usbuf.axlevel > AxDeleted)) {
1676 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1677 cdb_close_cursor(CDB_USERS);
1682 /* If we get to this point, there are no more unvalidated users.
1683 * Therefore we clear the "users need validation" flag.
1686 begin_critical_section(S_CONTROL);
1688 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1690 end_critical_section(S_CONTROL);
1691 cprintf("%d *** End of registration.\n", CIT_OK);
1700 void cmd_vali(char *v_args)
1704 struct ctdluser userbuf;
1706 extract_token(user, v_args, 0, '|', sizeof user);
1707 newax = extract_int(v_args, 1);
1709 if (CtdlAccessCheck(ac_aide) ||
1710 (newax > AxAideU) ||
1711 (newax < AxDeleted)) {
1715 if (CtdlGetUserLock(&userbuf, user) != 0) {
1716 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1720 userbuf.axlevel = newax;
1721 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1723 CtdlPutUserLock(&userbuf);
1725 /* If the access level was set to zero, delete the user */
1727 if (purge_user(user) == 0) {
1728 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1732 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1738 * Traverse the user file...
1740 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1743 struct ctdluser usbuf;
1744 struct cdbdata *cdbus;
1746 cdb_rewind(CDB_USERS);
1748 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1749 memset(&usbuf, 0, sizeof(struct ctdluser));
1750 memcpy(&usbuf, cdbus->ptr,
1751 ((cdbus->len > sizeof(struct ctdluser)) ?
1752 sizeof(struct ctdluser) : cdbus->len));
1754 (*CallBack) (&usbuf, in_data);
1760 * List one user (this works with cmd_list)
1762 void ListThisUser(struct ctdluser *usbuf, void *data)
1766 searchstring = (char *)data;
1767 if (bmstrcasestr(usbuf->fullname, searchstring) == NULL) {
1771 if (usbuf->axlevel > AxDeleted) {
1772 if ((CC->user.axlevel >= AxAideU)
1773 || ((usbuf->flags & US_UNLISTED) == 0)
1774 || ((CC->internal_pgm))) {
1775 cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
1779 (long)usbuf->lastcall,
1787 * List users (searchstring may be empty to list all users)
1789 void cmd_list(char *cmdbuf)
1791 char searchstring[256];
1792 extract_token(searchstring, cmdbuf, 0, '|', sizeof searchstring);
1793 striplt(searchstring);
1794 cprintf("%d \n", LISTING_FOLLOWS);
1795 ForEachUser(ListThisUser, (void *)searchstring );
1803 * assorted info we need to check at login
1805 void cmd_chek(char *argbuf)
1811 if (CtdlAccessCheck(ac_logged_in)) {
1815 CtdlGetUser(&CC->user, CC->curr_user); /* no lock is needed here */
1816 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1819 if (CC->user.axlevel >= AxAideU) {
1821 if (CitControl.MMflags & MM_VALID)
1825 /* check for mail */
1826 mail = InitialMailCheck();
1828 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1833 * check to see if a user exists
1835 void cmd_qusr(char *who)
1837 struct ctdluser usbuf;
1839 if (CtdlGetUser(&usbuf, who) == 0) {
1840 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1842 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1848 * Administrative Get User Parameters
1850 void cmd_agup(char *cmdbuf)
1852 struct ctdluser usbuf;
1853 char requested_user[128];
1855 if (CtdlAccessCheck(ac_aide)) {
1859 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1860 if (CtdlGetUser(&usbuf, requested_user) != 0) {
1861 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1864 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1871 (int) usbuf.axlevel,
1873 (long)usbuf.lastcall,
1880 * Administrative Set User Parameters
1882 void cmd_asup(char *cmdbuf)
1884 struct ctdluser usbuf;
1885 char requested_user[128];
1891 if (CtdlAccessCheck(ac_aide))
1894 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1895 if (CtdlGetUserLock(&usbuf, requested_user) != 0) {
1896 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1899 np = num_parms(cmdbuf);
1901 extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
1903 usbuf.flags = extract_int(cmdbuf, 2);
1905 usbuf.timescalled = extract_int(cmdbuf, 3);
1907 usbuf.posted = extract_int(cmdbuf, 4);
1909 newax = extract_int(cmdbuf, 5);
1910 if ((newax >= AxDeleted) && (newax <= AxAideU)) {
1911 usbuf.axlevel = newax;
1915 usbuf.lastcall = extract_long(cmdbuf, 7);
1918 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1920 CtdlPutUserLock(&usbuf);
1921 if (usbuf.axlevel == AxDeleted) {
1922 if (purge_user(requested_user) == 0) {
1928 snprintf(notify, SIZ,
1929 "User \"%s\" has been deleted by %s.\n",
1930 usbuf.fullname, CC->user.fullname);
1931 CtdlAideMessage(notify, "User Deletion Message");
1934 cprintf("%d Ok", CIT_OK);
1936 cprintf(" (%s deleted)", requested_user);
1943 * Count the number of new mail messages the user has
1947 int num_newmsgs = 0;
1949 num_newmsgs = CC->newmail;
1952 return (num_newmsgs);
1957 * Count the number of new mail messages the user has
1959 int InitialMailCheck()
1961 int num_newmsgs = 0;
1963 char mailboxname[ROOMNAMELEN];
1964 struct ctdlroom mailbox;
1966 struct cdbdata *cdbfr;
1967 long *msglist = NULL;
1970 CtdlMailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1971 if (CtdlGetRoom(&mailbox, mailboxname) != 0)
1973 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1975 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1977 if (cdbfr != NULL) {
1978 msglist = malloc(cdbfr->len);
1979 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1980 num_msgs = cdbfr->len / sizeof(long);
1984 for (a = 0; a < num_msgs; ++a) {
1985 if (msglist[a] > 0L) {
1986 if (msglist[a] > vbuf.v_lastseen) {
1991 if (msglist != NULL)
1994 return (num_newmsgs);
2000 * Set the preferred view for the current user/room combination
2002 void cmd_view(char *cmdbuf) {
2006 if (CtdlAccessCheck(ac_logged_in)) {
2010 requested_view = extract_int(cmdbuf, 0);
2012 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
2013 vbuf.v_view = requested_view;
2014 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
2016 cprintf("%d ok\n", CIT_OK);
2023 void cmd_renu(char *cmdbuf)
2026 char oldname[USERNAME_SIZE];
2027 char newname[USERNAME_SIZE];
2029 if (CtdlAccessCheck(ac_aide)) {
2033 extract_token(oldname, cmdbuf, 0, '|', sizeof oldname);
2034 extract_token(newname, cmdbuf, 1, '|', sizeof newname);
2036 retcode = rename_user(oldname, newname);
2039 cprintf("%d '%s' has been renamed to '%s'.\n", CIT_OK, oldname, newname);
2041 case RENAMEUSER_LOGGED_IN:
2042 cprintf("%d '%s' is currently logged in and cannot be renamed.\n",
2043 ERROR + ALREADY_LOGGED_IN , oldname);
2045 case RENAMEUSER_NOT_FOUND:
2046 cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, oldname);
2048 case RENAMEUSER_ALREADY_EXISTS:
2049 cprintf("%d A user named '%s' already exists.\n", ERROR + ALREADY_EXISTS, newname);
2053 cprintf("%d An unknown error occurred.\n", ERROR);
2058 /*****************************************************************************/
2059 /* MODULE INITIALIZATION STUFF */
2060 /*****************************************************************************/
2063 CTDL_MODULE_INIT(user_ops)
2066 CtdlRegisterProtoHook(cmd_user, "USER", "Autoconverted. TODO: document me.");
2067 CtdlRegisterProtoHook(cmd_pass, "PASS", "Autoconverted. TODO: document me.");
2068 CtdlRegisterProtoHook(cmd_creu, "CREU", "Autoconverted. TODO: document me.");
2069 CtdlRegisterProtoHook(cmd_setp, "SETP", "Autoconverted. TODO: document me.");
2070 CtdlRegisterProtoHook(cmd_getu, "GETU", "Autoconverted. TODO: document me.");
2071 CtdlRegisterProtoHook(cmd_setu, "SETU", "Autoconverted. TODO: document me.");
2072 CtdlRegisterProtoHook(cmd_slrp, "SLRP", "Autoconverted. TODO: document me.");
2073 CtdlRegisterProtoHook(cmd_invt, "INVT", "Autoconverted. TODO: document me.");
2074 CtdlRegisterProtoHook(cmd_kick, "KICK", "Autoconverted. TODO: document me.");
2075 CtdlRegisterProtoHook(cmd_forg, "FORG", "Autoconverted. TODO: document me.");
2076 CtdlRegisterProtoHook(cmd_gnur, "GNUR", "Autoconverted. TODO: document me.");
2077 CtdlRegisterProtoHook(cmd_vali, "VALI", "Autoconverted. TODO: document me.");
2078 CtdlRegisterProtoHook(cmd_list, "LIST", "Autoconverted. TODO: document me.");
2079 CtdlRegisterProtoHook(cmd_chek, "CHEK", "Autoconverted. TODO: document me.");
2080 CtdlRegisterProtoHook(cmd_qusr, "QUSR", "Autoconverted. TODO: document me.");
2081 CtdlRegisterProtoHook(cmd_agup, "AGUP", "Autoconverted. TODO: document me.");
2082 CtdlRegisterProtoHook(cmd_asup, "ASUP", "Autoconverted. TODO: document me.");
2083 CtdlRegisterProtoHook(cmd_seen, "SEEN", "Autoconverted. TODO: document me.");
2084 CtdlRegisterProtoHook(cmd_gtsn, "GTSN", "Autoconverted. TODO: document me.");
2085 CtdlRegisterProtoHook(cmd_view, "VIEW", "Autoconverted. TODO: document me.");
2086 CtdlRegisterProtoHook(cmd_renu, "RENU", "Autoconverted. TODO: document me.");
2087 CtdlRegisterProtoHook(cmd_newu, "NEWU", "Autoconverted. TODO: document me.");
2089 /* return our Subversion id for the Log */