chat_login.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /* chat_login: see chat_login.h. */
  2. #include "chat_login.h"
  3. /* ---- small string helpers (no libc: also built on the host) ---- */
  4. static unsigned int c_len(const char *s)
  5. {
  6. unsigned int n = 0;
  7. while (s && s[n])
  8. n++;
  9. return n;
  10. }
  11. static void c_copy(char *d, const char *s, unsigned int cap)
  12. {
  13. unsigned int i = 0;
  14. if (!cap)
  15. return;
  16. while (s && s[i] && i + 1 < cap) {
  17. d[i] = s[i];
  18. i++;
  19. }
  20. d[i] = '\0';
  21. }
  22. static int c_prefix(const char *s, const char *p)
  23. {
  24. while (*p) {
  25. if (*s != *p)
  26. return 0;
  27. s++;
  28. p++;
  29. }
  30. return 1;
  31. }
  32. static int __attribute__((unused)) c_suffix(const char *s, const char *suf)
  33. {
  34. unsigned int a = c_len(s), b = c_len(suf), i;
  35. if (b > a)
  36. return 0;
  37. for (i = 0; i < b; i++)
  38. if (s[a - b + i] != suf[i])
  39. return 0;
  40. return 1;
  41. }
  42. /* Find needle in hay[0..len); index or -1. */
  43. static int c_find(const char *hay, unsigned int len, const char *needle,
  44. unsigned int from)
  45. {
  46. unsigned int n = c_len(needle), i, j;
  47. if (!n || n > len)
  48. return -1;
  49. for (i = from; i + n <= len; i++) {
  50. for (j = 0; j < n; j++)
  51. if (hay[i + j] != needle[j])
  52. break;
  53. if (j == n)
  54. return (int)i;
  55. }
  56. return -1;
  57. }
  58. /* ---- server URL / config file ---- */
  59. int chat_server_normalize(const char *in, char *out, unsigned int cap)
  60. {
  61. unsigned int n = 0, i = 0, len;
  62. while (in[i] == ' ' || in[i] == '\t')
  63. i++;
  64. if (!c_prefix(in + i, "https://") && !c_prefix(in + i, "http://")) {
  65. const char *pre = "https://";
  66. while (*pre && n + 1 < cap)
  67. out[n++] = *pre++;
  68. }
  69. while (in[i] && in[i] != ' ' && in[i] != '\t' && n + 1 < cap)
  70. out[n++] = in[i++];
  71. out[n] = '\0';
  72. if (in[i] && in[i] != ' ' && in[i] != '\t')
  73. return -1; /* did not fit */
  74. while (in[i] == ' ' || in[i] == '\t')
  75. i++;
  76. if (in[i])
  77. return -1; /* embedded space */
  78. while (n > 0 && out[n - 1] == '/')
  79. out[--n] = '\0';
  80. len = n;
  81. /* need a host after the scheme */
  82. if (c_prefix(out, "https://"))
  83. return len > 8 ? 0 : -1;
  84. return len > 7 ? 0 : -1;
  85. }
  86. int chat_config_parse(const char *text, unsigned int len, char *server,
  87. unsigned int scap, char *cookie, unsigned int ccap)
  88. {
  89. unsigned int i = 0;
  90. int found = 0;
  91. if (scap)
  92. server[0] = '\0';
  93. if (ccap)
  94. cookie[0] = '\0';
  95. while (i < len) {
  96. unsigned int s = i, e, k;
  97. char *dst = 0;
  98. unsigned int cap = 0;
  99. while (i < len && text[i] != '\n')
  100. i++;
  101. e = i;
  102. if (i < len)
  103. i++;
  104. while (e > s && (text[e - 1] == '\r' || text[e - 1] == ' '))
  105. e--;
  106. while (s < e && (text[s] == ' ' || text[s] == '\t'))
  107. s++;
  108. if (s == e || text[s] == '#')
  109. continue;
  110. if (e - s > 7 && c_prefix(text + s, "server=")) {
  111. dst = server;
  112. cap = scap;
  113. s += 7;
  114. } else if (e - s > 7 && c_prefix(text + s, "cookie=")) {
  115. dst = cookie;
  116. cap = ccap;
  117. s += 7;
  118. }
  119. if (!dst || !cap)
  120. continue;
  121. for (k = 0; s + k < e && k + 1 < cap; k++)
  122. dst[k] = text[s + k];
  123. dst[k] = '\0';
  124. found = 1;
  125. }
  126. return found ? 0 : -1;
  127. }
  128. int chat_config_format(char *out, unsigned int cap, const char *server,
  129. const char *cookie)
  130. {
  131. unsigned int n = 0;
  132. #define APP(s) do { const char *ap = (s); \
  133. while (*ap) { if (n + 1 >= cap) return -1; out[n++] = *ap++; } } while (0)
  134. APP("# NebOS chat session (the cookie is a bearer credential)\n");
  135. APP("server=");
  136. APP(server);
  137. APP("\n");
  138. if (cookie && cookie[0]) {
  139. APP("cookie=");
  140. APP(cookie);
  141. APP("\n");
  142. }
  143. #undef APP
  144. out[n] = '\0';
  145. return (int)n;
  146. }
  147. int chat_login_body(char *out, unsigned int cap, const char *user,
  148. const char *pass, const char *totp)
  149. {
  150. unsigned int n = 0;
  151. int r;
  152. #define LIT(s) do { const char *ap = (s); \
  153. while (*ap) { if (n + 1 >= cap) return -1; out[n++] = *ap++; } } while (0)
  154. #define STR(s) do { \
  155. r = ujson_escape(out + n, cap - n, (s)); \
  156. if (r < 0) \
  157. return -1; \
  158. n += (unsigned int)r; \
  159. } while (0)
  160. LIT("{\"username\":");
  161. STR(user);
  162. LIT(",\"password\":");
  163. STR(pass);
  164. LIT(",\"totpToken\":");
  165. STR(totp ? totp : "");
  166. LIT("}");
  167. #undef LIT
  168. #undef STR
  169. out[n] = '\0';
  170. return (int)n;
  171. }
  172. /* ---- page / reply parsing ---- */
  173. static struct ujson_node pnodes[512];
  174. static char psbuf[8192];
  175. /* Resolve href against an absolute base URL. Handles absolute URLs,
  176. * scheme-relative, absolute-path and directory-relative references. */
  177. static int resolve(const char *base, const char *href, char *out,
  178. unsigned int cap)
  179. {
  180. unsigned int n = 0, i, origin_end, dir_end;
  181. if (c_prefix(href, "http://") || c_prefix(href, "https://")) {
  182. if (c_len(href) + 1 > cap)
  183. return -1;
  184. c_copy(out, href, cap);
  185. return 0;
  186. }
  187. /* origin = scheme://host[:port] */
  188. i = 0;
  189. while (base[i] && base[i] != ':')
  190. i++;
  191. if (base[i] != ':' || base[i + 1] != '/' || base[i + 2] != '/')
  192. return -1;
  193. if (href[0] == '/' && href[1] == '/') {
  194. if (i + 1 + c_len(href) + 1 > cap)
  195. return -1;
  196. for (n = 0; n <= i; n++)
  197. out[n] = base[n];
  198. c_copy(out + n, href, cap - n);
  199. return 0;
  200. }
  201. i += 3;
  202. while (base[i] && base[i] != '/' && base[i] != '?' && base[i] != '#')
  203. i++;
  204. origin_end = i;
  205. dir_end = origin_end;
  206. while (base[i] && base[i] != '?' && base[i] != '#') {
  207. if (base[i] == '/')
  208. dir_end = i;
  209. i++;
  210. }
  211. if (href[0] == '/') {
  212. if (origin_end + c_len(href) + 1 > cap)
  213. return -1;
  214. for (n = 0; n < origin_end; n++)
  215. out[n] = base[n];
  216. c_copy(out + n, href, cap - n);
  217. return 0;
  218. }
  219. if (dir_end + 1 + c_len(href) + 1 > cap)
  220. return -1;
  221. for (n = 0; n < dir_end; n++)
  222. out[n] = base[n];
  223. out[n++] = '/';
  224. c_copy(out + n, href, cap - n);
  225. return 0;
  226. }
  227. int chat_login_parse_page(const char *html, unsigned int len,
  228. const char *base_url, char *submit_url,
  229. unsigned int cap, char *app_name,
  230. unsigned int name_cap)
  231. {
  232. struct ujson j;
  233. char raw[1024];
  234. int at, s, e, root;
  235. submit_url[0] = '\0';
  236. if (name_cap)
  237. app_name[0] = '\0';
  238. raw[0] = '\0';
  239. at = c_find(html, len, "id=\"cloudron-config\"", 0);
  240. if (at >= 0) {
  241. s = c_find(html, len, ">", (unsigned int)at);
  242. e = s >= 0 ? c_find(html, len, "</script", (unsigned int)s) : -1;
  243. if (s >= 0 && e > s) {
  244. ujson_init(&j, pnodes, sizeof(pnodes) / sizeof(pnodes[0]),
  245. psbuf, sizeof(psbuf));
  246. root = ujson_parse(&j, html + s + 1,
  247. (unsigned int)(e - s - 1));
  248. if (root >= 0) {
  249. c_copy(raw, ujson_get_str(&j, root, "submitUrl"),
  250. sizeof(raw));
  251. if (name_cap)
  252. c_copy(app_name,
  253. ujson_get_str(&j, root, "name"),
  254. name_cap);
  255. }
  256. }
  257. }
  258. if (!raw[0]) {
  259. /* Fallback: a plain scan, unescaping \/ only. */
  260. at = c_find(html, len, "\"submitUrl\":\"", 0);
  261. if (at >= 0) {
  262. unsigned int i = (unsigned int)at + 13, k = 0;
  263. while (i < len && html[i] != '"' && k + 1 < sizeof(raw)) {
  264. if (html[i] == '\\' && i + 1 < len)
  265. i++;
  266. raw[k++] = html[i++];
  267. }
  268. raw[k] = '\0';
  269. if (i >= len || html[i] != '"')
  270. raw[0] = '\0';
  271. }
  272. }
  273. if (!raw[0])
  274. return -1;
  275. return resolve(base_url, raw, submit_url, cap);
  276. }
  277. int chat_login_parse_reply(int status, const char *body, unsigned int len,
  278. char *redirect, unsigned int rcap, char *msg,
  279. unsigned int mcap)
  280. {
  281. struct ujson j;
  282. int root;
  283. if (rcap)
  284. redirect[0] = '\0';
  285. if (mcap)
  286. msg[0] = '\0';
  287. ujson_init(&j, pnodes, sizeof(pnodes) / sizeof(pnodes[0]), psbuf,
  288. sizeof(psbuf));
  289. root = ujson_parse(&j, body, len);
  290. if (root >= 0 && ujson_type(&j, root) == UJSON_OBJECT) {
  291. const char *m = ujson_get_str(&j, root, "message");
  292. if (!m[0])
  293. m = ujson_get_str(&j, root, "error");
  294. c_copy(msg, m, mcap);
  295. }
  296. if (status == 401 || status == 403)
  297. return CHAT_REPLY_DENIED;
  298. if (status != 200 || root < 0 || ujson_type(&j, root) != UJSON_OBJECT)
  299. return CHAT_REPLY_ERROR;
  300. if (ujson_truthy(&j, ujson_get(&j, root, "twoFactorRequired"))) {
  301. if (ujson_truthy(&j, ujson_get(&j, root, "totpRequired")))
  302. return CHAT_REPLY_TOTP;
  303. return CHAT_REPLY_PASSKEY;
  304. }
  305. c_copy(redirect, ujson_get_str(&j, root, "redirectTo"), rcap);
  306. if (!redirect[0])
  307. return CHAT_REPLY_ERROR;
  308. return CHAT_REPLY_REDIRECT;
  309. }
  310. #ifndef CHAT_LOGIN_PURE
  311. /* ---- HTTP helpers ---- */
  312. int chat_http_body(struct uhttp *h, char *buf, unsigned int cap)
  313. {
  314. unsigned int n = 0;
  315. for (;;) {
  316. int r;
  317. if (n + 1 >= cap) {
  318. char scratch[1];
  319. /* Full: is there more? */
  320. r = uhttp_read(h, scratch, 1, UHTTP_IDLE_TIMEOUT_MS);
  321. buf[n] = '\0';
  322. if (r > 0) {
  323. h->keepalive = 0;
  324. uhttp_close(h);
  325. return UHTTP_ERR_TOOLONG;
  326. }
  327. break;
  328. }
  329. r = uhttp_read(h, buf + n, cap - 1 - n, UHTTP_IDLE_TIMEOUT_MS);
  330. if (r < 0) {
  331. buf[n] = '\0';
  332. h->keepalive = 0;
  333. uhttp_close(h);
  334. return r;
  335. }
  336. if (r == 0)
  337. break;
  338. n += (unsigned int)r;
  339. }
  340. buf[n] = '\0';
  341. uhttp_close(h);
  342. return (int)n;
  343. }
  344. int chat_http(struct uhttp *h, const char *method, const char *url,
  345. const char *json, char *buf, unsigned int cap,
  346. unsigned int *blen)
  347. {
  348. int r;
  349. if (blen)
  350. *blen = 0;
  351. h->keepalive = 1;
  352. if (method && json)
  353. uhttp_set_method(h, method, json, c_len(json),
  354. "application/json");
  355. else if (method)
  356. /* uhttp only sends Content-Length with a body, so a bodyless
  357. * POST carries an empty JSON object instead. */
  358. uhttp_set_method(h, method, "{}", 2, "application/json");
  359. else
  360. uhttp_set_method(h, 0, 0, 0, 0);
  361. r = uhttp_open(h, url, 0, 0);
  362. if (r != 0)
  363. return r;
  364. r = chat_http_body(h, buf, cap);
  365. if (r < 0)
  366. return r;
  367. if (blen)
  368. *blen = (unsigned int)r;
  369. return h->resp.status;
  370. }
  371. int chat_server_host(const char *server, char *host, unsigned int cap,
  372. int *secure)
  373. {
  374. struct uhttp_url u;
  375. if (uhttp_parse_url(server, &u) != 0)
  376. return -1;
  377. c_copy(host, u.host, cap);
  378. if (secure)
  379. *secure = u.secure;
  380. return 0;
  381. }
  382. static void set_err(struct chat_login *l, const char *a, const char *b)
  383. {
  384. unsigned int n = 0;
  385. while (a && *a && n + 1 < sizeof(l->error))
  386. l->error[n++] = *a++;
  387. while (b && *b && n + 1 < sizeof(l->error))
  388. l->error[n++] = *b++;
  389. l->error[n] = '\0';
  390. }
  391. /* 1 when the response that ended at final_url is back on the Chat host. */
  392. static int on_server(const struct chat_login *l, const char *final_url)
  393. {
  394. unsigned int n = c_len(l->server);
  395. unsigned int i;
  396. for (i = 0; i < n; i++)
  397. if (final_url[i] != l->server[i])
  398. return 0;
  399. return final_url[n] == '\0' || final_url[n] == '/' ||
  400. final_url[n] == '?';
  401. }
  402. int chat_session_check(struct uhttp *h, struct uhttp_jar *jar,
  403. const char *server, char *buf, unsigned int cap,
  404. unsigned int *blen)
  405. {
  406. char url[CHAT_SERVER_MAX + 16];
  407. int st;
  408. c_copy(url, server, sizeof(url));
  409. c_copy(url + c_len(url), "/api/me", sizeof(url) - c_len(url));
  410. h->jar = jar;
  411. h->accept = "application/json";
  412. st = chat_http(h, 0, url, 0, buf, cap, blen);
  413. if (st == 200)
  414. return 0;
  415. if (st == 401 || st == 403)
  416. return 1;
  417. if (st > 0)
  418. return -100 - st;
  419. return st;
  420. }
  421. /* After a successful submit (or an existing provider session) the page may
  422. * still be an interaction: a consent prompt (auto-confirmed, like the web
  423. * UI does) or an abort page (no access to the app). */
  424. static int finish(struct chat_login *l, struct uhttp *h,
  425. struct uhttp_jar *jar, const char *url, char *buf,
  426. unsigned int cap)
  427. {
  428. unsigned int len;
  429. int st, round;
  430. const char *method = 0;
  431. c_copy(l->redirect, url, sizeof(l->redirect));
  432. for (round = 0; round < 3; round++) {
  433. h->jar = jar;
  434. h->accept = "text/html,application/json,*/*";
  435. st = chat_http(h, method, l->redirect, 0, buf, cap, &len);
  436. if (st < 0) {
  437. set_err(l, "Login redirect failed: ",
  438. uhttp_error_string(st));
  439. return CHAT_LOGIN_ERROR;
  440. }
  441. if (on_server(l, h->resp.final_url)) {
  442. unsigned int me_len;
  443. if (c_find(h->resp.final_url,
  444. c_len(h->resp.final_url),
  445. "error=auth_failed", 0) >= 0) {
  446. set_err(l, "The Chat server rejected the login "
  447. "(auth_failed)", 0);
  448. return CHAT_LOGIN_ERROR;
  449. }
  450. st = chat_session_check(h, jar, l->server, buf, cap,
  451. &me_len);
  452. if (st == 0)
  453. return CHAT_LOGIN_OK;
  454. set_err(l, st == 1 ? "Signed in, but the Chat session "
  455. "was not accepted" : "Session check failed", 0);
  456. return CHAT_LOGIN_ERROR;
  457. }
  458. if (chat_login_parse_page(buf, len, h->resp.final_url,
  459. l->submit_url,
  460. sizeof(l->submit_url), l->app_name,
  461. sizeof(l->app_name)) != 0) {
  462. set_err(l, "Login did not return to the Chat server", 0);
  463. return CHAT_LOGIN_ERROR;
  464. }
  465. if (c_suffix(l->submit_url, "/confirm")) {
  466. c_copy(l->redirect, l->submit_url, sizeof(l->redirect));
  467. method = "POST";
  468. continue;
  469. }
  470. if (c_suffix(l->submit_url, "/abort")) {
  471. set_err(l, "This account has no access to the Chat app",
  472. 0);
  473. return CHAT_LOGIN_ERROR;
  474. }
  475. /* Back at a login form: the provider wants credentials. */
  476. return CHAT_LOGIN_FORM;
  477. }
  478. set_err(l, "Too many login interaction steps", 0);
  479. return CHAT_LOGIN_ERROR;
  480. }
  481. int chat_login_start(struct chat_login *l, struct uhttp *h,
  482. struct uhttp_jar *jar, const char *server, char *buf,
  483. unsigned int cap)
  484. {
  485. char url[CHAT_SERVER_MAX + 16];
  486. unsigned int len;
  487. int st;
  488. l->error[0] = '\0';
  489. l->submit_url[0] = '\0';
  490. l->app_name[0] = '\0';
  491. l->totp_required = 0;
  492. if (chat_server_normalize(server, l->server, sizeof(l->server)) != 0) {
  493. set_err(l, "Invalid server address", 0);
  494. return CHAT_LOGIN_ERROR;
  495. }
  496. c_copy(url, l->server, sizeof(url));
  497. c_copy(url + c_len(url), "/auth/login", sizeof(url) - c_len(url));
  498. h->jar = jar;
  499. h->accept = "text/html,*/*";
  500. st = chat_http(h, 0, url, 0, buf, cap, &len);
  501. if (st < 0) {
  502. set_err(l, "Cannot reach the server: ", uhttp_error_string(st));
  503. return CHAT_LOGIN_ERROR;
  504. }
  505. if (on_server(l, h->resp.final_url) && st == 200) {
  506. /* The provider already knew us and sent us straight back. */
  507. unsigned int me_len;
  508. if (chat_session_check(h, jar, l->server, buf, cap,
  509. &me_len) == 0)
  510. return CHAT_LOGIN_OK;
  511. }
  512. if (st != 200) {
  513. char code[8];
  514. unsigned int v = (unsigned int)st, k = 0, i;
  515. char tmp[8];
  516. while (v && k < sizeof(tmp)) {
  517. tmp[k++] = (char)('0' + v % 10);
  518. v /= 10;
  519. }
  520. for (i = 0; i < k; i++)
  521. code[i] = tmp[k - 1 - i];
  522. code[k] = '\0';
  523. set_err(l, "Login page returned HTTP ", code);
  524. return CHAT_LOGIN_ERROR;
  525. }
  526. if (chat_login_parse_page(buf, len, h->resp.final_url, l->submit_url,
  527. sizeof(l->submit_url), l->app_name,
  528. sizeof(l->app_name)) != 0) {
  529. set_err(l, "No Cloudron login form (external SSO or passkey "
  530. "login?) - use the cookie option", 0);
  531. return CHAT_LOGIN_NOFORM;
  532. }
  533. if (c_suffix(l->submit_url, "/confirm") ||
  534. c_suffix(l->submit_url, "/abort"))
  535. return finish(l, h, jar, h->resp.final_url, buf, cap);
  536. return CHAT_LOGIN_FORM;
  537. }
  538. int chat_login_submit(struct chat_login *l, struct uhttp *h,
  539. struct uhttp_jar *jar, const char *user,
  540. const char *pass, const char *totp, char *buf,
  541. unsigned int cap)
  542. {
  543. static char body[1600];
  544. char msg[128];
  545. unsigned int len;
  546. int st, kind;
  547. l->error[0] = '\0';
  548. if (!l->submit_url[0]) {
  549. set_err(l, "No login form", 0);
  550. return CHAT_LOGIN_ERROR;
  551. }
  552. if (chat_login_body(body, sizeof(body), user, pass, totp) < 0) {
  553. set_err(l, "Username or password too long", 0);
  554. return CHAT_LOGIN_ERROR;
  555. }
  556. h->jar = jar;
  557. h->accept = "application/json";
  558. st = chat_http(h, "POST", l->submit_url, body, buf, cap, &len);
  559. /* The body held the password: wipe it right away. */
  560. {
  561. unsigned int i;
  562. for (i = 0; i < sizeof(body); i++)
  563. body[i] = 0;
  564. }
  565. if (st < 0) {
  566. set_err(l, "Login request failed: ", uhttp_error_string(st));
  567. return CHAT_LOGIN_ERROR;
  568. }
  569. kind = chat_login_parse_reply(st, buf, len, l->redirect,
  570. sizeof(l->redirect), msg, sizeof(msg));
  571. switch (kind) {
  572. case CHAT_REPLY_DENIED:
  573. set_err(l, msg[0] ? msg : "Username and password do not match",
  574. 0);
  575. return CHAT_LOGIN_DENIED;
  576. case CHAT_REPLY_TOTP:
  577. l->totp_required = 1;
  578. return CHAT_LOGIN_TOTP;
  579. case CHAT_REPLY_PASSKEY:
  580. set_err(l, "This account signs in with a passkey; use the "
  581. "cookie option", 0);
  582. return CHAT_LOGIN_PASSKEY;
  583. case CHAT_REPLY_REDIRECT:
  584. break;
  585. default:
  586. set_err(l, msg[0] ? msg : "Unexpected reply from the login "
  587. "server", 0);
  588. return CHAT_LOGIN_ERROR;
  589. }
  590. {
  591. char next[CHAT_URL_MAX];
  592. /* redirectTo may be relative to the submit URL. */
  593. if (resolve(l->submit_url, l->redirect, next,
  594. sizeof(next)) != 0) {
  595. set_err(l, "Bad login redirect", 0);
  596. return CHAT_LOGIN_ERROR;
  597. }
  598. st = finish(l, h, jar, next, buf, cap);
  599. }
  600. if (st == CHAT_LOGIN_FORM) {
  601. set_err(l, "The login server asked for the password again", 0);
  602. return CHAT_LOGIN_ERROR;
  603. }
  604. return st;
  605. }
  606. #endif