(pop3d_apop): Call pop3d_begin_session instead of duplicating code from user.c
Showing
1 changed file
with
10 additions
and
73 deletions
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 4 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -53,11 +53,8 @@ pop3d_apopuser (const char *user) | ... | @@ -53,11 +53,8 @@ pop3d_apopuser (const char *user) |
53 | int rc = mu_dbm_open (APOP_PASSFILE, &db, MU_STREAM_READ, 0600); | 53 | int rc = mu_dbm_open (APOP_PASSFILE, &db, MU_STREAM_READ, 0600); |
54 | if (rc) | 54 | if (rc) |
55 | { | 55 | { |
56 | if (rc == -1) | ||
57 | syslog (LOG_INFO, _("Bad permissions on APOP password db")); | ||
58 | else | ||
59 | syslog (LOG_ERR, _("Unable to open APOP db: %s"), | 56 | syslog (LOG_ERR, _("Unable to open APOP db: %s"), |
60 | mu_strerror (rc)); | 57 | mu_strerror (errno)); |
61 | return NULL; | 58 | return NULL; |
62 | } | 59 | } |
63 | 60 | ||
... | @@ -74,15 +71,19 @@ pop3d_apopuser (const char *user) | ... | @@ -74,15 +71,19 @@ pop3d_apopuser (const char *user) |
74 | mu_dbm_close (db); | 71 | mu_dbm_close (db); |
75 | if (rc) | 72 | if (rc) |
76 | { | 73 | { |
77 | syslog (LOG_ERR, _("Cannot fetch APOP data: %s"), mu_strerror (rc)); | 74 | syslog (LOG_ERR, _("Cannot fetch APOP data: %s"), mu_strerror (errno)); |
78 | return NULL; | 75 | return NULL; |
79 | } | 76 | } |
80 | password = calloc (MU_DATUM_SIZE(data) + 1, sizeof (*password)); | 77 | password = calloc (MU_DATUM_SIZE(data) + 1, sizeof (*password)); |
81 | if (password == NULL) | 78 | if (password == NULL) |
79 | { | ||
80 | mu_dbm_datum_free (&data); | ||
82 | return NULL; | 81 | return NULL; |
82 | } | ||
83 | 83 | ||
84 | sprintf (password, "%.*s", (int) MU_DATUM_SIZE(data), | 84 | sprintf (password, "%.*s", (int) MU_DATUM_SIZE(data), |
85 | (char*) MU_DATUM_PTR(data)); | 85 | (char*) MU_DATUM_PTR(data)); |
86 | mu_dbm_datum_free (&data); | ||
86 | return password; | 87 | return password; |
87 | } | 88 | } |
88 | #else /* !USE_DBM */ | 89 | #else /* !USE_DBM */ |
... | @@ -146,12 +147,10 @@ int | ... | @@ -146,12 +147,10 @@ int |
146 | pop3d_apop (const char *arg) | 147 | pop3d_apop (const char *arg) |
147 | { | 148 | { |
148 | char *tmp, *user_digest, *user, *password; | 149 | char *tmp, *user_digest, *user, *password; |
149 | struct mu_auth_data *auth; | ||
150 | char buf[POP_MAXCMDLEN]; | 150 | char buf[POP_MAXCMDLEN]; |
151 | struct md5_ctx md5context; | 151 | struct md5_ctx md5context; |
152 | unsigned char md5digest[16]; | 152 | unsigned char md5digest[16]; |
153 | int status; | 153 | int status; |
154 | int lockit = 1; | ||
155 | char *mailbox_name = NULL; | 154 | char *mailbox_name = NULL; |
156 | 155 | ||
157 | if (state != AUTHORIZATION) | 156 | if (state != AUTHORIZATION) |
... | @@ -203,72 +202,10 @@ pop3d_apop (const char *arg) | ... | @@ -203,72 +202,10 @@ pop3d_apop (const char *arg) |
203 | } | 202 | } |
204 | 203 | ||
205 | free (user_digest); | 204 | free (user_digest); |
206 | auth = mu_get_auth_by_name (user); | 205 | auth_data = mu_get_auth_by_name (user); |
207 | free (user); | 206 | free (user); |
208 | if (auth == NULL) | 207 | if (auth_data == NULL) |
209 | return ERR_BAD_LOGIN; | ||
210 | |||
211 | /* Reset the uid. */ | ||
212 | if (auth->change_uid && setuid (auth->uid) == -1) | ||
213 | { | ||
214 | syslog (LOG_INFO, _("Cannot change to uid %s: %m"), | ||
215 | mu_umaxtostr (0, auth->uid)); | ||
216 | mu_auth_data_free (auth); | ||
217 | return ERR_BAD_LOGIN; | 208 | return ERR_BAD_LOGIN; |
218 | } | ||
219 | |||
220 | if ((status = mu_mailbox_create (&mbox, auth->mailbox)) != 0 | ||
221 | || (status = mu_mailbox_open (mbox, MU_STREAM_RDWR)) != 0) | ||
222 | { | ||
223 | mu_mailbox_destroy (&mbox); | ||
224 | /* For non existent mailbox, we fake. */ | ||
225 | if (status == ENOENT) | ||
226 | { | ||
227 | if (mu_mailbox_create (&mbox, "/dev/null") != 0 | ||
228 | || mu_mailbox_open (mbox, MU_STREAM_READ) != 0) | ||
229 | { | ||
230 | syslog (LOG_ERR, _("Cannot create temporary mailbox: %s"), | ||
231 | mu_strerror (status)); | ||
232 | mu_auth_data_free (auth); | ||
233 | free (mailbox_name); | ||
234 | state = AUTHORIZATION; | ||
235 | return ERR_UNKNOWN; | ||
236 | } | ||
237 | } | ||
238 | else | ||
239 | { | ||
240 | syslog (LOG_ERR, _("Cannot open mailbox %s: %s"), | ||
241 | auth->mailbox, | ||
242 | mu_strerror (status)); | ||
243 | state = AUTHORIZATION; | ||
244 | mu_auth_data_free (auth); | ||
245 | return ERR_MBOX_LOCK; | ||
246 | } | ||
247 | lockit = 0; /* Do not attempt to lock /dev/null ! */ | ||
248 | } | ||
249 | 209 | ||
250 | if (lockit && pop3d_lock()) | 210 | return pop3d_begin_session (); |
251 | { | ||
252 | mu_auth_data_free (auth); | ||
253 | mu_mailbox_close(mbox); | ||
254 | mu_mailbox_destroy(&mbox); | ||
255 | state = AUTHORIZATION; | ||
256 | return ERR_MBOX_LOCK; | ||
257 | } | ||
258 | |||
259 | state = TRANSACTION; | ||
260 | username = strdup (auth->name); | ||
261 | if (username == NULL) | ||
262 | pop3d_abquit (ERR_NO_MEM); | ||
263 | pop3d_outf ("+OK opened mailbox for %s\r\n", username); | ||
264 | mu_auth_data_free (auth); | ||
265 | |||
266 | /* mailbox name */ | ||
267 | { | ||
268 | mu_url_t url = NULL; | ||
269 | mu_mailbox_get_url (mbox, &url); | ||
270 | syslog (LOG_INFO, _("User `%s' logged in with mailbox `%s'"), | ||
271 | username, mu_url_to_string (url)); | ||
272 | } | ||
273 | return OK; | ||
274 | } | 211 | } | ... | ... |
-
Please register or sign in to post a comment