diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/Makefile.am vpopmail-vadmin-5.3.19/Makefile.am
--- vpopmail-5.3.19/Makefile.am	Wed Mar  5 18:09:47 2003
+++ vpopmail-vadmin-5.3.19/Makefile.am	Thu Apr  3 11:05:51 2003
@@ -14,7 +14,7 @@
 vpopmailbin_PROGRAMS = vchkpw vdelivermail clearopensmtp vadddomain \
  vdeldomain vpasswd vadduser vdeluser vaddaliasdomain vsetuserquota \
  vpopbull vdeloldusers vmoduser valias vuserinfo vmkpasswd vipmap \
- vdominfo vconvert vqmaillocal vkill
+ vdominfo vconvert vqmaillocal vkill vadmind vmoddomlimits
 	
 
 vuserinfo_SOURCES = vuserinfo.c maildirquota.c
@@ -80,6 +80,12 @@
 vipmap_SOURCES = vipmap.c 
 vipmap_LDADD = libvpopmail.a  @auth_libs@
 
+vadmind_SOURCES = vadmind.c
+vadmind_LDADD = libvpopmail.a @auth_libs@
+
+vmoddomlimits_SOURCES = vmoddomlimits.c
+vmoddomlimits_LDADD = libvpopmail.a @auth_libs@
+
 DEFS=-I. @auth_inc@ 
 
 install-data-local:
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/acconfig.h vpopmail-vadmin-5.3.19/acconfig.h
--- vpopmail-5.3.19/acconfig.h	Wed Mar  5 19:07:52 2003
+++ vpopmail-vadmin-5.3.19/acconfig.h	Thu Apr  3 11:04:05 2003
@@ -58,6 +58,18 @@
 
 #undef OPEN_SMTP_LOK_FILE
 
+#undef VADMIN_PASSWD_CDB_FILE
+
+#undef VADMIN_PASSWD_FILE
+
+#undef VADMIN_PASSWD_BAK_FILE
+
+#undef VADMIN_PASSWD_CDB_TMP_FILE
+
+#undef VADMIN_PASSWD_LOCK_FILE
+
+#undef VLIMITS_DEFAULT_FILE
+
 #undef TCPRULES_PROG
 
 #undef RELAY_CLEAR_MINUTES
Common subdirectories: vpopmail-5.3.19/attic and vpopmail-vadmin-5.3.19/attic
Common subdirectories: vpopmail-5.3.19/cdb and vpopmail-vadmin-5.3.19/cdb
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/config.h.in vpopmail-vadmin-5.3.19/config.h.in
--- vpopmail-5.3.19/config.h.in	Wed Mar  5 18:21:18 2003
+++ vpopmail-vadmin-5.3.19/config.h.in	Thu Apr  3 11:42:20 2003
@@ -10,9 +10,6 @@
 /* Define to empty if the keyword does not work.  */
 #undef const
 
-/* Define if you need to in order for stat and other things to work.  */
-#undef _POSIX_SOURCE
-
 /* Define to `unsigned' if <sys/types.h> doesn't define.  */
 #undef size_t
 
@@ -78,6 +75,18 @@
 
 #undef OPEN_SMTP_LOK_FILE
 
+#undef VADMIN_PASSWD_CDB_FILE
+
+#undef VADMIN_PASSWD_FILE
+
+#undef VADMIN_PASSWD_BAK_FILE
+
+#undef VADMIN_PASSWD_CDB_TMP_FILE
+
+#undef VADMIN_PASSWD_LOCK_FILE
+
+#undef VLIMITS_DEFAULT_FILE
+
 #undef TCPRULES_PROG
 
 #undef RELAY_CLEAR_MINUTES
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/configure.in vpopmail-vadmin-5.3.19/configure.in
--- vpopmail-5.3.19/configure.in	Wed Mar  5 19:39:22 2003
+++ vpopmail-vadmin-5.3.19/configure.in	Thu Apr  3 11:08:19 2003
@@ -237,6 +237,22 @@
 rm -f vpopmail.gid
 rm -f vpopusername 
 
+vadmin_passwd_cdb="vadmin_passwd.cdb"
+vadmin_passwd_cdb_tmp="vadmin_passwd.tmp"
+vadmin_passwd="vadmin_passwd"
+vadmin_passwd_bak="vadmin_passwd.bak"
+vadmin_passwd_lock="vadmin_passwd.lock"
+
+AC_DEFINE_UNQUOTED(VADMIN_PASSWD_CDB_FILE,"$vadmin_passwd_cdb")
+AC_DEFINE_UNQUOTED(VADMIN_PASSWD_CDB_TMP_FILE,"$vadmin_passwd_cdb_tmp")
+AC_DEFINE_UNQUOTED(VADMIN_PASSWD_FILE,"$vadmin_passwd")
+AC_DEFINE_UNQUOTED(VADMIN_PASSWD_BAK_FILE,"$vadmin_passwd_bak")
+AC_DEFINE_UNQUOTED(VADMIN_PASSWD_LOCK_FILE,"$vadmin_passwd_lock")
+
+vlimits_default="$vpopmaildir/etc/vlimits.default"
+
+AC_DEFINE_UNQUOTED(VLIMITS_DEFAULT_FILE,"$vlimits_default")
+
 
 if test ! -d $vpopmaildir/etc
 then 
