* Added a subcommand to the migrator to list out all of the directories which require...
[citadel.git] / citadel / citadel_dirs.c
index bade7734acf9f0060f1c62a2d59458f678a82226..6aa74959b267d5689bca109c0fcf55db2ce03691 100644 (file)
@@ -1,5 +1,3 @@
-#include "sysdep.h"
-#include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/stat.h>
@@ -20,7 +18,7 @@
 #endif
 
 #include <errno.h>
-
+#include <libcitadel.h>
 
 
 #include "citadel.h"
@@ -33,6 +31,7 @@ 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";
 char ctdl_key_dir[PATH_MAX]=SSL_DIR;
@@ -40,6 +39,7 @@ char ctdl_message_dir[PATH_MAX]="messages";
 char ctdl_usrpic_dir[PATH_MAX]="userpics";
 char ctdl_bbsbase_dir[PATH_MAX]="";
 char ctdl_etc_dir[PATH_MAX]="";
+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";
@@ -66,21 +66,41 @@ 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] = "";
-
-int home_specified = 0;
-
-
+char file_dpsam_conf[PATH_MAX] = "";
+char file_dspam_log[PATH_MAX] = "";
 
 
 
 
+void StripSlashes(char *Dir, int TrailingSlash)
+{
+       char *a, *b;
+
+       a = b = Dir;
+
+       while (!IsEmptyStr(a)) {
+               if (*a == '/') {
+                       while (*a == '/')
+                               a++;
+                       *b = '/';
+                       b++;
+               }
+               else {
+                       *b = *a;
+                       b++; a++;
+               }
+       }
+       if ((TrailingSlash) && (*(b - 1) != '/')){
+               *b = '/';
+               b++;
+       }
+       *b = '\0';
 
+}
 
 
-       /* calculate all our path on a central place */
-    /* where to keep our config */
-       
 #define COMPUTE_DIRECTORY(SUBDIR) memcpy(dirbuffer,SUBDIR, sizeof dirbuffer);\
        snprintf(SUBDIR,sizeof SUBDIR,  "%s%s%s%s%s%s%s", \
                         (home&!relh)?ctdl_home_directory:basedir, \
@@ -94,7 +114,7 @@ int home_specified = 0;
 #define DBG_PRINT(A) if (dbg==1) fprintf (stderr,"%s : %s \n", #A, A)
 
 
-void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctdldir, int dbg)
+void calc_dirs_n_files(int relh, int home, const char *relhome, char  *ctdldir, int dbg)
 {
        const char* basedir = "";
        char dirbuffer[PATH_MAX] = "";
@@ -103,6 +123,7 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
         * Ok, we keep our binaries either in the citadel base dir,
         * or in /usr/sbin / /usr/bin
         */
+       StripSlashes(ctdldir, 1);
 #ifdef HAVE_ETC_DIR
        snprintf(ctdl_sbin_dir, sizeof ctdl_sbin_dir, "/usr/sbin/");
        snprintf(ctdl_bin_dir, sizeof ctdl_bin_dir, "/usr/bin/");
@@ -110,6 +131,16 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
        snprintf(ctdl_sbin_dir, sizeof ctdl_sbin_dir, ctdldir);
        snprintf(ctdl_bin_dir, sizeof ctdl_bin_dir, ctdldir);
 #endif
+       StripSlashes(ctdl_sbin_dir, 1);
+       StripSlashes(ctdl_bin_dir, 1);
+
+#ifndef HAVE_AUTO_ETC_DIR
+       basedir=ctdldir;
+#else
+       basedir=AUTO_ETC_DIR;
+#endif
+       COMPUTE_DIRECTORY(ctdl_autoetc_dir);
+       StripSlashes(ctdl_autoetc_dir, 1);
 
 #ifndef HAVE_ETC_DIR
        basedir=ctdldir;
@@ -118,6 +149,8 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
 #endif
        COMPUTE_DIRECTORY(ctdl_netcfg_dir);
        COMPUTE_DIRECTORY(ctdl_etc_dir);
+       StripSlashes(ctdl_netcfg_dir, 1);
+       StripSlashes(ctdl_etc_dir, 1);
 
 #ifndef HAVE_UTILBIN_DIR
        basedir=ctdldir;
@@ -125,6 +158,7 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
        basedir=UTILBIN_DIR;
 #endif
        COMPUTE_DIRECTORY(ctdl_utilbin_dir);
+       StripSlashes(ctdl_utilbin_dir, 1);
 
 #ifndef HAVE_RUN_DIR
        basedir=ctdldir;
@@ -132,14 +166,25 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
        basedir=RUN_DIR;
 #endif
        COMPUTE_DIRECTORY(ctdl_run_dir);
+       StripSlashes(ctdl_run_dir, 1);
 
 #ifndef HAVE_STATICDATA_DIR
        basedir=ctdldir;
 #else
        basedir=STATICDATA_DIR;
 #endif
-       COMPUTE_DIRECTORY(ctdl_hlp_dir);
        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;
@@ -155,6 +200,17 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
        COMPUTE_DIRECTORY(ctdl_info_dir);
        COMPUTE_DIRECTORY(ctdl_usrpic_dir);
        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);
