version 1.163.2.1, 2004/02/28 03:51:33 |
version 1.163.2.2, 2004/08/19 22:37:32 |
|
|
#include "sshpty.h" |
#include "sshpty.h" |
#include "packet.h" |
#include "packet.h" |
#include "buffer.h" |
#include "buffer.h" |
#include "mpaux.h" |
#include "match.h" |
#include "uidswap.h" |
#include "uidswap.h" |
#include "compat.h" |
#include "compat.h" |
#include "channels.h" |
#include "channels.h" |
|
|
extern u_int utmp_len; |
extern u_int utmp_len; |
extern int startup_pipe; |
extern int startup_pipe; |
extern void destroy_sensitive_data(void); |
extern void destroy_sensitive_data(void); |
|
extern Buffer loginmsg; |
|
|
/* original command from peer. */ |
/* original command from peer. */ |
const char *original_command = NULL; |
const char *original_command = NULL; |
|
|
return 1; |
return 1; |
} |
} |
|
|
|
static void |
|
display_loginmsg(void) |
|
{ |
|
if (buffer_len(&loginmsg) > 0) { |
|
buffer_append(&loginmsg, "\0", 1); |
|
printf("%s", (char *)buffer_ptr(&loginmsg)); |
|
buffer_clear(&loginmsg); |
|
} |
|
} |
|
|
void |
void |
do_authenticated(Authctxt *authctxt) |
do_authenticated(Authctxt *authctxt) |
|
|
compression_level = packet_get_int(); |
compression_level = packet_get_int(); |
packet_check_eom(); |
packet_check_eom(); |
if (compression_level < 1 || compression_level > 9) { |
if (compression_level < 1 || compression_level > 9) { |
packet_send_debug("Received illegal compression level %d.", |
packet_send_debug("Received invalid compression level %d.", |
compression_level); |
compression_level); |
break; |
break; |
} |
} |
|
|
close(perr[1]); |
close(perr[1]); |
|
|
if (compat20) { |
if (compat20) { |
session_set_fds(s, pin[1], pout[0], s->is_subsystem ? -1 : perr[0]); |
if (s->is_subsystem) { |
|
close(perr[0]); |
|
perr[0] = -1; |
|
} |
|
session_set_fds(s, pin[1], pout[0], perr[0]); |
} else { |
} else { |
/* Enter the interactive session. */ |
/* Enter the interactive session. */ |
server_loop(pid, pin[1], pout[0], perr[0]); |
server_loop(pid, pin[1], pout[0], perr[0]); |
|
|
do_exec_no_pty(s, command); |
do_exec_no_pty(s, command); |
|
|
original_command = NULL; |
original_command = NULL; |
|
|
|
/* |
|
* Clear loginmsg: it's the child's responsibility to display |
|
* it to the user, otherwise multiple sessions may accumulate |
|
* multiple copies of the login messages. |
|
*/ |
|
buffer_clear(&loginmsg); |
} |
} |
|
|
|
|
|
|
void |
void |
do_login(Session *s, const char *command) |
do_login(Session *s, const char *command) |
{ |
{ |
char *time_string; |
|
socklen_t fromlen; |
socklen_t fromlen; |
struct sockaddr_storage from; |
struct sockaddr_storage from; |
struct passwd * pw = s->pw; |
struct passwd * pw = s->pw; |
|
|
if (check_quietlogin(s, command)) |
if (check_quietlogin(s, command)) |
return; |
return; |
|
|
if (options.print_lastlog && s->last_login_time != 0) { |
display_loginmsg(); |
time_string = ctime(&s->last_login_time); |
|
if (strchr(time_string, '\n')) |
|
*strchr(time_string, '\n') = 0; |
|
if (strcmp(s->hostname, "") == 0) |
|
printf("Last login: %s\r\n", time_string); |
|
else |
|
printf("Last login: %s from %s\r\n", time_string, |
|
s->hostname); |
|
} |
|
|
|
do_motd(); |
do_motd(); |
} |
} |
|
|
|
|
if (!options.use_login) { |
if (!options.use_login) { |
/* Set basic environment. */ |
/* Set basic environment. */ |
|
for (i = 0; i < s->num_env; i++) |
|
child_set_env(&env, &envsize, s->env[i].name, |
|
s->env[i].val); |
|
|
child_set_env(&env, &envsize, "USER", pw->pw_name); |
child_set_env(&env, &envsize, "USER", pw->pw_name); |
child_set_env(&env, &envsize, "LOGNAME", pw->pw_name); |
child_set_env(&env, &envsize, "LOGNAME", pw->pw_name); |
child_set_env(&env, &envsize, "HOME", pw->pw_dir); |
child_set_env(&env, &envsize, "HOME", pw->pw_dir); |
|
|
static void |
static void |
do_pwchange(Session *s) |
do_pwchange(Session *s) |
{ |
{ |
|
fflush(NULL); |
fprintf(stderr, "WARNING: Your password has expired.\n"); |
fprintf(stderr, "WARNING: Your password has expired.\n"); |
if (s->ttyfd != -1) { |
if (s->ttyfd != -1) { |
fprintf(stderr, |
fprintf(stderr, |
"You must change your password now and login again!\n"); |
"You must change your password now and login again!\n"); |
execl(_PATH_PASSWD_PROG, "passwd", (char *)NULL); |
execl(_PATH_PASSWD_PROG, "passwd", (char *)NULL); |
perror("passwd"); |
perror("passwd"); |
|
|
packet_disconnect("Protocol error: you already have a pty."); |
packet_disconnect("Protocol error: you already have a pty."); |
return 0; |
return 0; |
} |
} |
/* Get the time and hostname when the user last logged in. */ |
|
if (options.print_lastlog) { |
|
s->hostname[0] = '\0'; |
|
s->last_login_time = get_last_login_time(s->pw->pw_uid, |
|
s->pw->pw_name, s->hostname, sizeof(s->hostname)); |
|
} |
|
|
|
s->term = packet_get_string(&len); |
s->term = packet_get_string(&len); |
|
|
|
|
static int |
static int |
session_break_req(Session *s) |
session_break_req(Session *s) |
{ |
{ |
u_int break_length; |
|
|
|
break_length = packet_get_int(); /* ignored */ |
packet_get_int(); /* ignored */ |
packet_check_eom(); |
packet_check_eom(); |
|
|
if (s->ttyfd == -1 || |
if (s->ttyfd == -1 || |
|
|
} |
} |
|
|
static int |
static int |
|
session_env_req(Session *s) |
|
{ |
|
char *name, *val; |
|
u_int name_len, val_len, i; |
|
|
|
name = packet_get_string(&name_len); |
|
val = packet_get_string(&val_len); |
|
packet_check_eom(); |
|
|
|
/* Don't set too many environment variables */ |
|
if (s->num_env > 128) { |
|
debug2("Ignoring env request %s: too many env vars", name); |
|
goto fail; |
|
} |
|
|
|
for (i = 0; i < options.num_accept_env; i++) { |
|
if (match_pattern(name, options.accept_env[i])) { |
|
debug2("Setting env %d: %s=%s", s->num_env, name, val); |
|
s->env = xrealloc(s->env, sizeof(*s->env) * |
|
(s->num_env + 1)); |
|
s->env[s->num_env].name = name; |
|
s->env[s->num_env].val = val; |
|
s->num_env++; |
|
return (1); |
|
} |
|
} |
|
debug2("Ignoring env request %s: disallowed name", name); |
|
|
|
fail: |
|
xfree(name); |
|
xfree(val); |
|
return (0); |
|
} |
|
|
|
static int |
session_auth_agent_req(Session *s) |
session_auth_agent_req(Session *s) |
{ |
{ |
static int called = 0; |
static int called = 0; |
|
|
success = session_auth_agent_req(s); |
success = session_auth_agent_req(s); |
} else if (strcmp(rtype, "subsystem") == 0) { |
} else if (strcmp(rtype, "subsystem") == 0) { |
success = session_subsystem_req(s); |
success = session_subsystem_req(s); |
} else if (strcmp(rtype, "break") == 0) { |
} else if (strcmp(rtype, "env") == 0) { |
success = session_break_req(s); |
success = session_env_req(s); |
} |
} |
} |
} |
if (strcmp(rtype, "window-change") == 0) { |
if (strcmp(rtype, "window-change") == 0) { |
success = session_window_change_req(s); |
success = session_window_change_req(s); |
|
} else if (strcmp(rtype, "break") == 0) { |
|
success = session_break_req(s); |
} |
} |
|
|
return success; |
return success; |
} |
} |
|
|
|
|
void |
void |
session_close(Session *s) |
session_close(Session *s) |
{ |
{ |
|
int i; |
|
|
debug("session_close: session %d pid %ld", s->self, (long)s->pid); |
debug("session_close: session %d pid %ld", s->self, (long)s->pid); |
if (s->ttyfd != -1) |
if (s->ttyfd != -1) |
session_pty_cleanup(s); |
session_pty_cleanup(s); |
|
|
if (s->auth_proto) |
if (s->auth_proto) |
xfree(s->auth_proto); |
xfree(s->auth_proto); |
s->used = 0; |
s->used = 0; |
|
for (i = 0; i < s->num_env; i++) { |
|
xfree(s->env[i].name); |
|
xfree(s->env[i].val); |
|
} |
|
if (s->env != NULL) |
|
xfree(s->env); |
session_proctitle(s); |
session_proctitle(s); |
} |
} |
|
|