# This patch converts most VPOPMAILDIR-based strings in the code to
# standard configure-based locations (BINDIR, SYSCONFDIR, etc...)
# It also moves the DOMAINDIR/.messages into SYSCONFDIR/message
# 
# ~vpopmail/domains/.over-quota.msg => (sysconfdir)/over-quota.msg
# 
# and moves open-smtp files to LOCALSTATEDIR
# ~vpopmail/etc/open-smtp => (localstatedir)/open-smtp
# 
#
# Japheth Cleaver
# <cleaver@rohan.sdsu.edu>
# 

========================================================================
--- configure.in.use-std-locations	2004-07-28 11:38:26.000000000 -0700
+++ configure.in	2004-07-28 11:42:16.000000000 -0700
@@ -209,6 +209,15 @@
 
 #----------------------------------------------------------------------
 
+AC_DEFINE_UNQUOTED(PREFIX,"$prefix","")
+AC_DEFINE_UNQUOTED(BINDIR,"$bindir","")
+AC_DEFINE_UNQUOTED(SBINDIR,"$sbindir","")
+AC_DEFINE_UNQUOTED(SYSCONFDIR,"$sysconfdir","")
+AC_DEFINE_UNQUOTED(DATADIR,"$datadir","")
+AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$localstatedir","")
+
+#----------------------------------------------------------------------
+
 AC_MSG_CHECKING(whether we can locate the qmail directory)
 qmaildir=""
 for f in /var/qmail
