Commit 2f36e990 2f36e9904d36583e5fa6c611ae305f56d2eb7d27 by Sam Roberts

Check url authentication type at initialization to trap invalid ones early.

1 parent cca9cce8
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
48 #include <mailutils/error.h> 48 #include <mailutils/error.h>
49 #include <mailbox0.h> 49 #include <mailbox0.h>
50 #include <registrar0.h> 50 #include <registrar0.h>
51 #include <url0.h>
51 52
52 #define PROP_RFC822 1 53 #define PROP_RFC822 1
53 54
...@@ -288,11 +289,45 @@ _mailbox_pop_init (mailbox_t mbox) ...@@ -288,11 +289,45 @@ _mailbox_pop_init (mailbox_t mbox)
288 { 289 {
289 pop_data_t mpd; 290 pop_data_t mpd;
290 int status = 0; 291 int status = 0;
292 ticket_t ticket = NULL;
293 const char *auth = mbox->url->auth;
294
295 /* Allocate authority based on AUTH type, default to user/pass */
296 if (mbox->folder)
297 folder_get_ticket (mbox->folder, &ticket);
298 if (ticket == NULL)
299 ticket = mbox->ticket;
300 if ((status = authority_create (&mbox->authority, ticket, mbox)))
301 {
302 return status;
303 }
304
305 if (auth == NULL || strcasecmp (auth, "*") == 0)
306 {
307 authority_set_authenticate (mbox->authority, pop_user, mbox);
308 }
309 /*
310 else...
311
312 "+apop" could be supported.
313
314 Anything else starting with "+" is an extension mechanism.
315
316 Without a "+" it's a SASL mechanism.
317 */
318 else
319 {
320 authority_destroy (&mbox->authority, mbox);
321 return ENOTSUP;
322 }
291 323
292 /* Allocate specifics for pop data. */ 324 /* Allocate specifics for pop data. */
293 mpd = mbox->data = calloc (1, sizeof (*mpd)); 325 mpd = mbox->data = calloc (1, sizeof (*mpd));
294 if (mbox->data == NULL) 326 if (mbox->data == NULL)
295 return ENOMEM; 327 {
328 authority_destroy (&mbox->authority, mbox);
329 return ENOMEM;
330 }
296 331
297 mpd->mbox = mbox; /* Back pointer. */ 332 mpd->mbox = mbox; /* Back pointer. */
298 333
...@@ -343,6 +378,7 @@ END: ...@@ -343,6 +378,7 @@ END:
343 free (mbox->properties); 378 free (mbox->properties);
344 if (mbox->data) 379 if (mbox->data)
345 free (mbox->data); 380 free (mbox->data);
381 authority_destroy (&mbox->authority, mbox);
346 } 382 }
347 383
348 return status; 384 return status;
...@@ -593,33 +629,6 @@ pop_open (mailbox_t mbox, int flags) ...@@ -593,33 +629,6 @@ pop_open (mailbox_t mbox, int flags)
593 { 629 {
594 CHECK_ERROR_CLOSE (mbox, mpd, EACCES); 630 CHECK_ERROR_CLOSE (mbox, mpd, EACCES);
595 } 631 }
596
597 /* Create an authentication if none was set, according to the url. The
598 default is User/Passwd. */
599 if (mbox->authority == NULL)
600 {
601 char auth[64] = "";
602 size_t n = 0;
603 url_get_auth (mbox->url, auth, sizeof (auth), &n);
604 if (n == 0 || strcasecmp (auth, "*") == 0)
605 {
606 ticket_t ticket = NULL;
607 if (mbox->folder)
608 folder_get_ticket (mbox->folder, &ticket);
609 if (ticket == NULL)
610 ticket = mbox->ticket;
611 authority_create (&(mbox->authority), ticket, mbox);
612 authority_set_authenticate (mbox->authority, pop_user, mbox);
613 }
614 else if (strcasecmp (auth, "+apop") == 0)
615 {
616 /* Not supported. */
617 }
618 else
619 {
620 /* What can we do ? flag an error ? */
621 }
622 }
623 mpd->state = POP_AUTH; 632 mpd->state = POP_AUTH;
624 } 633 }
625 634
......