forked from brunonymous/vpopmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpgsql.h
235 lines (215 loc) · 7.52 KB
/
vpgsql.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
/*
* 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_PGSQL_H
#define VPOPMAIL_PGSQL_H
#include "config.h"
/* Edit to match your set up */
#define DB "vpopmail"
#define PG_CONNECT "user=postgres dbname=" DB
// char replacing spaces and dashes
#define SQL_DOT_CHAR '_'
#define PGSQL_DEFAULT_TABLE "vpopmail"
#define PGSQL_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 int4, pw_gid int4, \
pw_gecos varchar(64), \
pw_dir varchar(160), \
pw_shell varchar(20), \
pw_clear_passwd varchar(16), \
PRIMARY KEY(\"pw_domain\", \"pw_name\")"
#else
#define TABLE_LAYOUT "pw_name varchar(64) NOT NULL, \
pw_domain varchar(96) NOT NULL, \
pw_passwd varchar(128), \
pw_uid int4, pw_gid int4, \
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 int4, pw_gid int4, \
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 int4, pw_gid int4, \
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(18) NOT NULL, \
timestamp bigint DEFAULT 0 NOT NULL, PRIMARY KEY (ip_addr)"
#define LASTAUTH_TABLE_LAYOUT \
"userid varchar(32) NOT NULL, \
domain varchar(96) NOT NULL,\
remote_ip varchar(18) NOT NULL, \
timestamp bigint default 0 NOT NULL, \
PRIMARY key (userid, 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(18) NOT NULL, domain varchar(96), PRIMARY KEY (ip_addr)"
#endif
#define DIR_CONTROL_TABLE_LAYOUT "domain varchar(96) NOT NULL, cur_users int4, \
level_cur int4, level_max int4, \
level_start0 int4, level_start1 int4, level_start2 int4, \
level_end0 int4, level_end1 int4, level_end2 int4, \
level_mod0 int4, level_mod1 int4, level_mod2 int4, \
level_index0 int4, level_index1 int4, level_index2 int4, 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"
#define VALIAS_TABLE_LAYOUT "alias varchar(32) NOT NULL, \
domain varchar(96) NOT NULL, \
valias_line varchar(160) NOT NULL"
#define VALIAS_INDEX_LAYOUT "(alias, domain)"
#endif
#ifdef ENABLE_SQL_LOGGING
#define VLOG_TABLE_LAYOUT "id serial, \
userid char(32), passwd CHAR(32), \
domain CHAR(96), logon VARCHAR(200), \
remoteip char(18), message VARCHAR(255), \
timestamp bigint default 0 NOT NULL, error INT, \
INDEX user_idx (user), \
INDEX domain_idx (domain), INDEX remoteip_idx (remoteip), \
INDEX error_idx (error), INDEX message_idx (message)"
#endif