curl_sasl.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2012 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * RFC2195 CRAM-MD5 authentication
  22. * RFC2617 Basic and Digest Access Authentication
  23. * RFC2831 DIGEST-MD5 authentication
  24. * RFC4422 Simple Authentication and Security Layer (SASL)
  25. * RFC4616 PLAIN authentication
  26. * RFC6749 OAuth 2.0 Authorization Framework
  27. * RFC7628 A Set of SASL Mechanisms for OAuth
  28. * Draft LOGIN SASL Mechanism <draft-murchison-sasl-login-00.txt>
  29. *
  30. ***************************************************************************/
  31. #include "curl_setup.h"
  32. #if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \
  33. !defined(CURL_DISABLE_POP3)
  34. #include <curl/curl.h>
  35. #include "urldata.h"
  36. #include "curl_base64.h"
  37. #include "curl_md5.h"
  38. #include "vauth/vauth.h"
  39. #include "vtls/vtls.h"
  40. #include "curl_hmac.h"
  41. #include "curl_sasl.h"
  42. #include "warnless.h"
  43. #include "strtok.h"
  44. #include "sendf.h"
  45. #include "non-ascii.h" /* included for Curl_convert_... prototypes */
  46. /* The last 3 #include files should be in this order */
  47. #include "curl_printf.h"
  48. #include "curl_memory.h"
  49. #include "memdebug.h"
  50. /* Supported mechanisms */
  51. static const struct {
  52. const char *name; /* Name */
  53. size_t len; /* Name length */
  54. unsigned int bit; /* Flag bit */
  55. } mechtable[] = {
  56. { "LOGIN", 5, SASL_MECH_LOGIN },
  57. { "PLAIN", 5, SASL_MECH_PLAIN },
  58. { "CRAM-MD5", 8, SASL_MECH_CRAM_MD5 },
  59. { "DIGEST-MD5", 10, SASL_MECH_DIGEST_MD5 },
  60. { "GSSAPI", 6, SASL_MECH_GSSAPI },
  61. { "EXTERNAL", 8, SASL_MECH_EXTERNAL },
  62. { "NTLM", 4, SASL_MECH_NTLM },
  63. { "XOAUTH2", 7, SASL_MECH_XOAUTH2 },
  64. { "OAUTHBEARER", 11, SASL_MECH_OAUTHBEARER },
  65. { ZERO_NULL, 0, 0 }
  66. };
  67. /*
  68. * Curl_sasl_cleanup()
  69. *
  70. * This is used to cleanup any libraries or curl modules used by the sasl
  71. * functions.
  72. *
  73. * Parameters:
  74. *
  75. * conn [in] - The connection data.
  76. * authused [in] - The authentication mechanism used.
  77. */
  78. void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused)
  79. {
  80. #if defined(USE_KERBEROS5)
  81. /* Cleanup the gssapi structure */
  82. if(authused == SASL_MECH_GSSAPI) {
  83. Curl_auth_cleanup_gssapi(&conn->krb5);
  84. }
  85. #endif
  86. #if defined(USE_NTLM)
  87. /* Cleanup the NTLM structure */
  88. if(authused == SASL_MECH_NTLM) {
  89. Curl_auth_cleanup_ntlm(&conn->ntlm);
  90. }
  91. #endif
  92. #if !defined(USE_KERBEROS5) && !defined(USE_NTLM)
  93. /* Reserved for future use */
  94. (void)conn;
  95. (void)authused;
  96. #endif
  97. }
  98. /*
  99. * Curl_sasl_decode_mech()
  100. *
  101. * Convert a SASL mechanism name into a token.
  102. *
  103. * Parameters:
  104. *
  105. * ptr [in] - The mechanism string.
  106. * maxlen [in] - Maximum mechanism string length.
  107. * len [out] - If not NULL, effective name length.
  108. *
  109. * Returns the SASL mechanism token or 0 if no match.
  110. */
  111. unsigned int Curl_sasl_decode_mech(const char *ptr, size_t maxlen, size_t *len)
  112. {
  113. unsigned int i;
  114. char c;
  115. for(i = 0; mechtable[i].name; i++) {
  116. if(maxlen >= mechtable[i].len &&
  117. !memcmp(ptr, mechtable[i].name, mechtable[i].len)) {
  118. if(len)
  119. *len = mechtable[i].len;
  120. if(maxlen == mechtable[i].len)
  121. return mechtable[i].bit;
  122. c = ptr[mechtable[i].len];
  123. if(!ISUPPER(c) && !ISDIGIT(c) && c != '-' && c != '_')
  124. return mechtable[i].bit;
  125. }
  126. }
  127. return 0;
  128. }
  129. /*
  130. * Curl_sasl_parse_url_auth_option()
  131. *
  132. * Parse the URL login options.
  133. */
  134. CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
  135. const char *value, size_t len)
  136. {
  137. CURLcode result = CURLE_OK;
  138. size_t mechlen;
  139. if(!len)
  140. return CURLE_URL_MALFORMAT;
  141. if(sasl->resetprefs) {
  142. sasl->resetprefs = FALSE;
  143. sasl->prefmech = SASL_AUTH_NONE;
  144. }
  145. if(!strncmp(value, "*", len))
  146. sasl->prefmech = SASL_AUTH_DEFAULT;
  147. else {
  148. unsigned int mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
  149. if(mechbit && mechlen == len)
  150. sasl->prefmech |= mechbit;
  151. else
  152. result = CURLE_URL_MALFORMAT;
  153. }
  154. return result;
  155. }
  156. /*
  157. * Curl_sasl_init()
  158. *
  159. * Initializes the SASL structure.
  160. */
  161. void Curl_sasl_init(struct SASL *sasl, const struct SASLproto *params)
  162. {
  163. sasl->params = params; /* Set protocol dependent parameters */
  164. sasl->state = SASL_STOP; /* Not yet running */
  165. sasl->authmechs = SASL_AUTH_NONE; /* No known authentication mechanism yet */
  166. sasl->prefmech = SASL_AUTH_DEFAULT; /* Prefer all mechanisms */
  167. sasl->authused = SASL_AUTH_NONE; /* No the authentication mechanism used */
  168. sasl->resetprefs = TRUE; /* Reset prefmech upon AUTH parsing. */
  169. sasl->mutual_auth = FALSE; /* No mutual authentication (GSSAPI only) */
  170. sasl->force_ir = FALSE; /* Respect external option */
  171. }
  172. /*
  173. * state()
  174. *
  175. * This is the ONLY way to change SASL state!
  176. */
  177. static void state(struct SASL *sasl, struct connectdata *conn,
  178. saslstate newstate)
  179. {
  180. #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
  181. /* for debug purposes */
  182. static const char * const names[]={
  183. "STOP",
  184. "PLAIN",
  185. "LOGIN",
  186. "LOGIN_PASSWD",
  187. "EXTERNAL",
  188. "CRAMMD5",
  189. "DIGESTMD5",
  190. "DIGESTMD5_RESP",
  191. "NTLM",
  192. "NTLM_TYPE2MSG",
  193. "GSSAPI",
  194. "GSSAPI_TOKEN",
  195. "GSSAPI_NO_DATA",
  196. "OAUTH2",
  197. "OAUTH2_RESP",
  198. "CANCEL",
  199. "FINAL",
  200. /* LAST */
  201. };
  202. if(sasl->state != newstate)
  203. infof(conn->data, "SASL %p state change from %s to %s\n",
  204. (void *)sasl, names[sasl->state], names[newstate]);
  205. #else
  206. (void) conn;
  207. #endif
  208. sasl->state = newstate;
  209. }
  210. /*
  211. * Curl_sasl_can_authenticate()
  212. *
  213. * Check if we have enough auth data and capabilities to authenticate.
  214. */
  215. bool Curl_sasl_can_authenticate(struct SASL *sasl, struct connectdata *conn)
  216. {
  217. /* Have credentials been provided? */
  218. if(conn->bits.user_passwd)
  219. return TRUE;
  220. /* EXTERNAL can authenticate without a user name and/or password */
  221. if(sasl->authmechs & sasl->prefmech & SASL_MECH_EXTERNAL)
  222. return TRUE;
  223. return FALSE;
  224. }
  225. /*
  226. * Curl_sasl_start()
  227. *
  228. * Calculate the required login details for SASL authentication.
  229. */
  230. CURLcode Curl_sasl_start(struct SASL *sasl, struct connectdata *conn,
  231. bool force_ir, saslprogress *progress)
  232. {
  233. CURLcode result = CURLE_OK;
  234. struct Curl_easy *data = conn->data;
  235. unsigned int enabledmechs;
  236. const char *mech = NULL;
  237. char *resp = NULL;
  238. size_t len = 0;
  239. saslstate state1 = SASL_STOP;
  240. saslstate state2 = SASL_FINAL;
  241. const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
  242. conn->host.name;
  243. const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
  244. #if defined(USE_KERBEROS5) || defined(USE_NTLM)
  245. const char *service = data->set.str[STRING_SERVICE_NAME] ?
  246. data->set.str[STRING_SERVICE_NAME] :
  247. sasl->params->service;
  248. #endif
  249. const char *oauth_bearer = data->set.str[STRING_BEARER];
  250. sasl->force_ir = force_ir; /* Latch for future use */
  251. sasl->authused = 0; /* No mechanism used yet */
  252. enabledmechs = sasl->authmechs & sasl->prefmech;
  253. *progress = SASL_IDLE;
  254. /* Calculate the supported authentication mechanism, by decreasing order of
  255. security, as well as the initial response where appropriate */
  256. if((enabledmechs & SASL_MECH_EXTERNAL) && !conn->passwd[0]) {
  257. mech = SASL_MECH_STRING_EXTERNAL;
  258. state1 = SASL_EXTERNAL;
  259. sasl->authused = SASL_MECH_EXTERNAL;
  260. if(force_ir || data->set.sasl_ir)
  261. result = Curl_auth_create_external_message(data, conn->user, &resp,
  262. &len);
  263. }
  264. else if(conn->bits.user_passwd) {
  265. #if defined(USE_KERBEROS5)
  266. if((enabledmechs & SASL_MECH_GSSAPI) && Curl_auth_is_gssapi_supported() &&
  267. Curl_auth_user_contains_domain(conn->user)) {
  268. sasl->mutual_auth = FALSE;
  269. mech = SASL_MECH_STRING_GSSAPI;
  270. state1 = SASL_GSSAPI;
  271. state2 = SASL_GSSAPI_TOKEN;
  272. sasl->authused = SASL_MECH_GSSAPI;
  273. if(force_ir || data->set.sasl_ir)
  274. result = Curl_auth_create_gssapi_user_message(data, conn->user,
  275. conn->passwd,
  276. service,
  277. data->conn->host.name,
  278. sasl->mutual_auth,
  279. NULL, &conn->krb5,
  280. &resp, &len);
  281. }
  282. else
  283. #endif
  284. #ifndef CURL_DISABLE_CRYPTO_AUTH
  285. if((enabledmechs & SASL_MECH_DIGEST_MD5) &&
  286. Curl_auth_is_digest_supported()) {
  287. mech = SASL_MECH_STRING_DIGEST_MD5;
  288. state1 = SASL_DIGESTMD5;
  289. sasl->authused = SASL_MECH_DIGEST_MD5;
  290. }
  291. else if(enabledmechs & SASL_MECH_CRAM_MD5) {
  292. mech = SASL_MECH_STRING_CRAM_MD5;
  293. state1 = SASL_CRAMMD5;
  294. sasl->authused = SASL_MECH_CRAM_MD5;
  295. }
  296. else
  297. #endif
  298. #ifdef USE_NTLM
  299. if((enabledmechs & SASL_MECH_NTLM) && Curl_auth_is_ntlm_supported()) {
  300. mech = SASL_MECH_STRING_NTLM;
  301. state1 = SASL_NTLM;
  302. state2 = SASL_NTLM_TYPE2MSG;
  303. sasl->authused = SASL_MECH_NTLM;
  304. if(force_ir || data->set.sasl_ir)
  305. result = Curl_auth_create_ntlm_type1_message(data,
  306. conn->user, conn->passwd,
  307. service,
  308. hostname,
  309. &conn->ntlm, &resp,
  310. &len);
  311. }
  312. else
  313. #endif
  314. if((enabledmechs & SASL_MECH_OAUTHBEARER) && oauth_bearer) {
  315. mech = SASL_MECH_STRING_OAUTHBEARER;
  316. state1 = SASL_OAUTH2;
  317. state2 = SASL_OAUTH2_RESP;
  318. sasl->authused = SASL_MECH_OAUTHBEARER;
  319. if(force_ir || data->set.sasl_ir)
  320. result = Curl_auth_create_oauth_bearer_message(data, conn->user,
  321. hostname,
  322. port,
  323. oauth_bearer,
  324. &resp, &len);
  325. }
  326. else if((enabledmechs & SASL_MECH_XOAUTH2) && oauth_bearer) {
  327. mech = SASL_MECH_STRING_XOAUTH2;
  328. state1 = SASL_OAUTH2;
  329. sasl->authused = SASL_MECH_XOAUTH2;
  330. if(force_ir || data->set.sasl_ir)
  331. result = Curl_auth_create_xoauth_bearer_message(data, conn->user,
  332. oauth_bearer,
  333. &resp, &len);
  334. }
  335. else if(enabledmechs & SASL_MECH_PLAIN) {
  336. mech = SASL_MECH_STRING_PLAIN;
  337. state1 = SASL_PLAIN;
  338. sasl->authused = SASL_MECH_PLAIN;
  339. if(force_ir || data->set.sasl_ir)
  340. result = Curl_auth_create_plain_message(data, conn->sasl_authzid,
  341. conn->user, conn->passwd,
  342. &resp, &len);
  343. }
  344. else if(enabledmechs & SASL_MECH_LOGIN) {
  345. mech = SASL_MECH_STRING_LOGIN;
  346. state1 = SASL_LOGIN;
  347. state2 = SASL_LOGIN_PASSWD;
  348. sasl->authused = SASL_MECH_LOGIN;
  349. if(force_ir || data->set.sasl_ir)
  350. result = Curl_auth_create_login_message(data, conn->user, &resp, &len);
  351. }
  352. }
  353. if(!result && mech) {
  354. if(resp && sasl->params->maxirlen &&
  355. strlen(mech) + len > sasl->params->maxirlen) {
  356. free(resp);
  357. resp = NULL;
  358. }
  359. result = sasl->params->sendauth(conn, mech, resp);
  360. if(!result) {
  361. *progress = SASL_INPROGRESS;
  362. state(sasl, conn, resp ? state2 : state1);
  363. }
  364. }
  365. free(resp);
  366. return result;
  367. }
  368. /*
  369. * Curl_sasl_continue()
  370. *
  371. * Continue the authentication.
  372. */
  373. CURLcode Curl_sasl_continue(struct SASL *sasl, struct connectdata *conn,
  374. int code, saslprogress *progress)
  375. {
  376. CURLcode result = CURLE_OK;
  377. struct Curl_easy *data = conn->data;
  378. saslstate newstate = SASL_FINAL;
  379. char *resp = NULL;
  380. const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
  381. conn->host.name;
  382. const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
  383. #if !defined(CURL_DISABLE_CRYPTO_AUTH)
  384. char *chlg = NULL;
  385. size_t chlglen = 0;
  386. #endif
  387. #if !defined(CURL_DISABLE_CRYPTO_AUTH) || defined(USE_KERBEROS5) || \
  388. defined(USE_NTLM)
  389. const char *service = data->set.str[STRING_SERVICE_NAME] ?
  390. data->set.str[STRING_SERVICE_NAME] :
  391. sasl->params->service;
  392. char *serverdata;
  393. #endif
  394. size_t len = 0;
  395. const char *oauth_bearer = data->set.str[STRING_BEARER];
  396. *progress = SASL_INPROGRESS;
  397. if(sasl->state == SASL_FINAL) {
  398. if(code != sasl->params->finalcode)
  399. result = CURLE_LOGIN_DENIED;
  400. *progress = SASL_DONE;
  401. state(sasl, conn, SASL_STOP);
  402. return result;
  403. }
  404. if(sasl->state != SASL_CANCEL && sasl->state != SASL_OAUTH2_RESP &&
  405. code != sasl->params->contcode) {
  406. *progress = SASL_DONE;
  407. state(sasl, conn, SASL_STOP);
  408. return CURLE_LOGIN_DENIED;
  409. }
  410. switch(sasl->state) {
  411. case SASL_STOP:
  412. *progress = SASL_DONE;
  413. return result;
  414. case SASL_PLAIN:
  415. result = Curl_auth_create_plain_message(data, conn->sasl_authzid,
  416. conn->user, conn->passwd,
  417. &resp, &len);
  418. break;
  419. case SASL_LOGIN:
  420. result = Curl_auth_create_login_message(data, conn->user, &resp, &len);
  421. newstate = SASL_LOGIN_PASSWD;
  422. break;
  423. case SASL_LOGIN_PASSWD:
  424. result = Curl_auth_create_login_message(data, conn->passwd, &resp, &len);
  425. break;
  426. case SASL_EXTERNAL:
  427. result = Curl_auth_create_external_message(data, conn->user, &resp, &len);
  428. break;
  429. #ifndef CURL_DISABLE_CRYPTO_AUTH
  430. case SASL_CRAMMD5:
  431. sasl->params->getmessage(data->state.buffer, &serverdata);
  432. result = Curl_auth_decode_cram_md5_message(serverdata, &chlg, &chlglen);
  433. if(!result)
  434. result = Curl_auth_create_cram_md5_message(data, chlg, conn->user,
  435. conn->passwd, &resp, &len);
  436. free(chlg);
  437. break;
  438. case SASL_DIGESTMD5:
  439. sasl->params->getmessage(data->state.buffer, &serverdata);
  440. result = Curl_auth_create_digest_md5_message(data, serverdata,
  441. conn->user, conn->passwd,
  442. service,
  443. &resp, &len);
  444. newstate = SASL_DIGESTMD5_RESP;
  445. break;
  446. case SASL_DIGESTMD5_RESP:
  447. resp = strdup("");
  448. if(!resp)
  449. result = CURLE_OUT_OF_MEMORY;
  450. break;
  451. #endif
  452. #ifdef USE_NTLM
  453. case SASL_NTLM:
  454. /* Create the type-1 message */
  455. result = Curl_auth_create_ntlm_type1_message(data,
  456. conn->user, conn->passwd,
  457. service, hostname,
  458. &conn->ntlm, &resp, &len);
  459. newstate = SASL_NTLM_TYPE2MSG;
  460. break;
  461. case SASL_NTLM_TYPE2MSG:
  462. /* Decode the type-2 message */
  463. sasl->params->getmessage(data->state.buffer, &serverdata);
  464. result = Curl_auth_decode_ntlm_type2_message(data, serverdata,
  465. &conn->ntlm);
  466. if(!result)
  467. result = Curl_auth_create_ntlm_type3_message(data, conn->user,
  468. conn->passwd, &conn->ntlm,
  469. &resp, &len);
  470. break;
  471. #endif
  472. #if defined(USE_KERBEROS5)
  473. case SASL_GSSAPI:
  474. result = Curl_auth_create_gssapi_user_message(data, conn->user,
  475. conn->passwd,
  476. service,
  477. data->conn->host.name,
  478. sasl->mutual_auth, NULL,
  479. &conn->krb5,
  480. &resp, &len);
  481. newstate = SASL_GSSAPI_TOKEN;
  482. break;
  483. case SASL_GSSAPI_TOKEN:
  484. sasl->params->getmessage(data->state.buffer, &serverdata);
  485. if(sasl->mutual_auth) {
  486. /* Decode the user token challenge and create the optional response
  487. message */
  488. result = Curl_auth_create_gssapi_user_message(data, NULL, NULL,
  489. NULL, NULL,
  490. sasl->mutual_auth,
  491. serverdata, &conn->krb5,
  492. &resp, &len);
  493. newstate = SASL_GSSAPI_NO_DATA;
  494. }
  495. else
  496. /* Decode the security challenge and create the response message */
  497. result = Curl_auth_create_gssapi_security_message(data, serverdata,
  498. &conn->krb5,
  499. &resp, &len);
  500. break;
  501. case SASL_GSSAPI_NO_DATA:
  502. sasl->params->getmessage(data->state.buffer, &serverdata);
  503. /* Decode the security challenge and create the response message */
  504. result = Curl_auth_create_gssapi_security_message(data, serverdata,
  505. &conn->krb5,
  506. &resp, &len);
  507. break;
  508. #endif
  509. case SASL_OAUTH2:
  510. /* Create the authorisation message */
  511. if(sasl->authused == SASL_MECH_OAUTHBEARER) {
  512. result = Curl_auth_create_oauth_bearer_message(data, conn->user,
  513. hostname,
  514. port,
  515. oauth_bearer,
  516. &resp, &len);
  517. /* Failures maybe sent by the server as continuations for OAUTHBEARER */
  518. newstate = SASL_OAUTH2_RESP;
  519. }
  520. else
  521. result = Curl_auth_create_xoauth_bearer_message(data, conn->user,
  522. oauth_bearer,
  523. &resp, &len);
  524. break;
  525. case SASL_OAUTH2_RESP:
  526. /* The continuation is optional so check the response code */
  527. if(code == sasl->params->finalcode) {
  528. /* Final response was received so we are done */
  529. *progress = SASL_DONE;
  530. state(sasl, conn, SASL_STOP);
  531. return result;
  532. }
  533. else if(code == sasl->params->contcode) {
  534. /* Acknowledge the continuation by sending a 0x01 response base64
  535. encoded */
  536. resp = strdup("AQ==");
  537. if(!resp)
  538. result = CURLE_OUT_OF_MEMORY;
  539. break;
  540. }
  541. else {
  542. *progress = SASL_DONE;
  543. state(sasl, conn, SASL_STOP);
  544. return CURLE_LOGIN_DENIED;
  545. }
  546. case SASL_CANCEL:
  547. /* Remove the offending mechanism from the supported list */
  548. sasl->authmechs ^= sasl->authused;
  549. /* Start an alternative SASL authentication */
  550. result = Curl_sasl_start(sasl, conn, sasl->force_ir, progress);
  551. newstate = sasl->state; /* Use state from Curl_sasl_start() */
  552. break;
  553. default:
  554. failf(data, "Unsupported SASL authentication mechanism");
  555. result = CURLE_UNSUPPORTED_PROTOCOL; /* Should not happen */
  556. break;
  557. }
  558. switch(result) {
  559. case CURLE_BAD_CONTENT_ENCODING:
  560. /* Cancel dialog */
  561. result = sasl->params->sendcont(conn, "*");
  562. newstate = SASL_CANCEL;
  563. break;
  564. case CURLE_OK:
  565. if(resp)
  566. result = sasl->params->sendcont(conn, resp);
  567. break;
  568. default:
  569. newstate = SASL_STOP; /* Stop on error */
  570. *progress = SASL_DONE;
  571. break;
  572. }
  573. free(resp);
  574. state(sasl, conn, newstate);
  575. return result;
  576. }
  577. #endif /* protocols are enabled that use SASL */