+       StripSlashes(ctdl_usrpic_dir, 1);
+       StripSlashes(ctdl_bbsbase_dir, 1);
+
 #ifndef HAVE_SPOOL_DIR
        basedir=ctdldir;
 #else
@@ -164,75 +220,98 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
        COMPUTE_DIRECTORY(ctdl_netout_dir);
        COMPUTE_DIRECTORY(ctdl_netin_dir);
 
+       StripSlashes(ctdl_spool_dir, 1);
+       StripSlashes(ctdl_netout_dir, 1);
+       StripSlashes(ctdl_netin_dir, 1);
+
        /* ok, now we know the dirs, calc some commonly used files */
 
        snprintf(file_arcq, 
                         sizeof file_arcq,
                         "%srefcount_adjustments.dat",
-                        ctdl_etc_dir);
-
+                        ctdl_autoetc_dir);
+       StripSlashes(file_arcq, 0);
        snprintf(file_citadel_control, 
                         sizeof file_citadel_control,
                         "%scitadel.control",
-                        ctdl_etc_dir
+                        ctdl_autoetc_dir
                         );
-
+       StripSlashes(file_citadel_control, 0);
        snprintf(file_citadel_config, 
                         sizeof file_citadel_config,
                         "%scitadel.config",
-                        ctdl_etc_dir);
-
+                        ctdl_autoetc_dir);
+       StripSlashes(file_citadel_config, 0);
        snprintf(file_citadel_rc, 
                         sizeof file_citadel_rc,
                         "%scitadel.rc",
                         ctdl_etc_dir);
-
+       StripSlashes(file_citadel_rc, 0);
        snprintf(file_lmtp_socket, 
                         sizeof file_lmtp_socket,
                         "%slmtp.socket",
                         ctdl_run_dir);
-
+       StripSlashes(file_lmtp_socket, 0);
        snprintf(file_lmtp_unfiltered_socket, 
                         sizeof file_lmtp_socket,
                         "%slmtp-unfiltered.socket",
                         ctdl_run_dir);
-
+       StripSlashes(file_lmtp_unfiltered_socket, 0);
        snprintf(file_citadel_socket, 
                         sizeof file_citadel_socket,
                                "%scitadel.socket",
                         ctdl_run_dir);
+       StripSlashes(file_citadel_socket, 0);
        snprintf(file_pid_file, 
                 sizeof file_pid_file,
                 "%scitadel.pid",
                 ctdl_run_dir);
+       StripSlashes(file_pid_file, 0);
        snprintf(file_pid_paniclog, 
                 sizeof file_pid_paniclog, 
                 "%spanic.log",
                 ctdl_home_directory);
+       StripSlashes(file_pid_paniclog, 0);
        snprintf(file_crpt_file_key,
                 sizeof file_crpt_file_key, 
                 "%s/citadel.key",
                 ctdl_key_dir);
+       StripSlashes(file_crpt_file_key, 0);
        snprintf(file_crpt_file_csr,
                 sizeof file_crpt_file_csr, 
                 "%s/citadel.csr",
                 ctdl_key_dir);
+       StripSlashes(file_crpt_file_csr, 0);
        snprintf(file_crpt_file_cer,
                 sizeof file_crpt_file_cer, 
                 "%s/citadel.cer",
                 ctdl_key_dir);
-
+       StripSlashes(file_crpt_file_cer, 0);
        snprintf(file_chkpwd,
                 sizeof file_chkpwd, 
                 "%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.
@@ -246,12 +325,13 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
                 ctdl_spool_dir
 #endif
                );
-                
+       StripSlashes(file_mail_aliases, 0);
         snprintf(file_funambol_msg,
                 sizeof file_funambol_msg,
                 "%sfunambol_newmail_soap.xml",
-                ctdl_spool_dir);
-        
+                ctdl_shared_dir);
+       StripSlashes(file_funambol_msg, 0);
+
        DBG_PRINT(ctdl_bio_dir);
        DBG_PRINT(ctdl_bb_dir);
        DBG_PRINT(ctdl_data_dir);
@@ -288,6 +368,7 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
        DBG_PRINT(file_crpt_file_cer);
        DBG_PRINT(file_chkpwd);
        DBG_PRINT(file_base64);
+       DBG_PRINT(file_guesstimezone);
        DBG_PRINT(file_funambol_msg);
 }