version 1.134.2.1, 2002/06/26 15:30:38 |
version 1.134.2.2, 2002/10/11 14:51:52 |
|
|
|
|
/* Fork the child. */ |
/* Fork the child. */ |
if ((pid = fork()) == 0) { |
if ((pid = fork()) == 0) { |
|
fatal_remove_all_cleanups(); |
|
|
/* Child. Reinitialize the log since the pid has changed. */ |
/* Child. Reinitialize the log since the pid has changed. */ |
log_init(__progname, options.log_level, options.log_facility, log_stderr); |
log_init(__progname, options.log_level, options.log_facility, log_stderr); |
|
|
|
|
|
|
/* Fork the child. */ |
/* Fork the child. */ |
if ((pid = fork()) == 0) { |
if ((pid = fork()) == 0) { |
|
fatal_remove_all_cleanups(); |
|
|
/* Child. Reinitialize the log because the pid has changed. */ |
/* Child. Reinitialize the log because the pid has changed. */ |
log_init(__progname, options.log_level, options.log_facility, log_stderr); |
log_init(__progname, options.log_level, options.log_facility, log_stderr); |
|
|
* the address be 0.0.0.0. |
* the address be 0.0.0.0. |
*/ |
*/ |
memset(&from, 0, sizeof(from)); |
memset(&from, 0, sizeof(from)); |
|
fromlen = sizeof(from); |
if (packet_connection_is_on_socket()) { |
if (packet_connection_is_on_socket()) { |
fromlen = sizeof(from); |
|
if (getpeername(packet_get_connection_in(), |
if (getpeername(packet_get_connection_in(), |
(struct sockaddr *) & from, &fromlen) < 0) { |
(struct sockaddr *) & from, &fromlen) < 0) { |
debug("getpeername: %.100s", strerror(errno)); |
debug("getpeername: %.100s", strerror(errno)); |
|
|
record_login(pid, s->tty, pw->pw_name, pw->pw_uid, |
record_login(pid, s->tty, pw->pw_name, pw->pw_uid, |
get_remote_name_or_ip(utmp_len, |
get_remote_name_or_ip(utmp_len, |
options.verify_reverse_mapping), |
options.verify_reverse_mapping), |
(struct sockaddr *)&from); |
(struct sockaddr *)&from, fromlen); |
|
|
if (check_quietlogin(s, command)) |
if (check_quietlogin(s, command)) |
return; |
return; |
|
|
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); |
#ifdef HAVE_LOGIN_CAP |
#ifdef HAVE_LOGIN_CAP |
(void) setusercontext(lc, pw, pw->pw_uid, LOGIN_SETPATH); |
if (setusercontext(lc, pw, pw->pw_uid, LOGIN_SETPATH) < 0) |
child_set_env(&env, &envsize, "PATH", getenv("PATH")); |
child_set_env(&env, &envsize, "PATH", _PATH_STDPATH); |
|
else |
|
child_set_env(&env, &envsize, "PATH", getenv("PATH")); |
#else |
#else |
child_set_env(&env, &envsize, "PATH", _PATH_STDPATH); |
child_set_env(&env, &envsize, "PATH", _PATH_STDPATH); |
#endif |
#endif |
|
|
if (!options.use_login) { |
if (!options.use_login) { |
while (custom_environment) { |
while (custom_environment) { |
struct envstring *ce = custom_environment; |
struct envstring *ce = custom_environment; |
char *s = ce->s; |
char *str = ce->s; |
|
|
for (i = 0; s[i] != '=' && s[i]; i++) |
for (i = 0; str[i] != '=' && str[i]; i++) |
; |
; |
if (s[i] == '=') { |
if (str[i] == '=') { |
s[i] = 0; |
str[i] = 0; |
child_set_env(&env, &envsize, s, s + i + 1); |
child_set_env(&env, &envsize, str, str + i + 1); |
} |
} |
custom_environment = ce->next; |
custom_environment = ce->next; |
xfree(ce->s); |
xfree(ce->s); |
|
|
} |
} |
} |
} |
|
|
|
/* SSH_CLIENT deprecated */ |
snprintf(buf, sizeof buf, "%.50s %d %d", |
snprintf(buf, sizeof buf, "%.50s %d %d", |
get_remote_ipaddr(), get_remote_port(), get_local_port()); |
get_remote_ipaddr(), get_remote_port(), get_local_port()); |
child_set_env(&env, &envsize, "SSH_CLIENT", buf); |
child_set_env(&env, &envsize, "SSH_CLIENT", buf); |
|
|
|
snprintf(buf, sizeof buf, "%.50s %d %.50s %d", |
|
get_remote_ipaddr(), get_remote_port(), |
|
get_local_ipaddr(packet_get_connection_in()), get_local_port()); |
|
child_set_env(&env, &envsize, "SSH_CONNECTION", buf); |
|
|
if (s->ttyfd != -1) |
if (s->ttyfd != -1) |
child_set_env(&env, &envsize, "SSH_TTY", s->tty); |
child_set_env(&env, &envsize, "SSH_TTY", s->tty); |
if (s->term) |
if (s->term) |
|
|
auth_sock_name); |
auth_sock_name); |
|
|
/* read $HOME/.ssh/environment. */ |
/* read $HOME/.ssh/environment. */ |
if (!options.use_login) { |
if (options.permit_user_env && !options.use_login) { |
snprintf(buf, sizeof buf, "%.200s/.ssh/environment", |
snprintf(buf, sizeof buf, "%.200s/.ssh/environment", |
pw->pw_dir); |
pw->pw_dir); |
read_environment_file(&env, &envsize, buf); |
read_environment_file(&env, &envsize, buf); |
|
|
#endif |
#endif |
if (f) { |
if (f) { |
/* /etc/nologin exists. Print its contents and exit. */ |
/* /etc/nologin exists. Print its contents and exit. */ |
|
log("User %.100s not allowed because %s exists", |
|
pw->pw_name, _PATH_NOLOGIN); |
while (fgets(buf, sizeof(buf), f)) |
while (fgets(buf, sizeof(buf), f)) |
fputs(buf, stderr); |
fputs(buf, stderr); |
fclose(f); |
fclose(f); |
|
|
PRIVSEP(session_pty_cleanup2(session)); |
PRIVSEP(session_pty_cleanup2(session)); |
} |
} |
|
|
|
static char * |
|
sig2name(int sig) |
|
{ |
|
#define SSH_SIG(x) if (sig == SIG ## x) return #x |
|
SSH_SIG(ABRT); |
|
SSH_SIG(ALRM); |
|
SSH_SIG(FPE); |
|
SSH_SIG(HUP); |
|
SSH_SIG(ILL); |
|
SSH_SIG(INT); |
|
SSH_SIG(KILL); |
|
SSH_SIG(PIPE); |
|
SSH_SIG(QUIT); |
|
SSH_SIG(SEGV); |
|
SSH_SIG(TERM); |
|
SSH_SIG(USR1); |
|
SSH_SIG(USR2); |
|
#undef SSH_SIG |
|
return "SIG@openssh.com"; |
|
} |
|
|
static void |
static void |
session_exit_message(Session *s, int status) |
session_exit_message(Session *s, int status) |
{ |
{ |
|
|
packet_send(); |
packet_send(); |
} else if (WIFSIGNALED(status)) { |
} else if (WIFSIGNALED(status)) { |
channel_request_start(s->chanid, "exit-signal", 0); |
channel_request_start(s->chanid, "exit-signal", 0); |
packet_put_int(WTERMSIG(status)); |
packet_put_cstring(sig2name(WTERMSIG(status))); |
packet_put_char(WCOREDUMP(status)); |
packet_put_char(WCOREDUMP(status)); |
packet_put_cstring(""); |
packet_put_cstring(""); |
packet_put_cstring(""); |
packet_put_cstring(""); |