kentpeacock / rpms / openssh

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