On 09/17/2015 04:55 PM, Matt Brookings wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/17/2015 10:52 AM, Drew Wells wrote:
I basically did a diff from 5.4.29 to 5.4.33 and implemented that diff to 
5.5.0, some of it
had already been done to 5.5.0 and alot of it centered around the snprintf tidy 
up's and the
string_list implementation. The attached patch does not include any of the 
changes I
recently sent to the mailing list, just the changes from 5.4.[29->33].
This patch was generated from the 5.5.0 .tar.bz2, I had a look at SVN trunk and 
from what I could
see, it was 5.4.34.
The trunk on Sourceforge is the current 5.5.0.  The 5.4 series only appears in 
the tags and branches
area now.  I'll look over this patch and get it applied.  Thanks for putting it 
together!

I've just noticed a tiny problem with the previous patch I sent, so here is an updated version, this version also includes the missing '#include "pwstr.h"' in vadduser.c which causes a segfault on my dev environment so thought I should just include it. The tiny problem was "string_list *aliases" instead of "string_list aliases" in vadddomain() in vpopmail.c.


!DSPAM:55fbf97841551215118515!
diff -uPr vpopmail-5.5.0.orig/backends/mysql/vmysql.c 
vpopmail-5.5.0/backends/mysql/vmysql.c
--- vpopmail-5.5.0.orig/backends/mysql/vmysql.c 2010-11-05 18:37:23.000000000 
+0000
+++ vpopmail-5.5.0/backends/mysql/vmysql.c      2015-09-18 12:36:07.561092988 
+0100
@@ -1785,10 +1785,10 @@
         limits->maxforwards = atoi(row[2]);
         limits->maxautoresponders = atoi(row[3]);
         limits->maxmailinglists = atoi(row[4]);
-        limits->diskquota = atoi(row[5]);
-        limits->maxmsgcount = atoi(row[6]);
-        limits->defaultquota = atoi(row[7]);
-        limits->defaultmaxmsgcount = atoi(row[8]);
+        limits->diskquota = strtoll(row[5], NULL, 10);
+        limits->maxmsgcount = strtoll(row[6], NULL, 10);
+        limits->defaultquota = strtoll(row[7], NULL, 10);
+        limits->defaultmaxmsgcount = strtoll(row[8], NULL, 10);
         limits->disable_pop = atoi(row[9]);
         limits->disable_imap = atoi(row[10]);
         limits->disable_dialup = atoi(row[11]);
@@ -1808,8 +1808,8 @@
         limits->perm_maillist_users = perm & VLIMIT_DISABLE_ALL;
         perm >>= VLIMIT_DISABLE_BITS;
         limits->perm_maillist_moderators = perm & VLIMIT_DISABLE_ALL;
-        limits->perm_quota = atoi(row[23]);
-        limits->perm_defaultquota = atoi(row[24]);
+        limits->perm_quota = strtoll(row[23], NULL, 10);
+        limits->perm_defaultquota = strtoll(row[24], NULL, 10);
     }
     mysql_free_result(res_read);
 
@@ -1830,7 +1830,7 @@
         "diskquota = %d, maxmsgcount = %d, defaultquota = %d, 
defaultmaxmsgcount = %d, "
         "disable_pop = %d, disable_imap = %d, disable_dialup = %d, "
         "disable_passwordchanging = %d, disable_webmail = %d, disable_relay = 
%d, "
-        "disable_smtp = %d, disable_spamassassin = %d, delete_spam = %d, 
perm_account = %d, "
+        "disable_smtp = %d, disable_spamassassin = %d, delete_spam = %d, 
disable_maildrop = %d, perm_account = %d, "
         "perm_alias = %d, perm_forward = %d, perm_autoresponder = %d, 
perm_maillist = %d, "
         "perm_quota = %d, perm_defaultquota = %d "
         "ON DUPLICATE KEY UPDATE "
@@ -1847,7 +1847,7 @@
         limits->diskquota, limits->maxmsgcount, limits->defaultquota, 
limits->defaultmaxmsgcount,
         limits->disable_pop, limits->disable_imap, limits->disable_dialup,
         limits->disable_passwordchanging, limits->disable_webmail, 
