curl_sasl.c 20 KB

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