summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6ae8a44)
raw | patch | inline | side by side (parent: 6ae8a44)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 16 Jan 2015 13:16:12 +0000 (14:16 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 16 Jan 2015 13:16:12 +0000 (14:16 +0100) |
src/tools/sysdb/main.c | patch | blob | history |
diff --git a/src/tools/sysdb/main.c b/src/tools/sysdb/main.c
index 357ef34827672d0033030eeefe8d85d059f98836..e5f20ea4bbfbaf8c151ec11aa6d20f218c1daf35 100644 (file)
--- a/src/tools/sysdb/main.c
+++ b/src/tools/sysdb/main.c
#endif
static const char *
-get_homedir(const char *username)
+get_homedir(void)
{
+ char *username = sdb_get_current_user();
+
struct passwd pw_entry;
struct passwd *result = NULL;
int status;
- memset(&pw_entry, 0, sizeof(pw_entry));
- status = getpwnam_r(username, &pw_entry, buf, sizeof(buf), &result);
+ if (username) {
+ memset(&pw_entry, 0, sizeof(pw_entry));
+ status = getpwnam_r(username, &pw_entry, buf, sizeof(buf), &result);
+ }
+ else
+ status = -1;
if (status || (! result)) {
char errbuf[1024];
sdb_log(SDB_LOG_WARNING, "Failed to determine home directory "
"for user %s: %s", username,
sdb_strerror(errno, errbuf, sizeof(errbuf)));
+ free(username);
return NULL;
}
+ free(username);
return result->pw_dir;
} /* get_homedir */
using_history();
- if ((homedir = get_homedir(input.user))) {
+ if ((homedir = get_homedir())) {
snprintf(hist_file, sizeof(hist_file) - 1,
"%s/.sysdb_history", homedir);
hist_file[sizeof(hist_file) - 1] = '\0';