X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Futillib%2Fcitadel_dirs.c;h=daacbe3d7730e2f63fd2c11ac37f1cf839f91ff3;hb=9afd9114bb74ee65c505c1133cd6c5c5bb90c7de;hp=d9974c90db90f78021133ed964355951ce6eedd4;hpb=2975015a8e6b00893a0ba003f3b086132fb858c8;p=citadel.git diff --git a/citadel/utillib/citadel_dirs.c b/citadel/utillib/citadel_dirs.c index d9974c90d..daacbe3d7 100644 --- a/citadel/utillib/citadel_dirs.c +++ b/citadel/utillib/citadel_dirs.c @@ -1,7 +1,7 @@ /* * citadel_dirs.c : calculate pathnames for various files used in the Citadel system * - * Copyright (c) 1987-2014 by the citadel.org team + * Copyright (c) 1987-2017 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. @@ -19,17 +19,17 @@ #include #include #include +#include #include #include "citadel.h" +#include "citadel_dirs.h" /* our directories... */ char ctdl_home_directory[PATH_MAX] = ""; char ctdl_bio_dir[PATH_MAX]="bio"; -char ctdl_bb_dir[PATH_MAX]="bitbucket"; char ctdl_data_dir[PATH_MAX]="data"; char ctdl_dspam_dir[PATH_MAX]="dspam"; char ctdl_file_dir[PATH_MAX]="files"; -char ctdl_hlp_dir[PATH_MAX]="help"; char ctdl_shared_dir[PATH_MAX]=""; char ctdl_image_dir[PATH_MAX]="images"; char ctdl_info_dir[PATH_MAX]="info"; @@ -152,23 +152,12 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, char *ctdldir, COMPUTE_DIRECTORY(ctdl_message_dir); StripSlashes(ctdl_message_dir, 1); -#ifndef HAVE_HELP_DIR - basedir=ctdldir; -#else - basedir=HELP_DIR; -#endif - COMPUTE_DIRECTORY(ctdl_hlp_dir); - StripSlashes(ctdl_hlp_dir, 1); - COMPUTE_DIRECTORY(ctdl_shared_dir); - StripSlashes(ctdl_shared_dir, 1); - #ifndef HAVE_DATA_DIR basedir=ctdldir; #else basedir=DATA_DIR; #endif COMPUTE_DIRECTORY(ctdl_bio_dir); - COMPUTE_DIRECTORY(ctdl_bb_dir); COMPUTE_DIRECTORY(ctdl_data_dir); COMPUTE_DIRECTORY(ctdl_dspam_dir); COMPUTE_DIRECTORY(ctdl_file_dir); @@ -178,7 +167,6 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, char *ctdldir, COMPUTE_DIRECTORY(ctdl_bbsbase_dir); StripSlashes(ctdl_bio_dir, 1); - StripSlashes(ctdl_bb_dir, 1); StripSlashes(ctdl_data_dir, 1); StripSlashes(ctdl_dspam_dir, 1); StripSlashes(ctdl_file_dir, 1); @@ -318,11 +306,9 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, char *ctdldir, StripSlashes(file_funambol_msg, 0); DBG_PRINT(ctdl_bio_dir); - DBG_PRINT(ctdl_bb_dir); DBG_PRINT(ctdl_data_dir); DBG_PRINT(ctdl_dspam_dir); DBG_PRINT(ctdl_file_dir); - DBG_PRINT(ctdl_hlp_dir); DBG_PRINT(ctdl_image_dir); DBG_PRINT(ctdl_info_dir); DBG_PRINT(ctdl_key_dir); @@ -376,24 +362,31 @@ void remove_digest_file(struct ctdlroom *room) ctdl_netdigest_dir, room->QRnumber); StripSlashes(buf, 0); - fprintf(stderr, "----> %s \n", buf); unlink(buf); } -FILE *create_digest_file(struct ctdlroom *room) +FILE *create_digest_file(struct ctdlroom *room, int forceCreate) { - char buf[PATH_MAX]; + struct stat stbuf; + char fn[PATH_MAX]; + int exists; FILE *fp; - snprintf(buf, PATH_MAX, "%s/%ld.eml", + snprintf(fn, PATH_MAX, "%s/%ld.eml", ctdl_netdigest_dir, room->QRnumber); - StripSlashes(buf, 0); - fprintf(stderr, "----> %s \n", buf); + StripSlashes(fn, 0); + + exists = stat(fn, &stbuf); + if (!forceCreate && (exists == -1)) + return NULL; - fp = fopen(buf, "w+"); + fp = fopen(fn, "w+"); if (fp == NULL) { - + syslog(LOG_EMERG, + "failed to create digest file %s: %s", + fn, + strerror(errno)); } return fp; } @@ -403,39 +396,43 @@ int create_dir(char *which, long ACCESS, long UID, long GID) { int rv; rv = mkdir(which, ACCESS); - if ((rv == -1) && (errno == EEXIST)) + if ((rv == -1) && (errno != EEXIST)) { + syslog(LOG_EMERG, + "failed to create directory %s: %s", + which, + strerror(errno)); return rv; + } rv = chmod(which, ACCESS); - if (rv == -1) + if (rv == -1) { + syslog(LOG_EMERG, + "failed to set permissions for directory %s: %s", + which, + strerror(errno)); return rv; + } rv = chown(which, UID, GID); + if (rv == -1) { + syslog(LOG_EMERG, + "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; - - rv = create_dir(ctdl_info_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); - if (rv != -1) - rv = create_dir(ctdl_bio_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); - if (rv != -1) - rv = create_dir(ctdl_usrpic_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); - if (rv != -1) - rv = create_dir(ctdl_message_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); - if (rv != -1) - rv = create_dir(ctdl_hlp_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); - if (rv != -1) - rv = create_dir(ctdl_image_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); - if (rv != -1) - rv = create_dir(ctdl_bb_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); - if (rv != -1) - rv = create_dir(ctdl_file_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); - if (rv != -1) - rv = create_dir(ctdl_netcfg_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); - if (rv != -1) - rv = create_dir(ctdl_key_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); - if (rv != -1) - rv = create_dir(ctdl_run_dir , S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, UID, 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_spool_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); + rv += create_dir(ctdl_netout_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); + rv += create_dir(ctdl_netin_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); + rv += create_dir(ctdl_netdigest_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1); + rv += create_dir(ctdl_nettmp_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; }