1 // citadel_dirs.c : calculate pathnames for various files used in the Citadel system
3 // Copyright (c) 1987-2021 by the citadel.org team
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 // The program is distributed without any warranty, expressed or implied.
18 #include <libcitadel.h>
20 #include "citadel_dirs.h"
22 // Generate an associated file name for a room
23 size_t assoc_file_name(char *buf, size_t n, struct ctdlroom *qrbuf, const char *prefix) {
24 return snprintf(buf, n, "%s%ld", prefix, qrbuf->QRnumber);
28 int create_dir(char *which, long ACCESS, long UID, long GID) {
30 rv = mkdir(which, ACCESS);
31 if ((rv == -1) && (errno != EEXIST)) {
33 "failed to create directory %s: %s",
38 rv = chmod(which, ACCESS);
40 syslog(LOG_ERR, "failed to set permissions for directory %s: %s", which, strerror(errno));
43 rv = chown(which, UID, GID);
45 syslog(LOG_ERR, "failed to set owner for directory %s: %s", which, strerror(errno));
52 int create_run_directories(long UID, long GID) {
54 rv += create_dir(ctdl_message_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
55 rv += create_dir(ctdl_file_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
56 rv += create_dir(ctdl_key_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
57 rv += create_dir(ctdl_run_dir , S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, UID, GID);