aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--driver.c77
-rw-r--r--pop3.c57
2 files changed, 74 insertions, 60 deletions
diff --git a/driver.c b/driver.c
index 409632b6..91454e39 100644
--- a/driver.c
+++ b/driver.c
@@ -18,6 +18,12 @@
#include <sys/time.h>
#include <signal.h>
+#ifdef KERBEROS_V4
+#include <krb.h>
+#include <des.h>
+#include <netinet/in.h> /* must be included before "socket.h".*/
+#include <netdb.h>
+#endif
#include "socket.h"
#include "fetchmail.h"
#include "smtp.h"
@@ -469,6 +475,68 @@ struct hostrec *queryctl;
return(0);
}
+#ifdef KERBEROS_V4
+/*********************************************************************
+ function: kerberos_auth
+ description: Authenticate to the server host using Kerberos V4
+
+ arguments:
+ socket socket to server
+ servername server name
+
+ return value: exit code from the set of PS_.* constants defined in
+ fetchmail.h
+ calls:
+ globals: reads outlevel.
+ *********************************************************************/
+
+int
+kerberos_auth (socket, servername)
+ int socket;
+ char *servername;
+{
+ char * host_primary;
+ KTEXT ticket;
+ MSG_DAT msg_data;
+ CREDENTIALS cred;
+ Key_schedule schedule;
+ int rem;
+
+ /* Get the primary name of the host. */
+ {
+ struct hostent * hp = (gethostbyname (servername));
+ if (hp == 0)
+ {
+ fprintf (stderr, "MAILHOST unknown: %s\n", servername);
+ return (PS_ERROR);
+ }
+ host_primary = ((char *) (malloc ((strlen (hp -> h_name)) + 1)));
+ strcpy (host_primary, (hp -> h_name));
+ }
+
+ ticket = ((KTEXT) (malloc (sizeof (KTEXT_ST))));
+ rem
+ = (krb_sendauth (0L, socket, ticket, "pop",
+ host_primary,
+ ((char *) (krb_realmofhost (host_primary))),
+ ((unsigned long) 0),
+ (&msg_data),
+ (&cred),
+ (schedule),
+ ((struct sockaddr_in *) 0),
+ ((struct sockaddr_in *) 0),
+ "KPOPV0.1"));
+ free (ticket);
+ free (host_primary);
+ if (rem != KSUCCESS)
+ {
+ fprintf (stderr, "kerberos error: %s\n", (krb_get_err_text (rem)));
+ return (PS_ERROR);
+ }
+ return (0);
+}
+#endif /* KERBEROS_V4 */
+
/*********************************************************************
function: do_protocol
description: retrieve messages from the specified mail server
@@ -499,6 +567,7 @@ struct method *proto;
alarmed = 0;
sigsave = signal(SIGALRM, alarm_handler);
alarm (timeout);
+
/* lacking methods, there are some options that may fail */
if (!proto->is_old)
{
@@ -536,11 +605,11 @@ struct method *proto;
#ifdef KERBEROS_V4
if (queryctl->protocol == P_KPOP)
- {
- ok = (pop3_kerberos_auth (socket, queryctl));
+ {
+ ok = (kerberos_auth (socket, queryctl->servername));
if (ok != 0)
- goto cleanUp;
- }
+ goto cleanUp;
+ }
#endif
/* accept greeting message from mail server */
diff --git a/pop3.c b/pop3.c
index 47c0bc17..fc21ec64 100644
--- a/pop3.c
+++ b/pop3.c
@@ -15,14 +15,6 @@
#include <config.h>
#include <stdio.h>
-#ifdef KERBEROS_V4
-#include <krb.h>
-#include <des.h>
-/* <netinet/in.h> must be included before "socket.h". */
-#include <netinet/in.h>
-#include <netdb.h>
-#endif
-
#include "socket.h"
#include "fetchmail.h"
@@ -113,6 +105,7 @@ char *greeting;
strcat (buf, "KPOP support not compiled into this executable.\n");
return(PS_ERROR);
#endif
+ /* fall through */
case P_POP3:
if ((gen_transact(socket,"USER %s", queryctl->remotename)) != 0)
@@ -136,54 +129,6 @@ char *greeting;
return(0);
}
-#ifdef KERBEROS_V4
-int
-pop3_kerberos_auth (socket, queryctl)
- int socket;
- struct hostrec * queryctl;
-{
- char * host_primary;
- KTEXT ticket;
- MSG_DAT msg_data;
- CREDENTIALS cred;
- Key_schedule schedule;
- int rem;
-
- /* Get the primary name of the host. */
- {
- struct hostent * hp = (gethostbyname (queryctl->servername));
- if (hp == 0)
- {
- fprintf (stderr, "MAILHOST unknown: %s\n", queryctl->servername);
- return (PS_ERROR);
- }
- host_primary = ((char *) (malloc ((strlen (hp -> h_name)) + 1)));
- strcpy (host_primary, (hp -> h_name));
- }
-
- ticket = ((KTEXT) (malloc (sizeof (KTEXT_ST))));
- rem
- = (krb_sendauth (0L, socket, ticket, "pop",
- host_primary,
- ((char *) (krb_realmofhost (host_primary))),
- ((unsigned long) 0),
- (&msg_data),
- (&cred),
- (schedule),
- ((struct sockaddr_in *) 0),
- ((struct sockaddr_in *) 0),
- "KPOPV0.1"));
- free (ticket);
- free (host_primary);
- if (rem != KSUCCESS)
- {
- fprintf (stderr, "kerberos error: %s\n", (krb_get_err_text (rem)));
- return (PS_ERROR);
- }
- return (0);
-}
-#endif /* KERBEROS_V4 */
-
static pop3_getrange(socket, queryctl, countp)
/* get range of messages to be fetched */
int socket;