summaryrefslogtreecommitdiffhomepage
path: root/common-session.c
diff options
context:
space:
mode:
Diffstat (limited to 'common-session.c')
-rw-r--r--common-session.c61
1 files changed, 48 insertions, 13 deletions
diff --git a/common-session.c b/common-session.c
index 79313f2..3d759b5 100644
--- a/common-session.c
+++ b/common-session.c
@@ -52,14 +52,15 @@ int exitflag = 0; /* GLOBAL */
/* called only at the start of a session, set up initial state */
-void common_session_init(int sock, char* remotehost) {
+void common_session_init(int sock_in, int sock_out, char* remotehost) {
TRACE(("enter session_init"))
ses.remotehost = remotehost;
- ses.sock = sock;
- ses.maxfd = sock;
+ ses.sock_in = sock_in;
+ ses.sock_out = sock_out;
+ ses.maxfd = MAX(sock_in, sock_out);
ses.connect_time = 0;
ses.last_packet_time = 0;
@@ -137,11 +138,11 @@ void session_loop(void(*loophandler)()) {
FD_ZERO(&writefd);
FD_ZERO(&readfd);
dropbear_assert(ses.payload == NULL);
- if (ses.sock != -1) {
- FD_SET(ses.sock, &readfd);
- if (!isempty(&ses.writequeue)) {
- FD_SET(ses.sock, &writefd);
- }
+ if (ses.sock_in != -1) {
+ FD_SET(ses.sock_in, &readfd);
+ }
+ if (ses.sock_out != -1 && !isempty(&ses.writequeue)) {
+ FD_SET(ses.sock_out, &writefd);
}
/* We get woken up when signal handlers write to this pipe.
@@ -183,12 +184,14 @@ void session_loop(void(*loophandler)()) {
checktimeouts();
/* process session socket's incoming/outgoing data */
- if (ses.sock != -1) {
- if (FD_ISSET(ses.sock, &writefd) && !isempty(&ses.writequeue)) {
+ if (ses.sock_out != -1) {
+ if (FD_ISSET(ses.sock_out, &writefd) && !isempty(&ses.writequeue)) {
write_packet();
}
+ }
- if (FD_ISSET(ses.sock, &readfd)) {
+ if (ses.sock_in != -1) {
+ if (FD_ISSET(ses.sock_in, &readfd)) {
read_packet();
}
@@ -248,14 +251,14 @@ void session_identification() {
int i;
/* write our version string, this blocks */
- if (atomicio(write, ses.sock, LOCAL_IDENT "\r\n",
+ if (atomicio(write, ses.sock_out, LOCAL_IDENT "\r\n",
strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) {
ses.remoteclosed();
}
/* If they send more than 50 lines, something is wrong */
for (i = 0; i < 50; i++) {
- len = ident_readln(ses.sock, linebuf, sizeof(linebuf));
+ len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf));
if (len < 0 && errno != EINTR) {
/* It failed */
@@ -411,3 +414,35 @@ static long select_timeout() {
ret = MIN(opts.keepalive_secs, ret);
return ret;
}
+
+const char* get_user_shell() {
+ /* an empty shell should be interpreted as "/bin/sh" */
+ if (ses.authstate.pw_shell[0] == '\0') {
+ return "/bin/sh";
+ } else {
+ return ses.authstate.pw_shell;
+ }
+}
+void fill_passwd(const char* username) {
+ struct passwd *pw = NULL;
+ if (ses.authstate.pw_name)
+ m_free(ses.authstate.pw_name);
+ if (ses.authstate.pw_dir)
+ m_free(ses.authstate.pw_dir);
+ if (ses.authstate.pw_shell)
+ m_free(ses.authstate.pw_shell);
+ if (ses.authstate.pw_passwd)
+ m_free(ses.authstate.pw_passwd);
+
+ pw = getpwnam(username);
+ if (!pw) {
+ return;
+ }
+ ses.authstate.pw_uid = pw->pw_uid;
+ ses.authstate.pw_gid = pw->pw_gid;
+ ses.authstate.pw_name = m_strdup(pw->pw_name);
+ ses.authstate.pw_dir = m_strdup(pw->pw_dir);
+ ses.authstate.pw_shell = m_strdup(pw->pw_shell);
+ ses.authstate.pw_passwd = m_strdup(pw->pw_passwd);
+}
+