components/openssh/patches/010-gss_store_cred.patch
author Tomas Kuthan <tomas.kuthan@oracle.com>
Thu, 29 Oct 2015 02:40:10 -0700
changeset 5025 bdd7dc7d2af4
parent 1796 a2310ec32635
child 5818 5f0e7a0f17c2
permissions -rw-r--r--
PSARC/2015/395 OpenSSH 7.1p1 21696247 upgrade OpenSSH to 7.1p1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     1
#
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     2
# This patch modifies code for storing delegated GSS-API credentials to work
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     3
# with Solaris Kerberos.
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     4
#
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     5
# Default credential cache is used instead of per-session credentials cache
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     6
# because on Solaris gssd cannot use credentials from non-default cred store.
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     7
# A downside of this solution is, that the default credential cache file
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     8
# cannot be deleted upon logout and hence GSSAPICleanupCredentials is
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     9
# unsupported for now.
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    10
#
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    11
# To store the credentials a standardized GSS-API function gss_store_cred() is
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    12
# used instead of gss_krb5_copy_ccache(), because (unlike MIT Kerberos
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    13
# libgssapi_krb5) Solaris Kerberos libgss does not have Kerberos mechanism
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    14
# directly built in the library and this function is not directly accessible.
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    15
#
1796
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    16
# The patch is implemented as Solaris-specific using USE_GSS_STORE_CRED
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    17
# and GSSAPI_STORECREDS_NEEDS_RUID macros.
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    18
#
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    19
diff -pur old/config.h.in new/config.h.in
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    20
--- old/config.h.in
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    21
+++ new/config.h.in
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    22
@@ -1623,6 +1623,12 @@
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    23
 /* Use btmp to log bad logins */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    24
 #undef USE_BTMP
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    25
 
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    26
+/* Store delegated credentials in default cred. store using gss_store_cred */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    27
+#undef USE_GSS_STORE_CRED
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    28
+
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    29
+/* Set real uid prior to storing delegated credentials */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    30
+#undef GSSAPI_STORECREDS_NEEDS_RUID
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    31
+
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    32
 /* Use libedit for sftp */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    33
 #undef USE_LIBEDIT
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    34
 
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    35
diff -pur old/configure new/configure
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    36
--- old/configure
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    37
+++ new/configure
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    38
@@ -10944,6 +10944,9 @@ fi
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    39
 
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    40
 fi
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    41
 
1796
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    42
+        $as_echo "#define USE_GSS_STORE_CRED 1" >>confdefs.h
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    43
+        $as_echo "#define GSSAPI_STORECREDS_NEEDS_RUID 1" >>confdefs.h
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    44
+
1796
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    45
 	TEST_SHELL=$SHELL	# let configure find us a capable shell
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    46
 	;;
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    47
 *-*-sunos4*)
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    48
diff -pur old/configure.ac new/configure.ac
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    49
--- old/configure.ac
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    50
+++ new/configure.ac
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    51
@@ -910,6 +910,8 @@ mips-sony-bsd|mips-sony-newsos4)
1796
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    52
 		],
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    53
 	)
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    54
 	TEST_SHELL=$SHELL	# let configure find us a capable shell
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    55
+        AC_DEFINE([USE_GSS_STORE_CRED])
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    56
+        AC_DEFINE([GSSAPI_STORECREDS_NEEDS_RUID])
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    57
 	;;
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    58
 *-*-sunos4*)
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    59
 	CPPFLAGS="$CPPFLAGS -DSUNOS4"
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    60
diff -pur old/gss-serv-krb5.c new/gss-serv-krb5.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    61
--- old/gss-serv-krb5.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    62
+++ new/gss-serv-krb5.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    63
@@ -110,7 +110,7 @@ ssh_gssapi_krb5_userok(ssh_gssapi_client
1796
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    64
 	return retval;
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    65
 }
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    66
 
1796
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    67
-
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    68
+#ifndef USE_GSS_STORE_CRED
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    69
 /* This writes out any forwarded credentials from the structure populated
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    70
  * during userauth. Called after we have setuid to the user */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    71
 
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    72
@@ -196,6 +196,7 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_cl
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    73
 
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    74
 	return;
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    75
 }
1796
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
    76