@@ -461,7 +461,7 @@
     done
 
     AC_ARG_ENABLE(tcpserver_file,
-        [  --enable-tcpserver-file=PATH   File where tcpserver -x relay information is stored [/home/vpopmail/etc/tcp.smtp].],
+        [  --enable-tcpserver-file=PATH   File where tcpserver -x relay information is stored [~vpopmail/etc/tcp.smtp].],
         tcpserver_file="$enableval",
         [
             if test "$tcpserver_file" = ""
@@ -589,9 +497,9 @@
     AC_DEFINE_UNQUOTED(RELAY_CLEAR_MINUTES,$relay_clear_minutes,"")
 
 
-    open_smtp_cur="$vpopmaildir/etc/open-smtp"
-    open_smtp_tmp="$vpopmaildir/etc/open-smtp.tmp"
-    open_smtp_lok="$vpopmaildir/etc/open-smtp.lock"
+    open_smtp_cur="$localstatedir/open-smtp"
+    open_smtp_tmp="$localstatedir/open-smtp.tmp"
+    open_smtp_lok="$localstatedir/open-smtp.lock"
     AC_DEFINE_UNQUOTED(OPEN_SMTP_CUR_FILE,"$open_smtp_cur","")
     AC_DEFINE_UNQUOTED(OPEN_SMTP_TMP_FILE,"$open_smtp_tmp","")
     AC_DEFINE_UNQUOTED(OPEN_SMTP_LOK_FILE,"$open_smtp_lok","")
@@ -762,7 +762,7 @@
 
 #----------------------------------------------------------------------
 
-vlimits_default="$vpopmaildir/etc/vlimits.default"
+vlimits_default="$sysconfdir/vlimits.default"
 
 AC_DEFINE_UNQUOTED(VLIMITS_DEFAULT_FILE,"$vlimits_default","")
 
@@ -1304,21 +1304,21 @@
 AC_ARG_ENABLE(hardquota, [],
     [
         AC_MSG_RESULT(yes)
-        AC_MSG_ERROR(--enable-hardquota has been superceded. Please use the ~vpopmail/etc/vlimits.default file instead.)
+        AC_MSG_ERROR(--enable-hardquota has been superceded. Please use the SYSCONFDIR/vlimits.default file instead.)
     ]
 )
 
 AC_ARG_ENABLE(defaultquota, [],
     [
         AC_MSG_RESULT(yes)
-        AC_MSG_ERROR(--enable-defaultquota has been superceded. Please use the ~vpopmail/etc/vlimits.default file instead.)
+        AC_MSG_ERROR(--enable-defaultquota has been superceded. Please use the SYSCONFDIR/vlimits.default file instead.)
     ]
 )
 
 AC_ARG_ENABLE(default-domain, [],
     [
         AC_MSG_RESULT(yes)
-        AC_MSG_ERROR(--enable-default-domain has been superceded. The default domain should be put into the file ~vpopmail/etc/defaultdomain instead)
+        AC_MSG_ERROR(--enable-default-domain has been superceded. The default domain should be put into the file SYSCONFDIR/defaultdomain instead)
     ]
 )
 
--- vadddomain.c.use-std-locations	2004-07-28 11:53:36.000000000 -0700
+++ vadddomain.c	2004-07-28 11:54:10.000000000 -0700
@@ -94,11 +94,11 @@
 
             /* if catchall address is an email address... */
             if ( strstr(BounceEmail, "@") != NULL ) { 
-                fprintf(fs, "| %s/bin/vdelivermail '' %s\n", VPOPMAILDIR, 
+                fprintf(fs, "| %s/vdelivermail '' %s\n", SBINDIR, 
                     BounceEmail);
             /* No '@' - so assume catchall is a mailbox name */
             } else {
-                fprintf(fs, "| %s/bin/vdelivermail '' %s/%s\n", VPOPMAILDIR,
+                fprintf(fs, "| %s/vdelivermail '' %s/%s\n", SBINDIR,
                     a_dir, BounceEmail);
             }
 
--- vmysql.c.use-std-locations	2004-07-28 11:54:56.000000000 -0700
+++ vmysql.c	2004-07-28 11:58:11.000000000 -0700
@@ -111,7 +111,7 @@
     if (loaded) return 0;
     loaded = 1;
 
-    sprintf(config, "%s/etc/%s", VPOPMAILDIR, "vpopmail.mysql");
+    sprintf(config, "%s/%s", SYSCONFDIR, "vpopmail.mysql");
 
     fp = fopen(config, "r");
     if (fp == NULL) {
--- vpopmail.c.use-std-locations	2004-07-28 11:58:59.000000000 -0700
+++ vpopmail.c	2004-07-28 12:04:30.000000000 -0700
@@ -210,7 +210,7 @@
     chdir(calling_dir);
     return(VA_COULD_NOT_OPEN_QMAIL_DEFAULT);
   } else {
-    fprintf(fs, "| %s/bin/vdelivermail '' bounce-no-mailbox\n", VPOPMAILDIR);
+    fprintf(fs, "| %s/vdelivermail '' bounce-no-mailbox\n", SBINDIR);
     fclose(fs);
   }
 
@@ -1851,7 +1851,7 @@
  * default_domain()
  *   returns a pointer to a string, containing
  *   the default domain (or blank if not set).  Loads from
- *   ~vpopmail/etc/defaultdomain.  Only loads once per program
+ *   (sysconfdir)/defaultdomain.  Only loads once per program
  *   execution.
  */
 char *default_domain()
@@ -1865,7 +1865,7 @@
    if (!init) {
      init++;
      d[0] = '\0';  /* make sure d is empty in case file doesn't exist */
-     snprintf (path, sizeof(path), "%s/etc/defaultdomain", VPOPMAILDIR);
+     snprintf (path, sizeof(path), "%s/defaultdomain", SYSCONFDIR);
 
      fs = fopen (path, "r");
      if (fs != NULL) {
@@ -2410,7 +2410,7 @@
  * through this server.
  *
  * For mysql backend, the ip is added to the relay table
- * For cdb backend, the ip is added to the ~vpopmail/etc/open-smtp file
+ * For cdb backend, the ip is added to the (localstatedir)/open-smtp file
  * 
  * Then the update_rules() function is called which 
  * combines the tcp.smtp rules with the relay-table/open-smtp rules
@@ -2467,12 +2467,12 @@
   }
 
 #ifdef FILE_LOCKING
-  /* by default the OPEN_SMTP_LOK_FILE is ~vpopmail/etc/open-smtp.lock */
+  /* by default the OPEN_SMTP_LOK_FILE is (localstatedir)/open-smtp.lock */
   if ( (fd_lok_file=open(OPEN_SMTP_LOK_FILE, O_WRONLY | O_CREAT, S_IRUSR|S_IWUSR))<0) return(-1);
   get_write_lock(fd_lok_file);
 #endif /* FILE_LOCKING */
 
-  /* by default the OPEN_SMTP_CUR_FILE is ~vpopmail/etc/open-smtp */
+  /* by default the OPEN_SMTP_CUR_FILE is (localstatedir)/open-smtp */
   if ( (fs_cur_file = fopen(OPEN_SMTP_CUR_FILE, "r+")) == NULL ) {
     /* open for read/write failed, so try creating it from scratch */
     if ( (fs_cur_file = fopen(OPEN_SMTP_CUR_FILE, "w+")) == NULL ) {
@@ -2485,7 +2485,7 @@
     }
   }
 
-  /* by default the OPEN_SMTP_TMP_FILE is ~vpopmail/etc/open-smtp.tmp.pid */
+  /* by default the OPEN_SMTP_TMP_FILE is (localstatedir)/open-smtp.tmp.pid */
   snprintf(open_smtp_tmp_filename, sizeof(open_smtp_tmp_filename),
            "%s.%lu", OPEN_SMTP_TMP_FILE, (long unsigned)getpid());
   /* create the tmp file */
@@ -2697,7 +2697,7 @@
 #else
 
   /* open up the file that contains the list of recent open connections
-   * (by default this is ~vpopmail/etc/open-smtp)
+   * (by default this is (localstatedir)/open-smtp)
    * This file is generated by the open_smtp() function
    * the file has the following format :
    * x.x.x.x:ALLOW,RELAYCLIENT="",RBLSMTPD=""<TAB>timestamp
--- vdelivermail.c.use-std-locations	2007-08-14 18:19:43.000000000 -0700
+++ vdelivermail.c	2007-08-14 18:27:47.000000000 -0700
@@ -727,7 +727,7 @@
                 snprintf(tmp_file, sizeof(tmp_file), "%s/.over-quota.msg",TheDomainDir);
                 if ( (fs=fopen(tmp_file, "r")) == NULL ) {
                     /* if no domain over quota then check in vpopmail dir */
-                    snprintf(tmp_file, sizeof(tmp_file), "%s/%s/.over-quota.msg",VPOPMAILDIR,DOMAINS_DIR);
+                    snprintf(tmp_file, sizeof(tmp_file), "%s/over-quota.msg",SYSCONFDIR);
                     fs=fopen(tmp_file, "r");
                 }
 
@@ -760,7 +760,7 @@
             snprintf(tmp_file, sizeof(tmp_file), "%s/.over-quota.msg",TheDomainDir);
             if ( (fs=fopen(tmp_file, "r")) == NULL ) {
                 /* if no domain over quota then check in vpopmail dir */
-                snprintf(tmp_file, sizeof(tmp_file), "%s/%s/.over-quota.msg",VPOPMAILDIR,DOMAINS_DIR);
+                snprintf(tmp_file, sizeof(tmp_file), "%s/over-quota.msg",SYSCONFDIR);
                 fs=fopen(tmp_file, "r");
             }
 
@@ -1143,7 +1143,7 @@
         snprintf(tmp_file, sizeof(tmp_file), "%s/.no-user.msg",TheDomainDir);
         if ( (fs=fopen(tmp_file, "r")) == NULL ) {
             /* if no domain no user then check in vpopmail dir */
-            snprintf(tmp_file, sizeof(tmp_file), "%s/%s/.no-user.msg",VPOPMAILDIR,DOMAINS_DIR);
+            snprintf(tmp_file, sizeof(tmp_file), "%s/no-user.msg",SYSCONFDIR);
             fs=fopen(tmp_file, "r");
         }
         if ( fs == NULL ) {
@@ -1213,7 +1213,7 @@
            (stat(quotawarnmsg, &sb) != 0)) {
 
         /* if that fails look in vpopmail dir */
-        snprintf(quotawarnmsg, sizeof(quotawarnmsg), "%s/%s/.quotawarn.msg", VPOPMAILDIR, DOMAINS_DIR);
+        snprintf(quotawarnmsg, sizeof(quotawarnmsg), "%s/quotawarn.msg", SYSCONFDIR);
         if ( ((read_fd = open(quotawarnmsg, O_RDONLY)) < 0) || 
               (stat(quotawarnmsg, &sb) != 0)) {
             return 0;
--- clearopensmtp.c.use-std-locations	2006-03-08 18:59:02.000000000 -0800
+++ clearopensmtp.c	2006-03-08 18:59:23.000000000 -0800
@@ -56,11 +56,11 @@
          */
 	vclear_open_smtp(clear_minutes, mytime);
 #else
-        /* OPEN_SMTP_CUR_FILE is typically ~vpopmail/etc/open-smtp */
+        /* OPEN_SMTP_CUR_FILE is typically (localstatedir)/open-smtp */
 	fs_smtp_cur = fopen(OPEN_SMTP_CUR_FILE, "r+");
 	if ( fs_smtp_cur != NULL ) {
 
-                /* OPEN_SMTP_TMP_FILE is typically ~vpopmail/etc/open-smtp.tmp */
+                /* OPEN_SMTP_TMP_FILE is typically (localstatedir)/open-smtp.tmp */
  		/* create this file */
 		fs_smtp_tmp = fopen(OPEN_SMTP_TMP_FILE, "w+");
 		if ( fs_smtp_tmp == NULL ) {
--- vmysql.h.use-std-locations	2003-11-24 12:30:50.000000000 -0800
+++ vmysql.h	2003-11-24 12:31:05.000000000 -0800
@@ -20,7 +20,7 @@
 #define VPOPMAIL_MYSQL_H
 
 /* NOTE: As of vpopmail 5.3.25, MySQL connection info is stored in
-   ~vpopmail/etc/vpopmail.mysql.  The format of the file is as follows:
+   (sysconfdir)/vpopmail.mysql.  The format of the file is as follows:
    
    read server|read port|read user|read password|read database
    update server|update port|update user|update password|update database
--- vlimits.c.use-std-locations	2006-03-08 18:35:11.000000000 -0800
+++ vlimits.c	2006-03-08 18:35:45.000000000 -0800
@@ -286,7 +286,7 @@
 
 /* grab the limits for this domain
  * look first for a ~vpopmail/domains/domain/.qmailadmin-limits
- * if not found, try ~vpopmail/etc/vlimits.default
+ * if not found, try (sysconfdir)/vlimits.default
  * if neither found, return error
  */
 int vget_limits(const char *domain, struct vlimits *limits)
@@ -320,12 +320,12 @@
         chmod(dir, S_IRUSR|S_IWUSR);
     } else if (vlimits_read_limits_file (VLIMITS_DEFAULT_FILE, limits) == 0) {
         /* We couldn't find a .qmailadmin-limits in the domain's dir.
-         * but we did find a global file at ~vpopmail/etc/vlimits.default file
+         * but we did find a global file at (sysconfdir)/vlimits.default file
          * so we have used that instead
          */
     } else {
         /* No ~vpopmail/domains/domain/.qmailadmin-limits
-         * and also no ~vpopmail/etc/vlimits.default
+         * and also no (sysconfdir)/vlimits.default
          * so return error
          */ 
         return -1;

