curl_sasl.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2012 - 2017, 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. 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(data,
  305. conn->user, conn->passwd,
  306. &conn->ntlm, &resp, &len);
  307. }
  308. else
  309. #endif
  310. if((enabledmechs & SASL_MECH_OAUTHBEARER) && conn->oauth_bearer) {
  311. mech = SASL_MECH_STRING_OAUTHBEARER;
  312. state1 = SASL_OAUTH2;
  313. state2 = SASL_OAUTH2_RESP;
  314. sasl->authused = SASL_MECH_OAUTHBEARER;
  315. if(force_ir || data->set.sasl_ir)
  316. result = Curl_auth_create_oauth_bearer_message(data, conn->user,
  317. hostname,
  318. port,
  319. conn->oauth_bearer,
  320. &resp, &len);
  321. }
  322. else if((enabledmechs & SASL_MECH_XOAUTH2) && conn->oauth_bearer) {
  323. mech = SASL_MECH_STRING_XOAUTH2;
  324. state1 = SASL_OAUTH2;
  325. sasl->authused = SASL_MECH_XOAUTH2;
  326. if(force_ir || data->set.sasl_ir)
  327. result = Curl_auth_create_oauth_bearer_message(data, conn->user,
  328. NULL, 0,
  329. conn->oauth_bearer,
  330. &resp, &len);
  331. }
  332. else if(enabledmechs & SASL_MECH_LOGIN) {
  333. mech = SASL_MECH_STRING_LOGIN;
  334. state1 = SASL_LOGIN;
  335. state2 = SASL_LOGIN_PASSWD;
  336. sasl->authused = SASL_MECH_LOGIN;
  337. if(force_ir || data->set.sasl_ir)
  338. result = Curl_auth_create_login_message(data, conn->user, &resp, &len);
  339. }
  340. else if(enabledmechs & SASL_MECH_PLAIN) {
  341. mech = SASL_MECH_STRING_PLAIN;
  342. state1 = SASL_PLAIN;
  343. sasl->authused = SASL_MECH_PLAIN;
  344. if(force_ir || data->set.sasl_ir)
  345. result = Curl_auth_create_plain_message(data, conn->user, conn->passwd,
  346. &resp, &len);
  347. }
  348. }
  349. if(!result && mech) {
  350. if(resp && sasl->params->maxirlen &&
  351. strlen(mech) + len > sasl->params->maxirlen) {
  352. free(resp);
  353. resp = NULL;
  354. }
  355. result = sasl->params->sendauth(conn, mech, resp);
  356. if(!result) {
  357. *progress = SASL_INPROGRESS;
  358. state(sasl, conn, resp ? state2 : state1);
  359. }
  360. }
  361. free(resp);
  362. return result;
  363. }
  364. /*
  365. * Curl_sasl_continue()
  366. *
  367. * Continue the authentication.
  368. */
  369. CURLcode Curl_sasl_continue(struct SASL *sasl, struct connectdata *conn,
  370. int code, saslprogress *progress)
  371. {
  372. CURLcode result = CURLE_OK;
  373. struct Curl_easy *data = conn->data;
  374. saslstate newstate = SASL_FINAL;
  375. char *resp = NULL;
  376. const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
  377. conn->host.name;
  378. const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
  379. #if !defined(CURL_DISABLE_CRYPTO_AUTH)
  380. char *chlg = NULL;
  381. size_t chlglen = 0;
  382. #endif
  383. #if !defined(CURL_DISABLE_CRYPTO_AUTH) || defined(USE_KERBEROS5)
  384. const char *service = data->set.str[STRING_SERVICE_NAME] ?
  385. data->set.str[STRING_SERVICE_NAME] :
  386. sasl->params->service;
  387. #endif
  388. #if !defined(CURL_DISABLE_CRYPTO_AUTH) || defined(USE_KERBEROS5) || \
  389. defined(USE_NTLM)
  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. &conn->ntlm, &resp, &len);
  455. newstate = SASL_NTLM_TYPE2MSG;
  456. break;
  457. case SASL_NTLM_TYPE2MSG:
  458. /* Decode the type-2 message */
  459. sasl->params->getmessage(data->state.buffer, &serverdata);
  460. result = Curl_auth_decode_ntlm_type2_message(data, serverdata,
  461. &conn->ntlm);
  462. if(!result)
  463. result = Curl_auth_create_ntlm_type3_message(data, conn->user,
  464. conn->passwd, &conn->ntlm,
  465. &resp, &len);
  466. break;
  467. #endif
  468. #if defined(USE_KERBEROS5)
  469. case SASL_GSSAPI:
  470. result = Curl_auth_create_gssapi_user_message(data, conn->user,
  471. conn->passwd,
  472. service,
  473. data->easy_conn->host.name,
  474. sasl->mutual_auth, NULL,
  475. &conn->krb5,
  476. &resp, &len);
  477. newstate = SASL_GSSAPI_TOKEN;
  478. break;
  479. case SASL_GSSAPI_TOKEN:
  480. sasl->params->getmessage(data->state.buffer, &serverdata);
  481. if(sasl->mutual_auth) {
  482. /* Decode the user token challenge and create the optional response
  483. message */
  484. result = Curl_auth_create_gssapi_user_message(data, NULL, NULL,
  485. NULL, NULL,
  486. sasl->mutual_auth,
  487. serverdata, &conn->krb5,
  488. &resp, &len);
  489. newstate = SASL_GSSAPI_NO_DATA;
  490. }
  491. else
  492. /* Decode the security challenge and create the response message */
  493. result = Curl_auth_create_gssapi_security_message(data, serverdata,
  494. &conn->krb5,
  495. &resp, &len);
  496. break;
  497. case SASL_GSSAPI_NO_DATA:
  498. sasl->params->getmessage(data->state.buffer, &serverdata);
  499. /* Decode the security challenge and create the response message */
  500. result = Curl_auth_create_gssapi_security_message(data, serverdata,
  501. &conn->krb5,
  502. &resp, &len);
  503. break;
  504. #endif
  505. case SASL_OAUTH2:
  506. /* Create the authorisation message */
  507. if(sasl->authused == SASL_MECH_OAUTHBEARER) {
  508. result = Curl_auth_create_oauth_bearer_message(data, conn->user,
  509. hostname,
  510. port,
  511. conn->oauth_bearer,
  512. &resp, &len);
  513. /* Failures maybe sent by the server as continuations for OAUTHBEARER */
  514. newstate = SASL_OAUTH2_RESP;
  515. }
  516. else
  517. result = Curl_auth_create_oauth_bearer_message(data, conn->user,
  518. NULL, 0,
  519. conn->oauth_bearer,
  520. &resp, &len);
  521. break;
  522. case SASL_OAUTH2_RESP:
  523. /* The continuation is optional so check the response code */
  524. if(code == sasl->params->finalcode) {
  525. /* Final response was received so we are done */
  526. *progress = SASL_DONE;
  527. state(sasl, conn, SASL_STOP);
  528. return result;
  529. }
  530. else if(code == sasl->params->contcode) {
  531. /* Acknowledge the continuation by sending a 0x01 response base64
  532. encoded */
  533. resp = strdup("AQ==");
  534. if(!resp)
  535. result = CURLE_OUT_OF_MEMORY;
  536. break;
  537. }
  538. else {
  539. *progress = SASL_DONE;
  540. state(sasl, conn, SASL_STOP);
  541. return CURLE_LOGIN_DENIED;
  542. }
  543. case SASL_CANCEL:
  544. /* Remove the offending mechanism from the supported list */
  545. sasl->authmechs ^= sasl->authused;
  546. /* Start an alternative SASL authentication */
  547. result = Curl_sasl_start(sasl, conn, sasl->force_ir, progress);
  548. newstate = sasl->state; /* Use state from Curl_sasl_start() */
  549. break;
  550. default:
  551. failf(data, "Unsupported SASL authentication mechanism");
  552. result = CURLE_UNSUPPORTED_PROTOCOL; /* Should not happen */
  553. break;
  554. }
  555. switch(result) {
  556. case CURLE_BAD_CONTENT_ENCODING:
  557. /* Cancel dialog */
  558. result = sasl->params->sendcont(conn, "*");
  559. newstate = SASL_CANCEL;
  560. break;
  561. case CURLE_OK:
  562. if(resp)
  563. result = sasl->params->sendcont(conn, resp);
  564. break;
  565. default:
  566. newstate = SASL_STOP; /* Stop on error */
  567. *progress = SASL_DONE;
  568. break;
  569. }
  570. free(resp);
  571. state(sasl, conn, newstate);
  572. return result;
  573. }