roken: Add roken_get_username() and friends

We add roken_get_{shell, username, appdatadir, homedir}() functions.  These use
a combination of secure_getenv(), getpwuid_r(), getlogin_r(), or various WIN32
functions to get this information.

Use roken_get_appdatadir() instead of roken_get_homedir() when looking for
dotfiles.
This commit is contained in:
Nicolas Williams
2017-10-12 12:19:46 -05:00
committed by Nico Williams
parent 073ffd0423
commit 95eb83c424
7 changed files with 472 additions and 9 deletions

View File

@@ -311,17 +311,17 @@ _expand_euid(krb5_context context, PTYPE param, const char *postfix, char **str)
static krb5_error_code
_expand_username(krb5_context context, PTYPE param, const char *postfix, char **str)
{
uid_t uid = geteuid();
struct passwd *pwd, pw;
char pwbuf[2048];
char user[128];
const char *username = roken_get_username(user, sizeof(user));
if (rk_getpwuid_r(uid, &pw, pwbuf, sizeof(pwbuf), &pwd) != 0) {
krb5_set_error_message(context, ENOENT,
"Could not find username for UID '%ld'", (long)uid);
return ENOENT;
if (username == NULL) {
krb5_set_error_message(context, ENOTTY,
N_("unable to figure out current principal",
""));
return ENOTTY; /* XXX */
}
*str = strdup(pwd->pw_name);
*str = strdup(username);
if (*str == NULL)
return krb5_enomem(context);