forked from qmail/qmailadmin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.c
More file actions
177 lines (158 loc) · 4.25 KB
/
auth.c
File metadata and controls
177 lines (158 loc) · 4.25 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
/*
* $Id: auth.c,v 1.3.2.7 2009-05-02 17:51:40 tomcollins Exp $
* Copyright (C) 1999-2004 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 <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pwd.h>
#include <dirent.h>
#include <vpopmail.h>
#include <vauth.h>
/* undef some macros that get redefined below */
#undef PACKAGE
#undef VERSION
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
#undef QMAILDIR
#undef EZMLMDIR
#include "config.h"
#include "qmailadmin.h"
#include "qmailadminx.h"
#include "cgi.h"
#include "show.h"
#include "util.h"
//extern char *crypt();
void auth_system(const char *ip_addr, struct vqpasswd *pw)
{
FILE *fs;
time_t time1;
time_t time2;
#ifdef IPAUTH
char ip_value[MAX_BUFF];
#endif
if( chdir(RealDir) < 0 ){
snprintf (StatusMessage, sizeof(StatusMessage), "%s %s\n", html_text[171], RealDir);
show_login();
vclose();
exit(0);
}
snprintf(TmpBuf, sizeof(TmpBuf), "%s/" MAILDIR "/%s.qw", pw->pw_dir, Time);
fs = fopen(TmpBuf, "r");
if ( fs == NULL ) {
snprintf (StatusMessage, sizeof(StatusMessage), "%s\n", html_text[172]);
show_login();
vclose();
exit(0);
}
if ( fgets(TmpBuf, sizeof(TmpBuf), fs) == NULL ) {
snprintf (StatusMessage, sizeof(StatusMessage), "%s %d\n", html_text[150], 4);
vclose();
exit(0);
}
fclose(fs);
#ifdef IPAUTH
GetValue(TmpBuf, ip_value, "ip_addr=", sizeof(ip_value));
if ( strcmp(ip_addr, ip_value) != 0 ) {
unlink(TmpBuf1);
strcpy (StatusMessage, "invalid\n");
show_login();
vclose();
exit(0);
}
#endif
time1 = atoi(Time); time2 = time(NULL);
if ( time2 > time1 + 7200 ) {
unlink(TmpBuf1);
snprintf (StatusMessage, sizeof(StatusMessage), "%s\n", html_text[173]);
show_login();
vclose();
exit(0);
}
}
void auth_user_domain(const char *ip_addr, struct vqpasswd *pw)
{
FILE *fs;
time_t time1;
time_t time2;
#ifdef IPAUTH
char ip_value[MAX_BUFF];
#endif
if ( chdir(RealDir) < 0 ) {
snprintf (StatusMessage, sizeof(StatusMessage), "%s %s\n", html_text[171], RealDir );
show_login();
vclose();
exit(0);
}
snprintf(TmpBuf, sizeof(TmpBuf), "%s/" MAILDIR "/%s.qw", pw->pw_dir, Time);
fs = fopen(TmpBuf, "r");
if ( fs == NULL ) {
snprintf (StatusMessage, sizeof(StatusMessage), "%s\n", html_text[172]);
show_login();
vclose();
exit(0);
}
if ( fgets(TmpBuf, sizeof(TmpBuf), fs) == NULL ) {
snprintf (StatusMessage, sizeof(StatusMessage), "%s %d\n", html_text[150], 5);
vclose();
exit(0);
}
fclose(fs);
#ifdef IPAUTH
GetValue(TmpBuf, ip_value, "ip_addr=", sizeof(ip_value));
if ( strcmp(ip_addr, ip_value) != 0 ) {
unlink(TmpBuf1);
snprintf (StatusMessage, sizeof(StatusMessage), "%s %d (%s != %s)\n",
html_text[150], 6, ip_addr, ip_value);
show_login();
vclose();
exit(0);
}
#endif
time1 = atoi(Time); time2 = time(NULL);
if ( time2 > time1 + 7200 ) {
unlink(TmpBuf1);
snprintf (StatusMessage, sizeof(StatusMessage), "%s\n", html_text[173]);
show_login();
vclose();
exit(0);
}
}
void set_admin_type()
{
struct vqpasswd *vpw=NULL;
vpw = vauth_getpw(Username, Domain);
AdminType = NO_ADMIN;
if ( strlen(Domain) > 0 ) {
if ( strcmp(Username,"postmaster")==0 ) {
AdminType = DOMAIN_ADMIN;
#ifdef VQPASSWD_HAS_PW_FLAGS
} else if ( vpw->pw_flags & QA_ADMIN ) {
#else
} else if ( vpw->pw_gid & QA_ADMIN ) {
#endif
AdminType = DOMAIN_ADMIN;
} else {
AdminType = USER_ADMIN;
}
}
}