Common subdirectories: vpopmail-5.3.19/contrib and vpopmail-vadmin-5.3.19/contrib
Common subdirectories: vpopmail-5.3.19/convert and vpopmail-vadmin-5.3.19/convert
Common subdirectories: vpopmail-5.3.19/doc and vpopmail-vadmin-5.3.19/doc
Common subdirectories: vpopmail-5.3.19/ldap and vpopmail-vadmin-5.3.19/ldap
Common subdirectories: vpopmail-5.3.19/oracle and vpopmail-vadmin-5.3.19/oracle
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/vadmin-test.php vpopmail-vadmin-5.3.19/vadmin-test.php
--- vpopmail-5.3.19/vadmin-test.php	Thu Jan  1 01:00:00 1970
+++ vpopmail-vadmin-5.3.19/vadmin-test.php	Wed Apr  2 18:06:40 2003
@@ -0,0 +1,51 @@
+#!/usr/bin/php -q
+<?php
+//Version
+$iVersion = 1;
+
+$aAuth = array ();
+$aAuth["Type"]="master_plain";
+$aAuth["Login"]="blub";
+$aAuth["Password"]="asdf";
+
+/*$aAuth["Type"]="email_plain";
+$aAuth["Login"]="bernd@test2.com";
+$aAuth["Password"]="lala";*/
+
+
+$aCommand = array ();
+$aCommand["Command"]="vaddalias";
+$aCommand["AliasDomain"]="test5.com";
+$aCommand["Domain"]="test4.com";
+$aCommand["User"]="blub";
+$aCommand["AliasLine"]="&postmaster@ionium.org";
+$aCommand["RandomPw"] = 1;
+
+function get_dword_length($sString) {
+    $iLength = strlen($sString);
+    if ($iLength > 65535) {
+        return false;
+    }
+    $cLastByte = $iLength % 256;
+    $cFirstByte = $iLength>>8;
+    return chr($cFirstByte).chr($cLastByte);
+}
+
+function build_struct($aArray) {
+    $sReturn = chr(count($aArray));
+    foreach ($aArray as $sKey=>$sValue) {
+        if (($iLength = get_dword_length($sKey."=".$sValue)) === false) {
+            return false;
+        }
+        $sReturn.=$iLength.$sKey."=".$sValue;
+    }
+    if (($iLength = get_dword_length($sReturn)) === false) {
+        return false;
+    }
+    return $iLength.$sReturn;
+}
+
+echo chr($iVersion);    
+echo build_struct($aAuth);
+echo build_struct($aCommand);
+?>
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/vadmind.c vpopmail-vadmin-5.3.19/vadmind.c
--- vpopmail-5.3.19/vadmind.c	Thu Jan  1 01:00:00 1970
+++ vpopmail-vadmin-5.3.19/vadmind.c	Thu Apr  3 11:46:15 2003
@@ -0,0 +1,1022 @@
+/* */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <cdbmake.h>
+#include "config.h"
+#include "vpopmail.h"
+#include "vauth.h"
+#include "vlimits.h"
+
+#define MAX_BUFF 500
+
+#define AUTH_SIZE 156
+
+#define PROTOCOL_VERSION 1
+#define VADMIN_LVL_AUTH               0x01
+#define VADMIN_LVL_ADDDOMAIN          0x02
+#define VADMIN_LVL_DELDOMAIN          0x04
+#define VADMIN_LVL_ADDALIAS           0x08
+#define VADMIN_LVL_DELALIAS          0x010
+#define VADMIN_LVL_SELECTALIAS       0x020
+#define VADMIN_LVL_ADDUSER           0x040
+#define VADMIN_LVL_DELUSER           0x080
+#define VADMIN_LVL_CHNGPASSWD       0x0100
+
+#define VADMIN_LVL_ALL              (VADMIN_LVL_AUTH|VADMIN_LVL_ADDDOMAIN|VADMIN_LVL_DELDOMAIN|VADMIN_LVL_ADDALIAS|VADMIN_LVL_DELALIAS|VADMIN_LVL_SELECTALIAS|VADMIN_LVL_ADDUSER|VADMIN_LVL_DELUSER|VADMIN_LVL_CHNGPASSWD)
+
+#define VADMIN_ADDMASTERUSER 1
+#define VADMIN_DELMASTERUSER 2
+#define VADMIN_REBUILDCDB 3
+
+
+
+static char vadmin_passwd_file[MAX_BUFF];
+static char vadmin_passwd_bak_file[MAX_BUFF];
+static char vadmin_passwd_cdb_file[MAX_BUFF];
+static char vadmin_passwd_cdb_tmp_file[MAX_BUFF];
+static char vadmin_passwd_lock_file[MAX_BUFF];
+static char vadmin_passwd_dir[MAX_BUFF];
+
+char Domain[MAX_BUFF];
+char Passwd[MAX_BUFF];
+char User[MAX_BUFF];
+char Dir[MAX_BUFF];
+char Quota[MAX_BUFF];
+char BounceEmail[MAX_BUFF];
+char TmpBuf1[MAX_BUFF];
+char a_dir[MAX_BUFF];
+int  Apop;
+int  Bounce;
+int  RandomPw;
+uid_t Uid;
+gid_t Gid;
+uid_t a_uid;
+gid_t a_gid;
+
+int AdminAction;
+
+
+char IUser[MAX_BUFF];
+char IPasswd[MAX_BUFF];
+
+struct vlimits limits;
+
+struct auth_request {
+    char Type[MAX_BUFF];
+    char Login[MAX_BUFF];
+    char Password[MAX_BUFF];
+};
+
+struct command {
+    char Command[MAX_BUFF];
+    char Domain[MAX_BUFF];
+    char User[MAX_BUFF];
+    char Gecos[MAX_BUFF];
+    char Dir[MAX_BUFF];
+    char Quota[MAX_BUFF];
+    char Passwd[MAX_BUFF];
+    char AliasDomain[MAX_BUFF];
+    char AliasLine[MAX_BUFF];
+    char BounceEmail[MAX_BUFF];
+    uid_t Uid;
+    gid_t Gid;
+    int RandomPw;
+    int Apop;
+    
+    char a_dir[MAX_BUFF];
+    uid_t a_uid;
+    gid_t a_gid;
+};
+
+struct vadminpasswd {
+    char * pw_name;
+    char * pw_passwd;
+};
+
+/*
+PROTOCOL Version 01;
+
+struct {
+CHAR VersionNumber;
+DWORD LENGTH;
+CHAR ArgumentsNumber
+    struct auth_request;
+DWORD Length;
+CHAR ArgumentsNumber;
+    struct command;
+
+*/
+
+extern int cdb_seek();
+void usage();
+void get_options(int argc,char **argv);
+int vadmin_adduser(char * User, char * Passwd);
+void vadmin_set_passwd_files ();
+int vadmin_make_cdb();
+
+
+struct vadminpasswd *vadmin_getpw (char * user) {
+    FILE *pwf;
+    static struct vadminpasswd pwent;
+    static char line[2048];
+    char *ptr;
+    uint32 dlen;
+    
+    vadmin_set_passwd_files();
+    
+    if ((pwf = fopen(vadmin_passwd_cdb_file,"r")) == NULL) {
+        vadmin_make_cdb();
+        if ((pwf = fopen(vadmin_passwd_cdb_file,"r")) == NULL) {
+            return(NULL);
+        }
+    }
+    memset(line,0,MAX_BUFF);
+    strncpy(line,user,sizeof(line)); 
+    strncat(line,":",sizeof(line));
+    ptr = line;
+    while (*ptr != ':') { ptr++; }
+    ptr++;
+    switch (cdb_seek(fileno(pwf),user,strlen(user),&dlen)) {
+        case -1:
+            fclose(pwf);
+            return NULL;
+        case 0:
+            fclose(pwf);
+            return NULL;
+    }
+    if (fread(ptr,sizeof(char),dlen,pwf) != dlen) {
+        return NULL;
+    }
+    fclose(pwf);
+    line[(dlen+strlen(user)+1)] = 0;
+    
+    pwent.pw_name   = IUser;
+    pwent.pw_passwd = IPasswd;
+
+    ptr = line;
+    pwent.pw_name    = line;
+    while (*ptr!=0&&*ptr != ':') { ptr++; }
+    if ( *ptr!=0 ){ *ptr = 0; ptr++; pwent.pw_passwd = ptr; }
+
+//     fprintf (stderr,"vgetpw: db: results: pw_name   = %s\n",pwent.pw_name);
+//     fprintf (stderr,"                     pw_passwd = %s\n",pwent.pw_passwd);
+
+    return (&pwent);   
+}
+
+int init_auth_request (struct auth_request *MyAuth) {
+    memset(MyAuth->Type,0,MAX_BUFF);
+    memset(MyAuth->Login,0,MAX_BUFF);
+    memset(MyAuth->Password,0,MAX_BUFF);
+    return 0;
+}
+
+int init_command (struct command *MyCommand) {
+    memset(MyCommand->Command,0,MAX_BUFF);
+    memset(MyCommand->Domain,0,MAX_BUFF);
+    memset(MyCommand->User,0,MAX_BUFF);
+    memset(MyCommand->Gecos,0,MAX_BUFF);
+    memset(MyCommand->Dir,0,MAX_BUFF);
+    memset(MyCommand->Quota,0,MAX_BUFF);
+    memset(MyCommand->Passwd,0,MAX_BUFF);
+    memset(MyCommand->AliasDomain,0,MAX_BUFF);
+    memset(MyCommand->AliasLine,0,MAX_BUFF);
+    memset(MyCommand->BounceEmail,0,MAX_BUFF);
+    MyCommand->Uid = VPOPMAILUID;
+    MyCommand->Gid = VPOPMAILGID;
+    MyCommand->RandomPw = 0;
+    MyCommand->Apop = USE_POP;
+    return 0;
+}
+
+int decode_auth (struct auth_request *MyAuth, char *Query, ssize_t length)
+{
+    
+    // the first Byte of the Query contains the number of arguments, the query consists of.
+    char argcount = *Query++;
+    length-=1;
+    
+    char *buf;
+    int tmplen=0;
+    int i;
+    char *varname,*value;
+    //get login
+    for (i=0;i<argcount; i++) {
+        tmplen=(Query[0]<<8 | Query[1]);
+        Query +=2;
+        length -=2;
+        if (tmplen>length) {
+            printf("Error: Auth failed. (Bad auth struct)\n");
+            return -1;
+        }
+        buf = calloc (1,tmplen);
+        strncpy(buf, Query, tmplen);
+        Query += tmplen;
+        length -= tmplen;
+        varname=strtok(buf,"=");
+        value=strtok(NULL,"=");
+        
+        if (!strncmp(varname, "Type", strlen("Type")) && strlen("Type") == strlen(varname)) {
+            strncpy(MyAuth->Type, value, tmplen-strlen("Type")-1);
+        }
+        if (!strncmp(varname, "Login", strlen("Login")) && strlen("Login") == strlen(varname)) {
+            strncpy(MyAuth->Login, value, tmplen-strlen("Login")-1);
+        }
+        if (!strncmp(varname, "Password", strlen("Password")) && strlen("Password") == strlen(varname)) {
+            strncpy(MyAuth->Password, value, tmplen-strlen("Password")-1);
+        }
+        free(buf);
+    }
+    return 0;
+}
+
+int decode_command (struct command *MyCommand, char *Query, ssize_t length)
+{
+    // the first Byte of the Query contains the number of arguments, the query consists of.
+    // by removing the first byte, the length shortens by 1
+    char *buf;
+    //buf = strchr(Query,0)+2;
+    int tmplen=0;
+    int argcount = *Query++;
+    int i=0;
+    char *varname,*value,*tmpbuf;
+    //struct command MyCommand;
+    for (;i<argcount; i++) {
+        tmplen=(Query[0]<<8) | Query[1];
+        Query +=2;
+        buf = calloc (1,tmplen);
+        strncpy(buf,Query,tmplen);
+        //printf ("%s\n",buf);
+        Query += tmplen;
+        
+        varname=strtok(buf,"=");
+        value=strtok(NULL,"=");
+        //strncpy(value,buf,tmplen- (strlen(varname)+1));
+        
+        if (!strncmp(varname, "Command", strlen("Command"))) {
+            strncpy(MyCommand->Command, value, tmplen-strlen("Command")-1);
+        }
+        if (!strncmp(varname, "Domain", strlen("Domain"))) {
+            strncpy(MyCommand->Domain, value, tmplen-strlen("Domain")-1);
+        }
+        if (!strncmp(varname, "User", strlen("User"))) {
+            strncpy(MyCommand->User, value, tmplen-strlen("User")-1);
+        }
+        if (!strncmp(varname, "AliasDomain", strlen("AliasDomain"))) {
+            strncpy(MyCommand->AliasDomain, value, tmplen-strlen("AliasDomain")-1);
+        }
+        if (!strncmp(varname, "AliasLine", strlen("AliasLine"))) {
+            strncpy(MyCommand->AliasLine, value, tmplen-strlen("AliasLine")-1);
+        }
+        if (!strncmp(varname, "Uid", strlen("Uid"))) {
+            tmpbuf = calloc(1, tmplen-strlen("Uid")-1);
+            strncpy(tmpbuf, value, tmplen-strlen("Uid")-1);
+            MyCommand->Uid = atoi(tmpbuf);
+            free(tmpbuf);
+        }
+        if (!strncmp(varname, "Gid", strlen("Gid"))) {
+            tmpbuf = calloc(1, tmplen-strlen("Gid")-1);
+            strncpy(tmpbuf, value, tmplen-strlen("Gid")-1);
+            MyCommand->Gid = atoi(tmpbuf);
+            free(tmpbuf);
+        }
+        if (!strncmp(varname, "RandomPw", strlen("RandomPw"))) {
+            tmpbuf = calloc(1, tmplen-strlen("RandomPw")-1);
+            strncpy(tmpbuf, value, tmplen-strlen("RandomPw")-1);
+            MyCommand->RandomPw = atoi (tmpbuf);
+            free(tmpbuf);
+        }
+        if (!strncmp(varname, "Apop", strlen("Apop"))) {
+            tmpbuf = calloc(1, tmplen-strlen("Apop")-1);
+            strncpy(tmpbuf, value, tmplen-strlen("Apop")-1);
+            MyCommand->Apop = atoi (tmpbuf);
+            free(tmpbuf);
+        }
+        free(buf);
+    }
+    
+    
+    return 0;
+}
+
+int read_data (struct auth_request *MyAuth, struct command *MyCommand)
+{
+    char Version[1];
+    char Header[2];
+    ssize_t length;
+    char *AuthString;
+    char *CommandString;
+    
+    switch (read (STDIN_FILENO, Version, 1)) {
+    case -1 : printf ("Read error"); exit(-1);
+    case 1  : break;
+    default : printf ("Empty Commandstring"); exit(-1);
+    }
+    if (Version[0] != PROTOCOL_VERSION) {
+        printf("Wrong Protocol Version: %d", Version[0]);
+        exit(-1);
+    }
+    if (read (STDIN_FILENO, Header, 2) != 2) {
+        printf("Short read while reading auth header");
+        exit(-1);
+    }
+    length = Header[0]<<8 | Header[1];
+
+    AuthString = calloc (1,length);
+    if (read (STDIN_FILENO, AuthString, length) != length) {
+        printf("Short read while reading auth string");
+        exit(-1);
+    }
+    if (decode_auth (MyAuth, AuthString, length) != 0) {
+        printf("Authentification garbled\n");
+        exit(-1);
+    }
+
+    if (read (STDIN_FILENO, Header, 2) != 2) {
+        printf("Short read while reading command header");
+        exit(-1);
+    }
+    length = Header[0]<<8 | Header[1];
+    CommandString = calloc (1,length);
+    if (read (STDIN_FILENO, CommandString, length) != length) {
+        printf("Short read while reading command string");
+        exit(-1);
+    }
+    decode_command (MyCommand, CommandString, length);
+    return 0;
+}
+
+int cmd_vadddomain (struct command *MyCommand)
+{
+ int err;
+ FILE *fs;
+
+ int a_uid,a_gid;
+ 
+    if (MyCommand->RandomPw) {
+        strncpy( MyCommand->Passwd, vgen_pass(8),8);
+    }
+    if ( strlen(MyCommand->Passwd) <= 0 ) {
+        printf("Error: no password supplied\n");
+        return(-1);
+    }
+    if ( MyCommand->Dir[0] == 0 ) strncpy(MyCommand->Dir, VPOPMAILDIR, MAX_BUFF);
+    if ( (err=vadddomain(MyCommand->Domain,MyCommand->Dir,MyCommand->Uid,MyCommand->Gid)) != VA_SUCCESS ) {
+        printf("Error: %s\n", verror(err));
+        return(err);
+    }
+
+    if ((err=vadduser("postmaster", MyCommand->Domain, MyCommand->Passwd, "Postmaster", MyCommand->Apop )) != 
+        VA_SUCCESS ) {
+        printf("Error: %s\n", verror(err));
+        return(err);
+    }
+
+    if ( MyCommand->Quota[0] != 0 ) {
+        vsetuserquota( "postmaster", MyCommand->Domain, MyCommand->Quota ); 
+    }
+    if ( MyCommand->BounceEmail[0] != 0 ) {
+        if ( strstr(MyCommand->BounceEmail, "@") != NULL ) { 
+            vget_assign(MyCommand->Domain, a_dir, 156, &a_uid, &a_gid );
+            snprintf(TmpBuf1, MAX_BUFF, "%s/.qmail-default", a_dir);
+            if ( (fs = fopen(TmpBuf1, "w+"))!=NULL) {
+                fprintf(fs, "| %s/bin/vdelivermail '' %s\n", VPOPMAILDIR, 
+                    MyCommand->BounceEmail);
+                fclose(fs);
+                chown(TmpBuf1, a_uid, a_gid);
+            } else {
+                printf("Error: could not open %s\n", TmpBuf1);
+            }
+        } else {
+            printf("Invalid bounce email address %s\n", MyCommand->BounceEmail);
+        }
+    }
+    if ( RandomPw == 1 ) printf("Random password: %s\n", Passwd );
+    
+    return(0);
+ }
+
+int cmd_vdeldomain (struct command *MyCommand)
+{
+    int err;
+    if ( (err=vdeldomain(MyCommand->Domain)) != VA_SUCCESS) {
+        printf("Error: %s\n", verror(err));
+        return(err);
+    }
+    return(0);
+}
+
+int cmd_vaddaliasdomain (struct command *MyCommand)
+{
+    int err;
+    if ( (err = vaddaliasdomain( MyCommand->AliasDomain, MyCommand->Domain)) != VA_SUCCESS) {
+        printf("Error: %s\n", verror(err));
+        return(err);
+    }
+    return(0);
+}
+ 
+int cmd_vadduser (struct command *MyCommand)
+{
+    int err;
+    if ( MyCommand->Domain[0] == 0 ) {
+        printf("Error: Domain is missing.\n");
+        return(-1);
+    }
+
+    vget_real_domain(MyCommand->Domain, strlen(MyCommand->Domain));
+    
+    if (MyCommand->RandomPw) {
+        strncpy( MyCommand->Passwd, vgen_pass(8),8);
+    }
+
+    /* if the comment field is blank use the user name */
+    if ( MyCommand->Gecos[0] == 0 ) strncpy(MyCommand->Gecos, MyCommand->User, MAX_BUFF);
+
+    /* add the user */
+    if ( (err=vadduser(MyCommand->User, MyCommand->Domain, MyCommand->Passwd, MyCommand->Gecos, MyCommand->Apop )) < 0 ) {
+        printf("Error: %s\n", verror(err));
+        return(err);
+    }
+
+    /* set the users quota if set on the command line */
+    if ( MyCommand->Quota[0] != 0 ) vsetuserquota( MyCommand->User, MyCommand->Domain, MyCommand->Quota ); 
+
+    if ( RandomPw == 1 ) printf("Random password: %s\n", Passwd );
+    return(0);
+}
+
+int cmd_vdeluser (struct command *MyCommand)
+{
+    int err;
+    vget_real_domain(MyCommand->Domain, strlen(MyCommand->Domain));
+    if ( (err = vdeluser(User, Domain)) != VA_SUCCESS ) {
+        printf("Error: %s\n", verror(err));
+        return(err);
+    }
+    return(0);
+}
+
+int cmd_vaddalias (struct command *MyCommand)
+{
+    int err;
+    vget_real_domain(MyCommand->Domain, strlen(MyCommand->Domain));
+    if ( (err=valias_insert(MyCommand->User, MyCommand->Domain, MyCommand->AliasLine)) < 0 ) {
+        printf("Error: %s\n", verror(err));
+        return(err);
+    }
+    return(0);
+}
+
+int cmd_vdelalias (struct command *MyCommand)
+{
+    int err;
+    vget_real_domain(MyCommand->Domain, strlen(MyCommand->Domain));
+    if ( (err=valias_delete(MyCommand->User, MyCommand->Domain)) < 0 ) {
+        printf("Error: %s\n", verror(err));
+        return(err);
+    }
+    return(0);
+}
+
+int cmd_vselectalias (struct command *MyCommand)
+{
+    char Email[MAX_BUFF];
+    char Alias[MAX_BUFF];
+    char *tmpalias;
+    
+    memset(Email,0,MAX_BUFF);
+  
+    vget_real_domain(MyCommand->Domain, strlen(MyCommand->Domain));
+    
+    if ( MyCommand->User[0] != 0) {
+        strncpy(Email,MyCommand->User,strlen(MyCommand->User));
+        strncat(Email,"@",MAX_BUFF-strlen(Email)-1);
+        strncat(Email,MyCommand->Domain,MAX_BUFF-strlen(Email)-1);
+        
+        tmpalias = valias_select_all( Alias, Email );
+        while (tmpalias != NULL ) {
+            printf("%s@%s -> %s\n", Alias, Email, tmpalias);
+            tmpalias = valias_select_all_next(Alias);
+        }
+    } else {
+        tmpalias = valias_select( Alias, Domain );
+        while (tmpalias != NULL ) {
+            printf("%s@%s -> %s\n", Alias, Domain,tmpalias);
+            tmpalias = valias_select_next();
+        }
+    }
+    return(0);
+}
+
+int cmd_vpasswd (struct command *MyCommand)
+{
+    int err;
+    vget_real_domain(MyCommand->Domain, strlen(MyCommand->Domain));
+    if ( (err=vpasswd( MyCommand->User, MyCommand->Domain, MyCommand->Passwd, MyCommand->Apop )) != 0 ) {
+		printf("Error: %s\n", verror(err));
+		return(err);
+	}
+    return(0);
+}
+
+
+int main (argc,argv)
+int argc;
+char *argv[];
+{
+
+    struct vqpasswd *vpw = NULL;
+    struct command MyCommand;
+    struct auth_request MyAuth;
+    struct vlimits limits;
+    struct vadminpasswd *spw = NULL;
+    
+    //char pw_passwd[AUTH_SIZE];
+    char AuthUser[AUTH_SIZE];
+    char AuthDomain[AUTH_SIZE];
+    int AuthMask = 0;
+    
+    if (argc>1) {
+        AdminAction = 0;
+        get_options(argc,argv);
+        switch (AdminAction) {
+        case VADMIN_ADDMASTERUSER:
+            strncpy(Passwd,vgetpasswd(User),MAX_BUFF);
+            vadmin_adduser(User,Passwd);
+            break;
+        case VADMIN_REBUILDCDB:
+            vadmin_set_passwd_files();
+            vadmin_make_cdb();
+            break;
+        default: break;
+        }
+        exit(0);
+    }
+
+
+    init_auth_request(&MyAuth);
+    init_command (&MyCommand);
+    read_data(&MyAuth,&MyCommand);
+    
+    
+    memset(AuthUser,0,AUTH_SIZE);
+    memset(AuthDomain,0,AUTH_SIZE);
+
+    /* Authentification */
+    if (strncmp(MyAuth.Type, "email_", strlen("email_")) == 0) {
+        parse_email(MyAuth.Login, AuthUser, AuthDomain, AUTH_SIZE);
+        if ((vpw = vauth_getpw(AuthUser, AuthDomain)) == NULL) {
+            printf ("auth: failed (user not found)\n");
+            exit(-1);
+        }
+
+        if (strncmp(MyAuth.Type, "email_plain", strlen("email_plain")) == 0) {
+            if (strcmp(crypt(MyAuth.Password,vpw->pw_passwd),vpw->pw_passwd) != 0 ) {
+                printf ("auth: failed\n");
+                exit(-1);
+            }
+        } else if (strncmp(MyAuth.Type, "email_crypt", strlen("email_crypt")) == 0) {
+            if (strncmp(MyAuth.Password,vpw->pw_passwd, strlen(MyAuth.Password)) != 0) {
+                printf ("auth: failed\n");
+                exit(-1);
+            }
+        }
+        else {
+            printf ("auth: failed\n");
+            exit(-1);
+        }
+        // now add Permissions
+        AuthMask |= VADMIN_LVL_AUTH;  // everybody may use the AUTH command, which simply returns "auth: ok"
+        if (strncmp(AuthUser, "postmaster", strlen("postmaster")) && strlen(AuthUser)==strlen("postmaster")) {
+            //we have the postmaster here, allow everything for this domain
+            AuthMask |= VADMIN_LVL_ADDUSER | VADMIN_LVL_DELUSER;
+            AuthMask |= VADMIN_LVL_ADDALIAS | VADMIN_LVL_DELALIAS | VADMIN_LVL_SELECTALIAS;
+        }
+        else {
+            vget_limits(AuthDomain,&limits);
+
+            if(! limits.perm_account & VLIMIT_DISABLE_CREATE) {
+                AuthMask |= VADMIN_LVL_ADDUSER;
+            }
+            if(! limits.perm_account & VLIMIT_DISABLE_DELETE) {
+                AuthMask |= VADMIN_LVL_DELUSER;
+            }
+            if(! 
+                (limits.perm_alias & VLIMIT_DISABLE_CREATE &&
+                 limits.perm_forward & VLIMIT_DISABLE_CREATE &&
+                 limits.perm_autoresponder & VLIMIT_DISABLE_CREATE &&
+                 limits.perm_maillist & VLIMIT_DISABLE_CREATE
+                 )
+              ) {
+                AuthMask |= VADMIN_LVL_ADDALIAS;
+            }
+            if(! (limits.perm_alias & VLIMIT_DISABLE_DELETE &&
+                 limits.perm_forward & VLIMIT_DISABLE_DELETE &&
+                 limits.perm_autoresponder & VLIMIT_DISABLE_DELETE &&
+                 limits.perm_maillist & VLIMIT_DISABLE_DELETE
+                 )
+              ) {
+                AuthMask |= VADMIN_LVL_DELALIAS;
+            }
+        }
+    } else if (!strncmp(MyAuth.Type, "master_", strlen("master_"))) {
+        // somehow get the user from a passwd db
+
+        if ((spw = vadmin_getpw(MyAuth.Login)) == NULL) {
+            printf ("auth: failed (user does not exist)\n");
+            exit(-1);
+        }
+        if (!strncmp(MyAuth.Type, "master_plain", strlen("master_plain"))) {
+            if (strcmp(crypt(MyAuth.Password,spw->pw_passwd),spw->pw_passwd) != 0 ) {
+                printf ("auth: failed (wrong password)\n");
+                exit(-1);
+            }
+        } else {
+            printf ("auth: failed (wrong method)\n");
+            exit(-1);
+        }
+        AuthMask |= VADMIN_LVL_ALL;
+    } else {
+        printf ("auth: failed (wrong method)\n");
+        exit(-1);
+    }
+
+
+    if (!strncmp(MyCommand.Command, "vadddomain", strlen("vadddomain"))) {
+        if (AuthMask & VADMIN_LVL_ADDDOMAIN) {
+            if (cmd_vadddomain (&MyCommand) == 0) {
+                printf ("vadddomain: ok\n");
+            }
+            else {
+                printf ("vadddomain: failed\n");
+            }
+        }
+        else {
+            printf ("vadddomain: permission denied\n");
+        }
+    } else if (!strncmp(MyCommand.Command, "vdeldomain", strlen("vdeldomain"))) {
+        if (AuthMask & VADMIN_LVL_DELDOMAIN) {
+            if (cmd_vdeldomain (&MyCommand) == 0) {
+                printf ("vdeldomain: ok\n");
+            }
+            else {
+                printf ("vdeldomain: failed\n");
+            }
+        }
+        else {
+            printf ("vdeldomain: permission denied\n");
+        }
+    } else if (!strncmp(MyCommand.Command, "vaddaliasdomain", strlen("vaddaliasdomain"))) {
+        if (AuthMask & VADMIN_LVL_ADDDOMAIN) {
+            if (cmd_vaddaliasdomain (&MyCommand) == 0) {
+                printf ("vaddaliasdomain: ok\n");
+            }
+            else {
+                printf ("vaddaliasdomain: failed\n");
+            }
+        }
+        else {
+            printf ("vaddaliasdomain: permission denied\n");
+        }
+    } else if (!strncmp(MyCommand.Command, "vadduser", strlen("vadduser"))) {
+        if (AuthMask & VADMIN_LVL_ADDUSER && (AuthDomain[0]==0 || strncmp(AuthDomain,MyCommand.Domain, AUTH_SIZE) == 0)) {
+            if (cmd_vadduser (&MyCommand) == 0) {
+                printf ("vadduser: ok\n");
+            }
+            else {
+                printf ("vadduser: failed\n");
+            }
+        }
+        else {
+            printf ("vadduser: permission denied\n");
+        }
+    } else if (!strncmp(MyCommand.Command, "vdeluser", strlen("vdeluser"))) {
+        if (AuthMask & VADMIN_LVL_DELUSER && (AuthDomain[0]==0 || strncmp(AuthDomain,MyCommand.Domain, AUTH_SIZE) == 0)) {
+            if (cmd_vdeluser (&MyCommand) == 0) {
+                printf ("vdeluser: ok\n");
+            }
+            else {
+                printf ("vdeluser: failed\n");
+            }
+        }
+        else {
+            printf ("vdeluser: permission denied\n");
+        }
+    } else if (!strncmp(MyCommand.Command, "vaddalias", strlen("vaddalias"))) {
+        if (AuthMask & VADMIN_LVL_ADDALIAS && (AuthDomain[0]==0 || strncmp(AuthDomain,MyCommand.Domain, AUTH_SIZE) == 0)) {
+            if (cmd_vaddalias (&MyCommand) == 0) {
+                printf ("vaddalias: ok\n");
+            }
+            else {
+                printf ("vaddalias: failed\n");
+            }
+        }
+        else {
+            printf ("vaddalias: permission denied\n");
+        }
+    } else if (!strncmp(MyCommand.Command, "vdelalias", strlen("vdelalias"))) {
+        if (AuthMask & VADMIN_LVL_DELALIAS && (AuthDomain[0]==0 || strncmp(AuthDomain,MyCommand.Domain, AUTH_SIZE) == 0)) {
+            if (cmd_vdelalias (&MyCommand) == 0) {
+                printf ("vdelalias: ok\n");
+            }
+            else {
+                printf ("vdelalias: failed\n");
+            }
+        }
+        else {
+            printf ("vdelalias: permission denied\n");
+        }
+    } else if (!strncmp(MyCommand.Command, "vpasswd", strlen("vpasswd"))) {
+        if (AuthMask & VADMIN_LVL_CHNGPASSWD && (AuthDomain[0]==0 || strncmp(AuthDomain,MyCommand.Domain, AUTH_SIZE) == 0)) {
+            if (cmd_vpasswd (&MyCommand) == 0) {
+                printf ("vpasswd: ok\n");
+            }
+            else {
+                printf ("vpasswd: failed\n");
+            }
+        }
+        else {
+            printf ("vpasswd: permission denied\n");
+        }
+    } else if (!strncmp(MyCommand.Command, "vauth", strlen("vauth"))) {
+        if (AuthMask & VADMIN_LVL_AUTH) {
+            printf ("auth: ok\n");
+        } 
+    }
+
+    return 0;
+}
+
+void usage()
+{
+    printf( "vadmind: usage: [options]\n");
+    printf("options: -v (print the version)\n");
+    printf("         -a username (adds user \"username\" to the master access list)\n");
+    printf("         -d username (deletes user \"username\" from the master access list)\n");
+    printf("         -r (rebuilds cdb password file)\n");
+}
+
+void get_options(int argc,char **argv)
+{
+ int c;
+ int errflag;
+ extern char *optarg;
+ extern int optind;
+
+    memset(User, 0, MAX_BUFF);
+
+    errflag = 0;
+    while( !errflag && (c=getopt(argc,argv,"vrha:d:")) != -1 ) {
+        switch(c) {
+          case 'v':
+            printf("version: %s\n", VERSION);
+            break;
+          case 'h':
+            usage(); exit(0);
+          case 'a':
+            strncpy( User, optarg, MAX_BUFF-1);
+            AdminAction = VADMIN_ADDMASTERUSER;
+            break;
+          case 'd':
+            strncpy( User, optarg, MAX_BUFF-1);
+            AdminAction = VADMIN_DELMASTERUSER;
+            break;
+          case 'r':
+            AdminAction = VADMIN_REBUILDCDB;
+            break;
+          default:
+            errflag = 1;
+            break;
+        }
+    }
+}
+
+int vadmin_adduser(char * User, char * Passwd) {
+    char tmpbuf1[MAX_BUFF];
+    char tmpbuf2[MAX_BUFF];
+    char *tmpstr;
+    int added = 0;
+    char crypted[100];
+    FILE *fs1;
+    FILE *fs2;
+    struct vadminpasswd *spw = NULL;
+    //memset(crypted,0,100);
+    vadmin_set_passwd_files();
+    
+    /*if (is_username_valid(User)) {
+        printf("error: Username invalid\n");
+        return(-1);
+    }*/
+    if ((spw = vadmin_getpw(User)) != NULL) {
+        printf("error: User exists\n");
+        return(-1);
+    }
+    
+    mkpasswd3(Passwd,crypted,100);
+    if ((fs1 = fopen(vadmin_passwd_bak_file, "w+")) == NULL) {
+        printf("error: could not create passwd bak file\n");
+    }
+    if ((fs2 = fopen(vadmin_passwd_file, "r")) == NULL) {
+        printf("creating passwd file\n");
+        if ((fs2 = fopen(vadmin_passwd_file, "w+")) == NULL) {
+            printf("error: Could not open passwd file\n");
+            return -1;
+        }
+    }
+    while (fgets(tmpbuf1,MAX_BUFF,fs2)!=NULL){
+        //printf("length of tmpbuf1: %d", strlen(tmpbuf1));
+        strncpy(tmpbuf2, tmpbuf1, MAX_BUFF);
+        //printf("length of tmpbuf2: %d", strlen(tmpbuf2));
+        tmpstr = strtok(tmpbuf2,":");
+        //printf("length of tmpstr: %d", strlen(tmpstr));
+        if ( added == 0 && strcmp(User, tmpstr) < 0 ) {
+            added = 1;
+            fprintf(fs1,"%s:%s\n",User, crypted);
+        }
+        fputs(tmpbuf1, fs1);
+    }
+    if ( added == 0 ) {
+        fprintf(fs1,"%s:%s\n",User,crypted);
+    }
+    //printf("%s:%s\n",User, crypted);
+    fclose(fs1);
+    fclose(fs2);
+    //printf("%s -> %s\n",vadmin_passwd_bak_file, vadmin_passwd_file);
+    rename(vadmin_passwd_bak_file, vadmin_passwd_file);
+    vadmin_make_cdb();
+    return 0;
+}
+
+void vadmin_set_passwd_files() {
+    memset(vadmin_passwd_dir, 0, MAX_BUFF);
+    memset(vadmin_passwd_file, 0, MAX_BUFF);
+    memset(vadmin_passwd_cdb_file, 0, MAX_BUFF);
+    memset(vadmin_passwd_cdb_tmp_file, 0, MAX_BUFF);
+    memset(vadmin_passwd_lock_file, 0, MAX_BUFF);
+
+    snprintf(vadmin_passwd_dir, MAX_BUFF, "%s/etc", VPOPMAILDIR);
+    snprintf(vadmin_passwd_file, MAX_BUFF, "%s/%s", vadmin_passwd_dir,VADMIN_PASSWD_FILE);
+    snprintf(vadmin_passwd_bak_file, MAX_BUFF, "%s/%s.%d", vadmin_passwd_dir,VADMIN_PASSWD_BAK_FILE, getpid());
+    snprintf(vadmin_passwd_cdb_file, MAX_BUFF, "%s/%s", vadmin_passwd_dir,VADMIN_PASSWD_CDB_FILE);
+    snprintf(vadmin_passwd_cdb_tmp_file, MAX_BUFF, "%s/%s",vadmin_passwd_dir,VADMIN_PASSWD_CDB_TMP_FILE);
+    snprintf(vadmin_passwd_lock_file, MAX_BUFF, "%s/%s", vadmin_passwd_dir,VADMIN_PASSWD_LOCK_FILE);
+}
+
+int vadmin_make_cdb()
+{
+ char pwline[256];
+ char packbuf[8];
+ char *key;
+ char *data;
+ char *ptr;
+ int i,j,h;
+ int len;
+ long unsigned keylen,datalen;
+ uint32 pos,op;
+ struct cdbmake cdbm;
+ FILE *pwfile, *tmfile;
+ //char Dir[156];
+ //uid_t uid;
+ //gid_t gid;
+ //char *tmpstr;
+
+    /* If we don't optimize the index this time, just return */
+    if ( NoMakeIndex == 1 ) return(0);
+
+    if ((pwfile = fopen(vadmin_passwd_file,"r")) == NULL) {
+        return(-1);
+    }
+
+    cdbmake_init(&cdbm);
+    if ((tmfile = fopen(vadmin_passwd_cdb_tmp_file,"w")) == NULL) {
+        fprintf(stderr,"Error: could not create/open temporary file\n");
+        return(-1);
+    }
+
+    for (i=0; i < sizeof(cdbm.final); i++) {
+        if (putc(' ',tmfile) == EOF) {
+                fprintf(stdout,"Error:error writing temp file\n");
+            return(-1);
+        }
+    }
+    pos = sizeof(cdbm.final);
+    
+    /* creation **/
+    fgets(pwline,sizeof(pwline),pwfile);
+    while (!feof(pwfile)) {
+        key = pwline; ptr = pwline;
+        while (*ptr != ':') { ptr++; }
+        *ptr = 0; data = ptr; data++;
+        while (*ptr != '\n') { ptr++; }
+        *ptr = 0;
+        keylen = strlen(key); datalen = strlen(data);
+#ifdef DEBUG
+        fprintf (stdout,"Got entry: keylen = %lu, key = %s\n           datalen = %lu, data = %s\n",keylen,key,datalen,data);
+#endif
+
+        cdbmake_pack(packbuf, (uint32)keylen);
+        cdbmake_pack(packbuf + 4, (uint32)datalen);
+        if (fwrite(packbuf,1,8,tmfile) < 8) {
+            fprintf(stderr,"Error: error writing temp file\n");
+            return(-1);
+        }
+
+        h = CDBMAKE_HASHSTART;
+        for (i=0; i < keylen; i++) {
+            h = cdbmake_hashadd(h,key[i]);
+            if (putc(key[i],tmfile) == EOF) {
+                fprintf (stderr,"Error: error temp file\n");
+                return(-1);
+            }
+        }
+        for (i=0; i < datalen; i++) {
+            if (putc(data[i],tmfile) == EOF) {
+                fprintf (stderr,"Error: write error temp file");
+                return(-1);
+            }
+        }
+        if (!cdbmake_add(&cdbm,h,pos,malloc)) {
+            fprintf(stderr, "Error: out of memory\n");
+            return(-1);
+        }
+
+        op = pos;
+        pos += (uint32)8;
+        pos += (uint32)keylen;
+        pos += (uint32)datalen;
+        if (pos < op) {
+            fprintf(stderr,"Error: too much data\n");
+            return(-1);
+        }
+        if (!cdbmake_split(&cdbm,malloc)) {
+            fprintf(stderr,"Error: out of memory\n");
+            return(-1);
+        }
+        fgets(pwline,sizeof(pwline),pwfile);
+        free(cdbm.split);
+    }
+    fclose(pwfile);
+
+    if (!cdbmake_split(&cdbm,malloc)) {
+        fprintf(stderr, "Error: out of memory\n");
+        return(-1);
+    }
+
+    for (i=0; i < 256; i++) {
+        len = cdbmake_throw(&cdbm,pos,i);
+        for (j=0; j < len; j++) {
+            cdbmake_pack(packbuf,cdbm.hash[j].h);
+            cdbmake_pack(packbuf + 4, cdbm.hash[j].p);
+            if (fwrite(packbuf,1,8,tmfile) < 8) {
+                fprintf(stderr,"Error 1: error temp file\n");
+                return(-1);
+            }
+            op = pos;
+            pos += (uint32)8;
+            if (pos < op) {
+                fprintf (stdout, "Error 12: too much data\n");
+                return(-1);
+            }
+        }
+    }
+    if (fflush(tmfile) == EOF) {
+        fprintf (stderr,"Error 20: write error temp file\n");
+        return(-1);
+    }
+    rewind(tmfile);
+    if (fwrite(cdbm.final,1,sizeof(cdbm.final),tmfile)<sizeof(cdbm.final)){
+        fprintf(stderr,"Error 21: write error temp file\n");
+        return(-1);
+    }
+    if (fflush(tmfile) == EOF) {
+        fprintf(stderr,"Error 22: write error temp file\n");
+        return(-1);
+    }
+    
+    if (close(fileno(tmfile)) == -1) {
+        fprintf(stderr,"Error 24: error with close()\n");
+        return(-1);
+    }
+    if (rename(vadmin_passwd_cdb_tmp_file,vadmin_passwd_cdb_file)) {
+        fprintf(stderr, 
+            "Error 25: could not rename cdb.tmp to vpasswd.cdb\n");
+        return(-1);
+    }
+    free(cdbm.head);
+    free(cdbm.split);
+
+    /*tmpstr = vget_assign(domain, Dir, 156, &uid, &gid );*/
+    chown(vadmin_passwd_cdb_file, VPOPMAILUID, VPOPMAILGID);
+    chown(vadmin_passwd_lock_file, VPOPMAILUID, VPOPMAILGID);
+    chown(vadmin_passwd_file, VPOPMAILUID, VPOPMAILGID);
+
+    return 0;
+}
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/vcdb.c vpopmail-vadmin-5.3.19/vcdb.c
--- vpopmail-5.3.19/vcdb.c	Thu Feb 20 19:27:49 2003
+++ vpopmail-vadmin-5.3.19/vcdb.c	Thu Apr  3 11:04:05 2003
@@ -40,6 +40,7 @@
 #include "vauth.h"
 #include "vcdb.h"
 #include "file_lock.h"
