Merge pull request #694 from bebehei/issue-693-unset-home
Retrieve user's home from passwd entry as fallback
This commit is contained in:
commit
fbdef7b58a
21
src/utils.c
21
src/utils.c
@ -5,9 +5,11 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
@ -138,7 +140,7 @@ char *string_to_path(char *string)
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (string && STRN_EQ(string, "~/", 2)) {
|
if (string && STRN_EQ(string, "~/", 2)) {
|
||||||
char *home = g_strconcat(getenv("HOME"), "/", NULL);
|
char *home = g_strconcat(user_get_home(), "/", NULL);
|
||||||
|
|
||||||
string = string_replace_at(string, 0, 2, home);
|
string = string_replace_at(string, 0, 2, home);
|
||||||
|
|
||||||
@ -204,4 +206,21 @@ gint64 time_monotonic_now(void)
|
|||||||
#endif
|
#endif
|
||||||
return S2US(tv_now.tv_sec) + tv_now.tv_nsec / 1000;
|
return S2US(tv_now.tv_sec) + tv_now.tv_nsec / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* see utils.h */
|
||||||
|
const char *user_get_home(void)
|
||||||
|
{
|
||||||
|
static const char *home_directory = NULL;
|
||||||
|
ASSERT_OR_RET(!home_directory, home_directory);
|
||||||
|
|
||||||
|
// Check the HOME variable for the user's home
|
||||||
|
home_directory = getenv("HOME");
|
||||||
|
ASSERT_OR_RET(!home_directory, home_directory);
|
||||||
|
|
||||||
|
// Check the /etc/passwd entry for the user's home
|
||||||
|
home_directory = getpwuid(getuid())->pw_dir;
|
||||||
|
|
||||||
|
return home_directory;
|
||||||
|
}
|
||||||
|
|
||||||
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
||||||
|
@ -110,5 +110,12 @@ gint64 string_to_time(const char *string);
|
|||||||
*/
|
*/
|
||||||
gint64 time_monotonic_now(void);
|
gint64 time_monotonic_now(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the HOME directory of the user running dunst
|
||||||
|
*
|
||||||
|
* @returns: A string of the current home directory
|
||||||
|
*/
|
||||||
|
const char *user_get_home(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user