Changeset 3437:71b9f5245f22
- Timestamp:
- 2003-07-16 04:18:12 (5 years ago)
- Author:
- Brendan Cully <brendan@…>
- Branch:
- HEAD
- Message:
-
I noticed that my mutt hung when I tried SASL DIGEST-MD5
authentication (I'm not sure when this started). I believe this
patch should solve that problem in a reliable way.
This patch also attempts to reuse connections even when
authentication fails, instead of just throwing away a perfectly good
socket.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r3423
|
r3437
|
|
| 1 | 1 | /* |
| 2 | | * Copyright (C) 2000 Brendan Cully <brendan@kublai.com> |
| | 2 | * Copyright (C) 2000-3 Brendan Cully <brendan@kublai.com> |
| 3 | 3 | * |
| 4 | 4 | * This program is free software; you can redistribute it and/or modify |
| … |
… |
|
| 181 | 181 | return 0; |
| 182 | 182 | } |
| | 183 | |
| | 184 | void mutt_account_unsetpass (ACCOUNT* account) |
| | 185 | { |
| | 186 | account->flags &= !M_ACCT_PASS; |
| | 187 | } |
-
|
r2766
|
r3437
|
|
| 1 | 1 | /* |
| 2 | | * Copyright (C) 2000 Brendan Cully <brendan@kublai.com> |
| | 2 | * Copyright (C) 2000-3 Brendan Cully <brendan@kublai.com> |
| 3 | 3 | * |
| 4 | 4 | * This program is free software; you can redistribute it and/or modify |
| … |
… |
|
| 53 | 53 | int mutt_account_getuser (ACCOUNT* account); |
| 54 | 54 | int mutt_account_getpass (ACCOUNT* account); |
| | 55 | void mutt_account_unsetpass (ACCOUNT* account); |
| 55 | 56 | |
| 56 | 57 | #endif /* _MUTT_ACCOUNT_H_ */ |
-
|
r3421
|
r3437
|
|
| 1 | 1 | /* |
| 2 | | * Copyright (C) 2000-2 Brendan Cully <brendan@kublai.com> |
| | 2 | * Copyright (C) 2000-3 Brendan Cully <brendan@kublai.com> |
| 3 | 3 | * |
| 4 | 4 | * This program is free software; you can redistribute it and/or modify |
| … |
… |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | | mutt_message _("Authenticating (SASL)..."); |
| | 112 | mutt_message (_("Authenticating (%s)..."), mech); |
| 113 | 113 | |
| 114 | 114 | snprintf (buf, sizeof (buf), "AUTHENTICATE %s", mech); |
| … |
… |
|
| 154 | 154 | |
| 155 | 155 | /* send out response, or line break if none needed */ |
| 156 | | if (pc) |
| | 156 | if (olen) |
| 157 | 157 | { |
| 158 | 158 | if (sasl_encode64 (pc, olen, buf, sizeof (buf), &olen) != SASL_OK) |
| … |
… |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | | if (olen || rc == SASL_CONTINUE) |
| | 171 | if (irc == IMAP_CMD_RESPOND) |
| 172 | 172 | { |
| 173 | 173 | strfcpy (buf + olen, "\r\n", sizeof (buf) - olen); |
-
|
r3433
|
r3437
|
|
| 341 | 341 | /* don't open a new connection if one isn't wanted */ |
| 342 | 342 | if (flags & M_IMAP_CONN_NONEW) |
| 343 | | if (!idata || idata->state == IMAP_DISCONNECTED) |
| 344 | | goto err_conn; |
| | 343 | { |
| | 344 | if (!idata) |
| | 345 | { |
| | 346 | mutt_socket_free (conn); |
| | 347 | return NULL; |
| | 348 | } |
| | 349 | if (idata->state < IMAP_AUTHENTICATED) |
| | 350 | return NULL; |
| | 351 | } |
| 345 | 352 | |
| 346 | 353 | if (!idata) |
| … |
… |
|
| 348 | 355 | /* The current connection is a new connection */ |
| 349 | 356 | if (! (idata = imap_new_idata ())) |
| 350 | | goto err_conn; |
| | 357 | { |
| | 358 | mutt_socket_free (conn); |
| | 359 | return NULL; |
| | 360 | } |
| 351 | 361 | |
| 352 | 362 | conn->data = idata; |
| 353 | 363 | idata->conn = conn; |
| 354 | 364 | } |
| | 365 | |
| 355 | 366 | if (idata->state == IMAP_DISCONNECTED) |
| 356 | | if (imap_open_connection (idata) != 0) |
| 357 | | goto err_idata; |
| | 367 | imap_open_connection (idata); |
| | 368 | if (idata->state == IMAP_CONNECTED) |
| | 369 | { |
| | 370 | if (!imap_authenticate (idata)) |
| | 371 | { |
| | 372 | idata->state = IMAP_AUTHENTICATED; |
| | 373 | if (idata->conn->ssf) |
| | 374 | dprint (2, (debugfile, "Communication encrypted at %d bits\n", |
| | 375 | idata->conn->ssf)); |
| | 376 | imap_get_delim (idata); |
| | 377 | } |
| | 378 | else |
| | 379 | mutt_account_unsetpass (&idata->conn->account); |
| | 380 | |
| | 381 | FREE (&idata->capstr); |
| | 382 | } |
| 358 | 383 | |
| 359 | 384 | return idata; |
| 360 | | |
| 361 | | err_idata: |
| 362 | | imap_free_idata (&idata); |
| 363 | | err_conn: |
| 364 | | mutt_socket_free (conn); |
| 365 | | |
| 366 | | return NULL; |
| 367 | 385 | } |
| 368 | 386 | |
| … |
… |
|
| 376 | 394 | idata->state = IMAP_CONNECTED; |
| 377 | 395 | |
| 378 | | if (imap_cmd_step (idata) != IMAP_CMD_CONTINUE) |
| 379 | | goto bail; |
| | 396 | if (imap_cmd_step (idata) != IMAP_CMD_CONTINUE) { |
| | 397 | mutt_error (_("Unexpected response received from server: %s"), idata->cmd.buf); |
| | 398 | mutt_sleep (1); |
| | 399 | |
| | 400 | mutt_socket_close (idata->conn); |
| | 401 | idata->state = IMAP_DISCONNECTED; |
| | 402 | return -1; |
| | 403 | } |
| 380 | 404 | |
| 381 | 405 | if (ascii_strncasecmp ("* OK", idata->cmd.buf, 4) == 0) |
| … |
… |
|
| 414 | 438 | } |
| 415 | 439 | #endif |
| 416 | | if (imap_authenticate (idata)) |
| 417 | | goto bail; |
| 418 | | if (idata->conn->ssf) |
| 419 | | dprint (2, (debugfile, "Communication encrypted at %d bits\n", |
| 420 | | idata->conn->ssf)); |
| 421 | 440 | } |
| 422 | 441 | else if (ascii_strncasecmp ("* PREAUTH", idata->cmd.buf, 9) == 0) |
| 423 | 442 | { |
| | 443 | idata->state = IMAP_AUTHENTICATED; |
| 424 | 444 | if (imap_check_capabilities (idata) != 0) |
| 425 | 445 | goto bail; |
| | 446 | FREE (&idata->capstr); |
| 426 | 447 | } |
| 427 | 448 | else |
| … |
… |
|
| 431 | 452 | } |
| 432 | 453 | |
| 433 | | FREE (&idata->capstr); |
| 434 | | idata->state = IMAP_AUTHENTICATED; |
| 435 | | |
| 436 | | imap_get_delim (idata); |
| 437 | 454 | return 0; |
| 438 | 455 | |
| … |
… |
|
| 441 | 458 | bail: |
| 442 | 459 | FREE (&idata->capstr); |
| 443 | | idata->state = IMAP_DISCONNECTED; |
| 444 | 460 | return -1; |
| 445 | 461 | } |
| … |
… |
|
| 521 | 537 | if (!(idata = imap_conn_find (&(mx.account), M_IMAP_CONN_NOSELECT))) |
| 522 | 538 | goto fail_noidata; |
| | 539 | if (idata->state < IMAP_AUTHENTICATED) |
| | 540 | goto fail; |
| | 541 | |
| 523 | 542 | conn = idata->conn; |
| 524 | 543 | |