version 1.172.2.2, 2005/03/10 17:15:04 |
version 1.173, 2004/04/27 09:46:37 |
|
|
#include "packet.h" |
#include "packet.h" |
#include "buffer.h" |
#include "buffer.h" |
#include "match.h" |
#include "match.h" |
|
#include "mpaux.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) |
|
|
u_int proto_len, data_len, dlen, compression_level = 0; |
u_int proto_len, data_len, dlen, compression_level = 0; |
|
|
s = session_new(); |
s = session_new(); |
if (s == NULL) { |
|
error("no more sessions"); |
|
return; |
|
} |
|
s->authctxt = authctxt; |
s->authctxt = authctxt; |
s->pw = authctxt->pw; |
s->pw = authctxt->pw; |
|
|
|
|
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 invalid compression level %d.", |
packet_send_debug("Received illegal compression level %d.", |
compression_level); |
compression_level); |
break; |
break; |
} |
} |
|
|
close(perr[1]); |
close(perr[1]); |
|
|
if (compat20) { |
if (compat20) { |
if (s->is_subsystem) { |
session_set_fds(s, pin[1], pout[0], s->is_subsystem ? -1 : perr[0]); |
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; |
|
|
display_loginmsg(); |
if (options.print_lastlog && s->last_login_time != 0) { |
|
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++) |
for (i = 0; i < s->num_env; i++) |
child_set_env(&env, &envsize, s->env[i].name, |
child_set_env(&env, &envsize, s->env[i].name, |
s->env[i].val); |
s->env[i].val); |
|
|
child_set_env(&env, &envsize, "USER", pw->pw_name); |
child_set_env(&env, &envsize, "USER", pw->pw_name); |
|
|
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; |
|
|
packet_get_int(); /* ignored */ |
break_length = packet_get_int(); /* ignored */ |
packet_check_eom(); |
packet_check_eom(); |
|
|
if (s->ttyfd == -1 || |
if (s->ttyfd == -1 || |
|
|
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) { |
|
success = session_break_req(s); |
} else if (strcmp(rtype, "env") == 0) { |
} else if (strcmp(rtype, "env") == 0) { |
success = session_env_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; |
} |
} |
|
|