summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/krb5/os/expand_path.c24
-rw-r--r--src/lib/krb5/os/t_expand_path.c4
2 files changed, 26 insertions, 2 deletions
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;