forked from brunonymous/vpopmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vmysql.h
315 lines (285 loc) · 10.7 KB
/
vmysql.h
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
* 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
*/
#ifndef VPOPMAIL_MYSQL_H
#define VPOPMAIL_MYSQL_H
/* NOTE: As of vpopmail 5.3.25, MySQL connection info is stored in
~vpopmail/etc/vpopmail.mysql. The format of the file is as follows:
read server|read port|read user|read password|read database
update server|update port|update user|update password|update database
Comments (lines starting with '#') are allowed. The first line contains
connection information for READING from the database. The second (optional)
line contains connection information for UPDATING the database. If the
second line is left out, then vpopmail will use the same settings for
reading and updating.
Port should be the actual port, or 0 for default.
For example:
# This is the MySQL configuration file for vpopmail.
localhost|0|readonly|somepass|vpopmail
localhost|0|root|secret|vpopmail
*/
/* defaults - no need to change */
#define MYSQL_DEFAULT_TABLE "vpopmail"
#define MYSQL_DOT_CHAR '_'
#define MYSQL_LARGE_USERS_TABLE "users"
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define TABLE_LAYOUT "pw_name VARCHAR(64) not null, \
pw_domain VARCHAR(96) not NULL, \
pw_passwd VARCHAR(128), \
pw_uid int, pw_gid int, \
pw_gecos VARCHAR(64), \
pw_dir VARCHAR(160), \
pw_shell VARCHAR(20), \
pw_clear_passwd VARCHAR(16), \
primary key (pw_name, pw_domain ) "
#else
#define TABLE_LAYOUT "pw_name VARCHAR(64) not null, \
pw_domain VARCHAR(96) not null, \
pw_passwd VARCHAR(128), \
pw_uid int, pw_gid int, \
pw_gecos VARCHAR(64), \
pw_dir VARCHAR(160), \
pw_shell VARCHAR(20), \
primary key (pw_name, pw_domain ) "
#endif
#else
#ifdef CLEAR_PASS
#define TABLE_LAYOUT "pw_name VARCHAR(64) not null, \
pw_passwd VARCHAR(128), \
pw_uid int, pw_gid int, \
pw_gecos VARCHAR(64), \
pw_dir VARCHAR(160), \
pw_shell VARCHAR(20), \
pw_clear_passwd VARCHAR(16), \
primary key (pw_name ) "
#else
#define TABLE_LAYOUT "pw_name VARCHAR(64) not null, \
pw_passwd VARCHAR(128), \
pw_uid int, pw_gid int, \
pw_gecos VARCHAR(64), \
pw_dir VARCHAR(160), \
pw_shell VARCHAR(20), \
primary key (pw_name ) "
#endif
#endif
#define RELAY_TABLE_LAYOUT "ip_addr VARCHAR(39) not null, \
timestamp INT, primary key (ip_addr)"
#define LASTAUTH_TABLE_LAYOUT \
"user VARCHAR(32) NOT NULL, \
domain VARCHAR(96) NOT NULL,\
remote_ip VARCHAR(39) not null, \
timestamp INT default 0 NOT NULL, \
primary key (user, domain)"
char *vauth_munch_domain(char *);
int vauth_adddomain_size(char *, int);
int vauth_deldomain_size(char *, int);
int vauth_adduser_size(char *, char *, char *, char *, char *, int, int);
int vauth_deluser_size(char *, char *, int);
int vauth_vpasswd_size( char *, char *, char *, int, int);
int vauth_setquota_size( char *, char *, char *, int);
struct vqpasswd *vauth_getpw_size(char *, char *, int);
struct vqpasswd *vauth_user_size(char *, char *, char*, char *, int);
struct vqpasswd *vauth_getall_size(char *, int, int, int);
int vauth_setpw_size( struct vqpasswd *, char *, int);
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define INSERT "insert into `%s` \
( pw_name, pw_domain, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell \
, pw_clear_passwd ) values ( \"%s\", \"%s\", \
\"%s\", %d, 0, \"%s\", \"%s\", \"%s\" ,\"%s\" )"
#else
#define INSERT "insert into `%s` \
( pw_name, pw_domain, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell \
) values ( \"%s\", \"%s\", \
\"%s\", %d, 0, \"%s\", \"%s\", \"%s\" )"
#endif
#else
#ifdef CLEAR_PASS
#define INSERT "insert into `%s` \
( pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell \
, pw_clear_passwd ) values ( \"%s\", \
\"%s\", %d, 0, \"%s\", \"%s\", \"%s\" ,\"%s\" )"
#else
#define INSERT "insert into `%s` \
( pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell \
) values ( \"%s\", \
\"%s\", %d, 0, \"%s\", \"%s\", \"%s\" )"
#endif
#endif
#ifdef MANY_DOMAINS
#define DELETE_USER "delete from `%s` where pw_name = \"%s\" \
and pw_domain = \"%s\" "
#else
#define DELETE_USER "delete from `%s` where pw_name = \"%s\" "
#endif
#ifdef MANY_DOMAINS
#define SETQUOTA "update `%s` set pw_shell = \"%s\" where pw_name = \"%s\" \
and pw_domain = \"%s\" "
#else
#define SETQUOTA "update `%s` set pw_shell = \"%s\" where pw_name = \"%s\" "
#endif
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define USER_SELECT "select pw_name, pw_passwd, pw_uid, pw_gid, \
pw_gecos, pw_dir, pw_shell , pw_clear_passwd \
from `%s` where pw_name = \"%s\" and pw_domain = \"%s\" "
#else
#define USER_SELECT "select pw_name, pw_passwd, pw_uid, pw_gid, \
pw_gecos, pw_dir, pw_shell \
from `%s` where pw_name = \"%s\" and pw_domain = \"%s\" "
#endif
#else
#ifdef CLEAR_PASS
#define USER_SELECT "select pw_name, pw_passwd, pw_uid, pw_gid, \
pw_gecos, pw_dir, pw_shell , pw_clear_passwd \
from `%s` where pw_name = \"%s\" "
#else
#define USER_SELECT "select pw_name, pw_passwd, pw_uid, pw_gid, \
pw_gecos, pw_dir, pw_shell \
from `%s` where pw_name = \"%s\" "
#endif
#endif
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define GETALL "select pw_name, \
pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell, \
pw_clear_passwd from `%s` where pw_domain = \"%s\""
#else
#define GETALL "select pw_name, \
pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell \
from `%s` where pw_domain = \"%s\""
#endif
#else
#ifdef CLEAR_PASS
#define GETALL "select pw_name, \
pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell, \
pw_clear_passwd from `%s`"
#else
#define GETALL "select pw_name, \
pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell from `%s` "
#endif
#endif
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define SETPW "update `%s` set pw_passwd = \"%s\", \
pw_uid = %d, pw_gid = %d, pw_gecos = \"%s\", pw_dir = \"%s\", \
pw_shell = \"%s\" \
, pw_clear_passwd = \"%s\" \
where pw_name = \"%s\" \
and pw_domain = \"%s\" "
#else
#define SETPW "update `%s` set pw_passwd = \"%s\", \
pw_uid = %d, pw_gid = %d, pw_gecos = \"%s\", pw_dir = \"%s\", \
pw_shell = \"%s\" \
where pw_name = \"%s\" \
and pw_domain = \"%s\" "
#endif
#else
#ifdef CLEAR_PASS
#define SETPW "update `%s` set pw_passwd = \"%s\", \
pw_uid = %d, pw_gid = %d, pw_gecos = \"%s\", pw_dir = \"%s\", \
pw_shell = \"%s\" \
, pw_clear_passwd = \"%s\" \
where pw_name = \"%s\" "
#else
#define SETPW "update `%s` set pw_passwd = \"%s\", \
pw_uid = %d, pw_gid = %d, pw_gecos = \"%s\", pw_dir = \"%s\", \
pw_shell = \"%s\" \
where pw_name = \"%s\" "
#endif
#endif
#ifdef IP_ALIAS_DOMAINS
#define IP_ALIAS_TABLE_LAYOUT "ip_addr VARCHAR(39) not null, domain VARCHAR(96), primary key(ip_addr)"
#endif
#define DIR_CONTROL_TABLE_LAYOUT "domain VARCHAR(96) not null, cur_users int, \
level_cur int, level_max int, \
level_start0 int, level_start1 int, level_start2 int, \
level_end0 int, level_end1 int, level_end2 int, \
level_mod0 int, level_mod1 int, level_mod2 int, \
level_index0 int , level_index1 int, level_index2 int, the_dir VARCHAR(160), \
primary key (domain) "
#define DIR_CONTROL_SELECT "cur_users, \
level_cur, level_max, \
level_start0, level_start1, level_start2, \
level_end0, level_end1, level_end2, \
level_mod0, level_mod1, level_mod2, \
level_index0, level_index1, level_index2, the_dir"
#ifdef DEFAULT_DELIVERY
#define VALIAS_TABLE_LAYOUT \
"id int(11) PRIMARY KEY AUTO_INCREMENT, \
valias_type tinyint(1) NOT NULL DEFAULT 1 COMMENT '1=forwarder 0=lda', \
alias VARCHAR(32) NOT NULL, \
domain VARCHAR(96) NOT NULL, \
valias_line text NOT NULL, \
copy tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=redirect 1=copy&redirect', \
INDEX (alias,domain,valias_type), \
INDEX (alias, domain)"
#else
#define VALIAS_TABLE_LAYOUT "id int(11) PRIMARY KEY AUTO_INCREMENT, \
alias VARCHAR(32) NOT NULL, \
domain VARCHAR(96) NOT NULL, \
valias_line text NOT NULL, \
INDEX (alias, domain)"
#endif
#endif
#ifdef ENABLE_SQL_LOGGING
#define VLOG_TABLE_LAYOUT "id BIGINT PRIMARY KEY AUTO_INCREMENT, \
user VARCHAR(32), passwd VARCHAR(32), \
domain VARCHAR(96), logon VARCHAR(200), \
remoteip VARCHAR(39), message VARCHAR(255), \
timestamp INT default 0 NOT NULL, error TINYINT(1), \
INDEX user_idx (user), \
INDEX domain_idx (domain), INDEX remoteip_idx (remoteip), \
INDEX error_idx (error), INDEX message_idx (message)"
#endif
#ifdef ENABLE_MYSQL_LIMITS
#define LIMITS_TABLE_LAYOUT "domain VARCHAR(96) 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 BIGINT UNSIGNED NOT NULL DEFAULT 0, \
maxmsgcount BIGINT UNSIGNED NOT NULL DEFAULT 0, \
defaultquota BIGINT UNSIGNED NOT NULL DEFAULT 0, \
defaultmaxmsgcount BIGINT UNSIGNED 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, \
disable_spamassassin TINYINT(1) NOT NULL DEFAULT 0, \
delete_spam TINYINT(1) NOT NULL DEFAULT 0, \
disable_maildrop 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
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)"
int vcreate_sql_procedures();