+#include "vlimits.h"
 
 #define TOKENS " \n"
 
@@ -232,6 +233,7 @@
 #ifdef FILE_LOCKING
  FILE *lock_fs;
 #endif
+ struct vlimits limits;
 
     verrori = 0;
     lowerit(user);
@@ -331,6 +333,12 @@
     fprintf (stderr,"                     pw_shell  = %s\n",pwent.pw_shell);
 #endif
 
+    if (vget_limits (in_domain,&limits) == 0) {
+        if (! pwent.pw_gid && V_OVERRIDE) {
+            pwent.pw_gid = pwent.pw_gid | vlimits_get_gid_mask (&limits);
+        }
+    }
+
     free(in_domain);
     return(&pwent);
 }
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/vlimits.c vpopmail-vadmin-5.3.19/vlimits.c
--- vpopmail-5.3.19/vlimits.c	Wed Mar  5 19:41:06 2003
+++ vpopmail-vadmin-5.3.19/vlimits.c	Thu Apr  3 11:04:05 2003
@@ -16,22 +16,37 @@
 #include "vpopmail.h"
 
 
-#ifndef ENABLE_MYSQL_LIMITS
-
 #define TOKENS " :\t\n\r"
 
-/* find/read the .qmailadmin-limits file */
-int vget_limits(const char *domain, struct vlimits *limits)
+int vlimits_get_gid_mask(struct vlimits *limits)
 {
-    char buf[256];
-    char mydomain[256];
-    char dir[MAXPATHLEN];
-    uid_t uid;
-    gid_t gid;
-    char * s1;
-    char * s2;
-    FILE * fs;
+    int mask = 0;
+    if (limits->disable_pop != 0) {
+        mask |= NO_POP;
+    }
+    if (limits->disable_smtp != 0) {
+        mask |= NO_SMTP;
+    }
+    if (limits->disable_imap != 0) {
+        mask |= NO_IMAP;
+    }
+    if (limits->disable_relay != 0) {
+        mask |= NO_RELAY;
+    }
+    if (limits->disable_webmail != 0) {
+        mask |= NO_WEBMAIL;
+    }
+    if (limits->disable_passwordchanging != 0) {
+        mask |= NO_PASSWD_CHNG;
+    }
+    if (limits->disable_dialup != 0) {
+        mask |= NO_POP;
+    }
+    return mask;
+}
 
