d7f88ad4dc79e1fa94d39d00a69044925db64bd2
[citadel.git] / citadel / user_ops.c
1 /* 
2  * Server functions which perform operations on user objects.
3  *
4  * Copyright (c) 1987-2011 by the citadel.org team
5  *
6  * This program is open source software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20
21 #include "sysdep.h"
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <stdio.h>
26 #include <fcntl.h>
27 #include <signal.h>
28 #include <pwd.h>
29 #include <ctype.h>
30 #include <sys/types.h>
31 #include <sys/wait.h>
32 #include <syslog.h>
33 #ifdef HAVE_SYS_STAT_H
34 #include <sys/stat.h>
35 #endif
36
37 #if TIME_WITH_SYS_TIME
38 # include <sys/time.h>
39 # include <time.h>
40 #else
41 # if HAVE_SYS_TIME_H
42 #  include <sys/time.h>
43 # else
44 #  include <time.h>
45 # endif
46 #endif
47
48 #include <string.h>
49 #include <limits.h>
50 #include <libcitadel.h>
51 #include "auth.h"
52 #include "citadel.h"
53 #include "server.h"
54 #include "database.h"
55 #include "sysdep_decls.h"
56 #include "support.h"
57 #include "room_ops.h"
58 #include "file_ops.h"
59 #include "control.h"
60 #include "msgbase.h"
61 #include "config.h"
62 #include "citserver.h"
63 #include "citadel_dirs.h"
64 #include "genstamp.h"
65 #include "threads.h"
66 #include "citadel_ldap.h"
67 #include "context.h"
68 #include "ctdl_module.h"
69 #include "user_ops.h"
70
71 /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
72 int chkpwd_write_pipe[2];
73 int chkpwd_read_pipe[2];
74
75
76
77 /*
78  * getuser()  -  retrieve named user into supplied buffer.
79  *             returns 0 on success
80  */
81 int getuser(struct ctdluser *usbuf, char name[])
82 {
83         return CtdlGetUser(usbuf, name);
84 }
85
86
87 /*
88  * CtdlGetUser()  -  retrieve named user into supplied buffer.
89  *             returns 0 on success
90  */
91 int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len)
92 {
93
94         char usernamekey[USERNAME_SIZE];
95         struct cdbdata *cdbus;
96
97         if (usbuf != NULL) {
98                 memset(usbuf, 0, sizeof(struct ctdluser));
99         }
100
101         makeuserkey(usernamekey, name, len);
102         cdbus = cdb_fetch(CDB_USERS, usernamekey, strlen(usernamekey));
103
104         if (cdbus == NULL) {    /* user not found */
105                 return(1);
106         }
107         if (usbuf != NULL) {
108                 memcpy(usbuf, cdbus->ptr,
109                         ((cdbus->len > sizeof(struct ctdluser)) ?
110                          sizeof(struct ctdluser) : cdbus->len));
111         }
112         cdb_free(cdbus);
113
114         return (0);
115 }
116
117
118 int CtdlGetUser(struct ctdluser *usbuf, char *name)
119 {
120         return CtdlGetUserLen(usbuf, name, cutuserkey(name));
121 }
122
123
124 /*
125  * CtdlGetUserLock()  -  same as getuser() but locks the record
126  */
127 int CtdlGetUserLock(struct ctdluser *usbuf, char *name)
128 {
129         int retcode;
130
131         retcode = CtdlGetUser(usbuf, name);
132         if (retcode == 0) {
133                 begin_critical_section(S_USERS);
134         }
135         return (retcode);
136 }
137
138
139 /*
140  * lgetuser()  -  same as getuser() but locks the record
141  */
142 int lgetuser(struct ctdluser *usbuf, char *name)
143 {
144         return CtdlGetUserLock(usbuf, name);
145 }
146
147
148 /*
149  * CtdlPutUser()  -  write user buffer into the correct place on disk
150  */
151 void CtdlPutUser(struct ctdluser *usbuf)
152 {
153         char usernamekey[USERNAME_SIZE];
154
155         makeuserkey(usernamekey, 
156                     usbuf->fullname, 
157                     cutuserkey(usbuf->fullname));
158
159         usbuf->version = REV_LEVEL;
160         cdb_store(CDB_USERS,
161                   usernamekey, strlen(usernamekey),
162                   usbuf, sizeof(struct ctdluser));
163
164 }
165
166
167 /*
168  * putuser()  -  write user buffer into the correct place on disk
169  */
170 void putuser(struct ctdluser *usbuf)
171 {
172         CtdlPutUser(usbuf);
173 }
174
175
176 /*
177  * CtdlPutUserLock()  -  same as putuser() but locks the record
178  */
179 void CtdlPutUserLock(struct ctdluser *usbuf)
180 {
181         CtdlPutUser(usbuf);
182         end_critical_section(S_USERS);
183 }
184
185
186 /*
187  * lputuser()  -  same as putuser() but locks the record
188  */
189 void lputuser(struct ctdluser *usbuf)
190 {
191         CtdlPutUserLock(usbuf);
192 }
193
194
195 /*
196  * rename_user()  -  this is tricky because the user's display name is the database key
197  *
198  * Returns 0 on success or nonzero if there was an error...
199  *
200  */
201 int rename_user(char *oldname, char *newname) {
202         int retcode = RENAMEUSER_OK;
203         struct ctdluser usbuf;
204
205         char oldnamekey[USERNAME_SIZE];
206         char newnamekey[USERNAME_SIZE];
207
208         /* Create the database keys... */
209         makeuserkey(oldnamekey, oldname, cutuserkey(oldname));
210         makeuserkey(newnamekey, newname, cutuserkey(newname));
211
212         /* Lock up and get going */
213         begin_critical_section(S_USERS);
214
215         /* We cannot rename a user who is currently logged in */
216         if (CtdlIsUserLoggedIn(oldname)) {
217                 end_critical_section(S_USERS);
218                 return RENAMEUSER_LOGGED_IN;
219         }
220
221         if (CtdlGetUser(&usbuf, newname) == 0) {
222                 retcode = RENAMEUSER_ALREADY_EXISTS;
223         }
224         else {
225
226                 if (CtdlGetUser(&usbuf, oldname) != 0) {
227                         retcode = RENAMEUSER_NOT_FOUND;
228                 }
229
230                 else {          /* Sanity checks succeeded.  Now rename the user. */
231                         if (usbuf.usernum == 0)
232                         {
233                                 syslog(LOG_DEBUG, "Can not rename user \"Citadel\".\n");
234                                 retcode = RENAMEUSER_NOT_FOUND;
235                         } else {
236                                 syslog(LOG_DEBUG, "Renaming <%s> to <%s>\n", oldname, newname);
237                                 cdb_delete(CDB_USERS, oldnamekey, strlen(oldnamekey));
238                                 safestrncpy(usbuf.fullname, newname, sizeof usbuf.fullname);
239                                 CtdlPutUser(&usbuf);
240                                 cdb_store(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long),
241                                         usbuf.fullname, strlen(usbuf.fullname)+1 );
242
243                                 retcode = RENAMEUSER_OK;
244                         }
245                 }
246         
247         }
248
249         end_critical_section(S_USERS);
250         return(retcode);
251 }
252
253
254
255 /*
256  * Index-generating function used by Ctdl[Get|Set]Relationship
257  */
258 int GenerateRelationshipIndex(char *IndexBuf,
259                               long RoomID,
260                               long RoomGen,
261                               long UserID)
262 {
263
264         struct {
265                 long iRoomID;
266                 long iRoomGen;
267                 long iUserID;
268         } TheIndex;
269
270         TheIndex.iRoomID = RoomID;
271         TheIndex.iRoomGen = RoomGen;
272         TheIndex.iUserID = UserID;
273
274         memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
275         return (sizeof(TheIndex));
276 }
277
278
279
280 /*
281  * Back end for CtdlSetRelationship()
282  */
283 void put_visit(visit *newvisit)
284 {
285         char IndexBuf[32];
286         int IndexLen = 0;
287
288         memset (IndexBuf, 0, sizeof (IndexBuf));
289         /* Generate an index */
290         IndexLen = GenerateRelationshipIndex(IndexBuf,
291                                              newvisit->v_roomnum,
292                                              newvisit->v_roomgen,
293                                              newvisit->v_usernum);
294
295         /* Store the record */
296         cdb_store(CDB_VISIT, IndexBuf, IndexLen,
297                   newvisit, sizeof(visit)
298         );
299 }
300
301
302
303
304 /*
305  * Define a relationship between a user and a room
306  */
307 void CtdlSetRelationship(visit *newvisit,
308                          struct ctdluser *rel_user,
309                          struct ctdlroom *rel_room)
310 {
311
312
313         /* We don't use these in Citadel because they're implicit by the
314          * index, but they must be present if the database is exported.
315          */
316         newvisit->v_roomnum = rel_room->QRnumber;
317         newvisit->v_roomgen = rel_room->QRgen;
318         newvisit->v_usernum = rel_user->usernum;
319
320         put_visit(newvisit);
321 }
322
323 /*
324  * Locate a relationship between a user and a room
325  */
326 void CtdlGetRelationship(visit *vbuf,
327                          struct ctdluser *rel_user,
328                          struct ctdlroom *rel_room)
329 {
330
331         char IndexBuf[32];
332         int IndexLen;
333         struct cdbdata *cdbvisit;
334
335         /* Generate an index */
336         IndexLen = GenerateRelationshipIndex(IndexBuf,
337                                              rel_room->QRnumber,
338                                              rel_room->QRgen,
339                                              rel_user->usernum);
340
341         /* Clear out the buffer */
342         memset(vbuf, 0, sizeof(visit));
343
344         cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
345         if (cdbvisit != NULL) {
346                 memcpy(vbuf, cdbvisit->ptr,
347                        ((cdbvisit->len > sizeof(visit)) ?
348                         sizeof(visit) : cdbvisit->len));
349                 cdb_free(cdbvisit);
350         }
351         else {
352                 /* If this is the first time the user has seen this room,
353                  * set the view to be the default for the room.
354                  */
355                 vbuf->v_view = rel_room->QRdefaultview;
356         }
357
358         /* Set v_seen if necessary */
359         if (vbuf->v_seen[0] == 0) {
360                 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
361         }
362 }
363
364
365 void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
366 {
367         snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
368 }
369
370
371 void MailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
372 {
373         snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
374 }
375
376
377 /*
378  * Is the user currently logged in an Aide?
379  */
380 int is_aide(void)
381 {
382         if (CC->user.axlevel >= AxAideU)
383                 return (1);
384         else
385                 return (0);
386 }
387
388
389 /*
390  * Is the user currently logged in an Aide *or* the room aide for this room?
391  */
392 int is_room_aide(void)
393 {
394
395         if (!CC->logged_in) {
396                 return (0);
397         }
398
399         if ((CC->user.axlevel >= AxAideU)
400             || (CC->room.QRroomaide == CC->user.usernum)) {
401                 return (1);
402         } else {
403                 return (0);
404         }
405 }
406
407 /*
408  * CtdlGetUserByNumber() -      get user by number
409  *                      returns 0 if user was found
410  *
411  * Note: fetching a user this way requires one additional database operation.
412  */
413 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number)
414 {
415         struct cdbdata *cdbun;
416         int r;
417
418         cdbun = cdb_fetch(CDB_USERSBYNUMBER, &number, sizeof(long));
419         if (cdbun == NULL) {
420                 syslog(LOG_INFO, "User %ld not found\n", number);
421                 return(-1);
422         }
423
424         syslog(LOG_INFO, "User %ld maps to %s\n", number, cdbun->ptr);
425         r = CtdlGetUser(usbuf, cdbun->ptr);
426         cdb_free(cdbun);
427         return(r);
428 }
429
430 /*
431  * getuserbynumber() -  get user by number
432  *                      returns 0 if user was found
433  *
434  * Note: fetching a user this way requires one additional database operation.
435  */
436 int getuserbynumber(struct ctdluser *usbuf, long number)
437 {
438         return CtdlGetUserByNumber(usbuf, number);
439 }
440
441
442
443 /*
444  * Helper function for rebuild_usersbynumber()
445  */
446 void rebuild_ubn_for_user(struct ctdluser *usbuf, void *data) {
447
448         struct ubnlist {
449                 struct ubnlist *next;
450                 char username[USERNAME_SIZE];
451                 long usernum;
452         };
453
454         static struct ubnlist *u = NULL;
455         struct ubnlist *ptr = NULL;
456
457         /* Lazy programming here.  Call this function as a ForEachUser backend
458          * in order to queue up the room names, or call it with a null user
459          * to make it do the processing.
460          */
461         if (usbuf != NULL) {
462                 ptr = (struct ubnlist *) malloc(sizeof (struct ubnlist));
463                 if (ptr == NULL) return;
464
465                 ptr->usernum = usbuf->usernum;
466                 safestrncpy(ptr->username, usbuf->fullname, sizeof ptr->username);
467                 ptr->next = u;
468                 u = ptr;
469                 return;
470         }
471
472         while (u != NULL) {
473                 syslog(LOG_DEBUG, "Rebuilding usersbynumber index %10ld : %s\n",
474                         u->usernum, u->username);
475                 cdb_store(CDB_USERSBYNUMBER, &u->usernum, sizeof(long), u->username, strlen(u->username)+1);
476
477                 ptr = u;
478                 u = u->next;
479                 free(ptr);
480         }
481 }
482
483
484
485 /*
486  * Rebuild the users-by-number index
487  */
488 void rebuild_usersbynumber(void) {
489         cdb_trunc(CDB_USERSBYNUMBER);                   /* delete the old indices */
490         ForEachUser(rebuild_ubn_for_user, NULL);        /* enumerate the users */
491         rebuild_ubn_for_user(NULL, NULL);               /* and index them */
492 }
493
494
495
496 /*
497  * getuserbyuid()  -     get user by system uid (for PAM mode authentication)
498  *                     returns 0 if user was found
499  *
500  * WARNING: don't use this function unless you absolutely have to.  It does
501  *        a sequential search and therefore is computationally expensive.
502  */
503 int getuserbyuid(struct ctdluser *usbuf, uid_t number)
504 {
505         struct cdbdata *cdbus;
506
507         cdb_rewind(CDB_USERS);
508
509         while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
510                 memset(usbuf, 0, sizeof(struct ctdluser));
511                 memcpy(usbuf, cdbus->ptr,
512                        ((cdbus->len > sizeof(struct ctdluser)) ?
513                         sizeof(struct ctdluser) : cdbus->len));
514                 cdb_free(cdbus);
515                 if (usbuf->uid == number) {
516                         cdb_close_cursor(CDB_USERS);
517                         return (0);
518                 }
519         }
520         return (-1);
521 }
522
523 /*
524  * Back end for cmd_user() and its ilk
525  *
526  * NOTE: "authname" should only be used if we are attempting to use the "master user" feature
527  */
528 int CtdlLoginExistingUser(char *authname, const char *trythisname)
529 {
530         char username[SIZ];
531         int found_user;
532         long len;
533
534         syslog(LOG_DEBUG, "CtdlLoginExistingUser(%s, %s)\n", authname, trythisname);
535
536         if ((CC->logged_in)) {
537                 return login_already_logged_in;
538         }
539
540         if (trythisname == NULL) return login_not_found;
541         
542         if (!strncasecmp(trythisname, "SYS_", 4))
543         {
544                 syslog(LOG_DEBUG, "System user \"%s\" is not allowed to log in.\n", trythisname);
545                 return login_not_found;
546         }
547
548         /* If a "master user" is defined, handle its authentication if specified */
549         CC->is_master = 0;
550         if (strlen(config.c_master_user) > 0) if (strlen(config.c_master_pass) > 0) if (authname) {
551                 if (!strcasecmp(authname, config.c_master_user)) {
552                         CC->is_master = 1;
553                 }
554         }
555
556         /* Continue attempting user validation... */
557         safestrncpy(username, trythisname, sizeof (username));
558         striplt(username);
559         len = cutuserkey(username);
560
561         if (IsEmptyStr(username)) {
562                 return login_not_found;
563         }
564
565         if (config.c_auth_mode == AUTHMODE_HOST) {
566
567                 /* host auth mode */
568
569                 struct passwd pd;
570                 struct passwd *tempPwdPtr;
571                 char pwdbuffer[256];
572         
573                 syslog(LOG_DEBUG, "asking host about <%s>\n", username);
574 #ifdef HAVE_GETPWNAM_R
575 #ifdef SOLARIS_GETPWUID
576                 syslog(LOG_DEBUG, "Calling getpwnam_r()\n");
577                 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer);
578 #else // SOLARIS_GETPWUID
579                 syslog(LOG_DEBUG, "Calling getpwnam_r()\n");
580                 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
581 #endif // SOLARIS_GETPWUID
582 #else // HAVE_GETPWNAM_R
583                 syslog(LOG_DEBUG, "SHOULD NEVER GET HERE!!!\n");
584                 tempPwdPtr = NULL;
585 #endif // HAVE_GETPWNAM_R
586                 if (tempPwdPtr == NULL) {
587                         syslog(LOG_DEBUG, "no such user <%s>\n", username);
588                         return login_not_found;
589                 }
590         
591                 /* Locate the associated Citadel account.
592                  * If not found, make one attempt to create it.
593                  */
594                 found_user = getuserbyuid(&CC->user, pd.pw_uid);
595                 syslog(LOG_DEBUG, "found it: uid=%ld, gecos=%s here: %d\n",
596                         (long)pd.pw_uid, pd.pw_gecos, found_user);
597                 if (found_user != 0) {
598                         len = cutuserkey(username);
599                         create_user(username, len, 0);
600                         found_user = getuserbyuid(&CC->user, pd.pw_uid);
601                 }
602
603         }
604
605 #ifdef HAVE_LDAP
606         else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
607         
608                 /* LDAP auth mode */
609
610                 uid_t ldap_uid;
611                 char ldap_cn[256];
612                 char ldap_dn[256];
613
614                 found_user = CtdlTryUserLDAP(username, ldap_dn, sizeof ldap_dn, ldap_cn, sizeof ldap_cn, &ldap_uid);
615                 if (found_user != 0) {
616                         return login_not_found;
617                 }
618
619                 found_user = getuserbyuid(&CC->user, ldap_uid);
620                 if (found_user != 0) {
621                         create_user(username, len, 0);
622                         found_user = getuserbyuid(&CC->user, ldap_uid);
623                 }
624
625                 if (found_user == 0) {
626                         if (CC->ldap_dn != NULL) free(CC->ldap_dn);
627                         CC->ldap_dn = strdup(ldap_dn);
628                 }
629
630         }
631 #endif
632
633         else {
634                 /* native auth mode */
635
636                 struct recptypes *valid = NULL;
637         
638                 /* First, try to log in as if the supplied name is a display name */
639                 found_user = CtdlGetUser(&CC->user, username);
640         
641                 /* If that didn't work, try to log in as if the supplied name
642                 * is an e-mail address
643                 */
644                 if (found_user != 0) {
645                         valid = validate_recipients(username, NULL, 0);
646                         if (valid != NULL) {
647                                 if (valid->num_local == 1) {
648                                         found_user = CtdlGetUser(&CC->user, valid->recp_local);
649                                 }
650                                 free_recipients(valid);
651                         }
652                 }
653         }
654
655         /* Did we find something? */
656         if (found_user == 0) {
657                 if (((CC->nologin)) && (CC->user.axlevel < AxAideU)) {
658                         return login_too_many_users;
659                 } else {
660                         safestrncpy(CC->curr_user, CC->user.fullname,
661                                         sizeof CC->curr_user);
662                         return login_ok;
663                 }
664         }
665         return login_not_found;
666 }
667
668
669
670 /*
671  * USER cmd
672  */
673 void cmd_user(char *cmdbuf)
674 {
675         char username[256];
676         int a;
677
678         syslog(LOG_DEBUG, "cmd_user(%s)\n", cmdbuf);
679         extract_token(username, cmdbuf, 0, '|', sizeof username);
680         syslog(LOG_DEBUG, "username: %s\n", username);
681         striplt(username);
682         syslog(LOG_DEBUG, "username: %s\n", username);
683
684         a = CtdlLoginExistingUser(NULL, username);
685         switch (a) {
686         case login_already_logged_in:
687                 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
688                 return;
689         case login_too_many_users:
690                 cprintf("%d %s: "
691                         "Too many users are already online "
692                         "(maximum is %d)\n",
693                         ERROR + MAX_SESSIONS_EXCEEDED,
694                         config.c_nodename, config.c_maxsessions);
695                 return;
696         case login_ok:
697                 cprintf("%d Password required for %s\n",
698                         MORE_DATA, CC->curr_user);
699                 return;
700         case login_not_found:
701                 cprintf("%d %s not found.\n", ERROR + NO_SUCH_USER, username);
702                 return;
703         default:
704                 cprintf("%d Internal error\n", ERROR + INTERNAL_ERROR);
705         }
706 }
707
708
709
710 /*
711  * session startup code which is common to both cmd_pass() and cmd_newu()
712  */
713 void do_login(void)
714 {
715         CC->logged_in = 1;
716         syslog(LOG_NOTICE, "<%s> logged in\n", CC->curr_user);
717
718         CtdlGetUserLock(&CC->user, CC->curr_user);
719         ++(CC->user.timescalled);
720         CC->previous_login = CC->user.lastcall;
721         time(&CC->user.lastcall);
722
723         /* If this user's name is the name of the system administrator
724          * (as specified in setup), automatically assign access level 6.
725          */
726         if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
727                 CC->user.axlevel = AxAideU;
728         }
729
730         /* If we're authenticating off the host system, automatically give
731          * root the highest level of access.
732          */
733         if (config.c_auth_mode == AUTHMODE_HOST) {
734                 if (CC->user.uid == 0) {
735                         CC->user.axlevel = AxAideU;
736                 }
737         }
738
739         CtdlPutUserLock(&CC->user);
740
741         /*
742          * Populate CC->cs_inet_email with a default address.  This will be
743          * overwritten with the user's directory address, if one exists, when
744          * the vCard module's login hook runs.
745          */
746         snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
747                 CC->user.fullname, config.c_fqdn);
748         convert_spaces_to_underscores(CC->cs_inet_email);
749
750         /* Create any personal rooms required by the system.
751          * (Technically, MAILROOM should be there already, but just in case...)
752          */
753         CtdlCreateRoom(MAILROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
754         CtdlCreateRoom(SENTITEMS, 4, "", 0, 1, 0, VIEW_MAILBOX);
755         CtdlCreateRoom(USERTRASHROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
756         CtdlCreateRoom(USERDRAFTROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
757
758         /* Run any startup routines registered by loadable modules */
759         PerformSessionHooks(EVT_LOGIN);
760
761         /* Enter the lobby */
762         CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
763 }
764
765
766 void logged_in_response(void)
767 {
768         cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
769                 CIT_OK, CC->user.fullname, CC->user.axlevel,
770                 CC->user.timescalled, CC->user.posted,
771                 CC->user.flags, CC->user.usernum,
772                 CC->previous_login);
773 }
774
775
776
777 void CtdlUserLogout(void)
778 {
779         CitContext *CCC = MyContext();
780
781         syslog(LOG_DEBUG, "CtdlUserLogout() logging out <%s> from session %d",
782                 CCC->curr_user, CCC->cs_pid
783         );
784
785         /*
786          * If there is a download in progress, abort it.
787          */
788         if (CCC->download_fp != NULL) {
789                 fclose(CCC->download_fp);
790                 CCC->download_fp = NULL;
791         }
792
793         /*
794          * If there is an upload in progress, abort it.
795          */
796         if (CCC->upload_fp != NULL) {
797                 abort_upl(CCC);
798         }
799
800         /*
801          * If we were talking to a network node, we're not anymore...
802          */
803         if (!IsEmptyStr(CCC->net_node)) {
804                 network_talking_to(CCC->net_node, NTT_REMOVE);
805         }
806
807         /* Run any hooks registered by modules... */
808         PerformSessionHooks(EVT_LOGOUT);
809         
810         /*
811          * Clear out some session data.  Most likely, the CitContext for this
812          * session is about to get nuked when the session disconnects, but
813          * since it's possible to log in again without reconnecting, we cannot
814          * make that assumption.
815          */
816         strcpy(CCC->fake_username, "");
817         strcpy(CCC->fake_hostname, "");
818         strcpy(CCC->fake_roomname, "");
819         CCC->logged_in = 0;
820
821         /* Check to see if the user was deleted whilst logged in and purge them if necessary */
822         if ((CCC->user.axlevel == AxDeleted) && (CCC->user.usernum))
823                 purge_user(CCC->user.fullname);
824
825         /* Clear out the user record in memory so we don't behave like a ghost */
826         memset(&CCC->user, 0, sizeof(struct ctdluser));
827         CCC->curr_user[0] = 0;
828         CCC->is_master = 0;
829         CCC->cs_inet_email[0] = 0;
830         CCC->cs_inet_other_emails[0] = 0;
831         CCC->cs_inet_fn[0] = 0;
832         CCC->fake_username[0] = 0;
833         CCC->fake_hostname[0] = 0;
834         CCC->fake_roomname[0] = 0;
835         
836
837         /* Free any output buffers */
838         unbuffer_output();
839 }
840
841
842 /*
843  * Validate a password on the host unix system by talking to the chkpwd daemon
844  */
845 static int validpw(uid_t uid, const char *pass)
846 {
847         char buf[256];
848         int rv = 0;
849
850         if (IsEmptyStr(pass)) {
851                 syslog(LOG_DEBUG, "Refusing to chkpwd for uid=%d with empty password.\n", uid);
852                 return 0;
853         }
854
855         syslog(LOG_DEBUG, "Validating password for uid=%d using chkpwd...\n", uid);
856
857         begin_critical_section(S_CHKPWD);
858         rv = write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
859         rv = write(chkpwd_write_pipe[1], pass, 256);
860         rv = read(chkpwd_read_pipe[0], buf, 4);
861         end_critical_section(S_CHKPWD);
862
863         if (!strncmp(buf, "PASS", 4)) {
864                 syslog(LOG_DEBUG, "...pass\n");
865                 return(1);
866         }
867
868         syslog(LOG_DEBUG, "...fail\n");
869         return 0;
870 }
871
872 /* 
873  * Start up the chkpwd daemon so validpw() has something to talk to
874  */
875 void start_chkpwd_daemon(void) {
876         pid_t chkpwd_pid;
877         struct stat filestats;
878         int i;
879
880         syslog(LOG_DEBUG, "Starting chkpwd daemon for host authentication mode\n");
881
882         if ((stat(file_chkpwd, &filestats)==-1) ||
883             (filestats.st_size==0)){
884                 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd, strerror(errno));
885                 abort();
886         }
887         if (pipe(chkpwd_write_pipe) != 0) {
888                 syslog(LOG_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
889                 abort();
890         }
891         if (pipe(chkpwd_read_pipe) != 0) {
892                 syslog(LOG_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
893                 abort();
894         }
895
896         chkpwd_pid = fork();
897         if (chkpwd_pid < 0) {
898                 syslog(LOG_EMERG, "Unable to fork chkpwd daemon: %s\n", strerror(errno));
899                 abort();
900         }
901         if (chkpwd_pid == 0) {
902                 syslog(LOG_DEBUG, "Now calling dup2() write\n");
903                 dup2(chkpwd_write_pipe[0], 0);
904                 syslog(LOG_DEBUG, "Now calling dup2() write\n");
905                 dup2(chkpwd_read_pipe[1], 1);
906                 syslog(LOG_DEBUG, "Now closing stuff\n");
907                 for (i=2; i<256; ++i) close(i);
908                 syslog(LOG_DEBUG, "Now calling execl(%s)\n", file_chkpwd);
909                 execl(file_chkpwd, file_chkpwd, NULL);
910                 syslog(LOG_EMERG, "Unable to exec chkpwd daemon: %s\n", strerror(errno));
911                 abort();
912                 exit(errno);
913         }
914 }
915
916
917 int CtdlTryPassword(const char *password, long len)
918 {
919         int code;
920
921         if ((CC->logged_in)) {
922                 syslog(LOG_WARNING, "CtdlTryPassword: already logged in\n");
923                 return pass_already_logged_in;
924         }
925         if (!strcmp(CC->curr_user, NLI)) {
926                 syslog(LOG_WARNING, "CtdlTryPassword: no user selected\n");
927                 return pass_no_user;
928         }
929         if (CtdlGetUser(&CC->user, CC->curr_user)) {
930                 syslog(LOG_ERR, "CtdlTryPassword: internal error\n");
931                 return pass_internal_error;
932         }
933         if (password == NULL) {
934                 syslog(LOG_INFO, "CtdlTryPassword: NULL password string supplied\n");
935                 return pass_wrong_password;
936         }
937         code = (-1);
938
939         if (CC->is_master) {
940                 code = strcmp(password, config.c_master_pass);
941         }
942
943         else if (config.c_auth_mode == AUTHMODE_HOST) {
944
945                 /* host auth mode */
946
947                 if (validpw(CC->user.uid, password)) {
948                         code = 0;
949
950                         /*
951                          * sooper-seekrit hack: populate the password field in the
952                          * citadel database with the password that the user typed,
953                          * if it's correct.  This allows most sites to convert from
954                          * host auth to native auth if they want to.  If you think
955                          * this is a security hazard, comment it out.
956                          */
957
958                         CtdlGetUserLock(&CC->user, CC->curr_user);
959                         safestrncpy(CC->user.password, password, sizeof CC->user.password);
960                         CtdlPutUserLock(&CC->user);
961
962                         /*
963                          * (sooper-seekrit hack ends here)
964                          */
965
966                 }
967                 else {
968                         code = (-1);
969                 }
970         }
971
972 #ifdef HAVE_LDAP
973         else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
974
975                 /* LDAP auth mode */
976
977                 if ((CC->ldap_dn) && (!CtdlTryPasswordLDAP(CC->ldap_dn, password))) {
978                         code = 0;
979                 }
980                 else {
981                         code = (-1);
982                 }
983         }
984 #endif
985
986         else {
987
988                 /* native auth mode */
989                 char *pw;
990
991                 pw = (char*) malloc(len + 1);
992                 memcpy(pw, password, len + 1);
993                 strproc(pw);
994                 strproc(CC->user.password);
995                 code = strcasecmp(CC->user.password, pw);
996                 strproc(pw);
997                 strproc(CC->user.password);
998                 code = strcasecmp(CC->user.password, pw);
999                 free (pw);
1000         }
1001
1002         if (!code) {
1003                 do_login();
1004                 return pass_ok;
1005         } else {
1006                 syslog(LOG_WARNING, "Bad password specified for <%s>\n", CC->curr_user);
1007                 return pass_wrong_password;
1008         }
1009 }
1010
1011
1012 void cmd_pass(char *buf)
1013 {
1014         char password[SIZ];
1015         int a;
1016         long len;
1017
1018         memset(password, 0, sizeof(password));
1019         len = extract_token(password, buf, 0, '|', sizeof password);
1020         a = CtdlTryPassword(password, len);
1021
1022         switch (a) {
1023         case pass_already_logged_in:
1024                 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1025                 return;
1026         case pass_no_user:
1027                 cprintf("%d You must send a name with USER first.\n",
1028                         ERROR + USERNAME_REQUIRED);
1029                 return;
1030         case pass_wrong_password:
1031                 cprintf("%d Wrong password.\n", ERROR + PASSWORD_REQUIRED);
1032                 return;
1033         case pass_ok:
1034                 logged_in_response();
1035                 return;
1036         }
1037 }
1038
1039
1040
1041 /*
1042  * Delete a user record *and* all of its related resources.
1043  */
1044 int purge_user(char pname[])
1045 {
1046         char filename[64];
1047         struct ctdluser usbuf;
1048         char usernamekey[USERNAME_SIZE];
1049
1050         makeuserkey(usernamekey, pname, cutuserkey(pname));
1051
1052         /* If the name is empty we can't find them in the DB any way so just return */
1053         if (IsEmptyStr(pname))
1054                 return (ERROR + NO_SUCH_USER);
1055
1056         if (CtdlGetUser(&usbuf, pname) != 0) {
1057                 syslog(LOG_ERR, "Cannot purge user <%s> - not found\n", pname);
1058                 return (ERROR + NO_SUCH_USER);
1059         }
1060         /* Don't delete a user who is currently logged in.  Instead, just
1061          * set the access level to 0, and let the account get swept up
1062          * during the next purge.
1063          */
1064         if (CtdlIsUserLoggedInByNum(usbuf.usernum)) {
1065                 syslog(LOG_WARNING, "User <%s> is logged in; not deleting.\n", pname);
1066                 usbuf.axlevel = AxDeleted;
1067                 CtdlPutUser(&usbuf);
1068                 return (1);
1069         }
1070         syslog(LOG_NOTICE, "Deleting user <%s>\n", pname);
1071
1072 /*
1073  * FIXME:
1074  * This should all be wrapped in a S_USERS mutex.
1075  * Without the mutex the user could log in before we get to the next function
1076  * That would truly mess things up :-(
1077  * I would like to see the S_USERS start before the CtdlIsUserLoggedInByNum() above
1078  * and end after the user has been deleted from the database, below.
1079  * Question is should we enter the EVT_PURGEUSER whilst S_USERS is active?
1080  */
1081
1082         /* Perform any purge functions registered by server extensions */
1083         PerformUserHooks(&usbuf, EVT_PURGEUSER);
1084
1085         /* delete any existing user/room relationships */
1086         cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
1087
1088         /* delete the users-by-number index record */
1089         cdb_delete(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long));
1090
1091         /* delete the userlog entry */
1092         cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
1093
1094         /* remove the user's bio file */
1095         snprintf(filename, 
1096                          sizeof filename, 
1097                          "%s/%ld",
1098                          ctdl_bio_dir,
1099                          usbuf.usernum);
1100         unlink(filename);
1101
1102         /* remove the user's picture */
1103         snprintf(filename, 
1104                          sizeof filename, 
1105                          "%s/%ld.gif",
1106                          ctdl_image_dir,
1107                          usbuf.usernum);
1108         unlink(filename);
1109
1110         return (0);
1111 }
1112
1113
1114 int internal_create_user (const char *username, long len, struct ctdluser *usbuf, uid_t uid)
1115 {
1116         if (!CtdlGetUserLen(usbuf, username, len)) {
1117                 return (ERROR + ALREADY_EXISTS);
1118         }
1119
1120         /* Go ahead and initialize a new user record */
1121         memset(usbuf, 0, sizeof(struct ctdluser));
1122         safestrncpy(usbuf->fullname, username, sizeof usbuf->fullname);
1123         strcpy(usbuf->password, "");
1124         usbuf->uid = uid;
1125
1126         /* These are the default flags on new accounts */
1127         usbuf->flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
1128
1129         usbuf->timescalled = 0;
1130         usbuf->posted = 0;
1131         usbuf->axlevel = config.c_initax;
1132         usbuf->lastcall = time(NULL);
1133
1134         /* fetch a new user number */
1135         usbuf->usernum = get_new_user_number();
1136
1137         /* add user to the database */
1138         CtdlPutUser(usbuf);
1139         cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1);
1140
1141         return 0;
1142 }
1143
1144
1145
1146 /*
1147  * create_user()  -  back end processing to create a new user
1148  *
1149  * Set 'newusername' to the desired account name.
1150  * Set 'become_user' to nonzero if this is self-service account creation and we want
1151  * to actually log in as the user we just created, otherwise set it to 0.
1152  */
1153 int create_user(const char *newusername, long len, int become_user)
1154 {
1155         struct ctdluser usbuf;
1156         struct ctdlroom qrbuf;
1157         char username[256];
1158         char mailboxname[ROOMNAMELEN];
1159         char buf[SIZ];
1160         int retval;
1161         uid_t uid = (-1);
1162         
1163
1164         safestrncpy(username, newusername, sizeof username);
1165         strproc(username);
1166
1167         
1168         if (config.c_auth_mode == AUTHMODE_HOST) {
1169
1170                 /* host auth mode */
1171
1172                 struct passwd pd;
1173                 struct passwd *tempPwdPtr;
1174                 char pwdbuffer[SIZ];
1175         
1176 #ifdef HAVE_GETPWNAM_R
1177 #ifdef SOLARIS_GETPWUID
1178                 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer));
1179 #else // SOLARIS_GETPWUID
1180                 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
1181 #endif // SOLARIS_GETPWUID
1182 #else // HAVE_GETPWNAM_R
1183                 tempPwdPtr = NULL;
1184 #endif // HAVE_GETPWNAM_R
1185                 if (tempPwdPtr != NULL) {
1186                         extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
1187                         uid = pd.pw_uid;
1188                         if (IsEmptyStr (username))
1189                         {
1190                                 safestrncpy(username, pd.pw_name, sizeof username);
1191                                 len = cutuserkey(username);
1192                         }
1193                 }
1194                 else {
1195                         return (ERROR + NO_SUCH_USER);
1196                 }
1197         }
1198
1199 #ifdef HAVE_LDAP
1200         if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
1201                 if (CtdlTryUserLDAP(username, NULL, 0, username, sizeof username, &uid) != 0) {
1202                         return(ERROR + NO_SUCH_USER);
1203                 }
1204         }
1205 #endif /* HAVE_LDAP */
1206         
1207         if ((retval = internal_create_user(username, len, &usbuf, uid)) != 0)
1208                 return retval;
1209         
1210         /*
1211          * Give the user a private mailbox and a configuration room.
1212          * Make the latter an invisible system room.
1213          */
1214         CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
1215         CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_MAILBOX);
1216
1217         CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
1218         CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_BBS);
1219         if (CtdlGetRoomLock(&qrbuf, mailboxname) == 0) {
1220                 qrbuf.QRflags2 |= QR2_SYSTEM;
1221                 CtdlPutRoomLock(&qrbuf);
1222         }
1223
1224         /* Perform any create functions registered by server extensions */
1225         PerformUserHooks(&usbuf, EVT_NEWUSER);
1226
1227         /* Everything below this line can be bypassed if administratively
1228          * creating a user, instead of doing self-service account creation
1229          */
1230
1231         if (become_user) {
1232                 /* Now become the user we just created */
1233                 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
1234                 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
1235                 do_login();
1236         
1237                 /* Check to make sure we're still who we think we are */
1238                 if (CtdlGetUser(&CC->user, CC->curr_user)) {
1239                         return (ERROR + INTERNAL_ERROR);
1240                 }
1241         }
1242         
1243         snprintf(buf, SIZ, 
1244                 "New user account <%s> has been created, from host %s [%s].\n",
1245                 username,
1246                 CC->cs_host,
1247                 CC->cs_addr
1248         );
1249         CtdlAideMessage(buf, "User Creation Notice");
1250         syslog(LOG_NOTICE, "New user <%s> created\n", username);
1251         return (0);
1252 }
1253
1254
1255
1256 /*
1257  * cmd_newu()  -  create a new user account and log in as that user
1258  */
1259 void cmd_newu(char *cmdbuf)
1260 {
1261         int a;
1262         long len;
1263         char username[26];
1264
1265         if (config.c_auth_mode != AUTHMODE_NATIVE) {
1266                 cprintf("%d This system does not use native mode authentication.\n",
1267                         ERROR + NOT_HERE);
1268                 return;
1269         }
1270
1271         if (config.c_disable_newu) {
1272                 cprintf("%d Self-service user account creation "
1273                         "is disabled on this system.\n", ERROR + NOT_HERE);
1274                 return;
1275         }
1276
1277         if (CC->logged_in) {
1278                 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1279                 return;
1280         }
1281         if (CC->nologin) {
1282                 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
1283                         ERROR + MAX_SESSIONS_EXCEEDED,
1284                         config.c_nodename, config.c_maxsessions);
1285         }
1286         extract_token(username, cmdbuf, 0, '|', sizeof username);
1287         strproc(username);
1288         len = cutuserkey(username);
1289
1290         if (IsEmptyStr(username)) {
1291                 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1292                 return;
1293         }
1294
1295         if ((!strcasecmp(username, "bbs")) ||
1296             (!strcasecmp(username, "new")) ||
1297             (!strcasecmp(username, "."))) {
1298                 cprintf("%d '%s' is an invalid login name.\n", ERROR + ILLEGAL_VALUE, username);
1299                 return;
1300         }
1301
1302         a = create_user(username, len, 1);
1303
1304         if (a == 0) {
1305                 logged_in_response();
1306         } else if (a == ERROR + ALREADY_EXISTS) {
1307                 cprintf("%d '%s' already exists.\n",
1308                         ERROR + ALREADY_EXISTS, username);
1309                 return;
1310         } else if (a == ERROR + INTERNAL_ERROR) {
1311                 cprintf("%d Internal error - user record disappeared?\n",
1312                         ERROR + INTERNAL_ERROR);
1313                 return;
1314         } else {
1315                 cprintf("%d unknown error\n", ERROR + INTERNAL_ERROR);
1316         }
1317 }
1318
1319
1320 /*
1321  * set password - back end api code
1322  */
1323 void CtdlSetPassword(char *new_pw)
1324 {
1325         CtdlGetUserLock(&CC->user, CC->curr_user);
1326         safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
1327         CtdlPutUserLock(&CC->user);
1328         syslog(LOG_INFO, "Password changed for user <%s>\n", CC->curr_user);
1329         PerformSessionHooks(EVT_SETPASS);
1330 }
1331
1332
1333 /*
1334  * set password - citadel protocol implementation
1335  */
1336 void cmd_setp(char *new_pw)
1337 {
1338         int generate_random_password = 0;
1339
1340         if (CtdlAccessCheck(ac_logged_in)) {
1341                 return;
1342         }
1343         if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
1344                 cprintf("%d Not allowed.  Use the 'passwd' command.\n", ERROR + NOT_HERE);
1345                 return;
1346         }
1347         if (CC->is_master) {
1348                 cprintf("%d The master prefix password cannot be changed with this command.\n",
1349                         ERROR + NOT_HERE);
1350                 return;
1351         }
1352
1353         if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
1354                 char random_password[17];
1355                 generate_random_password = 1;
1356                 snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random());
1357                 CtdlSetPassword(random_password);
1358                 cprintf("%d %s\n", CIT_OK, random_password);
1359         }
1360         else {
1361                 strproc(new_pw);
1362                 if (IsEmptyStr(new_pw)) {
1363                         cprintf("%d Password unchanged.\n", CIT_OK);
1364                         return;
1365                 }
1366                 CtdlSetPassword(new_pw);
1367                 cprintf("%d Password changed.\n", CIT_OK);
1368         }
1369 }
1370
1371
1372 /*
1373  * cmd_creu() - administratively create a new user account (do not log in to it)
1374  */
1375 void cmd_creu(char *cmdbuf)
1376 {
1377         int a;
1378         long len;
1379         char username[SIZ];
1380         char password[SIZ];
1381         struct ctdluser tmp;
1382
1383         if (CtdlAccessCheck(ac_aide)) {
1384                 return;
1385         }
1386
1387         extract_token(username, cmdbuf, 0, '|', sizeof username);
1388         extract_token(password, cmdbuf, 1, '|', sizeof password);
1389         ////username[25] = 0;
1390         //password[31] = 0;
1391         strproc(username);
1392         strproc(password);
1393         len = cutuserkey(username);
1394
1395         if (IsEmptyStr(username)) {
1396                 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1397                 return;
1398         }
1399
1400         a = create_user(username, len, 0);
1401
1402         if (a == 0) {
1403                 if (!IsEmptyStr(password)) {
1404                         CtdlGetUserLock(&tmp, username);
1405                         safestrncpy(tmp.password, password, sizeof(tmp.password));
1406                         CtdlPutUserLock(&tmp);
1407                 }
1408                 cprintf("%d User '%s' created %s.\n", CIT_OK, username,
1409                                 (!IsEmptyStr(password)) ? "and password set" :
1410                                 "with no password");
1411                 return;
1412         } else if (a == ERROR + ALREADY_EXISTS) {
1413                 cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username);
1414                 return;
1415         } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
1416                 cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
1417                         ERROR + NO_SUCH_USER);
1418                 return;
1419         } else {
1420                 cprintf("%d An error occurred creating the user account.\n", ERROR + INTERNAL_ERROR);
1421         }
1422 }
1423
1424
1425
1426 /*
1427  * get user parameters
1428  */
1429 void cmd_getu(char *cmdbuf)
1430 {
1431
1432         if (CtdlAccessCheck(ac_logged_in))
1433                 return;
1434
1435         CtdlGetUser(&CC->user, CC->curr_user);
1436         cprintf("%d 80|24|%d|\n",
1437                 CIT_OK,
1438                 (CC->user.flags & US_USER_SET)
1439         );
1440 }
1441
1442 /*
1443  * set user parameters
1444  */
1445 void cmd_setu(char *new_parms)
1446 {
1447         if (CtdlAccessCheck(ac_logged_in))
1448                 return;
1449
1450         if (num_parms(new_parms) < 3) {
1451                 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1452                 return;
1453         }
1454         CtdlGetUserLock(&CC->user, CC->curr_user);
1455         CC->user.flags = CC->user.flags & (~US_USER_SET);
1456         CC->user.flags = CC->user.flags | (extract_int(new_parms, 2) & US_USER_SET);
1457         CtdlPutUserLock(&CC->user);
1458         cprintf("%d Ok\n", CIT_OK);
1459 }
1460
1461 /*
1462  * set last read pointer
1463  */
1464 void cmd_slrp(char *new_ptr)
1465 {
1466         long newlr;
1467         visit vbuf;
1468         visit original_vbuf;
1469
1470         if (CtdlAccessCheck(ac_logged_in)) {
1471                 return;
1472         }
1473
1474         if (!strncasecmp(new_ptr, "highest", 7)) {
1475                 newlr = CC->room.QRhighest;
1476         } else {
1477                 newlr = atol(new_ptr);
1478         }
1479
1480         CtdlGetUserLock(&CC->user, CC->curr_user);
1481
1482         CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1483         memcpy(&original_vbuf, &vbuf, sizeof(visit));
1484         vbuf.v_lastseen = newlr;
1485         snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1486
1487         /* Only rewrite the record if it changed */
1488         if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
1489            || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
1490                 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1491         }
1492
1493         CtdlPutUserLock(&CC->user);
1494         cprintf("%d %ld\n", CIT_OK, newlr);
1495 }
1496
1497
1498 void cmd_seen(char *argbuf) {
1499         long target_msgnum = 0L;
1500         int target_setting = 0;
1501
1502         if (CtdlAccessCheck(ac_logged_in)) {
1503                 return;
1504         }
1505
1506         if (num_parms(argbuf) != 2) {
1507                 cprintf("%d Invalid parameters\n", ERROR + ILLEGAL_VALUE);
1508                 return;
1509         }
1510
1511         target_msgnum = extract_long(argbuf, 0);
1512         target_setting = extract_int(argbuf, 1);
1513
1514         CtdlSetSeen(&target_msgnum, 1, target_setting,
1515                         ctdlsetseen_seen, NULL, NULL);
1516         cprintf("%d OK\n", CIT_OK);
1517 }
1518
1519
1520 void cmd_gtsn(char *argbuf) {
1521         visit vbuf;
1522
1523         if (CtdlAccessCheck(ac_logged_in)) {
1524                 return;
1525         }
1526
1527         /* Learn about the user and room in question */
1528         CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1529
1530         cprintf("%d ", CIT_OK);
1531         client_write(vbuf.v_seen, strlen(vbuf.v_seen));
1532         client_write(HKEY("\n"));
1533 }
1534
1535
1536 /*
1537  * API function for cmd_invt_kick() and anything else that needs to
1538  * invite or kick out a user to/from a room.
1539  * 
1540  * Set iuser to the name of the user, and op to 1=invite or 0=kick
1541  */
1542 int CtdlInvtKick(char *iuser, int op) {
1543         struct ctdluser USscratch;
1544         visit vbuf;
1545         char bbb[SIZ];
1546
1547         if (CtdlGetUser(&USscratch, iuser) != 0) {
1548                 return(1);
1549         }
1550
1551         CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1552         if (op == 1) {
1553                 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1554                 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1555         }
1556         if (op == 0) {
1557                 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1558                 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1559         }
1560         CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1561
1562         /* post a message in Aide> saying what we just did */
1563         snprintf(bbb, sizeof bbb, "%s has been %s \"%s\" by %s.\n",
1564                 iuser,
1565                 ((op == 1) ? "invited to" : "kicked out of"),
1566                 CC->room.QRname,
1567                 CC->user.fullname);
1568         CtdlAideMessage(bbb,"User Admin Message");
1569
1570         return(0);
1571 }
1572
1573
1574 /*
1575  * INVT and KICK commands
1576  */
1577 void cmd_invt_kick(char *iuser, int op) {
1578
1579         /*
1580          * These commands are only allowed by aides, room aides,
1581          * and room namespace owners
1582          */
1583         if (is_room_aide()) {
1584                 /* access granted */
1585         } else if ( ((atol(CC->room.QRname) == CC->user.usernum) ) && (CC->user.usernum != 0) ) {
1586                 /* access granted */
1587         } else {
1588                 /* access denied */
1589                 cprintf("%d Higher access or room ownership required.\n",
1590                         ERROR + HIGHER_ACCESS_REQUIRED);
1591                 return;
1592         }
1593
1594         if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1595                          ROOMNAMELEN)) {
1596                 cprintf("%d Can't add/remove users from this room.\n",
1597                         ERROR + NOT_HERE);
1598                 return;
1599         }
1600
1601         if (CtdlInvtKick(iuser, op) != 0) {
1602                 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1603                 return;
1604         }
1605
1606         cprintf("%d %s %s %s.\n",
1607                 CIT_OK, iuser,
1608                 ((op == 1) ? "invited to" : "kicked out of"),
1609                 CC->room.QRname);
1610         return;
1611 }
1612
1613 void cmd_invt(char *iuser) {cmd_invt_kick(iuser, 1);}
1614 void cmd_kick(char *iuser) {cmd_invt_kick(iuser, 0);}
1615
1616 /*
1617  * Forget (Zap) the current room (API call)
1618  * Returns 0 on success
1619  */
1620 int CtdlForgetThisRoom(void) {
1621         visit vbuf;
1622
1623         /* On some systems, Aides are not allowed to forget rooms */
1624         if (is_aide() && (config.c_aide_zap == 0)
1625            && ((CC->room.QRflags & QR_MAILBOX) == 0)  ) {
1626                 return(1);
1627         }
1628
1629         CtdlGetUserLock(&CC->user, CC->curr_user);
1630         CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1631
1632         vbuf.v_flags = vbuf.v_flags | V_FORGET;
1633         vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1634
1635         CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1636         CtdlPutUserLock(&CC->user);
1637
1638         /* Return to the Lobby, so we don't end up in an undefined room */
1639         CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
1640         return(0);
1641
1642 }
1643
1644
1645 /*
1646  * forget (Zap) the current room
1647  */
1648 void cmd_forg(char *argbuf)
1649 {
1650
1651         if (CtdlAccessCheck(ac_logged_in)) {
1652                 return;
1653         }
1654
1655         if (CtdlForgetThisRoom() == 0) {
1656                 cprintf("%d Ok\n", CIT_OK);
1657         }
1658         else {
1659                 cprintf("%d You may not forget this room.\n", ERROR + NOT_HERE);
1660         }
1661 }
1662
1663 /*
1664  * Get Next Unregistered User
1665  */
1666 void cmd_gnur(char *argbuf)
1667 {
1668         struct cdbdata *cdbus;
1669         struct ctdluser usbuf;
1670
1671         if (CtdlAccessCheck(ac_aide)) {
1672                 return;
1673         }
1674
1675         if ((CitControl.MMflags & MM_VALID) == 0) {
1676                 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1677                 return;
1678         }
1679
1680         /* There are unvalidated users.  Traverse the user database,
1681          * and return the first user we find that needs validation.
1682          */
1683         cdb_rewind(CDB_USERS);
1684         while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1685                 memset(&usbuf, 0, sizeof(struct ctdluser));
1686                 memcpy(&usbuf, cdbus->ptr,
1687                        ((cdbus->len > sizeof(struct ctdluser)) ?
1688                         sizeof(struct ctdluser) : cdbus->len));
1689                 cdb_free(cdbus);
1690                 if ((usbuf.flags & US_NEEDVALID)
1691                     && (usbuf.axlevel > AxDeleted)) {
1692                         cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1693                         cdb_close_cursor(CDB_USERS);
1694                         return;
1695                 }
1696         }
1697
1698         /* If we get to this point, there are no more unvalidated users.
1699          * Therefore we clear the "users need validation" flag.
1700          */
1701
1702         begin_critical_section(S_CONTROL);
1703         get_control();
1704         CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1705         put_control();
1706         end_critical_section(S_CONTROL);
1707         cprintf("%d *** End of registration.\n", CIT_OK);
1708
1709
1710 }
1711
1712
1713 /*
1714  * validate a user
1715  */
1716 void cmd_vali(char *v_args)
1717 {
1718         char user[128];
1719         int newax;
1720         struct ctdluser userbuf;
1721
1722         extract_token(user, v_args, 0, '|', sizeof user);
1723         newax = extract_int(v_args, 1);
1724
1725         if (CtdlAccessCheck(ac_aide) || 
1726             (newax > AxAideU) ||
1727             (newax < AxDeleted)) {
1728                 return;
1729         }
1730
1731         if (CtdlGetUserLock(&userbuf, user) != 0) {
1732                 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1733                 return;
1734         }
1735
1736         userbuf.axlevel = newax;
1737         userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1738
1739         CtdlPutUserLock(&userbuf);
1740
1741         /* If the access level was set to zero, delete the user */
1742         if (newax == 0) {
1743                 if (purge_user(user) == 0) {
1744                         cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1745                         return;
1746                 }
1747         }
1748         cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1749 }
1750
1751
1752
1753 /* 
1754  *  Traverse the user file...
1755  */
1756 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1757                  void *in_data)
1758 {
1759         struct ctdluser usbuf;
1760         struct cdbdata *cdbus;
1761
1762         cdb_rewind(CDB_USERS);
1763
1764         while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1765                 memset(&usbuf, 0, sizeof(struct ctdluser));
1766                 memcpy(&usbuf, cdbus->ptr,
1767                        ((cdbus->len > sizeof(struct ctdluser)) ?
1768                         sizeof(struct ctdluser) : cdbus->len));
1769                 cdb_free(cdbus);
1770                 (*CallBack) (&usbuf, in_data);
1771         }
1772 }
1773
1774
1775 /*
1776  * List one user (this works with cmd_list)
1777  */
1778 void ListThisUser(struct ctdluser *usbuf, void *data)
1779 {
1780         char *searchstring;
1781
1782         searchstring = (char *)data;
1783         if (bmstrcasestr(usbuf->fullname, searchstring) == NULL) {
1784                 return;
1785         }
1786
1787         if (usbuf->axlevel > AxDeleted) {
1788                 if ((CC->user.axlevel >= AxAideU)
1789                     || ((usbuf->flags & US_UNLISTED) == 0)
1790                     || ((CC->internal_pgm))) {
1791                         cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
1792                                 usbuf->fullname,
1793                                 usbuf->axlevel,
1794                                 usbuf->usernum,
1795                                 (long)usbuf->lastcall,
1796                                 usbuf->timescalled,
1797                                 usbuf->posted);
1798                 }
1799         }
1800 }
1801
1802 /* 
1803  *  List users (searchstring may be empty to list all users)
1804  */
1805 void cmd_list(char *cmdbuf)
1806 {
1807         char searchstring[256];
1808         extract_token(searchstring, cmdbuf, 0, '|', sizeof searchstring);
1809         striplt(searchstring);
1810         cprintf("%d \n", LISTING_FOLLOWS);
1811         ForEachUser(ListThisUser, (void *)searchstring );
1812         cprintf("000\n");
1813 }
1814
1815
1816
1817
1818 /*
1819  * assorted info we need to check at login
1820  */
1821 void cmd_chek(char *argbuf)
1822 {
1823         int mail = 0;
1824         int regis = 0;
1825         int vali = 0;
1826
1827         if (CtdlAccessCheck(ac_logged_in)) {
1828                 return;
1829         }
1830
1831         CtdlGetUser(&CC->user, CC->curr_user);  /* no lock is needed here */
1832         if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1833                 regis = 1;
1834
1835         if (CC->user.axlevel >= AxAideU) {
1836                 get_control();
1837                 if (CitControl.MMflags & MM_VALID)
1838                         vali = 1;
1839         }
1840
1841         /* check for mail */
1842         mail = InitialMailCheck();
1843
1844         cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1845 }
1846
1847
1848 /*
1849  * check to see if a user exists
1850  */
1851 void cmd_qusr(char *who)
1852 {
1853         struct ctdluser usbuf;
1854
1855         if (CtdlGetUser(&usbuf, who) == 0) {
1856                 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1857         } else {
1858                 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1859         }
1860 }
1861
1862
1863 /*
1864  * Administrative Get User Parameters
1865  */
1866 void cmd_agup(char *cmdbuf)
1867 {
1868         struct ctdluser usbuf;
1869         char requested_user[128];
1870
1871         if (CtdlAccessCheck(ac_aide)) {
1872                 return;
1873         }
1874
1875         extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1876         if (CtdlGetUser(&usbuf, requested_user) != 0) {
1877                 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1878                 return;
1879         }
1880         cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1881                 CIT_OK,
1882                 usbuf.fullname,
1883                 usbuf.password,
1884                 usbuf.flags,
1885                 usbuf.timescalled,
1886                 usbuf.posted,
1887                 (int) usbuf.axlevel,
1888                 usbuf.usernum,
1889                 (long)usbuf.lastcall,
1890                 usbuf.USuserpurge);
1891 }
1892
1893
1894
1895 /*
1896  * Administrative Set User Parameters
1897  */
1898 void cmd_asup(char *cmdbuf)
1899 {
1900         struct ctdluser usbuf;
1901         char requested_user[128];
1902         char notify[SIZ];
1903         int np;
1904         int newax;
1905         int deleted = 0;
1906
1907         if (CtdlAccessCheck(ac_aide))
1908                 return;
1909
1910         extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1911         if (CtdlGetUserLock(&usbuf, requested_user) != 0) {
1912                 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1913                 return;
1914         }
1915         np = num_parms(cmdbuf);
1916         if (np > 1)
1917                 extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
1918         if (np > 2)
1919                 usbuf.flags = extract_int(cmdbuf, 2);
1920         if (np > 3)
1921                 usbuf.timescalled = extract_int(cmdbuf, 3);
1922         if (np > 4)
1923                 usbuf.posted = extract_int(cmdbuf, 4);
1924         if (np > 5) {
1925                 newax = extract_int(cmdbuf, 5);
1926                 if ((newax >= AxDeleted) && (newax <= AxAideU)) {
1927                         usbuf.axlevel = newax;
1928                 }
1929         }
1930         if (np > 7) {
1931                 usbuf.lastcall = extract_long(cmdbuf, 7);
1932         }
1933         if (np > 8) {
1934                 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1935         }
1936         CtdlPutUserLock(&usbuf);
1937         if (usbuf.axlevel == AxDeleted) {
1938                 if (purge_user(requested_user) == 0) {
1939                         deleted = 1;
1940                 }
1941         }
1942
1943         if (deleted) {
1944                 snprintf(notify, SIZ, 
1945                          "User \"%s\" has been deleted by %s.\n",
1946                          usbuf.fullname, CC->user.fullname);
1947                 CtdlAideMessage(notify, "User Deletion Message");
1948         }
1949
1950         cprintf("%d Ok", CIT_OK);
1951         if (deleted)
1952                 cprintf(" (%s deleted)", requested_user);
1953         cprintf("\n");
1954 }
1955
1956
1957
1958 /*
1959  * Count the number of new mail messages the user has
1960  */
1961 int NewMailCount()
1962 {
1963         int num_newmsgs = 0;
1964
1965         num_newmsgs = CC->newmail;
1966         CC->newmail = 0;
1967
1968         return (num_newmsgs);
1969 }
1970
1971
1972 /*
1973  * Count the number of new mail messages the user has
1974  */
1975 int InitialMailCheck()
1976 {
1977         int num_newmsgs = 0;
1978         int a;
1979         char mailboxname[ROOMNAMELEN];
1980         struct ctdlroom mailbox;
1981         visit vbuf;
1982         struct cdbdata *cdbfr;
1983         long *msglist = NULL;
1984         int num_msgs = 0;
1985
1986         CtdlMailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1987         if (CtdlGetRoom(&mailbox, mailboxname) != 0)
1988                 return (0);
1989         CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1990
1991         cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1992
1993         if (cdbfr != NULL) {
1994                 msglist = malloc(cdbfr->len);
1995                 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1996                 num_msgs = cdbfr->len / sizeof(long);
1997                 cdb_free(cdbfr);
1998         }
1999         if (num_msgs > 0)
2000                 for (a = 0; a < num_msgs; ++a) {
2001                         if (msglist[a] > 0L) {
2002                                 if (msglist[a] > vbuf.v_lastseen) {
2003                                         ++num_newmsgs;
2004                                 }
2005                         }
2006                 }
2007         if (msglist != NULL)
2008                 free(msglist);
2009
2010         return (num_newmsgs);
2011 }
2012
2013
2014
2015 /*
2016  * Set the preferred view for the current user/room combination
2017  */
2018 void cmd_view(char *cmdbuf) {
2019         int requested_view;
2020         visit vbuf;
2021
2022         if (CtdlAccessCheck(ac_logged_in)) {
2023                 return;
2024         }
2025
2026         requested_view = extract_int(cmdbuf, 0);
2027
2028         CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
2029         vbuf.v_view = requested_view;
2030         CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
2031         
2032         cprintf("%d ok\n", CIT_OK);
2033 }
2034
2035
2036 /*
2037  * Rename a user
2038  */
2039 void cmd_renu(char *cmdbuf)
2040 {
2041         int retcode;
2042         char oldname[USERNAME_SIZE];
2043         char newname[USERNAME_SIZE];
2044
2045         if (CtdlAccessCheck(ac_aide)) {
2046                 return;
2047         }
2048
2049         extract_token(oldname, cmdbuf, 0, '|', sizeof oldname);
2050         extract_token(newname, cmdbuf, 1, '|', sizeof newname);
2051
2052         retcode = rename_user(oldname, newname);
2053         switch(retcode) {
2054                 case RENAMEUSER_OK:
2055                         cprintf("%d '%s' has been renamed to '%s'.\n", CIT_OK, oldname, newname);
2056                         return;
2057                 case RENAMEUSER_LOGGED_IN:
2058                         cprintf("%d '%s' is currently logged in and cannot be renamed.\n",
2059                                 ERROR + ALREADY_LOGGED_IN , oldname);
2060                         return;
2061                 case RENAMEUSER_NOT_FOUND:
2062                         cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, oldname);
2063                         return;
2064                 case RENAMEUSER_ALREADY_EXISTS:
2065                         cprintf("%d A user named '%s' already exists.\n", ERROR + ALREADY_EXISTS, newname);
2066                         return;
2067         }
2068
2069         cprintf("%d An unknown error occurred.\n", ERROR);
2070 }
2071
2072
2073
2074 /*****************************************************************************/
2075 /*                      MODULE INITIALIZATION STUFF                          */
2076 /*****************************************************************************/
2077
2078
2079 CTDL_MODULE_INIT(user_ops)
2080 {
2081         if (!threading) {
2082                 CtdlRegisterProtoHook(cmd_user, "USER", "Submit username for login");
2083                 CtdlRegisterProtoHook(cmd_pass, "PASS", "Complete login by submitting a password");
2084                 CtdlRegisterProtoHook(cmd_creu, "CREU", "Create User");
2085                 CtdlRegisterProtoHook(cmd_setp, "SETP", "Set the password for an account");
2086                 CtdlRegisterProtoHook(cmd_getu, "GETU", "Get User parameters");
2087                 CtdlRegisterProtoHook(cmd_setu, "SETU", "Set User parameters");
2088                 CtdlRegisterProtoHook(cmd_slrp, "SLRP", "Set Last Read Pointer");
2089                 CtdlRegisterProtoHook(cmd_invt, "INVT", "Invite a user to a room");
2090                 CtdlRegisterProtoHook(cmd_kick, "KICK", "Kick a user out of a room");
2091                 CtdlRegisterProtoHook(cmd_forg, "FORG", "Forget a room");
2092                 CtdlRegisterProtoHook(cmd_gnur, "GNUR", "Autoconverted. TODO: document me.");
2093                 CtdlRegisterProtoHook(cmd_vali, "VALI", "Validate new users");
2094                 CtdlRegisterProtoHook(cmd_list, "LIST", "List users");
2095                 CtdlRegisterProtoHook(cmd_chek, "CHEK", "Autoconverted. TODO: document me.");
2096                 CtdlRegisterProtoHook(cmd_qusr, "QUSR", "Autoconverted. TODO: document me.");
2097                 CtdlRegisterProtoHook(cmd_agup, "AGUP", "Autoconverted. TODO: document me.");
2098                 CtdlRegisterProtoHook(cmd_asup, "ASUP", "Autoconverted. TODO: document me.");
2099                 CtdlRegisterProtoHook(cmd_seen, "SEEN", "Autoconverted. TODO: document me.");
2100                 CtdlRegisterProtoHook(cmd_gtsn, "GTSN", "Autoconverted. TODO: document me.");
2101                 CtdlRegisterProtoHook(cmd_view, "VIEW", "Autoconverted. TODO: document me.");
2102                 CtdlRegisterProtoHook(cmd_renu, "RENU", "Autoconverted. TODO: document me.");
2103                 CtdlRegisterProtoHook(cmd_newu, "NEWU", "Autoconverted. TODO: document me.");
2104         }
2105         /* return our Subversion id for the Log */
2106         return "user_ops";
2107 }