auth-juniper.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*
  2. * OpenConnect (SSL + DTLS) VPN client
  3. *
  4. * Copyright © 2008-2015 Intel Corporation.
  5. *
  6. * Author: David Woodhouse <dwmw2@infradead.org>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public License
  10. * version 2.1, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. */
  17. /*
  18. * Grateful thanks to Tiebing Zhang, who did much of the hard work
  19. * of analysing and decoding the protocol.
  20. */
  21. #include <config.h>
  22. #include "openconnect-internal.h"
  23. #include <libxml/HTMLparser.h>
  24. #include <libxml/HTMLtree.h>
  25. #include <unistd.h>
  26. #include <fcntl.h>
  27. #include <sys/types.h>
  28. #ifndef _WIN32
  29. #include <sys/wait.h>
  30. #endif
  31. #include <time.h>
  32. #include <string.h>
  33. #include <ctype.h>
  34. #include <errno.h>
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37. #include <stdarg.h>
  38. /* XX: This is actually a lot of duplication with the CSTP version. */
  39. void oncp_common_headers(struct openconnect_info *vpninfo, struct oc_text_buf *buf)
  40. {
  41. http_common_headers(vpninfo, buf);
  42. // buf_append(buf, "Content-Length: 256\r\n");
  43. buf_append(buf, "NCP-Version: 3\r\n");
  44. // buf_append(buf, "Accept-Encoding: gzip\r\n");
  45. }
  46. static int oncp_can_gen_tokencode(struct openconnect_info *vpninfo,
  47. struct oc_auth_form *form,
  48. struct oc_form_opt *opt)
  49. {
  50. if (vpninfo->token_mode == OC_TOKEN_MODE_NONE ||
  51. vpninfo->token_bypassed)
  52. return -EINVAL;
  53. if (opt->type == OC_FORM_OPT_PASSWORD &&
  54. (!strcmp(form->auth_id, "frmLogin") ||
  55. !strcmp(form->auth_id, "loginForm"))) {
  56. /* XX: The first occurrence of a password input field in frmLogin is likely to be a password,
  57. * not token, input. However, if we have already added a password input field to this form,
  58. * then a second one is likely to hold a token.
  59. */
  60. struct oc_form_opt *p;
  61. for (p = form->opts; p; p = p->next) {
  62. if (p->type == OC_FORM_OPT_PASSWORD)
  63. goto okay;
  64. }
  65. return -EINVAL;
  66. }
  67. if (strcmp(form->auth_id, "frmDefender") &&
  68. strcmp(form->auth_id, "frmNextToken") &&
  69. strcmp(form->auth_id, "frmTotpToken") &&
  70. strcmp(form->auth_id, "loginForm"))
  71. return -EINVAL;
  72. okay:
  73. return can_gen_tokencode(vpninfo, form, opt);
  74. }
  75. int oncp_send_tncc_command(struct openconnect_info *vpninfo, int start)
  76. {
  77. const char *dspreauth = vpninfo->csd_token, *dsurl = vpninfo->csd_starturl ? : "null";
  78. struct oc_text_buf *buf;
  79. buf = buf_alloc();
  80. if (start) {
  81. buf_append(buf, "start\n");
  82. buf_append(buf, "IC=%s\n", vpninfo->hostname);
  83. buf_append(buf, "Cookie=%s\n", dspreauth);
  84. buf_append(buf, "DSSIGNIN=%s\n", dsurl);
  85. } else {
  86. buf_append(buf, "setcookie\n");
  87. buf_append(buf, "Cookie=%s\n", dspreauth);
  88. }
  89. if (buf_error(buf)) {
  90. vpn_progress(vpninfo, PRG_ERR,
  91. _("Failed to allocate memory for communication with TNCC\n"));
  92. return buf_free(buf);
  93. }
  94. if (cancellable_send(vpninfo, vpninfo->tncc_fd, buf->data, buf->pos) != buf->pos) {
  95. vpn_progress(vpninfo, PRG_ERR,
  96. _("Failed to send command to TNCC\n"));
  97. buf_free(buf);
  98. return -EIO;
  99. }
  100. /* Mainloop timers need to know the last Trojan was invoked */
  101. vpninfo->last_trojan = time(NULL);
  102. return buf_free(buf);
  103. }
  104. static int check_cookie_success(struct openconnect_info *vpninfo)
  105. {
  106. const char *dslast = NULL, *dsfirst = NULL, *dsurl = NULL, *dsid = NULL;
  107. struct oc_vpn_option *cookie;
  108. struct oc_text_buf *buf;
  109. for (cookie = vpninfo->cookies; cookie; cookie = cookie->next) {
  110. if (!strcmp(cookie->option, "DSFirstAccess"))
  111. dsfirst = cookie->value;
  112. else if (!strcmp(cookie->option, "DSLastAccess"))
  113. dslast = cookie->value;
  114. else if (!strcmp(cookie->option, "DSID"))
  115. dsid = cookie->value;
  116. else if (!strcmp(cookie->option, "DSSignInUrl"))
  117. dsurl = cookie->value;
  118. else if (!strcmp(cookie->option, "DSSIGNIN")) {
  119. free(vpninfo->csd_starturl);
  120. vpninfo->csd_starturl = strdup(cookie->value);
  121. } else if (!strcmp(cookie->option, "DSPREAUTH")) {
  122. free(vpninfo->csd_token);
  123. vpninfo->csd_token = strdup(cookie->value);
  124. }
  125. }
  126. if (!dsid)
  127. return -ENOENT;
  128. if (vpninfo->tncc_fd != -1) {
  129. /* update TNCC once we get a DSID cookie */
  130. oncp_send_tncc_command(vpninfo, 0);
  131. }
  132. /* XXX: Do these need escaping? Could they theoreetically have semicolons in? */
  133. buf = buf_alloc();
  134. buf_append(buf, "DSID=%s", dsid);
  135. if (dsfirst)
  136. buf_append(buf, "; DSFirst=%s", dsfirst);
  137. if (dslast)
  138. buf_append(buf, "; DSLast=%s", dslast);
  139. if (dsurl)
  140. buf_append(buf, "; DSSignInUrl=%s", dsurl);
  141. if (buf_error(buf))
  142. return buf_free(buf);
  143. free(vpninfo->cookie);
  144. vpninfo->cookie = buf->data;
  145. buf->data = NULL;
  146. buf_free(buf);
  147. return 0;
  148. }
  149. #ifdef _WIN32
  150. static int tncc_preauth(struct openconnect_info *vpninfo)
  151. {
  152. vpn_progress(vpninfo, PRG_ERR,
  153. _("TNCC support not implemented yet on Windows\n"));
  154. return -EOPNOTSUPP;
  155. }
  156. #else
  157. static int tncc_preauth(struct openconnect_info *vpninfo)
  158. {
  159. int sockfd[2];
  160. pid_t pid;
  161. const char *dspreauth = vpninfo->csd_token;
  162. char recvbuf[1024];
  163. int len, count, ret;
  164. if (!dspreauth) {
  165. vpn_progress(vpninfo, PRG_ERR,
  166. _("No DSPREAUTH cookie; not attempting TNCC\n"));
  167. return -EINVAL;
  168. }
  169. vpn_progress(vpninfo, PRG_INFO,
  170. _("Trying to run TNCC/Host Checker Trojan script '%s'.\n"),
  171. vpninfo->csd_wrapper);
  172. #ifdef SOCK_CLOEXEC
  173. if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sockfd))
  174. #endif
  175. {
  176. if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd))
  177. return -errno;
  178. set_fd_cloexec(sockfd[0]);
  179. set_fd_cloexec(sockfd[1]);
  180. }
  181. pid = fork();
  182. if (pid == -1) {
  183. close(sockfd[0]);
  184. close(sockfd[1]);
  185. return -errno;
  186. }
  187. if (!pid) {
  188. int i;
  189. /* Fork again to detach grandchild */
  190. if (fork())
  191. exit(1);
  192. close(sockfd[1]);
  193. /* The duplicated fd does not have O_CLOEXEC */
  194. dup2(sockfd[0], 0);
  195. /* We really don't want anything going to our stdout.
  196. Redirect the child's stdout, to our stderr. */
  197. dup2(2, 1);
  198. /* And close everything else.*/
  199. for (i = 3; i < 1024 ; i++)
  200. close(i);
  201. if (setenv("TNCC_SHA256", openconnect_get_peer_cert_hash(vpninfo)+11, 1)) /* remove initial 'pin-sha256:' */
  202. goto out;
  203. if (setenv("TNCC_HOSTNAME", vpninfo->localname, 1))
  204. goto out;
  205. if (!vpninfo->trojan_interval) {
  206. char is[32];
  207. snprintf(is, 32, "%d", vpninfo->trojan_interval);
  208. if (setenv("TNCC_INTERVAL", is, 1))
  209. goto out;
  210. }
  211. execl(vpninfo->csd_wrapper, vpninfo->csd_wrapper, vpninfo->hostname, NULL);
  212. out:
  213. fprintf(stderr, _("Failed to exec TNCC script %s: %s\n"),
  214. vpninfo->csd_wrapper, strerror(errno));
  215. exit(1);
  216. }
  217. waitpid(pid, NULL, 0);
  218. close(sockfd[0]);
  219. vpninfo->tncc_fd = sockfd[1];
  220. ret = oncp_send_tncc_command(vpninfo, 1);
  221. if (ret < 0) {
  222. err:
  223. close(vpninfo->tncc_fd);
  224. vpninfo->tncc_fd = -1;
  225. return ret;
  226. }
  227. vpn_progress(vpninfo, PRG_DEBUG,
  228. _("Sent start; waiting for response from TNCC\n"));
  229. /* First line: HTTP-like response code. */
  230. len = cancellable_gets(vpninfo, sockfd[1], recvbuf, sizeof(recvbuf));
  231. if (len < 0) {
  232. respfail:
  233. vpn_progress(vpninfo, PRG_ERR,
  234. _("Failed to read response from TNCC\n"));
  235. ret = -EIO;
  236. goto err;
  237. }
  238. if (strcmp(recvbuf, "200")) {
  239. vpn_progress(vpninfo, PRG_ERR,
  240. _("Received unsuccessful %s response from TNCC\n"),
  241. recvbuf);
  242. ret = -EINVAL;
  243. goto err;
  244. }
  245. vpn_progress(vpninfo, PRG_TRACE, _("TNCC response 200 OK\n"));
  246. /* We're not sure what the second line is. We ignore it. */
  247. len = cancellable_gets(vpninfo, sockfd[1], recvbuf, sizeof(recvbuf));
  248. if (len < 0)
  249. goto respfail;
  250. vpn_progress(vpninfo, PRG_TRACE, _("Second line of TNCC response: '%s'\n"),
  251. recvbuf);
  252. /* Third line is the DSPREAUTH cookie */
  253. len = cancellable_gets(vpninfo, sockfd[1], recvbuf, sizeof(recvbuf));
  254. if (len < 0)
  255. goto respfail;
  256. vpn_progress(vpninfo, PRG_DEBUG,
  257. _("Got new DSPREAUTH cookie from TNCC: %s\n"),
  258. recvbuf);
  259. http_add_cookie(vpninfo, "DSPREAUTH", recvbuf, 1);
  260. /* Fourth line, if present, is the interval to rerun TNCC */
  261. len = cancellable_gets(vpninfo, sockfd[1], recvbuf, sizeof(recvbuf));
  262. if (len < 0)
  263. goto respfail;
  264. if (len > 0) {
  265. int interval = atoi(recvbuf);
  266. if (interval != 0) {
  267. vpninfo->trojan_interval = interval;
  268. vpn_progress(vpninfo, PRG_DEBUG,
  269. _("Got reauth interval from TNCC: %d seconds\n"),
  270. interval);
  271. }
  272. }
  273. count = 0;
  274. do {
  275. len = cancellable_gets(vpninfo, sockfd[1], recvbuf,
  276. sizeof(recvbuf));
  277. if (len < 0)
  278. goto respfail;
  279. if (len > 0)
  280. vpn_progress(vpninfo, PRG_DEBUG,
  281. _("Unexpected non-empty line from TNCC after DSPREAUTH cookie: '%s'\n"),
  282. recvbuf);
  283. } while (len && (count++ < 10));
  284. if (len > 0) {
  285. vpn_progress(vpninfo, PRG_ERR,
  286. _("Too many non-empty lines from TNCC after DSPREAUTH cookie\n"));
  287. goto respfail;
  288. }
  289. return 0;
  290. }
  291. #endif
  292. static struct oc_auth_form *parse_roles_table_node(xmlNodePtr node)
  293. {
  294. struct oc_auth_form *form;
  295. xmlNodePtr table_itr;
  296. xmlNodePtr row_itr;
  297. xmlNodePtr data_itr;
  298. struct oc_form_opt_select *opt;
  299. struct oc_choice *choice;
  300. form = calloc(1, sizeof(*form));
  301. if (!form)
  302. return NULL;
  303. form->auth_id = strdup("frmSelectRoles");
  304. if (!form->auth_id) {
  305. free(form);
  306. return NULL;
  307. };
  308. opt = calloc(1, sizeof(*opt));
  309. if (!opt) {
  310. free_auth_form(form);
  311. return NULL;
  312. }
  313. form->opts = &opt->form;
  314. opt->form.label = strdup("frmSelectRoles");
  315. opt->form.name = strdup("frmSelectRoles");
  316. opt->form.type = OC_FORM_OPT_SELECT;
  317. form->authgroup_opt = opt; /* XX: --authgroup also sets realm field (see parse_select_node in auth-html.c) */
  318. for (table_itr = node->children; table_itr; table_itr = table_itr->next) {
  319. if (!table_itr->name || strcasecmp((const char *)table_itr->name, "tr"))
  320. continue;
  321. for (row_itr = table_itr->children; row_itr; row_itr = row_itr->next) {
  322. if (!row_itr->name || strcasecmp((const char *)row_itr->name, "td"))
  323. continue;
  324. for (data_itr = row_itr->children; data_itr; data_itr = data_itr->next) {
  325. struct oc_choice **new_choices;
  326. char *role_link = NULL;
  327. char *role_name = NULL;
  328. if (!data_itr->name || strcasecmp((const char *)data_itr->name, "a"))
  329. continue;
  330. // Discovered <a> tag with role selection.
  331. role_link = (char *)xmlGetProp(data_itr, (unsigned char *)"href");
  332. if (!role_link)
  333. continue;
  334. role_name = (char *)xmlNodeGetContent(data_itr);
  335. if (!role_name) {
  336. // some weird case?
  337. free(role_link);
  338. continue;
  339. }
  340. choice = calloc(1, sizeof(*choice));
  341. if (!choice) {
  342. free(role_name);
  343. free(role_link);
  344. free_auth_form(form);
  345. return NULL;
  346. }
  347. choice->label = role_name;
  348. choice->name = role_link;
  349. new_choices = realloc(opt->choices, sizeof(opt->choices[0]) * (opt->nr_choices+1));
  350. if (!new_choices) {
  351. free(choice);
  352. free(role_name);
  353. free(role_link);
  354. free_auth_form(form);
  355. return NULL;
  356. }
  357. opt->choices = new_choices;
  358. opt->choices[opt->nr_choices++] = choice;
  359. }
  360. }
  361. }
  362. return form;
  363. }
  364. static struct oc_auth_form *parse_roles_form_node(xmlNodePtr node)
  365. {
  366. struct oc_auth_form *form = NULL;
  367. xmlNodePtr child;
  368. // Set form->action here as a redirect url with keys and ids.
  369. for (child = htmlnode_dive(node, node); child && child != node;
  370. child = htmlnode_dive(node, child)) {
  371. if (child->name && !strcasecmp((char *)child->name, "table")) {
  372. char *table_id = (char *)xmlGetProp(child, (unsigned char *)"id");
  373. if (table_id) {
  374. if (!strcmp(table_id, "TABLE_SelectRole_1"))
  375. form = parse_roles_table_node(child);
  376. free(table_id);
  377. if (form)
  378. break;
  379. }
  380. }
  381. }
  382. return form;
  383. }
  384. int oncp_obtain_cookie(struct openconnect_info *vpninfo)
  385. {
  386. int ret;
  387. struct oc_text_buf *resp_buf = NULL;
  388. xmlDocPtr doc = NULL;
  389. xmlNodePtr node;
  390. struct oc_auth_form *form = NULL;
  391. char *form_name = NULL, *form_id = NULL;
  392. int try_tncc = !!vpninfo->csd_wrapper;
  393. resp_buf = buf_alloc();
  394. if (buf_error(resp_buf)) {
  395. ret = buf_error(resp_buf);
  396. goto out;
  397. }
  398. while (1) {
  399. char *form_buf = NULL;
  400. int role_select = 0;
  401. char *url;
  402. if (resp_buf && resp_buf->pos)
  403. ret = do_https_request(vpninfo, "POST", "application/x-www-form-urlencoded", resp_buf,
  404. &form_buf, NULL, HTTP_REDIRECT_TO_GET);
  405. else
  406. ret = do_https_request(vpninfo, "GET", NULL, NULL, &form_buf, NULL, HTTP_REDIRECT_TO_GET);
  407. /* After login, the server will redirect the "browser" to a landing page.
  408. * https://kb.pulsesecure.net/articles/Pulse_Security_Advisories/SA44784
  409. * turned some of those landing pages into a 403 but we don't *care*
  410. * about that as long as we have the cookie we wanted. So check for
  411. * cookie success *before* checking 'ret'. */
  412. if (!check_cookie_success(vpninfo)) {
  413. free(form_buf);
  414. ret = 0;
  415. break;
  416. }
  417. if (ret < 0)
  418. break;
  419. url = internal_get_url(vpninfo);
  420. if (!url) {
  421. free(form_buf);
  422. ret = -ENOMEM;
  423. break;
  424. }
  425. doc = htmlReadMemory(form_buf, ret, url, NULL,
  426. HTML_PARSE_RECOVER|HTML_PARSE_NOERROR|HTML_PARSE_NOWARNING|HTML_PARSE_NONET);
  427. free(url);
  428. free(form_buf);
  429. if (!doc) {
  430. vpn_progress(vpninfo, PRG_ERR,
  431. _("Failed to parse HTML document\n"));
  432. ret = -EINVAL;
  433. break;
  434. }
  435. buf_truncate(resp_buf);
  436. node = find_form_node(doc);
  437. if (!node) {
  438. if (try_tncc) {
  439. try_tncc = 0;
  440. ret = tncc_preauth(vpninfo);
  441. if (ret)
  442. return ret;
  443. goto tncc_done;
  444. }
  445. vpn_progress(vpninfo, PRG_ERR,
  446. _("Failed to find or parse web form in login page\n"));
  447. ret = -EINVAL;
  448. break;
  449. }
  450. free(form_name);
  451. free(form_id);
  452. form_name = (char *)xmlGetProp(node, (unsigned char *)"name");
  453. form_id = (char *)xmlGetProp(node, (unsigned char *)"id");
  454. if (!form_name && !form_id) {
  455. vpn_progress(vpninfo, PRG_ERR,
  456. _("Encountered form with no 'name' or 'id'\n"));
  457. goto dump_form;
  458. } else if (form_name && !strcmp(form_name, "frmLogin")) {
  459. form = parse_form_node(vpninfo, node, "btnSubmit", oncp_can_gen_tokencode);
  460. } else if (form_id && !strcmp(form_id, "loginForm")) {
  461. form = parse_form_node(vpninfo, node, "submitButton", oncp_can_gen_tokencode);
  462. } else if ((form_name && !strcmp(form_name, "frmDefender")) ||
  463. (form_name && !strcmp(form_name, "frmNextToken"))) {
  464. form = parse_form_node(vpninfo, node, "btnAction", oncp_can_gen_tokencode);
  465. } else if (form_name && !strcmp(form_name, "frmConfirmation")) {
  466. form = parse_form_node(vpninfo, node, "btnContinue", oncp_can_gen_tokencode);
  467. if (!form) {
  468. ret = -EINVAL;
  469. break;
  470. }
  471. /* XXX: Actually ask the user? */
  472. goto form_done;
  473. } else if (form_name && !strcmp(form_name, "frmSelectRoles")) {
  474. form = parse_roles_form_node(node);
  475. role_select = 1;
  476. } else if (form_name && !strcmp(form_name, "frmTotpToken")) {
  477. form = parse_form_node(vpninfo, node, "totpactionEnter", oncp_can_gen_tokencode);
  478. } else if ((form_name && !strcmp(form_name, "hiddenform")) ||
  479. (form_id && !strcmp(form_id, "formSAMLSSO"))) {
  480. form = parse_form_node(vpninfo, node, "submit", oncp_can_gen_tokencode);
  481. } else {
  482. char *form_action = (char *)xmlGetProp(node, (unsigned char *)"action");
  483. if (form_action && strstr(form_action, "remediate.cgi")) {
  484. vpn_progress(vpninfo, PRG_ERR,
  485. _("Form action (%s) likely indicates that TNCC/Host Checker failed.\n"),
  486. form_action);
  487. }
  488. free(form_action);
  489. vpn_progress(vpninfo, PRG_ERR,
  490. _("Unknown form (name '%s', id '%s')\n"),
  491. form_name, form_id);
  492. dump_form:
  493. fprintf(stderr, _("Dumping unknown HTML form:\n"));
  494. htmlNodeDumpFileFormat(stderr, node->doc, node, NULL, 1);
  495. ret = -EINVAL;
  496. break;
  497. }
  498. if (!form) {
  499. ret = -EINVAL;
  500. break;
  501. }
  502. do {
  503. ret = process_auth_form(vpninfo, form);
  504. } while (ret == OC_FORM_RESULT_NEWGROUP);
  505. if (ret)
  506. goto out;
  507. ret = do_gen_tokencode(vpninfo, form);
  508. if (ret) {
  509. vpn_progress(vpninfo, PRG_ERR, _("Failed to generate OTP tokencode; disabling token\n"));
  510. vpninfo->token_bypassed = 1;
  511. goto out;
  512. }
  513. /* frmSelectRoles is special; it's actually *links*, not a form. So
  514. * we need to process it differently... */
  515. if (role_select) {
  516. vpninfo->redirect_url = strdup(form->opts[0]._value);
  517. goto do_redirect;
  518. }
  519. form_done:
  520. append_form_opts(vpninfo, form, resp_buf);
  521. ret = buf_error(resp_buf);
  522. if (ret)
  523. break;
  524. if (form->action) {
  525. vpninfo->redirect_url = form->action;
  526. form->action = NULL;
  527. }
  528. do_redirect:
  529. free_auth_form(form);
  530. form = NULL;
  531. if (vpninfo->redirect_url)
  532. handle_redirect(vpninfo);
  533. tncc_done:
  534. xmlFreeDoc(doc);
  535. doc = NULL;
  536. }
  537. out:
  538. if (doc)
  539. xmlFreeDoc(doc);
  540. free(form_name);
  541. free(form_id);
  542. if (form)
  543. free_auth_form(form);
  544. buf_free(resp_buf);
  545. return ret;
  546. }