limits->disable_relay,
-        limits->disable_smtp, limits->disable_spamassassin, 
limits->delete_spam, limits->perm_account,
+        limits->disable_smtp, limits->disable_spamassassin, 
limits->delete_spam, limits->disable_maildrop, limits->perm_account,
         limits->perm_alias, limits->perm_forward, limits->perm_autoresponder,
         (limits->perm_maillist |
             (limits->perm_maillist_users << VLIMIT_DISABLE_BITS) |
diff -uPr vpopmail-5.5.0.orig/backends/mysql/vmysql.h.in 
vpopmail-5.5.0/backends/mysql/vmysql.h.in
--- vpopmail-5.5.0.orig/backends/mysql/vmysql.h.in      2010-11-05 
18:37:23.000000000 +0000
+++ vpopmail-5.5.0/backends/mysql/vmysql.h.in   2015-09-18 12:36:07.561092988 
+0100
@@ -268,10 +268,10 @@
       maxforwards              INT(10) NOT NULL DEFAULT -1, \
       maxautoresponders        INT(10) NOT NULL DEFAULT -1, \
       maxmailinglists          INT(10) NOT NULL DEFAULT -1, \
-      diskquota                INT(12) NOT NULL DEFAULT 0, \
-      maxmsgcount              INT(12) NOT NULL DEFAULT 0, \
-      defaultquota             INT(12) NOT NULL DEFAULT 0, \
-      defaultmaxmsgcount       INT(12) NOT NULL DEFAULT 0, \
+      diskquota                BIGINT UNSIGNED NOT NULL DEFAULT 0, \
+      maxmsgcount              BIGINT UNSIGNED NOT NULL DEFAULT 0, \
+      defaultquota             BIGINT UNSIGNED NOT NULL DEFAULT 0, \
+      defaultmaxmsgcount       BIGINT UNSIGNED NOT NULL DEFAULT 0, \
       disable_pop              TINYINT(1) NOT NULL DEFAULT 0, \
       disable_imap             TINYINT(1) NOT NULL DEFAULT 0, \
       disable_dialup           TINYINT(1) NOT NULL DEFAULT 0, \
diff -uPr vpopmail-5.5.0.orig/backfill.c vpopmail-5.5.0/backfill.c
--- vpopmail-5.5.0.orig/backfill.c      2010-11-05 18:37:22.000000000 +0000
+++ vpopmail-5.5.0/backfill.c   2015-09-18 12:36:07.562093054 +0100
@@ -13,7 +13,9 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <fcntl.h>
 #include "vpopmail.h"
+#include "file_lock.h"
 #include "vauth.h"
 #include "vauthmodule.h"
 
@@ -37,6 +39,7 @@
        int             fd;
 #ifdef FILE_LOCKING
        int             lockfd;
+       char            lockfile[MAX_BUFF];
 #endif
 
        if (stat(filename, &statbuf))
diff -uPr vpopmail-5.5.0.orig/client.c vpopmail-5.5.0/client.c
--- vpopmail-5.5.0.orig/client.c        2010-11-05 18:37:22.000000000 +0000
+++ vpopmail-5.5.0/client.c     2015-09-18 12:36:07.562093054 +0100
@@ -78,66 +78,64 @@
 
    config = config_begin("vusagec.conf");
    if (config == NULL)
-         fprintf(stderr, "client_connect: warning: config_begin failed\n");
+         return NULL;
 
    /*
          Disabled check
    */
 
-   else {
-         str = config_fetch_by_name(config, "Server", "Disable");
-         if ((str) && (*str)) {
-                if (!(strcasecmp(str, "True"))) {
-                       config_kill(config);
-                       return NULL;
-                }
-         }
+   str = config_fetch_by_name(config, "Server", "Disable");
+   if ((str) && (*str)) {
+       if (!(strcasecmp(str, "True"))) {
+           config_kill(config);
+           return NULL;
+        }
+   }
 
-         /*
-                Get timeout
-         */
-
-         str = config_fetch_by_name(config, "Server", "Timeout");
-         if (str) {
-                fl = atoi(str);
-                if ((fl == -1) || (fl == 0))
-                       fprintf(stderr, "client_connect: configuration error: 
Server::Timeout: %s\n", str);
-                else
-                       timeout = fl;
-         }
+   /*
+         Get timeout
+   */
 
-         /*
-                Determine connection type
-         */
-
-         str = config_fetch_by_name(config, "Server", "Remote");
-         if (str) {
-                ret = ippp_parse(str, &addr);
-                if (!ret) {
-                       config_kill(config);
-                       fprintf(stderr, "client_connect: configuration error: 
Server::Remote: %s\n", str);
-                       return NULL;
-                }
-         }
+   str = config_fetch_by_name(config, "Server", "Timeout");
+   if (str) {
+       fl = atoi(str);
+       if ((fl == -1) || (fl == 0))
+           fprintf(stderr, "client_connect: configuration error: 
Server::Timeout: %s\n", str);
+       else
+           timeout = fl;
+       }
 
-         else {
-                str = config_fetch_by_name(config, "Server", "Filename");
-                if (str) {
-                       if (!(*str)) {
-                          config_kill(config);
-                          fprintf(stderr, "client_connect: configuration 
error: Server::Filename\n");
-                          return NULL;
-                       }
-
-                       fl = strlen(str);
-                       if (fl >= sizeof(socket_file))
-                          fl = (sizeof(socket_file) - 1);
+   /*
+         Determine connection type
+   */
 
-                       memcpy(socket_file, str, fl);
-                }
-         }
+   str = config_fetch_by_name(config, "Server", "Remote");
+   if (str) {
+       ret = ippp_parse(str, &addr);
+       if (!ret) {
+           config_kill(config);
+           fprintf(stderr, "client_connect: configuration error: 
Server::Remote: %s\n", str);
+           return NULL;
+       }
+   }
+
+   else {
+       str = config_fetch_by_name(config, "Server", "Filename");
+       if (str) {
+           if (!(*str)) {
+               config_kill(config);
+               fprintf(stderr, "client_connect: configuration error: 
Server::Filename\n");
+               return NULL;
+           }
+
+           fl = strlen(str);
+           if (fl >= sizeof(socket_file))
+               fl = (sizeof(socket_file) - 1);
+
+           memcpy(socket_file, str, fl);
+       }
 
-         config_kill(config);
+       config_kill(config);
    }
 
    /*
diff -uPr vpopmail-5.5.0.orig/conf.c vpopmail-5.5.0/conf.c
--- vpopmail-5.5.0.orig/conf.c  2010-11-05 18:37:22.000000000 +0000
+++ vpopmail-5.5.0/conf.c       2015-09-18 12:36:07.563093118 +0100
@@ -787,13 +787,12 @@
 char *config_fetch_by_num(config_t *c, char *label, int num)
 {  
   int cur = 0;
+  config_label_t *l = NULL;
+  config_atom_t *a = NULL;
 
   if (c == NULL)
         return NULL;
 
-  config_label_t *l = NULL;
-  config_atom_t *a = NULL;
-
   if (c->labels == NULL)
      return NULL;
 
diff -uPr vpopmail-5.5.0.orig/doc/UPGRADE vpopmail-5.5.0/doc/UPGRADE
--- vpopmail-5.5.0.orig/doc/UPGRADE     2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/doc/UPGRADE  2015-09-18 12:36:07.564093180 +0100
@@ -4,6 +4,15 @@
 into the vpopmail libraries.  These include QmailAdmin, qmail-smtpd (if 
 you have the chkuser patch applied), Courier-IMAP etc.
 
++Upgrading to vpopmail-5.4.33
++----------------------------
++If you are storing limits in MySQL, the following schema changes must be made:
++
++ALTER TABLE `limits` ADD `disable_maildrop` TINYINT(1) DEFAULT '0' NOT NULL 
AFTER `disable_spamassassin`;
++ALTER TABLE `limits` MODIFY `diskquota` BIGINT UNSIGNED NOT NULL DEFAULT 0;
++ALTER TABLE `limits` MODIFY `maxmsgcount` BIGINT UNSIGNED NOT NULL DEFAULT 0;
++ALTER TABLE `limits` MODIFY `defaultquota` BIGINT UNSIGNED NOT NULL DEFAULT 0;
++ALTER TABLE `limits` MODIFY `defaultmaxmsgcount` BIGINT UNSIGNED NOT NULL 
DEFAULT 0;
 
 Upgrading to vpopmail-5.4.18
 ----------------------------
diff -uPr vpopmail-5.5.0.orig/maildirquota.c vpopmail-5.5.0/maildirquota.c
--- vpopmail-5.5.0.orig/maildirquota.c  2010-11-05 18:37:22.000000000 +0000
+++ vpopmail-5.5.0/maildirquota.c       2015-09-18 12:36:07.565093240 +0100
@@ -42,16 +42,16 @@
 
 /* private functions - no name clashes with courier */
 static char *makenewmaildirsizename(const char *, int *);
-static int countcurnew(const char *dir, time_t *maxtime, off_t *sizep, int 
*cntp);
-static int countsubdir(const char *dir, const char *subdir, time_t *maxtime, 
off_t *sizep, int *cntp);
+static int countcurnew(const char *dir, time_t *maxtime, storage_t *sizep, 
storage_t *cntp);
+static int countsubdir(const char *dir, const char *subdir, time_t *maxtime, 
storage_t *sizep, storage_t *cntp);
 static int statcurnew(const char *dir, time_t *maxtimestamp);
 static int statsubdir(const char *dir, const char *subdir, time_t *maxtime);
 static int doaddquota(const char *dir, int maildirsize_fd, const char 
*quota_type, 
-                      long maildirsize_size, int maildirsize_cnt, int isnew);
+                      storage_t maildirsize_size, storage_t maildirsize_cnt, 
int isnew);
 static int docheckquota(const char *dir, int *maildirsize_fdptr, const char 
*quota_type, 
-                        long xtra_size, int xtra_cnt, int *percentage);
-static int docount(const char *dir, time_t *dirstamp, off_t *sizep, int *cntp);
-static int maildir_checkquota(const char *dir, int *maildirsize_fdptr, const 
char *quota_type, long xtra_size, int xtra_cnt);
+                        storage_t xtra_size, storage_t xtra_cnt, int 
*percentage);
+static int docount(const char *dir, time_t *dirstamp, storage_t *sizep, 
storage_t *cntp);
+static int maildir_checkquota(const char *dir, int *maildirsize_fdptr, const 
char *quota_type, storage_t xtra_size, storage_t xtra_cnt);
 /*  moved into maildirquota.h as non-static
 static int maildir_addquota(const char *dir, int maildirsize_fd,
        const char *quota_type, long maildirsize_size, int maildirsize_cnt);
@@ -59,7 +59,7 @@
 static int maildir_safeopen(const char *path, int mode, int perm);
 static char *str_pid_t(pid_t t, char *arg);
 static char *str_time_t(time_t t, char *arg);
-static int maildir_parsequota(const char *n, unsigned long *s);
+static int maildir_parsequota(const char *n, storage_t *s);
 
 #define  NUMBUFSIZE      60
 #define        MDQUOTA_SIZE    'S'     /* Total size of all messages in 
maildir */
@@ -75,10 +75,11 @@
 char   domdir[MAX_PW_DIR];
 char   *p;
 char   domain[256], qb[256] = { 0 };
-long    size = 0;
-unsigned long maxsize = 0;
-int    cnt = 0, ret = 0;
-int    maxcnt = 0;
+storage_t size = 0;
+storage_t maxsize = 0;
+storage_t cnt = 0;
+int ret = 0;
+storage_t maxcnt = 0;
 struct vlimits limits;
    storage_t susage = 0, cusage = 0;
 
@@ -144,7 +145,7 @@
         return 0;
 }
 
-int readdomainquota(const char *dir, long *sizep, int *cntp)
+int readdomainquota(const char *dir, storage_t *sizep, storage_t *cntp)
 {
 int tries;
 char   checkdir[256];
@@ -205,7 +206,7 @@
        return 0;
 }
 
-int wrapreaduserquota(const char* dir, off_t *sizep, int *cntp)
+int wrapreaduserquota(const char* dir, storage_t *sizep, storage_t *cntp)
 {
 time_t tm;
 time_t maxtime;
@@ -284,10 +285,10 @@
 
        return 0;
 }
-int readuserquota(const char* dir, long *sizep, int *cntp)
+int readuserquota(const char* dir, storage_t *sizep, storage_t *cntp)
 {
        int retval;
-       off_t s;
+       storage_t s;
        
        s = (off_t) *sizep;
        retval = wrapreaduserquota(dir, &s, cntp);
@@ -315,7 +316,7 @@
                         if (quotafd >= 0)       close(quotafd);
                         ret_value = 1;
                 } else {
-                        maildir_addquota(dir, quotafd, q, stat_buf.st_size, 1);
+                        //maildir_addquota(dir, quotafd, q, stat_buf.st_size, 
1);
                         if (quotafd >= 0)       close(quotafd);
                         ret_value = 0;
                 }
@@ -349,8 +350,8 @@
 
 static int maildirsize_read(const char *filename,      /* The filename */
        int *fdptr,     /* Keep the file descriptor open */
-       off_t *sizeptr, /* Grand total of maildir size */
-       int *cntptr, /* Grand total of message count */
+       storage_t *sizeptr, /* Grand total of maildir size */
+       storage_t *cntptr, /* Grand total of message count */
        unsigned *nlines, /* # of lines in maildirsize */
        struct stat *statptr)   /* The stats on maildirsize */
 {
@@ -358,8 +359,9 @@
  int f;
  char *p;
  unsigned l;
- int n;
+ storage_t n;
  int first;
+ int ret = 0;
 
    /*
          Old-style
@@ -372,6 +374,18 @@
        p=buf;
        l=sizeof(buf);
 
+       /*
+               Maildir++ specification says to rebuild the maildirsize file if 
the
+               file is 5120 or more bytes, or is more than 15 minutes old
+       */
+
+       ret = fstat(f, statptr);
+       if ((ret != -1) && ((statptr->st_size >= 5120) || (time(NULL) > 
statptr->st_mtime + (15*60)))) {
+          unlink(filename);
+          close(f);
+          return -1;
+       }
+
        while (l)
        {
                n=read(f, p, l);
@@ -384,7 +398,7 @@
                p += n;
                l -= n;
        }
-       if (l == 0 || fstat(f, statptr))        /* maildir too big */
+       if (l == 0 || ret)      /* maildir too big */
        {
                close(f);
                return (-1);
@@ -398,8 +412,8 @@
        first=1;
        while (*p)
        {
-       long n=0;
-       int c=0;
+       storage_t n=0;
+       storage_t c=0;
        char    *q=p;
 
                while (*p)
@@ -414,7 +428,7 @@
                        first=0;
                        continue;
                }
-               sscanf(q, "%ld %d", &n, &c);
+               sscanf(q, "%llu %llu", &n, &c);
                *sizeptr += n;
                *cntptr += c;
                ++ *nlines;
@@ -423,9 +437,9 @@
        return (0);
 }
 
-static int qcalc(off_t s, unsigned n, const char *quota, int *percentage)
+static int qcalc(storage_t s, storage_t n, const char *quota, int *percentage)
 {
-off_t i;
+storage_t i;
 int    spercentage=0;
 int    npercentage=0;
 
@@ -450,6 +464,7 @@
                                return (-1);
                        }
 
+#if 0
                        /*
                        ** For huge quotas, over 20mb,
                        ** divide numerator & denominator by 1024 to prevent
@@ -458,6 +473,7 @@
 
                        x=1;
                        if (i > 20000000) x=1024;
+#endif
 
                        spercentage = i ? (s/x) * 100 / (i/x):100;
                        break;
@@ -469,10 +485,12 @@
                                return (-1);
                        }
 
+#if 0
                        /* Ditto */
 
                        x=1;
                        if (i > 20000000) x=1024;
+#endif
 
                        npercentage = i ? ((off_t)n/x) * 100 / (i/x):100;
                        break;
@@ -485,8 +503,8 @@
 static int maildir_checkquota(const char *dir,
        int *maildirsize_fdptr,
        const char *quota_type,
-       long xtra_size,
-       int xtra_cnt)
+       storage_t xtra_size,
+       storage_t xtra_cnt)
 {
 int    dummy, ret = 0;
 
@@ -496,13 +514,21 @@
 
    fprintf(stderr, "warning: program using deprecated quota function at 
%s:%d\n", __FILE__, __LINE__);
 
+   if ((xtra_size == 0) || (xtra_cnt == 0))
+       return 0;
+
    /*
          Ping the daemon
    */
 
    ret = client_query_quick(" ", NULL, NULL);
-   if (ret)
-      return vmaildir_readquota(dir, quota_type);
+   if (ret) {
+      ret = vmaildir_readquota(dir, quota_type);
+      if (ret >= 100)
+          return -1;
+
+      return 0;
+   }
 
    /*
          Fall back
@@ -570,16 +596,16 @@
 static int docheckquota(const char *dir,
        int *maildirsize_fdptr,
        const char *quota_type,
-       long xtra_size,
-       int xtra_cnt,
+       storage_t xtra_size,
+       storage_t xtra_cnt,
        int *percentage)
 {
 char   *checkfolder=(char *)malloc(strlen(dir)+sizeof("/maildirfolder"));
 char   *newmaildirsizename;
 struct stat stat_buf;
 int    maildirsize_fd = -1;
-off_t  maildirsize_size;
-int     maildirsize_cnt;
+storage_t maildirsize_size;
+storage_t maildirsize_cnt;
 unsigned maildirsize_nlines;
 int    n;
 time_t tm;
@@ -747,7 +773,7 @@
 }
 
 int    maildir_addquota(const char *dir, int maildirsize_fd,
-       const char *quota_type, long maildirsize_size, int maildirsize_cnt)
+       const char *quota_type, storage_t maildirsize_size, storage_t 
maildirsize_cnt)
 {
    int ret = 0;
 
@@ -776,7 +802,7 @@
 }
 
 static int doaddquota(const char *dir, int maildirsize_fd,
-       const char *quota_type, long maildirsize_size, int maildirsize_cnt,
+       const char *quota_type, storage_t maildirsize_size, storage_t 
maildirsize_cnt,
        int isnew)
 {
 union  {
@@ -845,8 +871,7 @@
                niov=2;
        }
 
-
-       sprintf(u.buf, "%ld %d\n", maildirsize_size, maildirsize_cnt);
+       sprintf(u.buf, "%llu %lu\n", maildirsize_size, maildirsize_cnt);
        iov[niov].iov_base=u.buf;
        iov[niov].iov_len=strlen(u.buf);
 
@@ -974,7 +999,7 @@
        return (n);
 }
 
-static int countcurnew(const char *dir, time_t *maxtime, off_t *sizep, int 
*cntp)
+static int countcurnew(const char *dir, time_t *maxtime, storage_t *sizep, 
storage_t *cntp)
 {
 char   *p=(char *)malloc(strlen(dir)+5);
 int    n;
@@ -991,7 +1016,7 @@
        return (n);
 }
 
-static int countsubdir(const char *dir, const char *subdir, time_t *maxtime, 
off_t *sizep, int *cntp)
+static int countsubdir(const char *dir, const char *subdir, time_t *maxtime, 
storage_t *sizep, storage_t *cntp)
 {
 char   *p;
 int    n;
@@ -1008,13 +1033,13 @@
        return (n);
 }
 
-static int docount(const char *dir, time_t *dirstamp, off_t *sizep, int *cntp)
+static int docount(const char *dir, time_t *dirstamp, storage_t *sizep, 
storage_t *cntp)
 {
 struct stat    stat_buf;
 char   *p;
 DIR    *dirp;
 struct dirent *de;
-unsigned long  s;
+storage_t s;
 
        if (stat(dir, &stat_buf))       return (0);     /* Ignore */
        if (stat_buf.st_mtime > *dirstamp)      *dirstamp=stat_buf.st_mtime;
@@ -1044,7 +1069,7 @@
 
 
                if (maildir_parsequota(n, &s) == 0)
-                       stat_buf.st_size=s;
+                       *sizep += s;
                else
                {
                        p=(char *)malloc(strlen(dir)+strlen(n)+2);
@@ -1060,8 +1085,8 @@
                                continue;
                        }
                        free(p);
+                       *sizep += stat_buf.st_size;
                }
-               *sizep += stat_buf.st_size;
                ++*cntp;
        }
 
@@ -1132,7 +1157,7 @@
         return (strcpy(arg, p));
 }
 
-static int maildir_parsequota(const char *n, unsigned long *s)
+static int maildir_parsequota(const char *n, storage_t *s)
 {
 const char *o;
 int     yes;
@@ -1164,6 +1189,7 @@
                 *s=0;
                 while (*o >= '0' && *o <= '9')
                         *s= *s*10 + (*o++ - '0');
+
                 return (0);
         }
         return (-1);
diff -uPr vpopmail-5.5.0.orig/maildirquota.h vpopmail-5.5.0/maildirquota.h
--- vpopmail-5.5.0.orig/maildirquota.h  2010-11-05 18:37:22.000000000 +0000
+++ vpopmail-5.5.0/maildirquota.h       2015-09-18 12:36:07.565093240 +0100
@@ -8,6 +8,8 @@
    -Bill Shupp
  */
 
+#include "storage.h"
+
 #define QUOTA_WARN_PERCENT 90
 
 /* I've removed pretty much the whole file execept for
@@ -15,8 +17,8 @@
    I"ve made the courier functions static.
    - Brian Kolaci
 */
-int readdomainquota(const char *dir, long *sizep, int *cntp);
-int readuserquota(const char* dir, long *sizep, int *cntp);
+int readdomainquota(const char *dir, storage_t *sizep, storage_t *cntp);
+int readuserquota(const char* dir, storage_t *sizep, storage_t *cntp);
 int domain_over_maildirquota(const char *userdir);
 int user_over_maildirquota(const char *dir, const char *quota);
 int vmaildir_readquota(const char *dir,        const char *quota);
@@ -24,5 +26,5 @@
 int maildir_addquota(const char *,     /* Pointer to the maildir */
        int,    /* Must be the int pointed to by 2nd arg to checkquota */
        const char *,   /* The quota */
-       long,   /* +/- bytes */
-       int);   /* +/- files */
+       storage_t,      /* +/- bytes */
+       storage_t);     /* +/- files */
diff -uPr vpopmail-5.5.0.orig/vadduser.c vpopmail-5.5.0/vadduser.c
--- vpopmail-5.5.0.orig/vadduser.c      2010-11-05 18:37:22.000000000 +0000
+++ vpopmail-5.5.0/vadduser.c   2015-09-18 12:37:08.355095118 +0100
@@ -30,6 +30,7 @@
 #include "vpopmail.h"
 #include "vauth.h"
 #include "vauthmodule.h"
+#include "pwstr.h"
 
 char Email[MAX_BUFF];
 char Passwd[MAX_BUFF];
diff -uPr vpopmail-5.5.0.orig/vchkpw.c vpopmail-5.5.0/vchkpw.c
--- vpopmail-5.5.0.orig/vchkpw.c        2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/vchkpw.c     2015-09-18 12:36:07.566093298 +0100
@@ -733,26 +733,26 @@
 
   if ( (verror == VLOG_ERROR_PASSWD) && ( ENABLE_LOGGING==1 || 
ENABLE_LOGGING==2 || ENABLE_LOGGING==3 || ENABLE_LOGGING==4 ) ) {
       if ( (logsql(verror, TheUser, TheDomain, ThePass, TheName, IpAddr, 
LogLine) ) != 0 ) {
-          syslog(LOG_NOTICE,"vchkpw: can't write SQL logs");
+          syslog(LOG_NOTICE,"%s","vchkpw: can't write SQL logs");
       }
       if ( (logsql(verror, TheUser, TheDomain, ThePass, TheName, IpAddr, 
LogLine) ) != 0 ) {
-          syslog(LOG_NOTICE,"vchkpw: can't write SQL logs");
+          syslog(LOG_NOTICE,"%s","vchkpw: can't write SQL logs");
       }
   } else if ( verror == VLOG_ERROR_INTERNAL ) {
       if ( (logsql(verror, TheUser, TheDomain, ThePass, TheName, IpAddr, 
LogLine) ) != 0 ) {
-        syslog(LOG_NOTICE,"vchkpw: can't write SQL logs");
+          syslog(LOG_NOTICE,"%s","vchkpw: can't write SQL logs");
       }
   } else if ( verror == VLOG_ERROR_LOGON ) {
       if ( (logsql(verror, TheUser, TheDomain, ThePass, TheName, IpAddr, 
LogLine) ) != 0 ) {
-        syslog(LOG_NOTICE,"vchkpw: can't write SQL logs");
+          syslog(LOG_NOTICE,"%s","vchkpw: can't write SQL logs");
       }
   } else if ( verror == VLOG_ERROR_ACCESS ) {
       if ( (logsql(verror, TheUser, TheDomain, ThePass, TheName, IpAddr, 
LogLine) ) != 0 ) {
-        syslog(LOG_NOTICE,"vchkpw: can't write SQL logs");
+          syslog(LOG_NOTICE,"%s","vchkpw: can't write SQL logs");
       }
   } else if ( verror == VLOG_AUTH && ( ENABLE_LOGGING == 1 || ENABLE_LOGGING 
== 4 ) ) {
       if ( (logsql(verror, TheUser, TheDomain, ThePass, TheName, IpAddr, 
LogLine) ) != 0 ) {
-        syslog(LOG_NOTICE,"vchkpw: can't write SQL logs");
+          syslog(LOG_NOTICE,"%s","vchkpw: can't write SQL logs");
       }
   }
 #endif
diff -uPr vpopmail-5.5.0.orig/vdeldomain.c vpopmail-5.5.0/vdeldomain.c
--- vpopmail-5.5.0.orig/vdeldomain.c    2010-11-05 18:37:22.000000000 +0000
+++ vpopmail-5.5.0/vdeldomain.c 2015-09-18 12:36:07.566093298 +0100
@@ -43,9 +43,9 @@
  int err=0;
 
  domain_entry *entry;
- char *aliases[MAX_DOM_ALIAS];
+ string_list aliases;
  char parent[MAX_BUFF];
- int  i, aliascount=0, doit=1;
+ int  i, doit=1;
 
    err = vauth_load_module(NULL);
    if (!err)
@@ -69,9 +69,11 @@
                }
        }
 
