curl_sasl.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2012 - 2019, 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->conn->host.name,
  275. sasl->mutual_auth,
  276. NULL, &conn->krb5,
  277. &resp, &len);
  278. }
  279. else
  280. #endif
  281. #ifndef CURL_DISABLE_CRYPTO_AUTH
  282. if((enabledmechs & SASL_MECH_DIGEST_MD5) &&
  283. Curl_auth_is_digest_supported()) {
  284. mech = SASL_MECH_STRING_DIGEST_MD5;
  285. state1 = SASL_DIGESTMD5;
  286. sasl->authused = SASL_MECH_DIGEST_MD5;
  287. }
  288. else if(enabledmechs & SASL_MECH_CRAM_MD5) {
  289. mech = SASL_MECH_STRING_CRAM_MD5;
  290. state1 = SASL_CRAMMD5;
  291. sasl->authused = SASL_MECH_CRAM_MD5;
  292. }
  293. else
  294. #endif
  295. #ifdef USE_NTLM
  296. if((enabledmechs & SASL_MECH_NTLM) && Curl_auth_is_ntlm_supported()) {
  297. mech = SASL_MECH_STRING_NTLM;
  298. state1 = SASL_NTLM;
  299. state2 = SASL_NTLM_TYPE2MSG;
  300. sasl->authused = SASL_MECH_NTLM;
  301. if(force_ir || data->set.sasl_ir)
  302. result = Curl_auth_create_ntlm_type1_message(data,
  303. conn->user, conn->passwd,
  304. service,
  305. hostname,
  306. &conn->ntlm, &resp,
  307. &len);
  308. }
  309. else
  310. #endif
  311. if((enabledmechs & SASL_MECH_OAUTHBEARER) && conn->oauth_bearer) {
  312. mech = SASL_MECH_STRING_OAUTHBEARER;
  313. state1 = SASL_OAUTH2;
  314. state2 = SASL_OAUTH2_RESP;
  315. sasl->authused = SASL_MECH_OAUTHBEARER;
  316. if(force_ir || data->set.sasl_ir)
  317. result = Curl_auth_create_oauth_bearer_message(data, conn->user,
  318. hostname,
  319. port,
  320. conn->oauth_bearer,
  321. &resp, &len);
  322. }
  323. else if((enabledmechs & SASL_MECH_XOAUTH2) && conn->oauth_bearer) {
  324. mech = SASL_MECH_STRING_XOAUTH2;
  325. state1 = SASL_OAUTH2;
  326. sasl->authused = SASL_MECH_XOAUTH2;
  327. if(force_ir || data->set.sasl_ir)
  328. result = Curl_auth_create_xoauth_bearer_message(data, conn->user,
  329. conn->oauth_bearer,
  330. &resp, &len);
  331. }
  332. else if(enabledmechs & SASL_MECH_PLAIN) {
  333. mech = SASL_MECH_STRING_PLAIN;
  334. state1 = SASL_PLAIN;
  335. sasl->authused = SASL_MECH_PLAIN;
  336. if(force_ir || data->set.sasl_ir)
  337. result = Curl_auth_create_plain_message(data, NULL, conn->user,
  338. conn->passwd, &resp, &len);
  339. }
  340. else if(enabledmechs & SASL_MECH_LOGIN) {
  341. mech = SASL_MECH_STRING_LOGIN;
  342. state1 = SASL_LOGIN;
  343. state2 = SASL_LOGIN_PASSWD;
  344. sasl->authused = SASL_MECH_LOGIN;
  345. if(force_ir || data->set.sasl_ir)
  346. result = Curl_auth_create_login_message(data, conn->user, &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. defined(USE_NTLM)
  385. const char *service = data->set.str[STRING_SERVICE_NAME] ?
  386. data->set.str[STRING_SERVICE_NAME] :
  387. sasl->params->service;
  388. char *serverdata;
  389. #endif
  390. size_t len = 0;
  391. *progress = SASL_INPROGRESS;
  392. if(sasl->state == SASL_FINAL) {
  393. if(code != sasl->params->finalcode)
  394. result = CURLE_LOGIN_DENIED;
  395. *progress = SASL_DONE;
  396. state(sasl, conn, SASL_STOP);
  397. return result;
  398. }
  399. if(sasl->state != SASL_CANCEL && sasl->state != SASL_OAUTH2_RESP &&
  400. code != sasl->params->contcode) {
  401. *progress = SASL_DONE;
  402. state(sasl, conn, SASL_STOP);
  403. return CURLE_LOGIN_DENIED;
  404. }
  405. switch(sasl->state) {
  406. case SASL_STOP:
  407. *progress = SASL_DONE;
  408. return result;
  409. case SASL_PLAIN:
  410. result = Curl_auth_create_plain_message(data, NULL, conn->user,
  411. conn->passwd, &resp, &len);
  412. break;
  413. case SASL_LOGIN:
  414. result = Curl_auth_create_login_message(data, conn->user, &resp, &len);
  415. newstate = SASL_LOGIN_PASSWD;
  416. break;
  417. case SASL_LOGIN_PASSWD:
  418. result = Curl_auth_create_login_message(data, conn->passwd, &resp, &len);
  419. break;
  420. case SASL_EXTERNAL:
  421. result = Curl_auth_create_external_message(data, conn->user, &resp, &len);
  422. break;
  423. #ifndef CURL_DISABLE_CRYPTO_AUTH
  424. case SASL_CRAMMD5:
  425. sasl->params->getmessage(data->state.buffer, &serverdata);
  426. result = Curl_auth_decode_cram_md5_message(serverdata, &chlg, &chlglen);
  427. if(!result)
  428. result = Curl_auth_create_cram_md5_message(data, chlg, conn->user,
  429. conn->passwd, &resp, &len);
  430. free(chlg);
  431. break;
  432. case SASL_DIGESTMD5:
  433. sasl->params->getmessage(data->state.buffer, &serverdata);
  434. result = Curl_auth_create_digest_md5_message(data, serverdata,
  435. conn->user, conn->passwd,
  436. service,
  437. &resp, &len);
  438. newstate = SASL_DIGESTMD5_RESP;
  439. break;
  440. case SASL_DIGESTMD5_RESP:
  441. resp = strdup("");
  442. if(!resp)
  443. result = CURLE_OUT_OF_MEMORY;
  444. break;
  445. #endif
  446. #ifdef USE_NTLM
  447. case SASL_NTLM:
  448. /* Create the type-1 message */
  449. result = Curl_auth_create_ntlm_type1_message(data,
  450. conn->user, conn->passwd,
  451. service, hostname,
  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->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_xoauth_bearer_message(data, conn->user,
  516. conn->oauth_bearer,
  517. &resp, &len);
  518. break;
  519. case SASL_OAUTH2_RESP:
  520. /* The continuation is optional so check the response code */
  521. if(code == sasl->params->finalcode) {
  522. /* Final response was received so we are done */
  523. *progress = SASL_DONE;
  524. state(sasl, conn, SASL_STOP);
  525. return result;
  526. }
  527. else if(code == sasl->params->contcode) {
  528. /* Acknowledge the continuation by sending a 0x01 response base64
  529. encoded */
  530. resp = strdup("AQ==");
  531. if(!resp)
  532. result = CURLE_OUT_OF_MEMORY;
  533. break;
  534. }
  535. else {
  536. *progress = SASL_DONE;
  537. state(sasl, conn, SASL_STOP);
  538. return CURLE_LOGIN_DENIED;
  539. }
  540. case SASL_CANCEL:
  541. /* Remove the offending mechanism from the supported list */
  542. sasl->authmechs ^= sasl->authused;
  543. /* Start an alternative SASL authentication */
  544. result = Curl_sasl_start(sasl, conn, sasl->force_ir, progress);
  545. newstate = sasl->state; /* Use state from Curl_sasl_start() */
  546. break;
  547. default:
  548. failf(data, "Unsupported SASL authentication mechanism");
  549. result = CURLE_UNSUPPORTED_PROTOCOL; /* Should not happen */
  550. break;
  551. }
  552. switch(result) {
  553. case CURLE_BAD_CONTENT_ENCODING:
  554. /* Cancel dialog */
  555. result = sasl->params->sendcont(conn, "*");
  556. newstate = SASL_CANCEL;
  557. break;
  558. case CURLE_OK:
  559. if(resp)
  560. result = sasl->params->sendcont(conn, resp);
  561. break;
  562. default:
  563. newstate = SASL_STOP; /* Stop on error */
  564. *progress = SASL_DONE;
  565. break;
  566. }
  567. free(resp);
  568. state(sasl, conn, newstate);
  569. return result;
  570. }