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