kentpeacock / rpms / openssh

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