rework some things with sasl.
[apps/madmutt.git] / pop / pop_auth.c
index eb575bf..976317c 100644 (file)
@@ -7,31 +7,18 @@
  * please see the file GPL in the top level source directory.
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include <lib-lib/lib-lib.h>
 
-#include <lib-lib/mem.h>
-#include <lib-lib/ascii.h>
-#include <lib-lib/macros.h>
 #include <lib-hash/hash.h>
-#include <lib-lib/debug.h>
+#include <lib-mx/mx.h>
 
 #include "mutt.h"
-#include "mx.h"
 #include "pop.h"
 
-
-#include <string.h>
-#include <unistd.h>
-
-#ifdef USE_SASL
 #include <sasl/sasl.h>
 #include <sasl/saslutil.h>
 #include "mutt_sasl.h"
-#endif
 
-#ifdef USE_SASL
 /* SASL authenticator */
 static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
 {
@@ -42,14 +29,11 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
   char inbuf[LONG_STRING];
   const char *mech;
 
-#ifdef USE_SASL
   const char *pc = NULL;
-#endif
   unsigned int len, olen;
   unsigned char client_start;
 
   if (mutt_sasl_client_new (pop_data->conn, &saslconn) < 0) {
-    debug_print (1, ("Error allocating SASL connection.\n"));
     return POP_A_FAILURE;
   }
 
@@ -57,18 +41,14 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
     method = pop_data->auth_list;
 
   for (;;) {
-#ifdef USE_SASL
-    rc =
-      sasl_client_start (saslconn, method, &interaction, &pc, &olen, &mech);
-#endif
+    rc = sasl_client_start (saslconn, method, &interaction, &pc, &olen,
+                            &mech);
     if (rc != SASL_INTERACT)
       break;
     mutt_sasl_interact (interaction);
   }
 
   if (rc != SASL_OK && rc != SASL_CONTINUE) {
-    debug_print (1, ("Failure starting authentication exchange. No shared mechanisms?\n"));
-
     /* SASL doesn't support suggested mechanisms, so fall back */
     return POP_A_UNAVAIL;
   }
@@ -93,13 +73,10 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
     if (rc != SASL_CONTINUE)
       break;
 
-#ifdef USE_SASL
     if (!m_strncmp(inbuf, "+ ", 2)
         && sasl_decode64 (inbuf, strlen (inbuf), buf, LONG_STRING - 1,
                           &len) != SASL_OK)
-#endif
     {
-      debug_print (1, ("error base64-decoding server response.\n"));
       goto bail;
     }
 
@@ -119,15 +96,12 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
     /* send out response, or line break if none needed */
     if (pc) {
       if (sasl_encode64 (pc, olen, buf, sizeof (buf), &olen) != SASL_OK) {
-        debug_print (1, ("error base64-encoding client response.\n"));
         goto bail;
       }
 
       /* sasl_client_st(art|ep) allocate pc with malloc, expect me to 
        * free it */
-#ifndef USE_SASL
-      p_delete(&pc);
-#endif
+      p_delete((char **)&pc);
     }
   }
 
@@ -155,7 +129,6 @@ bail:
 
   return POP_A_FAILURE;
 }
-#endif
 
 /* Get the server timestamp for APOP authentication */
 void pop_apop_timestamp (POP_DATA * pop_data, char *buf)
@@ -235,14 +208,11 @@ static pop_auth_res_t pop_auth_user (POP_DATA * pop_data,
   if (pop_data->cmd_user == CMD_UNKNOWN) {
     if (ret == PQ_OK) {
       pop_data->cmd_user = CMD_AVAILABLE;
-
-      debug_print (1, ("set USER capability\n"));
     }
 
     if (ret == PQ_ERR) {
       pop_data->cmd_user = CMD_NOT_AVAILABLE;
 
-      debug_print (1, ("unset USER capability\n"));
       snprintf (pop_data->err_msg, sizeof (pop_data->err_msg),
                 _("Command USER is not supported by server."));
     }
@@ -250,12 +220,7 @@ static pop_auth_res_t pop_auth_user (POP_DATA * pop_data,
 
   if (ret == PQ_OK) {
     snprintf (buf, sizeof (buf), "PASS %s\r\n", pop_data->conn->account.pass);
-    ret = pop_query_d (pop_data, buf, sizeof (buf),
-#ifdef DEBUG
-    /* don't print the password unless we're at the ungodly debugging level */
-    DebugLevel < M_SOCK_LOG_FULL ? "PASS *\r\n" :
-#endif
-    NULL);
+    ret = pop_query (pop_data, buf, sizeof (buf));
   }
 
   switch (ret) {
@@ -276,9 +241,7 @@ static pop_auth_res_t pop_auth_user (POP_DATA * pop_data,
 }
 
 static pop_auth_t pop_authenticators[] = {
-#ifdef USE_SASL
   {pop_auth_sasl, NULL},
-#endif
   {pop_auth_apop, "apop"},
   {pop_auth_user, "user"},
   {NULL, NULL}
@@ -314,7 +277,6 @@ pop_query_status pop_authenticate (POP_DATA * pop_data)
       comma = strchr (method, ':');
       if (comma)
         *comma++ = '\0';
-      debug_print (2, ("Trying method %s\n", method));
       authenticator = pop_authenticators;
 
       while (authenticator->authenticate) {
@@ -350,7 +312,6 @@ pop_query_status pop_authenticate (POP_DATA * pop_data)
   }
   else {
     /* Fall back to default: any authenticator */
-    debug_print (2, ("Using any available method.\n"));
     authenticator = pop_authenticators;
 
     while (authenticator->authenticate) {