2 * citadel_dirs.c : calculate pathnames for various files used in the Citadel system
4 * Copyright (c) 1987-2021 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
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.
23 #include <libcitadel.h>
25 #include "citadel_dirs.h"
28 * Generate an associated file name for a room
30 size_t assoc_file_name(char *buf, size_t n, struct ctdlroom *qrbuf, const char *prefix) {
31 return snprintf(buf, n, "%s%ld", prefix, qrbuf->QRnumber);
35 int create_dir(char *which, long ACCESS, long UID, long GID) {
37 rv = mkdir(which, ACCESS);
38 if ((rv == -1) && (errno != EEXIST)) {
40 "failed to create directory %s: %s",
45 rv = chmod(which, ACCESS);
48 "failed to set permissions for directory %s: %s",
53 rv = chown(which, UID, GID);
56 "failed to set owner for directory %s: %s",
65 int create_run_directories(long UID, long GID) {
67 rv += create_dir(ctdl_message_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
68 rv += create_dir(ctdl_file_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
69 rv += create_dir(ctdl_key_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
70 rv += create_dir(ctdl_run_dir , S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, UID, GID);