summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2010-11-05 14:47:01 +1100
committerDarren Tucker <dtucker@zip.com.au>2010-11-05 14:47:01 +1100
commitb12fe272a0e850175417aa56e6efef8f08250977 (patch)
treeabd6a1ee2fefd9b12525a85d21667bee3b8cb99a
parentcc12418e18242ce1f61d7035da4956274ba13a96 (diff)
- (dtucker) [platform.c platform.h session.c] Move the Cygwin special-case
check into platform.c
-rw-r--r--ChangeLog2
-rw-r--r--platform.c18
-rw-r--r--platform.h3
-rw-r--r--session.c5
4 files changed, 22 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index cc6e09ad5..65e0f9e3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -40,6 +40,8 @@
40 platform.c. 40 platform.c.
41 - (dtucker) [platform.c session.c] Move PAM credential establishment for the 41 - (dtucker) [platform.c session.c] Move PAM credential establishment for the
42 non-LOGIN_CAP case into platform.c. 42 non-LOGIN_CAP case into platform.c.
43 - (dtucker) [platform.c platform.h session.c] Move the Cygwin special-case
44 check into platform.c
43 45
4420101025 4620101025
45 - (tim) [openbsd-compat/glob.h] Remove sys/cdefs.h include that came with 47 - (tim) [openbsd-compat/glob.h] Remove sys/cdefs.h include that came with
diff --git a/platform.c b/platform.c
index b4fb88e5f..f2cf11f56 100644
--- a/platform.c
+++ b/platform.c
@@ -1,4 +1,4 @@
1/* $Id: platform.c,v 1.13 2010/11/05 02:32:53 dtucker Exp $ */ 1/* $Id: platform.c,v 1.14 2010/11/05 03:47:01 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006 Darren Tucker. All rights reserved. 4 * Copyright (c) 2006 Darren Tucker. All rights reserved.
@@ -17,6 +17,10 @@
17 */ 17 */
18 18
19#include "config.h" 19#include "config.h"
20
21#include <sys/types.h>
22#include <unistd.h>
23
20#include "platform.h" 24#include "platform.h"
21 25
22#include "openbsd-compat/openbsd-compat.h" 26#include "openbsd-compat/openbsd-compat.h"
@@ -59,6 +63,18 @@ platform_post_fork_child(void)
59#endif 63#endif
60} 64}
61 65
66/* return 1 if we are running with privilege to swap UIDs, 0 otherwise */
67int
68platform_privileged_uidswap(void)
69{
70#ifdef HAVE_CYGWIN
71 /* uid 0 is not special on Cygwin so always try */
72 return 1;
73#else
74 return (getuid() == 0 || geteuid() == 0);
75#endif
76}
77
62/* 78/*
63 * This gets called before switching UIDs, and is called even when sshd is 79 * This gets called before switching UIDs, and is called even when sshd is
64 * not running as root. 80 * not running as root.
diff --git a/platform.h b/platform.h
index be66d55c6..944d2c340 100644
--- a/platform.h
+++ b/platform.h
@@ -1,4 +1,4 @@
1/* $Id: platform.h,v 1.6 2010/11/05 01:36:15 dtucker Exp $ */ 1/* $Id: platform.h,v 1.7 2010/11/05 03:47:01 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006 Darren Tucker. All rights reserved. 4 * Copyright (c) 2006 Darren Tucker. All rights reserved.
@@ -24,6 +24,7 @@ void platform_pre_listen(void);
24void platform_pre_fork(void); 24void platform_pre_fork(void);
25void platform_post_fork_parent(pid_t child_pid); 25void platform_post_fork_parent(pid_t child_pid);
26void platform_post_fork_child(void); 26void platform_post_fork_child(void);
27int platform_privileged_uidswap(void);
27void platform_setusercontext(struct passwd *); 28void platform_setusercontext(struct passwd *);
28void platform_setusercontext_post_groups(struct passwd *); 29void platform_setusercontext_post_groups(struct passwd *);
29char *platform_get_krb5_client(const char *); 30char *platform_get_krb5_client(const char *);
diff --git a/session.c b/session.c
index f1f26ef69..58e681282 100644
--- a/session.c
+++ b/session.c
@@ -1471,10 +1471,7 @@ do_setusercontext(struct passwd *pw)
1471 1471
1472 platform_setusercontext(pw); 1472 platform_setusercontext(pw);
1473 1473
1474#ifndef HAVE_CYGWIN 1474 if (platform_privileged_uidswap()) {
1475 if (getuid() == 0 || geteuid() == 0)
1476#endif /* HAVE_CYGWIN */
1477 {
1478#ifdef HAVE_LOGIN_CAP 1475#ifdef HAVE_LOGIN_CAP
1479 if (setusercontext(lc, pw, pw->pw_uid, 1476 if (setusercontext(lc, pw, pw->pw_uid,
1480 (LOGIN_SETALL & ~(LOGIN_SETPATH|LOGIN_SETUSER))) < 0) { 1477 (LOGIN_SETALL & ~(LOGIN_SETPATH|LOGIN_SETUSER))) < 0) {