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>
42 #include "sysdep_decls.h"
49 #include "citserver.h"
50 #include "citadel_dirs.h"
54 /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
55 int chkpwd_write_pipe
[2];
56 int chkpwd_read_pipe
[2];
59 * makeuserkey() - convert a username into the format used as a database key
60 * (it's just the username converted into lower case)
62 INLINE
void makeuserkey(char *key
, char *username
) {
65 len
= strlen(username
);
66 if (len
>= USERNAME_SIZE
)
68 CtdlLogPrintf (CTDL_EMERG
, "Username to long: %s", username
);
70 len
= USERNAME_SIZE
- 1;
71 username
[USERNAME_SIZE
- 1]='\0';
73 for (i
=0; i
<=len
; ++i
) {
74 key
[i
] = tolower(username
[i
]);
80 * getuser() - retrieve named user into supplied buffer.
81 * returns 0 on success
83 int getuser(struct ctdluser
*usbuf
, char name
[])
86 char usernamekey
[USERNAME_SIZE
];
87 struct cdbdata
*cdbus
;
90 memset(usbuf
, 0, sizeof(struct ctdluser
));
93 makeuserkey(usernamekey
, name
);
94 cdbus
= cdb_fetch(CDB_USERS
, usernamekey
, strlen(usernamekey
));
96 if (cdbus
== NULL
) { /* user not found */
100 memcpy(usbuf
, cdbus
->ptr
,
101 ((cdbus
->len
> sizeof(struct ctdluser
)) ?
102 sizeof(struct ctdluser
) : cdbus
->len
));
111 * lgetuser() - same as getuser() but locks the record
113 int lgetuser(struct ctdluser
*usbuf
, char *name
)
117 retcode
= getuser(usbuf
, name
);
119 begin_critical_section(S_USERS
);
126 * putuser() - write user buffer into the correct place on disk
128 void putuser(struct ctdluser
*usbuf
)
130 char usernamekey
[USERNAME_SIZE
];
132 makeuserkey(usernamekey
, usbuf
->fullname
);
134 usbuf
->version
= REV_LEVEL
;
136 usernamekey
, strlen(usernamekey
),
137 usbuf
, sizeof(struct ctdluser
));
143 * lputuser() - same as putuser() but locks the record
145 void lputuser(struct ctdluser
*usbuf
)
148 end_critical_section(S_USERS
);
153 * rename_user() - this is tricky because the user's display name is the database key
155 * Returns 0 on success or nonzero if there was an error...
158 int rename_user(char *oldname
, char *newname
) {
159 struct CitContext
*cptr
;
160 int retcode
= RENAMEUSER_OK
;
161 struct ctdluser usbuf
;
163 char oldnamekey
[USERNAME_SIZE
];
164 char newnamekey
[USERNAME_SIZE
];
166 /* We cannot rename a user who is currently logged in */
167 for (cptr
= ContextList
; cptr
!= NULL
; cptr
= cptr
->next
) {
168 if (!strcasecmp(cptr
->user
.fullname
, oldname
)) {
169 return(RENAMEUSER_LOGGED_IN
);
173 /* Create the database keys... */
174 makeuserkey(oldnamekey
, oldname
);
175 makeuserkey(newnamekey
, newname
);
177 /* Lock up and get going */
178 begin_critical_section(S_USERS
);
180 if (getuser(&usbuf
, newname
) == 0) {
181 retcode
= RENAMEUSER_ALREADY_EXISTS
;
185 if (getuser(&usbuf
, oldname
) != 0) {
186 retcode
= RENAMEUSER_NOT_FOUND
;
189 else { /* Sanity checks succeeded. Now rename the user. */
190 if (usbuf
.usernum
== 0)
192 CtdlLogPrintf (CTDL_DEBUG
, "Can not rename user \"Citadel\".\n");
193 retcode
= RENAMEUSER_NOT_FOUND
;
195 CtdlLogPrintf(CTDL_DEBUG
, "Renaming <%s> to <%s>\n", oldname
, newname
);
196 cdb_delete(CDB_USERS
, oldnamekey
, strlen(oldnamekey
));
197 safestrncpy(usbuf
.fullname
, newname
, sizeof usbuf
.fullname
);
199 cdb_store(CDB_USERSBYNUMBER
, &usbuf
.usernum
, sizeof(long),
200 usbuf
.fullname
, strlen(usbuf
.fullname
)+1 );
202 retcode
= RENAMEUSER_OK
;
208 end_critical_section(S_USERS
);
215 * Index-generating function used by Ctdl[Get|Set]Relationship
217 int GenerateRelationshipIndex(char *IndexBuf
,
229 TheIndex
.iRoomID
= RoomID
;
230 TheIndex
.iRoomGen
= RoomGen
;
231 TheIndex
.iUserID
= UserID
;
233 memcpy(IndexBuf
, &TheIndex
, sizeof(TheIndex
));
234 return (sizeof(TheIndex
));
240 * Back end for CtdlSetRelationship()
242 void put_visit(struct visit
*newvisit
)
247 memset (IndexBuf
, 0, sizeof (IndexBuf
));
248 /* Generate an index */
249 IndexLen
= GenerateRelationshipIndex(IndexBuf
,
252 newvisit
->v_usernum
);
254 /* Store the record */
255 cdb_store(CDB_VISIT
, IndexBuf
, IndexLen
,
256 newvisit
, sizeof(struct visit
)
264 * Define a relationship between a user and a room
266 void CtdlSetRelationship(struct visit
*newvisit
,
267 struct ctdluser
*rel_user
,
268 struct ctdlroom
*rel_room
)
272 /* We don't use these in Citadel because they're implicit by the
273 * index, but they must be present if the database is exported.
275 newvisit
->v_roomnum
= rel_room
->QRnumber
;
276 newvisit
->v_roomgen
= rel_room
->QRgen
;
277 newvisit
->v_usernum
= rel_user
->usernum
;
283 * Locate a relationship between a user and a room
285 void CtdlGetRelationship(struct visit
*vbuf
,
286 struct ctdluser
*rel_user
,
287 struct ctdlroom
*rel_room
)
292 struct cdbdata
*cdbvisit
;
294 /* Generate an index */
295 IndexLen
= GenerateRelationshipIndex(IndexBuf
,
300 /* Clear out the buffer */
301 memset(vbuf
, 0, sizeof(struct visit
));
303 cdbvisit
= cdb_fetch(CDB_VISIT
, IndexBuf
, IndexLen
);
304 if (cdbvisit
!= NULL
) {
305 memcpy(vbuf
, cdbvisit
->ptr
,
306 ((cdbvisit
->len
> sizeof(struct visit
)) ?
307 sizeof(struct visit
) : cdbvisit
->len
));
311 /* If this is the first time the user has seen this room,
312 * set the view to be the default for the room.
314 vbuf
->v_view
= rel_room
->QRdefaultview
;
317 /* Set v_seen if necessary */
318 if (vbuf
->v_seen
[0] == 0) {
319 snprintf(vbuf
->v_seen
, sizeof vbuf
->v_seen
, "*:%ld", vbuf
->v_lastseen
);
324 void MailboxName(char *buf
, size_t n
, const struct ctdluser
*who
, const char *prefix
)
326 snprintf(buf
, n
, "%010ld.%s", who
->usernum
, prefix
);
331 * Is the user currently logged in an Aide?
335 if (CC
->user
.axlevel
>= 6)
343 * Is the user currently logged in an Aide *or* the room aide for this room?
345 int is_room_aide(void)
348 if (!CC
->logged_in
) {
352 if ((CC
->user
.axlevel
>= 6)
353 || (CC
->room
.QRroomaide
== CC
->user
.usernum
)) {
361 * getuserbynumber() - get user by number
362 * returns 0 if user was found
364 * Note: fetching a user this way requires one additional database operation.
366 int getuserbynumber(struct ctdluser
*usbuf
, long number
)
368 struct cdbdata
*cdbun
;
371 cdbun
= cdb_fetch(CDB_USERSBYNUMBER
, &number
, sizeof(long));
373 CtdlLogPrintf(CTDL_INFO
, "User %ld not found\n", number
);
377 CtdlLogPrintf(CTDL_INFO
, "User %ld maps to %s\n", number
, cdbun
->ptr
);
378 r
= getuser(usbuf
, cdbun
->ptr
);
386 * Helper function for rebuild_usersbynumber()
388 void rebuild_ubn_for_user(struct ctdluser
*usbuf
, void *data
) {
391 struct ubnlist
*next
;
392 char username
[USERNAME_SIZE
];
396 static struct ubnlist
*u
= NULL
;
397 struct ubnlist
*ptr
= NULL
;
399 /* Lazy programming here. Call this function as a ForEachUser backend
400 * in order to queue up the room names, or call it with a null user
401 * to make it do the processing.
404 ptr
= (struct ubnlist
*) malloc(sizeof (struct ubnlist
));
405 if (ptr
== NULL
) return;
407 ptr
->usernum
= usbuf
->usernum
;
408 safestrncpy(ptr
->username
, usbuf
->fullname
, sizeof ptr
->username
);
415 CtdlLogPrintf(CTDL_DEBUG
, "Rebuilding usersbynumber index %10ld : %s\n",
416 u
->usernum
, u
->username
);
417 cdb_store(CDB_USERSBYNUMBER
, &u
->usernum
, sizeof(long), u
->username
, strlen(u
->username
)+1);
428 * Rebuild the users-by-number index
430 void rebuild_usersbynumber(void) {
431 cdb_trunc(CDB_USERSBYNUMBER
); /* delete the old indices */
432 ForEachUser(rebuild_ubn_for_user
, NULL
); /* enumerate the users */
433 rebuild_ubn_for_user(NULL
, NULL
); /* and index them */
439 * getuserbyuid() - get user by system uid (for PAM mode authentication)
440 * returns 0 if user was found
442 * WARNING: don't use this function unless you absolutely have to. It does
443 * a sequential search and therefore is computationally expensive.
445 int getuserbyuid(struct ctdluser
*usbuf
, uid_t number
)
447 struct cdbdata
*cdbus
;
449 cdb_rewind(CDB_USERS
);
451 while (cdbus
= cdb_next_item(CDB_USERS
), cdbus
!= NULL
) {
452 memset(usbuf
, 0, sizeof(struct ctdluser
));
453 memcpy(usbuf
, cdbus
->ptr
,
454 ((cdbus
->len
> sizeof(struct ctdluser
)) ?
455 sizeof(struct ctdluser
) : cdbus
->len
));
457 if (usbuf
->uid
== number
) {
458 cdb_close_cursor(CDB_USERS
);
466 * Back end for cmd_user() and its ilk
468 * NOTE: "authname" should only be used if we are attempting to use the "master user" feature
470 int CtdlLoginExistingUser(char *authname
, char *trythisname
)
475 CtdlLogPrintf(9, "CtdlLoginExistingUser(%s, %s)\n", authname
, trythisname
);
477 if ((CC
->logged_in
)) {
478 return login_already_logged_in
;
481 if (trythisname
== NULL
) return login_not_found
;
483 if (!strncasecmp(trythisname
, "SYS_", 4))
485 CtdlLogPrintf(CTDL_DEBUG
, "System user \"%s\" is not allowed to log in.\n", trythisname
);
486 return login_not_found
;
489 /* If a "master user" is defined, handle its authentication if specified */
491 if (strlen(config
.c_master_user
) > 0) if (strlen(config
.c_master_pass
) > 0) if (authname
) {
492 if (!strcasecmp(authname
, config
.c_master_user
)) {
497 /* Continue attempting user validation... */
498 safestrncpy(username
, trythisname
, USERNAME_SIZE
);
501 if (IsEmptyStr(username
)) {
502 return login_not_found
;
505 if (config
.c_auth_mode
== AUTHMODE_HOST
) {
510 struct passwd
*tempPwdPtr
;
513 CtdlLogPrintf(CTDL_DEBUG
, "asking host about <%s>\n", username
);
514 #ifdef HAVE_GETPWNAM_R
515 #ifdef SOLARIS_GETPWUID
516 CtdlLogPrintf(CTDL_DEBUG
, "Calling getpwnam_r()\n");
517 tempPwdPtr
= getpwnam_r(username
, &pd
, pwdbuffer
, sizeof pwdbuffer
);
518 #else // SOLARIS_GETPWUID
519 CtdlLogPrintf(CTDL_DEBUG
, "Calling getpwnam_r()\n");
520 getpwnam_r(username
, &pd
, pwdbuffer
, sizeof pwdbuffer
, &tempPwdPtr
);
521 #endif // SOLARIS_GETPWUID
522 #else // HAVE_GETPWNAM_R
523 CtdlLogPrintf(CTDL_DEBUG
, "SHOULD NEVER GET HERE!!!\n");
525 #endif // HAVE_GETPWNAM_R
526 if (tempPwdPtr
== NULL
) {
527 CtdlLogPrintf(CTDL_DEBUG
, "no such user <%s>\n", username
);
528 return login_not_found
;
531 /* Locate the associated Citadel account.
532 * If not found, make one attempt to create it.
534 found_user
= getuserbyuid(&CC
->user
, pd
.pw_uid
);
535 CtdlLogPrintf(CTDL_DEBUG
, "found it: uid=%ld, gecos=%s here: %d\n",
536 (long)pd
.pw_uid
, pd
.pw_gecos
, found_user
);
537 if (found_user
!= 0) {
538 create_user(username
, 0);
539 found_user
= getuserbyuid(&CC
->user
, pd
.pw_uid
);
545 /* native auth mode */
547 struct recptypes
*valid
= NULL
;
549 /* First, try to log in as if the supplied name is a display name */
550 found_user
= getuser(&CC
->user
, username
);
552 /* If that didn't work, try to log in as if the supplied name
553 * is an e-mail address
555 if (found_user
!= 0) {
556 valid
= validate_recipients(username
, NULL
, 0);
558 if (valid
->num_local
== 1) {
559 found_user
= getuser(&CC
->user
, valid
->recp_local
);
561 free_recipients(valid
);
566 /* Did we find something? */
567 if (found_user
== 0) {
568 if (((CC
->nologin
)) && (CC
->user
.axlevel
< 6)) {
569 return login_too_many_users
;
571 safestrncpy(CC
->curr_user
, CC
->user
.fullname
,
572 sizeof CC
->curr_user
);
576 return login_not_found
;
584 void cmd_user(char *cmdbuf
)
589 extract_token(username
, cmdbuf
, 0, '|', sizeof username
);
592 a
= CtdlLoginExistingUser(NULL
, username
);
594 case login_already_logged_in
:
595 cprintf("%d Already logged in.\n", ERROR
+ ALREADY_LOGGED_IN
);
597 case login_too_many_users
:
599 "Too many users are already online "
601 ERROR
+ MAX_SESSIONS_EXCEEDED
,
602 config
.c_nodename
, config
.c_maxsessions
);
605 cprintf("%d Password required for %s\n",
606 MORE_DATA
, CC
->curr_user
);
608 case login_not_found
:
609 cprintf("%d %s not found.\n", ERROR
+ NO_SUCH_USER
, username
);
612 cprintf("%d Internal error\n", ERROR
+ INTERNAL_ERROR
);
619 * session startup code which is common to both cmd_pass() and cmd_newu()
624 CtdlLogPrintf(CTDL_NOTICE
, "<%s> logged in\n", CC
->curr_user
);
626 lgetuser(&CC
->user
, CC
->curr_user
);
627 ++(CC
->user
.timescalled
);
628 CC
->previous_login
= CC
->user
.lastcall
;
629 time(&CC
->user
.lastcall
);
631 /* If this user's name is the name of the system administrator
632 * (as specified in setup), automatically assign access level 6.
634 if (!strcasecmp(CC
->user
.fullname
, config
.c_sysadm
)) {
635 CC
->user
.axlevel
= 6;
638 /* If we're authenticating off the host system, automatically give
639 * root the highest level of access.
641 if (config
.c_auth_mode
== AUTHMODE_HOST
) {
642 if (CC
->user
.uid
== 0) {
643 CC
->user
.axlevel
= 6;
650 * Populate CC->cs_inet_email with a default address. This will be
651 * overwritten with the user's directory address, if one exists, when
652 * the vCard module's login hook runs.
654 snprintf(CC
->cs_inet_email
, sizeof CC
->cs_inet_email
, "%s@%s",
655 CC
->user
.fullname
, config
.c_fqdn
);
656 convert_spaces_to_underscores(CC
->cs_inet_email
);
658 /* Create any personal rooms required by the system.
659 * (Technically, MAILROOM should be there already, but just in case...)
661 create_room(MAILROOM
, 4, "", 0, 1, 0, VIEW_MAILBOX
);
662 create_room(SENTITEMS
, 4, "", 0, 1, 0, VIEW_MAILBOX
);
663 create_room(USERTRASHROOM
, 4, "", 0, 1, 0, VIEW_MAILBOX
);
665 /* Run any startup routines registered by loadable modules */
666 PerformSessionHooks(EVT_LOGIN
);
668 /* Enter the lobby */
669 usergoto(config
.c_baseroom
, 0, 0, NULL
, NULL
);
673 void logged_in_response(void)
675 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
676 CIT_OK
, CC
->user
.fullname
, CC
->user
.axlevel
,
677 CC
->user
.timescalled
, CC
->user
.posted
,
678 CC
->user
.flags
, CC
->user
.usernum
,
685 * misc things to be taken care of when a user is logged out
689 struct CitContext
*CCC
= CC
; /* CachedCitContext - performance boost */
691 * If there is a download in progress, abort it.
693 if (CCC
->download_fp
!= NULL
) {
694 fclose(CCC
->download_fp
);
695 CCC
->download_fp
= NULL
;
699 * If there is an upload in progress, abort it.
701 if (CCC
->upload_fp
!= NULL
) {
706 * If we were talking to a network node, we're not anymore...
708 if (!IsEmptyStr(CCC
->net_node
)) {
709 network_talking_to(CCC
->net_node
, NTT_REMOVE
);
712 /* Run any hooks registered by modules... */
713 PerformSessionHooks(EVT_LOGOUT
);
716 * Clear out some session data. Most likely, the CitContext for this
717 * session is about to get nuked when the session disconnects, but
718 * since it's possible to log in again without reconnecting, we cannot
719 * make that assumption.
721 strcpy(CCC
->fake_username
, "");
722 strcpy(CCC
->fake_hostname
, "");
723 strcpy(CCC
->fake_roomname
, "");
726 /* Check to see if the user was deleted whilst logged in and purge them if necessary */
727 if ((CCC
->user
.axlevel
== 0) && (CCC
->user
.usernum
))
728 purge_user(CCC
->user
.fullname
);
730 /* Free any output buffers */
731 if (CCC
->output_buffer
!= NULL
) {
737 * Validate a password on the host unix system by talking to the chkpwd daemon
739 static int validpw(uid_t uid
, const char *pass
)
743 if (IsEmptyStr(pass
)) {
744 CtdlLogPrintf(CTDL_DEBUG
, "refusing to check empty password for uid=%d using chkpwd...\n", uid
);
748 CtdlLogPrintf(CTDL_DEBUG
, "Validating password for uid=%d using chkpwd...\n", uid
);
750 begin_critical_section(S_CHKPWD
);
751 write(chkpwd_write_pipe
[1], &uid
, sizeof(uid_t
));
752 write(chkpwd_write_pipe
[1], pass
, 256);
753 read(chkpwd_read_pipe
[0], buf
, 4);
754 end_critical_section(S_CHKPWD
);
756 if (!strncmp(buf
, "PASS", 4)) {
757 CtdlLogPrintf(CTDL_DEBUG
, "...pass\n");
761 CtdlLogPrintf(CTDL_DEBUG
, "...fail\n");
766 * Start up the chkpwd daemon so validpw() has something to talk to
768 void start_chkpwd_daemon(void) {
770 struct stat filestats
;
773 CtdlLogPrintf(CTDL_DEBUG
, "Starting chkpwd daemon for host authentication mode\n");
775 if ((stat(file_chkpwd
, &filestats
)==-1) ||
776 (filestats
.st_size
==0)){
777 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd
, strerror(errno
));
780 if (pipe(chkpwd_write_pipe
) != 0) {
781 CtdlLogPrintf(CTDL_EMERG
, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno
));
784 if (pipe(chkpwd_read_pipe
) != 0) {
785 CtdlLogPrintf(CTDL_EMERG
, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno
));
790 if (chkpwd_pid
< 0) {
791 CtdlLogPrintf(CTDL_EMERG
, "Unable to fork chkpwd daemon: %s\n", strerror(errno
));
794 if (chkpwd_pid
== 0) {
795 CtdlLogPrintf(CTDL_DEBUG
, "Now calling dup2() write\n");
796 dup2(chkpwd_write_pipe
[0], 0);
797 CtdlLogPrintf(CTDL_DEBUG
, "Now calling dup2() write\n");
798 dup2(chkpwd_read_pipe
[1], 1);
799 CtdlLogPrintf(CTDL_DEBUG
, "Now closing stuff\n");
800 for (i
=2; i
<256; ++i
) close(i
);
801 CtdlLogPrintf(CTDL_DEBUG
, "Now calling execl(%s)\n", file_chkpwd
);
802 execl(file_chkpwd
, file_chkpwd
, NULL
);
803 CtdlLogPrintf(CTDL_EMERG
, "Unable to exec chkpwd daemon: %s\n", strerror(errno
));
810 int CtdlTryPassword(char *password
)
814 if ((CC
->logged_in
)) {
815 CtdlLogPrintf(CTDL_WARNING
, "CtdlTryPassword: already logged in\n");
816 return pass_already_logged_in
;
818 if (!strcmp(CC
->curr_user
, NLI
)) {
819 CtdlLogPrintf(CTDL_WARNING
, "CtdlTryPassword: no user selected\n");
822 if (getuser(&CC
->user
, CC
->curr_user
)) {
823 CtdlLogPrintf(CTDL_ERR
, "CtdlTryPassword: internal error\n");
824 return pass_internal_error
;
826 if (password
== NULL
) {
827 CtdlLogPrintf(CTDL_INFO
, "CtdlTryPassword: NULL password string supplied\n");
828 return pass_wrong_password
;
833 code
= strcmp(password
, config
.c_master_pass
);
836 else if (config
.c_auth_mode
== AUTHMODE_HOST
) {
840 if (validpw(CC
->user
.uid
, password
)) {
844 * sooper-seekrit hack: populate the password field in the
845 * citadel database with the password that the user typed,
846 * if it's correct. This allows most sites to convert from
847 * host auth to native auth if they want to. If you think
848 * this is a security hazard, comment it out.
851 lgetuser(&CC
->user
, CC
->curr_user
);
852 safestrncpy(CC
->user
.password
, password
, sizeof CC
->user
.password
);
856 * (sooper-seekrit hack ends here)
867 /* native auth mode */
870 strproc(CC
->user
.password
);
871 code
= strcasecmp(CC
->user
.password
, password
);
873 strproc(CC
->user
.password
);
874 code
= strcasecmp(CC
->user
.password
, password
);
881 CtdlLogPrintf(CTDL_WARNING
, "Bad password specified for <%s>\n", CC
->curr_user
);
882 return pass_wrong_password
;
887 void cmd_pass(char *buf
)
892 extract_token(password
, buf
, 0, '|', sizeof password
);
893 a
= CtdlTryPassword(password
);
896 case pass_already_logged_in
:
897 cprintf("%d Already logged in.\n", ERROR
+ ALREADY_LOGGED_IN
);
900 cprintf("%d You must send a name with USER first.\n",
901 ERROR
+ USERNAME_REQUIRED
);
903 case pass_wrong_password
:
904 cprintf("%d Wrong password.\n", ERROR
+ PASSWORD_REQUIRED
);
907 logged_in_response();
915 * Delete a user record *and* all of its related resources.
917 int purge_user(char pname
[])
920 struct ctdluser usbuf
;
921 char usernamekey
[USERNAME_SIZE
];
922 struct CitContext
*ccptr
;
923 int user_is_logged_in
= 0;
925 makeuserkey(usernamekey
, pname
);
927 /* If the name is empty we can't find them in the DB any way so just return */
928 if (IsEmptyStr(pname
))
929 return (ERROR
+ NO_SUCH_USER
);
931 if (getuser(&usbuf
, pname
) != 0) {
932 CtdlLogPrintf(CTDL_ERR
, "Cannot purge user <%s> - not found\n", pname
);
933 return (ERROR
+ NO_SUCH_USER
);
935 /* Don't delete a user who is currently logged in. Instead, just
936 * set the access level to 0, and let the account get swept up
937 * during the next purge.
939 user_is_logged_in
= 0;
940 begin_critical_section(S_SESSION_TABLE
);
941 for (ccptr
= ContextList
; ccptr
!= NULL
; ccptr
= ccptr
->next
) {
942 if (ccptr
->user
.usernum
== usbuf
.usernum
) {
943 user_is_logged_in
= 1;
946 end_critical_section(S_SESSION_TABLE
);
947 if (user_is_logged_in
== 1) {
948 CtdlLogPrintf(CTDL_WARNING
, "User <%s> is logged in; not deleting.\n", pname
);
953 CtdlLogPrintf(CTDL_NOTICE
, "Deleting user <%s>\n", pname
);
955 /* Perform any purge functions registered by server extensions */
956 PerformUserHooks(&usbuf
, EVT_PURGEUSER
);
958 /* delete any existing user/room relationships */
959 cdb_delete(CDB_VISIT
, &usbuf
.usernum
, sizeof(long));
961 /* delete the users-by-number index record */
962 cdb_delete(CDB_USERSBYNUMBER
, &usbuf
.usernum
, sizeof(long));
964 /* delete the userlog entry */
965 cdb_delete(CDB_USERS
, usernamekey
, strlen(usernamekey
));
967 /* remove the user's bio file */
975 /* remove the user's picture */
987 int internal_create_user (char *username
, struct ctdluser
*usbuf
, uid_t uid
)
989 if (!getuser(usbuf
, username
)) {
990 return (ERROR
+ ALREADY_EXISTS
);
993 /* Go ahead and initialize a new user record */
994 memset(usbuf
, 0, sizeof(struct ctdluser
));
995 safestrncpy(usbuf
->fullname
, username
, sizeof usbuf
->fullname
);
996 strcpy(usbuf
->password
, "");
999 /* These are the default flags on new accounts */
1000 usbuf
->flags
= US_LASTOLD
| US_DISAPPEAR
| US_PAGINATOR
| US_FLOORS
;
1002 usbuf
->timescalled
= 0;
1004 usbuf
->axlevel
= config
.c_initax
;
1005 usbuf
->USscreenwidth
= 80;
1006 usbuf
->USscreenheight
= 24;
1007 usbuf
->lastcall
= time(NULL
);
1009 /* fetch a new user number */
1010 usbuf
->usernum
= get_new_user_number();
1012 /* add user to the database */
1014 cdb_store(CDB_USERSBYNUMBER
, &usbuf
->usernum
, sizeof(long), usbuf
->fullname
, strlen(usbuf
->fullname
)+1);
1022 * create_user() - back end processing to create a new user
1024 * Set 'newusername' to the desired account name.
1025 * Set 'become_user' to nonzero if this is self-service account creation and we want
1026 * to actually log in as the user we just created, otherwise set it to 0.
1028 int create_user(char *newusername
, int become_user
)
1030 struct ctdluser usbuf
;
1031 struct ctdlroom qrbuf
;
1033 char mailboxname
[ROOMNAMELEN
];
1039 safestrncpy(username
, newusername
, sizeof username
);
1043 if (config
.c_auth_mode
== AUTHMODE_HOST
) {
1045 /* host auth mode */
1048 struct passwd
*tempPwdPtr
;
1049 char pwdbuffer
[256];
1051 #ifdef HAVE_GETPWNAM_R
1052 #ifdef SOLARIS_GETPWUID
1053 tempPwdPtr
= getpwnam_r(username
, &pd
, pwdbuffer
, sizeof(pwdbuffer
));
1054 #else // SOLARIS_GETPWUID
1055 getpwnam_r(username
, &pd
, pwdbuffer
, sizeof pwdbuffer
, &tempPwdPtr
);
1056 #endif // SOLARIS_GETPWUID
1057 #else // HAVE_GETPWNAM_R
1059 #endif // HAVE_GETPWNAM_R
1060 if (tempPwdPtr
!= NULL
) {
1061 extract_token(username
, pd
.pw_gecos
, 0, ',', sizeof username
);
1063 if (IsEmptyStr (username
))
1065 safestrncpy(username
, pd
.pw_name
, sizeof username
);
1069 return (ERROR
+ NO_SUCH_USER
);
1073 if ((retval
= internal_create_user(username
, &usbuf
, uid
)) != 0)
1077 * Give the user a private mailbox and a configuration room.
1078 * Make the latter an invisible system room.
1080 MailboxName(mailboxname
, sizeof mailboxname
, &usbuf
, MAILROOM
);
1081 create_room(mailboxname
, 5, "", 0, 1, 1, VIEW_MAILBOX
);
1083 MailboxName(mailboxname
, sizeof mailboxname
, &usbuf
, USERCONFIGROOM
);
1084 create_room(mailboxname
, 5, "", 0, 1, 1, VIEW_BBS
);
1085 if (lgetroom(&qrbuf
, mailboxname
) == 0) {
1086 qrbuf
.QRflags2
|= QR2_SYSTEM
;
1090 /* Perform any create functions registered by server extensions */
1091 PerformUserHooks(&usbuf
, EVT_NEWUSER
);
1093 /* Everything below this line can be bypassed if administratively
1094 * creating a user, instead of doing self-service account creation
1098 /* Now become the user we just created */
1099 memcpy(&CC
->user
, &usbuf
, sizeof(struct ctdluser
));
1100 safestrncpy(CC
->curr_user
, username
, sizeof CC
->curr_user
);
1103 /* Check to make sure we're still who we think we are */
1104 if (getuser(&CC
->user
, CC
->curr_user
)) {
1105 return (ERROR
+ INTERNAL_ERROR
);
1110 "New user account <%s> has been created, from host %s [%s].\n",
1115 aide_message(buf
, "User Creation Notice");
1116 CtdlLogPrintf(CTDL_NOTICE
, "New user <%s> created\n", username
);
1123 * cmd_newu() - create a new user account and log in as that user
1125 void cmd_newu(char *cmdbuf
)
1130 if (config
.c_auth_mode
!= AUTHMODE_NATIVE
) {
1131 cprintf("%d This system does not use native mode authentication.\n",
1136 if (config
.c_disable_newu
) {
1137 cprintf("%d Self-service user account creation "
1138 "is disabled on this system.\n", ERROR
+ NOT_HERE
);
1142 if (CC
->logged_in
) {
1143 cprintf("%d Already logged in.\n", ERROR
+ ALREADY_LOGGED_IN
);
1147 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
1148 ERROR
+ MAX_SESSIONS_EXCEEDED
,
1149 config
.c_nodename
, config
.c_maxsessions
);
1151 extract_token(username
, cmdbuf
, 0, '|', sizeof username
);
1155 if (IsEmptyStr(username
)) {
1156 cprintf("%d You must supply a user name.\n", ERROR
+ USERNAME_REQUIRED
);
1160 if ((!strcasecmp(username
, "bbs")) ||
1161 (!strcasecmp(username
, "new")) ||
1162 (!strcasecmp(username
, "."))) {
1163 cprintf("%d '%s' is an invalid login name.\n", ERROR
+ ILLEGAL_VALUE
, username
);
1167 a
= create_user(username
, 1);
1170 logged_in_response();
1171 } else if (a
== ERROR
+ ALREADY_EXISTS
) {
1172 cprintf("%d '%s' already exists.\n",
1173 ERROR
+ ALREADY_EXISTS
, username
);
1175 } else if (a
== ERROR
+ INTERNAL_ERROR
) {
1176 cprintf("%d Internal error - user record disappeared?\n",
1177 ERROR
+ INTERNAL_ERROR
);
1180 cprintf("%d unknown error\n", ERROR
+ INTERNAL_ERROR
);
1186 * set password - back end api code
1188 void CtdlSetPassword(char *new_pw
)
1190 lgetuser(&CC
->user
, CC
->curr_user
);
1191 safestrncpy(CC
->user
.password
, new_pw
, sizeof(CC
->user
.password
));
1192 lputuser(&CC
->user
);
1193 CtdlLogPrintf(CTDL_INFO
, "Password changed for user <%s>\n", CC
->curr_user
);
1194 PerformSessionHooks(EVT_SETPASS
);
1199 * set password - citadel protocol implementation
1201 void cmd_setp(char *new_pw
)
1203 int generate_random_password
= 0;
1205 if (CtdlAccessCheck(ac_logged_in
)) {
1208 if ( (CC
->user
.uid
!= CTDLUID
) && (CC
->user
.uid
!= (-1)) ) {
1209 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR
+ NOT_HERE
);
1212 if (CC
->is_master
) {
1213 cprintf("%d The master prefix password cannot be changed with this command.\n",
1218 if (!strcasecmp(new_pw
, "GENERATE_RANDOM_PASSWORD")) {
1219 char random_password
[17];
1220 generate_random_password
= 1;
1221 snprintf(random_password
, sizeof random_password
, "%08lx%08lx", random(), random());
1222 CtdlSetPassword(random_password
);
1223 cprintf("%d %s\n", CIT_OK
, random_password
);
1227 if (IsEmptyStr(new_pw
)) {
1228 cprintf("%d Password unchanged.\n", CIT_OK
);
1231 CtdlSetPassword(new_pw
);
1232 cprintf("%d Password changed.\n", CIT_OK
);
1238 * cmd_creu() - administratively create a new user account (do not log in to it)
1240 void cmd_creu(char *cmdbuf
)
1245 struct ctdluser tmp
;
1247 if (CtdlAccessCheck(ac_aide
)) {
1251 extract_token(username
, cmdbuf
, 0, '|', sizeof username
);
1252 extract_token(password
, cmdbuf
, 1, '|', sizeof password
);
1258 if (IsEmptyStr(username
)) {
1259 cprintf("%d You must supply a user name.\n", ERROR
+ USERNAME_REQUIRED
);
1263 a
= create_user(username
, 0);
1266 if (!IsEmptyStr(password
)) {
1267 lgetuser(&tmp
, username
);
1268 safestrncpy(tmp
.password
, password
, sizeof(tmp
.password
));
1271 cprintf("%d User '%s' created %s.\n", CIT_OK
, username
,
1272 (!IsEmptyStr(password
)) ? "and password set" :
1273 "with no password");
1275 } else if (a
== ERROR
+ ALREADY_EXISTS
) {
1276 cprintf("%d '%s' already exists.\n", ERROR
+ ALREADY_EXISTS
, username
);
1278 } else if ( (config
.c_auth_mode
!= AUTHMODE_NATIVE
) && (a
== ERROR
+ NO_SUCH_USER
) ) {
1279 cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
1280 ERROR
+ NO_SUCH_USER
);
1283 cprintf("%d An error occurred creating the user account.\n", ERROR
+ INTERNAL_ERROR
);
1290 * get user parameters
1295 if (CtdlAccessCheck(ac_logged_in
))
1298 getuser(&CC
->user
, CC
->curr_user
);
1299 cprintf("%d %d|%d|%d|\n",
1301 CC
->user
.USscreenwidth
,
1302 CC
->user
.USscreenheight
,
1303 (CC
->user
.flags
& US_USER_SET
)
1308 * set user parameters
1310 void cmd_setu(char *new_parms
)
1312 if (CtdlAccessCheck(ac_logged_in
))
1315 if (num_parms(new_parms
) < 3) {
1316 cprintf("%d Usage error.\n", ERROR
+ ILLEGAL_VALUE
);
1319 lgetuser(&CC
->user
, CC
->curr_user
);
1320 CC
->user
.USscreenwidth
= extract_int(new_parms
, 0);
1321 CC
->user
.USscreenheight
= extract_int(new_parms
, 1);
1322 CC
->user
.flags
= CC
->user
.flags
& (~US_USER_SET
);
1323 CC
->user
.flags
= CC
->user
.flags
|
1324 (extract_int(new_parms
, 2) & US_USER_SET
);
1326 lputuser(&CC
->user
);
1327 cprintf("%d Ok\n", CIT_OK
);
1331 * set last read pointer
1333 void cmd_slrp(char *new_ptr
)
1337 struct visit original_vbuf
;
1339 if (CtdlAccessCheck(ac_logged_in
)) {
1343 if (!strncasecmp(new_ptr
, "highest", 7)) {
1344 newlr
= CC
->room
.QRhighest
;
1346 newlr
= atol(new_ptr
);
1349 lgetuser(&CC
->user
, CC
->curr_user
);
1351 CtdlGetRelationship(&vbuf
, &CC
->user
, &CC
->room
);
1352 memcpy(&original_vbuf
, &vbuf
, sizeof(struct visit
));
1353 vbuf
.v_lastseen
= newlr
;
1354 snprintf(vbuf
.v_seen
, sizeof vbuf
.v_seen
, "*:%ld", newlr
);
1356 /* Only rewrite the record if it changed */
1357 if ( (vbuf
.v_lastseen
!= original_vbuf
.v_lastseen
)
1358 || (strcmp(vbuf
.v_seen
, original_vbuf
.v_seen
)) ) {
1359 CtdlSetRelationship(&vbuf
, &CC
->user
, &CC
->room
);
1362 lputuser(&CC
->user
);
1363 cprintf("%d %ld\n", CIT_OK
, newlr
);
1367 void cmd_seen(char *argbuf
) {
1368 long target_msgnum
= 0L;
1369 int target_setting
= 0;
1371 if (CtdlAccessCheck(ac_logged_in
)) {
1375 if (num_parms(argbuf
) != 2) {
1376 cprintf("%d Invalid parameters\n", ERROR
+ ILLEGAL_VALUE
);
1380 target_msgnum
= extract_long(argbuf
, 0);
1381 target_setting
= extract_int(argbuf
, 1);
1383 CtdlSetSeen(&target_msgnum
, 1, target_setting
,
1384 ctdlsetseen_seen
, NULL
, NULL
);
1385 cprintf("%d OK\n", CIT_OK
);
1389 void cmd_gtsn(char *argbuf
) {
1392 if (CtdlAccessCheck(ac_logged_in
)) {
1396 CtdlGetSeen(buf
, ctdlsetseen_seen
);
1397 cprintf("%d %s\n", CIT_OK
, buf
);
1402 * API function for cmd_invt_kick() and anything else that needs to
1403 * invite or kick out a user to/from a room.
1405 * Set iuser to the name of the user, and op to 1=invite or 0=kick
1407 int CtdlInvtKick(char *iuser
, int op
) {
1408 struct ctdluser USscratch
;
1412 if (getuser(&USscratch
, iuser
) != 0) {
1416 CtdlGetRelationship(&vbuf
, &USscratch
, &CC
->room
);
1418 vbuf
.v_flags
= vbuf
.v_flags
& ~V_FORGET
& ~V_LOCKOUT
;
1419 vbuf
.v_flags
= vbuf
.v_flags
| V_ACCESS
;
1422 vbuf
.v_flags
= vbuf
.v_flags
& ~V_ACCESS
;
1423 vbuf
.v_flags
= vbuf
.v_flags
| V_FORGET
| V_LOCKOUT
;
1425 CtdlSetRelationship(&vbuf
, &USscratch
, &CC
->room
);
1427 /* post a message in Aide> saying what we just did */
1428 snprintf(bbb
, sizeof bbb
, "%s has been %s \"%s\" by %s.\n",
1430 ((op
== 1) ? "invited to" : "kicked out of"),
1433 aide_message(bbb
,"User Admin Message");
1440 * INVT and KICK commands
1442 void cmd_invt_kick(char *iuser
, int op
) {
1445 * These commands are only allowed by aides, room aides,
1446 * and room namespace owners
1449 || (atol(CC
->room
.QRname
) == CC
->user
.usernum
) ) {
1450 /* access granted */
1453 cprintf("%d Higher access or room ownership required.\n",
1454 ERROR
+ HIGHER_ACCESS_REQUIRED
);
1458 if (!strncasecmp(CC
->room
.QRname
, config
.c_baseroom
,
1460 cprintf("%d Can't add/remove users from this room.\n",
1465 if (CtdlInvtKick(iuser
, op
) != 0) {
1466 cprintf("%d No such user.\n", ERROR
+ NO_SUCH_USER
);
1470 cprintf("%d %s %s %s.\n",
1472 ((op
== 1) ? "invited to" : "kicked out of"),
1479 * Forget (Zap) the current room (API call)
1480 * Returns 0 on success
1482 int CtdlForgetThisRoom(void) {
1485 /* On some systems, Aides are not allowed to forget rooms */
1486 if (is_aide() && (config
.c_aide_zap
== 0)
1487 && ((CC
->room
.QRflags
& QR_MAILBOX
) == 0) ) {
1491 lgetuser(&CC
->user
, CC
->curr_user
);
1492 CtdlGetRelationship(&vbuf
, &CC
->user
, &CC
->room
);
1494 vbuf
.v_flags
= vbuf
.v_flags
| V_FORGET
;
1495 vbuf
.v_flags
= vbuf
.v_flags
& ~V_ACCESS
;
1497 CtdlSetRelationship(&vbuf
, &CC
->user
, &CC
->room
);
1498 lputuser(&CC
->user
);
1500 /* Return to the Lobby, so we don't end up in an undefined room */
1501 usergoto(config
.c_baseroom
, 0, 0, NULL
, NULL
);
1508 * forget (Zap) the current room
1513 if (CtdlAccessCheck(ac_logged_in
)) {
1517 if (CtdlForgetThisRoom() == 0) {
1518 cprintf("%d Ok\n", CIT_OK
);
1521 cprintf("%d You may not forget this room.\n", ERROR
+ NOT_HERE
);
1526 * Get Next Unregistered User
1530 struct cdbdata
*cdbus
;
1531 struct ctdluser usbuf
;
1533 if (CtdlAccessCheck(ac_aide
)) {
1537 if ((CitControl
.MMflags
& MM_VALID
) == 0) {
1538 cprintf("%d There are no unvalidated users.\n", CIT_OK
);
1542 /* There are unvalidated users. Traverse the user database,
1543 * and return the first user we find that needs validation.
1545 cdb_rewind(CDB_USERS
);
1546 while (cdbus
= cdb_next_item(CDB_USERS
), cdbus
!= NULL
) {
1547 memset(&usbuf
, 0, sizeof(struct ctdluser
));
1548 memcpy(&usbuf
, cdbus
->ptr
,
1549 ((cdbus
->len
> sizeof(struct ctdluser
)) ?
1550 sizeof(struct ctdluser
) : cdbus
->len
));
1552 if ((usbuf
.flags
& US_NEEDVALID
)
1553 && (usbuf
.axlevel
> 0)) {
1554 cprintf("%d %s\n", MORE_DATA
, usbuf
.fullname
);
1555 cdb_close_cursor(CDB_USERS
);
1560 /* If we get to this point, there are no more unvalidated users.
1561 * Therefore we clear the "users need validation" flag.
1564 begin_critical_section(S_CONTROL
);
1566 CitControl
.MMflags
= CitControl
.MMflags
& (~MM_VALID
);
1568 end_critical_section(S_CONTROL
);
1569 cprintf("%d *** End of registration.\n", CIT_OK
);
1578 void cmd_vali(char *v_args
)
1582 struct ctdluser userbuf
;
1584 extract_token(user
, v_args
, 0, '|', sizeof user
);
1585 newax
= extract_int(v_args
, 1);
1587 if (CtdlAccessCheck(ac_aide
)) {
1591 if (lgetuser(&userbuf
, user
) != 0) {
1592 cprintf("%d '%s' not found.\n", ERROR
+ NO_SUCH_USER
, user
);
1596 userbuf
.axlevel
= newax
;
1597 userbuf
.flags
= (userbuf
.flags
& ~US_NEEDVALID
);
1601 /* If the access level was set to zero, delete the user */
1603 if (purge_user(user
) == 0) {
1604 cprintf("%d %s Deleted.\n", CIT_OK
, userbuf
.fullname
);
1608 cprintf("%d User '%s' validated.\n", CIT_OK
, userbuf
.fullname
);
1614 * Traverse the user file...
1616 void ForEachUser(void (*CallBack
) (struct ctdluser
* EachUser
, void *out_data
),
1619 struct ctdluser usbuf
;
1620 struct cdbdata
*cdbus
;
1622 cdb_rewind(CDB_USERS
);
1624 while (cdbus
= cdb_next_item(CDB_USERS
), cdbus
!= NULL
) {
1625 memset(&usbuf
, 0, sizeof(struct ctdluser
));
1626 memcpy(&usbuf
, cdbus
->ptr
,
1627 ((cdbus
->len
> sizeof(struct ctdluser
)) ?
1628 sizeof(struct ctdluser
) : cdbus
->len
));
1630 (*CallBack
) (&usbuf
, in_data
);
1636 * List one user (this works with cmd_list)
1638 void ListThisUser(struct ctdluser
*usbuf
, void *data
)
1642 searchstring
= (char *)data
;
1643 if (bmstrcasestr(usbuf
->fullname
, searchstring
) == NULL
) {
1647 if (usbuf
->axlevel
> 0) {
1648 if ((CC
->user
.axlevel
>= 6)
1649 || ((usbuf
->flags
& US_UNLISTED
) == 0)
1650 || ((CC
->internal_pgm
))) {
1651 cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
1655 (long)usbuf
->lastcall
,
1663 * List users (searchstring may be empty to list all users)
1665 void cmd_list(char *cmdbuf
)
1667 char searchstring
[256];
1668 extract_token(searchstring
, cmdbuf
, 0, '|', sizeof searchstring
);
1669 striplt(searchstring
);
1670 cprintf("%d \n", LISTING_FOLLOWS
);
1671 ForEachUser(ListThisUser
, (void *)searchstring
);
1679 * assorted info we need to check at login
1687 if (CtdlAccessCheck(ac_logged_in
)) {
1691 getuser(&CC
->user
, CC
->curr_user
); /* no lock is needed here */
1692 if ((REGISCALL
!= 0) && ((CC
->user
.flags
& US_REGIS
) == 0))
1695 if (CC
->user
.axlevel
>= 6) {
1697 if (CitControl
.MMflags
& MM_VALID
)
1701 /* check for mail */
1702 mail
= InitialMailCheck();
1704 cprintf("%d %d|%d|%d|%s|\n", CIT_OK
, mail
, regis
, vali
, CC
->cs_inet_email
);
1709 * check to see if a user exists
1711 void cmd_qusr(char *who
)
1713 struct ctdluser usbuf
;
1715 if (getuser(&usbuf
, who
) == 0) {
1716 cprintf("%d %s\n", CIT_OK
, usbuf
.fullname
);
1718 cprintf("%d No such user.\n", ERROR
+ NO_SUCH_USER
);
1724 * Administrative Get User Parameters
1726 void cmd_agup(char *cmdbuf
)
1728 struct ctdluser usbuf
;
1729 char requested_user
[128];
1731 if (CtdlAccessCheck(ac_aide
)) {
1735 extract_token(requested_user
, cmdbuf
, 0, '|', sizeof requested_user
);
1736 if (getuser(&usbuf
, requested_user
) != 0) {
1737 cprintf("%d No such user.\n", ERROR
+ NO_SUCH_USER
);
1740 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1747 (int) usbuf
.axlevel
,
1749 (long)usbuf
.lastcall
,
1756 * Administrative Set User Parameters
1758 void cmd_asup(char *cmdbuf
)
1760 struct ctdluser usbuf
;
1761 char requested_user
[128];
1767 if (CtdlAccessCheck(ac_aide
))
1770 extract_token(requested_user
, cmdbuf
, 0, '|', sizeof requested_user
);
1771 if (lgetuser(&usbuf
, requested_user
) != 0) {
1772 cprintf("%d No such user.\n", ERROR
+ NO_SUCH_USER
);
1775 np
= num_parms(cmdbuf
);
1777 extract_token(usbuf
.password
, cmdbuf
, 1, '|', sizeof usbuf
.password
);
1779 usbuf
.flags
= extract_int(cmdbuf
, 2);
1781 usbuf
.timescalled
= extract_int(cmdbuf
, 3);
1783 usbuf
.posted
= extract_int(cmdbuf
, 4);
1785 newax
= extract_int(cmdbuf
, 5);
1786 if ((newax
>= 0) && (newax
<= 6)) {
1787 usbuf
.axlevel
= extract_int(cmdbuf
, 5);
1791 usbuf
.lastcall
= extract_long(cmdbuf
, 7);
1794 usbuf
.USuserpurge
= extract_int(cmdbuf
, 8);
1797 if (usbuf
.axlevel
== 0) {
1798 if (purge_user(requested_user
) == 0) {
1804 snprintf(notify
, SIZ
,
1805 "User \"%s\" has been deleted by %s.\n",
1806 usbuf
.fullname
, CC
->user
.fullname
);
1807 aide_message(notify
, "User Deletion Message");
1810 cprintf("%d Ok", CIT_OK
);
1812 cprintf(" (%s deleted)", requested_user
);
1819 * Check to see if the user who we just sent mail to is logged in. If yes,
1820 * bump the 'new mail' counter for their session. That enables them to
1821 * receive a new mail notification without having to hit the database.
1823 void BumpNewMailCounter(long which_user
) {
1824 struct CitContext
*ptr
;
1826 begin_critical_section(S_SESSION_TABLE
);
1828 for (ptr
= ContextList
; ptr
!= NULL
; ptr
= ptr
->next
) {
1829 if (ptr
->user
.usernum
== which_user
) {
1834 end_critical_section(S_SESSION_TABLE
);
1839 * Count the number of new mail messages the user has
1843 int num_newmsgs
= 0;
1845 num_newmsgs
= CC
->newmail
;
1848 return (num_newmsgs
);
1853 * Count the number of new mail messages the user has
1855 int InitialMailCheck()
1857 int num_newmsgs
= 0;
1859 char mailboxname
[ROOMNAMELEN
];
1860 struct ctdlroom mailbox
;
1862 struct cdbdata
*cdbfr
;
1863 long *msglist
= NULL
;
1866 MailboxName(mailboxname
, sizeof mailboxname
, &CC
->user
, MAILROOM
);
1867 if (getroom(&mailbox
, mailboxname
) != 0)
1869 CtdlGetRelationship(&vbuf
, &CC
->user
, &mailbox
);
1871 cdbfr
= cdb_fetch(CDB_MSGLISTS
, &mailbox
.QRnumber
, sizeof(long));
1873 if (cdbfr
!= NULL
) {
1874 msglist
= malloc(cdbfr
->len
);
1875 memcpy(msglist
, cdbfr
->ptr
, cdbfr
->len
);
1876 num_msgs
= cdbfr
->len
/ sizeof(long);
1880 for (a
= 0; a
< num_msgs
; ++a
) {
1881 if (msglist
[a
] > 0L) {
1882 if (msglist
[a
] > vbuf
.v_lastseen
) {
1887 if (msglist
!= NULL
)
1890 return (num_newmsgs
);
1896 * Set the preferred view for the current user/room combination
1898 void cmd_view(char *cmdbuf
) {
1902 if (CtdlAccessCheck(ac_logged_in
)) {
1906 requested_view
= extract_int(cmdbuf
, 0);
1908 CtdlGetRelationship(&vbuf
, &CC
->user
, &CC
->room
);
1909 vbuf
.v_view
= requested_view
;
1910 CtdlSetRelationship(&vbuf
, &CC
->user
, &CC
->room
);
1912 cprintf("%d ok\n", CIT_OK
);
1919 void cmd_renu(char *cmdbuf
)
1922 char oldname
[USERNAME_SIZE
];
1923 char newname
[USERNAME_SIZE
];
1925 if (CtdlAccessCheck(ac_aide
)) {
1929 extract_token(oldname
, cmdbuf
, 0, '|', sizeof oldname
);
1930 extract_token(newname
, cmdbuf
, 1, '|', sizeof newname
);
1932 retcode
= rename_user(oldname
, newname
);
1935 cprintf("%d '%s' has been renamed to '%s'.\n", CIT_OK
, oldname
, newname
);
1937 case RENAMEUSER_LOGGED_IN
:
1938 cprintf("%d '%s' is currently logged in and cannot be renamed.\n",
1939 ERROR
+ ALREADY_LOGGED_IN
, oldname
);
1941 case RENAMEUSER_NOT_FOUND
:
1942 cprintf("%d '%s' does not exist.\n", ERROR
+ NO_SUCH_USER
, oldname
);
1944 case RENAMEUSER_ALREADY_EXISTS
:
1945 cprintf("%d A user named '%s' already exists.\n", ERROR
+ ALREADY_EXISTS
, newname
);
1949 cprintf("%d An unknown error occurred.\n", ERROR
);