+       string_list_init(&aliases, 10);
+
        while( entry ) {
                if (strcmp(entry->domain, entry->realdomain) != 0) {
-                       aliases[aliascount++] = strdup(entry->domain);
+                       string_list_add(&aliases, entry->domain);
                } else {
                        snprintf(parent,sizeof(parent),"%s",entry->domain);
                }
@@ -79,7 +81,7 @@
                entry = get_domain_entries(NULL);
        }
 
-       if( aliascount > 0 && 0 == strncmp(Domain,parent,MAX_BUFF)) {  
+       if( aliases.count > 0 && 0 == strncmp(Domain,parent,MAX_BUFF)) {  
                //  Have aliases
                if( force ) {
                        printf("Warning: Alias domains deleted:\n");
@@ -88,12 +90,13 @@
                        doit=0;
                }
 
-               for(i=0;i<aliascount;i++) {
-                       printf ("   %s\n", aliases[i]);
-                       free( aliases[i] );
+               for(i=0;i<aliases.count;i++) {
+                       printf ("   %s\n", aliases.values[i]);
                } 
        }
 
+       string_list_free(&aliases);
+
         if( doit ) {
        if ( (err=vdeldomain(Domain)) != VA_SUCCESS) {
                printf("Error: %s\n", verror(err));
diff -uPr vpopmail-5.5.0.orig/vdominfo.c vpopmail-5.5.0/vdominfo.c
--- vpopmail-5.5.0.orig/vdominfo.c      2010-11-05 18:37:23.000000000 +0000
+++ vpopmail-5.5.0/vdominfo.c   2015-09-18 12:36:07.567093355 +0100
@@ -248,8 +248,8 @@
 void display_one_domain( char * Domain )
 {
  domain_entry *entry;
- char *aliases[MAX_DOM_ALIAS];
- int  i, aliascount=0;
+ string_list aliases;
+ int  i;
 
     entry = get_domain_entries( Domain );
     if (entry==NULL) {
@@ -262,11 +262,13 @@
       }
     }
 
+    string_list_init(&aliases, 10);
+
     while( entry ) {
        if (strcmp(entry->domain, entry->realdomain) != 0) {
 //             printf ("Note:   %s is an alias for %s\n",
 //                         entry->domain, entry->realdomain);
-                aliases[aliascount++] = strdup(entry->domain);
+                string_list_add(&aliases, entry->domain);
 
         } else {
                display_domain(entry->domain, entry->path, entry->uid, 
@@ -276,9 +278,9 @@
         entry = get_domain_entries(NULL);
     }
 
-    for(i=0;i<aliascount;i++) {
-       printf ("alias:  %s\n", aliases[i]);
-        free( aliases[i] );
-    } 
+    for(i=0;i<aliases.count;i++) {
+       printf ("alias:  %s\n", aliases.values[i]);
+    }
+    string_list_free(&aliases); 
 }
 
diff -uPr vpopmail-5.5.0.orig/vlimits.c vpopmail-5.5.0/vlimits.c
--- vpopmail-5.5.0.orig/vlimits.c       2010-11-05 18:37:23.000000000 +0000
+++ vpopmail-5.5.0/vlimits.c    2015-09-18 12:36:07.567093355 +0100
@@ -187,22 +187,22 @@
 
                        else if (!strcmp(s1, "quota")) {
                 if (s2)
-                limits->diskquota = atoi(s2);
+                limits->diskquota = strtoll(s2, NULL, 10);
             }
 
                        else if (!strcmp(s1, "maxmsgcount")) {
                 if (s2)
-                limits->maxmsgcount = atoi(s2);
+                limits->maxmsgcount = strtoll(s2, NULL, 10);
             }
 
             if (!strcmp(s1, "default_quota")) {
                 if (s2)
-                limits->defaultquota = atoi(s2);
+                limits->defaultquota = strtoll(s2, NULL, 10);
             }
 
                        else if (!strcmp(s1, "default_maxmsgcount")) {
                 if (s2)
-                limits->defaultmaxmsgcount = atoi(s2);
+                limits->defaultmaxmsgcount = strtoll(s2, NULL, 10);
             }
 
                        else if (!strcmp(s1, "disable_pop")) {
@@ -480,10 +480,10 @@
         fprintf(fs, "maxforwards: %d\n", limits->maxforwards);
         fprintf(fs, "maxautoresponders: %d\n", limits->maxautoresponders);
         fprintf(fs, "maxmailinglists: %d\n", limits->maxmailinglists);
-        fprintf(fs, "quota: %d\n", limits->diskquota);
-        fprintf(fs, "maxmsgcount: %d\n", limits->maxmsgcount);
-        fprintf(fs, "default_quota: %d\n", limits->defaultquota);
-        fprintf(fs, "default_maxmsgcount: %d\n", limits->defaultmaxmsgcount);
+        fprintf(fs, "quota: %llu\n", limits->diskquota);
+        fprintf(fs, "maxmsgcount: %llu\n", limits->maxmsgcount);
+        fprintf(fs, "default_quota: %llu\n", limits->defaultquota);
+        fprintf(fs, "default_maxmsgcount: %llu\n", limits->defaultmaxmsgcount);
         if (limits->disable_pop) fprintf(fs, "disable_pop\n");
         if (limits->disable_imap) fprintf(fs, "disable_imap\n");
         if (limits->disable_dialup) fprintf(fs, "disable_dialup\n");
diff -uPr vpopmail-5.5.0.orig/vlimits.h vpopmail-5.5.0/vlimits.h
--- vpopmail-5.5.0.orig/vlimits.h       2010-11-05 18:37:22.000000000 +0000
+++ vpopmail-5.5.0/vlimits.h    2015-09-18 12:36:07.568093410 +0100
@@ -20,6 +20,8 @@
 #define VLIMIT_DISABLE_ALL 
(VLIMIT_DISABLE_CREATE|VLIMIT_DISABLE_MODIFY|VLIMIT_DISABLE_DELETE)
 #define VLIMIT_DISABLE_BITS 3
 
+#include "storage.h"
+
 struct vlimits {
       /* max service limits */
       int       maxpopaccounts;
@@ -29,10 +31,10 @@
       int       maxmailinglists;
 
       /* quota & message count limits */
-      int       diskquota;
-      int       maxmsgcount;
-      int       defaultquota;
-      int       defaultmaxmsgcount;
+      storage_t diskquota;
+      storage_t maxmsgcount;
+      storage_t defaultquota;
+      storage_t defaultmaxmsgcount;
 
       /* the following are 0 (false) or 1 (true) */
       short     disable_pop;
diff -uPr vpopmail-5.5.0.orig/vlistlib.c vpopmail-5.5.0/vlistlib.c
--- vpopmail-5.5.0.orig/vlistlib.c      2010-11-05 18:37:22.000000000 +0000
+++ vpopmail-5.5.0/vlistlib.c   2015-09-18 12:36:07.568093410 +0100
@@ -193,8 +193,8 @@
 
     if( DomainOnly ) {    //   Have domain
         if ( strstr( Address, "@") != NULL ) return(4);
-        snprintf( LI->Name,   MAX_FILE_NAME, "%s", "" );
-        snprintf( LI->Domain, MAX_FILE_NAME, "%s", Address );
+        snprintf( LI->Name,   sizeof(LI->Name), "%s", "" );
+        snprintf( LI->Domain, sizeof(LI->Domain), "%s", Address );
     }
 
     else {                //   Have mail list
@@ -206,13 +206,13 @@
 
     if(( LI->entry = get_domain_entries( LI->Domain )) == NULL ) return(3);
 
-    snprintf( LI->OwnerEmail,   MAX_FILE_NAME, "postmaster@%s", LI->Domain ); 
-    snprintf( LI->ReplyTo_Addr, MAX_FILE_NAME, "%s", "" );
-    snprintf( LI->SQLBase,      MAX_FILE_NAME, "ezmlm" );
-    snprintf( LI->SQLHost,      MAX_FILE_NAME, "localhost" );
-    snprintf( LI->SQLPass,      MAX_FILE_NAME, "dbpass" );
-    snprintf( LI->SQLTable,     MAX_FILE_NAME, "ezmlm" );
-    snprintf( LI->SQLUser,      MAX_FILE_NAME, "dbUser" );
+    snprintf( LI->OwnerEmail,   sizeof(LI->OwnerEmail), "postmaster@%s", 
LI->Domain ); 
+    snprintf( LI->ReplyTo_Addr, sizeof(LI->ReplyTo_Addr), "%s", "" );
+    snprintf( LI->SQLBase,      sizeof(LI->SQLBase), "ezmlm" );
+    snprintf( LI->SQLHost,      sizeof(LI->SQLHost), "localhost" );
+    snprintf( LI->SQLPass,      sizeof(LI->SQLPass), "dbpass" );
+    snprintf( LI->SQLTable,     sizeof(LI->SQLTable), "ezmlm" );
+    snprintf( LI->SQLUser,      sizeof(LI->SQLUser), "dbUser" );
 
 //    printf( "before make name\n" );
 
diff -uPr vpopmail-5.5.0.orig/vmoddomlimits.c vpopmail-5.5.0/vmoddomlimits.c
--- vpopmail-5.5.0.orig/vmoddomlimits.c 2010-11-05 18:37:22.000000000 +0000
+++ vpopmail-5.5.0/vmoddomlimits.c      2015-09-18 12:36:07.569093463 +0100
@@ -212,10 +212,10 @@
             printf ((limits.perm_defaultquota & VLIMIT_DISABLE_DELETE ? 
"DENY_DELETE  " :"ALLOW_DELETE ") );
             
             printf("\n");
-            printf("Domain Quota: %d MB\n", limits.diskquota);
-            printf("Default User Quota: %d bytes\n", limits.defaultquota);
-            printf("Max Domain Messages: %d\n", limits.maxmsgcount);
-            printf("Default Max Messages per User: %d\n", 
limits.defaultmaxmsgcount);
+            printf("Domain Quota: %llu MB\n", limits.diskquota);
+            printf("Default User Quota: %llu bytes\n", limits.defaultquota);
+            printf("Max Domain Messages: %llu\n", limits.maxmsgcount);
+            printf("Default Max Messages per User: %llu\n", 
limits.defaultmaxmsgcount);
             return(vexit(0));
         }
                 
@@ -237,16 +237,16 @@
         
         /* quota & message count limits */
         if (DomainQuota[0] != 0) {
-            limits.diskquota = atoi(DomainQuota);
+            limits.diskquota = strtoll(DomainQuota, NULL, 10);
         }
         if (DomainMaxMsgCount[0] != 0) {
-            limits.maxmsgcount = atoi(DomainMaxMsgCount);
+            limits.maxmsgcount = strtoll(DomainMaxMsgCount, NULL, 10);
         }
         if (DefaultUserQuota[0] != 0) {
-            limits.defaultquota = atoi(format_maildirquota(DefaultUserQuota));
+            limits.defaultquota = 
strtoll(format_maildirquota(DefaultUserQuota), NULL, 10);
         }
         if (DefaultUserMaxMsgCount[0] != 0) {
-            limits.defaultmaxmsgcount = atoi(DefaultUserMaxMsgCount);
+            limits.defaultmaxmsgcount = strtoll(DefaultUserMaxMsgCount, NULL, 
10);
         }
         
         if (GidFlag == 1) {
diff -uPr vpopmail-5.5.0.orig/vpopmail.c vpopmail-5.5.0/vpopmail.c
--- vpopmail-5.5.0.orig/vpopmail.c      2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/vpopmail.c   2015-09-18 12:36:07.571093562 +0100
@@ -42,6 +42,7 @@
 #include "vauth.h"
 #include "vlimits.h"
 #include "maildirquota.h"
+#include "storage.h"
 #include "vauthmodule.h"
 #include "pwstr.h"
 
@@ -85,6 +86,44 @@
    char *value;
  } sortrec;
 
+/************************************************************************/
+
+void string_list_init(string_list *a, int initial) {
+  a->count = 0;
+  a->size = ((initial + 3) / 4) * 4;
+  if (a->size <= 0) a->size = 4;
+  a->values = calloc(a->size, sizeof(char **));
+  if (a->values == NULL) a->size = 0;
+}
+
+int string_list_add(string_list *a, char *value) {
+  if (a->count >= (a->size - 2)) {
+    char **new;
+
+    a->size += 8;
+    new = realloc(a->values, a->size * sizeof(char **));
+    if (new != NULL) {
+      a->values = new;
+      return a->size;
+    }
+    return 0;
+  }
+
+  if ((a->values[a->count] = strdup(value)) == NULL)
+    return 0;
+  a->count++;
+  return 1;
+}
+
+void string_list_free(string_list *a) {
+ int i;
+
+  if (a->values == NULL) return;
+  for (i = 0; i < a->count; i++)
+    free(a->values[i]);
+  free(a->values);
+}
+
 
 /************************************************************************/
 
@@ -104,24 +143,16 @@
  char dir_control_for_uid[MAX_BUFF];
  char tmpbuf[MAX_BUFF];
  char Dir[MAX_BUFF];
- char calling_dir[MAX_BUFF];
+ int call_dir;
  char ddir[512] = { 0 };
 
- char *aliases[1];
- int aliascount=0;
+ string_list aliases;
 
 #ifdef ONCHANGE_SCRIPT
   /*  Don't execute any implied onchange in called functions  */
   allow_onchange = 0;
 #endif
 
-  /*
-   * In case we need to use delete_line, build an array and count 
-   * to use as its parameters 
-   *
-   */
-  aliases[aliascount++]=strdup(domain);
-
   /* we only do lower case */
   lowerit(domain);
 
@@ -156,7 +187,7 @@
   umask(VPOPMAIL_UMASK);
 
   /* store the calling directory */
-  getcwd(calling_dir, sizeof(calling_dir));
+  call_dir = open(".", O_RDONLY);
 
   if ((dir == NULL) || ((const char *)dir == (const char 
*)VPOPMAIL_DIR_DOMAINS) || (!(*dir))) {
         memset(ddir, 0, sizeof(ddir));
@@ -176,7 +207,7 @@
 
     /* if it's not there, no problem, just try to create it */
     if ( mkdir(dir, VPOPMAIL_DIR_MODE) != 0 ) {
-      chdir(calling_dir);
+      fchdir(call_dir); close(call_dir);
       return(VA_CAN_NOT_MAKE_DOMAINS_DIR);
     }
 
@@ -185,7 +216,7 @@
 
     /* now try moving into the Domains subdir again */
     if ( chdir(dir) != 0 ) {
-      chdir(calling_dir);
+      fchdir(call_dir); close(call_dir);
       return(VA_BAD_D_DIR);
     }
   }
@@ -218,7 +249,7 @@
   if (strlen(dir)+strlen(DomainSubDir) > MAX_PW_DIR) {
     /* back out of changes made so far */
     dec_dir_control(dir_control_for_uid, uid, gid);
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     return(VA_DIR_TOO_LONG);
   }
 
@@ -226,7 +257,7 @@
   if ( r_mkdir(DomainSubDir, uid, gid ) != 0 ) {
     /* back out of changes made so far */
     dec_dir_control(dir_control_for_uid, uid, gid);
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     return(VA_COULD_NOT_MAKE_DOMAIN_DIR);
   }
   
@@ -234,7 +265,7 @@
     /* back out of changes made so far */
     vdelfiles(DomainSubDir);
     dec_dir_control(dir_control_for_uid, uid, gid);
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     return(VA_BAD_D_DIR);
   }
 
@@ -247,7 +278,7 @@
       fprintf(stderr, "Failed to delete directory tree: %s\n", DomainSubDir);
     }
     dec_dir_control(dir_control_for_uid, uid, gid);
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     return(VA_COULD_NOT_OPEN_QMAIL_DEFAULT);
   } else {
     fprintf(fs, "| %s/vdelivermail '' bounce-no-mailbox\n", VPOPMAIL_DIR_BIN);
@@ -262,7 +293,7 @@
       fprintf(stderr, "Failed to delete directory tree: %s\n", DomainSubDir);
     }
     dec_dir_control(dir_control_for_uid, uid, gid);
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     fprintf (stderr, "Error. Failed to add domain to assign file\n");
     return (VA_COULD_NOT_UPDATE_FILE);
   }
@@ -292,11 +323,14 @@
 
     vget_assign(domain, Dir, sizeof(Dir), &uid, &gid );
 
-    if ( del_domain_assign(aliases, aliascount, domain, Dir, uid, gid) != 0) {
+    string_list_init(&aliases, 1);
+    string_list_add(&aliases, domain);
+
+    if ( del_domain_assign(aliases.values, aliases.count, domain, Dir, uid, 
gid) != 0) {
       fprintf(stderr, "Failed while attempting to remove domain from assign 
file\n");
     }
 
-    if (del_control(aliases,aliascount) !=0) {
+    if (del_control(aliases.values,aliases.count) !=0) {
       fprintf(stderr, "Failed while attempting to delete domain from the qmail 
control files\n");
     }
 
@@ -309,6 +343,9 @@
     /* send a HUP signal to qmail-send process to reread control files */
     signal_process("qmail-send", SIGHUP);
 
+    fchdir(call_dir); close(call_dir);
+    string_list_free(&aliases);
+
     return (VA_NO_AUTH_CONNECTION);
   }    
  
@@ -327,9 +364,7 @@
 #endif
 
   /* return back to the callers directory and return success */
-  chdir(calling_dir);
-
-  free( aliases[0] );
+  fchdir(call_dir); close(call_dir);
 
   return(VA_SUCCESS);
 }
@@ -352,9 +387,10 @@
  char dircontrol[MAX_BUFF];
  uid_t uid;
  gid_t gid;
- char *aliases[MAX_DOM_ALIAS];
+ string_list aliases;
  domain_entry *entry;
- int i=0, aliascount=0;
+ int i=0;
+ int call_dir;
 
   /* we always convert domains to lower case */
   lowerit(domain);
@@ -389,7 +425,8 @@
       *  that are about to be deleted.  It will be the only one
       *  but I will use the same code as multi domains anyway.
       */
-     aliases[aliascount++] = strdup( domain_to_del );
+     string_list_init(&aliases, 1);
+     string_list_add(&aliases, domain_to_del);
 
 #ifdef ONCHANGE_SCRIPT
      /* tell other programs that data has changed */
@@ -437,14 +474,16 @@
        }
      }
 
+     string_list_init(&aliases, 10);
+
      while( entry ) {
-       aliases[aliascount++] = strdup(entry->domain);
+       string_list_add(&aliases, entry->domain);
        entry = get_domain_entries(NULL);
      }
 
 //   Dump the alias list
-//     for(i=0;i<aliascount;i++) {
-//       fprintf(stderr,"alias %s\n", aliases[i]);
+//     for(i=0;i<aliases.count;i++) {
+//       fprintf(stderr,"alias %s\n", aliases.values[i]);
 //     }
 
 
@@ -490,20 +529,20 @@
 
     /* Now remove domain from filesystem */
     /* if it's a symbolic link just remove the link */
-    if ( S_ISLNK(statbuf.st_mode) ) {
+    if ( readlink(Dir, (char *) &call_dir, sizeof(call_dir)) != -1) {
       if ( unlink(Dir) !=0) {
         fprintf (stderr, "Warning: Failed to remove symlink for %s\n", domain);
       }
     } else {
-      char cwdbuff[MAX_BUFF];
-      char *cwd;
       /* Not a symlink.. so we have to del some files structure now */
       /* zap the domain's directory tree */
-      cwd = getcwd (cwdbuff, sizeof(cwdbuff));  /* save calling directory */
+      call_dir = open(".", O_RDONLY);
+
       if ( vdelfiles(Dir) != 0 ) {
         fprintf(stderr, "Warning: Failed to delete directory tree: %s\n", 
domain);
       }
-      if (cwd != NULL) chdir (cwd);
+
+      fchdir(call_dir); close(call_dir);
     }
 
     /* decrement the master domain control info */
@@ -516,12 +555,12 @@
   /* delete the email domain from the qmail control files :
    * rcpthosts, morercpthosts, virtualdomains
    */
-  if (del_control(aliases,aliascount) != 0) {
+  if (del_control(aliases.values,aliases.count) != 0) {
     fprintf (stderr, "Warning: Failed to delete domain from qmail's control 
files\n");
   }
 
   /* delete the assign file line */
-  if (del_domain_assign(aliases, aliascount, domain, Dir, uid, gid) != 0) {
+  if (del_domain_assign(aliases.values, aliases.count, domain, Dir, uid, gid) 
!= 0) {
     fprintf (stderr, "Warning: Failed to delete domain from the assign 
file\n");
   }
 
@@ -529,13 +568,9 @@
   signal_process("qmail-send", SIGHUP);
 
   /*  clean up memory used by the alias list  */
-  for(i=0;i<aliascount;i++) {
-    free( aliases[i] );
-  }
-
+  string_list_free(&aliases);
 
   return(VA_SUCCESS);
-
 }
 
 /************************************************************************/
@@ -639,7 +674,7 @@
    int ret;
  char Dir[MAX_BUFF];
  char *user_hash;
- char calling_dir [MAX_BUFF];
+ int call_dir;
  uid_t uid = -1;
  gid_t gid = -1;
  struct vlimits limits;
@@ -686,9 +721,6 @@
   if (ret != 1)
         return ret;
 
-  /* record the dir where the vadduser command was run from */
-  getcwd(calling_dir, sizeof(calling_dir));
-
   /* lookup the home dir, uid and gid for the domain */
   if ( vget_assign(domain, Dir, sizeof(Dir), &uid, &gid)==NULL) {
     return(VA_DOMAIN_DOES_NOT_EXIST);
@@ -699,15 +731,19 @@
     return(VA_CANNOT_READ_LIMITS);
   }
 
+  /* record the dir where the vadduser command was run from */
+  call_dir = open(".", O_RDONLY);
+
   /* go to the domain's home dir (ie test it exists) */
   /* would a stat be a better option here? */
   if ( chdir(Dir) != 0 ) {
+    close(call_dir);
     return(VA_BAD_D_DIR);
   }
 
   /* create dir for the the user */ 
   if ( (user_hash=make_user_dir(username, domain, uid, gid)) == NULL ) {
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     if (verrori != 0 ) return(verrori);
     else return(VA_BAD_U_DIR);
   }
@@ -718,19 +754,19 @@
     fprintf(stderr, "Failed while attempting to add user to auth backend\n");
     /* back out of changes made so far */
     chdir(Dir); if (strlen(user_hash)>0) { chdir(user_hash);} 
vdelfiles(username);
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     return(VA_NO_AUTH_CONNECTION);
   }
 
   if (limits.defaultquota > 0) {
     if (limits.defaultmaxmsgcount > 0)
-      snprintf (quota, sizeof(quota), "%dS,%dC", limits.defaultquota,
+      snprintf (quota, sizeof(quota), "%lluS,%lluC", limits.defaultquota,
         limits.defaultmaxmsgcount);
     else
-      snprintf (quota, sizeof(quota), "%dS", limits.defaultquota);
+      snprintf (quota, sizeof(quota), "%lluS", limits.defaultquota);
   } else {
     if (limits.defaultmaxmsgcount > 0)
-      snprintf (quota, sizeof(quota), "%dC", limits.defaultmaxmsgcount);
+      snprintf (quota, sizeof(quota), "%lluC", limits.defaultmaxmsgcount);
     else
       strcpy (quota, "NOQUOTA");
   }
@@ -757,14 +793,14 @@
   if (vauth_module_feature("AUTH_LOGGING")) {
          if (vset_lastauth(username,domain,NULL_REMOTE_IP) !=0) {
                 /* should we back out of all the work we have done so far? */
-                chdir(calling_dir);
+                fchdir(call_dir); close(call_dir);
                 fprintf (stderr, "Failed to create create lastauth entry\n");
                 return (VA_NO_AUTH_CONNECTION);
          }
   }
 
   /* jump back into the dir from which the vadduser was run */
-  chdir(calling_dir);
+  fchdir(call_dir); close(call_dir);
 
 #ifdef ONCHANGE_SCRIPT
   allow_onchange = temp_onchange;
@@ -1012,10 +1048,10 @@
  struct stat mystat;
  char tmpstr1[MAX_BUFF];
  char tmpstr2[MAX_BUFF];
- char *aliases[1];
- int aliascount=0;
+ string_list aliases;
 
- aliases[aliascount++]=strdup(alias_domain);
+  string_list_init(&aliases, 1);
+  string_list_add(&aliases,alias_domain);
 
   snprintf(tmpstr1, sizeof(tmpstr1), "%s/users/assign", QMAILDIR);
 
@@ -1086,13 +1122,13 @@
 
   /* make sure it's not in locals and set mode */
   snprintf(tmpstr1, sizeof(tmpstr1), "%s/control/locals", QMAILDIR);
-  if (remove_lines( tmpstr1, aliases, aliascount) < 0) {
+  if (remove_lines( tmpstr1, aliases.values, aliases.count) < 0) {
     fprintf (stderr, "Failure while attempting to remove_lines() the locals 
file\n");
     return(-1);
   }
   chmod(tmpstr1, VPOPMAIL_QMAIL_MODE ); 
 
-  free( aliases[0] );
+  string_list_free(&aliases);
 
   return(0);
 }
@@ -1105,12 +1141,12 @@
  * - /var/qmail/control/rcpthosts
  * - /var/qmail/control/virtualdomains
  */
-int del_control(char *aliases[MAX_DOM_ALIAS], int aliascount ) 
+int del_control(char **aliases, int aliascount ) 
 {
  char tmpbuf1[MAX_BUFF];
  char tmpbuf2[MAX_BUFF];
  struct stat statbuf;
- char *virthosts[MAX_DOM_ALIAS];
+ string_list virthosts;
 
  int problem_occurred = 0, i=0;
 
@@ -1168,21 +1204,20 @@
   } /* switch for rcpthosts */
 
   /* delete entry from control/virtualdomains (if it exists) */
+  string_list_init(&virthosts, 10);
   
   for(i=0;i<aliascount;i++) {
     snprintf(tmpbuf1, sizeof(tmpbuf1), "%s:%s", aliases[i], aliases[i]);
-    virthosts[i]=strdup(tmpbuf1);
+    string_list_add(&virthosts, tmpbuf1);
   }
 
   snprintf(tmpbuf2, sizeof(tmpbuf2), "%s/control/virtualdomains", QMAILDIR);
-  if (remove_lines( tmpbuf2, virthosts, aliascount) < 0 ) {
+  if (remove_lines( tmpbuf2, virthosts.values, virthosts.count) < 0 ) {
     fprintf(stderr, "Failed while attempting to remove_lines() the 
virtualdomains file\n"); 
     problem_occurred = 1; 
   }
 
-  for(i=0;i<aliascount;i++) {
-    free( virthosts[i] );
-  }
+  string_list_free(&virthosts);
 
   /* make sure correct permissions are set on virtualdomains */
   chmod(tmpbuf2, VPOPMAIL_QMAIL_MODE ); 
@@ -1205,31 +1240,36 @@
  *          greater than 0 = number of aliases deleted
  *
  */
-int del_domain_assign( char *aliases[MAX_DOM_ALIAS], int aliascount, 
+int del_domain_assign( char **aliases, int aliascount, 
                        char *real_domain, 
                        char *dir, gid_t uid, gid_t gid )  
 {
  char search_string[MAX_BUFF];
  char assign_file[MAX_BUFF];
- char *virthosts[MAX_DOM_ALIAS];
+ string_list virthosts;
  int i;
 
+  string_list_init(&virthosts, 10);
+
   /* format the removal string */ 
   for(i=0;i<aliascount;i++) {
   snprintf(search_string, sizeof(search_string), "+%s-:%s:%lu:%lu:%s:-::",
       aliases[i], real_domain, (long unsigned)uid, (long unsigned)gid, dir);
-    virthosts[i] = strdup( search_string );
+    string_list_add(&virthosts, search_string);
   }
 
   /* format the assign file name */
   snprintf(assign_file, sizeof(assign_file), "%s/users/assign", QMAILDIR);
 
   /* remove the formatted string from the file */
-  if (remove_lines( assign_file, virthosts, aliascount ) < 0) {
+  if (remove_lines( assign_file, virthosts.values, virthosts.count ) < 0) {
     fprintf(stderr, "Failed while attempting to remove_lines() the assign 
file\n");
+    string_list_free(&virthosts);
     return (-1);
   }
 
+  string_list_free(&virthosts);
+
   /* force the permission on the file */
   chmod(assign_file, VPOPMAIL_QMAIL_MODE ); 
 
@@ -1251,7 +1291,7 @@
  *          0 on success, no match found
  *          1 on success, match was found
  */
-int remove_lines( char *filename, char *aliases[MAX_DOM_ALIAS], int aliascount 
)
+int remove_lines( char *filename, char **aliases, int aliascount )
 {
  FILE *fs = NULL;
  FILE *fs1 = NULL;
@@ -1816,7 +1856,7 @@
  char Dir[MAX_BUFF];
  uid_t uid;
  gid_t gid;
- char calling_dir[MAX_BUFF];
+ int call_dir;
 
   if ( user == 0 || strlen(user)<=0) return(VA_ILLEGAL_USERNAME);
 
@@ -1845,7 +1885,7 @@
   lowerit(domain);
 
   /* backup the dir where the vdeluser was run from */
-  getcwd(calling_dir, sizeof(calling_dir));
+  call_dir = open(".", O_RDONLY);
 
   /* lookup the location of this domain's directory */
   if ( vget_assign(domain, Dir, sizeof(Dir), &uid, &gid ) == NULL ) {
@@ -1854,7 +1894,7 @@
 
   /* change into that directory */
   if ( chdir(Dir) != 0 ) {
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     return(VA_BAD_D_DIR);
   }
 
@@ -1878,7 +1918,7 @@
   /* del the user from the auth system */
   if (vauth_deluser( user, domain ) !=0 ) {
     fprintf (stderr, "Failed to delete user from auth backend\n");
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     return (-1);
   }
 
@@ -1891,12 +1931,12 @@
    */
   if ( vdelfiles(mypw->pw_dir) != 0 ) {
     fprintf(stderr, "could not remove %s\n", mypw->pw_dir);
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     return(VA_BAD_DIR);
   }
 
   /* go back to the callers directory */
-  chdir(calling_dir);
+  fchdir(call_dir); close(call_dir);
   return(VA_SUCCESS);
 
 }
@@ -2463,15 +2503,13 @@
 {
  char *user_hash;
  struct vqpasswd *mypw;
- char calling_dir[MAX_BUFF];
+ int call_dir;
  char domain_dir[MAX_BUFF];
  const char *dirnames[] = {"Maildir", "Maildir/new", "Maildir/cur", 
        "Maildir/tmp"};
  int i;
 
   verrori = 0;
-  /* record the dir where the command was run from */
-  getcwd(calling_dir, sizeof(calling_dir));
 
   /* retrieve the dir that stores this domain */
   if (vget_assign(domain, domain_dir, sizeof(domain_dir), NULL, NULL) == NULL) 
{
@@ -2479,6 +2517,9 @@
     return(NULL);
   }
 
+  /* record the dir where the command was run from */
+  call_dir = open(".", O_RDONLY);
+
   /* go to the dir for our chosen domain */
   chdir(domain_dir); 
 
@@ -2498,7 +2539,7 @@
      long to save back to the auth backend */
   if ((strlen(domain_dir)+strlen(user_hash)+strlen(username)) > MAX_PW_DIR) {
     fprintf (stderr, "Error. Path exceeds maximum permitted length\n");
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     return (NULL);
   }
 
@@ -2506,14 +2547,14 @@
   if ( mkdir(username, VPOPMAIL_DIR_MODE) != 0 ) {
     /* need to add some code to remove the hashed dirs we created above... */
     verrori = VA_EXIST_U_DIR;
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     return(NULL);
   }
 
   if ( chdir(username) != 0 ) {
     /* back out of changes made above */
     chdir(domain_dir); chdir(user_hash); vdelfiles(username);
-    chdir(calling_dir);
+    fchdir(call_dir); close(call_dir);
     fprintf(stderr, "make_user_dir: error 2\n");
     return(NULL);
   }
@@ -2524,7 +2565,7 @@
       /* back out of changes made above */
       chdir("..");
       vdelfiles(username);
-      chdir(calling_dir);
+      fchdir(call_dir); close(call_dir);
       return(NULL);
     }
   }
@@ -2552,7 +2593,7 @@
     free (mypw->pw_dir);
   }
 
-  chdir(calling_dir);
+  fchdir(call_dir); close(call_dir);
   return(user_hash);
 }
 
@@ -3273,18 +3314,12 @@
 int vmake_maildir(char *domain, char *dir )
 {
  char tmpbuf[MAX_BUFF];
- char calling_dir[MAX_BUFF];
+ int call_dir;
  uid_t uid;
  gid_t gid;
  char *tmpstr;
  int i;
 
-  /* record which dir the command was launched from */
-  getcwd(calling_dir, sizeof(calling_dir));
-
-  /* set the mask for file creation */
-  umask(VPOPMAIL_UMASK);
- 
   /* check if domain exists.
    * if domain exists, store the dir into tmpbuf, and store uid and gid
    */
@@ -3292,6 +3327,12 @@
     return( VA_DOMAIN_DOES_NOT_EXIST );
   }
 
+  /* record which dir the command was launched from */
+  call_dir = open(".", O_RDONLY);
+
+  /* set the mask for file creation */
+  umask(VPOPMAIL_UMASK);
+ 
   /* so, we should have some variables like this now :
    *   dir:    /home/vpopmail/domains/[x]/somedomain.com/[x]/someuser
    *   tmpbuf: /home/vpopmail/domains/[x]/somedomain.com
@@ -3306,7 +3347,7 @@
   /* tmpstr should now contain : [x]/someuser */
 
   /* so 1st cd into the domain dir (which should already exist) */
-  if ( chdir(tmpbuf) == -1 ) { chdir(calling_dir); return( VA_BAD_DIR); }
+  if ( chdir(tmpbuf) == -1 ) { fchdir(call_dir); close(call_dir); return( 
VA_BAD_DIR); }
 
   /* Next, create the user's dir
    * ie [x]/someuser
@@ -3314,21 +3355,22 @@
   r_mkdir(tmpstr, uid, gid);
 
   /* we should now be able to cd into the user's dir */
-  if ( chdir(dir) != 0 ) { chdir(calling_dir); return(-1); }
+  if ( chdir(dir) != 0 ) { fchdir(call_dir); close(call_dir); return(-1); }
 
   /* now create the Maildir */
-  if (mkdir("Maildir",VPOPMAIL_DIR_MODE) == -1) { chdir(calling_dir); 
return(-1); }
-  if (chdir("Maildir") == -1) { chdir(calling_dir); return(-1); }
-  if (mkdir("cur",VPOPMAIL_DIR_MODE) == -1) { chdir(calling_dir); return(-1); }
-  if (mkdir("new",VPOPMAIL_DIR_MODE) == -1) { chdir(calling_dir); return(-1); }
-  if (mkdir("tmp",VPOPMAIL_DIR_MODE) == -1) { chdir(calling_dir); return(-1); }
+  if (mkdir("Maildir",VPOPMAIL_DIR_MODE) == -1) { fchdir(call_dir); 
close(call_dir); return(-1); }
+  if (chdir("Maildir") == -1) { fchdir(call_dir); close(call_dir); return(-1); 
}
+  if (mkdir("cur",VPOPMAIL_DIR_MODE) == -1) { fchdir(call_dir); 
close(call_dir); return(-1); }
+  if (mkdir("new",VPOPMAIL_DIR_MODE) == -1) { fchdir(call_dir); 
close(call_dir); return(-1); }
+  if (mkdir("tmp",VPOPMAIL_DIR_MODE) == -1) { fchdir(call_dir); 
close(call_dir); return(-1); }
 
   /* set permissions on the user's dir */
   chdir(dir);
   r_chown(dir, uid, gid);
 
   /* change back to the orignal dir */
-  chdir(calling_dir);
+  fchdir(call_dir); close(call_dir);
+
   return(0);
 }
 
@@ -3923,8 +3965,8 @@
 
 char *format_maildirquota(const char *q) {
 int     i;
-double quota_size;
-long   quota_count;
+storage_t quota_size;
+storage_t quota_count;
 char   *p;
 static char    tempquota[128];
 
@@ -3934,34 +3976,34 @@
     }
 
     /* translate the quota to a number, or leave it */
-    quota_size = -1.0;
-    quota_count = -1;
+    quota_size = 0;
+    quota_count = 0;
     snprintf (tempquota, sizeof(tempquota), "%s", q);
     p = strtok (tempquota, ",");
     while (p != NULL) {
       i = strlen(p) - 1;
       if (p[i] == 'C') { /* specify a limit on the number of messages (COUNT) 
*/
-        quota_count = atol(p);
+        quota_count = strtoll(p, NULL, 10);
       } else { /* specify a limit on the size */
         /* strip optional trailing S */
         if ((p[i] == 'S') || (p[i] == 's')) p[i--] = '\0';
         /* strip optional trailing B (for KB, MB) */
         if ((p[i] == 'B') || (p[i] == 'b')) p[i--] = '\0';
 
-        quota_size = atof(p);
+        quota_size = strtoll(p, NULL, 10);
         if ((p[i] == 'M') || (p[i] == 'm')) quota_size *= 1024 * 1024;
         if ((p[i] == 'K') || (p[i] == 'k')) quota_size *= 1024;
       }
       p = strtok (NULL, ",");
     }
 
-    if (quota_count == -1)
-      if (quota_size == -1.0) strcpy (tempquota, ""); /* invalid quota */
-      else sprintf (tempquota, "%.0fS", quota_size);
-    else if (quota_size == -1.0)
-      sprintf (tempquota, "%luC", quota_count);
+    if (quota_count == 0)
+      if (quota_size == 0) strcpy (tempquota, ""); /* invalid quota */
+      else sprintf (tempquota, "%lluS", quota_size);
+    else if (quota_size == 0)
+      sprintf (tempquota, "%lluC", quota_count);
     else
-      sprintf (tempquota, "%.0fS,%luC", quota_size, quota_count);
+      sprintf (tempquota, "%lluS,%lluC", quota_size, quota_count);
 
     return tempquota;
 }
@@ -4027,16 +4069,28 @@
 char *maildir_to_email (const char *maildir)
 {
        static char email[256];
+       char calling_dir[MAX_BUFF];
        int i;
        char *pnt, *last;
        char *mdcopy;
        char *user;
        int sawdot;
        
-       mdcopy = malloc (strlen (maildir) + 1);
-       if (mdcopy == NULL) return "";
-       strcpy (mdcopy, maildir);
-       
+       /* prepend the cwd if the maildir starts with ./ */
+       if (strlen (maildir) > 1 && maildir[0] == '.' && maildir[1] == '/')
+       {
+               getcwd(calling_dir, sizeof(calling_dir));
+               mdcopy = malloc (strlen (maildir) + strlen (calling_dir) + 1);
+               if (mdcopy == NULL) return "";
+               strcat (strcpy (mdcopy, calling_dir), maildir + 1);
+       }
+       else
+       {
+               mdcopy = malloc (strlen (maildir) + 1);
+               if (mdcopy == NULL) return "";
+               strcpy (mdcopy, maildir);
+       }
+
        /* find the last occurrence of /Maildir/ */
        pnt = mdcopy;
        do {
@@ -4192,7 +4246,7 @@
        int printed;   /* number of characters printed */
        const char *f; /* current position in format string */
        char *b;       /* current position in output buffer */
-       char n[20];    /* buffer to hold string representation of number */
+       char n[60];    /* buffer to hold string representation of number */
        
         int argn = 0;  /* used for numbered arguments */
         char argstr[10];
@@ -4224,9 +4278,14 @@
                                case 'u':
                                        snprintf (n, sizeof(n), "%u", va_arg 
(ap, unsigned int));
                                        break;
+
+                               case 'S':
+                                       snprintf (n, sizeof(n), "%llu", va_arg 
(ap, storage_t));
+                                       break;
                                        
                                case 'l':
                                        f++;
+
                                        switch (*f) {
                                                case 'd':
                                                case 'i':
diff -uPr vpopmail-5.5.0.orig/vpopmaild.c vpopmail-5.5.0/vpopmaild.c
--- vpopmail-5.5.0.orig/vpopmaild.c     2010-11-05 18:37:23.000000000 +0000
+++ vpopmail-5.5.0/vpopmaild.c  2015-09-18 12:36:07.573093655 +0100
@@ -245,8 +245,8 @@
 
   memset(ReadBuf,0,sizeof(ReadBuf));
   if (select(2,&rfds,(fd_set *) 0,(fd_set *)0,&tv)>=1) {
-    fgets(ReadBuf,sizeof(ReadBuf),stdin);
-    return(1);
+    if (fgets(ReadBuf,sizeof(ReadBuf),stdin) != NULL)
+      return(1);
   }
   return(-1);
 }
@@ -301,7 +301,7 @@
     exit( -1 );
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
   wait_write();
 
   /* authenticate first or drop connection */
@@ -1202,8 +1202,8 @@
 {
  char *domain;
  domain_entry *entry;
- char *aliases[MAX_DOM_ALIAS];
- int  i, aliascount=0;
+ string_list aliases;
+ int i;
 
   if ( !(AuthVpw.pw_gid & SA_ADMIN) ) {
     show_error( ERR_NOT_AUTHORIZED, 1401 );
@@ -1232,10 +1232,11 @@
   snprintf(WriteBuf,sizeof(WriteBuf), RET_OK_MORE);
   wait_write();
 
+  string_list_init(&aliases, 10);
+
   while( entry ) {
     if (strcmp(entry->domain, entry->realdomain) != 0) {
-      aliases[aliascount++] = strdup(entry->domain);
-
+      string_list_add(&aliases, entry->domain);
     } else {
       snprintf(WriteBuf,sizeof(WriteBuf),"domain %s" RET_CRLF, 
                entry->domain);
@@ -1258,14 +1259,13 @@
     entry = get_domain_entries(NULL);
   }
 
-  for(i=0;i<aliascount;i++) {
+  for(i=0;i<aliases.count;i++) {
     snprintf(WriteBuf,sizeof(WriteBuf),"alias %s" RET_CRLF, 
-             aliases[i]);
+             aliases.values[i]);
     wait_write();
-    free( aliases[i] );
   } 
 
-
+  string_list_free(&aliases);
 
   snprintf(WriteBuf, sizeof(WriteBuf), "." RET_CRLF);
   return(0);
@@ -1420,7 +1420,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
   return(0);
 }
 
@@ -1444,7 +1444,7 @@
       strerror(errno));
     return(-1);
   }
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
   return(0);
 }
 
@@ -1476,7 +1476,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
 
   while((mydirent=readdir(mydir))!=NULL){
@@ -1514,7 +1514,7 @@
     /* oh well, at least we might die soon */
   }
 
-  snprintf(WriteBuf, sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf, sizeof(WriteBuf), "%s", "." RET_CRLF);
   return(0);
 }
 
@@ -1545,9 +1545,8 @@
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
   return(0);
-
 }
 
 
@@ -1572,7 +1571,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
   return(0);
 }
 
@@ -1605,7 +1604,7 @@
   }
   fclose(fs);
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
   return(0);
 }
 
@@ -1630,7 +1629,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
 
   while(fgets(tmpbuf,sizeof(tmpbuf),fs)!=NULL){
@@ -1645,7 +1644,7 @@
   fclose(fs);
 
   if ( tmpbuf[0] != 0 && tmpbuf[strlen(tmpbuf)-1] != '\n' ) {
-    snprintf(WriteBuf,sizeof(WriteBuf), RET_CRLF "." RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_CRLF "." RET_CRLF);
   } else {
     snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
   }
@@ -1672,11 +1671,11 @@
       strerror(errno));
     return(-1);
   }
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
   snprintf(WriteBuf,sizeof(WriteBuf), "uid: %d\n", mystat.st_uid); 
   wait_write();
-  snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   return(0);
 }
 
@@ -1741,7 +1740,7 @@
     entry=get_domain_entries(NULL);
     
   }
-  snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   return(0);
 }
 
@@ -1778,7 +1777,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
 
   count = 0;
@@ -1796,7 +1795,7 @@
   }
 
   if( miss ) {
-    snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
     return(0);
   } else if( per_page > 0 ) {
     page = ( count / per_page ) + 1;
@@ -1807,7 +1806,7 @@
   snprintf(WriteBuf,sizeof(WriteBuf), "page %i" RET_CRLF, page );
   wait_write();
 
-  snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   return(0);
 }
 
@@ -1828,7 +1827,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
 
   count = 0;
@@ -1840,7 +1839,7 @@
   snprintf(WriteBuf,sizeof(WriteBuf), "count %i" RET_CRLF, count);
   wait_write();
 
-  snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   return(0);
 }
 
