curl_sasl.c 19 KB

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