-----BEGIN PGP SIGNED MESSAGE-----
Hello Ken,
During my work with the Python vpopmail module, I figured there ain't
any real vaddaliasdomain() call in the API so I decided to my own and
get rid of the annoying symlinking that vaddaliasdomain does.
Basically, I just use add_alias_domain() to create a new domain that
has the same directory as the old one listed in the assign file (this
is against 4.10.35 and I noticed that 4.9.10 appears to have another
add_domain_assign that appends domains/$domain to the dir string
passed to it).
- -------------------
int vaddaliasdomain( char *new_domain, char *old_domain)
{
FILE *fs;
int i;
char *domain_sub_dir;
char tmpbuf[156];
char * tmpstr;
char old_working_dir[156];
uid_t uid;
gid_t gid;
char dir[156];
/* we only do lower case */
lowerit(new_domain);
lowerit(old_domain);
/* check invalid email domain characters */
for(i=0; new_domain[i]!=0;++i) {
if (i == 0 && new_domain[i] == '-' )
return(VA_INVALID_DOMAIN_NAME);
if (isalnum((int) new_domain[i])==0 && new_domain[i]!='-' &&
new_domain[i]!='.')
return(VA_INVALID_DOMAIN_NAME);
}
if ( new_domain[i-1] == '-' ) return(VA_INVALID_DOMAIN_NAME);
/* after the name is okay, check if it already exists */
if ( vget_assign(new_domain, NULL, 156, NULL, NULL ) != NULL ) {
return(VA_DOMAIN_ALREADY_EXISTS);
}
tmpstr = vget_assign(old_domain, dir , 156, &uid, &gid);
if ( tmpstr == NULL ) {
return(VA_OLD_DOMAIN_DOES_NOT_EXIST);
}
add_domain_assign(new_domain, dir, uid, gid);
signal_process("qmail-send", SIGHUP);
return NULL;
}
- ---------------
Please note that it introduces a new error code named
VA_OLD_DOMAIN_DOES_NOT_EXIST.
Accordingly, vaddaliasdomain.c needs to be changed to:
- ----------------
/*
* vaddomain
* part of the vpopmail package
*
* Copyright (C) 1999,2001 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"
#define MAX_BUFF 500
char Domain_old[MAX_BUFF];
char Domain_new[MAX_BUFF];
char TmpBuf1[MAX_BUFF];
char TmpBuf2[MAX_BUFF];
char TmpBuf3[MAX_BUFF];
void usage();
void get_options(int argc,char **argv);
int main(argc,argv)
int argc;
char *argv[];
{
char Dir[156];
char *tmpstr;
int result;
get_options(argc,argv);
lowerit(Domain_old);
lowerit(Domain_new);
result=vaddaliasdomain(Domain_new,Domain_old);
if(result==VA_INVALID_DOMAIN_NAME)
{
printf("Error: The aliasdomain %s is invalid.\n", Domain_new);
usage();
return(1);
}
else if(result==VA_DOMAIN_ALREADY_EXISTS)
{
printf("Error: The domain %s already exists.\n", Domain_new);
usage();
return(1);
}
else if(result==VA_OLD_DOMAIN_DOES_NOT_EXIST)
{
printf("Error: The domain %s doesn't exist.\n", Domain_old);
usage();
return(1);
}
if(result==0)
{
printf("Successfully added domain %s as an alias to %s\n",
Domain_new, Domain_old);
return(0);
}
}
void usage()
{
printf("vaddaliasdomain: usage: [options] new_domain
old_domain\n");
printf("options: -v (print version number)\n");
}
void get_options(int argc,char **argv)
{
int c;
int errflag;
memset(Domain_old, 0, MAX_BUFF);
memset(Domain_new, 0, MAX_BUFF);
memset(TmpBuf1, 0, MAX_BUFF);
memset(TmpBuf2, 0, MAX_BUFF);
errflag = 0;
while( !errflag && (c=getopt(argc,argv,"v")) != -1 ) {
switch(c) {
case 'v':
printf("version: %s\n", VERSION);
break;
default:
errflag = 1;
break;
}
}
if ( optind < argc ) {
strncpy(Domain_new, argv[optind], MAX_BUFF);
++optind;
}
if ( optind < argc ) {
strncpy(Domain_old, argv[optind], MAX_BUFF);
++optind;
}
if ( Domain_new[0] == 0 || Domain_old[0] == 0 ) {
usage();
vexit(-1);
}
}
- ----------
When I get the time to do it, I'll come up with a solution to delete
the aliasdomains... I assume patching vdeldomain (it currently
complains that the aliases don't exist which makes not too much sense
too me as vaddaliasdomain correctly stops if the alias is already
existing!) so that it only deletes the directory hierarchy when
the last part of the directory is equal to the domain should work.
Thoughts?
Best regards,
Gabriel
-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5i
iQEVAwUBO4u3l8Za2WpymlDxAQHcAQgAp8m430plR5q2Y/y0RpH1XvWbJwZ7lr24
lBtIM9UaMfWjOZUX4FxLDTQe1oeWdy534RQmlLmBZuGqKL9vZTkN6R4ipyQom3lY
pL0h4JTayfZ/6tfO/oRaN4Yb3aHdsbULGDR0owIoMBzIlGJgMqcy1nA/WBVY4O7W
igIJ1eYf8Fvlr9aR4gNq4aAgzDJAFnFfFRgsJJFLOrQ3AnEg+POW57f8gZ+je8hs
maOOrOojOmkRLljHhYO/En8u2ZoJ0sCl/h8tQHUxuxrCqxYOCuX8CLpBXx3VRR22
VRqV+PjIGTsTMQ9OyPCY3Cgk679RUPcI/dUpHQdqyXF1jTkv/AJwlw==
=xW8h
-----END PGP SIGNATURE-----