@@ -1873,7 +1872,7 @@
      return(-1);
    }
  
-   snprintf(WriteBuf, sizeof(WriteBuf), RET_OK_MORE);
+   snprintf(WriteBuf, sizeof(WriteBuf), "%s", RET_OK_MORE);
    wait_write();
  
    first=1;
@@ -1885,7 +1884,7 @@
 
    snprintf(WriteBuf,sizeof(WriteBuf), "count %i" RET_CRLF, count);
    wait_write();
-   snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+   snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
    return(0);
  }
         
@@ -1939,7 +1938,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf, sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf, sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
 
   first=1;
@@ -1956,13 +1955,13 @@
       send_user_info(tmpvpw);
     }
 
-    snprintf(WriteBuf, sizeof(WriteBuf), RET_CRLF );
+    snprintf(WriteBuf, sizeof(WriteBuf), "%s", RET_CRLF );
     wait_write();
 
     ++count;
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   return(0);
 }
 
@@ -2017,7 +2016,7 @@
   /*  print all aliases  */
   if (strstr(Email, "@") == NULL) {
     tmpalias = valias_select_all(Alias, Email);
-    snprintf(WriteBuf, sizeof(WriteBuf), RET_OK_MORE);
+    snprintf(WriteBuf, sizeof(WriteBuf), "%s", RET_OK_MORE);
     wait_write();
       
     while (tmpalias != NULL) {
@@ -2030,9 +2029,9 @@
   } else {
     tmpalias = valias_select(Alias, Domain);
     if (tmpalias == NULL) {
-      snprintf(WriteBuf, sizeof(WriteBuf), RET_OK);
+      snprintf(WriteBuf, sizeof(WriteBuf), "%s", RET_OK);
     } else {
-      snprintf(WriteBuf, sizeof(WriteBuf), RET_OK_MORE);
+      snprintf(WriteBuf, sizeof(WriteBuf), "%s", RET_OK_MORE);
       wait_write();
       
       while (tmpalias != NULL) {
@@ -2043,7 +2042,7 @@
     }
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   return(0);
 }
 
@@ -2106,7 +2105,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf, sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf, sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
 
   j = bkscandir(".", &namelist, 0, qa_sort);
@@ -2135,7 +2134,7 @@
     }
     ++count;
   }