+int vlimits_init_default(struct vlimits *limits)
+{
     /* initialize structure */
     memset(limits, 0, sizeof(*limits));
     limits->maxpopaccounts = -1;
@@ -39,15 +54,20 @@
     limits->maxforwards = -1;
     limits->maxautoresponders = -1;
     limits->maxmailinglists = -1;
+    // if this fails, we have the very basic limits above
+    vlimits_read_limits_file(VLIMITS_DEFAULT_FILE, limits);
 
-    /* use copy of name as vget_assign may change it on us */
-    strncpy(mydomain, domain, sizeof(mydomain));
-    mydomain[255] = '\0';
+    return 0;
+}
 
-    /* get filename */
-    vget_assign(mydomain, dir, sizeof(dir), &uid, &gid);
-    strncat(dir, "/.qmailadmin-limits", sizeof(dir));
 
+int vlimits_read_limits_file(const char *dir, struct vlimits * limits)
+{
+    char buf[256];    
+    char * s1;
+    char * s2;
+    FILE * fs;
+    
     /* open file */
     if ((fs = fopen(dir, "r")) != NULL) {
         while (fgets(buf, sizeof(buf), fs) != NULL) {
@@ -185,10 +205,46 @@
             }
         }
         fclose(fs);
+        return 0;
+    }
+    else {
+        return -1;
+    }
+}
+
+#ifndef ENABLE_MYSQL_LIMITS
+/* find/read the .qmailadmin-limits file */
+int vget_limits(const char *domain, struct vlimits *limits)
+{
+    char mydomain[256];
+    char dir[MAXPATHLEN];
+    uid_t uid;
+    gid_t gid;
+
+
+    /* initialize structure */
+    memset(limits, 0, sizeof(*limits));
+    limits->maxpopaccounts = -1;
+    limits->maxaliases = -1;
+    limits->maxforwards = -1;
+    limits->maxautoresponders = -1;
+    limits->maxmailinglists = -1;
+
+    /* use copy of name as vget_assign may change it on us */
+    strncpy(mydomain, domain, sizeof(mydomain));
+    mydomain[255] = '\0';
+
+    /* get filename */
+    vget_assign(mydomain, dir, sizeof(dir), &uid, &gid);
+    strncat(dir, "/.qmailadmin-limits", sizeof(dir)-strlen(dir)-1);
+
+    /* open file */
+    if (vlimits_read_limits_file (dir, limits) == 0) {
         chown(dir,uid,gid);
         chmod(dir, S_IRUSR|S_IWUSR);
     } else {
-        return -1;
+        vlimits_init_default(limits);
+        vset_limits(domain, limits);
     }
 
     return 0;
@@ -208,7 +264,7 @@
 
     /* get filename */
     vget_assign(mydomain, dir, sizeof(dir), &uid, &gid);
-    strncat(dir, "/.qmailadmin-limits", sizeof(dir));
+    strncat(dir, "/.qmailadmin-limits", sizeof(dir)-strlen(dir)-1);
 
     /* open file */
     if ((fs = fopen(dir, "w+")) != NULL) {
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/vlimits.default vpopmail-vadmin-5.3.19/vlimits.default
--- vpopmail-5.3.19/vlimits.default	Thu Jan  1 01:00:00 1970
+++ vpopmail-vadmin-5.3.19/vlimits.default	Thu Apr  3 11:11:22 2003
@@ -0,0 +1,16 @@
+maxpopaccounts: -1
+maxaliases: -1
+maxforwards: -1
+maxautoresponders: -1
+maxmailinglists: -1
+quota: 0
+maxmsgcount: 0
+default_quota: 0
+default_maxmsgcount: 0
+perm_account: 7
+perm_alias: 7
+perm_forward: 7
+perm_autoresponder: 7
+perm_maillist: 7
+perm_quota: 7
+perm_defaultquota: 7
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/vlimits.h vpopmail-vadmin-5.3.19/vlimits.h
--- vpopmail-5.3.19/vlimits.h	Fri Jan 24 09:30:33 2003
+++ vpopmail-vadmin-5.3.19/vlimits.h	Thu Apr  3 11:04:05 2003
@@ -50,6 +50,9 @@
       short     perm_defaultquota;
 };
 
+int vlimits_init_default(struct vlimits * limits);
+int vlimits_read_limits_file(const char * dir, struct vlimits * limits);
+int vlimits_get_gid_mask(struct vlimits *limits);
 int vget_limits(const char * domain, struct vlimits * limits);
 int vset_limits(const char * domain, const struct vlimits * limits);
 int vdel_limits(const char * domain);
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/vmoddomlimits.c vpopmail-vadmin-5.3.19/vmoddomlimits.c
--- vpopmail-5.3.19/vmoddomlimits.c	Thu Jan  1 01:00:00 1970
+++ vpopmail-vadmin-5.3.19/vmoddomlimits.c	Thu Apr  3 11:04:05 2003
@@ -0,0 +1,511 @@
+/*
+ * Copyright (C) 1999-2002 Inter7 Internet Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <signal.h>
+#include "config.h"
+#include "vpopmail.h"
+#include "vauth.h"
+#include "vlimits.h"
+
+#define MAX_BUFF 500
+
+char Domain[MAX_BUFF];
+
+char DomainQuota[MAX_BUFF];
+char DefaultUserQuota[MAX_BUFF];
+char DomainMaxMsgCount[MAX_BUFF];
+char DefaultUserMaxMsgCount[MAX_BUFF];
+char MaxPopAccounts[MAX_BUFF];
+char MaxAliases[MAX_BUFF];
+char MaxForwards[MAX_BUFF];
+char MaxAutoresponders[MAX_BUFF];
+char MaxMailinglists[MAX_BUFF];
+char GidFlagString[MAX_BUFF];
+char PermAccountFlagString[MAX_BUFF];
+char PermAliasFlagString[MAX_BUFF];
+char PermForwardFlagString[MAX_BUFF];
+char PermAutoresponderFlagString[MAX_BUFF];
+char PermMaillistFlagString[MAX_BUFF];
+char PermMaillistUsersFlagString[MAX_BUFF];
+char PermMaillistModeratorsFlagString[MAX_BUFF];
+char PermQuotaFlagString[MAX_BUFF];
+char PermDefaultQuotaFlagString[MAX_BUFF];
+
+int GidFlag = 0;
+int PermAccountFlag = 0;
+int PermAliasFlag = 0;
+int PermForwardFlag = 0;
+int PermAutoresponderFlag = 0;
+int PermMaillistFlag = 0;
+int PermMaillistUsersFlag = 0;
+int PermMaillistModeratorsFlag = 0;
+int PermQuotaFlag = 0;
+int PermDefaultQuotaFlag = 0;
+
+int QuotaFlag = 0;
+int ShowLimits = 0;
+struct vlimits limits;
+
+void usage();
+void get_options(int argc,char **argv);
+
+int main(argc,argv)
+ int argc;
+ char *argv[];
+{
+ int i;
+ char OptionString[MAX_BUFF];
+ 
+
+    get_options(argc,argv);
+    
+    if ( vget_assign(Domain, NULL, 156, NULL, NULL ) != NULL ) {    
+    
+        vget_limits(Domain,&limits);
+        if (ShowLimits) {
+            memset (OptionString, 0, MAX_BUFF);
+            printf("Domain: %s\n", Domain);
+            printf("--\n");
+            printf("Max Pop Accounts: %d\n", limits.maxpopaccounts);
+            printf("Max Aliases: %d\n", limits.maxaliases);
+            printf("Max Forwards: %d\n", limits.maxforwards);
+            printf("Max Autoresponders: %d\n", limits.maxautoresponders);
+            printf("Max Mailinglists: %d\n", limits.maxmailinglists);
+            printf("GID Flags:\n");
+            if (limits.disable_imap != 0) {
+                printf("  NO_IMAP\n");
+                strcat(OptionString, "i");
+            }
+            if (limits.disable_smtp != 0) {
+                printf("  NO_SMTP\n");
+                strcat(OptionString, "s");
+            }
+            if (limits.disable_pop != 0) {
+                printf("  NO_POP\n");
+                strcat(OptionString, "p");
+            }
+            if (limits.disable_webmail != 0) {
+                printf("  NO_WEBMAIL\n");
+                strcat(OptionString, "w");
+            }
+            if (limits.disable_passwordchanging != 0) {
+                printf("  NO_PASSWD_CHNG\n");
+                strcat(OptionString, "d");
+            }
+            if (limits.disable_relay != 0) {
+                printf("  NO_RELAY\n");
+                strcat(OptionString, "r");
+            }
+            if (limits.disable_dialup != 0) {
+                printf("  NO_DIALUP\n");
+                strcat(OptionString, "u");
+            }
+            printf("Flags (for commandline): %s\n", OptionString);
+            printf("Flags for non postmaster accounts:");
+            printf("\n  pop account:            ");
+            printf ((limits.perm_account & VLIMIT_DISABLE_CREATE ? "DENY_CREATE  " :"ALLOW_CREATE ") );
+            printf ((limits.perm_account & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY  " :"ALLOW_MODIFY ") );
+            printf ((limits.perm_account & VLIMIT_DISABLE_DELETE ? "DENY_DELETE  " :"ALLOW_DELETE ") );
+            printf("\n  alias:                  ");
+            printf ((limits.perm_alias & VLIMIT_DISABLE_CREATE ? "DENY_CREATE  " :"ALLOW_CREATE ") );
+            printf ((limits.perm_alias & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY  " :"ALLOW_MODIFY ") );
+            printf ((limits.perm_alias & VLIMIT_DISABLE_DELETE ? "DENY_DELETE  " :"ALLOW_DELETE ") );
+            printf("\n  forward:                ");
+            printf ((limits.perm_forward & VLIMIT_DISABLE_CREATE ? "DENY_CREATE  " :"ALLOW_CREATE ") );
+            printf ((limits.perm_forward & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY  " :"ALLOW_MODIFY ") );
+            printf ((limits.perm_forward & VLIMIT_DISABLE_DELETE ? "DENY_DELETE  " :"ALLOW_DELETE ") );
+            printf("\n  autoresponder:          ");
+            printf ((limits.perm_autoresponder & VLIMIT_DISABLE_CREATE ? "DENY_CREATE  " :"ALLOW_CREATE ") );
+            printf ((limits.perm_autoresponder & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY  " :"ALLOW_MODIFY ") );
+            printf ((limits.perm_autoresponder & VLIMIT_DISABLE_DELETE ? "DENY_DELETE  " :"ALLOW_DELETE ") );
+            printf("\n  mailinglist:            ");
+            printf ((limits.perm_maillist & VLIMIT_DISABLE_CREATE ? "DENY_CREATE  " :"ALLOW_CREATE ") );
+            printf ((limits.perm_maillist & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY  " :"ALLOW_MODIFY ") );
+            printf ((limits.perm_maillist & VLIMIT_DISABLE_DELETE ? "DENY_DELETE  " :"ALLOW_DELETE ") );
+            printf("\n  mailinglist users:      ");
+            printf ((limits.perm_maillist_users & VLIMIT_DISABLE_CREATE ? "DENY_CREATE  " :"ALLOW_CREATE ") );
+            printf ((limits.perm_maillist_users & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY  " :"ALLOW_MODIFY ") );
+            printf ((limits.perm_maillist_users & VLIMIT_DISABLE_DELETE ? "DENY_DELETE  " :"ALLOW_DELETE ") );
+            printf("\n  mailinglist moderators: ");
+            printf ((limits.perm_maillist_moderators & VLIMIT_DISABLE_CREATE ? "DENY_CREATE  " :"ALLOW_CREATE ") );
+            printf ((limits.perm_maillist_moderators & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY  " :"ALLOW_MODIFY ") );
+            printf ((limits.perm_maillist_moderators & VLIMIT_DISABLE_DELETE ? "DENY_DELETE  " :"ALLOW_DELETE ") );
+            printf("\n  quota:                  ");
+            printf ((limits.perm_quota & VLIMIT_DISABLE_CREATE ? "DENY_CREATE  " :"ALLOW_CREATE ") );
+            printf ((limits.perm_quota & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY  " :"ALLOW_MODIFY ") );
+            printf ((limits.perm_quota & VLIMIT_DISABLE_DELETE ? "DENY_DELETE  " :"ALLOW_DELETE ") );
+            printf("\n  default quota:          ");
+            printf ((limits.perm_defaultquota & VLIMIT_DISABLE_CREATE ? "DENY_CREATE  " :"ALLOW_CREATE ") );
+            printf ((limits.perm_defaultquota & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY  " :"ALLOW_MODIFY ") );
+            printf ((limits.perm_defaultquota & VLIMIT_DISABLE_DELETE ? "DENY_DELETE  " :"ALLOW_DELETE ") );
+            
+            printf("\n");
+            printf("Domain Quota: %d\n", limits.diskquota);
+            printf("Default User Quota: %d\n", limits.defaultquota);
+            printf("Max Domain Messages: %d\n", limits.maxmsgcount);
+            printf("Default Max Messages per User: %d\n", limits.defaultmaxmsgcount);
+            return(vexit(0));
+        }
+                
+        if (MaxPopAccounts[0] != 0) {
+            limits.maxpopaccounts = atoi(MaxPopAccounts);
+        }
+        if (MaxAliases[0] != 0) {
+            limits.maxaliases = atoi(MaxAliases);
+        }
+        if (MaxForwards[0] != 0) {
+            limits.maxforwards = atoi(MaxForwards);
+        }
+        if (MaxAutoresponders[0] != 0) {
+            limits.maxautoresponders = atoi(MaxAutoresponders);
+        }
+        if (MaxMailinglists[0] != 0) {
+            limits.maxmailinglists = atoi(MaxMailinglists);
+        }
+        
+        /* quota & message count limits */
+        if (DomainQuota[0] != 0) {
+            limits.diskquota = atoi(DomainQuota);
+        }
+        if (DomainMaxMsgCount[0] != 0) {
+            limits.maxmsgcount = atoi(DomainMaxMsgCount);
+        }
+        if (DefaultUserQuota[0] != 0) {
+            limits.defaultquota = atoi(DefaultUserQuota);
+        }
+        if (DefaultUserMaxMsgCount[0] != 0) {
+            limits.defaultmaxmsgcount = atoi(DefaultUserMaxMsgCount);
+        }
+        
+        if (GidFlag == 1) {
+            GidFlag = 0;
+            limits.disable_dialup = 0;
+            limits.disable_passwordchanging = 0;
+            limits.disable_pop = 0;
+            limits.disable_smtp = 0;
+            limits.disable_webmail = 0;
+            limits.disable_imap = 0;
+            limits.disable_relay = 0;
+            for (i=0; i<strlen(GidFlagString); i++) {
+                switch(GidFlagString[i]) {
+                    case 'u': limits.disable_dialup = 1; break;
+                    case 'd': limits.disable_passwordchanging = 1; break;
+                    case 'p': limits.disable_pop = 1; break;
+                    case 's': limits.disable_smtp = 1; break;
+                    case 'w': limits.disable_webmail = 1; break;
+                    case 'i': limits.disable_imap = 1; break;
+                    case 'r': limits.disable_relay = 1; break;
+                }
+            }
+        }
+        if (PermAccountFlag == 1) {
+            limits.perm_account=0;
+            for (i=0; i<strlen(PermAccountFlagString); i++) {
+                switch(PermAccountFlagString[i]) {
+                    case 'a': limits.perm_account|=VLIMIT_DISABLE_ALL; break;
+                    case 'c': limits.perm_account|=VLIMIT_DISABLE_CREATE; break;
+                    case 'm': limits.perm_account|=VLIMIT_DISABLE_MODIFY; break;
+                    case 'd': limits.perm_account|=VLIMIT_DISABLE_DELETE; break;
+                }
+            }
+        }
+        if (PermAliasFlag == 1) {
+            limits.perm_alias=0;
+            for (i=0; i<strlen(PermAliasFlagString); i++) {
+                switch(PermAliasFlagString[i]) {
+                    case 'a': limits.perm_alias|=VLIMIT_DISABLE_ALL; break;
+                    case 'c': limits.perm_alias|=VLIMIT_DISABLE_CREATE; break;
+                    case 'm': limits.perm_alias|=VLIMIT_DISABLE_MODIFY; break;
+                    case 'd': limits.perm_alias|=VLIMIT_DISABLE_DELETE; break;
+                }
+            }
+        }
+        if (PermForwardFlag == 1) {
+            limits.perm_forward=0;
+            for (i=0; i<strlen(PermForwardFlagString); i++) {
+                switch(PermForwardFlagString[i]) {
+                    case 'a': limits.perm_forward|=VLIMIT_DISABLE_ALL; break;
+                    case 'c': limits.perm_forward|=VLIMIT_DISABLE_CREATE; break;
+                    case 'm': limits.perm_forward|=VLIMIT_DISABLE_MODIFY; break;
+                    case 'd': limits.perm_forward|=VLIMIT_DISABLE_DELETE; break;
+                }
+            }
+        }
+        if (PermAutoresponderFlag == 1) {
+            limits.perm_autoresponder=0;
+            for (i=0; i<strlen(PermAutoresponderFlagString); i++) {
+                switch(PermAutoresponderFlagString[i]) {
+                    case 'a': limits.perm_autoresponder|=VLIMIT_DISABLE_ALL; break;
+                    case 'c': limits.perm_autoresponder|=VLIMIT_DISABLE_CREATE; break;
+                    case 'm': limits.perm_autoresponder|=VLIMIT_DISABLE_MODIFY; break;
+                    case 'd': limits.perm_autoresponder|=VLIMIT_DISABLE_DELETE; break;
+                }
+            }
+        }
+        if (PermMaillistFlag == 1) {
+            limits.perm_maillist=0;
+            for (i=0; i<strlen(PermMaillistFlagString); i++) {
+                switch(PermMaillistFlagString[i]) {
+                    case 'a': limits.perm_maillist|=VLIMIT_DISABLE_ALL; break;
+                    case 'c': limits.perm_maillist|=VLIMIT_DISABLE_CREATE; break;
+                    case 'm': limits.perm_maillist|=VLIMIT_DISABLE_MODIFY; break;
+                    case 'd': limits.perm_maillist|=VLIMIT_DISABLE_DELETE; break;
+                }
+            }
+        }
+        if (PermMaillistUsersFlag == 1) {
+            limits.perm_maillist_users=0;
+            for (i=0; i<strlen(PermMaillistUsersFlagString); i++) {
+                switch(PermMaillistUsersFlagString[i]) {
+                    case 'a': limits.perm_maillist_users|=VLIMIT_DISABLE_ALL; break;
+                    case 'c': limits.perm_maillist_users|=VLIMIT_DISABLE_CREATE; break;
+                    case 'm': limits.perm_maillist_users|=VLIMIT_DISABLE_MODIFY; break;
+                    case 'd': limits.perm_maillist_users|=VLIMIT_DISABLE_DELETE; break;
+                }
+            }
+        }
+        if (PermMaillistModeratorsFlag == 1) {
+            limits.perm_maillist_moderators=0;
+            for (i=0; i<strlen(PermMaillistModeratorsFlagString); i++) {
+                switch(PermMaillistModeratorsFlagString[i]) {
+                    case 'a': limits.perm_maillist_moderators|=VLIMIT_DISABLE_ALL; break;
+                    case 'c': limits.perm_maillist_moderators|=VLIMIT_DISABLE_CREATE; break;
+                    case 'm': limits.perm_maillist_moderators|=VLIMIT_DISABLE_MODIFY; break;
+                    case 'd': limits.perm_maillist_moderators|=VLIMIT_DISABLE_DELETE; break;
+                }
+            }
+        }
+        if (PermQuotaFlag == 1) {
+            limits.perm_quota=0;
+            for (i=0; i<strlen(PermQuotaFlagString); i++) {
+                switch(PermQuotaFlagString[i]) {
+                    case 'a': limits.perm_quota|=VLIMIT_DISABLE_ALL; break;
+                    case 'c': limits.perm_quota|=VLIMIT_DISABLE_CREATE; break;
+                    case 'm': limits.perm_quota|=VLIMIT_DISABLE_MODIFY; break;
+                    case 'd': limits.perm_quota|=VLIMIT_DISABLE_DELETE; break;
+                }
+            }
+        }
+        if (PermDefaultQuotaFlag == 1) {
+            limits.perm_defaultquota=0;
+            for (i=0; i<strlen(PermDefaultQuotaFlagString); i++) {
+                switch(PermDefaultQuotaFlagString[i]) {
+                    case 'a': limits.perm_defaultquota|=VLIMIT_DISABLE_ALL; break;
+                    case 'c': limits.perm_defaultquota|=VLIMIT_DISABLE_CREATE; break;
+                    case 'm': limits.perm_defaultquota|=VLIMIT_DISABLE_MODIFY; break;
+                    case 'd': limits.perm_defaultquota|=VLIMIT_DISABLE_DELETE; break;
+                }
+            }
+        }
+        vset_limits(Domain,&limits);
+    }
+    
+    return(vexit(0));
+
+}
+
+void usage()
+{
+    printf( "vmoddomlimits: usage: [options] domain \n");
+    printf("options: -v ( display the vpopmail version number )\n");
+    printf("         -S ( show current settings )\n");
+    printf("         -Q quota ( set domain quota )\n");
+    printf("         -q quota ( set default user quota )\n");
+    printf("         -M count ( set domain max msg count )\n");
+    printf("         -m count ( set default user max msg count )\n");
+    printf("         -P count ( set max ammount of pop accounts )\n");
+    printf("         -A count ( set max ammount of aliases )\n");
+    printf("         -F count ( set max ammount of forwards )\n");
+    printf("         -R count ( set max ammount of autoresponders )\n");
+    printf("         -L count ( set max ammount of mailing lists )\n");
+    
+
+    printf("the following options are bit flags in the gid int field\n");
+    printf("         -g \"flags\"  (set flags, see below)\n");
+    printf("         gid flags:\n");
+    printf("            u ( set no dialup flag )\n");
+    printf("            d ( set no password changing flag )\n");
+    printf("            p ( set no pop access flag )\n");
+    printf("            s ( set no smtp access flag )\n");
+    printf("            w ( set no web mail access flag )\n");
+    printf("            i ( set no imap access flag )\n");
+    printf("            r ( set no external relay flag )\n");
+    
+    printf("the following options are bit flags for non postmaster admins\n");
+    printf("         -p \"flags\"  (set pop account flags)\n");
+    printf("         -a \"flags\"  (set alias flags)\n");
+    printf("         -f \"flags\"  (set forward flags)\n");
+    printf("         -r \"flags\"  (set autoresponder flags)\n");
+    printf("         -l \"flags\"  (set mailinglist flags)\n");
+    printf("         -u \"flags\"  (set mailinglist users flags)\n");
+    printf("         -o \"flags\"  (set mailinglist moderators flags)\n");
+    printf("         -x \"flags\"  (set quota flags)\n");
+    printf("         -z \"flags\"  (set default quota flags)\n");
+    printf("         perm flags:\n");
+    printf("            a ( set deny all flag )\n");
+    printf("            c ( set deny create flag )\n");
+    printf("            m ( set deny modify flag )\n");
+    printf("            d ( set deny delete flag )\n");
+                
+}
+
+void get_options(int argc,char **argv)
+{
+ int c;
+ int errflag;
+ extern char *optarg;
+ extern int optind;
+
+    memset(Domain, 0, MAX_BUFF);
+    memset(DomainQuota, 0, MAX_BUFF);
+    memset(DefaultUserQuota, 0, MAX_BUFF);
+    memset(DomainMaxMsgCount, 0, MAX_BUFF);
+    memset(DefaultUserMaxMsgCount, 0, MAX_BUFF);
+    memset(MaxPopAccounts, 0, MAX_BUFF);
+    memset(MaxAliases, 0, MAX_BUFF);
+    memset(MaxForwards, 0, MAX_BUFF);
+    memset(MaxAutoresponders, 0, MAX_BUFF);
+    memset(MaxMailinglists, 0, MAX_BUFF);
+    memset(GidFlagString, 0, MAX_BUFF);
+    
+    memset(PermAccountFlagString,0,MAX_BUFF);
+    memset(PermAliasFlagString,0,MAX_BUFF);
+    memset(PermForwardFlagString,0,MAX_BUFF);
+    memset(PermAutoresponderFlagString,0,MAX_BUFF);
+    memset(PermMaillistFlagString,0,MAX_BUFF);
+    memset(PermMaillistUsersFlagString,0,MAX_BUFF);
+    memset(PermMaillistModeratorsFlagString,0,MAX_BUFF);
+    memset(PermQuotaFlagString,0,MAX_BUFF);
+    memset(PermDefaultQuotaFlagString,0,MAX_BUFF);
+    
+    QuotaFlag = 0;
+    GidFlag = 0;
+    PermAccountFlag = 0;
+    PermAliasFlag = 0;
+    PermForwardFlag = 0;
+    PermAutoresponderFlag = 0;
+    PermMaillistFlag = 0;
+    PermMaillistUsersFlag = 0;
+    PermMaillistModeratorsFlag = 0;
+    PermQuotaFlag = 0;
+    PermDefaultQuotaFlag = 0;
+    //NoMakeIndex = 0;
+    ShowLimits = 0;
+    errflag = 0;
+    while( (c=getopt(argc,argv,"vSQ:q:M:m:P:A:F:R:L:g:p:a:f:r:l:u:o:x:z:h")) != -1 ) {
+        switch(c) {
+            case 'v':
+                printf("version: %s\n", VERSION);
+                break;
+            case 'S':
+                ShowLimits = 1;
+                break;
+            case 'Q':
+                strncpy( DomainQuota, optarg, MAX_BUFF-1);
+                break;
+            case 'q':
+                strncpy( DefaultUserQuota, optarg, MAX_BUFF-1);
+                break;
+            case 'M':
+                strncpy( DomainMaxMsgCount, optarg, MAX_BUFF-1);
+                break;
+            case 'm':
+                strncpy( DefaultUserMaxMsgCount, optarg, MAX_BUFF-1);
+                break;
+            case 'P':
+                strncpy( MaxPopAccounts, optarg, MAX_BUFF-1);
+                break;
+            case 'A':
+                strncpy( MaxAliases, optarg, MAX_BUFF-1);
+                break;
+            case 'F':
+                strncpy( MaxForwards, optarg, MAX_BUFF-1);
+                break;
+            case 'R':
+                strncpy( MaxAutoresponders, optarg, MAX_BUFF-1);
+                break;
+            case 'L':
+                strncpy( MaxMailinglists, optarg, MAX_BUFF-1);
+                break;
+            case 'g':
+                strncpy( GidFlagString, optarg, MAX_BUFF-1);
+                GidFlag = 1;
+                break;
+            case 'p':
+                strncpy( PermAccountFlagString, optarg, MAX_BUFF-1);
+                PermAccountFlag = 1;
+                break;
+            case 'a':
+                strncpy( PermAliasFlagString, optarg, MAX_BUFF-1);
+                PermAliasFlag = 1;
+                break;
+            case 'f':
+                strncpy( PermForwardFlagString, optarg, MAX_BUFF-1);
+                PermForwardFlag = 1;
+                break;
+            case 'r':
+                strncpy( PermAutoresponderFlagString, optarg, MAX_BUFF-1);
+                PermAutoresponderFlag = 1;
+                break;
+            case 'l':
+                strncpy( PermMaillistFlagString, optarg, MAX_BUFF-1);
+                PermMaillistFlag = 1;
+                break;
+            case 'u':
+                strncpy( PermMaillistUsersFlagString, optarg, MAX_BUFF-1);
+                PermMaillistUsersFlag = 1;
+                break;
+            case 'o':
+                strncpy( PermMaillistModeratorsFlagString, optarg, MAX_BUFF-1);
+                PermMaillistModeratorsFlag = 1;
+                break;
+            case 'x':
+                strncpy( PermQuotaFlagString, optarg, MAX_BUFF-1);
+                PermQuotaFlag = 1;
+                break;
+            case 'z':
+                strncpy( PermDefaultQuotaFlagString, optarg, MAX_BUFF-1);
+                PermDefaultQuotaFlag = 1;
+                break;
+            case 'h':
+                usage();
+                vexit(0);
+            default:
+                errflag = 1;
+                break;
+        }
+    }
+
+    if ( optind < argc ) {
+        strncpy(Domain, argv[optind], MAX_BUFF);
+        ++optind;
+    }
+
+    if ( Domain[0] == 0 ) { 
+        usage();
+        vexit(-1);
+    }
+}
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/vmysql.c vpopmail-vadmin-5.3.19/vmysql.c
--- vpopmail-5.3.19/vmysql.c	Wed Mar  5 18:09:47 2003
+++ vpopmail-vadmin-5.3.19/vmysql.c	Thu Apr  3 11:04:05 2003
@@ -327,6 +327,7 @@
  uid_t myuid;
  uid_t uid;
  gid_t gid;
