* es.po: the correct license for this file was supposed to be GPL v2-or-later, not...
[citadel.git] / citadel / citadel_dirs.c
blob770ee0d5bcaae1212fa742d32c4ac9d8d52b5fbd
1 #include "sysdep.h"
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <stdio.h>
5 #include <sys/stat.h>
6 #include <ctype.h>
7 #include <string.h>
8 #include <limits.h>
11 #if TIME_WITH_SYS_TIME
12 # include <sys/time.h>
13 # include <time.h>
14 #else
15 # if HAVE_SYS_TIME_H
16 # include <sys/time.h>
17 # else
18 # include <time.h>
19 # endif
20 #endif
22 #include <errno.h>
23 #include <libcitadel.h>
26 #include "citadel.h"
28 /* our directories... */
29 char ctdl_home_directory[PATH_MAX] = "";
30 char ctdl_bio_dir[PATH_MAX]="bio";
31 char ctdl_bb_dir[PATH_MAX]="bitbucket";
32 char ctdl_data_dir[PATH_MAX]="data";
33 char ctdl_dspam_dir[PATH_MAX]="dspam";
34 char ctdl_file_dir[PATH_MAX]="files";
35 char ctdl_hlp_dir[PATH_MAX]="help";
36 char ctdl_shared_dir[PATH_MAX]="";
37 char ctdl_image_dir[PATH_MAX]="images";
38 char ctdl_info_dir[PATH_MAX]="info";
39 char ctdl_key_dir[PATH_MAX]=SSL_DIR;
40 char ctdl_message_dir[PATH_MAX]="messages";
41 char ctdl_usrpic_dir[PATH_MAX]="userpics";
42 char ctdl_bbsbase_dir[PATH_MAX]="";
43 char ctdl_etc_dir[PATH_MAX]="";
44 char ctdl_autoetc_dir[PATH_MAX]="";
45 /* attention! this may be non volatile on some oses */
46 char ctdl_run_dir[PATH_MAX]="";
47 char ctdl_spool_dir[PATH_MAX]="network";
48 char ctdl_netout_dir[PATH_MAX]="network/spoolout";
49 char ctdl_netin_dir[PATH_MAX]="network/spoolin";
50 char ctdl_netcfg_dir[PATH_MAX]="netconfigs";
51 char ctdl_utilbin_dir[PATH_MAX]="";
52 char ctdl_sbin_dir[PATH_MAX]="";
53 char ctdl_bin_dir[PATH_MAX]="";
55 /* some of our files, that are needed in several places */
56 char file_citadel_control[PATH_MAX]="";
57 char file_citadel_rc[PATH_MAX]="";
58 char file_citadel_config[PATH_MAX]="";
59 char file_lmtp_socket[PATH_MAX]="";
60 char file_lmtp_unfiltered_socket[PATH_MAX]="";
61 char file_arcq[PATH_MAX]="";
62 char file_citadel_socket[PATH_MAX]="";
63 char file_mail_aliases[PATH_MAX]="";
64 char file_pid_file[PATH_MAX]="";
65 char file_pid_paniclog[PATH_MAX]="";
66 char file_crpt_file_key[PATH_MAX]="";
67 char file_crpt_file_csr[PATH_MAX]="";
68 char file_crpt_file_cer[PATH_MAX]="";
69 char file_chkpwd[PATH_MAX]="";
70 char file_base64[PATH_MAX]="";
71 char file_guesstimezone[PATH_MAX]="";
72 char file_funambol_msg[PATH_MAX] = "";
73 char file_dpsam_conf[PATH_MAX] = "";
74 char file_dspam_log[PATH_MAX] = "";
79 void StripSlashes(char *Dir, int TrailingSlash)
81 char *a, *b;
83 a = b = Dir;
85 while (!IsEmptyStr(a)) {
86 if (*a == '/') {
87 while (*a == '/')
88 a++;
89 *b = '/';
90 b++;
92 else {
93 *b = *a;
94 b++; a++;
97 if ((TrailingSlash) && (*(b - 1) != '/')){
98 *b = '/';
99 b++;
101 *b = '\0';
106 #define COMPUTE_DIRECTORY(SUBDIR) memcpy(dirbuffer,SUBDIR, sizeof dirbuffer);\
107 snprintf(SUBDIR,sizeof SUBDIR, "%s%s%s%s%s%s%s", \
108 (home&!relh)?ctdl_home_directory:basedir, \
109 ((basedir!=ctdldir)&(home&!relh))?basedir:"/", \
110 ((basedir!=ctdldir)&(home&!relh))?"/":"", \
111 relhome, \
112 (relhome[0]!='\0')?"/":"",\
113 dirbuffer,\
114 (dirbuffer[0]!='\0')?"/":"");
116 #define DBG_PRINT(A) if (dbg==1) fprintf (stderr,"%s : %s \n", #A, A)
119 void calc_dirs_n_files(int relh, int home, const char *relhome, char *ctdldir, int dbg)
121 const char* basedir = "";
122 char dirbuffer[PATH_MAX] = "";
125 * Ok, we keep our binaries either in the citadel base dir,
126 * or in /usr/sbin / /usr/bin
128 StripSlashes(ctdldir, 1);
129 #ifdef HAVE_ETC_DIR
130 snprintf(ctdl_sbin_dir, sizeof ctdl_sbin_dir, "/usr/sbin/");
131 snprintf(ctdl_bin_dir, sizeof ctdl_bin_dir, "/usr/bin/");
132 #else
133 snprintf(ctdl_sbin_dir, sizeof ctdl_sbin_dir, ctdldir);
134 snprintf(ctdl_bin_dir, sizeof ctdl_bin_dir, ctdldir);
135 #endif
136 StripSlashes(ctdl_sbin_dir, 1);
137 StripSlashes(ctdl_bin_dir, 1);
139 #ifndef HAVE_AUTO_ETC_DIR
140 basedir=ctdldir;
141 #else
142 basedir=AUTO_ETC_DIR;
143 #endif
144 COMPUTE_DIRECTORY(ctdl_autoetc_dir);
145 StripSlashes(ctdl_autoetc_dir, 1);
147 #ifndef HAVE_ETC_DIR
148 basedir=ctdldir;
149 #else
150 basedir=ETC_DIR;
151 #endif
152 COMPUTE_DIRECTORY(ctdl_netcfg_dir);
153 COMPUTE_DIRECTORY(ctdl_etc_dir);
154 StripSlashes(ctdl_netcfg_dir, 1);
155 StripSlashes(ctdl_etc_dir, 1);
157 #ifndef HAVE_UTILBIN_DIR
158 basedir=ctdldir;
159 #else
160 basedir=UTILBIN_DIR;
161 #endif
162 COMPUTE_DIRECTORY(ctdl_utilbin_dir);
163 StripSlashes(ctdl_utilbin_dir, 1);
165 #ifndef HAVE_RUN_DIR
166 basedir=ctdldir;
167 #else
168 basedir=RUN_DIR;
169 #endif
170 COMPUTE_DIRECTORY(ctdl_run_dir);
171 StripSlashes(ctdl_run_dir, 1);
173 #ifndef HAVE_STATICDATA_DIR
174 basedir=ctdldir;
175 #else
176 basedir=STATICDATA_DIR;
177 #endif
178 COMPUTE_DIRECTORY(ctdl_message_dir);
179 StripSlashes(ctdl_message_dir, 1);
181 #ifndef HAVE_HELP_DIR
182 basedir=ctdldir;
183 #else
184 basedir=HELP_DIR;
185 #endif
186 COMPUTE_DIRECTORY(ctdl_hlp_dir);
187 StripSlashes(ctdl_hlp_dir, 1);
188 COMPUTE_DIRECTORY(ctdl_shared_dir);
189 StripSlashes(ctdl_shared_dir, 1);
191 #ifndef HAVE_DATA_DIR
192 basedir=ctdldir;
193 #else
194 basedir=DATA_DIR;
195 #endif
196 COMPUTE_DIRECTORY(ctdl_bio_dir);
197 COMPUTE_DIRECTORY(ctdl_bb_dir);
198 COMPUTE_DIRECTORY(ctdl_data_dir);
199 COMPUTE_DIRECTORY(ctdl_dspam_dir);
200 COMPUTE_DIRECTORY(ctdl_file_dir);
201 COMPUTE_DIRECTORY(ctdl_image_dir);
202 COMPUTE_DIRECTORY(ctdl_info_dir);
203 COMPUTE_DIRECTORY(ctdl_usrpic_dir);
204 COMPUTE_DIRECTORY(ctdl_bbsbase_dir);
206 StripSlashes(ctdl_bio_dir, 1);
207 StripSlashes(ctdl_bb_dir, 1);
208 StripSlashes(ctdl_data_dir, 1);
209 StripSlashes(ctdl_dspam_dir, 1);
210 StripSlashes(ctdl_file_dir, 1);
211 StripSlashes(ctdl_image_dir, 1);
212 StripSlashes(ctdl_info_dir, 1);
213 StripSlashes(ctdl_usrpic_dir, 1);
214 StripSlashes(ctdl_bbsbase_dir, 1);
216 #ifndef HAVE_SPOOL_DIR
217 basedir=ctdldir;
218 #else
219 basedir=SPOOL_DIR;
220 #endif
221 COMPUTE_DIRECTORY(ctdl_spool_dir);
222 COMPUTE_DIRECTORY(ctdl_netout_dir);
223 COMPUTE_DIRECTORY(ctdl_netin_dir);
225 StripSlashes(ctdl_spool_dir, 1);
226 StripSlashes(ctdl_netout_dir, 1);
227 StripSlashes(ctdl_netin_dir, 1);
229 /* ok, now we know the dirs, calc some commonly used files */
231 snprintf(file_arcq,
232 sizeof file_arcq,
233 "%srefcount_adjustments.dat",
234 ctdl_autoetc_dir);
235 StripSlashes(file_arcq, 0);
236 snprintf(file_citadel_control,
237 sizeof file_citadel_control,
238 "%scitadel.control",
239 ctdl_autoetc_dir
241 StripSlashes(file_citadel_control, 0);
242 snprintf(file_citadel_config,
243 sizeof file_citadel_config,
244 "%scitadel.config",
245 ctdl_autoetc_dir);
246 StripSlashes(file_citadel_config, 0);
247 snprintf(file_citadel_rc,
248 sizeof file_citadel_rc,
249 "%scitadel.rc",
250 ctdl_etc_dir);
251 StripSlashes(file_citadel_rc, 0);
252 snprintf(file_lmtp_socket,
253 sizeof file_lmtp_socket,
254 "%slmtp.socket",
255 ctdl_run_dir);
256 StripSlashes(file_lmtp_socket, 0);
257 snprintf(file_lmtp_unfiltered_socket,
258 sizeof file_lmtp_socket,
259 "%slmtp-unfiltered.socket",
260 ctdl_run_dir);
261 StripSlashes(file_lmtp_unfiltered_socket, 0);
262 snprintf(file_citadel_socket,
263 sizeof file_citadel_socket,
264 "%scitadel.socket",
265 ctdl_run_dir);
266 StripSlashes(file_citadel_socket, 0);
267 snprintf(file_pid_file,
268 sizeof file_pid_file,
269 "%scitadel.pid",
270 ctdl_run_dir);
271 StripSlashes(file_pid_file, 0);
272 snprintf(file_pid_paniclog,
273 sizeof file_pid_paniclog,
274 "%spanic.log",
275 ctdl_home_directory);
276 StripSlashes(file_pid_paniclog, 0);
277 snprintf(file_crpt_file_key,
278 sizeof file_crpt_file_key,
279 "%s/citadel.key",
280 ctdl_key_dir);
281 StripSlashes(file_crpt_file_key, 0);
282 snprintf(file_crpt_file_csr,
283 sizeof file_crpt_file_csr,
284 "%s/citadel.csr",
285 ctdl_key_dir);
286 StripSlashes(file_crpt_file_csr, 0);
287 snprintf(file_crpt_file_cer,
288 sizeof file_crpt_file_cer,
289 "%s/citadel.cer",
290 ctdl_key_dir);
291 StripSlashes(file_crpt_file_cer, 0);
292 snprintf(file_chkpwd,
293 sizeof file_chkpwd,
294 "%schkpwd",
295 ctdl_utilbin_dir);
296 StripSlashes(file_chkpwd, 0);
297 snprintf(file_base64,
298 sizeof file_base64,
299 "%sbase64",
300 ctdl_utilbin_dir);
301 StripSlashes(file_base64, 0);
302 snprintf(file_guesstimezone,
303 sizeof file_guesstimezone,
304 "%sguesstimezone.sh",
305 ctdl_utilbin_dir);
307 snprintf(file_dpsam_conf,
308 sizeof file_dpsam_conf,
309 "%sdspam.conf",
310 ctdl_etc_dir);
311 StripSlashes(file_dpsam_conf, 0);
312 snprintf(file_dspam_log,
313 sizeof file_dspam_log,
314 "%sdspam.log",
315 ctdl_home_directory);
316 StripSlashes(file_dspam_log, 0);
318 * DIRTY HACK FOLLOWS! due to configs in the network dir in the
319 * legacy installations, we need to calculate ifdeffed here.
321 snprintf(file_mail_aliases,
322 sizeof file_mail_aliases,
323 "%smail.aliases",
324 #ifdef HAVE_ETC_DIR
325 ctdl_etc_dir
326 #else
327 ctdl_spool_dir
328 #endif
330 StripSlashes(file_mail_aliases, 0);
331 snprintf(file_funambol_msg,
332 sizeof file_funambol_msg,
333 "%sfunambol_newmail_soap.xml",
334 ctdl_shared_dir);
335 StripSlashes(file_funambol_msg, 0);
337 DBG_PRINT(ctdl_bio_dir);
338 DBG_PRINT(ctdl_bb_dir);
339 DBG_PRINT(ctdl_data_dir);
340 DBG_PRINT(ctdl_dspam_dir);
341 DBG_PRINT(ctdl_file_dir);
342 DBG_PRINT(ctdl_hlp_dir);
343 DBG_PRINT(ctdl_image_dir);
344 DBG_PRINT(ctdl_info_dir);
345 DBG_PRINT(ctdl_key_dir);
346 DBG_PRINT(ctdl_message_dir);
347 DBG_PRINT(ctdl_usrpic_dir);
348 DBG_PRINT(ctdl_etc_dir);
349 DBG_PRINT(ctdl_run_dir);
350 DBG_PRINT(ctdl_spool_dir);
351 DBG_PRINT(ctdl_netout_dir);
352 DBG_PRINT(ctdl_netin_dir);
353 DBG_PRINT(ctdl_netcfg_dir);
354 DBG_PRINT(ctdl_bbsbase_dir);
355 DBG_PRINT(ctdl_sbin_dir);
356 DBG_PRINT(ctdl_bin_dir);
357 DBG_PRINT(ctdl_utilbin_dir);
358 DBG_PRINT(file_citadel_control);
359 DBG_PRINT(file_citadel_rc);
360 DBG_PRINT(file_citadel_config);
361 DBG_PRINT(file_lmtp_socket);
362 DBG_PRINT(file_lmtp_unfiltered_socket);
363 DBG_PRINT(file_arcq);
364 DBG_PRINT(file_citadel_socket);
365 DBG_PRINT(file_mail_aliases);
366 DBG_PRINT(file_pid_file);
367 DBG_PRINT(file_pid_paniclog);
368 DBG_PRINT(file_crpt_file_key);
369 DBG_PRINT(file_crpt_file_csr);
370 DBG_PRINT(file_crpt_file_cer);
371 DBG_PRINT(file_chkpwd);
372 DBG_PRINT(file_base64);
373 DBG_PRINT(file_guesstimezone);
374 DBG_PRINT(file_funambol_msg);
379 * Generate an associated file name for a room
381 void assoc_file_name(char *buf, size_t n,
382 struct ctdlroom *qrbuf, const char *prefix)
384 snprintf(buf, n, "%s%ld", prefix, qrbuf->QRnumber);