-  snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   return(0);
 }
 
@@ -2157,16 +2156,16 @@
 
   if (vauth_module_feature("IP_ALIAS_DOMAINS")) {
   if ( vget_ip_map(ip,tmpdomain,sizeof(tmpdomain)) < 0 ) {
-    snprintf(WriteBuf,sizeof(WriteBuf), RET_ERR "0.3003 error" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_ERR "0.3003 error" RET_CRLF);
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf),RET_OK_MORE);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
  
   snprintf(WriteBuf,sizeof(WriteBuf),"%s %s" RET_CRLF, ip, tmpdomain);
   wait_write();
-  snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   }
 
   else
@@ -2202,11 +2201,11 @@
   }
 
   if ( vadd_ip_map(ip,domain) < 0 ) {
-    snprintf(WriteBuf,sizeof(WriteBuf), RET_ERR "0.3105 error" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_ERR "0.3105 error" RET_CRLF);
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf),RET_OK);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
    }
 
    else
@@ -2241,7 +2240,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf),RET_OK);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
   }
 
   else
@@ -2262,7 +2261,7 @@
   }
 
   if (vauth_module_feature("IP_ALIAS_DOMAINS")) {
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
 
   first = 1;
@@ -2272,7 +2271,7 @@
     snprintf(WriteBuf, sizeof(WriteBuf), "%s %s" RET_CRLF, r_ip, r_domain);
     wait_write();
   }
