]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Add %{username} token to path expansion
authorGreg Hudson <ghudson@mit.edu>
Wed, 1 Aug 2012 18:05:52 +0000 (14:05 -0400)
committerGreg Hudson <ghudson@mit.edu>
Wed, 1 Aug 2012 18:06:07 +0000 (14:06 -0400)
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
src/lib/krb5/os/expand_path.c
src/lib/krb5/os/t_expand_path.c

index ee7344c5d8be3bf1487eec02d4ce179453cf27e9..689e61c927d4f66d3b78e9143108506f632852e1 100644 (file)
@@ -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
index deab4e3b1ff097104cd6f3da537e377d42fbf054..2da145fd62b5c3a63f0a45c68a10ddbe857f4839 100644 (file)
@@ -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},
index b318ff980a662d0a2000d5ebb59b36e5721e25f0..5f63577a3c5e41f7effe68bea5927e8cb2751a31 100644 (file)
@@ -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;