81b597850b1dbfbe00396ea6119ba1014ed80e3e
[citadel.git] / citadel / context.c
1 /*
2  * Citadel context management stuff.
3  * Here's where we (hopefully) have all the code that manipulates contexts.
4  *
5  * Copyright (c) 1987-2011 by the citadel.org team
6  *
7  * This program is open source software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License, version 3.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
15
16 #include "ctdl_module.h"
17 #include "serv_extensions.h"
18 #include "ecrash.h"
19
20 #include "citserver.h"
21 #include "user_ops.h"
22 #include "locate_host.h"
23 #include "context.h"
24 #include "control.h"
25
26 int DebugSession = 0;
27
28 pthread_key_t MyConKey;                         /* TSD key for MyContext() */
29
30
31 CitContext masterCC;
32 CitContext *ContextList = NULL;
33
34 time_t last_purge = 0;                          /* Last dead session purge */
35 int num_sessions = 0;                           /* Current number of sessions */
36 int next_pid = 0;
37
38 /* Flag for single user mode */
39 static int want_single_user = 0;
40
41 /* Try to go single user */
42
43 int CtdlTrySingleUser(void)
44 {
45         int can_do = 0;
46         
47         begin_critical_section(S_SINGLE_USER);
48         if (want_single_user)
49                 can_do = 0;
50         else
51         {
52                 can_do = 1;
53                 want_single_user = 1;
54         }
55         end_critical_section(S_SINGLE_USER);
56         return can_do;
57 }
58
59 void CtdlEndSingleUser(void)
60 {
61         begin_critical_section(S_SINGLE_USER);
62         want_single_user = 0;
63         end_critical_section(S_SINGLE_USER);
64 }
65
66
67 int CtdlWantSingleUser(void)
68 {
69         return want_single_user;
70 }
71
72 int CtdlIsSingleUser(void)
73 {
74         if (want_single_user)
75         {
76                 /* check for only one context here */
77                 if (num_sessions == 1)
78                         return TRUE;
79         }
80         return FALSE;
81 }
82
83
84
85
86
87 /*
88  * Locate a context by its session number and terminate it if the user is able.
89  * User can NOT terminate their current session.
90  * User CAN terminate any other session that has them logged in.
91  * Aide CAN terminate any session except the current one.
92  */
93 int CtdlTerminateOtherSession (int session_num)
94 {
95         struct CitContext *CCC = CC;
96         int ret = 0;
97         CitContext *ccptr;
98         int aide;
99
100         if (session_num == CCC->cs_pid) return TERM_NOTALLOWED;
101
102         aide = ( (CCC->user.axlevel >= AxAideU) || (CCC->internal_pgm) ) ;
103
104         CONM_syslog(LOG_DEBUG, "Locating session to kill\n");
105         begin_critical_section(S_SESSION_TABLE);
106         for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
107                 if (session_num == ccptr->cs_pid) {
108                         ret |= TERM_FOUND;
109                         if ((ccptr->user.usernum == CCC->user.usernum) || aide) {
110                                 ret |= TERM_ALLOWED;
111                         }
112                         break;
113                 }
114         }
115
116         if (((ret & TERM_FOUND) != 0) && ((ret & TERM_ALLOWED) != 0))
117         {
118                 if (ccptr->IO != NULL) {
119                         AsyncIO *IO = ccptr->IO;
120                         end_critical_section(S_SESSION_TABLE);
121                         KillAsyncIOContext(IO);
122                 }
123                 else
124                 {
125                         if (ccptr->user.usernum == CCC->user.usernum)
126                                 ccptr->kill_me = KILLME_ADMIN_TERMINATE;
127                         else
128                                 ccptr->kill_me = KILLME_IDLE;
129                         end_critical_section(S_SESSION_TABLE);
130                 }
131         }
132         else
133                 end_critical_section(S_SESSION_TABLE);
134
135         return ret;
136 }
137
138
139
140 /*
141  * Check to see if the user who we just sent mail to is logged in.  If yes,
142  * bump the 'new mail' counter for their session.  That enables them to
143  * receive a new mail notification without having to hit the database.
144  */
145 void BumpNewMailCounter(long which_user) 
146 {
147         CtdlBumpNewMailCounter(which_user);
148 }
149
150 void CtdlBumpNewMailCounter(long which_user)
151 {
152         CitContext *ptr;
153
154         begin_critical_section(S_SESSION_TABLE);
155
156         for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
157                 if (ptr->user.usernum == which_user) {
158                         ptr->newmail += 1;
159                 }
160         }
161
162         end_critical_section(S_SESSION_TABLE);
163 }
164
165
166 /*
167  * Check to see if a user is currently logged in
168  * Take care with what you do as a result of this test.
169  * The user may not have been logged in when this function was called BUT
170  * because of threading the user might be logged in before you test the result.
171  */
172 int CtdlIsUserLoggedIn (char *user_name)
173 {
174         CitContext *cptr;
175         int ret = 0;
176
177         begin_critical_section (S_SESSION_TABLE);
178         for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
179                 if (!strcasecmp(cptr->user.fullname, user_name)) {
180                         ret = 1;
181                         break;
182                 }
183         }
184         end_critical_section(S_SESSION_TABLE);
185         return ret;
186 }
187
188
189
190 /*
191  * Check to see if a user is currently logged in.
192  * Basically same as CtdlIsUserLoggedIn() but uses the user number instead.
193  * Take care with what you do as a result of this test.
194  * The user may not have been logged in when this function was called BUT
195  * because of threading the user might be logged in before you test the result.
196  */
197 int CtdlIsUserLoggedInByNum (long usernum)
198 {
199         CitContext *cptr;
200         int ret = 0;
201
202         begin_critical_section(S_SESSION_TABLE);
203         for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
204                 if (cptr->user.usernum == usernum) {
205                         ret = 1;
206                 }
207         }
208         end_critical_section(S_SESSION_TABLE);
209         return ret;
210 }
211
212
213
214 /*
215  * Return a pointer to the CitContext structure bound to the thread which
216  * called this function.  If there's no such binding (for example, if it's
217  * called by the housekeeper thread) then a generic 'master' CC is returned.
218  *
219  * This function is used *VERY* frequently and must be kept small.
220  */
221 CitContext *MyContext(void) {
222         register CitContext *c;
223         return ((c = (CitContext *) pthread_getspecific(MyConKey), c == NULL) ? &masterCC : c);
224 }
225
226
227
228
229 /*
230  * Terminate idle sessions.  This function pounds through the session table
231  * comparing the current time to each session's time-of-last-command.  If an
232  * idle session is found it is terminated, then the search restarts at the
233  * beginning because the pointer to our place in the list becomes invalid.
234  */
235 void terminate_idle_sessions(void)
236 {
237         CitContext *ccptr;
238         time_t now;
239         int killed = 0;
240         int longrunners = 0;
241
242         now = time(NULL);
243         begin_critical_section(S_SESSION_TABLE);
244         for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
245                 if (
246                         (ccptr != CC)
247                         && (config.c_sleeping > 0)
248                         && (now - (ccptr->lastcmd) > config.c_sleeping)
249                 ) {
250                         if (!ccptr->dont_term) {
251                                 ccptr->kill_me = KILLME_IDLE;
252                                 ++killed;
253                         }
254                         else {
255                                 ++longrunners;
256                         }
257                 }
258         }
259         end_critical_section(S_SESSION_TABLE);
260         if (killed > 0)
261                 CON_syslog(LOG_INFO, "Scheduled %d idle sessions for termination\n", killed);
262         if (longrunners > 0)
263                 CON_syslog(LOG_INFO, "Didn't terminate %d protected idle sessions", longrunners);
264 }
265
266
267 /*
268  * During shutdown, close the sockets of any sessions still connected.
269  */
270 void terminate_all_sessions(void)
271 {
272         CitContext *ccptr;
273         int killed = 0;
274
275         begin_critical_section(S_SESSION_TABLE);
276         for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
277                 if (ccptr->client_socket != -1)
278                 {
279                         if (ccptr->IO != NULL) {
280                                 CON_syslog(LOG_INFO, "terminate_all_sessions() is murdering %s IO[%ld]CC[%d]", ccptr->curr_user, ccptr->IO->ID, ccptr->cs_pid);
281                         }
282                         else {
283                                 CON_syslog(LOG_INFO, "terminate_all_sessions() is murdering %s CC[%d]", ccptr->curr_user, ccptr->cs_pid);
284                         }
285                         close(ccptr->client_socket);
286                         ccptr->client_socket = -1;
287                         killed++;
288                 }
289         }
290         end_critical_section(S_SESSION_TABLE);
291         if (killed > 0) {
292                 CON_syslog(LOG_INFO, "Flushed %d stuck sessions\n", killed);
293         }
294 }
295
296
297
298 /*
299  * Terminate a session.
300  */
301 void RemoveContext (CitContext *con)
302 {
303         const char *c;
304         if (con == NULL) {
305                 CONM_syslog(LOG_ERR, "WARNING: RemoveContext() called with NULL!");
306                 return;
307         }
308         c = con->ServiceName;
309         if (c == NULL) {
310                 c = "WTF?";
311         }
312         CON_syslog(LOG_DEBUG, "RemoveContext(%s) session %d", c, con->cs_pid);
313 ///     cit_backtrace();
314
315         /* Run any cleanup routines registered by loadable modules.
316          * Note: We have to "become_session()" because the cleanup functions
317          *       might make references to "CC" assuming it's the right one.
318          */
319         become_session(con);
320         CtdlUserLogout();
321         PerformSessionHooks(EVT_STOP);
322         client_close();                         /* If the client is still connected, blow 'em away. */
323         become_session(NULL);
324
325         CON_syslog(LOG_NOTICE, "[%3d]SRV[%s] Session ended.", con->cs_pid, c);
326
327         /* 
328          * If the client is still connected, blow 'em away. 
329          * if the socket is 0 or -1, its already gone or was never there.
330          */
331         if (con->client_socket > 0)
332         {
333                 CON_syslog(LOG_NOTICE, "Closing socket %d", con->client_socket);
334                 close(con->client_socket);
335         }
336
337         /* If using AUTHMODE_LDAP, free the DN */
338         if (con->ldap_dn) {
339                 free(con->ldap_dn);
340                 con->ldap_dn = NULL;
341         }
342         FreeStrBuf(&con->StatusMessage);
343         FreeStrBuf(&con->MigrateBuf);
344         FreeStrBuf(&con->RecvBuf.Buf);
345         if (con->cached_msglist) {
346                 free(con->cached_msglist);
347         }
348
349         CONM_syslog(LOG_DEBUG, "Done with RemoveContext()");
350 }
351
352
353
354 /*
355  * Initialize a new context and place it in the list.  The session number
356  * used to be the PID (which is why it's called cs_pid), but that was when we
357  * had one process per session.  Now we just assign them sequentially, starting
358  * at 1 (don't change it to 0 because masterCC uses 0).
359  */
360 CitContext *CreateNewContext(void) {
361         CitContext *me;
362
363         me = (CitContext *) malloc(sizeof(CitContext));
364         if (me == NULL) {
365                 CONM_syslog(LOG_ALERT, "citserver: can't allocate memory!!\n");
366                 return NULL;
367         }
368         memset(me, 0, sizeof(CitContext));
369
370         /* Give the context a name. Hopefully makes it easier to track */
371         strcpy (me->user.fullname, "SYS_notauth");
372         
373         /* The new context will be created already in the CON_EXECUTING state
374          * in order to prevent another thread from grabbing it while it's
375          * being set up.
376          */
377         me->state = CON_EXECUTING;
378         /*
379          * Generate a unique session number and insert this context into
380          * the list.
381          */
382         me->MigrateBuf = NewStrBuf();
383
384         me->RecvBuf.Buf = NewStrBuf();
385
386         me->lastcmd = time(NULL);       /* set lastcmd to now to prevent idle timer infanticide TODO: if we have a valid IO, use that to set the timer. */
387
388
389         begin_critical_section(S_SESSION_TABLE);
390         me->cs_pid = ++next_pid;
391         me->prev = NULL;
392         me->next = ContextList;
393         ContextList = me;
394         if (me->next != NULL) {
395                 me->next->prev = me;
396         }
397         ++num_sessions;
398         end_critical_section(S_SESSION_TABLE);
399         return (me);
400 }
401
402
403 /*
404  * Initialize a new context and place it in the list.  The session number
405  * used to be the PID (which is why it's called cs_pid), but that was when we
406  * had one process per session.  Now we just assign them sequentially, starting
407  * at 1 (don't change it to 0 because masterCC uses 0).
408  */
409 CitContext *CloneContext(CitContext *CloneMe) {
410         CitContext *me;
411
412         me = (CitContext *) malloc(sizeof(CitContext));
413         if (me == NULL) {
414                 CONM_syslog(LOG_ALERT, "citserver: can't allocate memory!!\n");
415                 return NULL;
416         }
417         memcpy(me, CloneMe, sizeof(CitContext));
418
419         memset(&me->RecvBuf, 0, sizeof(IOBuffer));
420         memset(&me->SendBuf, 0, sizeof(IOBuffer));
421         memset(&me->SBuf, 0, sizeof(IOBuffer));
422         me->MigrateBuf = NULL;
423         me->sMigrateBuf = NULL;
424         me->redirect_buffer = NULL;
425 #ifdef HAVE_OPENSSL
426         me->ssl = NULL;
427 #endif
428
429         me->download_fp = NULL;
430         me->upload_fp = NULL;
431         /// TODO: what about the room/user?
432         me->ma = NULL;
433         me->openid_data = NULL;
434         me->ldap_dn = NULL;
435         me->session_specific_data = NULL;
436         
437         me->CIT_ICAL = NULL;
438
439         me->cached_msglist = NULL;
440         me->download_fp = NULL;
441         me->upload_fp = NULL;
442         me->client_socket = 0;
443
444         me->MigrateBuf = NewStrBuf();
445         me->RecvBuf.Buf = NewStrBuf();
446         
447         begin_critical_section(S_SESSION_TABLE);
448         {
449                 me->cs_pid = ++next_pid;
450                 me->prev = NULL;
451                 me->next = ContextList;
452                 me->lastcmd = time(NULL);       /* set lastcmd to now to prevent idle timer infanticide */
453                 ContextList = me;
454                 if (me->next != NULL) {
455                         me->next->prev = me;
456                 }
457                 ++num_sessions;
458         }
459         end_critical_section(S_SESSION_TABLE);
460         return (me);
461 }
462
463
464 /*
465  * Return an array containing a copy of the context list.
466  * This allows worker threads to perform "for each context" operations without
467  * having to lock and traverse the live list.
468  */
469 CitContext *CtdlGetContextArray(int *count)
470 {
471         int nContexts, i;
472         CitContext *nptr, *cptr;
473         
474         nContexts = num_sessions;
475         nptr = malloc(sizeof(CitContext) * nContexts);
476         if (!nptr) {
477                 *count = 0;
478                 return NULL;
479         }
480         begin_critical_section(S_SESSION_TABLE);
481         for (cptr = ContextList, i=0; cptr != NULL && i < nContexts; cptr = cptr->next, i++) {
482                 memcpy(&nptr[i], cptr, sizeof (CitContext));
483         }
484         end_critical_section (S_SESSION_TABLE);
485         
486         *count = i;
487         return nptr;
488 }
489
490
491
492 /*
493  * Back-end function for starting a session
494  */
495 void begin_session(CitContext *con)
496 {
497         /* 
498          * Initialize some variables specific to our context.
499          */
500         con->logged_in = 0;
501         con->internal_pgm = 0;
502         con->download_fp = NULL;
503         con->upload_fp = NULL;
504         con->cached_msglist = NULL;
505         con->cached_num_msgs = 0;
506         con->FirstExpressMessage = NULL;
507         time(&con->lastcmd);
508         time(&con->lastidle);
509         strcpy(con->lastcmdname, "    ");
510         strcpy(con->cs_clientname, "(unknown)");
511         strcpy(con->curr_user, NLI);
512         *con->net_node = '\0';
513         *con->fake_username = '\0';
514         *con->fake_hostname = '\0';
515         *con->fake_roomname = '\0';
516         *con->cs_clientinfo = '\0';
517         safestrncpy(con->cs_host, config.c_fqdn, sizeof con->cs_host);
518         safestrncpy(con->cs_addr, "", sizeof con->cs_addr);
519         con->cs_UDSclientUID = -1;
520         con->cs_host[sizeof con->cs_host - 1] = 0;
521         if (!CC->is_local_socket) {
522                 locate_host(con->cs_host, sizeof con->cs_host,
523                         con->cs_addr, sizeof con->cs_addr,
524                         con->client_socket
525                 );
526         }
527         else {
528                 con->cs_host[0] = 0;
529                 con->cs_addr[0] = 0;
530 #ifdef HAVE_STRUCT_UCRED
531                 {
532                         /* as http://www.wsinnovations.com/softeng/articles/uds.html told us... */
533                         struct ucred credentials;
534                         socklen_t ucred_length = sizeof(struct ucred);
535                         
536                         /*fill in the user data structure */
537                         if(getsockopt(con->client_socket, SOL_SOCKET, SO_PEERCRED, &credentials, &ucred_length)) {
538                                 syslog(LOG_NOTICE, "could obtain credentials from unix domain socket");
539                                 
540                         }
541                         else {          
542                                 /* the process ID of the process on the other side of the socket */
543                                 /* credentials.pid; */
544                                 
545                                 /* the effective UID of the process on the other side of the socket  */
546                                 con->cs_UDSclientUID = credentials.uid;
547                                 
548                                 /* the effective primary GID of the process on the other side of the socket */
549                                 /* credentials.gid; */
550                                 
551                                 /* To get supplemental groups, we will have to look them up in our account
552                                    database, after a reverse lookup on the UID to get the account name.
553                                    We can take this opportunity to check to see if this is a legit account.
554                                 */
555                                 snprintf(con->cs_clientinfo, sizeof(con->cs_clientinfo),
556                                          "PID: "F_PID_T"; UID: "F_UID_T"; GID: "F_XPID_T" ", 
557                                          credentials.pid,
558                                          credentials.uid,
559                                          credentials.gid);
560                         }
561                 }
562 #endif
563         }
564         con->cs_flags = 0;
565         con->upload_type = UPL_FILE;
566         con->dl_is_net = 0;
567
568         con->nologin = 0;
569         if (((config.c_maxsessions > 0)&&(num_sessions > config.c_maxsessions)) || CtdlWantSingleUser()) {
570                 con->nologin = 1;
571         }
572
573         if (!CC->is_local_socket) {
574                 syslog(LOG_NOTICE, "Session (%s) started from %s (%s).\n", con->ServiceName, con->cs_host, con->cs_addr);
575         }
576         else {
577                 syslog(LOG_NOTICE, "Session (%s) started via local socket UID:%d.\n", con->ServiceName, con->cs_UDSclientUID);
578         }
579
580         /* Run any session startup routines registered by loadable modules */
581         PerformSessionHooks(EVT_START);
582 }
583
584
585 /*
586  * This function fills in a context and its user field correctly
587  * Then creates/loads that user
588  */
589 void CtdlFillSystemContext(CitContext *context, char *name)
590 {
591         char sysname[SIZ];
592         long len;
593
594         memset(context, 0, sizeof(CitContext));
595         context->internal_pgm = 1;
596         context->cs_pid = 0;
597         strcpy (sysname, "SYS_");
598         strcat (sysname, name);
599         len = cutuserkey(sysname);
600         memcpy(context->curr_user, sysname, len + 1);
601         context->client_socket = (-1);
602         context->state = CON_SYS;
603         context->ServiceName = name;
604
605         /* internal_create_user has the side effect of loading the user regardless of wether they
606          * already existed or needed to be created
607          */
608         internal_create_user (sysname, len, &(context->user), -1) ;
609         
610         /* Check to see if the system user needs upgrading */
611         if (context->user.usernum == 0)
612         {       /* old system user with number 0, upgrade it */
613                 context->user.usernum = get_new_user_number();
614                 CON_syslog(LOG_INFO, "Upgrading system user \"%s\" from user number 0 to user number %ld\n", context->user.fullname, context->user.usernum);
615                 /* add user to the database */
616                 CtdlPutUser(&(context->user));
617                 cdb_store(CDB_USERSBYNUMBER, &(context->user.usernum), sizeof(long), context->user.fullname, strlen(context->user.fullname)+1);
618         }
619 }
620
621
622 /*
623  * Cleanup any contexts that are left lying around
624  */
625 void context_cleanup(void)
626 {
627         CitContext *ptr = NULL;
628         CitContext *rem = NULL;
629
630         /*
631          * Clean up the contexts.
632          * There are no threads so no critical_section stuff is needed.
633          */
634         ptr = ContextList;
635         
636         /* We need to update the ContextList because some modules may want to itterate it
637          * Question is should we NULL it before iterating here or should we just keep updating it
638          * as we remove items?
639          *
640          * Answer is to NULL it first to prevent modules from doing any actions on the list at all
641          */
642         ContextList=NULL;
643         while (ptr != NULL){
644                 /* Remove the session from the active list */
645                 rem = ptr->next;
646                 --num_sessions;
647
648                 CON_syslog(LOG_DEBUG, "context_cleanup(): purging session %d\n", ptr->cs_pid);
649                 RemoveContext(ptr);
650                 free (ptr);
651                 ptr = rem;
652         }
653 }
654
655
656
657 /*
658  * Purge all sessions which have the 'kill_me' flag set.
659  * This function has code to prevent it from running more than once every
660  * few seconds, because running it after every single unbind would waste a lot
661  * of CPU time and keep the context list locked too much.  To force it to run
662  * anyway, set "force" to nonzero.
663  */
664 void dead_session_purge(int force) {
665         CitContext *ptr, *ptr2;         /* general-purpose utility pointer */
666         CitContext *rem = NULL;         /* list of sessions to be destroyed */
667         
668         if (force == 0) {
669                 if ( (time(NULL) - last_purge) < 5 ) {
670                         return; /* Too soon, go away */
671                 }
672         }
673         time(&last_purge);
674
675         if (try_critical_section(S_SESSION_TABLE))
676                 return;
677                 
678         ptr = ContextList;
679         while (ptr) {
680                 ptr2 = ptr;
681                 ptr = ptr->next;
682                 
683                 if ( (ptr2->state == CON_IDLE) && (ptr2->kill_me) ) {
684                         /* Remove the session from the active list */
685                         if (ptr2->prev) {
686                                 ptr2->prev->next = ptr2->next;
687                         }
688                         else {
689                                 ContextList = ptr2->next;
690                         }
691                         if (ptr2->next) {
692                                 ptr2->next->prev = ptr2->prev;
693                         }
694
695                         --num_sessions;
696                         /* And put it on our to-be-destroyed list */
697                         ptr2->next = rem;
698                         rem = ptr2;
699                 }
700         }
701         end_critical_section(S_SESSION_TABLE);
702
703         /* Now that we no longer have the session list locked, we can take
704          * our time and destroy any sessions on the to-be-killed list, which
705          * is allocated privately on this thread's stack.
706          */
707         while (rem != NULL) {
708                 CON_syslog(LOG_DEBUG, "dead_session_purge(): purging session %d, reason=%d\n", rem->cs_pid, rem->kill_me);
709                 RemoveContext(rem);
710                 ptr = rem;
711                 rem = rem->next;
712                 free(ptr);
713         }
714 }
715
716
717
718
719
720 /*
721  * masterCC is the context we use when not attached to a session.  This
722  * function initializes it.
723  */
724 void InitializeMasterCC(void) {
725         memset(&masterCC, 0, sizeof(struct CitContext));
726         masterCC.internal_pgm = 1;
727         masterCC.cs_pid = 0;
728 }
729
730
731
732
733
734 /*
735  * Set the "async waiting" flag for a session, if applicable
736  */
737 void set_async_waiting(struct CitContext *ccptr)
738 {
739         CON_syslog(LOG_DEBUG, "Setting async_waiting flag for session %d\n", ccptr->cs_pid);
740         if (ccptr->is_async) {
741                 ccptr->async_waiting++;
742                 if (ccptr->state == CON_IDLE) {
743                         ccptr->state = CON_READY;
744                 }
745         }
746 }
747
748
749 void DebugSessionEnable(const int n)
750 {
751         DebugSession = n;
752 }
753 CTDL_MODULE_INIT(session)
754 {
755         if (!threading) {
756                 CtdlRegisterDebugFlagHook(HKEY("session"), DebugSessionEnable, &DebugSession);
757         }
758         return "session";
759 }