common-session.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. * Dropbear - a SSH2 server
  3. *
  4. * Copyright (c) Matt Johnston
  5. * All rights reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE. */
  24. #include "includes.h"
  25. #include "session.h"
  26. #include "dbutil.h"
  27. #include "packet.h"
  28. #include "algo.h"
  29. #include "buffer.h"
  30. #include "dss.h"
  31. #include "ssh.h"
  32. #include "dbrandom.h"
  33. #include "kex.h"
  34. #include "channel.h"
  35. #include "runopts.h"
  36. #include "netio.h"
  37. static void checktimeouts(void);
  38. static long select_timeout(void);
  39. static int ident_readln(int fd, char* buf, int count);
  40. static void read_session_identification(void);
  41. struct sshsession ses; /* GLOBAL */
  42. /* called only at the start of a session, set up initial state */
  43. void common_session_init(int sock_in, int sock_out) {
  44. time_t now;
  45. #if DEBUG_TRACE
  46. debug_start_net();
  47. #endif
  48. TRACE(("enter session_init"))
  49. ses.sock_in = sock_in;
  50. ses.sock_out = sock_out;
  51. ses.maxfd = MAX(sock_in, sock_out);
  52. if (sock_in >= 0) {
  53. setnonblocking(sock_in);
  54. }
  55. if (sock_out >= 0) {
  56. setnonblocking(sock_out);
  57. }
  58. ses.socket_prio = DROPBEAR_PRIO_NORMAL;
  59. /* Sets it to lowdelay */
  60. update_channel_prio();
  61. #if !DROPBEAR_SVR_MULTIUSER
  62. /* A sanity check to prevent an accidental configuration option
  63. leaving multiuser systems exposed */
  64. errno = 0;
  65. getuid();
  66. if (errno != ENOSYS) {
  67. dropbear_exit("Non-multiuser Dropbear requires a non-multiuser kernel");
  68. }
  69. #endif
  70. now = monotonic_now();
  71. ses.connect_time = now;
  72. ses.last_packet_time_keepalive_recv = now;
  73. ses.last_packet_time_idle = now;
  74. ses.last_packet_time_any_sent = 0;
  75. ses.last_packet_time_keepalive_sent = 0;
  76. #if DROPBEAR_FUZZ
  77. if (!fuzz.fuzzing)
  78. #endif
  79. {
  80. if (pipe(ses.signal_pipe) < 0) {
  81. dropbear_exit("Signal pipe failed");
  82. }
  83. setnonblocking(ses.signal_pipe[0]);
  84. setnonblocking(ses.signal_pipe[1]);
  85. ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[0]);
  86. ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[1]);
  87. }
  88. ses.writepayload = buf_new(TRANS_MAX_PAYLOAD_LEN);
  89. ses.transseq = 0;
  90. ses.readbuf = NULL;
  91. ses.payload = NULL;
  92. ses.recvseq = 0;
  93. initqueue(&ses.writequeue);
  94. ses.requirenext = SSH_MSG_KEXINIT;
  95. ses.dataallowed = 1; /* we can send data until we actually
  96. send the SSH_MSG_KEXINIT */
  97. ses.ignorenext = 0;
  98. ses.lastpacket = 0;
  99. ses.reply_queue_head = NULL;
  100. ses.reply_queue_tail = NULL;
  101. /* set all the algos to none */
  102. ses.keys = (struct key_context*)m_malloc(sizeof(struct key_context));
  103. ses.newkeys = NULL;
  104. ses.keys->recv.algo_crypt = &dropbear_nocipher;
  105. ses.keys->trans.algo_crypt = &dropbear_nocipher;
  106. ses.keys->recv.crypt_mode = &dropbear_mode_none;
  107. ses.keys->trans.crypt_mode = &dropbear_mode_none;
  108. ses.keys->recv.algo_mac = &dropbear_nohash;
  109. ses.keys->trans.algo_mac = &dropbear_nohash;
  110. ses.keys->algo_kex = NULL;
  111. ses.keys->algo_hostkey = -1;
  112. ses.keys->recv.algo_comp = DROPBEAR_COMP_NONE;
  113. ses.keys->trans.algo_comp = DROPBEAR_COMP_NONE;
  114. #ifndef DISABLE_ZLIB
  115. ses.keys->recv.zstream = NULL;
  116. ses.keys->trans.zstream = NULL;
  117. #endif
  118. /* key exchange buffers */
  119. ses.session_id = NULL;
  120. ses.kexhashbuf = NULL;
  121. ses.transkexinit = NULL;
  122. ses.dh_K = NULL;
  123. ses.remoteident = NULL;
  124. ses.chantypes = NULL;
  125. ses.allowprivport = 0;
  126. #if DROPBEAR_PLUGIN
  127. ses.plugin_session = NULL;
  128. #endif
  129. TRACE(("leave session_init"))
  130. }
  131. void session_loop(void(*loophandler)(void)) {
  132. fd_set readfd, writefd;
  133. struct timeval timeout;
  134. int val;
  135. /* main loop, select()s for all sockets in use */
  136. for(;;) {
  137. const int writequeue_has_space = (ses.writequeue_len <= 2*TRANS_MAX_PAYLOAD_LEN);
  138. timeout.tv_sec = select_timeout();
  139. timeout.tv_usec = 0;
  140. DROPBEAR_FD_ZERO(&writefd);
  141. DROPBEAR_FD_ZERO(&readfd);
  142. dropbear_assert(ses.payload == NULL);
  143. /* We get woken up when signal handlers write to this pipe.
  144. SIGCHLD in svr-chansession is the only one currently. */
  145. #if DROPBEAR_FUZZ
  146. if (!fuzz.fuzzing)
  147. #endif
  148. {
  149. FD_SET(ses.signal_pipe[0], &readfd);
  150. }
  151. /* set up for channels which can be read/written */
  152. setchannelfds(&readfd, &writefd, writequeue_has_space);
  153. /* Pending connections to test */
  154. set_connect_fds(&writefd);
  155. /* We delay reading from the input socket during initial setup until
  156. after we have written out our initial KEXINIT packet (empty writequeue).
  157. This means our initial packet can be in-flight while we're doing a blocking
  158. read for the remote ident.
  159. We also avoid reading from the socket if the writequeue is full, that avoids
  160. replies backing up */
  161. if (ses.sock_in != -1
  162. && (ses.remoteident || isempty(&ses.writequeue))
  163. && writequeue_has_space) {
  164. FD_SET(ses.sock_in, &readfd);
  165. }
  166. /* Ordering is important, this test must occur after any other function
  167. might have queued packets (such as connection handlers) */
  168. if (ses.sock_out != -1 && !isempty(&ses.writequeue)) {
  169. FD_SET(ses.sock_out, &writefd);
  170. }
  171. val = select(ses.maxfd+1, &readfd, &writefd, NULL, &timeout);
  172. if (ses.exitflag) {
  173. dropbear_exit("Terminated by signal");
  174. }
  175. if (val < 0 && errno != EINTR) {
  176. dropbear_exit("Error in select");
  177. }
  178. if (val <= 0) {
  179. /* If we were interrupted or the select timed out, we still
  180. * want to iterate over channels etc for reading, to handle
  181. * server processes exiting etc.
  182. * We don't want to read/write FDs. */
  183. DROPBEAR_FD_ZERO(&writefd);
  184. DROPBEAR_FD_ZERO(&readfd);
  185. }
  186. /* We'll just empty out the pipe if required. We don't do
  187. any thing with the data, since the pipe's purpose is purely to
  188. wake up the select() above. */
  189. ses.channel_signal_pending = 0;
  190. if (FD_ISSET(ses.signal_pipe[0], &readfd)) {
  191. char x;
  192. TRACE(("signal pipe set"))
  193. while (read(ses.signal_pipe[0], &x, 1) > 0) {}
  194. ses.channel_signal_pending = 1;
  195. }
  196. /* check for auth timeout, rekeying required etc */
  197. checktimeouts();
  198. /* process session socket's incoming data */
  199. if (ses.sock_in != -1) {
  200. if (FD_ISSET(ses.sock_in, &readfd)) {
  201. if (!ses.remoteident) {
  202. /* blocking read of the version string */
  203. read_session_identification();
  204. } else {
  205. read_packet();
  206. }
  207. }
  208. /* Process the decrypted packet. After this, the read buffer
  209. * will be ready for a new packet */
  210. if (ses.payload != NULL) {
  211. process_packet();
  212. }
  213. }
  214. /* if required, flush out any queued reply packets that
  215. were being held up during a KEX */
  216. maybe_flush_reply_queue();
  217. handle_connect_fds(&writefd);
  218. /* loop handler prior to channelio, in case the server loophandler closes
  219. channels on process exit */
  220. loophandler();
  221. /* process pipes etc for the channels, ses.dataallowed == 0
  222. * during rekeying ) */
  223. channelio(&readfd, &writefd);
  224. /* process session socket's outgoing data */
  225. if (ses.sock_out != -1) {
  226. if (!isempty(&ses.writequeue)) {
  227. write_packet();
  228. }
  229. }
  230. } /* for(;;) */
  231. /* Not reached */
  232. }
  233. static void cleanup_buf(buffer **buf) {
  234. if (!*buf) {
  235. return;
  236. }
  237. buf_burn_free(*buf);
  238. *buf = NULL;
  239. }
  240. /* clean up a session on exit */
  241. void session_cleanup() {
  242. TRACE(("enter session_cleanup"))
  243. /* we can't cleanup if we don't know the session state */
  244. if (!ses.init_done) {
  245. TRACE(("leave session_cleanup: !ses.init_done"))
  246. return;
  247. }
  248. /* BEWARE of changing order of functions here. */
  249. /* Must be before extra_session_cleanup() */
  250. chancleanup();
  251. if (ses.extra_session_cleanup) {
  252. ses.extra_session_cleanup();
  253. }
  254. /* After these are freed most functions will fail */
  255. #if DROPBEAR_CLEANUP
  256. /* listeners call cleanup functions, this should occur before
  257. other session state is freed. */
  258. remove_all_listeners();
  259. remove_connect_pending();
  260. while (!isempty(&ses.writequeue)) {
  261. buf_free(dequeue(&ses.writequeue));
  262. }
  263. m_free(ses.newkeys);
  264. #ifndef DISABLE_ZLIB
  265. if (ses.keys->recv.zstream != NULL) {
  266. if (inflateEnd(ses.keys->recv.zstream) == Z_STREAM_ERROR) {
  267. dropbear_exit("Crypto error");
  268. }
  269. m_free(ses.keys->recv.zstream);
  270. }
  271. #endif
  272. m_free(ses.remoteident);
  273. m_free(ses.authstate.pw_dir);
  274. m_free(ses.authstate.pw_name);
  275. m_free(ses.authstate.pw_shell);
  276. m_free(ses.authstate.pw_passwd);
  277. m_free(ses.authstate.username);
  278. #endif
  279. cleanup_buf(&ses.session_id);
  280. cleanup_buf(&ses.hash);
  281. cleanup_buf(&ses.payload);
  282. cleanup_buf(&ses.readbuf);
  283. cleanup_buf(&ses.writepayload);
  284. cleanup_buf(&ses.kexhashbuf);
  285. cleanup_buf(&ses.transkexinit);
  286. if (ses.dh_K) {
  287. mp_clear(ses.dh_K);
  288. }
  289. m_free(ses.dh_K);
  290. m_burn(ses.keys, sizeof(struct key_context));
  291. m_free(ses.keys);
  292. TRACE(("leave session_cleanup"))
  293. }
  294. void send_session_identification() {
  295. buffer *writebuf = buf_new(strlen(LOCAL_IDENT "\r\n") + 1);
  296. buf_putbytes(writebuf, (const unsigned char *) LOCAL_IDENT "\r\n", strlen(LOCAL_IDENT "\r\n"));
  297. writebuf_enqueue(writebuf);
  298. }
  299. static void read_session_identification() {
  300. /* max length of 255 chars */
  301. char linebuf[256];
  302. int len = 0;
  303. char done = 0;
  304. int i;
  305. /* Servers may send other lines of data before sending the
  306. * version string, client must be able to process such lines.
  307. * If they send more than 50 lines, something is wrong */
  308. for (i = IS_DROPBEAR_CLIENT ? 50 : 1; i > 0; i--) {
  309. len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf));
  310. if (len < 0 && errno != EINTR) {
  311. /* It failed */
  312. break;
  313. }
  314. if (len >= 4 && memcmp(linebuf, "SSH-", 4) == 0) {
  315. /* start of line matches */
  316. done = 1;
  317. break;
  318. }
  319. }
  320. if (!done) {
  321. TRACE(("error reading remote ident: %s\n", strerror(errno)))
  322. ses.remoteclosed();
  323. } else {
  324. /* linebuf is already null terminated */
  325. ses.remoteident = m_malloc(len);
  326. memcpy(ses.remoteident, linebuf, len);
  327. }
  328. /* Shall assume that 2.x will be backwards compatible. */
  329. if (strncmp(ses.remoteident, "SSH-2.", 6) != 0
  330. && strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) {
  331. dropbear_exit("Incompatible remote version '%s'", ses.remoteident);
  332. }
  333. DEBUG1(("remoteident: %s", ses.remoteident))
  334. }
  335. /* returns the length including null-terminating zero on success,
  336. * or -1 on failure */
  337. static int ident_readln(int fd, char* buf, int count) {
  338. char in;
  339. int pos = 0;
  340. int num = 0;
  341. fd_set fds;
  342. struct timeval timeout;
  343. TRACE(("enter ident_readln"))
  344. if (count < 1) {
  345. return -1;
  346. }
  347. DROPBEAR_FD_ZERO(&fds);
  348. /* select since it's a non-blocking fd */
  349. /* leave space to null-terminate */
  350. while (pos < count-1) {
  351. FD_SET(fd, &fds);
  352. timeout.tv_sec = 1;
  353. timeout.tv_usec = 0;
  354. if (select(fd+1, &fds, NULL, NULL, &timeout) < 0) {
  355. if (errno == EINTR) {
  356. continue;
  357. }
  358. TRACE(("leave ident_readln: select error"))
  359. return -1;
  360. }
  361. checktimeouts();
  362. /* Have to go one byte at a time, since we don't want to read past
  363. * the end, and have to somehow shove bytes back into the normal
  364. * packet reader */
  365. if (FD_ISSET(fd, &fds)) {
  366. num = read(fd, &in, 1);
  367. /* a "\n" is a newline, "\r" we want to read in and keep going
  368. * so that it won't be read as part of the next line */
  369. if (num < 0) {
  370. /* error */
  371. if (errno == EINTR) {
  372. continue; /* not a real error */
  373. }
  374. TRACE(("leave ident_readln: read error"))
  375. return -1;
  376. }
  377. if (num == 0) {
  378. /* EOF */
  379. TRACE(("leave ident_readln: EOF"))
  380. return -1;
  381. }
  382. #if DROPBEAR_FUZZ
  383. fuzz_dump(&in, 1);
  384. #endif
  385. if (in == '\n') {
  386. /* end of ident string */
  387. break;
  388. }
  389. /* we don't want to include '\r's */
  390. if (in != '\r') {
  391. buf[pos] = in;
  392. pos++;
  393. }
  394. }
  395. }
  396. buf[pos] = '\0';
  397. TRACE(("leave ident_readln: return %d", pos+1))
  398. return pos+1;
  399. }
  400. void ignore_recv_response() {
  401. /* Do nothing */
  402. TRACE(("Ignored msg_request_response"))
  403. }
  404. static void send_msg_keepalive() {
  405. time_t old_time_idle = ses.last_packet_time_idle;
  406. struct Channel *chan = get_any_ready_channel();
  407. CHECKCLEARTOWRITE();
  408. if (chan) {
  409. /* Channel requests are preferable, more implementations
  410. handle them than SSH_MSG_GLOBAL_REQUEST */
  411. TRACE(("keepalive channel request %d", chan->index))
  412. start_send_channel_request(chan, DROPBEAR_KEEPALIVE_STRING);
  413. } else {
  414. TRACE(("keepalive global request"))
  415. /* Some peers will reply with SSH_MSG_REQUEST_FAILURE,
  416. some will reply with SSH_MSG_UNIMPLEMENTED, some will exit. */
  417. buf_putbyte(ses.writepayload, SSH_MSG_GLOBAL_REQUEST);
  418. buf_putstring(ses.writepayload, DROPBEAR_KEEPALIVE_STRING,
  419. strlen(DROPBEAR_KEEPALIVE_STRING));
  420. }
  421. buf_putbyte(ses.writepayload, 1); /* want_reply */
  422. encrypt_packet();
  423. ses.last_packet_time_keepalive_sent = monotonic_now();
  424. /* keepalives shouldn't update idle timeout, reset it back */
  425. ses.last_packet_time_idle = old_time_idle;
  426. }
  427. /* Check all timeouts which are required. Currently these are the time for
  428. * user authentication, and the automatic rekeying. */
  429. static void checktimeouts() {
  430. time_t now;
  431. now = monotonic_now();
  432. if (IS_DROPBEAR_SERVER && ses.connect_time != 0
  433. && now - ses.connect_time >= AUTH_TIMEOUT) {
  434. dropbear_close("Timeout before auth");
  435. }
  436. /* we can't rekey if we haven't done remote ident exchange yet */
  437. if (ses.remoteident == NULL) {
  438. return;
  439. }
  440. if (!ses.kexstate.sentkexinit
  441. && (now - ses.kexstate.lastkextime >= KEX_REKEY_TIMEOUT
  442. || ses.kexstate.datarecv+ses.kexstate.datatrans >= KEX_REKEY_DATA)) {
  443. TRACE(("rekeying after timeout or max data reached"))
  444. send_msg_kexinit();
  445. }
  446. if (opts.keepalive_secs > 0 && ses.authstate.authdone) {
  447. /* Avoid sending keepalives prior to auth - those are
  448. not valid pre-auth packet types */
  449. /* Send keepalives if we've been idle */
  450. if (now - ses.last_packet_time_any_sent >= opts.keepalive_secs) {
  451. send_msg_keepalive();
  452. }
  453. /* Also send an explicit keepalive message to trigger a response
  454. if the remote end hasn't sent us anything */
  455. if (now - ses.last_packet_time_keepalive_recv >= opts.keepalive_secs
  456. && now - ses.last_packet_time_keepalive_sent >= opts.keepalive_secs) {
  457. send_msg_keepalive();
  458. }
  459. if (now - ses.last_packet_time_keepalive_recv
  460. >= opts.keepalive_secs * DEFAULT_KEEPALIVE_LIMIT) {
  461. dropbear_exit("Keepalive timeout");
  462. }
  463. }
  464. if (opts.idle_timeout_secs > 0
  465. && now - ses.last_packet_time_idle >= opts.idle_timeout_secs) {
  466. dropbear_close("Idle timeout");
  467. }
  468. }
  469. static void update_timeout(long limit, long now, long last_event, long * timeout) {
  470. TRACE2(("update_timeout limit %ld, now %ld, last %ld, timeout %ld",
  471. limit, now, last_event, *timeout))
  472. if (last_event > 0 && limit > 0) {
  473. *timeout = MIN(*timeout, last_event+limit-now);
  474. TRACE2(("new timeout %ld", *timeout))
  475. }
  476. }
  477. static long select_timeout() {
  478. /* determine the minimum timeout that might be required, so
  479. as to avoid waking when unneccessary */
  480. long timeout = KEX_REKEY_TIMEOUT;
  481. long now = monotonic_now();
  482. if (!ses.kexstate.sentkexinit) {
  483. update_timeout(KEX_REKEY_TIMEOUT, now, ses.kexstate.lastkextime, &timeout);
  484. }
  485. if (ses.authstate.authdone != 1 && IS_DROPBEAR_SERVER) {
  486. /* AUTH_TIMEOUT is only relevant before authdone */
  487. update_timeout(AUTH_TIMEOUT, now, ses.connect_time, &timeout);
  488. }
  489. if (ses.authstate.authdone) {
  490. update_timeout(opts.keepalive_secs, now,
  491. MAX(ses.last_packet_time_keepalive_recv, ses.last_packet_time_keepalive_sent),
  492. &timeout);
  493. }
  494. update_timeout(opts.idle_timeout_secs, now, ses.last_packet_time_idle,
  495. &timeout);
  496. /* clamp negative timeouts to zero - event has already triggered */
  497. return MAX(timeout, 0);
  498. }
  499. const char* get_user_shell() {
  500. /* an empty shell should be interpreted as "/bin/sh" */
  501. if (ses.authstate.pw_shell[0] == '\0') {
  502. return "/bin/sh";
  503. } else {
  504. return ses.authstate.pw_shell;
  505. }
  506. }
  507. void fill_passwd(const char* username) {
  508. struct passwd *pw = NULL;
  509. if (ses.authstate.pw_name)
  510. m_free(ses.authstate.pw_name);
  511. if (ses.authstate.pw_dir)
  512. m_free(ses.authstate.pw_dir);
  513. if (ses.authstate.pw_shell)
  514. m_free(ses.authstate.pw_shell);
  515. if (ses.authstate.pw_passwd)
  516. m_free(ses.authstate.pw_passwd);
  517. pw = getpwnam(username);
  518. if (!pw) {
  519. return;
  520. }
  521. ses.authstate.pw_uid = pw->pw_uid;
  522. ses.authstate.pw_gid = pw->pw_gid;
  523. ses.authstate.pw_name = m_strdup(pw->pw_name);
  524. ses.authstate.pw_dir = m_strdup(pw->pw_dir);
  525. ses.authstate.pw_shell = m_strdup(pw->pw_shell);
  526. {
  527. char *passwd_crypt = pw->pw_passwd;
  528. #ifdef HAVE_SHADOW_H
  529. /* get the shadow password if possible */
  530. struct spwd *spasswd = getspnam(ses.authstate.pw_name);
  531. if (spasswd && spasswd->sp_pwdp) {
  532. passwd_crypt = spasswd->sp_pwdp;
  533. }
  534. #endif
  535. if (!passwd_crypt) {
  536. /* android supposedly returns NULL */
  537. passwd_crypt = "!!";
  538. }
  539. ses.authstate.pw_passwd = m_strdup(passwd_crypt);
  540. }
  541. }
  542. /* Called when channels are modified */
  543. void update_channel_prio() {
  544. enum dropbear_prio new_prio;
  545. int any = 0;
  546. unsigned int i;
  547. TRACE(("update_channel_prio"))
  548. if (ses.sock_out < 0) {
  549. TRACE(("leave update_channel_prio: no socket"))
  550. return;
  551. }
  552. new_prio = DROPBEAR_PRIO_NORMAL;
  553. for (i = 0; i < ses.chansize; i++) {
  554. struct Channel *channel = ses.channels[i];
  555. if (!channel) {
  556. continue;
  557. }
  558. any = 1;
  559. if (channel->prio == DROPBEAR_PRIO_LOWDELAY) {
  560. new_prio = DROPBEAR_PRIO_LOWDELAY;
  561. break;
  562. }
  563. }
  564. if (any == 0) {
  565. /* lowdelay during setup */
  566. TRACE(("update_channel_prio: not any"))
  567. new_prio = DROPBEAR_PRIO_LOWDELAY;
  568. }
  569. if (new_prio != ses.socket_prio) {
  570. TRACE(("Dropbear priority transitioning %d -> %d", ses.socket_prio, new_prio))
  571. set_sock_priority(ses.sock_out, new_prio);
  572. ses.socket_prio = new_prio;
  573. }
  574. }