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