-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcgipaf_init.c
More file actions
413 lines (305 loc) · 13.3 KB
/
cgipaf_init.c
File metadata and controls
413 lines (305 loc) · 13.3 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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/*
* cgipaf_init.c
*
* Copyright (C) 2002, 2003, 2013, 2014 Staf Wagemakers Belgie/Belgium
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
unsetenv("IFS");
set_memerr(out_of_memory); /* set out of memory handler */
fflush(0);
/* reset parms */
memset(forward,'\0',sizeof(forward));
memset(not_forward,'\0',sizeof(not_forward));
forward_to=txt_NULL;
memset(keep_msg,'\0',sizeof(keep_msg));
memset(not_keep_msg,'\0',sizeof(not_keep_msg));
memset(not_autoreply,'\0',sizeof(not_autoreply));
/* init options table */
options=add_2_string_pair(options,txt_name,txt_NULL); /* 0 */
options=add_2_string_pair(options,txt_max_length,max_length_txt); /* 1 */
options=add_2_string_pair(options,txt_min_length,min_length_txt); /* 2 */
options=add_2_string_pair(options,txt_max_invalid,max_invalid_txt); /* 3 */
options=add_2_string_pair(options,txt_invalid_timeout,max_invalid_txt); /* 4 */
options=add_2_string_pair(options,txt_invalid_wait,invalid_wait_txt); /* 5 */
options=add_2_string_pair(options,txt_forward_to,txt_NULL); /* 6 */
options=add_2_string_pair(options,txt_forward,forward); /* 7 */
options=add_2_string_pair(options,txt_not_forward,not_forward); /* 8 */
options=add_2_string_pair(options,txt_keep_msg,keep_msg); /* 9 */
options=add_2_string_pair(options,txt_not_keep_msg,not_keep_msg); /* 10 */
options=add_2_string_pair(options,txt_autoreply,autoreply); /* 11 */
options=add_2_string_pair(options,txt_not_autoreply,not_autoreply); /* 12 */
options=add_2_string_pair(options,txt_autoreply_msg,txt_NULL); /* 13 */
options=add_2_string_pair(options,txt_cookietimeout,cookie_timeout_txt); /* 14 */
options=add_2_string_pair(options,txt_password,txt_NULL); /* 15 */
options=add_2_string_pair(options,txt_crackliberror,txt_NULL); /* 16 */
options=add_2_string_pair(options,txt_pamerrormsg,txt_NULL); /* 17 */
options=add_2_string_pair(options,txt_mailcfg_exitcode,mailcfg_exitcode_txt); /* 18 */
options=add_2_string_pair(options,txt_homedir,txt_NULL); /* 19 */
options=add_2_string_pair(options,txt_domain,txt_NULL); /* 20 */
options=add_2_string_pair(options,txt_badpassword,txt_NULL); /* 21 */
options=add_2_string_pair(options,txt_usermaildomain,txt_NULL); /* 22 */
options=add_2_string_pair(options,txt_message,txt_NULL); /* 23 */
options=add_2_string_pair(options,txt_viewmailcfg_exitcode,viewmailcfg_exitcode_txt); /* 24 */
/*
* test setuid(0)
*/
if (setuid(0)==-1) {
write_log(LOG_USER,7,"setuid(0) failed");
print_txt_msg(err_setuidzero);
exit(0);
}
/*
* set doc_root & accessdb
*/
/* Where are my documents??? */
if ((config_file=fopen(CONFIGFILE,"r"))!=NULL) {
doc_root=get_sg_item(config_file,CFGSECTION,DOC_ROOT);
/* is logging enabled? */
if ((cp=get_sg_item(config_file,CFGSECTION,CFG_SYSLOG))!=NULL) {
if (is_var_yes(cp)==0) enable_log(0);
xfree(cp);
}
/* set loglevel */
if ((cp=get_config_item(config_file,CFG_LOGLEVEL))!=NULL) {
sscanf(cp,"%d",&brol);
set_loglevel(brol);
xfree(cp);
write_log(LOG_USER,7,"Set loglevel to %d",set_loglevel(-1));
}
/* set_SCRIPT_FILENAME */
if ((cp=get_sg_item(config_file,CFGSECTION,CFG_UNSET_SCRIPT_FILENAME))!=NULL) {
if (is_var_yes(cp)==0) set_script_filename=0;
else set_script_filename=2;
xfree(cp);
}
if ((cp=get_sg_item(config_file,CFGSECTION,CFG_SET_SCRIPT_FILENAME))!=NULL) {
if (is_var_yes(cp)==0) set_script_filename=0;
else set_script_filename=1;
xfree(cp);
}
}
#if defined(CGIPAF_MAILCFG) || defined(CGIPAF_VIEWMAILCFG)
else {
/* couldn't open the cfgfile, print errormessage and exit */
print_txt_msg(err_mcfg_configfile);
puts(CONFIGFILE);
puts(txt_contact_webmaster);
write_log(LOG_USER,3,"%s %s",err_mcfg_configfile,CONFIGFILE);
exit(0);
}
#endif
if (config_file!=NULL)
write_log(LOG_USER,7,"configfile %s opened",CONFIGFILE);
else {
write_log(LOG_USER,1,"can't open configfile %s, %s",CONFIGFILE,strerror(errno));
set_loglevel(7);
write_log(LOG_USER,7,"failed to open configfile, switch to debug mode");
}
if (doc_root!=NULL) {
write_log(LOG_USER,7,"doc_root set to %s",doc_root);
if (chdir(doc_root)==-1)
write_log(LOG_USER,3,"chdir(%s) failed, %s",doc_root,strerror(errno));
}
#ifdef _WITHPAM
/* set the pam service name */
if ((pam_servicename=get_sg_item(config_file,CFGSECTION,CFG_PAM_SERVICE))!=NULL) {
set_pam_service(pam_servicename);
}
pam_servicename=set_pam_service(NULL);
write_log(LOG_USER,7,"pam service name set to %s",pam_servicename);
#ifdef CGIPAF_PASSWD
/* set the pam_chauth_flag */
if ((cp=get_sg_item(config_file,CFGSECTION,CFG_PAM_CHANGE_EXPIRED_AUTHTOK))!=NULL) {
if (is_var_yes(cp)!=1) {
write_log(LOG_USER,7,"set PAM_CHANGE_EXPIRED_AUTHOK to off");
set_pam_chauth_flag(0);
}
else {
write_log(LOG_USER,7,"set PAM_CHANGE_EXPIRED_AUTHOK to on");
}
xfree(cp);
}
#endif /* CGIPAF_PASSWD */
#endif /* _WITH_PAM */
#ifdef CGIPAF_PASSWD
#ifdef HAVE_LIBCRACK
/* enable cracklib if cracklib is set to "on" */
if ((cp=get_sg_item(config_file,CFGSECTION,CFG_CRACKLIB))!=NULL) {
if (is_var_yes(cp)==0) {
enable_cracklib=0;
write_log(LOG_USER,7,"cracklib disabled");
}
else {
enable_cracklib=1;
write_log(LOG_USER,7,"cracklib enabled");
}
xfree(cp);
if (enable_cracklib==1) {
if ((cp=get_sg_item(config_file,CFGSECTION,CFG_CRACKLIB_DICTPATH))!=NULL) {
cracklib_dictpath=xmalloc(strlen(cp)+1);
strcpy(cracklib_dictpath,cp);
xfree(cp);
write_log(LOG_INFO,7,"cracklib_dictpath set to \"%s\"",cracklib_dictpath);
}
/* vrfy that cracklib_dictpath is readable */
if (cracklib_dictpath==NULL) {
write_log(LOG_INFO,6,"cracklib_dictpath is NULL, please set cracklib_dictpath if you want to enable cracklib.");
char err_cracklibdictpath[]="Configuration error cracklib_dictpath is NULL, please set cracklib_dictpath if you want to enable cracklib.";
options[16][1]=(char *) xmalloc(strlen(err_cracklibdictpath));
options[21][1]=options[16][1];
strcpy(options[16][1],err_cracklibdictpath);
show_msg(config_file,doc_root,CFGSECTION,ERR_CRACKLIB,err_cracklib,options,txt_message);
exit(0);
}
char *full_cracklib_dictpath;
FILE *fp;
full_cracklib_dictpath=xmalloc(strlen(cracklib_dictpath)+strlen(".pwi")+1);
strcpy(full_cracklib_dictpath,cracklib_dictpath);
strcat(full_cracklib_dictpath,".pwi");
if(!(fp=fopen(full_cracklib_dictpath,"r"))) {
write_log(LOG_INFO,6,"full_cracklib_dictpath \"%s\" is not readable configuration mistake?",full_cracklib_dictpath);
char err_cracklibdictpath[]="Configuration error failed to open dictionary: ";
/*
* Save the error into the cracklib error and badpassword options array
*/
options[16][1]=(char *) xmalloc(strlen(err_cracklibdictpath)+strlen(full_cracklib_dictpath)+1);
strcpy(options[16][1],err_cracklibdictpath);
strcat(options[16][1],full_cracklib_dictpath);
options[21][1]=options[16][1];
show_msg(config_file,doc_root,CFGSECTION,ERR_CRACKLIB,err_cracklib,options,txt_message);
exit(0);
}
else {
fclose(fp);
}
}
}
#endif /* HAVE_LIBCRACK */
#endif /* CGIPAF_PASSWD */
/* Should we use an accessdb, if yes get max_invalid & invalid_timeout */
if ((cp=get_sg_item(config_file,CFGSECTION,CFG_ACCESSDB))!=NULL) {
accessdb=cp;
write_log(LOG_USER,7,"accessdb set to %s",accessdb);
if ((cp=get_sg_item(config_file,CFGSECTION,CFG_MAXINVALID))!=NULL) {
sscanf(cp,"%d",&max_invalid);
write_log(LOG_USER,7,"max_invalid set to %d",max_invalid);
}
if ((cp=get_sg_item(config_file,CFGSECTION,CFG_INVALIDTIMEOUT))!=NULL) {
sscanf(cp,"%d",&invalid_timeout);
write_log(LOG_USER,7,"invalid_timeout set to %d",invalid_timeout);
}
}
snprintf(invalid_timeout_txt,80,"%d",invalid_timeout);
snprintf(max_invalid_txt,80,"%d",max_invalid);
#if defined(CGIPAF_MAILCFG) || defined(CGIPAF_VIEWMAILCFG)
/* we need accessdb to store our cookies */
if(accessdb==NULL) {
write_log(LOG_USER,3,"%s",err_mcfg_accessdb);
show_msg_and_exit(config_file,doc_root,CFGSECTION,ERR_ACCESSDB,err_mcfg_accessdb,options,txt_message);
exit(0);
}
/* get the cookie time out */
cp=get_section_config_item(config_file,CFGSECTION,CFG_COOKIETIMEOUT);
if(cp!=NULL) sscanf(cp,"%d",&tmpInt);
cookie_timeout=tmpInt;
write_log(LOG_USER,7,"cookie_timeout set to %d",cookie_timeout);
snprintf(cookie_timeout_txt,80,"%d",(int) cookie_timeout);
#endif
#ifdef CGIPAF_MAILCFG
/* set the sendmail cmd path */
if ((sendmail=get_section_config_item(config_file,CFGSECTION,SENDMAIL))==NULL)
sendmail=txt_sendmail;
write_log(LOG_USER,7,"sendmail set to %s",sendmail);
/* set the formail cmd path */
if ((formail=get_section_config_item(config_file,CFGSECTION,FORMAIL))==NULL)
formail=txt_formail;
write_log(LOG_USER,7,"formail set to %s",formail);
/* set the mailerdomain */
domain=get_section_config_item(config_file,CFGSECTION,CFGDOMAIN);
if(domain!=NULL)
write_log(LOG_USER,7,"domain set to %s",domain);
else write_log(LOG_USER,7,"domain not set");
domain=options[20][1]=get_maildomain(domain);
#endif
#ifdef CGIPAF_VIEWMAILCFG
/* use a statefile or not */
if ((cp=get_sg_item(config_file,CFGSECTION,CFG_USE_STATEFILE))!=NULL) {
if(is_var_yes(cp)!=0) use_mailcfg_statefile(1);
write_log(LOG_USER,7,"use_state_file set to %d",use_mailcfg_statefile(-1));
xfree(cp);
}
if ((cp=get_sg_item(config_file,CFGSECTION,RUN_MAILCFG))!=NULL) {
use_mailcfg_statefile(1);
write_log(LOG_USER,7,"run_mailcfg enabled, enable use_state_file");
xfree(cp);
}
#endif
#ifdef CGIPAF_PASSWD
/*
* Get the max and min password length and store them in
* min_length / max_length
*/
if ((cp=get_section_config_item(config_file,CFGSECTION,CFG_MINLENGTH))==NULL)
min_length=MINLENGTH;
else { sscanf(cp,"%d",&min_length); }
write_log(LOG_USER,7,"min_length set to %d",min_length);
snprintf(min_length_txt,80,"%d",min_length);
if ((cp=get_section_config_item(config_file,CFGSECTION,CFG_MAXLENGTH))==NULL)
max_length=MAXLENGTH;
else { sscanf(cp,"%d",&max_length); }
write_log(LOG_USER,7,"min_length set to %d",max_length);
snprintf(max_length_txt,80,"%d",max_length);
/*
* Get the words not allowed in newpassword
* Added by DJR
*/
illegal_words=get_config_array(config_file,CFG_ILLEGALWORDS); /* will check for success of operation later */
/* We dont want too much data */
max_postlength=MAXPOSTLENGTH;
if ((cp=get_section_config_item(config_file,CFGSECTION,CFG_MAXPOSTLENGTH))==NULL) {
max_postlength=MAXPOSTLENGTH;
}
else {
sscanf(cp,"%d",&max_postlength);
}
write_log(LOG_USER,7,"max_postlength set to %d",max_postlength);
if ((cp=getenv("CONTENT_LENGTH"))!=NULL) {
sscanf(cp,"%d",&brol);
if (brol>max_postlength) {
print_html_msg(txt_too_much);
write_log(LOG_USER,3,"%s",txt_too_much);
exit(1);
}
}
#endif
/* read the POST data */
write_log(LOG_USER,7,"Reading POST data...");
data=read_post();
write_log(LOG_USER,7,"Finished reading POST data...");
/* No Post? -> Ask the user to login */
if (data==NULL) {
write_log(LOG_USER,7,"no POST data, show login_document");
show_msg_and_exit(config_file,doc_root,CFGSECTION,LOGIN_DOCUMENT,err_readdata,options,txt_message);
}
if (data->name==NULL) {
write_log(LOG_USER,7,"empty post array, show login_document");
show_msg_and_exit(config_file,doc_root,CFGSECTION,LOGIN_DOCUMENT,err_readdata,options,txt_message);
}
/* add post variabeles to the options table */
write_log(LOG_USER,7,"cgipaf_init.c: add_post_2_string_pair started.");
options=add_post_2_string_pair(data,options);
write_log(LOG_USER,7,"cgipaf_init.c ends...");