citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
citserver.c
Go to the documentation of this file.
1// Main source module for the Citadel server
2//
3// Copyright (c) 1987-2022 by the citadel.org team
4//
5// This program is open source software. Use, duplication, or disclosure
6// is subject to the terms of the GNU General Public License, version 3.
7
8#include <stdlib.h>
9#include <unistd.h>
10#include <stdio.h>
11#include <sys/stat.h>
12#include "sysdep.h"
13#include <time.h>
14#include <libcitadel.h>
15
16#include "ctdl_module.h"
17#include "housekeeping.h"
18#include "locate_host.h"
19#include "citserver.h"
20#include "user_ops.h"
21#include "control.h"
22#include "config.h"
23
29
30
31// We need pseudo-random numbers for a few things. Seed generously.
33 FILE *urandom;
34 struct timeval tv;
35 unsigned int seed;
36
37 syslog(LOG_INFO, "Seeding the pseudo-random number generator...");
38 urandom = fopen("/dev/urandom", "r");
39 if (urandom != NULL) {
40 if (fread(&seed, sizeof seed, 1, urandom) == -1) {
41 syslog(LOG_ERR, "citserver: failed to read random seed: %m");
42 }
43 fclose(urandom);
44 }
45 else {
46 gettimeofday(&tv, NULL);
47 seed = tv.tv_usec;
48 }
49 srand(seed);
50 srandom(seed);
51}
52
53
54// Various things that need to be initialized at startup
55void master_startup(void) {
56 struct ctdlroom qrbuf;
57 struct passwd *pw;
58 gid_t gid;
59
60 syslog(LOG_DEBUG, "master_startup() started");
62
63 syslog(LOG_INFO, "Checking directory access");
64 if ((pw = getpwuid(ctdluid)) == NULL) {
65 gid = getgid();
66 }
67 else {
68 gid = pw->pw_gid;
69 }
70
71 if (create_run_directories(CTDLUID, gid) != 0) {
72 syslog(LOG_ERR, "citserver: failed to access and create directories");
73 exit(1);
74 }
75
76 syslog(LOG_DEBUG, "citserver: ctdl_message_dir is %s", ctdl_message_dir);
77 syslog(LOG_DEBUG, "citserver: ctdl_file_dir is %s", ctdl_file_dir);
78 syslog(LOG_DEBUG, "citserver: ctdl_key_dir is %s", ctdl_key_dir);
79 syslog(LOG_DEBUG, "citserver: ctdl_run_dir is %s", ctdl_run_dir);
80
81 syslog(LOG_INFO, "Opening databases");
83
84 // Load site-specific configuration
85 seed_random_number_generator(); // must be done before config system
86 syslog(LOG_INFO, "Initializing configuration system");
90
91 // If we have an existing database that is older than version 928, reindex the user records.
92 // Unfortunately we cannot do this in serv_upgrade.c because it needs to happen VERY early during startup.
93 int existing_db = CtdlGetConfigInt("MM_hosted_upgrade_level");
94 if ( (existing_db > 0) && (existing_db < 928) ) {
96 }
97
98 // Check floor reference counts
100
101 syslog(LOG_INFO, "Creating base rooms (if necessary)");
102 CtdlCreateRoom(CtdlGetConfigStr("c_baseroom"), 0, "", 0, 1, 0, VIEW_BBS);
103 CtdlCreateRoom(AIDEROOM, 3, "", 0, 1, 0, VIEW_BBS);
104 CtdlCreateRoom(SYSCONFIGROOM, 3, "", 0, 1, 0, VIEW_BBS);
105 CtdlCreateRoom(CtdlGetConfigStr("c_twitroom"), 0, "", 0, 1, 0, VIEW_BBS);
106
107 // The "Local System Configuration" room doesn't need to be visible
108 if (CtdlGetRoomLock(&qrbuf, SYSCONFIGROOM) == 0) {
111 }
112
113 // Aide needs to be public postable, else we're not RFC conformant.
114 if (CtdlGetRoomLock(&qrbuf, AIDEROOM) == 0) {
117 }
118
119 syslog(LOG_DEBUG, "master_startup() finished");
120}
121
122
123// Cleanup routine to be called when the server is shutting down. Returns the needed exit code.
124int master_cleanup(int exitcode) {
125 static int already_cleaning_up = 0;
126
127 if (already_cleaning_up) {
128 while (1) {
129 usleep(1000000);
130 }
131 }
132 already_cleaning_up = 1;
133
134 // Do system-dependent stuff
136
137 // Close the configuration system
139
140 // Close databases
141 syslog(LOG_INFO, "citserver: closing databases");
143
144 // If the operator requested a halt but not an exit, halt here.
145 if (shutdown_and_halt) {
146 syslog(LOG_ERR, "citserver: Halting server without exiting.");
147 fflush(stdout);
148 fflush(stderr);
149 while (1) {
150 sleep(32767);
151 }
152 }
153
154 // Now go away.
155 syslog(LOG_ERR, "citserver: Exiting with status %d", exitcode);
156 fflush(stdout);
157 fflush(stderr);
158
159 if (restart_server != 0) {
160 exitcode = 1;
161 }
162 else if ((running_as_daemon != 0) && ((exitcode == 0))) {
163 exitcode = CTDLEXIT_SHUTDOWN;
164 }
165 return (exitcode);
166}
167
168
169// returns an asterisk if there are any instant messages waiting, space otherwise.
171 if (CC->FirstExpressMessage == NULL) {
172 return (' ');
173 }
174 else {
175 return ('*');
176 }
177}
178
179
181 if (CC->nologin == 1) {
182 cprintf("%d Too many users are already online (maximum is %d)\n",
184 );
186 }
187 else {
188 cprintf("%d %s Citadel server ready.\n", CIT_OK, CtdlGetConfigStr("c_fqdn"));
189 CC->can_receive_im = 1;
190 }
191}
192
193
195 CC->internal_pgm = 1;
196 cprintf("%d %s Citadel server ADMIN CONNECTION ready.\n", CIT_OK, CtdlGetConfigStr("c_fqdn"));
197}
198
199
200// This loop performs all asynchronous functions.
201void do_async_loop(void) {
203}
int create_run_directories(long UID, long GID)
Definition: citadel_dirs.c:51
#define ctdl_message_dir
Definition: citadel_dirs.h:20
#define ctdl_run_dir
Definition: citadel_dirs.h:23
#define ctdl_file_dir
Definition: citadel_dirs.h:15
#define ctdl_key_dir
Definition: citadel_dirs.h:19
char CtdlCheckExpress(void)
Definition: citserver.c:170
time_t server_startup_time
Definition: citserver.c:26
int master_cleanup(int exitcode)
Definition: citserver.c:124
int openid_level_supported
Definition: citserver.c:28
void master_startup(void)
Definition: citserver.c:55
void citproto_begin_session()
Definition: citserver.c:180
int ScheduledShutdown
Definition: citserver.c:25
int panic_fd
Definition: citserver.c:27
char * unique_session_numbers
Definition: citserver.c:24
void do_async_loop(void)
Definition: citserver.c:201
void seed_random_number_generator(void)
Definition: citserver.c:32
void citproto_begin_admin_session()
Definition: citserver.c:194
char * CtdlGetConfigStr(char *key)
Definition: config.c:363
void shutdown_config_system(void)
Definition: config.c:302
void initialize_config_system(void)
Definition: config.c:214
int CtdlGetConfigInt(char *key)
Definition: config.c:390
void validate_config(void)
Definition: config.c:40
#define CC
Definition: context.h:140
void migrate_legacy_control_record(void)
Definition: control.c:111
int CtdlGetRoomLock(struct ctdlroom *qrbuf, const char *room_name)
Definition: room_ops.c:352
#define CTDLUID
Definition: ctdl_module.h:262
unsigned CtdlCreateRoom(char *new_room_name, int new_room_type, char *new_room_pass, int new_room_floor, int really_create, int avoid_access, int new_room_view)
Definition: room_ops.c:1035
void CtdlPutRoomLock(struct ctdlroom *qrbuf)
Definition: room_ops.c:400
void open_databases(void)
Definition: database.c:172
void close_databases(void)
Definition: database.c:305
void check_ref_counts(void)
Definition: housekeeping.c:40
#define CIT_OK
Definition: ipcdef.h:6
#define QR2_SMTP_PUBLIC
Definition: ipcdef.h:59
#define ERROR
Definition: ipcdef.h:9
#define MAX_SESSIONS_EXCEEDED
Definition: ipcdef.h:24
#define QR2_SYSTEM
Definition: ipcdef.h:55
void PerformSessionHooks(int EventType)
struct ctdlroom qrbuf
Definition: serv_migrate.c:497
uid_t ctdluid
Definition: server_main.c:24
#define CTDLEXIT_SHUTDOWN
Definition: server.h:66
#define EVT_ASYNC
Definition: server.h:220
@ KILLME_MAX_SESSIONS_EXCEEDED
Definition: server.h:92
unsigned QRflags2
Definition: citadel.h:107
#define AIDEROOM
Definition: sysconfig.h:63
#define SYSCONFIGROOM
Definition: sysconfig.h:72
void cprintf(const char *format,...)
Definition: sysdep.c:369
void sysdep_master_cleanup(void)
Definition: sysdep.c:559
volatile int restart_server
Definition: sysdep.c:42
volatile int shutdown_and_halt
Definition: sysdep.c:41
volatile int running_as_daemon
Definition: sysdep.c:43
void ForEachUser(void(*CallBack)(char *, void *out_data), void *in_data)
Definition: user_ops.c:1077
void reindex_user_928(char *username, void *out_data)
Definition: user_ops.c:198