summaryrefslogtreecommitdiffstats
path: root/crypto/openssh/session.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssh/session.c')
-rw-r--r--crypto/openssh/session.c74
1 files changed, 36 insertions, 38 deletions
diff --git a/crypto/openssh/session.c b/crypto/openssh/session.c
index 1de0c60..d99576b 100644
--- a/crypto/openssh/session.c
+++ b/crypto/openssh/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.270 2014/01/31 16:39:19 tedu Exp $ */
+/* $OpenBSD: session.c,v 1.278 2015/04/24 01:36:00 deraadt Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@@ -50,6 +50,7 @@ __RCSID("$FreeBSD$");
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
+#include <netdb.h>
#ifdef HAVE_PATHS_H
#include <paths.h>
#endif
@@ -60,6 +61,7 @@ __RCSID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <limits.h>
#include "openbsd-compat/sys-queue.h"
#include "xmalloc.h"
@@ -84,11 +86,11 @@ __RCSID("$FreeBSD$");
#include "authfd.h"
#include "pathnames.h"
#include "log.h"
+#include "misc.h"
#include "servconf.h"
#include "sshlogin.h"
#include "serverloop.h"
#include "canohost.h"
-#include "misc.h"
#include "session.h"
#include "kex.h"
#include "monitor_wrap.h"
@@ -183,7 +185,6 @@ auth_input_request_forwarding(struct passwd * pw)
{
Channel *nc;
int sock = -1;
- struct sockaddr_un sunaddr;
if (auth_sock_name != NULL) {
error("authentication forwarding requested twice.");
@@ -209,33 +210,15 @@ auth_input_request_forwarding(struct passwd * pw)
xasprintf(&auth_sock_name, "%s/agent.%ld",
auth_sock_dir, (long) getpid());
- /* Create the socket. */
- sock = socket(AF_UNIX, SOCK_STREAM, 0);
- if (sock < 0) {
- error("socket: %.100s", strerror(errno));
- restore_uid();
- goto authsock_err;
- }
-
- /* Bind it to the name. */
- memset(&sunaddr, 0, sizeof(sunaddr));
- sunaddr.sun_family = AF_UNIX;
- strlcpy(sunaddr.sun_path, auth_sock_name, sizeof(sunaddr.sun_path));
-
- if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) < 0) {
- error("bind: %.100s", strerror(errno));
- restore_uid();
- goto authsock_err;
- }
+ /* Start a Unix listener on auth_sock_name. */
+ sock = unix_listener(auth_sock_name, SSH_LISTEN_BACKLOG, 0);
/* Restore the privileged uid. */
restore_uid();
- /* Start listening on the socket. */
- if (listen(sock, SSH_LISTEN_BACKLOG) < 0) {
- error("listen: %.100s", strerror(errno));
+ /* Check for socket/bind/listen failure. */
+ if (sock < 0)
goto authsock_err;
- }
/* Allocate a channel for the authentication agent socket. */
nc = channel_new("auth socket",
@@ -274,6 +257,7 @@ do_authenticated(Authctxt *authctxt)
setproctitle("%s", authctxt->pw->pw_name);
/* setup the channel layer */
+ /* XXX - streamlocal? */
if (no_port_forwarding_flag ||
(options.allow_tcp_forwarding & FORWARD_LOCAL) == 0)
channel_disable_adm_local_opens();
@@ -393,7 +377,7 @@ do_authenticated1(Authctxt *authctxt)
}
debug("Received TCP/IP port forwarding request.");
if (channel_input_port_forward_request(s->pw->pw_uid == 0,
- options.gateway_ports) < 0) {
+ &options.fwd_opts) < 0) {
debug("Port forwarding failed.");
break;
}
@@ -1014,7 +998,7 @@ child_set_env(char ***envp, u_int *envsizep, const char *name,
if (envsize >= 1000)
fatal("child_set_env: too many env vars");
envsize += 50;
- env = (*envp) = xrealloc(env, envsize, sizeof(char *));
+ env = (*envp) = xreallocarray(env, envsize, sizeof(char *));
*envsizep = envsize;
}
/* Need to set the NULL pointer at end of array beyond the new slot. */
@@ -1370,7 +1354,8 @@ do_rc_files(Session *s, const char *shell)
/* ignore _PATH_SSH_USER_RC for subsystems and admin forced commands */
if (!s->is_subsystem && options.adm_forced_command == NULL &&
- !no_user_rc && stat(_PATH_SSH_USER_RC, &st) >= 0) {
+ !no_user_rc && options.permit_user_rc &&
+ stat(_PATH_SSH_USER_RC, &st) >= 0) {
snprintf(cmd, sizeof cmd, "%s -c '%s %s'",
shell, _PATH_BSHELL, _PATH_SSH_USER_RC);
if (debug_flag)
@@ -1465,7 +1450,7 @@ static void
safely_chroot(const char *path, uid_t uid)
{
const char *cp;
- char component[MAXPATHLEN];
+ char component[PATH_MAX];
struct stat st;
if (*path != '/')
@@ -1517,6 +1502,9 @@ void
do_setusercontext(struct passwd *pw)
{
char *chroot_path, *tmp;
+#ifdef USE_LIBIAF
+ int doing_chroot = 0;
+#endif
platform_setusercontext(pw);
@@ -1556,6 +1544,9 @@ do_setusercontext(struct passwd *pw)
/* Make sure we don't attempt to chroot again */
free(options.chroot_directory);
options.chroot_directory = NULL;
+#ifdef USE_LIBIAF
+ doing_chroot = 1;
+#endif
}
#ifdef HAVE_LOGIN_CAP
@@ -1570,7 +1561,14 @@ do_setusercontext(struct passwd *pw)
(void) setusercontext(lc, pw, pw->pw_uid, LOGIN_SETUMASK);
#else
# ifdef USE_LIBIAF
- if (set_id(pw->pw_name) != 0) {
+/* In a chroot environment, the set_id() will always fail; typically
+ * because of the lack of necessary authentication services and runtime
+ * such as ./usr/lib/libiaf.so, ./usr/lib/libpam.so.1, and ./etc/passwd
+ * We skip it in the internal sftp chroot case.
+ * We'll lose auditing and ACLs but permanently_set_uid will
+ * take care of the rest.
+ */
+ if ((doing_chroot == 0) && set_id(pw->pw_name) != 0) {
fatal("set_id(%s) Failed", pw->pw_name);
}
# endif /* USE_LIBIAF */
@@ -1635,11 +1633,11 @@ launch_login(struct passwd *pw, const char *hostname)
static void
child_close_fds(void)
{
- extern AuthenticationConnection *auth_conn;
+ extern int auth_sock;
- if (auth_conn) {
- ssh_close_authentication_connection(auth_conn);
- auth_conn = NULL;
+ if (auth_sock != -1) {
+ close(auth_sock);
+ auth_sock = -1;
}
if (packet_get_connection_in() == packet_get_connection_out())
@@ -1928,7 +1926,7 @@ session_new(void)
return NULL;
debug2("%s: allocate (allocated %d max %d)",
__func__, sessions_nalloc, options.max_sessions);
- tmp = xrealloc(sessions, sessions_nalloc + 1,
+ tmp = xreallocarray(sessions, sessions_nalloc + 1,
sizeof(*sessions));
if (tmp == NULL) {
error("%s: cannot allocate %d sessions",
@@ -2255,7 +2253,7 @@ session_env_req(Session *s)
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, s->num_env + 1,
+ s->env = xreallocarray(s->env, s->num_env + 1,
sizeof(*s->env));
s->env[s->num_env].name = name;
s->env[s->num_env].val = val;
@@ -2652,7 +2650,7 @@ session_setup_x11fwd(Session *s)
{
struct stat st;
char display[512], auth_display[512];
- char hostname[MAXHOSTNAMELEN];
+ char hostname[NI_MAXHOST];
u_int i;
if (no_x11_forwarding_flag) {
@@ -2663,7 +2661,7 @@ session_setup_x11fwd(Session *s)
debug("X11 forwarding disabled in server configuration file.");
return 0;
}
- if (!options.xauth_location ||
+ if (options.xauth_location == NULL ||
(stat(options.xauth_location, &st) == -1)) {
packet_send_debug("No xauth program; cannot forward with spoofing.");
return 0;
OpenPOWER on IntegriCloud