summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2012-08-01 14:05:52 -0400
committerGreg Hudson <ghudson@mit.edu>2012-08-01 14:06:07 -0400
commit69947d9bf040f01e6ea2d0a6e761692132487b7e (patch)
tree7e463bab2c1346248760dd9e82d62f0693c22eb3
parent3551501359c6d2396fa4779d378ae165f5b37242 (diff)
downloadkrb5-69947d9bf040f01e6ea2d0a6e761692132487b7e.tar.gz
krb5-69947d9bf040f01e6ea2d0a6e761692132487b7e.tar.xz
krb5-69947d9bf040f01e6ea2d0a6e761692132487b7e.zip
Add %{username} token to path expansion
For Unix-like platforms, add %{username} to the path expansion facility, expanding to the result of getpwuid on the euid. Also, for manual testing convenience, make t_expand_path print the result if no second argument is given.
-rw-r--r--doc/rst_source/krb_admins/conf_files/krb5_conf.rst1
-rw-r--r--src/lib/krb5/os/expand_path.c24
-rw-r--r--src/lib/krb5/os/t_expand_path.c4
3 files changed, 27 insertions, 2 deletions
diff --git a/doc/rst_source/krb_admins/conf_files/krb5_conf.rst b/doc/rst_source/krb_admins/conf_files/krb5_conf.rst
index ee7344c5d8..689e61c927 100644
--- a/doc/rst_source/krb_admins/conf_files/krb5_conf.rst
+++ b/doc/rst_source/krb_admins/conf_files/krb5_conf.rst
@@ -991,6 +991,7 @@ to be expanded. Valid parameters are:
%{LIBDIR} Installation library directory
%{BINDIR} Installation binary directory
%{SBINDIR} Installation admin binary directory
+ %{username} (Unix) Username of effective user ID
%{APPDATA} (Windows) Roaming application data for current user
%{COMMON_APPDATA} (Windows) Application data for all users
%{LOCAL_APPDATA} (Windows) Local application data for current user
diff --git a/src/lib/krb5/os/expand_path.c b/src/lib/krb5/os/expand_path.c
index deab4e3b1f..2da145fd62 100644
--- a/src/lib/krb5/os/expand_path.c
+++ b/src/lib/krb5/os/expand_path.c
@@ -264,7 +264,8 @@ expand_csidl(krb5_context context, PTYPE folder, const char *postfix,
return 0;
}
-#else
+#else /* not _WIN32 */
+#include <pwd.h>
static krb5_error_code
expand_path(krb5_context context, PTYPE param, const char *postfix, char **ret)
@@ -306,6 +307,26 @@ expand_euid(krb5_context context, PTYPE param, const char *postfix, char **str)
return 0;
}
+static krb5_error_code
+expand_username(krb5_context context, PTYPE param, const char *postfix,
+ char **str)
+{
+ uid_t euid = geteuid();
+ struct passwd *pw, pwx;
+ char pwbuf[BUFSIZ];
+
+ if (k5_getpwuid_r(euid, &pwx, pwbuf, sizeof(pwbuf), &pw) != 0) {
+ krb5_set_error_message(context, ENOENT,
+ _("Can't find username for uid %lu"),
+ (unsigned long)euid);
+ return ENOENT;
+ }
+ *str = strdup(pw->pw_name);
+ if (*str == NULL)
+ return ENOMEM;
+ return 0;
+}
+
#endif /* not _WIN32 */
/*
@@ -366,6 +387,7 @@ static const struct token {
{"BINDIR", 0, BINDIR, expand_path},
{"SBINDIR", 0, SBINDIR, expand_path},
{"euid", 0, NULL, expand_euid},
+ {"username", 0, NULL, expand_username},
#endif
{"TEMP", 0, NULL, expand_temp_folder},
{"USERID", 0, NULL, expand_userid},
diff --git a/src/lib/krb5/os/t_expand_path.c b/src/lib/krb5/os/t_expand_path.c
index b318ff980a..5f63577a3c 100644
--- a/src/lib/krb5/os/t_expand_path.c
+++ b/src/lib/krb5/os/t_expand_path.c
@@ -9,7 +9,9 @@ main(int argc, char **argv)
if (k5_expand_path_tokens_extra(NULL, argv[1], &path, "animal", "frog",
"place", "pad", "s", "s", NULL) != 0)
return 2;
- if (strcmp(path, argv[2]) != 0)
+ if (argc == 2)
+ printf("%s\n", path);
+ else if (strcmp(path, argv[2]) != 0)
return 1;
free(path);
return 0;