curl_sasl.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2012 - 2019, 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. #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. sasl->force_ir = force_ir; /* Latch for future use */
  250. sasl->authused = 0; /* No mechanism used yet */
  251. enabledmechs = sasl->authmechs & sasl->prefmech;
  252. *progress = SASL_IDLE;
  253. /* Calculate the supported authentication mechanism, by decreasing order of
  254. security, as well as the initial response where appropriate */
  255. if((enabledmechs & SASL_MECH_EXTERNAL) && !conn->passwd[0]) {
  256. mech = SASL_MECH_STRING_EXTERNAL;
  257. state1 = SASL_EXTERNAL;
  258. sasl->authused = SASL_MECH_EXTERNAL;
  259. if(force_ir || data->set.sasl_ir)
  260. result = Curl_auth_create_external_message(data, conn->user, &resp,
  261. &len);
  262. }
  263. else if(conn->bits.user_passwd) {
  264. #if defined(USE_KERBEROS5)
  265. if((enabledmechs & SASL_MECH_GSSAPI) && Curl_auth_is_gssapi_supported() &&
  266. Curl_auth_user_contains_domain(conn->user)) {
  267. sasl->mutual_auth = FALSE;
  268. mech = SASL_MECH_STRING_GSSAPI;
  269. state1 = SASL_GSSAPI;
  270. state2 = SASL_GSSAPI_TOKEN;
  271. sasl->authused = SASL_MECH_GSSAPI;
  272. if(force_ir || data->set.sasl_ir)
  273. result = Curl_auth_create_gssapi_user_message(data, conn->user,
  274. conn->passwd,
  275. service,
  276. data->conn->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. service,
  307. hostname,
  308. &conn->ntlm, &resp,
  309. &len);
  310. }
  311. else
  312. #endif
  313. if((enabledmechs & SASL_MECH_OAUTHBEARER) && conn->oauth_bearer) {
  314. mech = SASL_MECH_STRING_OAUTHBEARER;
  315. state1 = SASL_OAUTH2;
  316. state2 = SASL_OAUTH2_RESP;
  317. sasl->authused = SASL_MECH_OAUTHBEARER;
  318. if(force_ir || data->set.sasl_ir)
  319. result = Curl_auth_create_oauth_bearer_message(data, conn->user,
  320. hostname,
  321. port,
  322. conn->oauth_bearer,
  323. &resp, &len);
  324. }
  325. else if((enabledmechs & SASL_MECH_XOAUTH2) && conn->oauth_bearer) {
  326. mech = SASL_MECH_STRING_XOAUTH2;
  327. state1 = SASL_OAUTH2;
  328. sasl->authused = SASL_MECH_XOAUTH2;
  329. if(force_ir || data->set.sasl_ir)
  330. result = Curl_auth_create_xoauth_bearer_message(data, conn->user,
  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, NULL, conn->user,
  340. conn->passwd, &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, NULL, conn->user,
  413. conn->passwd, &resp, &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(data,
  452. conn->user, conn->passwd,
  453. service, hostname,
  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->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_xoauth_bearer_message(data, conn->user,
  518. conn->oauth_bearer,
  519. &resp, &len);
  520. break;
  521. case SASL_OAUTH2_RESP:
  522. /* The continuation is optional so check the response code */
  523. if(code == sasl->params->finalcode) {
  524. /* Final response was received so we are done */
  525. *progress = SASL_DONE;
  526. state(sasl, conn, SASL_STOP);
  527. return result;
  528. }
  529. else if(code == sasl->params->contcode) {
  530. /* Acknowledge the continuation by sending a 0x01 response base64
  531. encoded */
  532. resp = strdup("AQ==");
  533. if(!resp)
  534. result = CURLE_OUT_OF_MEMORY;
  535. break;
  536. }
  537. else {
  538. *progress = SASL_DONE;
  539. state(sasl, conn, SASL_STOP);
  540. return CURLE_LOGIN_DENIED;
  541. }
  542. case SASL_CANCEL:
  543. /* Remove the offending mechanism from the supported list */
  544. sasl->authmechs ^= sasl->authused;
  545. /* Start an alternative SASL authentication */
  546. result = Curl_sasl_start(sasl, conn, sasl->force_ir, progress);
  547. newstate = sasl->state; /* Use state from Curl_sasl_start() */
  548. break;
  549. default:
  550. failf(data, "Unsupported SASL authentication mechanism");
  551. result = CURLE_UNSUPPORTED_PROTOCOL; /* Should not happen */
  552. break;
  553. }
  554. switch(result) {
  555. case CURLE_BAD_CONTENT_ENCODING:
  556. /* Cancel dialog */
  557. result = sasl->params->sendcont(conn, "*");
  558. newstate = SASL_CANCEL;
  559. break;
  560. case CURLE_OK:
  561. if(resp)
  562. result = sasl->params->sendcont(conn, resp);
  563. break;
  564. default:
  565. newstate = SASL_STOP; /* Stop on error */
  566. *progress = SASL_DONE;
  567. break;
  568. }
  569. free(resp);
  570. state(sasl, conn, newstate);
  571. return result;
  572. }
  573. #endif /* protocols are enabled that use SASL */