/* * v ip map * 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 #include #include #include #include #include "config.h" #include "vpopmail.h" #include "vauth.h" void usage(); void get_options(int argc,char **argv); #define MAX_BUFF 200 int Action; char Ip[MAX_BUFF]; char Domain[MAX_BUFF]; #define PRINT_IT 0 #define ADD_IT 1 #define DELETE_IT 2 int main(argc,argv) int argc; char *argv[]; { #ifdef IP_ALIAS_DOMAINS int result; int first; #endif get_options(argc,argv); #ifdef IP_ALIAS_DOMAINS switch(Action) { case ADD_IT: result = vadd_ip_map(Ip, Domain); break; case DELETE_IT: result = vdel_ip_map(Ip, Domain); break; case PRINT_IT: first = 1; while( (result=vshow_ip_map( first, Ip, Domain)) == 1 ) { first = 0; printf("%s %s\n", Ip, Domain); } break; default: usage(); vexit(-1); break; } #else printf("IP aliases are not compiled into vpopmail\n"); printf("You will need to do the following steps\n"); printf("make distclean\n"); printf("./configure --enable-ip-alias-domains=y [your other options]\n"); printf("make\n"); printf("make install-strip\n"); #endif return(vexit(0)); } void usage() { printf("vipmap: usage: [options] ip domain\n"); printf("options: -d delete mapping\n"); printf(" -a add mapping\n"); printf(" -p print mapping\n"); printf(" -v show version\n"); } void get_options(int argc,char **argv) { int c; int errflag; Action = PRINT_IT; memset( Ip, 0, MAX_BUFF); memset( Domain, 0, MAX_BUFF); errflag = 0; while( !errflag && (c=getopt(argc,argv,"vpda")) != -1 ) { switch(c) { case 'v': printf("version: %s\n", VERSION); break; case 'p': Action = PRINT_IT; break; case 'a': Action = ADD_IT; break; case 'd': Action = DELETE_IT; break; default: errflag = 1; break; } } if ( errflag == 1 ) { usage(); vexit(-1); } if ( Action == ADD_IT || Action == DELETE_IT ) { if ( optind < argc ) { strncpy(Ip, argv[optind], MAX_BUFF); ++optind; } else { usage(); vexit(-1); } if ( optind < argc ) { strncpy(Domain, argv[optind], MAX_BUFF); ++optind; } else { usage(); vexit(-1); } } }