krb5 commit: Add %{username} token to path expansion
Greg Hudson
ghudson at MIT.EDU
Wed Aug 1 14:06:25 EDT 2012
https://github.com/krb5/krb5/commit/69947d9bf040f01e6ea2d0a6e761692132487b7e
commit 69947d9bf040f01e6ea2d0a6e761692132487b7e
Author: Greg Hudson <ghudson at mit.edu>
Date: Wed Aug 1 14:05:52 2012 -0400
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.
doc/rst_source/krb_admins/conf_files/krb5_conf.rst | 1 +
src/lib/krb5/os/expand_path.c | 24 +++++++++++++++++++-
src/lib/krb5/os/t_expand_path.c | 4 ++-
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 ee7344c..689e61c 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 deab4e3..2da145f 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 b318ff9..5f63577 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;
More information about the cvs-krb5
mailing list