Rocco Rutte:
[apps/madmutt.git] / pop / pop_auth.c
index 2583e18..df6de73 100644 (file)
@@ -16,6 +16,9 @@
 #include "md5.h"
 #include "pop.h"
 
+#include "lib/mem.h"
+#include "lib/intl.h"
+
 #include <string.h>
 #include <unistd.h>
 
@@ -103,11 +106,11 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
       break;
 
 #ifdef USE_SASL2
-    if (!mutt_strncmp (inbuf, "+ ", 2)
+    if (!safe_strncmp (inbuf, "+ ", 2)
         && sasl_decode64 (inbuf, strlen (inbuf), buf, LONG_STRING - 1,
                           &len) != SASL_OK)
 #else
-    if (!mutt_strncmp (inbuf, "+ ", 2)
+    if (!safe_strncmp (inbuf, "+ ", 2)
         && sasl_decode64 (inbuf, strlen (inbuf), buf, &len) != SASL_OK)
 #endif
     {
@@ -150,7 +153,7 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
   if (rc != SASL_OK)
     goto bail;
 
-  if (!mutt_strncmp (inbuf, "+OK", 3)) {
+  if (!safe_strncmp (inbuf, "+OK", 3)) {
     mutt_sasl_setup_conn (pop_data->conn, saslconn);
     return POP_A_SUCCESS;
   }
@@ -159,9 +162,9 @@ bail:
   sasl_dispose (&saslconn);
 
   /* terminate SASL sessoin if the last responce is not +OK nor -ERR */
-  if (!mutt_strncmp (inbuf, "+ ", 2)) {
+  if (!safe_strncmp (inbuf, "+ ", 2)) {
     snprintf (buf, sizeof (buf), "*\r\n");
-    if (pop_query (pop_data, buf, sizeof (buf)) == -1)
+    if (pop_query (pop_data, buf, sizeof (buf)) == PQ_NOT_CONNECTED)
       return POP_A_SOCKET;
   }
 
@@ -216,9 +219,9 @@ static pop_auth_res_t pop_auth_apop (POP_DATA * pop_data, const char *method)
             hash);
 
   switch (pop_query (pop_data, buf, sizeof (buf))) {
-  case 0:
+  case PQ_OK:
     return POP_A_SUCCESS;
-  case -1:
+  case PQ_NOT_CONNECTED:
     return POP_A_SOCKET;
   }
 
@@ -233,9 +236,9 @@ static pop_auth_res_t pop_auth_apop (POP_DATA * pop_data, const char *method)
 static pop_auth_res_t pop_auth_user (POP_DATA * pop_data, const char *method)
 {
   char buf[LONG_STRING];
-  int ret;
+  pop_query_status ret;
 
-  if (!pop_data->cmd_user)
+  if (pop_data->cmd_user == CMD_NOT_AVAILABLE)
     return POP_A_UNAVAIL;
 
   mutt_message _("Logging in...");
@@ -243,15 +246,15 @@ static pop_auth_res_t pop_auth_user (POP_DATA * pop_data, const char *method)
   snprintf (buf, sizeof (buf), "USER %s\r\n", pop_data->conn->account.user);
   ret = pop_query (pop_data, buf, sizeof (buf));
 
-  if (pop_data->cmd_user == 2) {
-    if (ret == 0) {
-      pop_data->cmd_user = 1;
+  if (pop_data->cmd_user == CMD_UNKNOWN) {
+    if (ret == PQ_OK) {
+      pop_data->cmd_user = CMD_AVAILABLE;
 
       dprint (1, (debugfile, "pop_auth_user: set USER capability\n"));
     }
 
-    if (ret == -2) {
-      pop_data->cmd_user = 0;
+    if (ret == PQ_ERR) {
+      pop_data->cmd_user = CMD_NOT_AVAILABLE;
 
       dprint (1, (debugfile, "pop_auth_user: unset USER capability\n"));
       snprintf (pop_data->err_msg, sizeof (pop_data->err_msg),
@@ -259,7 +262,7 @@ static pop_auth_res_t pop_auth_user (POP_DATA * pop_data, const char *method)
     }
   }
 
-  if (ret == 0) {
+  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
@@ -270,9 +273,9 @@ static pop_auth_res_t pop_auth_user (POP_DATA * pop_data, const char *method)
   }
 
   switch (ret) {
-  case 0:
+  case PQ_OK:
     return POP_A_SUCCESS;
-  case -1:
+  case PQ_NOT_CONNECTED:
     return POP_A_SOCKET;
   }
 
@@ -298,7 +301,7 @@ static pop_auth_t pop_authenticators[] = {
  * -2 - login failed,
  * -3 - authentication canceled.
 */
-int pop_authenticate (POP_DATA * pop_data)
+pop_query_status pop_authenticate (POP_DATA * pop_data)
 {
   ACCOUNT *acct = &pop_data->conn->account;
   pop_auth_t *authenticator;
@@ -310,7 +313,7 @@ int pop_authenticate (POP_DATA * pop_data)
 
   if (mutt_account_getuser (acct) || !acct->user[0] ||
       mutt_account_getpass (acct) || !acct->pass[0])
-    return -3;
+    return PFD_FUNCT_ERROR;
 
   if (PopAuthenticators && *PopAuthenticators) {
     /* Try user-specified list of authentication methods */
@@ -330,12 +333,12 @@ int pop_authenticate (POP_DATA * pop_data)
           ret = authenticator->authenticate (pop_data, method);
           if (ret == POP_A_SOCKET)
             switch (pop_connect (pop_data)) {
-            case 0:
+            case PQ_OK:
               {
                 ret = authenticator->authenticate (pop_data, method);
                 break;
               }
-            case -2:
+            case PQ_ERR:
               ret = POP_A_FAILURE;
             }
 
@@ -365,13 +368,13 @@ int pop_authenticate (POP_DATA * pop_data)
       ret = authenticator->authenticate (pop_data, authenticator->method);
       if (ret == POP_A_SOCKET)
         switch (pop_connect (pop_data)) {
-        case 0:
+        case PQ_OK:
           {
             ret =
               authenticator->authenticate (pop_data, authenticator->method);
             break;
           }
-        case -2:
+        case PQ_ERR:
           ret = POP_A_FAILURE;
         }
 
@@ -387,13 +390,13 @@ int pop_authenticate (POP_DATA * pop_data)
 
   switch (ret) {
   case POP_A_SUCCESS:
-    return 0;
+    return PQ_OK;
   case POP_A_SOCKET:
-    return -1;
+    return PQ_NOT_CONNECTED;
   case POP_A_UNAVAIL:
     if (!attempts)
       mutt_error (_("No authenticators available"));
   }
 
-  return -2;
+  return PQ_ERR;
 }