Commit 7a815d78 7a815d785e31f506d95cdcdcd55cec87eb9e5519 by Sergey Poznyakoff

Switched to the new authentication/authorization functions.

1 parent 761d8e06
...@@ -17,10 +17,6 @@ ...@@ -17,10 +17,6 @@
17 17
18 #include "pop3d.h" 18 #include "pop3d.h"
19 19
20 #ifdef HAVE_MYSQL
21 #include "../MySql/MySql.h"
22 #endif
23
24 /* 20 /*
25 APOP name digest 21 APOP name digest
26 22
...@@ -149,7 +145,7 @@ int ...@@ -149,7 +145,7 @@ int
149 pop3d_apop (const char *arg) 145 pop3d_apop (const char *arg)
150 { 146 {
151 char *tmp, *user_digest, *user, *password; 147 char *tmp, *user_digest, *user, *password;
152 struct passwd *pw; 148 struct mu_auth_data *auth;
153 char buf[POP_MAXCMDLEN]; 149 char buf[POP_MAXCMDLEN];
154 struct md5_ctx md5context; 150 struct md5_ctx md5context;
155 unsigned char md5digest[16]; 151 unsigned char md5digest[16];
...@@ -202,24 +198,19 @@ pop3d_apop (const char *arg) ...@@ -202,24 +198,19 @@ pop3d_apop (const char *arg)
202 } 198 }
203 199
204 free (user_digest); 200 free (user_digest);
205 pw = getpwnam (user); 201 auth = mu_get_auth_by_name (user);
206 #ifdef HAVE_MYSQL
207 if (!pw)
208 pw = getMpwnam (user);
209 #endif /* HAVE_MYSQL */
210 free (user); 202 free (user);
211 if (pw == NULL) 203 if (auth == NULL)
212 return ERR_BAD_LOGIN; 204 return ERR_BAD_LOGIN;
213 205
214 /* Reset the uid. */ 206 /* Reset the uid. */
215 if (setuid (pw->pw_uid) == -1) 207 if (auth->change_uid && setuid (auth->uid) == -1)
216 return ERR_BAD_LOGIN; 208 {
217 209 mu_auth_data_free (auth);
218 mailbox_name = calloc (strlen (mu_path_maildir) + 1 210 return ERR_BAD_LOGIN;
219 + strlen (pw->pw_name) + 1, 1); 211 }
220 sprintf (mailbox_name, "%s%s", mu_path_maildir, pw->pw_name);
221 212
222 if ((status = mailbox_create (&mbox, mailbox_name)) != 0 213 if ((status = mailbox_create (&mbox, auth->mailbox)) != 0
223 || (status = mailbox_open (mbox, MU_STREAM_RDWR)) != 0) 214 || (status = mailbox_open (mbox, MU_STREAM_RDWR)) != 0)
224 { 215 {
225 mailbox_destroy (&mbox); 216 mailbox_destroy (&mbox);
...@@ -229,6 +220,7 @@ pop3d_apop (const char *arg) ...@@ -229,6 +220,7 @@ pop3d_apop (const char *arg)
229 if (mailbox_create (&mbox, "/dev/null") != 0 220 if (mailbox_create (&mbox, "/dev/null") != 0
230 || mailbox_open (mbox, MU_STREAM_READ) != 0) 221 || mailbox_open (mbox, MU_STREAM_READ) != 0)
231 { 222 {
223 mu_auth_data_free (auth);
232 free (mailbox_name); 224 free (mailbox_name);
233 state = AUTHORIZATION; 225 state = AUTHORIZATION;
234 return ERR_UNKNOWN; 226 return ERR_UNKNOWN;
...@@ -236,16 +228,16 @@ pop3d_apop (const char *arg) ...@@ -236,16 +228,16 @@ pop3d_apop (const char *arg)
236 } 228 }
237 else 229 else
238 { 230 {
239 free (mailbox_name);
240 state = AUTHORIZATION; 231 state = AUTHORIZATION;
232 mu_auth_data_free (auth);
241 return ERR_MBOX_LOCK; 233 return ERR_MBOX_LOCK;
242 } 234 }
243 lockit = 0; /* Do not attempt to lock /dev/null ! */ 235 lockit = 0; /* Do not attempt to lock /dev/null ! */
244 } 236 }
245 free (mailbox_name);
246 237
247 if (lockit && pop3d_lock()) 238 if (lockit && pop3d_lock())
248 { 239 {
240 mu_auth_data_free (auth);
249 mailbox_close(mbox); 241 mailbox_close(mbox);
250 mailbox_destroy(&mbox); 242 mailbox_destroy(&mbox);
251 state = AUTHORIZATION; 243 state = AUTHORIZATION;
...@@ -253,10 +245,12 @@ pop3d_apop (const char *arg) ...@@ -253,10 +245,12 @@ pop3d_apop (const char *arg)
253 } 245 }
254 246
255 state = TRANSACTION; 247 state = TRANSACTION;
256 username = strdup (pw->pw_name); 248 username = strdup (auth->name);
257 if (username == NULL) 249 if (username == NULL)
258 pop3d_abquit (ERR_NO_MEM); 250 pop3d_abquit (ERR_NO_MEM);
259 pop3d_outf ("+OK opened mailbox for %s\r\n", username); 251 pop3d_outf ("+OK opened mailbox for %s\r\n", username);
252 mu_auth_data_free (auth);
253
260 /* mailbox name */ 254 /* mailbox name */
261 { 255 {
262 url_t url = NULL; 256 url_t url = NULL;
......