X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fcitadel_dirs.c;fp=citadel%2Fcitadel_dirs.c;h=f1fb3e9a632c1726f3db9c2e32ed03996219a3d7;hb=b9a2089d59579d13694e08b299c2aaf44ef9df6c;hp=0000000000000000000000000000000000000000;hpb=a554ab0a6cc536fdb4265235be703a864c2e5a23;p=citadel.git diff --git a/citadel/citadel_dirs.c b/citadel/citadel_dirs.c new file mode 100644 index 000000000..f1fb3e9a6 --- /dev/null +++ b/citadel/citadel_dirs.c @@ -0,0 +1,72 @@ +/* + * citadel_dirs.c : calculate pathnames for various files used in the Citadel system + * + * Copyright (c) 1987-2021 by the citadel.org team + * + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "citadel.h" +#include "citadel_dirs.h" + +/* + * Generate an associated file name for a room + */ +size_t assoc_file_name(char *buf, size_t n, struct ctdlroom *qrbuf, const char *prefix) { + return snprintf(buf, n, "%s%ld", prefix, qrbuf->QRnumber); +} + + +int create_dir(char *which, long ACCESS, long UID, long GID) { + int rv; + rv = mkdir(which, ACCESS); + if ((rv == -1) && (errno != EEXIST)) { + syslog(LOG_ERR, + "failed to create directory %s: %s", + which, + strerror(errno)); + return rv; + } + rv = chmod(which, ACCESS); + if (rv == -1) { + syslog(LOG_ERR, + "failed to set permissions for directory %s: %s", + which, + strerror(errno)); + return rv; + } + rv = chown(which, UID, GID); + if (rv == -1) { + syslog(LOG_ERR, + "failed to set owner for directory %s: %s", + which, + strerror(errno)); + return rv; + } + return rv; +} + + +int create_run_directories(long UID, long GID) { + int rv = 0; + rv += create_dir(ctdl_message_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); + rv += create_dir(ctdl_file_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); + rv += create_dir(ctdl_key_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); + rv += create_dir(ctdl_run_dir , S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, UID, GID); + return rv; +}