citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

citadel_dirs.c
Go to the documentation of this file.
1// citadel_dirs.c : calculate pathnames for various files used in the Citadel system
2//
3// Copyright (c) 1987-2021 by the citadel.org team
4//
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.
8
9#include <unistd.h>
10#include <stdio.h>
11#include <sys/stat.h>
12#include <ctype.h>
13#include <string.h>
14#include <limits.h>
15#include <time.h>
16#include <errno.h>
17#include <syslog.h>
18#include <libcitadel.h>
19#include "citadel.h"
20#include "citadel_dirs.h"
21
22// Generate an associated file name for a room
23size_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);
25}
26
27
28int create_dir(char *which, long ACCESS, long UID, long GID) {
29 int rv;
30 rv = mkdir(which, ACCESS);
31 if ((rv == -1) && (errno != EEXIST)) {
32 syslog(LOG_ERR,
33 "failed to create directory %s: %s",
34 which,
35 strerror(errno));
36 return rv;
37 }
38 rv = chmod(which, ACCESS);
39 if (rv == -1) {
40 syslog(LOG_ERR, "failed to set permissions for directory %s: %s", which, strerror(errno));
41 return rv;
42 }
43 rv = chown(which, UID, GID);
44 if (rv == -1) {
45 syslog(LOG_ERR, "failed to set owner for directory %s: %s", which, strerror(errno));
46 return rv;
47 }
48 return rv;
49}
50
51
52int create_run_directories(long UID, long GID) {
53 int rv = 0;
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);
58 return rv;
59}
size_t assoc_file_name(char *buf, size_t n, struct ctdlroom *qrbuf, const char *prefix)
Definition: citadel_dirs.c:23
int create_dir(char *which, long ACCESS, long UID, long GID)
Definition: citadel_dirs.c:28
int create_run_directories(long UID, long GID)
Definition: citadel_dirs.c:52
#define ctdl_message_dir
Definition: citadel_dirs.h:20
#define ctdl_run_dir
Definition: citadel_dirs.h:23
#define ctdl_file_dir
Definition: citadel_dirs.h:15
#define ctdl_key_dir
Definition: citadel_dirs.h:19
struct ctdlroom qrbuf
Definition: serv_migrate.c:497
long QRnumber
Definition: citadel.h:105