summaryrefslogtreecommitdiff
path: root/platform.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2011-01-24 12:43:25 +0000
committerColin Watson <cjwatson@debian.org>2011-01-24 12:43:25 +0000
commit626f1d986ff72aa514da63e34744e1de9cf21b9a (patch)
treed215a5280bc2e57251e4a9e08bfd3674ad824a94 /platform.c
parent6ed622cb6fe8f71bbe0d998cdd12280410bfb420 (diff)
parent0970072c89b079b022538e3c366fbfa2c53fc821 (diff)
* New upstream release (http://www.openssh.org/txt/release-5.7):
- Implement Elliptic Curve Cryptography modes for key exchange (ECDH) and host/user keys (ECDSA) as specified by RFC5656. ECDH and ECDSA offer better performance than plain DH and DSA at the same equivalent symmetric key length, as well as much shorter keys. - sftp(1)/sftp-server(8): add a protocol extension to support a hard link operation. It is available through the "ln" command in the client. The old "ln" behaviour of creating a symlink is available using its "-s" option or through the preexisting "symlink" command. - scp(1): Add a new -3 option to scp: Copies between two remote hosts are transferred through the local host (closes: #508613). - ssh(1): "atomically" create the listening mux socket by binding it on a temporary name and then linking it into position after listen() has succeeded. This allows the mux clients to determine that the server socket is either ready or stale without races (closes: #454784). Stale server sockets are now automatically removed (closes: #523250). - ssh(1): install a SIGCHLD handler to reap expired child process (closes: #594687). - ssh(1)/ssh-agent(1): honour $TMPDIR for client xauth and ssh-agent temporary directories (closes: #357469, although only if you arrange for ssh-agent to actually see $TMPDIR since the setgid bit will cause it to be stripped off).
Diffstat (limited to 'platform.c')
-rw-r--r--platform.c132
1 files changed, 130 insertions, 2 deletions
diff --git a/platform.c b/platform.c
index e3a428aaa..a455472b3 100644
--- a/platform.c
+++ b/platform.c
@@ -1,4 +1,4 @@
1/* $Id: platform.c,v 1.3 2009/12/20 23:49:22 dtucker Exp $ */ 1/* $Id: platform.c,v 1.18 2011/01/11 06:02:25 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006 Darren Tucker. All rights reserved. 4 * Copyright (c) 2006 Darren Tucker. All rights reserved.
@@ -16,11 +16,27 @@
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19#include "config.h" 19#include "includes.h"
20
21#include <sys/types.h>
22
23#include <stdarg.h>
24#include <unistd.h>
25
26#include "log.h"
27#include "buffer.h"
28#include "servconf.h"
29#include "key.h"
30#include "hostfile.h"
31#include "auth.h"
32#include "auth-pam.h"
20#include "platform.h" 33#include "platform.h"
21 34
22#include "openbsd-compat/openbsd-compat.h" 35#include "openbsd-compat/openbsd-compat.h"
23 36
37extern int use_privsep;
38extern ServerOptions options;
39
24void 40void
25platform_pre_listen(void) 41platform_pre_listen(void)
26{ 42{
@@ -57,6 +73,118 @@ platform_post_fork_child(void)
57#endif 73#endif
58} 74}
59 75
76/* return 1 if we are running with privilege to swap UIDs, 0 otherwise */
77int
78platform_privileged_uidswap(void)
79{
80#ifdef HAVE_CYGWIN
81 /* uid 0 is not special on Cygwin so always try */
82 return 1;
83#else
84 return (getuid() == 0 || geteuid() == 0);
85#endif
86}
87
88/*
89 * This gets called before switching UIDs, and is called even when sshd is
90 * not running as root.
91 */
92void
93platform_setusercontext(struct passwd *pw)
94{
95#ifdef WITH_SELINUX
96 /* Cache selinux status for later use */
97 (void)ssh_selinux_enabled();
98#endif
99
100#ifdef USE_SOLARIS_PROJECTS
101 /* if solaris projects were detected, set the default now */
102 if (getuid() == 0 || geteuid() == 0)
103 solaris_set_default_project(pw);
104#endif
105
106#if defined(HAVE_LOGIN_CAP) && defined (__bsdi__)
107 if (getuid() == 0 || geteuid() == 0)
108 setpgid(0, 0);
109# endif
110
111#if defined(HAVE_LOGIN_CAP) && defined(USE_PAM)
112 /*
113 * If we have both LOGIN_CAP and PAM, we want to establish creds
114 * before calling setusercontext (in session.c:do_setusercontext).
115 */
116 if (getuid() == 0 || geteuid() == 0) {
117 if (options.use_pam) {
118 do_pam_setcred(use_privsep);
119 }
120 }
121# endif /* USE_PAM */
122
123#if !defined(HAVE_LOGIN_CAP) && defined(HAVE_GETLUID) && defined(HAVE_SETLUID)
124 if (getuid() == 0 || geteuid() == 0) {
125 /* Sets login uid for accounting */
126 if (getluid() == -1 && setluid(pw->pw_uid) == -1)
127 error("setluid: %s", strerror(errno));
128 }
129#endif
130}
131
132/*
133 * This gets called after we've established the user's groups, and is only
134 * called if sshd is running as root.
135 */
136void
137platform_setusercontext_post_groups(struct passwd *pw)
138{
139#if !defined(HAVE_LOGIN_CAP) && defined(USE_PAM)
140 /*
141 * PAM credentials may take the form of supplementary groups.
142 * These will have been wiped by the above initgroups() call.
143 * Reestablish them here.
144 */
145 if (options.use_pam) {
146 do_pam_setcred(use_privsep);
147 }
148#endif /* USE_PAM */
149
150#if !defined(HAVE_LOGIN_CAP) && (defined(WITH_IRIX_PROJECT) || \
151 defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY))
152 irix_setusercontext(pw);
153#endif /* defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) */
154
155#ifdef _AIX
156 aix_usrinfo(pw);
157#endif /* _AIX */
158
159#if !defined(HAVE_LOGIN_CAP) && defined(USE_LIBIAF)
160 if (set_id(pw->pw_name) != 0) {
161 exit(1);
162 }
163# endif /* USE_LIBIAF */
164
165#ifdef HAVE_SETPCRED
166 /*
167 * If we have a chroot directory, we set all creds except real
168 * uid which we will need for chroot. If we don't have a
169 * chroot directory, we don't override anything.
170 */
171 {
172 char **creds = NULL, *chroot_creds[] =
173 { "REAL_USER=root", NULL };
174
175 if (options.chroot_directory != NULL &&
176 strcasecmp(options.chroot_directory, "none") != 0)
177 creds = chroot_creds;
178
179 if (setpcred(pw->pw_name, creds) == -1)
180 fatal("Failed to set process credentials");
181 }
182#endif /* HAVE_SETPCRED */
183#ifdef WITH_SELINUX
184 ssh_selinux_setup_exec_context(pw->pw_name);
185#endif
186}
187
60char * 188char *
61platform_krb5_get_principal_name(const char *pw_name) 189platform_krb5_get_principal_name(const char *pw_name)
62{ 190{