forked from brunonymous/vpopmail
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvipmap.c
More file actions
146 lines (129 loc) · 3.04 KB
/
Copy pathvipmap.c
File metadata and controls
146 lines (129 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* Copyright (C) 1999-2009 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 <memory.h>
#include <string.h>
#include "config.h"
#include "vpopmail.h"
#include "vauth.h"
void usage();
void get_options(int argc,char **argv);
int Action;
char Ip[MAX_BUFF];
char Domain[MAX_BUFF];
#define PRINT_IT 0
#define ADD_IT 1
#define DELETE_IT 2
int main(int argc, char *argv[])
{
#ifdef IP_ALIAS_DOMAINS
int result;
int first;
#endif
if( vauth_open( 1 )) {
vexiterror( stderr, "Initial open." );
}
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, sizeof(Ip));
memset( Domain, 0, sizeof(Ip));
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 ( argc <= 1 ) {
usage();
vexit(-1);
}
if ( Action == ADD_IT || Action == DELETE_IT ) {
if ( optind < argc ) {
snprintf(Ip, sizeof(Ip), "%s", argv[optind]);
++optind;
} else {
usage();
vexit(-1);
}
if ( optind < argc ) {
snprintf(Domain, sizeof(Domain), "%s", argv[optind]);
++optind;
} else {
usage();
vexit(-1);
}
}
}