Commit 43400b40 authored by Steve Holme's avatar Steve Holme
Browse files

email: Post graceful SASL authentication cancellation tidy up

parent 8179354c
Loading
Loading
Loading
Loading
+1 −3
Original line number Original line Diff line number Diff line
@@ -10,9 +10,7 @@ Curl and libcurl 7.33.1
This release includes the following changes:
This release includes the following changes:


 o SSL: protocol version can be specified more precisely [1]
 o SSL: protocol version can be specified more precisely [1]
 o email: Added support for cancelling NTLM authentication
 o imap/pop3/smtp: Added graceful cancellation of SASL authentication
 o email: Added support for cancelling DIGEST-MD5 authentication
 o email: Added support for canceling CRAM-MD5 authentication
 o Add "Happy Eyeballs" for IPv4/IPv6 dual connect attempts
 o Add "Happy Eyeballs" for IPv4/IPv6 dual connect attempts


This release includes the following bugfixes:
This release includes the following bugfixes:
+6 −7
Original line number Original line Diff line number Diff line
@@ -559,14 +559,14 @@ CURLcode Curl_sasl_create_ntlm_type3_message(struct SessionHandle *data,
/*
/*
 * Curl_sasl_create_xoauth2_message()
 * Curl_sasl_create_xoauth2_message()
 *
 *
 * This is used to generate an already encoded XOAUTH2 message ready
 * This is used to generate an already encoded OAuth 2.0 message ready for
 * for sending to the recipient.
 * sending to the recipient.
 *
 *
 * Parameters:
 * Parameters:
 *
 *
 * data    [in]     - The session handle.
 * data    [in]     - The session handle.
 * user    [in]     - The user name.
 * user    [in]     - The user name.
 * bearer  [in]     - The XOAUTH Bearer token.
 * bearer  [in]     - The bearer token.
 * outptr  [in/out] - The address where a pointer to newly allocated memory
 * outptr  [in/out] - The address where a pointer to newly allocated memory
 *                    holding the result will be stored upon completion.
 *                    holding the result will be stored upon completion.
 * outlen  [out]    - The length of the output message.
 * outlen  [out]    - The length of the output message.
@@ -579,16 +579,15 @@ CURLcode Curl_sasl_create_xoauth2_message(struct SessionHandle *data,
                                          char **outptr, size_t *outlen)
                                          char **outptr, size_t *outlen)
{
{
  CURLcode result = CURLE_OK;
  CURLcode result = CURLE_OK;
  char *xoauth;
  char *xoauth = NULL;


  /* Generate the message */
  xoauth = aprintf("user=%s\1auth=Bearer %s\1\1", user, bearer);
  xoauth = aprintf("user=%s\1auth=Bearer %s\1\1", user, bearer);

  if(!xoauth)
  if(!xoauth)
    return CURLE_OUT_OF_MEMORY;
    return CURLE_OUT_OF_MEMORY;


  /* Base64 encode the reply */
  /* Base64 encode the reply */
  result = Curl_base64_encode(data, xoauth, strlen(xoauth), outptr,
  result = Curl_base64_encode(data, xoauth, strlen(xoauth), outptr, outlen);
                              outlen);


  Curl_safefree(xoauth);
  Curl_safefree(xoauth);


+35 −50
Original line number Original line Diff line number Diff line
@@ -1007,19 +1007,16 @@ static CURLcode imap_state_auth_plain_resp(struct connectdata *conn,
    /* Create the authorisation message */
    /* Create the authorisation message */
    result = Curl_sasl_create_plain_message(data, conn->user, conn->passwd,
    result = Curl_sasl_create_plain_message(data, conn->user, conn->passwd,
                                            &plainauth, &len);
                                            &plainauth, &len);

    if(!result && plainauth) {
      /* Send the message */
      /* Send the message */
    if(!result) {
      if(plainauth) {
      result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", plainauth);
      result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", plainauth);


      if(!result)
      if(!result)
        state(conn, IMAP_AUTHENTICATE_FINAL);
        state(conn, IMAP_AUTHENTICATE_FINAL);
    }
    }
  }


  Curl_safefree(plainauth);
  Curl_safefree(plainauth);
    }
  }


  return result;
  return result;
}
}
@@ -1044,19 +1041,16 @@ static CURLcode imap_state_auth_login_resp(struct connectdata *conn,
    /* Create the user message */
    /* Create the user message */
    result = Curl_sasl_create_login_message(data, conn->user,
    result = Curl_sasl_create_login_message(data, conn->user,
                                            &authuser, &len);
                                            &authuser, &len);

    if(!result && authuser) {
      /* Send the user */
      /* Send the user */
    if(!result) {
      if(authuser) {
      result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", authuser);
      result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", authuser);


      if(!result)
      if(!result)
        state(conn, IMAP_AUTHENTICATE_LOGIN_PASSWD);
        state(conn, IMAP_AUTHENTICATE_LOGIN_PASSWD);
    }
    }
  }


  Curl_safefree(authuser);
  Curl_safefree(authuser);
    }
  }


  return result;
  return result;
}
}
@@ -1081,19 +1075,16 @@ static CURLcode imap_state_auth_login_password_resp(struct connectdata *conn,
    /* Create the password message */
    /* Create the password message */
    result = Curl_sasl_create_login_message(data, conn->passwd,
    result = Curl_sasl_create_login_message(data, conn->passwd,
                                            &authpasswd, &len);
                                            &authpasswd, &len);

    if(!result && authpasswd) {
      /* Send the password */
      /* Send the password */
    if(!result) {
      if(authpasswd) {
      result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", authpasswd);
      result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", authpasswd);


      if(!result)
      if(!result)
        state(conn, IMAP_AUTHENTICATE_FINAL);
        state(conn, IMAP_AUTHENTICATE_FINAL);
    }
    }
  }


  Curl_safefree(authpasswd);
  Curl_safefree(authpasswd);
    }
  }


  return result;
  return result;
}
}
@@ -1252,19 +1243,16 @@ static CURLcode imap_state_auth_ntlm_resp(struct connectdata *conn,
    result = Curl_sasl_create_ntlm_type1_message(conn->user, conn->passwd,
    result = Curl_sasl_create_ntlm_type1_message(conn->user, conn->passwd,
                                                 &conn->ntlm,
                                                 &conn->ntlm,
                                                 &type1msg, &len);
                                                 &type1msg, &len);

    if(!result && type1msg) {
      /* Send the message */
      /* Send the message */
    if(!result) {
      if(type1msg) {
      result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", type1msg);
      result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", type1msg);


      if(!result)
      if(!result)
        state(conn, IMAP_AUTHENTICATE_NTLM_TYPE2MSG);
        state(conn, IMAP_AUTHENTICATE_NTLM_TYPE2MSG);
    }
    }
  }


  Curl_safefree(type1msg);
  Curl_safefree(type1msg);
    }
  }


  return result;
  return result;
}
}
@@ -1341,19 +1329,16 @@ static CURLcode imap_state_auth_xoauth2_resp(struct connectdata *conn,
    result = Curl_sasl_create_xoauth2_message(conn->data, conn->user,
    result = Curl_sasl_create_xoauth2_message(conn->data, conn->user,
                                              conn->xoauth2_bearer,
                                              conn->xoauth2_bearer,
                                              &xoauth, &len);
                                              &xoauth, &len);

    if(!result && xoauth) {
      /* Send the message */
      /* Send the message */
    if(!result) {
      if(xoauth) {
      result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", xoauth);
      result = Curl_pp_sendf(&conn->proto.imapc.pp, "%s", xoauth);


      if(!result)
      if(!result)
        state(conn, IMAP_AUTHENTICATE_FINAL);
        state(conn, IMAP_AUTHENTICATE_FINAL);
    }
    }
  }


  Curl_safefree(xoauth);
  Curl_safefree(xoauth);
    }
  }


  return result;
  return result;
}
}
+35 −50
Original line number Original line Diff line number Diff line
@@ -865,19 +865,16 @@ static CURLcode pop3_state_auth_plain_resp(struct connectdata *conn,
    /* Create the authorisation message */
    /* Create the authorisation message */
    result = Curl_sasl_create_plain_message(data, conn->user, conn->passwd,
    result = Curl_sasl_create_plain_message(data, conn->user, conn->passwd,
                                            &plainauth, &len);
                                            &plainauth, &len);

    if(!result && plainauth) {
      /* Send the message */
      /* Send the message */
    if(!result) {
      if(plainauth) {
      result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", plainauth);
      result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", plainauth);


      if(!result)
      if(!result)
        state(conn, POP3_AUTH_FINAL);
        state(conn, POP3_AUTH_FINAL);
    }
    }
  }


  Curl_safefree(plainauth);
  Curl_safefree(plainauth);
    }
  }


  return result;
  return result;
}
}
@@ -902,19 +899,16 @@ static CURLcode pop3_state_auth_login_resp(struct connectdata *conn,
    /* Create the user message */
    /* Create the user message */
    result = Curl_sasl_create_login_message(data, conn->user,
    result = Curl_sasl_create_login_message(data, conn->user,
                                            &authuser, &len);
                                            &authuser, &len);

    if(!result && authuser) {
      /* Send the user */
      /* Send the user */
    if(!result) {
      if(authuser) {
      result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", authuser);
      result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", authuser);


      if(!result)
      if(!result)
        state(conn, POP3_AUTH_LOGIN_PASSWD);
        state(conn, POP3_AUTH_LOGIN_PASSWD);
    }
    }
  }


  Curl_safefree(authuser);
  Curl_safefree(authuser);
    }
  }


  return result;
  return result;
}
}
@@ -939,19 +933,16 @@ static CURLcode pop3_state_auth_login_password_resp(struct connectdata *conn,
    /* Create the password message */
    /* Create the password message */
    result = Curl_sasl_create_login_message(data, conn->passwd,
    result = Curl_sasl_create_login_message(data, conn->passwd,
                                            &authpasswd, &len);
                                            &authpasswd, &len);

    if(!result && authpasswd) {
      /* Send the password */
      /* Send the password */
    if(!result) {
      if(authpasswd) {
      result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", authpasswd);
      result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", authpasswd);


      if(!result)
      if(!result)
        state(conn, POP3_AUTH_FINAL);
        state(conn, POP3_AUTH_FINAL);
    }
    }
  }


  Curl_safefree(authpasswd);
  Curl_safefree(authpasswd);
    }
  }


  return result;
  return result;
}
}
@@ -1110,19 +1101,16 @@ static CURLcode pop3_state_auth_ntlm_resp(struct connectdata *conn,
    result = Curl_sasl_create_ntlm_type1_message(conn->user, conn->passwd,
    result = Curl_sasl_create_ntlm_type1_message(conn->user, conn->passwd,
                                                 &conn->ntlm,
                                                 &conn->ntlm,
                                                 &type1msg, &len);
                                                 &type1msg, &len);

    if(!result && type1msg) {
      /* Send the message */
      /* Send the message */
    if(!result) {
      if(type1msg) {
      result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", type1msg);
      result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", type1msg);


      if(!result)
      if(!result)
        state(conn, POP3_AUTH_NTLM_TYPE2MSG);
        state(conn, POP3_AUTH_NTLM_TYPE2MSG);
    }
    }
  }


  Curl_safefree(type1msg);
  Curl_safefree(type1msg);
    }
  }


  return result;
  return result;
}
}
@@ -1198,19 +1186,16 @@ static CURLcode pop3_state_auth_xoauth2_resp(struct connectdata *conn,
    result = Curl_sasl_create_xoauth2_message(conn->data, conn->user,
    result = Curl_sasl_create_xoauth2_message(conn->data, conn->user,
                                              conn->xoauth2_bearer,
                                              conn->xoauth2_bearer,
                                              &xoauth, &len);
                                              &xoauth, &len);

    if(!result && xoauth) {
      /* Send the message */
      /* Send the message */
    if(!result) {
      if(xoauth) {
      result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", xoauth);
      result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", xoauth);


      if(!result)
      if(!result)
        state(conn, POP3_AUTH_FINAL);
        state(conn, POP3_AUTH_FINAL);
    }
    }
  }


  Curl_safefree(xoauth);
  Curl_safefree(xoauth);
    }
  }


  return result;
  return result;
}
}
+35 −50
Original line number Original line Diff line number Diff line
@@ -845,19 +845,16 @@ static CURLcode smtp_state_auth_plain_resp(struct connectdata *conn,
    /* Create the authorisation message */
    /* Create the authorisation message */
    result = Curl_sasl_create_plain_message(conn->data, conn->user,
    result = Curl_sasl_create_plain_message(conn->data, conn->user,
                                            conn->passwd, &plainauth, &len);
                                            conn->passwd, &plainauth, &len);

    if(!result && plainauth) {
      /* Send the message */
      /* Send the message */
    if(!result) {
      if(plainauth) {
      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", plainauth);
      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", plainauth);


      if(!result)
      if(!result)
        state(conn, SMTP_AUTH_FINAL);
        state(conn, SMTP_AUTH_FINAL);
    }
    }
  }


  Curl_safefree(plainauth);
  Curl_safefree(plainauth);
    }
  }


  return result;
  return result;
}
}
@@ -882,19 +879,16 @@ static CURLcode smtp_state_auth_login_resp(struct connectdata *conn,
    /* Create the user message */
    /* Create the user message */
    result = Curl_sasl_create_login_message(conn->data, conn->user,
    result = Curl_sasl_create_login_message(conn->data, conn->user,
                                            &authuser, &len);
                                            &authuser, &len);

    if(!result && authuser) {
      /* Send the user */
      /* Send the user */
    if(!result) {
      if(authuser) {
      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", authuser);
      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", authuser);


      if(!result)
      if(!result)
        state(conn, SMTP_AUTH_LOGIN_PASSWD);
        state(conn, SMTP_AUTH_LOGIN_PASSWD);
    }
    }
  }


  Curl_safefree(authuser);
  Curl_safefree(authuser);
    }
  }


  return result;
  return result;
}
}
@@ -919,19 +913,16 @@ static CURLcode smtp_state_auth_login_password_resp(struct connectdata *conn,
    /* Create the password message */
    /* Create the password message */
    result = Curl_sasl_create_login_message(conn->data, conn->passwd,
    result = Curl_sasl_create_login_message(conn->data, conn->passwd,
                                            &authpasswd, &len);
                                            &authpasswd, &len);

    if(!result && authpasswd) {
      /* Send the password */
      /* Send the password */
    if(!result) {
      if(authpasswd) {
      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", authpasswd);
      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", authpasswd);


      if(!result)
      if(!result)
        state(conn, SMTP_AUTH_FINAL);
        state(conn, SMTP_AUTH_FINAL);
    }
    }
  }


  Curl_safefree(authpasswd);
  Curl_safefree(authpasswd);
    }
  }


  return result;
  return result;
}
}
@@ -1091,19 +1082,16 @@ static CURLcode smtp_state_auth_ntlm_resp(struct connectdata *conn,
    result = Curl_sasl_create_ntlm_type1_message(conn->user, conn->passwd,
    result = Curl_sasl_create_ntlm_type1_message(conn->user, conn->passwd,
                                                 &conn->ntlm,
                                                 &conn->ntlm,
                                                 &type1msg, &len);
                                                 &type1msg, &len);

    if(!result && type1msg) {
      /* Send the message */
      /* Send the message */
    if(!result) {
      if(type1msg) {
      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", type1msg);
      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", type1msg);


      if(!result)
      if(!result)
        state(conn, SMTP_AUTH_NTLM_TYPE2MSG);
        state(conn, SMTP_AUTH_NTLM_TYPE2MSG);
    }
    }
  }


  Curl_safefree(type1msg);
  Curl_safefree(type1msg);
    }
  }


  return result;
  return result;
}
}
@@ -1179,19 +1167,16 @@ static CURLcode smtp_state_auth_xoauth2_resp(struct connectdata *conn,
    result = Curl_sasl_create_xoauth2_message(conn->data, conn->user,
    result = Curl_sasl_create_xoauth2_message(conn->data, conn->user,
                                              conn->xoauth2_bearer,
                                              conn->xoauth2_bearer,
                                              &xoauth, &len);
                                              &xoauth, &len);

    if(!result && xoauth) {
      /* Send the message */
      /* Send the message */
    if(!result) {
      if(xoauth) {
      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", xoauth);
      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", xoauth);


      if(!result)
      if(!result)
        state(conn, SMTP_AUTH_FINAL);
        state(conn, SMTP_AUTH_FINAL);
    }
    }
  }


  Curl_safefree(xoauth);
  Curl_safefree(xoauth);
    }
  }


  return result;
  return result;
}
}