+ struct vlimits limits;
 
     vget_assign(domain,NULL,156,&uid,&gid);
     myuid = geteuid();
@@ -406,6 +407,11 @@
         return(NULL);
     }
     mysql_free_result(res_read);
+    if (vget_limits (in_domain,&limits) == 0) {
+        if (! vpw.pw_gid && V_OVERRIDE) {
+            vpw.pw_gid |= vlimits_get_gid_mask (&limits);
+        }
+    }
     return(&vpw);
 }
 
@@ -1444,8 +1450,9 @@
     }
 
     if (mysql_num_rows(res_read) == 0) {
-        fprintf(stderr, "vnysql: can't find limits for domain '%s'\n", domain);
-        return -1;
+        vlimits_init_default(limits);
+        vset_limits(domain, limits);
+        return 0;
     }
 
     if ((row = mysql_fetch_row(res_read)) != NULL) {
@@ -1533,10 +1540,7 @@
             return(-1);
         }
     }
-    if (!(res_update = mysql_store_result(&mysql_update))) {
-        fprintf(stderr, "vmysql: store result failed\n");
-        return -1;
-    }
+    res_update = mysql_store_result(&mysql_update);
     mysql_free_result(res_update);
 
     return 0;
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/vpopmail.c vpopmail-vadmin-5.3.19/vpopmail.c
--- vpopmail-5.3.19/vpopmail.c	Mon Jan 27 17:29:15 2003
+++ vpopmail-vadmin-5.3.19/vpopmail.c	Thu Apr  3 11:04:05 2003
@@ -38,6 +38,7 @@
 #include "vpopmail.h"
 #include "file_lock.h"
 #include "vauth.h"
