"Fossies" - the Fresh Open Source Software Archive

Member "citadel/citadel_dirs.c" (5 Jun 2021, 1863 Bytes) of package /linux/www/citadel.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "citadel_dirs.c" see the Fossies "Dox" file reference documentation.

    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 /*
   23  * Generate an associated file name for a room
   24  */
   25 size_t assoc_file_name(char *buf, size_t n, struct ctdlroom *qrbuf, const char *prefix) {
   26     return snprintf(buf, n, "%s%ld", prefix, qrbuf->QRnumber);
   27 }
   28 
   29 
   30 int create_dir(char *which, long ACCESS, long UID, long GID) {
   31     int rv;
   32     rv = mkdir(which, ACCESS);
   33     if ((rv == -1) && (errno != EEXIST)) {
   34         syslog(LOG_ERR,
   35                "failed to create directory %s: %s",
   36                which,
   37                strerror(errno));
   38         return rv;
   39     }
   40     rv = chmod(which, ACCESS);
   41     if (rv == -1) {
   42         syslog(LOG_ERR,
   43                "failed to set permissions for directory %s: %s",
   44                which,
   45                strerror(errno));
   46         return rv;
   47     }
   48     rv = chown(which, UID, GID);
   49     if (rv == -1) {
   50         syslog(LOG_ERR,
   51                "failed to set owner for directory %s: %s",
   52                which,
   53                strerror(errno));
   54         return rv;
   55     }
   56     return rv;
   57 }
   58 
   59 
   60 int create_run_directories(long UID, long GID) {
   61     int rv = 0;
   62     rv += create_dir(ctdl_message_dir   , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
   63     rv += create_dir(ctdl_file_dir      , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
   64     rv += create_dir(ctdl_key_dir       , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
   65     rv += create_dir(ctdl_run_dir       , S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, UID, GID);
   66     return rv;
   67 }