Removed the "base64" utility program. We've been doing base64 with a library functio...
[citadel.git] / citadel / utillib / citadel_dirs.c
index ff624707408c15484dd1051169705489c714323c..e242db80d03287222e1433fb8dc065ddd84e2e85 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * citadel_dirs.c : calculate pathnames for various files used in the Citadel system
  *
- * Copyright (c) 1987-2012 by the citadel.org team
+ * Copyright (c) 1987-2018 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.
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
+#include <time.h>
 #include <errno.h>
+#include <syslog.h>
 #include <libcitadel.h>
-
-
 #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";
@@ -55,8 +41,7 @@ char ctdl_autoetc_dir[PATH_MAX]="";
 /* attention! this may be non volatile on some oses */
 char ctdl_run_dir[PATH_MAX]="";
 char ctdl_spool_dir[PATH_MAX]="network";
-char ctdl_netout_dir[PATH_MAX]="network/spoolout";
-char ctdl_netin_dir[PATH_MAX]="network/spoolin";
+char ctdl_netdigest_dir[PATH_MAX]="network/digest";
 char ctdl_nettmp_dir[PATH_MAX]="network/spooltmp";
 char ctdl_netcfg_dir[PATH_MAX]="netconfigs";
 char ctdl_utilbin_dir[PATH_MAX]="";
@@ -79,11 +64,7 @@ char file_crpt_file_key[PATH_MAX]="";
 char file_crpt_file_csr[PATH_MAX]="";
 char file_crpt_file_cer[PATH_MAX]="";
 char file_chkpwd[PATH_MAX]="";
-char file_base64[PATH_MAX]="";
 char file_guesstimezone[PATH_MAX]="";
-char file_funambol_msg[PATH_MAX] = "";
-char file_dpsam_conf[PATH_MAX] = "";
-char file_dspam_log[PATH_MAX] = "";
 
 
 
@@ -164,25 +145,13 @@ 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);
        COMPUTE_DIRECTORY(ctdl_image_dir);
        COMPUTE_DIRECTORY(ctdl_info_dir);
@@ -190,9 +159,7 @@ 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);
        StripSlashes(ctdl_image_dir, 1);
        StripSlashes(ctdl_info_dir, 1);
@@ -205,13 +172,11 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, char  *ctdldir,
        basedir=SPOOL_DIR;
 #endif
        COMPUTE_DIRECTORY(ctdl_spool_dir);
-       COMPUTE_DIRECTORY(ctdl_netout_dir);
-       COMPUTE_DIRECTORY(ctdl_netin_dir);
+       COMPUTE_DIRECTORY(ctdl_netdigest_dir);
        COMPUTE_DIRECTORY(ctdl_nettmp_dir);
 
        StripSlashes(ctdl_spool_dir, 1);
-       StripSlashes(ctdl_netout_dir, 1);
-       StripSlashes(ctdl_netin_dir, 1);
+       StripSlashes(ctdl_netdigest_dir, 1);
        StripSlashes(ctdl_nettmp_dir, 1);
 
        /* ok, now we know the dirs, calc some commonly used files */
@@ -287,26 +252,11 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, char  *ctdldir,
                 "%schkpwd",
                 ctdl_utilbin_dir);
        StripSlashes(file_chkpwd, 0);
-       snprintf(file_base64,
-                sizeof file_base64,
-                "%sbase64",
-                ctdl_utilbin_dir);
-       StripSlashes(file_base64, 0);
        snprintf(file_guesstimezone,
                 sizeof file_guesstimezone,
                 "%sguesstimezone.sh",
                 ctdl_utilbin_dir);
 
-       snprintf(file_dpsam_conf,
-                sizeof file_dpsam_conf,
-                "%sdspam.conf",
-                ctdl_etc_dir);
-       StripSlashes(file_dpsam_conf, 0);
-       snprintf(file_dspam_log, 
-                sizeof file_dspam_log, 
-                "%sdspam.log",
-                ctdl_home_directory);
-       StripSlashes(file_dspam_log, 0);
        /* 
         * DIRTY HACK FOLLOWS! due to configs in the network dir in the 
         * legacy installations, we need to calculate ifdeffed here.
@@ -321,18 +271,10 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, char  *ctdldir,
 #endif
                );
        StripSlashes(file_mail_aliases, 0);
-        snprintf(file_funambol_msg,
-                sizeof file_funambol_msg,
-                "%sfunambol_newmail_soap.xml",
-                ctdl_shared_dir);
-       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);
@@ -341,8 +283,7 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, char  *ctdldir,
        DBG_PRINT(ctdl_etc_dir);
        DBG_PRINT(ctdl_run_dir);
        DBG_PRINT(ctdl_spool_dir);
-       DBG_PRINT(ctdl_netout_dir);
-       DBG_PRINT(ctdl_netin_dir);
+       DBG_PRINT(ctdl_netdigest_dir);
        DBG_PRINT(ctdl_nettmp_dir);
        DBG_PRINT(ctdl_netcfg_dir);
        DBG_PRINT(ctdl_bbsbase_dir);
@@ -362,9 +303,7 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, char  *ctdldir,
        DBG_PRINT(file_crpt_file_csr);
        DBG_PRINT(file_crpt_file_cer);
        DBG_PRINT(file_chkpwd);
-       DBG_PRINT(file_base64);
        DBG_PRINT(file_guesstimezone);
-       DBG_PRINT(file_funambol_msg);
 }
 
 
@@ -377,44 +316,83 @@ size_t assoc_file_name(char *buf, size_t n,
        return snprintf(buf, n, "%s%ld", prefix, qrbuf->QRnumber);
 }
 
+void remove_digest_file(struct ctdlroom *room)
+{
+       char buf[PATH_MAX];
+
+       snprintf(buf, PATH_MAX, "%s/%ld.eml", 
+                ctdl_netdigest_dir,
+                room->QRnumber);
+       StripSlashes(buf, 0);
+       unlink(buf);
+}
+
+FILE *create_digest_file(struct ctdlroom *room, int forceCreate)
+{
+       struct stat stbuf;
+       char fn[PATH_MAX];
+       int exists;
+       FILE *fp;
+
+       snprintf(fn, PATH_MAX, "%s/%ld.eml", 
+                ctdl_netdigest_dir,
+                room->QRnumber);
+       StripSlashes(fn, 0);
+
+       exists = stat(fn, &stbuf); 
+       if (!forceCreate && (exists == -1))
+               return NULL;
+       
+       fp = fopen(fn, "w+");
+       if (fp == NULL) {
+               syslog(LOG_EMERG,
+                      "failed to create digest file %s: %s",
+                      fn,
+                      strerror(errno));
+       }
+       return fp;
+}
+
 
 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_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;
 }