+#include "vlimits.h"
 
 #define MAX_BUFF 500
 static char Crypted[MAX_BUFF];
@@ -93,6 +94,7 @@
  int i;
  char *domain_sub_dir;
  char tmpbuf[156];
+ struct vlimits limits;
 
   /* we only do lower case */
   lowerit(domain);
@@ -201,6 +203,8 @@
   /* return back to the callers directory and return success */
   chdir(TmpBuf1);
 
+  vlimits_init_default (&limits);
+  vset_limits(domain, &limits);
   return(VA_SUCCESS);
 
 }
@@ -272,6 +276,7 @@
 
   /* return back to the callers directory */
   chdir(TmpBuf1);
+  vdel_limits(domain);
 
   return(VA_SUCCESS);
 
diff --exclude-from=exclude-vpop.diff.list -uN vpopmail-5.3.19/vpopmail.h vpopmail-vadmin-5.3.19/vpopmail.h
--- vpopmail-5.3.19/vpopmail.h	Mon Jan 27 17:29:15 2003
+++ vpopmail-vadmin-5.3.19/vpopmail.h	Thu Apr  3 11:04:05 2003
@@ -93,6 +93,7 @@
 #define V_USER3       0x400
 #define NO_SMTP       0x800
 #define QA_ADMIN     0x1000
+#define V_OVERRIDE   0x2000
 
 extern int OptimizeAddDomain;
 extern int NoMakeIndex;
