#include <opie.h>
#endif /* OPIE_ENABLE */
-static int last;
-#ifdef SDPS_ENABLE
-char *sdps_envfrom;
-char *sdps_envto;
-#endif /* SDPS_ENABLE */
+/* global variables: please reinitialize them explicitly for proper
+ * working in daemon mode */
+/* TODO: session variables to be initialized before server greeting */
#ifdef OPIE_ENABLE
static char lastok[POPBUFSIZE+1];
#endif /* OPIE_ENABLE */
-/* these variables are shared between the CAPA probe and the authenticator */
+/* session variables initialized in capa_probe() or pop3_getauth() */
#if defined(GSSAPI)
- flag has_gssapi = FALSE;
+flag has_gssapi = FALSE;
#endif /* defined(GSSAPI) */
#if defined(KERBEROS_V4) || defined(KERBEROS_V5)
- flag has_kerberos = FALSE;
+flag has_kerberos = FALSE;
#endif /* defined(KERBEROS_V4) || defined(KERBEROS_V5) */
- static flag has_cram = FALSE;
+static flag has_cram = FALSE;
#ifdef OPIE_ENABLE
- flag has_otp = FALSE;
+flag has_otp = FALSE;
#endif /* OPIE_ENABLE */
#ifdef SSL_ENABLE
- static flag has_ssl = FALSE;
+static flag has_ssl = FALSE;
#endif /* SSL_ENABLE */
+/* mailbox variables initialized in pop3_getrange() */
+static int last;
+
+/* mail variables initialized in pop3_fetch() */
+#ifdef SDPS_ENABLE
+char *sdps_envfrom;
+char *sdps_envto;
+#endif /* SDPS_ENABLE */
+
#ifdef NTLM_ENABLE
#include "ntlm.h"
-static tSmbNtlmAuthRequest request;
-static tSmbNtlmAuthChallenge challenge;
-static tSmbNtlmAuthResponse response;
-
/*
* NTLM support by Grant Edwards.
*
* Much source (ntlm.h, smb*.c smb*.h) was borrowed from Samba.
*/
-static int do_pop3_ntlm(int sock, struct query *ctl)
+static int do_pop3_ntlm(int sock, struct query *ctl,
+ int msn_instead /** if true, send AUTH MSN, else send AUTH NTLM */)
{
+ tSmbNtlmAuthRequest request;
+ tSmbNtlmAuthChallenge challenge;
+ tSmbNtlmAuthResponse response;
+
char msgbuf[2048];
int result,len;
- gen_send(sock, "AUTH MSN");
+ gen_send(sock, msn_instead ? "AUTH MSN" : "AUTH NTLM");
if ((result = gen_recv(sock, msgbuf, sizeof msgbuf)))
return result;
if (!(ctl->server.sdps) && MULTIDROP(ctl) && strstr(greeting, "demon."))
ctl->server.sdps = TRUE;
#endif /* SDPS_ENABLE */
+
#ifdef NTLM_ENABLE
- /* MSN servers require the use of NTLM (MSN) authentication */
- if (!strcasecmp(ctl->server.pollname, "pop3.email.msn.com") ||
- ctl->server.authenticate == A_NTLM)
- {
- if (!do_pop3_ntlm(sock, ctl))
- {
- return(PS_SUCCESS);
- }
- else
- {
- return(PS_AUTHFAIL);
- }
- }
+ /* MSN servers require the use of NTLM (MSN) authentication */
+ if (!strcasecmp(ctl->server.pollname, "pop3.email.msn.com") ||
+ ctl->server.authenticate == A_MSN)
+ return (do_pop3_ntlm(sock, ctl, 1) == 0) ? PS_SUCCESS : PS_AUTHFAIL;
+ if (ctl->server.authenticate == A_NTLM)
+ return (do_pop3_ntlm(sock, ctl, 0) == 0) ? PS_SUCCESS : PS_AUTHFAIL;
+#else
+ if (ctl->server.authenticate == A_NTLM || ctl->server.authenticate == A_MSN)
+ {
+ report(stderr,
+ GT_("Required NTLM capability not compiled into fetchmail\n"));
+ }
#endif
switch (ctl->server.protocol) {
case P_POP3:
#ifdef RPA_ENABLE
+ /* XXX FIXME: AUTH probing (RFC1734) should become global */
/* CompuServe POP3 Servers as of 990730 want AUTH first for RPA */
if (strstr(ctl->remotename, "@compuserve.com"))
{
}
report(stderr,
GT_("SSL connection failed.\n"));
- return(PS_AUTHFAIL);
+ return PS_SOCKET;
}
did_stls = TRUE;
* rather than doing SASL.
*/
if (has_kerberos &&
-#ifdef INET6_ENABLE
ctl->server.service && (strcmp(ctl->server.service, KPOP_PORT)!=0)
-#else /* INET6_ENABLE */
- ctl->server.port != KPOP_PORT
-#endif /* INET6_ENABLE */
&& (ctl->server.authenticate == A_KERBEROS_V4
|| ctl->server.authenticate == A_KERBEROS_V5
|| ctl->server.authenticate == A_ANY))
*++end = '\0';
/* copy timestamp and password into digestion buffer */
- xalloca(msg, char *, (end-start+1) + strlen(ctl->password) + 1);
+ msg = xmalloc((end-start+1) + strlen(ctl->password) + 1);
strcpy(msg,start);
strcat(msg,ctl->password);
-
strcpy(ctl->digest, MD5Digest((unsigned char *)msg));
+ free(msg);
ok = gen_transact(sock, "APOP %s %s", ctl->remotename, ctl->digest);
break;
return PS_SUCCESS;
}
-static int pop3_getuidl(int sock, int num , char *id, size_t idsize)
+/** request UIDL for single message \a num and stuff the result into the
+ * buffer \a id which can hold \a idsize bytes */
+static int pop3_getuidl(int sock, int num, char *id /** output */, size_t idsize)
{
int ok;
char buf [POPBUFSIZE+1];
static const struct method pop3 =
{
"POP3", /* Post Office Protocol v3 */
-#ifdef INET6_ENABLE
"pop3", /* standard POP3 port */
"pop3s", /* ssl POP3 port */
-#else /* INET6_ENABLE */
- 110, /* standard POP3 port */
- 995, /* ssl POP3 port */
-#endif /* INET6_ENABLE */
FALSE, /* this is not a tagged protocol */
TRUE, /* this uses a message delimiter */
pop3_ok, /* parse command response */
NULL, /* no message trailer */
pop3_delete, /* how to delete a message */
pop3_mark_seen, /* how to mark a message as seen */
+ NULL, /* no action at end of mailbox */
pop3_logout, /* log out, we're done */
FALSE, /* no, we can't re-poll */
};
{
#ifndef MBOX
if (ctl->mailboxes->id) {
- fprintf(stderr,GT_("Option --remote is not supported with POP3\n"));
+ fprintf(stderr,GT_("Option --folder is not supported with POP3\n"));
return(PS_SYNTAX);
}
#endif /* MBOX */