OK, I've finally found the time to work on the qmailadmin-limits API's for file and MySQL based storage. I've attached the patch for vpopmail 5.3.11, available at shupp.org.
I've augmented the previous implementation to add the extra features requested and pretty much implemented what I stated in the email last month. All the feedback from the last post was positive, so I went straight from that email. The API routines are as follows: int vget_limits(char *domain, struct vlimits *limits); int vset_limits(char *domain, struct vlimits *limits); int vdel_limits(char *domain); The data structure to manipulate is: /* * permissions for non-postmaster admins */ #define VLIMIT_DISABLE_CREATE 0x01 #define VLIMIT_DISABLE_MODIFY 0x02 #define VLIMIT_DISABLE_DELETE 0x04 #define VLIMIT_DISABLE_ALL (VLIMIT_DISABLE_CREATE|VLIMIT_DISABLE_MODIFY|VLIMIT_DISABLE_DELETE) #define VLIMIT_DISABLE_BITS 3 struct vlimits { /* max service limits */ int maxpopaccounts; int maxaliases; int maxforwards; int maxautoresponders; int maxmailinglists; /* quota & message count limits */ int diskquota; int maxmsgcount; int defaultquota; int defaultmaxmsgcount; /* the following are 0 (false) or 1 (true) */ short disable_pop; short disable_imap; short disable_dialup; short disable_passwordchanging; short disable_webmail; short disable_relay; short disable_smtp; /* the following permissions are for non-postmaster admins */ short perm_account; short perm_alias; short perm_forward; short perm_autoresponder; short perm_maillist; short perm_maillist_users; short perm_maillist_moderators; short perm_quota; short perm_defaultquota; }; The permissions are a bit field with create, modify and delete permissions. This just provides the API routines. I personally have a modifed vdelivermail and qmailadmin that impose per user and per domain quotas that implement real disk based quotas, not maildir quotas, therefore I did not include them. The API's need to be incorporated into several programs. A new program is needed to manipulate the values in this table/file. Programs to be augmented are at least vqadmin, qmailadmin, vdelivermail as well as the vpopmail library routines themselves to use the API rather than hard coded values for quotas. The API has the disk quota and the max message count values split apart as two distinct values (for both the domain and the defaults for new users). The reason behind this is to quickly use the value as needed from the API. When a "new user" is added to the system, a maildir compliant quota will be constructed into a string containing both numbers. I felt it was easier to combine 2 numbers into a string rather than split a string into 2 integers, so why not have it done for you already. I'll be digging through the latest vdelivermail (my patched binary is a 5.2 version) to see how to integrate the new API into that next. I'll also take a look at qmailadmin right after that. It looks like qmailadmin is going to be the biggest to change. There will be work required to integrate the "disable..." flags into the various programs such as imap-mail, webmail, pop access, etc. Thanks, Brian
Common subdirectories: vpopmail-5.3.11/attic and vpopmail-5.3.11.new/attic Common subdirectories: vpopmail-5.3.11/cdb and vpopmail-5.3.11.new/cdb Common subdirectories: vpopmail-5.3.11/contrib and vpopmail-5.3.11.new/contrib Common subdirectories: vpopmail-5.3.11/convert and vpopmail-5.3.11.new/convert Common subdirectories: vpopmail-5.3.11/doc and vpopmail-5.3.11.new/doc Common subdirectories: vpopmail-5.3.11/ldap and vpopmail-5.3.11.new/ldap Common subdirectories: vpopmail-5.3.11/oracle and vpopmail-5.3.11.new/oracle diff -rc vpopmail-5.3.11/vlimits.c vpopmail-5.3.11.new/vlimits.c *** vpopmail-5.3.11/vlimits.c Wed Oct 23 17:19:50 2002 --- vpopmail-5.3.11.new/vlimits.c Wed Nov 20 15:17:50 2002 *************** *** 38,52 **** limits->maxforwards = -1; limits->maxautoresponders = -1; limits->maxmailinglists = -1; limits->diskquota = 0; ! limits->defaultquota = ""; ! limits->disablepop = 0; ! limits->disableimap = 0; ! limits->disabledialup = 0; ! limits->disablepasswordchanging = 0; ! limits->disablerelay = 0; ! limits->disablesmtp = 0; ! limits->disablewebmail = 0; /* get filename */ vget_assign(domain, dir, sizeof(dir), &uid, &gid); --- 38,66 ---- limits->maxforwards = -1; limits->maxautoresponders = -1; limits->maxmailinglists = -1; + /* + already set to zero from memset() limits->diskquota = 0; ! limits->maxmsgcount = 0; ! limits->defaultquota = 0; ! limits->defaultmaxmsgcount = 0; ! limits->disable_pop = 0; ! limits->disable_imap = 0; ! limits->disable_dialup = 0; ! limits->disable_passwordchanging = 0; ! limits->disable_relay = 0; ! limits->disable_smtp = 0; ! limits->disable_webmail = 0; ! limits->perm_account = 0; ! limits->perm_alias = 0; ! limits->perm_forward = 0; ! limits->perm_autoresponder = 0; ! limits->perm_maillist = 0; ! limits->perm_maillist_users = 0; ! limits->perm_maillist_moderators = 0; ! limits->perm_quota = 0; ! limits->perm_defaultquota = 0; ! */ /* get filename */ vget_assign(domain, dir, sizeof(dir), &uid, &gid); *************** *** 54,139 **** /* open file */ if ((fs = fopen(dir, "r")) != NULL) { ! while (fgets(buf, sizeof(buf), fs) != NULL) { ! if ((s1 = strtok(buf, TOKENS)) == NULL) ! continue; ! if (!strcmp(s1, "maxpopaccounts")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->maxpopaccounts = atoi(s2); ! } ! if (!strcmp(s1, "maxaliases")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->maxaliases = atoi(s2); ! } ! if (!strcmp(s1, "maxforwards")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->maxforwards = atoi(s2); ! } ! if (!strcmp(s1, "maxautoresponders")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->maxautoresponders = atoi(s2); ! } ! if (!strcmp(s1, "maxmailinglists")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->maxmailinglists = atoi(s2); ! } ! if (!strcmp(s1, "quota")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->diskquota = atoi(s2); ! } ! if (!strcmp(s1, "default_quota")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->defaultquota = format_maildirquota(s2); ! } ! if (!strcmp(s1, "disable_pop")) { ! limits->disablepop = 1; ! } ! if (!strcmp(s1, "disable_imap")) { ! limits->disableimap = 1; ! } ! if (!strcmp(s1, "disable_dialup")) { ! limits->disabledialup = 1; ! } ! if (!strcmp(s1, "disable_password_changing")) { ! limits->disablepasswordchanging = 1; ! } ! if (!strcmp(s1, "disable_external_relay")) { ! limits->disablerelay = 1; ! } ! if (!strcmp(s1, "disable_smtp")) { ! limits->disablesmtp = 1; ! } ! if (!strcmp(s1, "disable_webmail")) { ! limits->disablewebmail = 1; ! } ! } ! fclose(fs); ! chown(dir,uid,gid); ! chmod(dir, S_IRUSR|S_IWUSR); } else { ! fprintf(stderr, "vlimits: failed to open limits file (%d): %s\n", errno, dir); ! return -1; } return 0; --- 68,213 ---- /* open file */ if ((fs = fopen(dir, "r")) != NULL) { ! while (fgets(buf, sizeof(buf), fs) != NULL) { ! if ((s1 = strtok(buf, TOKENS)) == NULL) ! continue; ! if (!strcmp(s1, "maxpopaccounts")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->maxpopaccounts = atoi(s2); ! } ! if (!strcmp(s1, "maxaliases")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->maxaliases = atoi(s2); ! } ! if (!strcmp(s1, "maxforwards")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->maxforwards = atoi(s2); ! } ! if (!strcmp(s1, "maxautoresponders")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->maxautoresponders = atoi(s2); ! } ! if (!strcmp(s1, "maxmailinglists")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->maxmailinglists = atoi(s2); ! } ! if (!strcmp(s1, "quota")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->diskquota = atoi(s2); ! } ! if (!strcmp(s1, "maxmsgcount")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->maxmsgcount = atoi(s2); ! } ! if (!strcmp(s1, "default_quota")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->defaultquota = atoi(s2); ! } ! if (!strcmp(s1, "default_maxmsgcount")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->defaultmaxmsgcount = atoi(s2); ! } ! if (!strcmp(s1, "disable_pop")) { ! limits->disable_pop = 1; ! } ! if (!strcmp(s1, "disable_imap")) { ! limits->disable_imap = 1; ! } ! if (!strcmp(s1, "disable_dialup")) { ! limits->disable_dialup = 1; ! } ! if (!strcmp(s1, "disable_password_changing")) { ! limits->disable_passwordchanging = 1; ! } ! if (!strcmp(s1, "disable_external_relay")) { ! limits->disable_relay = 1; ! } ! ! if (!strcmp(s1, "disable_smtp")) { ! limits->disable_smtp = 1; ! } ! ! if (!strcmp(s1, "disable_webmail")) { ! limits->disable_webmail = 1; ! } ! ! if (!strcmp(s1, "perm_account")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->perm_account = atoi(s2) & VLIMIT_DISABLE_ALL; ! } ! ! if (!strcmp(s1, "perm_alias")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->perm_alias = atoi(s2) & VLIMIT_DISABLE_ALL; ! } ! ! if (!strcmp(s1, "perm_forward")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->perm_forward = atoi(s2) & VLIMIT_DISABLE_ALL; ! } ! ! if (!strcmp(s1, "perm_autoresponder")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->perm_autoresponder = atoi(s2) & VLIMIT_DISABLE_ALL; ! } ! ! if (!strcmp(s1, "perm_maillist")) { ! unsigned long perm; ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! perm = atol(s2); ! limits->perm_maillist = perm & VLIMIT_DISABLE_ALL; ! perm >>= VLIMIT_DISABLE_BITS; ! limits->perm_maillist_users = perm & VLIMIT_DISABLE_ALL; ! perm >>= VLIMIT_DISABLE_BITS; ! limits->perm_maillist_moderators = perm & VLIMIT_DISABLE_ALL; ! } ! ! if (!strcmp(s1, "perm_quota")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->perm_quota = atoi(s2) & VLIMIT_DISABLE_ALL; ! } ! ! if (!strcmp(s1, "perm_defaultquota")) { ! if ((s2 = strtok(buf, TOKENS)) == NULL) ! continue; ! limits->perm_defaultquota = atoi(s2) & VLIMIT_DISABLE_ALL; ! } ! } ! fclose(fs); ! chown(dir,uid,gid); ! chmod(dir, S_IRUSR|S_IWUSR); } else { ! fprintf(stderr, "vlimits: failed to open limits file (%d): %s\n", errno, dir); ! return -1; } return 0; *************** *** 152,182 **** /* open file */ if ((fs = fopen(dir, "w+")) != NULL) { ! fprintf(fs, "maxpopaccounts: %d\n", limits->maxpopaccounts); ! fprintf(fs, "maxaliases: %d\n", limits->maxaliases); ! 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, "default_quota: %s\n", limits->defaultquota); ! if (limits->disablepop) ! fprintf(fs, "disable_pop\n"); ! if (limits->disableimap) ! fprintf(fs, "disable_imap\n"); ! if (limits->disabledialup) ! fprintf(fs, "disable_dialup\n"); ! if (limits->disablepasswordchanging) ! fprintf(fs, "disable_password_changing\n"); ! if (limits->disablewebmail) ! fprintf(fs, "disable_webmail\n"); ! if (limits->disablerelay) ! fprintf(fs, "disable_external_relay\n"); ! if (limits->disablesmtp) ! fprintf(fs, "disable_smtp\n"); ! fclose(fs); } else { ! fprintf(stderr, "vlimits: failed to open limits file (%d): %s\n", errno, dir); ! return -1; } return 0; --- 226,265 ---- /* open file */ if ((fs = fopen(dir, "w+")) != NULL) { ! fprintf(fs, "maxpopaccounts: %d\n", limits->maxpopaccounts); ! fprintf(fs, "maxaliases: %d\n", limits->maxaliases); ! 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); ! if (limits->disablepop) ! fprintf(fs, "disable_pop\n"); ! if (limits->disableimap) ! fprintf(fs, "disable_imap\n"); ! if (limits->disabledialup) ! fprintf(fs, "disable_dialup\n"); ! if (limits->disablepasswordchanging) ! fprintf(fs, "disable_password_changing\n"); ! if (limits->disablewebmail) ! fprintf(fs, "disable_webmail\n"); ! if (limits->disablerelay) ! fprintf(fs, "disable_external_relay\n"); ! if (limits->disablesmtp) ! fprintf(fs, "disable_smtp\n"); ! fprintf(fs, "perm_account: %d\n", limits->perm_account); ! fprintf(fs, "perm_alias: %d\n", limits->perm_alias); ! fprintf(fs, "perm_forward: %d\n", limits->perm_forward); ! fprintf(fs, "perm_autoresponder: %d\n", limits->perm_autoresponder); ! fprintf(fs, "perm_maillist: %ld\n", limits->perm_maillist); ! fprintf(fs, "perm_quota: %d\n", (limits->perm_quota)|(limits->perm_maillist_users<<VLIMIT_DISABLE_BITS)|(limits->perm_maillist_moderators<<(VLIMIT_DISABLE_BITS*2))); ! fprintf(fs, "perm_defaultquota: %d\n", limits->perm_defaultquota); ! fclose(fs); } else { ! fprintf(stderr, "vlimits: failed to open limits file (%d): %s\n", errno, dir); ! return -1; } return 0; *************** *** 195,198 **** } #endif - --- 278,280 ---- diff -rc vpopmail-5.3.11/vlimits.h vpopmail-5.3.11.new/vlimits.h *** vpopmail-5.3.11/vlimits.h Wed Oct 23 17:18:58 2002 --- vpopmail-5.3.11.new/vlimits.h Wed Nov 20 15:17:39 2002 *************** *** 7,31 **** #ifndef VPOPMAIL_VLIMITS_H #define VPOPMAIL_VLIMITS_H struct vlimits { int maxpopaccounts; int maxaliases; int maxforwards; int maxautoresponders; int maxmailinglists; int diskquota; ! char *defaultquota; ! short disablepop; ! short disableimap; ! short disabledialup; ! short disablepasswordchanging; ! short disablewebmail; ! short disablerelay; ! short disablesmtp; }; ! int vget_limits(char * domain, struct vlimits * limits); ! int vset_limits(char * domain, struct vlimits * limits); ! int vdel_limits(char * domain); #endif --- 7,59 ---- #ifndef VPOPMAIL_VLIMITS_H #define VPOPMAIL_VLIMITS_H + /* + * permissions for non-postmaster admins + */ + #define VLIMIT_DISABLE_CREATE 0x01 + #define VLIMIT_DISABLE_MODIFY 0x02 + #define VLIMIT_DISABLE_DELETE 0x04 + + #define VLIMIT_DISABLE_ALL +(VLIMIT_DISABLE_CREATE|VLIMIT_DISABLE_MODIFY|VLIMIT_DISABLE_DELETE) + #define VLIMIT_DISABLE_BITS 3 + struct vlimits { + /* max service limits */ int maxpopaccounts; int maxaliases; int maxforwards; int maxautoresponders; int maxmailinglists; + + /* quota & message count limits */ int diskquota; ! int maxmsgcount; ! int defaultquota; ! int defaultmaxmsgcount; ! ! /* the following are 0 (false) or 1 (true) */ ! short disable_pop; ! short disable_imap; ! short disable_dialup; ! short disable_passwordchanging; ! short disable_webmail; ! short disable_relay; ! short disable_smtp; ! ! /* the following permissions are for non-postmaster admins */ ! short perm_account; ! short perm_alias; ! short perm_forward; ! short perm_autoresponder; ! short perm_maillist; ! short perm_maillist_users; ! short perm_maillist_moderators; ! short perm_quota; ! short perm_defaultquota; }; ! 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); #endif diff -rc vpopmail-5.3.11/vmysql.c vpopmail-5.3.11.new/vmysql.c *** vpopmail-5.3.11/vmysql.c Mon Oct 21 14:59:13 2002 --- vpopmail-5.3.11.new/vmysql.c Wed Nov 20 15:18:11 2002 *************** *** 223,229 **** #ifndef MANY_DOMAINS tmpstr = vauth_munch_domain( domain ); #else ! tmpstr = MYSQL_DEFAULT_TABLE; #endif snprintf(SqlBufUpdate,SQL_BUF_SIZE, --- 223,229 ---- #ifndef MANY_DOMAINS tmpstr = vauth_munch_domain( domain ); #else ! tmpstr = MYSQL_DEFAULT_TABLE; #endif snprintf(SqlBufUpdate,SQL_BUF_SIZE, *************** *** 910,916 **** res_read = NULL; if (mysql_query(&mysql_read,SqlBufRead)) { ! vcreate_ip_map_table(); if (mysql_query(&mysql_read,SqlBufRead)) { return(0); } --- 910,916 ---- res_read = NULL; if (mysql_query(&mysql_read,SqlBufRead)) { ! vcreate_ip_map_table(); if (mysql_query(&mysql_read,SqlBufRead)) { return(0); } *************** *** 1089,1099 **** "delete from dir_control where domain = \"%s\"", domain); if (mysql_query(&mysql_update,SqlBufUpdate)) { ! vcreate_dir_control(domain); ! if (mysql_query(&mysql_update,SqlBufUpdate)) { printf("vmysql: sql error[e]: %s\n", mysql_error(&mysql_update)); ! return(-1); ! } } res_update = mysql_store_result(&mysql_update); mysql_free_result(res_update); --- 1089,1099 ---- "delete from dir_control where domain = \"%s\"", domain); if (mysql_query(&mysql_update,SqlBufUpdate)) { ! vcreate_dir_control(domain); ! if (mysql_query(&mysql_update,SqlBufUpdate)) { printf("vmysql: sql error[e]: %s\n", mysql_error(&mysql_update)); ! return(-1); ! } } res_update = mysql_store_result(&mysql_update); mysql_free_result(res_update); *************** *** 1398,1404 **** #ifdef ENABLE_MYSQL_LIMITS void vcreate_limits_table() { ! if ( vauth_open_update() != 0 ) return; snprintf( SqlBufCreate, SQL_BUF_SIZE, "CREATE TABLE limits ( %s )", LIMITS_TABLE_LAYOUT); --- 1398,1405 ---- #ifdef ENABLE_MYSQL_LIMITS void vcreate_limits_table() { ! if (vauth_open_update() != 0) ! return; snprintf( SqlBufCreate, SQL_BUF_SIZE, "CREATE TABLE limits ( %s )", LIMITS_TABLE_LAYOUT); *************** *** 1410,1431 **** mysql_free_result(res_update); } ! int vget_limits( char *domain, struct vlimits *limits ) { ! int err; ! /* if we can not connect, set the verrori value */ ! if ( (err=vauth_open_read()) != 0 ) { ! return(-1); ! } ! ! snprintf( SqlBufRead, SQL_BUF_SIZE, "SELECT maxpopaccounts, maxaliases, " ! "maxforwards, maxautoresponders, maxmailinglists, diskquota, " ! "defaultquota, disablepop, disableimap, disabledialup, " ! "disablepasswordchanging, disablewebmail, disablerelay \n" "FROM limits \n" ! "WHERE domain = '%s'", domain); if (mysql_query(&mysql_read,SqlBufRead)) { vcreate_limits_table(); if (mysql_query(&mysql_read,SqlBufRead)) { --- 1411,1432 ---- mysql_free_result(res_update); } ! int vget_limits(const char *domain, struct vlimits *limits) { ! if (vauth_open_read() != 0) ! return(-1); ! snprintf(SqlBufRead, SQL_BUF_SIZE, "SELECT maxpopaccounts, maxaliases, " ! "maxforwards, maxautoresponders, maxmailinglists, diskquota, " ! "maxmsgcount, defaultquota, defaultmaxmsgcount, " ! "disable_pop, disable_imap, disable_dialup, " ! "disable_passwordchanging, disable_webmail, disable_relay, " ! "disable_smtp, perm_account, perm_alias, perm_forward, " ! "perm_autoresponder, perm_maillist, perm_quota, perm_defaultquota \n" "FROM limits \n" ! "WHERE domain = '%s'", domain); + if (mysql_query(&mysql_read,SqlBufRead)) { vcreate_limits_table(); if (mysql_query(&mysql_read,SqlBufRead)) { *************** *** 1434,1462 **** } } if (!(res_read = mysql_store_result(&mysql_read))) { ! fprintf(stderr, "vmysql: store result failed\n"); ! return -1; } if (mysql_num_rows(res_read) == 0) { ! fprintf(stderr, "vnysql: can't find limits for domain '%s'\n", domain); ! return -1; } if ((row = mysql_fetch_row(res_read)) != NULL) { ! limits->maxpopaccounts = atoi(row[0]); ! limits->maxaliases = atoi(row[1]); ! limits->maxforwards = atoi(row[2]); ! limits->maxautoresponders = atoi(row[3]); ! limits->maxmailinglists = atoi(row[4]); ! limits->diskquota = atoi(row[5]); ! limits->defaultquota = atoi(row[6]); ! limits->disablepop = atoi(row[7]); ! limits->disableimap = atoi(row[8]); ! limits->disabledialup = atoi(row[9]); ! limits->disablepasswordchanging = atoi(row[10]); ! limits->disablewebmail = atoi(row[11]); ! limits->disablerelay = atoi(row[12]); } mysql_free_result(res_read); --- 1435,1479 ---- } } if (!(res_read = mysql_store_result(&mysql_read))) { ! fprintf(stderr, "vmysql: store result failed\n"); ! return -1; } if (mysql_num_rows(res_read) == 0) { ! fprintf(stderr, "vnysql: can't find limits for domain '%s'\n", domain); ! return -1; } if ((row = mysql_fetch_row(res_read)) != NULL) { ! int perm = atol(row[20]); ! ! limits->maxpopaccounts = atoi(row[0]); ! limits->maxaliases = atoi(row[1]); ! 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->disable_pop = atoi(row[9]); ! limits->disable_imap = atoi(row[10]); ! limits->disable_dialup = atoi(row[11]); ! limits->disable_passwordchanging = atoi(row[12]); ! limits->disable_webmail = atoi(row[13]); ! limits->disable_relay = atoi(row[14]); ! limits->disable_smtp = atoi(row[15]); ! limits->perm_account = atoi(row[16]); ! limits->perm_alias = atoi(row[17]); ! limits->perm_forward = atoi(row[18]); ! limits->perm_autoresponder = atoi(row[19]); ! limits->perm_maillist = perm & VLIMIT_DISABLE_ALL; ! perm >>= VLIMIT_DISABLE_BITS; ! 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[21]); ! limits->perm_defaultquota = atoi(row[22]); } mysql_free_result(res_read); *************** *** 1463,1498 **** return 0; } ! int vdel_limits( char *domain ) { ! snprintf( SqlBufUpdate, SQL_BUF_SIZE, "DELETE FROM limits WHERE domain = \"%s\"", ! domain); ! ! if (mysql_query(&mysql_update,SqlBufUpdate)) { return(-1); - } - res_update = mysql_store_result(&mysql_update); - mysql_free_result(res_update); - return 0; - } ! int vset_limits( char *domain, struct vlimits *limits ) ! { ! int err; ! ! /* if we can not connect, set the verrori value */ ! if ( (err=vauth_open_update()) != 0 ) { ! return(-1); ! } ! ! snprintf( SqlBufUpdate, SQL_BUF_SIZE, "REPLACE INTO limits ( " ! "domain, maxpopaccounts, maxaliases, " ! "maxforwards, maxautoresponders, maxmailinglists, diskquota, " ! "defaultquota, disablepop, disableimap, disabledialup, " ! "disablepasswordchanging, disablewebmail, disablerelay ) \n" "VALUES \n" ! "('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", ! domain, limits->maxpopaccounts, limits->maxaliases, limits->maxforwards, --- 1480,1501 ---- return 0; } ! int vset_limits(const char *domain, const struct vlimits *limits) { ! if (vauth_open_update() != 0) return(-1); ! snprintf(SqlBufUpdate, SQL_BUF_SIZE, "REPLACE INTO limits (" ! "domain, maxpopaccounts, maxaliases, " ! "maxforwards, maxautoresponders, maxmailinglists, " ! "diskquota, maxmsgcount, defaultquota, defaultmaxmsgcount, " ! "disable_pop, disable_imap, disable_dialup, " ! "disable_passwordchanging, disable_webmail, disable_relay, " ! "disable_smtp, perm_account, perm_alias, perm_forward, " ! "perm_autoresponder, perm_maillist, perm_quota, perm_defaultquota) \n" "VALUES \n" ! "('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", ! domain, limits->maxpopaccounts, limits->maxaliases, limits->maxforwards, *************** *** 1499,1511 **** limits->maxautoresponders, limits->maxmailinglists, limits->diskquota, limits->defaultquota, ! limits->disablepop, ! limits->disableimap, ! limits->disabledialup, ! limits->disablepasswordchanging, ! limits->disablewebmail, ! limits->disablerelay); if (mysql_query(&mysql_update,SqlBufUpdate)) { vcreate_limits_table(); --- 1502,1526 ---- limits->maxautoresponders, limits->maxmailinglists, 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->perm_account, ! limits->perm_alias, ! limits->perm_forward, ! limits->perm_autoresponder, ! (limits->perm_maillist | ! (limits->perm_maillist_users << VLIMIT_DISABLE_BITS) | ! (limits->perm_maillist_moderators << (VLIMIT_DISABLE_BITS * 2))), ! limits->perm_quota, ! limits->perm_defaultquota); if (mysql_query(&mysql_update,SqlBufUpdate)) { vcreate_limits_table(); *************** *** 1515,1526 **** } } if (!(res_update = mysql_store_result(&mysql_update))) { ! fprintf(stderr, "vmysql: store result failed\n"); ! return -1; } mysql_free_result(res_update); return 0; } #endif --- 1530,1553 ---- } } if (!(res_update = mysql_store_result(&mysql_update))) { ! fprintf(stderr, "vmysql: store result failed\n"); ! return -1; } mysql_free_result(res_update); return 0; } + + int vdel_limits(const char *domain) + { + snprintf(SqlBufUpdate, SQL_BUF_SIZE, "DELETE FROM limits WHERE domain = \"%s\"", +domain); + + if (mysql_query(&mysql_update,SqlBufUpdate)) + return(-1); + res_update = mysql_store_result(&mysql_update); + mysql_free_result(res_update); + return 0; + } + #endif diff -rc vpopmail-5.3.11/vmysql.h vpopmail-5.3.11.new/vmysql.h *** vpopmail-5.3.11/vmysql.h Wed Oct 23 15:50:10 2002 --- vpopmail-5.3.11.new/vmysql.h Tue Nov 19 23:18:09 2002 *************** *** 252,269 **** #ifdef ENABLE_MYSQL_LIMITS #define LIMITS_TABLE_LAYOUT "domain CHAR(64) PRIMARY KEY, \ ! maxpopaccounts INT(10) NOT NULL DEFAULT -1, \ ! maxaliases INT(10) NOT NULL DEFAULT -1, \ ! 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, \ ! defaultquota INT(12) NOT NULL DEFAULT 0, \ ! disablepop TINYINT(1) NOT NULL DEFAULT 0, \ ! disableimap TINYINT(1) NOT NULL DEFAULT 0, \ ! disabledialup TINYINT(1) NOT NULL DEFAULT 0, \ ! disablepasswordchanging TINYINT(1) NOT NULL DEFAULT 0, \ ! disablewebmail TINYINT(1) NOT NULL DEFAULT 0, \ ! disablerelay TINYINT(1) NOT NULL DEFAULT 0, \ ! disablesmtp TINYINT(1) NOT NULL DEFAULT 0" #endif --- 252,279 ---- #ifdef ENABLE_MYSQL_LIMITS #define LIMITS_TABLE_LAYOUT "domain CHAR(64) PRIMARY KEY, \ ! maxpopaccounts INT(10) NOT NULL DEFAULT -1, \ ! maxaliases INT(10) NOT NULL DEFAULT -1, \ ! 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, \ ! disable_pop TINYINT(1) NOT NULL DEFAULT 0, \ ! disable_imap TINYINT(1) NOT NULL DEFAULT 0, \ ! disable_dialup TINYINT(1) NOT NULL DEFAULT 0, \ ! disable_passwordchanging TINYINT(1) NOT NULL DEFAULT 0, \ ! disable_webmail TINYINT(1) NOT NULL DEFAULT 0, \ ! disable_relay TINYINT(1) NOT NULL DEFAULT 0, \ ! disable_smtp TINYINT(1) NOT NULL DEFAULT 0, \ ! perm_account TINYINT(2) NOT NULL DEFAULT 0, \ ! perm_alias TINYINT(2) NOT NULL DEFAULT 0, \ ! perm_forward TINYINT(2) NOT NULL DEFAULT 0, \ ! perm_autoresponder TINYINT(2) NOT NULL DEFAULT 0, \ ! perm_maillist TINYINT(4) NOT NULL DEFAULT 0, \ ! perm_quota TINYINT(2) NOT NULL DEFAULT 0, \ ! perm_defaultquota TINYINT(2) NOT NULL DEFAULT 0" #endif + diff -rc vpopmail-5.3.11/vpopmail.c vpopmail-5.3.11.new/vpopmail.c *** vpopmail-5.3.11/vpopmail.c Wed Oct 23 16:01:40 2002 --- vpopmail-5.3.11.new/vpopmail.c Wed Nov 20 16:11:52 2002 *************** *** 574,640 **** int add_domain_assign( char *alias_domain, char *real_domain, char *dir, uid_t uid, gid_t gid ) { ! FILE *fs1 = NULL; ! struct stat mystat; ! static char tmpstr1[MAX_BUFF]; ! static char tmpstr2[MAX_BUFF]; ! static char tmpstr3[MAX_BUFF]; ! snprintf(tmpstr1, MAX_BUFF, "%s/users/assign", QMAILDIR); ! /* stat assign file, if it's not there create one */ ! if ( stat(tmpstr1,&mystat) != 0 ) { ! /* put a . on one line by itself */ ! if ( (fs1 = fopen(tmpstr1, "w+"))==NULL ) { ! printf("could not open assign file\n"); ! return(-1); } - fputs(".\n", fs1); - fclose(fs1); - } ! snprintf(tmpstr3, MAX_BUFF, "+%s-:%s:%lu:%lu:%s:-::", alias_domain, real_domain, (long unsigned)uid, (long unsigned)gid, dir); ! /* update the file and add the above line and remove duplicates */ ! update_file(tmpstr1, tmpstr3); ! /* set the mode in case we are running with a strange mask */ ! chmod(tmpstr1, VPOPMAIL_QMAIL_MODE ); ! /* compile the assign file */ ! if ( OptimizeAddDomain == 0 ) update_newu(); ! /* If we have more than 50 domains in rcpthosts ! * make a morercpthosts and compile it ! */ ! if ( count_rcpthosts() >= 50 ) { ! snprintf(tmpstr1, MAX_BUFF, "%s/control/morercpthosts", QMAILDIR); ! update_file(tmpstr1, alias_domain); ! snprintf(tmpstr1, MAX_BUFF, "%s/control/morercpthosts", QMAILDIR); chmod(tmpstr1, VPOPMAIL_QMAIL_MODE ); - if ( OptimizeAddDomain == 0 ) compile_morercpthosts(); ! /* or just add to rcpthosts */ ! } else { ! snprintf(tmpstr1, MAX_BUFF, "%s/control/rcpthosts", QMAILDIR); ! update_file(tmpstr1, alias_domain); ! snprintf(tmpstr1, MAX_BUFF, "%s/control/rcpthosts", QMAILDIR); chmod(tmpstr1, VPOPMAIL_QMAIL_MODE ); - } - - /* Add to virtualdomains file and remove duplicates and set mode */ - snprintf(tmpstr1, MAX_BUFF, "%s/control/virtualdomains", QMAILDIR ); - snprintf(tmpstr2, MAX_BUFF, "%s:%s", alias_domain, alias_domain ); - update_file(tmpstr1, tmpstr2); - chmod(tmpstr1, VPOPMAIL_QMAIL_MODE ); ! /* make sure it's not in locals and set mode */ ! snprintf(tmpstr1, MAX_BUFF, "%s/control/locals", QMAILDIR); ! remove_line( alias_domain, tmpstr1); ! chmod(tmpstr1, VPOPMAIL_QMAIL_MODE ); ! ! return(0); } /* --- 574,642 ---- int add_domain_assign( char *alias_domain, char *real_domain, char *dir, uid_t uid, gid_t gid ) { ! FILE *fs1 = NULL; ! struct stat mystat; ! static char tmpstr1[MAX_BUFF]; ! static char tmpstr2[MAX_BUFF]; ! static char tmpstr3[MAX_BUFF]; ! snprintf(tmpstr1, MAX_BUFF, "%s/users/assign", QMAILDIR); ! /* stat assign file, if it's not there create one */ ! if ( stat(tmpstr1,&mystat) != 0 ) { ! /* put a . on one line by itself */ ! if ( (fs1 = fopen(tmpstr1, "w+"))==NULL ) { ! printf("could not open assign file\n"); ! return(-1); ! } ! fputs(".\n", fs1); ! fclose(fs1); } ! snprintf(tmpstr3, MAX_BUFF, "+%s-:%s:%lu:%lu:%s:-::", alias_domain, real_domain, (long unsigned)uid, (long unsigned)gid, dir); ! /* update the file and add the above line and remove duplicates */ ! update_file(tmpstr1, tmpstr3); ! /* set the mode in case we are running with a strange mask */ ! chmod(tmpstr1, VPOPMAIL_QMAIL_MODE ); ! /* compile the assign file */ ! if ( OptimizeAddDomain == 0 ) ! update_newu(); ! /* If we have more than 50 domains in rcpthosts ! * make a morercpthosts and compile it ! */ ! if ( count_rcpthosts() >= 50 ) { ! snprintf(tmpstr1, MAX_BUFF, "%s/control/morercpthosts", QMAILDIR); ! update_file(tmpstr1, alias_domain); ! snprintf(tmpstr1, MAX_BUFF, "%s/control/morercpthosts", QMAILDIR); ! chmod(tmpstr1, VPOPMAIL_QMAIL_MODE ); ! if ( OptimizeAddDomain == 0 ) ! compile_morercpthosts(); ! ! /* or just add to rcpthosts */ ! } else { ! snprintf(tmpstr1, MAX_BUFF, "%s/control/rcpthosts", QMAILDIR); ! update_file(tmpstr1, alias_domain); ! snprintf(tmpstr1, MAX_BUFF, "%s/control/rcpthosts", QMAILDIR); ! chmod(tmpstr1, VPOPMAIL_QMAIL_MODE ); ! } ! ! /* Add to virtualdomains file and remove duplicates and set mode */ ! snprintf(tmpstr1, MAX_BUFF, "%s/control/virtualdomains", QMAILDIR ); ! snprintf(tmpstr2, MAX_BUFF, "%s:%s", alias_domain, alias_domain ); ! update_file(tmpstr1, tmpstr2); chmod(tmpstr1, VPOPMAIL_QMAIL_MODE ); ! /* make sure it's not in locals and set mode */ ! snprintf(tmpstr1, MAX_BUFF, "%s/control/locals", QMAILDIR); ! remove_line( alias_domain, tmpstr1); chmod(tmpstr1, VPOPMAIL_QMAIL_MODE ); ! return(0); } /* *************** *** 641,677 **** * delete a domain from the control files */ int del_control( domain ) ! char *domain; { ! static char tmpbuf1[MAX_BUFF]; ! static char tmpbuf2[MAX_BUFF]; ! snprintf(tmpbuf1, MAX_BUFF, "%s/control/rcpthosts", QMAILDIR); ! if ( remove_line( domain, tmpbuf1) == 0 ) { ! snprintf(tmpbuf1, MAX_BUFF, "%s/control/morercpthosts", QMAILDIR); ! if ( remove_line( domain, tmpbuf1) == 1 ) { ! struct stat statbuf; ! if ( stat( tmpbuf1, &statbuf) == 0 ) { ! if ( statbuf.st_size == 0 ) { ! unlink(tmpbuf1); ! strncat(tmpbuf1, ".cdb", MAX_BUFF); ! unlink(tmpbuf1); ! } else { ! compile_morercpthosts(); ! chmod(tmpbuf1, VPOPMAIL_QMAIL_MODE ); } ! } } - } else { - chmod(tmpbuf1, VPOPMAIL_QMAIL_MODE ); - } ! snprintf(tmpbuf1, MAX_BUFF, "%s:%s", domain, domain); ! snprintf(tmpbuf2, MAX_BUFF, "%s/control/virtualdomains", QMAILDIR); ! remove_line( tmpbuf1, tmpbuf2); ! chmod(tmpbuf2, VPOPMAIL_QMAIL_MODE ); ! return(0); } /* --- 643,679 ---- * delete a domain from the control files */ int del_control( domain ) ! char *domain; { ! static char tmpbuf1[MAX_BUFF]; ! static char tmpbuf2[MAX_BUFF]; ! snprintf(tmpbuf1, MAX_BUFF, "%s/control/rcpthosts", QMAILDIR); ! if ( remove_line( domain, tmpbuf1) == 0 ) { ! snprintf(tmpbuf1, MAX_BUFF, "%s/control/morercpthosts", QMAILDIR); ! if ( remove_line( domain, tmpbuf1) == 1 ) { ! struct stat statbuf; ! if ( stat( tmpbuf1, &statbuf) == 0 ) { ! if ( statbuf.st_size == 0 ) { ! unlink(tmpbuf1); ! strncat(tmpbuf1, ".cdb", MAX_BUFF); ! unlink(tmpbuf1); ! } else { ! compile_morercpthosts(); ! chmod(tmpbuf1, VPOPMAIL_QMAIL_MODE ); ! } ! } } ! } else { ! chmod(tmpbuf1, VPOPMAIL_QMAIL_MODE ); } ! snprintf(tmpbuf1, MAX_BUFF, "%s:%s", domain, domain); ! snprintf(tmpbuf2, MAX_BUFF, "%s/control/virtualdomains", QMAILDIR); ! remove_line( tmpbuf1, tmpbuf2); ! chmod(tmpbuf2, VPOPMAIL_QMAIL_MODE ); ! return(0); } /* Common subdirectories: vpopmail-5.3.11/doc/doc_html and vpopmail-5.3.11.new/doc/doc_html Common subdirectories: vpopmail-5.3.11/doc/man_html and vpopmail-5.3.11.new/doc/man_html