Commit dce74af3 dce74af3eee990f65773eed400a28e92ef2ad2f5 by Sergey Poznyakoff

(authenticate_imap_login): Do not

close the stream on authentication failures.
(authenticate_imap_select): Bugfix
(imap_parse): Use MU_ERR_AUTH_FAILURE where appropriate.
1 parent 9c092fa5
...@@ -180,18 +180,16 @@ authenticate_imap_login (authority_t auth) ...@@ -180,18 +180,16 @@ authenticate_imap_login (authority_t auth)
180 } 180 }
181 181
182 if (f_imap->user == NULL) 182 if (f_imap->user == NULL)
183 { 183 return MU_ERR_NOUSERNAME;
184 CHECK_ERROR_CLOSE (folder, f_imap, MU_ERR_NOUSERNAME); 184
185 }
186 if (f_imap->passwd == NULL) 185 if (f_imap->passwd == NULL)
187 { 186 return MU_ERR_NOPASSWORD;
188 CHECK_ERROR_CLOSE (folder, f_imap, MU_ERR_NOPASSWORD); 187
189 } 188 status = imap_writeline (f_imap, "g%u LOGIN \"%s\" \"%s\"\r\n",
190 status = imap_writeline (f_imap, "g%u LOGIN %s \"%s\"\r\n",
191 f_imap->seq, f_imap->user, f_imap->passwd); 189 f_imap->seq, f_imap->user, f_imap->passwd);
192 CHECK_ERROR_CLOSE(folder, f_imap, status); 190 CHECK_ERROR_CLOSE(folder, f_imap, status);
193 FOLDER_DEBUG2 (folder, MU_DEBUG_PROT, "g%u LOGIN %s *\n", 191 FOLDER_DEBUG2 (folder, MU_DEBUG_PROT, "g%u LOGIN %s *\n",
194 f_imap->seq, f_imap->user); 192 f_imap->seq, f_imap->user);
195 f_imap->seq++; 193 f_imap->seq++;
196 free (f_imap->user); 194 free (f_imap->user);
197 f_imap->user = NULL; 195 f_imap->user = NULL;
...@@ -213,7 +211,8 @@ authenticate_imap_login (authority_t auth) ...@@ -213,7 +211,8 @@ authenticate_imap_login (authority_t auth)
213 case IMAP_LOGIN_ACK: 211 case IMAP_LOGIN_ACK:
214 /* Get the login ack. */ 212 /* Get the login ack. */
215 status = imap_parse (f_imap); 213 status = imap_parse (f_imap);
216 CHECK_EAGAIN (f_imap, status); 214 if (status)
215 return status;
217 FOLDER_DEBUG0 (folder, MU_DEBUG_PROT, f_imap->buffer); 216 FOLDER_DEBUG0 (folder, MU_DEBUG_PROT, f_imap->buffer);
218 f_imap->state = IMAP_AUTH_DONE; 217 f_imap->state = IMAP_AUTH_DONE;
219 218
...@@ -369,11 +368,16 @@ find_auth_method (const char *name) ...@@ -369,11 +368,16 @@ find_auth_method (const char *name)
369 static int 368 static int
370 authenticate_imap_select (authority_t auth) 369 authenticate_imap_select (authority_t auth)
371 { 370 {
371 folder_t folder = authority_get_owner (auth);
372 f_imap_t f_imap = folder->data;
372 struct auth_tab *p; 373 struct auth_tab *p;
373 int status; 374 int status = MU_ERR_AUTH_FAILURE;
374 375
375 for (p = auth_tab; status && p->name; p++) 376 for (p = auth_tab; status && p->name; p++)
376 status = p->method (auth); 377 {
378 f_imap->state = IMAP_AUTH;
379 status = p->method (auth);
380 }
377 381
378 return status; 382 return status;
379 } 383 }
...@@ -2457,9 +2461,11 @@ imap_parse (f_imap_t f_imap) ...@@ -2457,9 +2461,11 @@ imap_parse (f_imap_t f_imap)
2457 observable_t observable = NULL; 2461 observable_t observable = NULL;
2458 folder_get_observable (f_imap->folder, &observable); 2462 folder_get_observable (f_imap->folder, &observable);
2459 observable_notify (observable, MU_EVT_AUTHORITY_FAILED); 2463 observable_notify (observable, MU_EVT_AUTHORITY_FAILED);
2464 status = MU_ERR_AUTH_FAILURE;
2460 } 2465 }
2466 else
2467 status = EINVAL;
2461 mu_error ("NO/Bad Tagged: %s %s\n", response, remainder); 2468 mu_error ("NO/Bad Tagged: %s %s\n", response, remainder);
2462 status = EINVAL;
2463 } 2469 }
2464 } 2470 }
2465 f_imap->ptr = f_imap->buffer; 2471 f_imap->ptr = f_imap->buffer;
......