+#endif /* #ifndef USE_GSS_STORE_CRED */
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    77
 
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    78
 ssh_gssapi_mech gssapi_kerberos_mech = {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    79
 	"toWM5Slw5Ew8Mqkay+al2g==",
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    80
@@ -204,7 +205,11 @@ ssh_gssapi_mech gssapi_kerberos_mech = {
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    81
 	NULL,
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    82
 	&ssh_gssapi_krb5_userok,
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    83
 	NULL,
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    84
+#ifdef USE_GSS_STORE_CRED
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    85
+	NULL
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    86
+#else
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    87
 	&ssh_gssapi_krb5_storecreds
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    88
+#endif
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    89
 };
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    90
 
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    91
 #endif /* KRB5 */
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    92
diff -pur old/gss-serv.c new/gss-serv.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    93
--- old/gss-serv.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    94
+++ new/gss-serv.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
    95
@@ -320,22 +320,66 @@ ssh_gssapi_getclient(Gssctxt *ctx, ssh_g
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    96
 void
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    97
 ssh_gssapi_cleanup_creds(void)
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    98
 {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    99
+#ifdef USE_GSS_STORE_CRED
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   100
+	debug("removing gssapi cred file not implemented");
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   101
+#else
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   102
 	if (gssapi_client.store.filename != NULL) {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   103
 		/* Unlink probably isn't sufficient */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   104
 		debug("removing gssapi cred file\"%s\"",
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   105
 		    gssapi_client.store.filename);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   106
 		unlink(gssapi_client.store.filename);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   107
 	}
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   108
+#endif /* USE_GSS_STORE_CRED */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   109
 }
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   110
 
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   111
 /* As user */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   112
 void
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   113
 ssh_gssapi_storecreds(void)
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   114
 {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   115
+#ifdef USE_GSS_STORE_CRED
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   116
+	OM_uint32 maj_status, min_status;
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   117
+
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   118
+	if (gssapi_client.creds == NULL) {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   119
+		debug("No credentials stored");
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   120
+		return;
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   121
+	}
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   122
+
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   123
+	maj_status = gss_store_cred(&min_status, gssapi_client.creds,
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   124
+	    GSS_C_INITIATE, &gssapi_client.mech->oid, 1, 1, NULL, NULL);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   125
+
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   126
+	if (GSS_ERROR(maj_status)) {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   127
+		Buffer b;
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   128
+		gss_buffer_desc msg;
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   129
+		OM_uint32 lmin;
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   130
+		OM_uint32 more = 0;
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   131
+		buffer_init(&b);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   132
+		/* GSS-API error */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   133
+		do {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   134
+			gss_display_status(&lmin, maj_status, GSS_C_GSS_CODE,
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   135
+			    GSS_C_NULL_OID, &more, &msg);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   136
+			buffer_append(&b, msg.value, msg.length);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   137
+			buffer_put_char(&b, '\n');
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   138
+			gss_release_buffer(&lmin, &msg);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   139
+		} while (more != 0);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   140
+		/* Mechanism specific error */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   141
+		do {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   142
+			gss_display_status(&lmin, min_status, GSS_C_MECH_CODE,
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   143
+			    &gssapi_client.mech->oid, &more, &msg);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   144
+			buffer_append(&b, msg.value, msg.length);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   145
+			buffer_put_char(&b, '\n');
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   146
+			gss_release_buffer(&lmin, &msg);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   147
+		} while (more != 0);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   148
+		buffer_put_char(&b, '\0');
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   149
+		error("GSS-API error while storing delegated credentials: %s",
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   150
+		    buffer_ptr(&b));
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   151
+		buffer_free(&b);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   152
+	}
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   153
+#else	/* #ifdef USE_GSS_STORE_CRED */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   154
 	if (gssapi_client.mech && gssapi_client.mech->storecreds) {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   155
 		(*gssapi_client.mech->storecreds)(&gssapi_client);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   156
 	} else
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   157
 		debug("ssh_gssapi_storecreds: Not a GSSAPI mechanism");
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   158
+#endif	/* #ifdef USE_GSS_STORE_CRED */
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   159
 }
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   160
 
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   161
 /* This allows GSSAPI methods to do things to the childs environment based
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   162
diff -pur old/servconf.c new/servconf.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   163
--- old/servconf.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   164
+++ new/servconf.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   165
@@ -489,7 +489,11 @@ static struct {
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   166
 	{ "afstokenpassing", sUnsupported, SSHCFG_GLOBAL },
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   167
 #ifdef GSSAPI
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   168
 	{ "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   169
-	{ "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   170
+#ifdef USE_GSS_STORE_CRED
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   171
+	{ "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
1796
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
   172
+#else /* USE_GSS_STORE_CRED */
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   173
+ 	{ "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
1796
a2310ec32635 PSARC 2014/078 OpenSSH 6.5
Huie-Ying Lee <huieying.lee@oracle.com>
parents: 1786
diff changeset
   174
+#endif /* USE_GSS_STORE_CRED */
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   175
 	{ "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   176
 #else
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   177
 	{ "gssapiauthentication", sUnsupported, SSHCFG_ALL },
5025
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   178
@@ -2264,7 +2268,9 @@ dump_config(ServerOptions *o)
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   179
 #endif
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   180
 #ifdef GSSAPI
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   181
 	dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   182
+#ifndef USE_GSS_STORE_CRED
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   183
 	dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   184
+#endif /* !USE_GSS_STORE_CRED */
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   185
 #endif
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   186
 	dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   187
 	dump_cfg_fmtint(sKbdInteractiveAuthentication,
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   188
diff -pur old/sshd.c new/sshd.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   189
--- old/sshd.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   190
+++ new/sshd.c
bdd7dc7d2af4 PSARC/2015/395 OpenSSH 7.1p1
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1796
diff changeset
   191
@@ -2228,9 +2228,23 @@ main(int ac, char **av)
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   192
 
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   193
 #ifdef GSSAPI
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   194
 	if (options.gss_authentication) {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   195
+#ifdef GSSAPI_STORECREDS_NEEDS_RUID
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   196
+		if (setreuid(authctxt->pw->pw_uid, -1) != 0) {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   197
+			debug("setreuid %u: %.100s",
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   198
+			    (u_int) authctxt->pw->pw_uid, strerror(errno));
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   199
+			goto bail_storecred;
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   200
+		}
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   201
+#endif
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   202
 		temporarily_use_uid(authctxt->pw);
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   203
 		ssh_gssapi_storecreds();
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   204
 		restore_uid();
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   205
+#ifdef GSSAPI_STORECREDS_NEEDS_RUID
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   206
+		if (setuid(geteuid()) != 0) {
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   207
+			fatal("setuid %u: %.100s", (u_int) geteuid(),
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   208
+			    strerror(errno));
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   209
+		}
1786
d2b02f72138c 18267729 Delegating credentials in OpenSSH (fix parfait)
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 1783
diff changeset
   210
+ bail_storecred: ;
1783
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   211
+#endif
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   212
 	}
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   213
 #endif
d716b9b5961b 18267729 Delegating credentials in OpenSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   214
 #ifdef USE_PAM