-  snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   }
 
   else
@@ -2302,7 +2301,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
 
   snprintf(WriteBuf,sizeof(WriteBuf), "max_popaccounts %d" RET_CRLF, 
@@ -2315,74 +2314,74 @@
     mylimits.maxautoresponders); wait_write();
   snprintf(WriteBuf,sizeof(WriteBuf), "max_mailinglists %d" RET_CRLF, 
     mylimits.maxmailinglists); wait_write();
-  snprintf(WriteBuf,sizeof(WriteBuf), "disk_quota %d" RET_CRLF, 
+  snprintf(WriteBuf,sizeof(WriteBuf), "disk_quota %llu" RET_CRLF, 
     mylimits.diskquota); wait_write();
-  snprintf(WriteBuf,sizeof(WriteBuf), "max_msgcount %d" RET_CRLF, 
+  snprintf(WriteBuf,sizeof(WriteBuf), "max_msgcount %llu" RET_CRLF, 
     mylimits.maxmsgcount); wait_write();
-  snprintf(WriteBuf,sizeof(WriteBuf), "default_quota %d" RET_CRLF, 
+  snprintf(WriteBuf,sizeof(WriteBuf), "default_quota %llu" RET_CRLF, 
     mylimits.defaultquota); wait_write();
-  snprintf(WriteBuf,sizeof(WriteBuf), "default_maxmsgcount %d" RET_CRLF, 
+  snprintf(WriteBuf,sizeof(WriteBuf), "default_maxmsgcount %llu" RET_CRLF, 
     mylimits.defaultmaxmsgcount); wait_write();
 
   if (mylimits.disable_pop) 
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_pop 1" RET_CRLF); 
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_pop 1" RET_CRLF); 
   else 
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_pop 0" RET_CRLF); 
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_pop 0" RET_CRLF); 
 
   wait_write();
 
   if (mylimits.disable_imap) 
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_imap 1" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_imap 1" RET_CRLF);
   else
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_imap 0" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_imap 0" RET_CRLF);
   wait_write();
 
   if (mylimits.disable_dialup) 
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_dialup 1" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_dialup 1" RET_CRLF);
   else 
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_dialup 0" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_dialup 0" RET_CRLF);
   wait_write();
 
   if (mylimits.disable_passwordchanging) 
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_password_changing 1" 
RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_password_changing 1" 
RET_CRLF);
   else 
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_password_changing 0" 
RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_password_changing 0" 
RET_CRLF);
   wait_write();
 
   if (mylimits.disable_webmail)
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_webmail 1" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_webmail 1" RET_CRLF);
   else
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_webmail 0" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_webmail 0" RET_CRLF);
   wait_write();
 
   if (mylimits.disable_relay)
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_external_relay 1" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_external_relay 1" 
RET_CRLF);
   else
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_external_relay 0" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_external_relay 0" 
RET_CRLF);
   wait_write();
 
   if (mylimits.disable_smtp)
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_smtp 1" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_smtp 1" RET_CRLF);
   else
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_smtp 0" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_smtp 0" RET_CRLF);
   wait_write();
 
   if (mylimits.disable_spamassassin) 
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_spamassassin 1" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_spamassassin 1" 
RET_CRLF);
   else 
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_spamassassin 0" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_spamassassin 0" 
RET_CRLF);
   wait_write();
 
   if (mylimits.delete_spam)
