]> diplodocus.org Git - nmh/commitdiff
Fixed popsbr.c to look like its nmh 1.5 version, except it now
authorDavid Levine <levinedl@acm.org>
Wed, 16 Apr 2014 02:57:30 +0000 (21:57 -0500)
committerDavid Levine <levinedl@acm.org>
Wed, 16 Apr 2014 02:57:30 +0000 (21:57 -0500)
uses nmh_get_credentials() instead of ruserpass() directly.  Also,
added checks of return values of nmh_get_credentials() to smtp.c.

mts/smtp/smtp.c
uip/popsbr.c

index 0261d6d..f415444 100644 (file)
@@ -1059,7 +1059,9 @@ sm_get_user(void *context, int id, const char **result, unsigned *len)
          * That's used when those values really don't matter, and only
          * with legacy/.netrc, i.e., with a credentials profile entry.
          */
          * That's used when those values really don't matter, and only
          * with legacy/.netrc, i.e., with a credentials profile entry.
          */
-        nmh_get_credentials (creds->host, creds->user, 1, creds);
+        if (nmh_get_credentials (creds->host, creds->user, 1, creds) != OK) {
+            return SASL_BADPARAM;
+        }
     }
 
     *result = creds->user;
     }
 
     *result = creds->user;
@@ -1086,9 +1088,11 @@ sm_get_pass(sasl_conn_t *conn, void *context, int id,
          * Pass the 0 third argument to nmh_get_credentials() so
          * that the default password isn't used.  With legacy/.netrc
          * credentials support, we'll only get here if the -user
          * Pass the 0 third argument to nmh_get_credentials() so
          * that the default password isn't used.  With legacy/.netrc
          * credentials support, we'll only get here if the -user
-         * switch to send(1)/post(8) wasn used.
+         * switch to send(1)/post(8) wasn't used.
          */
          */
-        nmh_get_credentials (creds->host, creds->user, 0, creds);
+        if (nmh_get_credentials (creds->host, creds->user, 0, creds) != OK) {
+            return SASL_BADPARAM;
+        }
     }
 
     len = strlen (creds->password);
     }
 
     len = strlen (creds->password);
index be0540c..2eb823c 100644 (file)
@@ -70,7 +70,7 @@ static int command(const char *, ...);
 static int multiline(void);
 
 #ifdef CYRUS_SASL
 static int multiline(void);
 
 #ifdef CYRUS_SASL
-static int pop_auth_sasl(char *, char *, char *, char *);
+static int pop_auth_sasl(char *, char *, char *);
 static int sasl_fgetc(FILE *);
 #endif /* CYRUS_SASL */
 
 static int sasl_fgetc(FILE *);
 #endif /* CYRUS_SASL */
 
@@ -90,7 +90,7 @@ static int putline (char *, FILE *);
  */
 
 int
  */
 
 int
-pop_auth_sasl(char *user, char *password, char *host, char *mech)
+pop_auth_sasl(char *user, char *host, char *mech)
 {
     int result, status, sasl_capability = 0;
     unsigned int buflen, outlen;
 {
     int result, status, sasl_capability = 0;
     unsigned int buflen, outlen;
@@ -158,7 +158,6 @@ pop_auth_sasl(char *user, char *password, char *host, char *mech)
     callbacks[POP_SASL_CB_N_USER].context = user;
     p_context.user = user;
     p_context.host = host;
     callbacks[POP_SASL_CB_N_USER].context = user;
     p_context.user = user;
     p_context.host = host;
-    p_context.password = password;
     callbacks[POP_SASL_CB_N_PASS].context = &p_context;
 
     result = sasl_client_init(callbacks);
     callbacks[POP_SASL_CB_N_PASS].context = &p_context;
 
     result = sasl_client_init(callbacks);
@@ -351,7 +350,7 @@ static int
 sasl_get_pass(sasl_conn_t *conn, void *context, int id, sasl_secret_t **psecret)
 {
     struct pass_context *p_context = (struct pass_context *) context;
 sasl_get_pass(sasl_conn_t *conn, void *context, int id, sasl_secret_t **psecret)
 {
     struct pass_context *p_context = (struct pass_context *) context;
-    char *pass = p_context->password;
+    struct nmh_creds creds = { 0, 0, 0 };
     int len;
 
     NMH_UNUSED (conn);
     int len;
 
     NMH_UNUSED (conn);
@@ -359,12 +358,25 @@ sasl_get_pass(sasl_conn_t *conn, void *context, int id, sasl_secret_t **psecret)
     if (! psecret || id != SASL_CB_PASS)
        return SASL_BADPARAM;
 
     if (! psecret || id != SASL_CB_PASS)
        return SASL_BADPARAM;
 
-    len = strlen(pass);
+    if (creds.password == NULL) {
+        /*
+         * Pass the 0 third argument to nmh_get_credentials() so
+         * that the default password isn't used.  With legacy/.netrc
+         * credentials support, we'll only get here if the -user
+         * switch to send(1)/post(8) wasn't used.
+         */
+        if (nmh_get_credentials (p_context->host, p_context->user, 0, &creds)
+            != OK) {
+            return SASL_BADPARAM;
+        }
+    }
+
+    len = strlen (creds.password);
 
     *psecret = (sasl_secret_t *) mh_xmalloc(sizeof(sasl_secret_t) + len);
 
     (*psecret)->len = len;
 
     *psecret = (sasl_secret_t *) mh_xmalloc(sizeof(sasl_secret_t) + len);
 
     (*psecret)->len = len;
-    strcpy((char *) (*psecret)->data, pass);
+    strcpy((char *) (*psecret)->data, creds.password);
 
     return SASL_OK;
 }
 
     return SASL_OK;
 }
@@ -505,7 +517,7 @@ pop_init (char *host, char *port, char *user, char *pass, char *proxy,
            if (*response == '+') {
 #  ifdef CYRUS_SASL
                if (sasl) {
            if (*response == '+') {
 #  ifdef CYRUS_SASL
                if (sasl) {
-                   if (pop_auth_sasl(user, pass, host, mech) != NOTOK)
+                   if (pop_auth_sasl(user, host, mech) != NOTOK)
                        return OK;
                } else
 #  endif /* CYRUS_SASL */
                        return OK;
                } else
 #  endif /* CYRUS_SASL */