curl_sasl.c 20 KB

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