diff options
Diffstat (limited to 'jabberd/main.c')
-rw-r--r-- | jabberd/main.c | 910 |
1 files changed, 0 insertions, 910 deletions
diff --git a/jabberd/main.c b/jabberd/main.c deleted file mode 100644 index de0551f..0000000 --- a/jabberd/main.c +++ /dev/null | |||
@@ -1,910 +0,0 @@ | |||
1 | /* jabberd - a dispatcher program for jabber 2.x | ||
2 | Copyright (C) 2007 Sergey Poznyakoff | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License as published by the | ||
6 | Free Software Foundation; either version 3 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include "jabberd.h" | ||
18 | |||
19 | char *progname; | ||
20 | char *config_file = SYSCONFDIR "/jabberd.cfg"; | ||
21 | int debug_level = 0; | ||
22 | int foreground = 0; | ||
23 | int log_to_stderr = 0; | ||
24 | char *user = "jabber"; | ||
25 | char *syslog_tag = "jabberd"; | ||
26 | int log_facility = LOG_LOCAL7; | ||
27 | int x_argc; | ||
28 | char **x_argv; | ||
29 | char *pidfile = STATEDIR "/jabberd.pid"; | ||
30 | char *ctlfile = STATEDIR "/.jabberd.ctl"; | ||
31 | char *statfile = STATEDIR "/.jabberd.stat"; | ||
32 | unsigned long shutdown_timeout = 5; | ||
33 | mode_t jabberd_umask = 037; | ||
34 | |||
35 | void | ||
36 | syslog_printer (int prio, const char *fmt, va_list ap) | ||
37 | { | ||
38 | #if HAVE_VSYSLOG | ||
39 | vsyslog (prio, fmt, ap); | ||
40 | #else | ||
41 | char buf[128]; | ||
42 | vsnprintf (buf, sizeof buf, fmt, ap); | ||
43 | syslog (prio, "%s", buf); | ||
44 | #endif | ||
45 | } | ||
46 | |||
47 | void | ||
48 | stderr_printer (int prio, const char *fmt, va_list ap) | ||
49 | { | ||
50 | const char *p = gsc_syslog_priority_to_str (prio); | ||
51 | fprintf (stderr, "%s: ", progname); | ||
52 | |||
53 | if (p) | ||
54 | fprintf (stderr, "[%s] ", p); | ||
55 | |||
56 | vfprintf (stderr, fmt, ap); | ||
57 | fputc ('\n', stderr); | ||
58 | } | ||
59 | |||
60 | |||
61 | static void (*log_printer) (int prio, const char *fmt, va_list ap) = | ||
62 | stderr_printer; | ||
63 | |||
64 | void | ||
65 | logmsg (int prio, char *fmt, ...) | ||
66 | { | ||
67 | va_list ap; | ||
68 | va_start (ap, fmt); | ||
69 | log_printer (prio, fmt, ap); | ||
70 | va_end (ap); | ||
71 | } | ||
72 | |||
73 | void * | ||
74 | emalloc (size_t size) | ||
75 | { | ||
76 | char *p = malloc (size); | ||
77 | if (!p) | ||
78 | { | ||
79 | logmsg (LOG_EMERG, "%s", strerror (errno)); | ||
80 | exit (1); | ||
81 | } | ||
82 | return p; | ||
83 | } | ||
84 | |||
85 | void | ||
86 | usage () | ||
87 | { | ||
88 | printf ("usage: jabberd [-Dfehv][-c config][-r tag [tag...]]\n"); | ||
89 | printf ("jabberd -- A dispatcher program for jabber 2.x\n"); | ||
90 | printf ("\n"); | ||
91 | printf ("General-purpose options:\n"); | ||
92 | printf (" -c, --config-file=FILE use this configuration file\n"); | ||
93 | printf (" -D, --debug increase debugging level\n"); | ||
94 | printf (" -e, --stderr use standard error for diagnostics output\n"); | ||
95 | printf (" -f, --foreground run in foreground mode (implies -e)\n"); | ||
96 | printf (" --force start up even if another copy seems to be running\n"); | ||
97 | |||
98 | printf ("\nControlling running instance:\n"); | ||
99 | printf (" --status display status information\n"); | ||
100 | printf (" --stop stop the running copy\n"); | ||
101 | printf (" --reload, --hup reload the running copy\n"); | ||
102 | printf (" -r, --restart tag [tag...] restart named components\n"); | ||
103 | |||
104 | printf ("\nInformational options:\n"); | ||
105 | printf (" -h, --help display this help list\n"); | ||
106 | printf (" -v, --version display program version\n"); | ||
107 | |||
108 | |||
109 | printf ("\n"); | ||
110 | printf ("Report bugs to <%s>\n", PACKAGE_BUGREPORT); | ||
111 | } | ||
112 | |||
113 | |||
114 | /* Configuration file handling */ | ||
115 | |||
116 | void | ||
117 | cfg_syslog_tag (gsc_config_file_t *file, char *kw, char *val, void *unused) | ||
118 | { | ||
119 | syslog_tag = strdup (val); | ||
120 | } | ||
121 | |||
122 | void | ||
123 | cfg_syslog_facility (gsc_config_file_t *file, char *kw, char *val, void *unused) | ||
124 | { | ||
125 | if (gsc_str_to_syslog_facility (val, &log_facility)) | ||
126 | file->error_msg (file->file_name, file->line, "Unknown facility `%s'", | ||
127 | val); | ||
128 | } | ||
129 | |||
130 | void | ||
131 | cfg_user (gsc_config_file_t *file, char *kw, char *val, void *unused) | ||
132 | { | ||
133 | struct passwd *pwd = getpwnam (val); | ||
134 | if (!pwd) | ||
135 | file->error_msg (file->file_name, file->line, "no such user `%s'", | ||
136 | val); | ||
137 | else if (pwd->pw_uid == 0) | ||
138 | file->error_msg (file->file_name, file->line, "user `%s' has zero UID", | ||
139 | val); | ||
140 | else | ||
141 | user = strdup (val); | ||
142 | } | ||
143 | |||
144 | struct group_list | ||
145 | { | ||
146 | struct group_list *next; | ||
147 | gid_t gid; | ||
148 | }; | ||
149 | |||
150 | static struct group_list *group_list; | ||
151 | |||
152 | void | ||
153 | cfg_group (gsc_config_file_t *file, char *kw, char *val, void *unused) | ||
154 | { | ||
155 | struct group *group = getgrnam (val); | ||
156 | if (group) | ||
157 | { | ||
158 | struct group_list *p = emalloc (sizeof *p); | ||
159 | p->gid = group->gr_gid; | ||
160 | p->next = group_list; | ||
161 | group_list = p; | ||
162 | } | ||
163 | else | ||
164 | file->error_msg (file->file_name, file->line, "unknown group `%s'", | ||
165 | val); | ||
166 | } | ||
167 | |||
168 | void | ||
169 | cfg_pidfile (gsc_config_file_t *file, char *kw, char *val, void *unused) | ||
170 | { | ||
171 | pidfile = strdup (val); | ||
172 | } | ||
173 | |||
174 | void | ||
175 | cfg_ctlfile (gsc_config_file_t *file, char *kw, char *val, void *unused) | ||
176 | { | ||
177 | ctlfile = strdup (val); | ||
178 | } | ||
179 | |||
180 | void | ||
181 | cfg_statfile (gsc_config_file_t *file, char *kw, char *val, void *unused) | ||
182 | { | ||
183 | ctlfile = strdup (val); | ||
184 | } | ||
185 | |||
186 | void | ||
187 | cfg_umask (gsc_config_file_t *file, char *kw, char *val, void *unused) | ||
188 | { | ||
189 | char *p; | ||
190 | unsigned long n = strtoul (val, &p, 8); | ||
191 | if (*p) | ||
192 | file->error_msg (file->file_name, file->line, | ||
193 | "invalid umask; stopped near `%s'", p); | ||
194 | else | ||
195 | jabberd_umask = (mode_t) n; | ||
196 | } | ||
197 | |||
198 | void | ||
199 | cfg_prog (gsc_config_file_t *file, char *kw, char *val, void *unused) | ||
200 | { | ||
201 | char *prog = val; | ||
202 | char *p = val; | ||
203 | |||
204 | for (; *p && !isspace (*p); p++) | ||
205 | ; | ||
206 | |||
207 | if (*p) | ||
208 | { | ||
209 | *p++ = 0; | ||
210 | for (; *p && isspace (*p); p++) | ||
211 | ; | ||
212 | |||
213 | val = p; | ||
214 | } | ||
215 | else | ||
216 | val = 0; | ||
217 | |||
218 | register_jabber_process (prog, val); | ||
219 | } | ||
220 | |||
221 | struct transport_rec | ||
222 | { | ||
223 | char *tag; | ||
224 | char *command; | ||
225 | int facility; | ||
226 | int retr[2]; | ||
227 | int depc; | ||
228 | char **depv; | ||
229 | char *pidfile; | ||
230 | }; | ||
231 | |||
232 | static void | ||
233 | cfg_transport_command (gsc_config_file_t *file, char *kw, char *val, void *data) | ||
234 | { | ||
235 | struct transport_rec *prec = data; | ||
236 | prec->command = strdup (val); | ||
237 | } | ||
238 | |||
239 | void | ||
240 | cfg_transport_facility (gsc_config_file_t *file, char *kw, char *val, void *data) | ||
241 | { | ||
242 | struct transport_rec *prec = data; | ||
243 | if (gsc_str_to_syslog_facility (val, &prec->facility)) | ||
244 | file->error_msg (file->file_name, file->line, | ||
245 | "Unknown facility `%s'", | ||
246 | val); | ||
247 | } | ||
248 | |||
249 | void | ||
250 | cfg_transport_stdout (gsc_config_file_t *file, char *kw, char *val, void *data) | ||
251 | { | ||
252 | struct transport_rec *prec = data; | ||
253 | if (gsc_str_to_syslog_priority (val, &prec->retr[RETR_OUT])) | ||
254 | file->error_msg (file->file_name, file |