rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone

Blame SOURCES/openssh-7.2p2-k5login_directory.patch

3e8b5b
diff --git a/auth-krb5.c b/auth-krb5.c
3e8b5b
index 2b02a04..19b9364 100644
3e8b5b
--- a/auth-krb5.c
3e8b5b
+++ b/auth-krb5.c
3e8b5b
@@ -375,5 +375,21 @@ cleanup:
3e8b5b
 		return (krb5_cc_resolve(ctx, ccname, ccache));
3e8b5b
 	}
3e8b5b
 }
3e8b5b
+
3e8b5b
+/*
3e8b5b
+ * Reads  k5login_directory  option from the  krb5.conf
3e8b5b
+ */
3e8b5b
+krb5_error_code
3e8b5b
+ssh_krb5_get_k5login_directory(krb5_context ctx, char **k5login_directory) {
3e8b5b
+	profile_t p;
3e8b5b
+	int ret = 0;
3e8b5b
+
3e8b5b
+	ret = krb5_get_profile(ctx, &p);
3e8b5b
+	if (ret)
3e8b5b
+		return ret;
3e8b5b
+
3e8b5b
+	return profile_get_string(p, "libdefaults", "k5login_directory", NULL, NULL,
3e8b5b
+		k5login_directory);
3e8b5b
+}
3e8b5b
 #endif /* !HEIMDAL */
3e8b5b
 #endif /* KRB5 */
3e8b5b
diff --git a/auth.h b/auth.h
3e8b5b
index f9d191c..c432d2f 100644
3e8b5b
--- a/auth.h
3e8b5b
+++ b/auth.h
3e8b5b
@@ -222,5 +222,7 @@ int	 sys_auth_passwd(Authctxt *, const char *);
3e8b5b
 #if defined(KRB5) && !defined(HEIMDAL)
3e8b5b
 #include <krb5.h>
3e8b5b
 krb5_error_code ssh_krb5_cc_new_unique(krb5_context, krb5_ccache *, int *);
3e8b5b
+krb5_error_code ssh_krb5_get_k5login_directory(krb5_context ctx,
3e8b5b
+	char **k5login_directory);
3e8b5b
 #endif
3e8b5b
 #endif
3e8b5b
diff --git a/gss-serv-krb5.c b/gss-serv-krb5.c
3e8b5b
index a7c0c5f..df8cc9a 100644
3e8b5b
--- a/gss-serv-krb5.c
3e8b5b
+++ b/gss-serv-krb5.c
3e8b5b
@@ -244,8 +244,27 @@ ssh_gssapi_k5login_exists()
3e8b5b
 {
3e8b5b
 	char file[MAXPATHLEN];
3e8b5b
 	struct passwd *pw = the_authctxt->pw;
3e8b5b
+	char *k5login_directory = NULL;
3e8b5b
+	int ret = 0;
3e8b5b
+
3e8b5b
+	ret = ssh_krb5_get_k5login_directory(krb_context, &k5login_directory);
3e8b5b
+	debug3("%s: k5login_directory = %s (rv=%d)", __func__, k5login_directory, ret);
3e8b5b
+	if (k5login_directory == NULL || ret != 0) {
3e8b5b
+		/* If not set, the library will look for  k5login
3e8b5b
+		 * files in the user's home directory, with the filename  .k5login.
3e8b5b
+		 */
3e8b5b
+		snprintf(file, sizeof(file), "%s/.k5login", pw->pw_dir);
3e8b5b
+	} else {
3e8b5b
+		/* If set, the library will look for a local user's k5login file
3e8b5b
+		 * within the named directory, with a filename corresponding to the
3e8b5b
+		 * local username.
3e8b5b
+		 */
3e8b5b
+		snprintf(file, sizeof(file), "%s%s%s", k5login_directory, 
3e8b5b
+			k5login_directory[strlen(k5login_directory)-1] != '/' ? "/" : "",
3e8b5b
+			pw->pw_name);
3e8b5b
+	}
3e8b5b
+	debug("%s: Checking existence of file %s", __func__, file);
3e8b5b
 
3e8b5b
-	snprintf(file, sizeof(file), "%s/.k5login", pw->pw_dir);
3e8b5b
 	return access(file, F_OK) == 0;
3e8b5b
 }
3e8b5b
 
3e8b5b
diff --git a/sshd.8 b/sshd.8
3e8b5b
index 5c4f15b..135e290 100644
3e8b5b
--- a/sshd.8
3e8b5b
+++ b/sshd.8
3e8b5b
@@ -806,6 +806,10 @@ rlogin/rsh.
3e8b5b
 These files enforce GSSAPI/Kerberos authentication access control.
3e8b5b
 Further details are described in
3e8b5b
 .Xr ksu 1 .
3e8b5b
+The location of the k5login file depends on the configuration option
3e8b5b
+.Cm k5login_directory
3e8b5b
+in the
3e8b5b
+.Xr krb5.conf 5 .
3e8b5b
 .Pp
3e8b5b
 .It Pa ~/.ssh/
3e8b5b
 This directory is the default location for all user-specific configuration