-    snprintf(WriteBuf,sizeof(WriteBuf), "delete_spam 1" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "delete_spam 1" RET_CRLF);
   else
-    snprintf(WriteBuf,sizeof(WriteBuf), "delete_spam 0" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "delete_spam 0" RET_CRLF);
   wait_write();
 
   if (mylimits.disable_maildrop) 
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_maildrop 1" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_maildrop 1" RET_CRLF);
   else 
-    snprintf(WriteBuf,sizeof(WriteBuf), "disable_maildrop 0" RET_CRLF);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", "disable_maildrop 0" RET_CRLF);
   wait_write();
 
   snprintf(WriteBuf,sizeof(WriteBuf), "perm_account %d" RET_CRLF, 
@@ -2405,7 +2404,7 @@
     mylimits.perm_defaultquota); wait_write();
   wait_write();
 
-  snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   return(0);
 }
 
@@ -2434,7 +2433,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
   wait_write();
 
   while(fgets(ReadBuf,sizeof(ReadBuf),stdin)!=NULL ) {
@@ -2442,7 +2441,7 @@
 
     if ( (param = strtok(ReadBuf,PARAM_TOKENS)) == NULL ) continue;
     if ( (value = strtok(NULL,PARAM_TOKENS)) == NULL )  {
-      snprintf(WriteBuf,sizeof(WriteBuf), 
+      snprintf(WriteBuf,sizeof(WriteBuf), "%s",
         "  Warning: missing value" RET_CRLF);
       wait_write();
       continue;
@@ -2505,7 +2504,7 @@
     } else if ( strcmp(param,"perm_defaultquota") == 0 ) {
       mylimits.perm_defaultquota = atoi(value);
     } else {
-      snprintf(WriteBuf,sizeof(WriteBuf), 
+      snprintf(WriteBuf,sizeof(WriteBuf), "%s",
         "  Warning: invalid option" RET_CRLF);
       wait_write();
     }
@@ -2515,7 +2514,7 @@
   if ( vset_limits(domain,&mylimits) < 0 ) {
     show_error( ERR_NO_SET_LIMITS, 3504 );
   } else {
-    snprintf(WriteBuf,sizeof(WriteBuf),RET_OK);
+    snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
   }
   return(0);
 }
@@ -2541,7 +2540,7 @@
     return(-1);
   }
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
   return(0);
 }
 
@@ -2576,10 +2575,10 @@
   } 
 
   if (!(vauth_module_feature("AUTH_LOGGING")))
-         snprintf(WriteBuf,sizeof(WriteBuf), RET_OK);
+         snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
 
   else {
-         snprintf(WriteBuf,sizeof(WriteBuf), RET_OK_MORE);
+         snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK_MORE);
          wait_write();
 
          snprintf(WriteBuf, sizeof(WriteBuf), "time %ld" RET_CRLF,
@@ -2590,7 +2589,7 @@
                 vget_lastauthip(tmpvpw, TmpDomain));
          wait_write();
 
-         snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+         snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   }
 
   return(0);
