v. 2021.02.26 Combined patch for vpopmail-5.4.33 by Roberto Puzzanghera More info here https://notes.sagredo.eu ================================================================================================== == This patch puts together * A patch to make vpopmail store domain aliases to MySQL. This gets dovecot's sql auth driver aware of domain aliases, provided that you modify the sql query accordingly. More info here https://notes.sagredo.eu/en/qmail-notes-185/dovecot-vpopmail-auth-driver-removal-241.html * A patch which makes vpopmail to copy your favourite delivery agent (stored in QMAILDIR/control/defauldelivery) into the .qmail-default file of any newly created domains, overriding the default vpopmail's behaiviour, where vpopmail copies its delivery agent vdelivermail. configure --enable-defaultdelivery (default is OFF) to enable this functionality. * A patch which gets vpopmail to compile with gcc-10 == Settings for sql-aliasdomains feature * An autoreconf is needed as I modified the original configure.in and Makefile.am files autoreconf -f -i ./configure \ --enable-auth-module=mysql \ --enable-sql-aliasdomains (default) * Adjust your dovecot-sql.conf.ext in order to auth both real and alias domains: (more info here https://notes.sagredo.eu/en/qmail-notes-185/installing-dovecot-and-sieve-on-a-vpopmail-qmail-server-28.html#sql) password_query = SELECT \ CONCAT(vpopmail.pw_name, '@', vpopmail.pw_domain) AS user, \ vpopmail.pw_passwd AS password, \ vpopmail.pw_dir as userdb_home, \ 89 AS userdb_uid, \ 89 AS userdb_gid \ FROM `vpopmail` \ LEFT JOIN aliasdomains \ ON aliasdomains.alias='%d' \ WHERE \ vpopmail.pw_name = '%n' \ AND \ (vpopmail.pw_domain = aliasdomains.domain \ OR \ vpopmail.pw_domain = '%d') user_query = \ SELECT \ vpopmail.pw_dir AS home, \ 89 AS uid, \ 89 AS gid, \ CONCAT('*:bytes=', REPLACE(SUBSTRING_INDEX(vpopmail.pw_shell, 'S', 1), 'NOQUOTA', '0')) AS quota_rule \ FROM vpopmail \ LEFT JOIN aliasdomains \ ON aliasdomains.alias='%d' \ WHERE \ vpopmail.pw_name = '%n' \ AND \ (vpopmail.pw_domain = aliasdomains.domain \ OR \ vpopmail.pw_domain = '%d') AND \ ('%a'!='995' or !(vpopmail.pw_gid & 2)) \ AND \ ('%r'!='localhost' or !(vpopmail.pw_gid & 4)) \ AND \ ('%r'='localhost' or '%a'!='993' or !(vpopmail.pw_gid & 8)) * Create/delete aliasdomains in the usual way with vaddaliasdomain/vdeldomain * If you already have aliasdomains, you have to populate the dbtable. You can use my "vsavealiasdomains" program to save all your domain aliases to MySQL. Type "vsavealiasadomains -A" to save all your domain aliases to MySQL. Type "vsavealiasadomains -h" for more options. =============================================================================================== diff -ruN ../vpopmail-5.4.33-original/Makefile.am vpopmail-5.4.33/Makefile.am --- ../vpopmail-5.4.33-original/Makefile.am 2011-02-28 18:00:45.000000000 +0100 +++ vpopmail-5.4.33/Makefile.am 2021-02-15 10:53:18.767309165 +0100 @@ -31,7 +31,7 @@ vdeldomain vpasswd vadduser vdeluser vaddaliasdomain vsetuserquota \ vpopbull vdeloldusers vmoduser valias vuserinfo vmkpasswd vipmap \ vdominfo vconvert vkill vmoddomlimits vchangepw dotqmail2valias \ - vpopmaild vlist authvchkpw vusagec + vpopmaild vlist authvchkpw vusagec vsavealiasdomains vusagec_SOURCES = vusagec.c client.c conf.c ippp.c vusagec_LDADD = libvpopmail.a @auth_libs@ @@ -114,6 +114,9 @@ vmoddomlimits_SOURCES = vmoddomlimits.c vmoddomlimits_LDADD = libvpopmail.a @auth_libs@ +vsavealiasdomains_SOURCES = vsavealiasdomains.c +vsavealiasdomains_LDADD = libvpopmail.a @auth_libs@ + DEFS=-I. @auth_inc@ install: install-recursive vusage-msg diff -ruN ../vpopmail-5.4.33-original/configure.in vpopmail-5.4.33/configure.in --- ../vpopmail-5.4.33-original/configure.in 2011-02-28 18:00:45.000000000 +0100 +++ vpopmail-5.4.33/configure.in 2021-02-26 15:44:47.048941684 +0100 @@ -1454,6 +1454,30 @@ ;; esac + +#---------------------------------------------------------------------- + +AC_MSG_CHECKING(whether defaultdelivery is enabled) +AC_ARG_ENABLE(defaultdelivery, + [ --enable-defaultdelivery Copy the content of control/defaultdelivery to .qmail-default on domain creation.], + DEFAULT_DELIVERY=$enableval, + [ + DEFAULT_DELIVERY=n + ] +) + +case $DEFAULT_DELIVERY in + 1*|y*|Y*) + AC_MSG_RESULT(yes) + DEFAULT_DELIVERY=1 + AC_DEFINE_UNQUOTED(DEFAULT_DELIVERY,$DEFAULT_DELIVERY,"") + ;; + *) + AC_MSG_RESULT(no) + ;; +esac + + #---------------------------------------------------------------------- AC_MSG_CHECKING(whether many-domains is enabled) @@ -1484,6 +1508,40 @@ #---------------------------------------------------------------------- +AC_MSG_CHECKING(whether sql-aliasdomains is enabled) +AC_ARG_ENABLE(sql-aliasdomains, + [ --enable-sql-aliasdomains Creates a table for alias/domain pairs. Only valid for MySQL auth module.], + SQL_ALIASDOMAINS=$enableval, + [ + if [[ "$AUTH_MODULE" != "mysql" ]]; + then + SQL_ALIASDOMAINS=n + else + SQL_ALIASDOMAINS=y + AC_DEFINE_UNQUOTED(SQL_ALIASDOMAINS,$SQL_ALIASDOMAINS,"") + fi + ] +) + +case $SQL_ALIASDOMAINS in + 1*|y*|Y*) + AC_MSG_RESULT(yes) + if [[ "$AUTH_MODULE" != "mysql" ]]; + then + AC_MSG_ERROR(sql-aliasdomains is only supported in the MySQL authentication module.) + else + SQL_ALIASDOMAINS=1 + AC_DEFINE_UNQUOTED(SQL_ALIASDOMAINS,$SQL_ALIASDOMAINS,"") + fi + ;; + *) + AC_MSG_RESULT(no) + SQL_ALIASDOMAINS=0 + ;; +esac + +#---------------------------------------------------------------------- + AC_MSG_CHECKING(whether any discontinued --enable commands have been used) AC_ARG_ENABLE(mysql-logging, [], @@ -1838,6 +1896,16 @@ esac +case $DEFAULT_DELIVERY in + 1*|y*|Y*) + echo " defaultdelivery = ON --enable-defaultdelivery" + ;; + *) + echo " defaultdelivery = OFF --disable-defaultdelivery (default)" + ;; +esac + + if test "$USE_SQL" = 1 then if test "$MANY_DOMAINS" = 1 @@ -1848,6 +1916,16 @@ fi fi +if [[ "$AUTH_MODULE" == "mysql" ]]; +then + if test "$SQL_ALIASDOMAINS" = 1 + then + echo "SQL domain aliases = ON domain aliases saved to MySQL --enable-sql-aliasdomains (default)" + else + echo "SQL domain aliases = OFF domain aliases NOT saved to MySQL --disable-sql-aliasdomains" + fi +fi + case $ENABLE_SPAMASSASSIN in 1*|y*|Y*) echo " spamassassin = ON --enable-spamassassin" diff -ruN ../vpopmail-5.4.33-original/doc/README.defaultdelivery vpopmail-5.4.33/doc/README.defaultdelivery --- ../vpopmail-5.4.33-original/doc/README.defaultdelivery 1970-01-01 01:00:00.000000000 +0100 +++ vpopmail-5.4.33/doc/README.defaultdelivery 2021-02-26 21:31:30.885855645 +0100 @@ -0,0 +1,17 @@ +v. 2021.02.26 +vpopmail-defaultdelivery patch for vpopmail-5.4.33 by Roberto Puzzanghera +More info here https://notes.sagredo.eu/en/qmail-notes-185/installing-and-configuring-vpopmail-81.html + +================================================================================================================== + +Normally vpopmail copies its delivery agent vdelivermail into the .qmail-default file of newly created domains. +This patch makes vpopmail to copy your favourite delivery agent, stored in QMAILDIR/control/defauldelivery. + +== Settings + +An autoreconf is needed as I modified the original configure.in and Makefile.am files. + +Configure as follows: + +autoreconf -f -i +./configure --enable-defaultdelivery (default OFF) diff -ruN ../vpopmail-5.4.33-original/doc/README.sql-aliasdomains vpopmail-5.4.33/doc/README.sql-aliasdomains --- ../vpopmail-5.4.33-original/doc/README.sql-aliasdomains 1970-01-01 01:00:00.000000000 +0100 +++ vpopmail-5.4.33/doc/README.sql-aliasdomains 2021-02-16 09:29:25.811171140 +0100 @@ -0,0 +1,62 @@ +v. 2021.02.15 +sql-aliasdomains patch for vpopmail-5.4.33 by Roberto Puzzanghera +More info here https://notes.sagredo.eu/en/qmail-notes-185/dovecot-vpopmail-auth-driver-removal-241.html + +================================================================================================================== + +* A patch to make vpopmail store domain aliases to MySQL. This gets dovecot's sql auth driver + aware of domain aliases, provided that you modify the sql query accordingly. + More info here https://notes.sagredo.eu/en/qmail-notes-185/dovecot-vpopmail-auth-driver-removal-241.html + +* A patch which gets vpopmail to compile with gcc-10 + +== Settings + +* An autoreconf is needed as I modified the original configure.in and Makefile.am files + + autoreconf -f -i + ./configure \ + --enable-auth-module=mysql \ + --enable-sql-aliasdomains (default) + +* Adjust your dovecot-sql.conf.ext in order to auth both real and alias domains: + (more info here https://notes.sagredo.eu/en/qmail-notes-185/installing-dovecot-and-sieve-on-a-vpopmail-qmail-server-28.html#sql) + +password_query = \ + SELECT \ + CONCAT(vpopmail.pw_name, '@', vpopmail.pw_domain) AS user, \ + vpopmail.pw_passwd AS password, \ + vpopmail.pw_dir AS userdb_home, \ + 89 AS userdb_uid, \ + 89 AS userdb_gid, \ + CONCAT('*:bytes=', REPLACE(SUBSTRING_INDEX(vpopmail.pw_shell, 'S', 1), 'NOQUOTA', '0')) AS userdb_quota_rule \ + FROM `vpopmail` \ + LEFT JOIN aliasdomains ON aliasdomains.alias='%d' \ + WHERE \ + vpopmail.pw_name='%n' \ + AND \ + (vpopmail.pw_domain='%d' OR vpopmail.pw_domain=aliasdomains.domain) \ + AND \ + ('%a'!='995' OR !(vpopmail.pw_gid & 2)) \ + AND \ + ('%r'!='[WEBMAIL-IP]' OR !(vpopmail.pw_gid & 4)) \ + AND \ + ('%r'='WEBMAIL-IP' OR '%a'!='993' OR !(vpopmail.pw_gid & 8)) + +user_query = \ + SELECT \ + vpopmail.pw_dir AS home, \ + 89 AS uid, \ + 89 AS gid \ + FROM vpopmail \ + WHERE \ + vpopmail.pw_name='%n' \ + AND \ + vpopmail.pw_domain='%d' + +* Create/delete aliasdomains in the usual way with vaddaliasdomain/vdeldomain + +* If you already have aliasdomains, you have to populate the dbtable. You can use my "vsavealiasdomains" program + to save all your domain aliases to MySQL. + Type "vsavealiasadomains -A" to save all your domain aliases to MySQL. + Type "vsavealiasadomains -h" for more options. diff -ruN ../vpopmail-5.4.33-original/vmysql.c vpopmail-5.4.33/vmysql.c --- ../vpopmail-5.4.33-original/vmysql.c 2011-02-28 18:00:45.000000000 +0100 +++ vpopmail-5.4.33/vmysql.c 2021-02-14 18:03:15.811565913 +0100 @@ -96,6 +96,20 @@ void vcreate_lastauth_table(); #endif +char *MYSQL_READ_SERVER; +int MYSQL_READ_PORT; +char *MYSQL_READ_SOCKET; +char *MYSQL_READ_USER; +char *MYSQL_READ_PASSWD; +char *MYSQL_READ_DATABASE; + +char *MYSQL_UPDATE_SERVER; +int MYSQL_UPDATE_PORT; +char *MYSQL_UPDATE_SOCKET; +char *MYSQL_UPDATE_USER; +char *MYSQL_UPDATE_PASSWD; +int MYSQL_UPDATE_VPORT; +char *MYSQL_UPDATE_DATABASE; /************************************************************************/ /* @@ -361,8 +375,11 @@ #else /* if creation fails, don't show an error */ vauth_create_table (MYSQL_DEFAULT_TABLE, TABLE_LAYOUT, 0); - return (0); #endif +#ifdef SQL_ALIASDOMAINS + vcreate_aliasdomains_table(); +#endif + return (0); } @@ -1866,3 +1883,57 @@ return(strcmp(crypt(clear_pass,vpw->pw_passwd),vpw->pw_passwd)); } + + +/************************************************************************/ +void vcreate_aliasdomains_table() +{ + /* if creation fails do not throw an error */ + vauth_create_table ("aliasdomains", ALIASDOMAINS_TABLE_LAYOUT, 0); + return; +} + +/************************************************************************/ +int vcreate_sql_aliasdomain(char *domain, char *alias) +{ + int err; + + if ( (err=vauth_open_update()) != 0 ) return(err); + + qnprintf( SqlBufUpdate, SQL_BUF_SIZE, + "INSERT IGNORE INTO aliasdomains (domain,alias) VALUES ('%s','%s')", + domain, + alias ); + + if (mysql_query(&mysql_update,SqlBufUpdate)) { + vcreate_aliasdomains_table(); + if (mysql_query(&mysql_update,SqlBufUpdate)) { + fprintf(stderr, "vmysql: sql error[m]: %s\n", mysql_error(&mysql_update)); + return(-1); + } + } + return(0); +} + + +/************************************************************************/ +int vdelete_sql_aliasdomain(char *alias) +{ + int err; + + if ( (err=vauth_open_update()) != 0 ) return(err); + + qnprintf( SqlBufUpdate, SQL_BUF_SIZE, + "DELETE FROM aliasdomains WHERE alias='%s'", + alias ); + + if (mysql_query(&mysql_update,SqlBufUpdate)) { + vcreate_aliasdomains_table(); + if (mysql_query(&mysql_update,SqlBufUpdate)) { + fprintf(stderr, "vmysql: sql error[m]: %s\n", mysql_error(&mysql_update)); + return(-1); + } + } + return(0); +} + diff -ruN ../vpopmail-5.4.33-original/vmysql.h vpopmail-5.4.33/vmysql.h --- ../vpopmail-5.4.33-original/vmysql.h 2011-02-28 18:00:45.000000000 +0100 +++ vpopmail-5.4.33/vmysql.h 2021-02-14 18:03:15.812565902 +0100 @@ -41,20 +41,20 @@ */ -char *MYSQL_READ_SERVER; -int MYSQL_READ_PORT; -char *MYSQL_READ_SOCKET; -char *MYSQL_READ_USER; -char *MYSQL_READ_PASSWD; -char *MYSQL_READ_DATABASE; - -char *MYSQL_UPDATE_SERVER; -int MYSQL_UPDATE_PORT; -char *MYSQL_UPDATE_SOCKET; -char *MYSQL_UPDATE_USER; -char *MYSQL_UPDATE_PASSWD; -int MYSQL_UPDATE_VPORT; -char *MYSQL_UPDATE_DATABASE; +extern char *MYSQL_READ_SERVER; +extern int MYSQL_READ_PORT; +extern char *MYSQL_READ_SOCKET; +extern char *MYSQL_READ_USER; +extern char *MYSQL_READ_PASSWD; +extern char *MYSQL_READ_DATABASE; + +extern char *MYSQL_UPDATE_SERVER; +extern int MYSQL_UPDATE_PORT; +extern char *MYSQL_UPDATE_SOCKET; +extern char *MYSQL_UPDATE_USER; +extern char *MYSQL_UPDATE_PASSWD; +extern int MYSQL_UPDATE_VPORT; +extern char *MYSQL_UPDATE_DATABASE; /* defaults - no need to change */ #define MYSQL_DEFAULT_TABLE "vpopmail" @@ -306,3 +306,10 @@ perm_defaultquota TINYINT(2) NOT NULL DEFAULT 0" #endif +void vcreate_aliasdomains_table(); +int vdelete_sql_aliasdomain(char *alias); +int vcreate_sql_aliasdomain(char *domain, char *alias); + +#define ALIASDOMAINS_TABLE_LAYOUT "alias varchar(100) NOT NULL, \ + domain varchar(100) NOT NULL, \ + PRIMARY KEY (alias)" diff -ruN ../vpopmail-5.4.33-original/vpgsql.c vpopmail-5.4.33/vpgsql.c --- ../vpopmail-5.4.33-original/vpgsql.c 2011-02-28 18:00:45.000000000 +0100 +++ vpopmail-5.4.33/vpgsql.c 2021-02-14 18:03:15.812565902 +0100 @@ -392,10 +392,10 @@ #endif #ifdef ENABLE_SQL_LOGGING - qnprintf( sqlBufUpdate, SQL_BUF_SIZE, + qnprintf( SqlBufUpdate, SQL_BUF_SIZE, "delete from vlog where domain = '%s'", domain ); pgres=PQexec(pgc, SqlBufUpdate); - if( !pgres || PGresultStatus(pgres)!=PGRES_COMMAND_OK) { + if( !pgres || PQresultStatus(pgres)!=PGRES_COMMAND_OK) { return(-1); } #endif @@ -445,11 +445,11 @@ #endif #ifdef ENABLE_SQL_LOGGING - qnprintf( sqlBufUpdate, SQL_BUF_SIZE, + qnprintf( SqlBufUpdate, SQL_BUF_SIZE, "delete from vlog where domain = '%s' and user='%s'", domain, user ); pgres=PQexec(pgc, SqlBufUpdate); - if( !pgres || PGresultStatus(pgres)!=PGRES_COMMAND_OK) { + if( !pgres || PQresultStatus(pgres)!=PGRES_COMMAND_OK) { err = -1; } #endif diff -ruN ../vpopmail-5.4.33-original/vpopmail.c vpopmail-5.4.33/vpopmail.c --- ../vpopmail-5.4.33-original/vpopmail.c 2011-02-28 18:00:45.000000000 +0100 +++ vpopmail-5.4.33/vpopmail.c 2021-02-26 21:21:13.599109071 +0100 @@ -147,7 +147,16 @@ char Dir[MAX_BUFF]; int call_dir; string_list aliases; - + char ch, defaultdelivery_file[60], dotqmaildefault_file[60]; + FILE *defaultdelivery, *dotqmaildefault; + int default_delivery_option; + +#ifdef DEFAULT_DELIVERY + default_delivery_option = 1; +#else + default_delivery_option = 0; +#endif + #ifdef ONCHANGE_SCRIPT /* Don't execute any implied onchange in called functions */ allow_onchange = 0; @@ -269,6 +278,27 @@ dec_dir_control(dir_control_for_uid, uid, gid); fchdir(call_dir); close(call_dir); return(VA_COULD_NOT_OPEN_QMAIL_DEFAULT); + } else if ( default_delivery_option == 1 ) { + + /* Copy the content of control/defaultdelivery into .qmail-default */ + + snprintf(defaultdelivery_file, sizeof(defaultdelivery_file), "%s/control/defaultdelivery", QMAILDIR); + defaultdelivery = fopen(defaultdelivery_file, "r"); + if( defaultdelivery == NULL ) + { + printf("\nERROR: Missing %s/control/defaultdelivery file.\n", QMAILDIR); + printf("To create a %s/control/defaultdelivery type:\n", QMAILDIR); + printf("echo \"| %s/bin/vdelivermail '' bounce-no-mailbox\" > %s/control/defaultdelivery\n\n", VPOPMAILDIR, QMAILDIR); + exit(EXIT_FAILURE); + } + + snprintf(dotqmaildefault_file, sizeof(dotqmaildefault_file), "%s/%s/%s/.qmail-default", dir, DOMAINS_DIR, DomainSubDir); + dotqmaildefault = fopen(dotqmaildefault_file, "w"); + + while ( ( ch = fgetc(defaultdelivery) ) != EOF ) fputc(ch, dotqmaildefault); + + fclose(defaultdelivery); + fclose(dotqmaildefault); } else { fprintf(fs, "| %s/bin/vdelivermail '' bounce-no-mailbox\n", VPOPMAILDIR); fclose(fs); @@ -554,6 +584,17 @@ fprintf (stderr, "Warning: Failed to delete domain from the assign file\n"); } +#ifdef SQL_ALIASDOMAINS + /* aliasdomain table will eventually be created */ + char alias_string[MAX_BUFF]; + + for(i=0; i +#include +#include +#include +#include "config.h" +#include "vpopmail.h" +#include "vauth.h" + +char Domain[MAX_BUFF]; +char Alias[MAX_BUFF]; +int SaveAll; + +void usage(); +void get_options(int argc, char **argv); +void save_all_aliases(); +void save_one_real_domain_aliases( char *Domain ); +void save_alias( char *Domain, char *Alias ); +#ifndef SQL_ALIASDOMAINS +int vcreate_sql_aliasdomain(char *Domain, char *Alias); +#endif + +int main(int argc, char *argv[]) +{ + if( vauth_open( 0 )) { + vexiterror( stderr, "Initial open." ); + } + +#ifndef SQL_ALIASDOMAINS + printf("\nPlease use option --enable-sql-aliasdomains at configure time\n\n"); + exit(-1); +#else + get_options(argc,argv); + + /* did we want to save all aliases of one single domain? */ + if ( Domain[0] > 0 && Alias[0] == 0 ) { + save_one_real_domain_aliases( Domain ); + } + /* did we want to save an alias of a particular domain? */ + else if ( Domain[0] > 0 && Alias[0] > 0 ) { + save_alias( Domain, Alias ); + } + /* save all aliases of all domains */ + else if ( SaveAll == 1 ) { + save_all_aliases(); + } + else { + usage(); + } + return(vexit(0)); +#endif +} + +void usage() +{ + printf("\nUsage: vsavealiasdomains [options] [real_domain] [alias_domain]\n"); + printf("options: -v (print version number)\n"); + printf(" -h (help)\n"); + printf(" -A (saves all aliases of all domains to MySQL)\n"); + printf("vsavealiasdomains domain (saves all aliases of a domain to MySQL)\n"); + printf("vsavealiasdomains real_domain alias_domain (saves an alias domain to MySQL)\n\n"); +} + +void get_options(int argc, char **argv) +{ + int c; + int errflag; + extern int optind; + + SaveAll = 0; + + memset(Domain, 0, sizeof(Domain)); + + errflag = 0; + while( !errflag && (c=getopt(argc,argv,"vAh")) != -1 ) { + switch(c) { + case 'v': + printf("version: %s\n", VERSION); + break; + + case 'A': + SaveAll = 1; + break; + + case 'h': + errflag = 1; + break; + + default: + errflag = 1; + break; + } + } + + if ( errflag > 0 ) { + usage(); + vexit(-1); + } + + if ( optind < argc ) { + snprintf(Domain, sizeof(Domain), "%s", argv[optind]); + ++optind; + } + + if ( optind < argc ) { + snprintf(Alias, sizeof(Alias), "%s", argv[optind]); + ++optind; + } + + if ( Domain[0]>0 && Alias[0]>0 && strcmp( Domain, Alias ) == 0 ) { + printf("Error: real domain and alias domain are the same!\n"); + usage(); + vexit(-1); + } +} + +#ifdef SQL_ALIASDOMAINS +/* + * Save all aliases of all real domains to database + */ +void save_all_aliases() +{ + domain_entry *entry; + entry = get_domain_entries(""); + + if (entry==NULL) { + if( verrori ) { + printf("Can't get domain entries - %s\n", verror( verrori )); + vexit(-1); + } else { + printf("No domain found\n"); + vexit(0); + } + } + + int i = 0; + while( entry ) { + /* we won't save realdomain/realdomain pairs */ + if ( strcmp(entry->realdomain,entry->domain) != 0 ) { + vcreate_sql_aliasdomain(entry->realdomain, entry->domain); + printf ("Alias: %s Real domain: %s saved\n", entry->domain, entry->realdomain); + ++i; + } + entry = get_domain_entries(NULL); + } + if ( i == 0 ) { + printf ("No aliases found\n"); + } +} + + +/* + * Save all aliases of domain Domain to database + */ +void save_one_real_domain_aliases( char *Domain ) +{ + domain_entry *entry; + entry = get_domain_entries ( Domain ); + + if (entry==NULL) { + if( verrori ) { + printf("Can't get domain entries - %s\n", verror( verrori )); + vexit(-1); + } else { + printf("%s does not exist\n", Domain); + vexit(0); + } + } + + int i = 0; + while( entry ) { + /* we won't save realdomain/realdomain pairs */ + if ( strcmp(entry->realdomain,entry->domain) != 0 ) { + vcreate_sql_aliasdomain(entry->realdomain, entry->domain); + printf ("Alias: %s Real domain: %s saved\n", entry->domain, entry->realdomain); + i++; + } + entry = get_domain_entries(NULL); + } + if ( i == 0 ) { + printf ("No aliases found for domain %s\n", Domain); + } +} + + +/* + * Save the pair Alias/Domain to database + */ +void save_alias( char *Domain, char *Alias ) +{ + domain_entry *entry; + entry = get_domain_entries ( Domain ); + + if (entry==NULL) { + if( verrori ) { + printf("Can't get domain entries - %s\n", verror( verrori )); + vexit(-1); + } else { + printf("%s does not exist\n", Domain); + vexit(0); + } + } + + int i = 0; + while( entry ) { + /* we won't save realdomain/realdomain pairs */ + if ( strcmp(Alias,entry->domain) == 0 && strcmp(entry->realdomain,entry->domain) != 0 ) { + vcreate_sql_aliasdomain(entry->realdomain, entry->domain); + printf ("Alias: %s Real domain: %s saved\n", entry->domain, entry->realdomain); + i++; + } + entry = get_domain_entries(NULL); + } + if ( i == 0 ) { + printf ("No alias %s found for domain %s\n", Alias, Domain); + } +} +#endif