*/
#include "includes.h"
-RCSID("$OpenBSD: session.c,v 1.42 2000/10/27 07:32:18 markus Exp $");
+RCSID("$OpenBSD: session.c,v 1.52 2001/02/03 10:08:37 markus Exp $");
-#include "xmalloc.h"
#include "ssh.h"
+#include "ssh1.h"
+#include "ssh2.h"
+#include "xmalloc.h"
#include "pty.h"
#include "packet.h"
#include "buffer.h"
#include "mpaux.h"
-#include "servconf.h"
#include "uidswap.h"
#include "compat.h"
#include "channels.h"
#include "nchan.h"
-
#include "bufaux.h"
-#include "ssh2.h"
#include "auth.h"
#include "auth-options.h"
+#include "pathnames.h"
+#include "log.h"
+#include "servconf.h"
+#include "login.h"
+#include "serverloop.h"
+#include "canohost.h"
#ifdef WITH_IRIX_PROJECT
#include <proj.h>
#endif /* WITH_IRIX_PROJECT */
+#ifdef WITH_IRIX_JOBS
+#include <sys/resource.h>
+#endif
+#ifdef WITH_IRIX_AUDIT
+#include <sat.h>
+#endif /* WITH_IRIX_AUDIT */
#if defined(HAVE_USERSEC_H)
#include <usersec.h>
/* import */
extern ServerOptions options;
-#ifdef HAVE___PROGNAME
extern char *__progname;
-#else /* HAVE___PROGNAME */
-static const char *__progname = "sshd";
-#endif /* HAVE___PROGNAME */
-
extern int log_stderr;
extern int debug_flag;
-extern unsigned int utmp_len;
+extern u_int utmp_len;
extern int startup_pipe;
char *command;
int n_bytes;
int plen;
- unsigned int proto_len, data_len, dlen;
+ u_int proto_len, data_len, dlen;
/*
* Cancel the alarm we set to limit the time taken for
case SSH_CMSG_EXEC_SHELL:
case SSH_CMSG_EXEC_CMD:
- /* Set interactive/non-interactive mode. */
- packet_set_interactive(have_pty || s->display != NULL,
- options.keepalives);
-
if (type == SSH_CMSG_EXEC_CMD) {
command = packet_get_string(&dlen);
debug("Exec command '%.500s'", command);
if (s == NULL)
fatal("do_exec_no_pty: no session");
- signal(SIGPIPE, SIG_DFL);
-
session_proctitle(s);
#ifdef USE_PAM
/* Child. Reinitialize the log since the pid has changed. */
log_init(__progname, options.log_level, options.log_facility, log_stderr);
+ signal(SIGPIPE, SIG_DFL);
+
/*
* Create a new session and process group since the 4.4BSD
* setlogin() affects the entire process group.
if (pid < 0)
packet_disconnect("fork failed: %.100s", strerror(errno));
s->pid = pid;
+ /* Set interactive/non-interactive mode. */
+ packet_set_interactive(s->display != NULL);
#ifdef USE_PIPES
/* We are the parent. Close the child sides of the pipes. */
close(pin[0]);
/* Child. Reinitialize the log because the pid has changed. */
log_init(__progname, options.log_level, options.log_facility, log_stderr);
+ signal(SIGPIPE, SIG_DFL);
+
/* Close the master side of the pseudo tty. */
close(ptyfd);
s->ptymaster = ptymaster;
/* Enter interactive session. */
+ packet_set_interactive(1);
if (compat20) {
session_set_fds(s, ptyfd, fdout, -1);
} else {
{
static const char *remote = "";
if (utmp_len > 0)
- remote = get_canonical_hostname();
+ remote = get_canonical_hostname(options.reverse_mapping_check);
if (utmp_len == 0 || strlen(remote) > utmp_len)
remote = get_remote_ipaddr();
return remote;
* already exists, its value is overriden.
*/
void
-child_set_env(char ***envp, unsigned int *envsizep, const char *name,
+child_set_env(char ***envp, u_int *envsizep, const char *name,
const char *value)
{
- unsigned int i, namelen;
+ u_int i, namelen;
char **env;
/*
* and assignments of the form name=value. No other forms are allowed.
*/
void
-read_environment_file(char ***env, unsigned int *envsize,
+read_environment_file(char ***env, u_int *envsize,
const char *filename)
{
FILE *f;
char buf[256];
char cmd[1024];
FILE *f = NULL;
- unsigned int envsize, i;
+ u_int envsize, i;
char **env;
extern char **environ;
struct stat st;
#ifdef WITH_IRIX_PROJECT
prid_t projid;
#endif /* WITH_IRIX_PROJECT */
+#ifdef WITH_IRIX_JOBS
+ jid_t jid = 0;
+#else
+#ifdef WITH_IRIX_ARRAY
+ int jid = 0;
+#endif /* WITH_IRIX_ARRAY */
+#endif /* WITH_IRIX_JOBS */
+
/* login(1) is only called if we execute the login shell */
if (options.use_login && command != NULL)
#ifdef HAVE_OSF_SIA
extern char **saved_argv;
extern int saved_argc;
- char *host = get_canonical_hostname ();
+ char *host = get_canonical_hostname(options.reverse_mapping_check);
if (sia_become_user(NULL, saved_argc, saved_argv, host,
pw->pw_name, ttyname, 0, NULL, NULL, SIA_BEU_SETLUID) !=
exit(1);
}
endgrent();
+# ifdef WITH_IRIX_JOBS
+ jid = jlimit_startjob(pw->pw_name, pw->pw_uid, "interactive");
+ if (jid == -1) {
+ fatal("Failed to create job container: %.100s",
+ strerror(errno));
+ }
+# endif /* WITH_IRIX_JOBS */
# ifdef WITH_IRIX_ARRAY
/* initialize array session */
- if (newarraysess() != 0)
- fatal("Failed to set up new array session: %.100s",
- strerror(errno));
+ if (jid == 0) {
+ if (newarraysess() != 0)
+ fatal("Failed to set up new array session: %.100s",
+ strerror(errno));
+ }
# endif /* WITH_IRIX_ARRAY */
# ifdef WITH_IRIX_PROJECT
/* initialize irix project info */
fatal("Failed to initialize project %d for %s: %.100s",
(int)projid, pw->pw_name, strerror(errno));
# endif /* WITH_IRIX_PROJECT */
+#ifdef WITH_IRIX_AUDIT
+ if (sysconf(_SC_AUDIT)) {
+ debug("Setting sat id to %d", (int) pw->pw_uid);
+ if (satsetid(pw->pw_uid))
+ debug("error setting satid: %.100s", strerror(errno));
+ }
+#endif /* WITH_IRIX_AUDIT */
+
/* Permanently switch to the desired uid. */
permanently_set_uid(pw->pw_uid);
# endif /* HAVE_LOGIN_CAP */
* in this order).
*/
if (!options.use_login) {
- if (stat(SSH_USER_RC, &st) >= 0) {
+ if (stat(_PATH_SSH_USER_RC, &st) >= 0) {
if (debug_flag)
- fprintf(stderr, "Running "_PATH_BSHELL" %s\n", SSH_USER_RC);
+ fprintf(stderr, "Running %s %s\n", _PATH_BSHELL, _PATH_SSH_USER_RC);
- f = popen(_PATH_BSHELL " " SSH_USER_RC, "w");
+ f = popen(_PATH_BSHELL " " _PATH_SSH_USER_RC, "w");
if (f) {
if (auth_proto != NULL && auth_data != NULL)
fprintf(f, "%s %s\n", auth_proto, auth_data);
pclose(f);
} else
- fprintf(stderr, "Could not run %s\n", SSH_USER_RC);
- } else if (stat(SSH_SYSTEM_RC, &st) >= 0) {
+ fprintf(stderr, "Could not run %s\n", _PATH_SSH_USER_RC);
+ } else if (stat(_PATH_SSH_SYSTEM_RC, &st) >= 0) {
if (debug_flag)
- fprintf(stderr, "Running "_PATH_BSHELL" %s\n", SSH_SYSTEM_RC);
+ fprintf(stderr, "Running %s %s\n", _PATH_BSHELL, _PATH_SSH_SYSTEM_RC);
- f = popen(_PATH_BSHELL " " SSH_SYSTEM_RC, "w");
+ f = popen(_PATH_BSHELL " " _PATH_SSH_SYSTEM_RC, "w");
if (f) {
if (auth_proto != NULL && auth_data != NULL)
fprintf(f, "%s %s\n", auth_proto, auth_data);
pclose(f);
} else
- fprintf(stderr, "Could not run %s\n", SSH_SYSTEM_RC);
+ fprintf(stderr, "Could not run %s\n", _PATH_SSH_SYSTEM_RC);
} else if (options.xauth_location != NULL) {
/* Add authority data to .Xauthority if appropriate. */
if (auth_proto != NULL && auth_data != NULL) {
int
session_pty_req(Session *s)
{
- unsigned int len;
+ u_int len;
char *term_modes; /* encoded terminal modes */
if (no_pty_flag)
int
session_subsystem_req(Session *s)
{
- unsigned int len;
+ u_int len;
int success = 0;
char *subsys = packet_get_string(&len);
int i;
int
session_exec_req(Session *s)
{
- unsigned int len;
+ u_int len;
char *command = packet_get_string(&len);
packet_done();
if (forced_command) {
return 1;
}
+int
+session_auth_agent_req(Session *s)
+{
+ static int called = 0;
+ packet_done();
+ if (no_agent_forwarding_flag) {
+ debug("session_auth_agent_req: no_agent_forwarding_flag");
+ return 0;
+ }
+ if (called) {
+ return 0;
+ } else {
+ called = 1;
+ return auth_input_request_forwarding(s->pw);
+ }
+}
+
void
session_input_channel_req(int id, void *arg)
{
- unsigned int len;
+ u_int len;
int reply;
int success = 0;
char *rtype;
success = session_pty_req(s);
} else if (strcmp(rtype, "x11-req") == 0) {
success = session_x11_req(s);
+ } else if (strcmp(rtype, "auth-agent-req@openssh.com") == 0) {
+ success = session_auth_agent_req(s);
} else if (strcmp(rtype, "subsystem") == 0) {
success = session_subsystem_req(s);
}
* interested in data we write.
* Note that we must not call 'chan_read_failed', since there could
* be some more data waiting in the pipe.
- * djm - This is no longer true as we have allowed one pass through
- * the select loop before killing the connection
*/
if (c->ostate != CHAN_OUTPUT_CLOSED)
chan_write_failed(c);
- if (c->istate != CHAN_INPUT_CLOSED)
- chan_read_failed(c);
s->chanid = -1;
}
}
void
-do_authenticated2(void)
+do_authenticated2(Authctxt *authctxt)
{
-#ifdef HAVE_LOGIN_CAP
- struct passwd *pw;
-#endif
/*
* Cancel the alarm we set to limit the time taken for
startup_pipe = -1;
}
#if defined(HAVE_LOGIN_CAP) && defined(HAVE_PW_CLASS_IN_PASSWD)
- pw = auth_get_user();
- if ((lc = login_getclass(pw->pw_class)) == NULL) {
+ if ((lc = login_getclass(authctxt->pw->pw_class)) == NULL) {
error("unable to get login class");
return;
}