@@ -2617,35 +2616,36 @@
 int get_user_size()
 {
   char *email_address;
-  int ret, cnt;
-  long bytes;
+  int ret;
+  storage_t cnt;
+  storage_t bytes;
 
   if (!(AuthVpw.pw_gid & QA_ADMIN) && !(AuthVpw.pw_gid & SA_ADMIN)) {
-    snprintf(WriteBuf, sizeof(WriteBuf), RET_ERR "3801 not authorized" 
RET_CRLF);
+    snprintf(WriteBuf, sizeof(WriteBuf), "%s", RET_ERR "3801 not authorized" 
RET_CRLF);
     return(-1);
   }
 
   if ((email_address = strtok(NULL, TOKENS)) == NULL) {
-    snprintf(WriteBuf, sizeof(WriteBuf), 
+    snprintf(WriteBuf, sizeof(WriteBuf), "%s",
       RET_ERR "3802 email_address required" RET_CRLF);
     return(-1);
   }
 
   if (parse_email(email_address, TmpUser, TmpDomain, AUTH_SIZE) != 0) {
-    snprintf(WriteBuf, sizeof(WriteBuf), 
+    snprintf(WriteBuf, sizeof(WriteBuf), "%s",
       RET_ERR "3803 invalid email address" RET_CRLF);
     return(-1);
   }
 
   if (!(AuthVpw.pw_gid & SA_ADMIN) && (AuthVpw.pw_gid & QA_ADMIN) 
     && (strcmp(TheDomain, TmpDomain) != 0)) {
-    snprintf(WriteBuf, sizeof(WriteBuf), 
+    snprintf(WriteBuf, sizeof(WriteBuf), "%s",
       RET_ERR "3804 not authorized for domain" RET_CRLF);
     return(-1);
   }
 
   if ((tmpvpw = vauth_getpw(TmpUser, TmpDomain)) == NULL) {
-    snprintf(WriteBuf, sizeof(WriteBuf), 
+    snprintf(WriteBuf, sizeof(WriteBuf), "%s",
       RET_ERR "3805 user does not exist" RET_CRLF);
     return(-1);
   }
@@ -2653,18 +2653,18 @@
   bytes = 0;
   cnt = 0;
   if ((ret = readuserquota(tmpvpw->pw_dir, &bytes, &cnt)) != 0) {
-    snprintf(WriteBuf, sizeof(WriteBuf), 
+    snprintf(WriteBuf, sizeof(WriteBuf), "%s",
       RET_ERR "3806 unable to fetch size of user account" RET_CRLF);
     return(-1);
   }
 
-  snprintf(WriteBuf, sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf, sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
-  snprintf(WriteBuf, sizeof(WriteBuf), "size %ld" RET_CRLF, bytes);
+  snprintf(WriteBuf, sizeof(WriteBuf), "size %llu" RET_CRLF, bytes);
   wait_write();
-  snprintf(WriteBuf, sizeof(WriteBuf), "count %d" RET_CRLF, cnt);
+  snprintf(WriteBuf, sizeof(WriteBuf), "count %lu" RET_CRLF, cnt);
   wait_write();
-  snprintf(WriteBuf, sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf, sizeof(WriteBuf), "%s", "." RET_CRLF);
 
   return(0);
 }
@@ -2672,31 +2672,32 @@
 int get_domain_size()
 {
   char *domain, tmpdir[256];
-  int ret, cnt, first;
-  long bytes;
-  unsigned int totalcnt;
-  unsigned long long totalbytes;
+  int ret, first;
+  storage_t cnt;
+  storage_t bytes;
+  storage_t totalcnt;
+  storage_t totalbytes;
 
   if (!(AuthVpw.pw_gid & QA_ADMIN) && !(AuthVpw.pw_gid & SA_ADMIN)) {
-    snprintf(WriteBuf, sizeof(WriteBuf), 
+    snprintf(WriteBuf, sizeof(WriteBuf), "%s",
       RET_ERR "3901 not authorized" RET_CRLF);
     return(-1);
   }
 
   if ((domain = strtok(NULL, TOKENS)) == NULL) {
-    snprintf(WriteBuf, sizeof(WriteBuf), 
+    snprintf(WriteBuf, sizeof(WriteBuf), "%s",
       RET_ERR "3902 domain required" RET_CRLF);
     return(-1);
   }
 
   if (!(AuthVpw.pw_gid & SA_ADMIN) && (AuthVpw.pw_gid & QA_ADMIN) 
     && (strcmp(TheDomain, domain) != 0)) {
-    snprintf(WriteBuf, sizeof(WriteBuf),
+    snprintf(WriteBuf, sizeof(WriteBuf), "%s",
       RET_ERR "3903 not authorized for domain" RET_CRLF);
     return(-1);
   }
 
-  snprintf(WriteBuf, sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf, sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
 
   totalbytes = 0;
@@ -2714,12 +2715,12 @@
     } else {
       snprintf(WriteBuf, sizeof(WriteBuf), "user %s@%s" RET_CRLF, 
tmpvpw->pw_name, domain);
       wait_write();
-      snprintf(WriteBuf, sizeof(WriteBuf), "size %ld" RET_CRLF, bytes);
+      snprintf(WriteBuf, sizeof(WriteBuf), "size %llu" RET_CRLF, bytes);
       wait_write();
-      snprintf(WriteBuf, sizeof(WriteBuf), "count %d" RET_CRLF, cnt);
+      snprintf(WriteBuf, sizeof(WriteBuf), "count %llu" RET_CRLF, cnt);
       wait_write();
-      totalbytes += (unsigned long)bytes;
-      totalcnt += (unsigned int)cnt;
+      totalbytes += bytes;
+      totalcnt += cnt;
     }
   }
 
@@ -2727,16 +2728,16 @@
   wait_write();
   snprintf(WriteBuf, sizeof(WriteBuf), "size %llu" RET_CRLF, totalbytes);
   wait_write();
-  snprintf(WriteBuf, sizeof(WriteBuf), "count %u" RET_CRLF, totalcnt);
+  snprintf(WriteBuf, sizeof(WriteBuf), "count %llu" RET_CRLF, totalcnt);
   wait_write();
-  snprintf(WriteBuf, sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf, sizeof(WriteBuf), "%s", "." RET_CRLF);
 
   return(0);
 }
 
 int quit()
 {
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK);
   wait_write();
   vclose();
 
@@ -2747,7 +2748,7 @@
 {
  int i;
 
-  snprintf(WriteBuf,sizeof(WriteBuf), RET_OK_MORE);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", RET_OK_MORE);
   wait_write();
 
   for(i=0;LoginFunctions[i].command!=NULL;++i ) {
@@ -2762,7 +2763,7 @@
     }
     wait_write();
   }
-  snprintf(WriteBuf,sizeof(WriteBuf), "." RET_CRLF);
+  snprintf(WriteBuf,sizeof(WriteBuf), "%s", "." RET_CRLF);
   
   return(1); 
 }
diff -uPr vpopmail-5.5.0.orig/vpopmail.h vpopmail-5.5.0/vpopmail.h
--- vpopmail-5.5.0.orig/vpopmail.h      2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/vpopmail.h   2015-09-18 12:36:07.574093700 +0100
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 #include <sys/types.h>         // for uid_t
+#include "storage.h"
 #include "vauth.h"
 
 /*  Enable expanded debug information.  Consider these for ./configure options 
 */
@@ -35,7 +36,6 @@
 
 /* max buffer sizes */
 #define MAX_BUFF 300
-#define MAX_DOM_ALIAS 100
 
 /* max field sizes */
 #define MAX_PW_NAME          32
@@ -166,6 +166,16 @@
 #define REPLYTO_LIST 2
 #define REPLYTO_ADDRESS 3
 
+/*   List of strings */
+typedef struct string_list {
+    int size;
+    int count;
+    char **values;
+} string_list;
+
+void string_list_init(string_list *a, int first);
+int string_list_add(string_list *a, char *value);
+void string_list_free(string_list *a);
 
 /*   Domain entry  */
 typedef struct domain_entry {
@@ -174,11 +184,8 @@
         int             uid;
         int             gid;
         char    *path;
-        char    *aliases[MAX_DOM_ALIAS];
 } domain_entry;
 
-
-
 /*   Structure for mailing list data  */
 typedef struct listInfoType {
    domain_entry *entry;
@@ -295,11 +302,11 @@
 int add_domain_assign( char *alias_domain, char *real_domain, 
                        char *dir, uid_t uid, gid_t gid);
 //int del_control( char *);
-int del_control( char *aliases[MAX_DOM_ALIAS], int aliascount);
-int del_domain_assign( char *aliasies[MAX_DOM_ALIAS], int aliascount, 
+int del_control( char **aliases, int aliascount);
+int del_domain_assign( char **aliasies, int aliascount, 
                        char *real_domain,
                        char *dir, uid_t uid, gid_t gid);
-int remove_lines( char *filename, char *aliases[MAX_DOM_ALIAS], int 
aliascount);
+int remove_lines( char *filename, char **aliases, int aliascount);
 int signal_process( char *, int );
 int update_newu();
 int add_user_assign( char *, char *);
@@ -336,7 +343,7 @@
 char *format_maildirquota(const char *q);
 char *date_header();
 int qnprintf (char *buffer, size_t size, const char *format, ...);
-int readuserquota(const char* dir, long *sizep, int *cntp);
+int readuserquota(const char* dir, storage_t *sizep, storage_t *cntp);
 #ifndef HAVE_WARN
 #define warn(...) fprintf(stderr, __VA_ARGS__)
 #endif
diff -uPr vpopmail-5.5.0.orig/vusaged/directory.c 
vpopmail-5.5.0/vusaged/directory.c
--- vpopmail-5.5.0.orig/vusaged/directory.c     2010-11-05 18:37:24.000000000 
+0000
+++ vpopmail-5.5.0/vusaged/directory.c  2015-09-18 12:36:07.574093700 +0100
@@ -32,7 +32,7 @@
    #include <assert.h>
 #endif
 #include <conf.h>
-#include <storage.h>
+#include "../storage.h"
 #include "path.h"
 #include "directory.h"
 
diff -uPr vpopmail-5.5.0.orig/vusaged/directory.h 
vpopmail-5.5.0/vusaged/directory.h
--- vpopmail-5.5.0.orig/vusaged/directory.h     2010-11-05 18:37:24.000000000 
+0000
+++ vpopmail-5.5.0/vusaged/directory.h  2015-09-18 12:36:07.574093700 +0100
@@ -24,7 +24,7 @@
 #include <time.h>
 #include <sys/stat.h>
 #include "conf.h"
-#include "storage.h"
+#include "../storage.h"
 
 /*
    A single directory structure
diff -uPr vpopmail-5.5.0.orig/vusaged/domain.c vpopmail-5.5.0/vusaged/domain.c
--- vpopmail-5.5.0.orig/vusaged/domain.c        2010-11-05 18:37:24.000000000 
+0000
+++ vpopmail-5.5.0/vusaged/domain.c     2015-09-18 12:36:07.575093742 +0100
@@ -25,7 +25,7 @@
    #include <assert.h>
 #endif
 #include <pthread.h>
-#include <storage.h>
+#include "../storage.h"
 #include "cache.h"
 #include "domain.h"
 
diff -uPr vpopmail-5.5.0.orig/vusaged/domain.h vpopmail-5.5.0/vusaged/domain.h
--- vpopmail-5.5.0.orig/vusaged/domain.h        2010-11-05 18:37:24.000000000 
+0000
+++ vpopmail-5.5.0/vusaged/domain.h     2015-09-18 12:36:07.575093742 +0100
@@ -22,7 +22,7 @@
    #define __DOMAIN_H_
 
 #include <pthread.h>
-#include "storage.h"
+#include "../storage.h"
 
 /*
    Maximum length of a domain name
diff -uPr vpopmail-5.5.0.orig/vusaged/quota.h vpopmail-5.5.0/vusaged/quota.h
--- vpopmail-5.5.0.orig/vusaged/quota.h 2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/vusaged/quota.h      2015-09-18 12:36:07.576093784 +0100
@@ -21,7 +21,7 @@
 #ifndef __QUOTA_H_
    #define __QUOTA_H_
 
-#include "storage.h"
+#include "../storage.h"
 
 /*
    Quota size in bytes
diff -uPr vpopmail-5.5.0.orig/vusaged/user.c vpopmail-5.5.0/vusaged/user.c
--- vpopmail-5.5.0.orig/vusaged/user.c  2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/vusaged/user.c       2015-09-18 12:36:07.576093784 +0100
@@ -32,7 +32,7 @@
 #include <vauth.h>
 #include <vauthmodule.h>
 #include <conf.h>
-#include <storage.h>
+#include "../storage.h"
 #include "path.h"
 #include "cache.h"
 #include "userstore.h"
diff -uPr vpopmail-5.5.0.orig/vusaged/user.h vpopmail-5.5.0/vusaged/user.h
--- vpopmail-5.5.0.orig/vusaged/user.h  2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/vusaged/user.h       2015-09-18 12:36:07.577093823 +0100
@@ -24,7 +24,7 @@
 #include <time.h>
 #include <pthread.h>
 #include "../conf.h"
-#include "storage.h"
+#include "../storage.h"
 #include "domain.h"
 #include "userstore.h"
 #include "../vauth.h"
diff -uPr vpopmail-5.5.0.orig/vusaged/userstore.c 
vpopmail-5.5.0/vusaged/userstore.c
--- vpopmail-5.5.0.orig/vusaged/userstore.c     2010-11-05 18:37:24.000000000 
+0000
+++ vpopmail-5.5.0/vusaged/userstore.c  2015-09-18 12:36:07.577093823 +0100
@@ -29,7 +29,7 @@
 #ifdef ASSERT_DEBUG
    #include <assert.h>
 #endif
-#include <storage.h>
+#include "../storage.h"
 #include <conf.h>
 #include "path.h"
 #include "directory.h"
diff -uPr vpopmail-5.5.0.orig/vusaged/userstore.h 
vpopmail-5.5.0/vusaged/userstore.h
--- vpopmail-5.5.0.orig/vusaged/userstore.h     2010-11-05 18:37:24.000000000 
+0000
+++ vpopmail-5.5.0/vusaged/userstore.h  2015-09-18 12:36:07.578093862 +0100
@@ -21,7 +21,7 @@
 #ifndef __USERSTORE_H_
    #define __USERSTORE_H_
 
-#include "storage.h"
+#include "../storage.h"
 #include "directory.h"
 #include "conf.h"
 #include <pthread.h>
diff -uPr vpopmail-5.5.0.orig/vusaged/vdb.c vpopmail-5.5.0/vusaged/vdb.c
--- vpopmail-5.5.0.orig/vusaged/vdb.c   2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/vusaged/vdb.c        2015-09-18 12:36:07.578093862 +0100
@@ -13,7 +13,7 @@
 #ifdef ASSERT_DEBUG
    #include <assert.h>
 #endif
-#include <storage.h>
+#include "../storage.h"
 #include <conf.h>
 #include <vpopmail.h>
 #include "path.h"
diff -uPr vpopmail-5.5.0.orig/vusaged/vdb.h vpopmail-5.5.0/vusaged/vdb.h
--- vpopmail-5.5.0.orig/vusaged/vdb.h   2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/vusaged/vdb.h        2015-09-18 12:36:07.579093900 +0100
@@ -5,7 +5,7 @@
 #ifndef __VDB_H_
    #define __VDB_H_
 
-#include <storage.h>
+#include "../storage.h"
 #include <conf.h>
 
 /*

Reply via email to