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