parent
a5c04381fc
commit
92e109d75f
|
@ -88,7 +88,7 @@ int
|
|||
EspawnApplication(const char *params, int flags)
|
||||
{
|
||||
char exe[FILEPATH_LEN_MAX];
|
||||
char *sh;
|
||||
const char *sh;
|
||||
char *path;
|
||||
char *real_exec;
|
||||
|
||||
|
@ -105,7 +105,7 @@ EspawnApplication(const char *params, int flags)
|
|||
|
||||
ExecSetupEnv(flags);
|
||||
|
||||
sh = usershell(getuid());
|
||||
sh = usershell();
|
||||
|
||||
if (path_canexec(exe))
|
||||
{
|
||||
|
|
13
src/config.c
13
src/config.c
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
|
||||
* Copyright (C) 2004-2010 Kim Woelders
|
||||
* Copyright (C) 2004-2012 Kim Woelders
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
|
@ -233,16 +233,11 @@ static int
|
|||
ConfigFilePreparse(const char *src, const char *dst, const char *themepath)
|
||||
{
|
||||
char execline[FILEPATH_LEN_MAX];
|
||||
char *def_home, *def_user, *def_shell;
|
||||
const char *variant;
|
||||
|
||||
if (EDebug(EDBUG_TYPE_CONFIG))
|
||||
Eprintf("ConfigFilePreparse %s -> %s\n", src, dst);
|
||||
|
||||
def_home = homedir(getuid());
|
||||
def_user = username(getuid());
|
||||
def_shell = usershell(getuid());
|
||||
|
||||
/* When themepath is NULL it shouldn't be used, but this is consistent
|
||||
* with old behavior */
|
||||
if (!themepath)
|
||||
|
@ -264,13 +259,9 @@ ConfigFilePreparse(const char *src, const char *dst, const char *themepath)
|
|||
e_wm_version, EDirRoot(), EDirBin(), themepath, variant,
|
||||
EDirUser(), EDirUserCache(),
|
||||
WinGetW(VROOT), WinGetH(VROOT), WinGetW(VROOT), WinGetH(VROOT),
|
||||
WinGetDepth(VROOT), def_user, def_home, def_shell, src, dst);
|
||||
WinGetDepth(VROOT), username(), userhome(), usershell(), src, dst);
|
||||
Esystem(execline);
|
||||
|
||||
Efree(def_user);
|
||||
Efree(def_shell);
|
||||
Efree(def_home);
|
||||
|
||||
return exists(dst) ? 0 : 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
|
||||
* Copyright (C) 2004-2010 Kim Woelders
|
||||
* Copyright (C) 2004-2012 Kim Woelders
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
|
@ -547,9 +547,10 @@ EDirMake(const char *base, const char *name)
|
|||
static void
|
||||
EDirsSetup(void)
|
||||
{
|
||||
char s[1024], *home, *cfgdir;
|
||||
const char *home;
|
||||
char s[1024], *cfgdir;
|
||||
|
||||
home = homedir(getuid());
|
||||
home = userhome();
|
||||
EDirCheck(home);
|
||||
|
||||
/* Set user config dir if not already set */
|
||||
|
@ -559,7 +560,6 @@ EDirsSetup(void)
|
|||
Esnprintf(s, sizeof(s), "%s/.e16", home);
|
||||
Mode.conf.dir = cfgdir = Estrdup(s);
|
||||
}
|
||||
Efree(home);
|
||||
|
||||
if (exists(cfgdir))
|
||||
{
|
||||
|
|
|
@ -60,7 +60,7 @@ static void
|
|||
set_save_props(SmcConn smc_conn, int master_flag)
|
||||
{
|
||||
const char *s;
|
||||
char *user;
|
||||
const char *user;
|
||||
const char *program;
|
||||
char priority = 10;
|
||||
char style;
|
||||
|
@ -135,13 +135,13 @@ set_save_props(SmcConn smc_conn, int master_flag)
|
|||
/* Slave WMs never restart */
|
||||
style = SmRestartNever;
|
||||
|
||||
user = username(getuid());
|
||||
user = username();
|
||||
/* The SM specs state that the SmProgram should be the argument passed
|
||||
* to execve. Passing argv[0] is close enough. */
|
||||
program = Mode.wm.exec_name;
|
||||
|
||||
userIDVal.length = (user) ? strlen(user) : 0;
|
||||
userIDVal.value = user;
|
||||
userIDVal.value = (char *)user;
|
||||
programVal.length = strlen(program);
|
||||
programVal.value = (char *)program;
|
||||
styleVal.length = 1;
|
||||
|
@ -235,7 +235,6 @@ set_save_props(SmcConn smc_conn, int master_flag)
|
|||
props[n++] = &priorityProp;
|
||||
|
||||
SmcSetProperties(smc_conn, n, props);
|
||||
Efree(user);
|
||||
}
|
||||
|
||||
/* This function is usually exclusively devoted to saving data.
|
||||
|
|
111
src/user.c
111
src/user.c
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
|
||||
* Copyright (C) 2012 Kim Woelders
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
|
@ -29,83 +30,61 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char *
|
||||
username(int uid)
|
||||
{
|
||||
char *s;
|
||||
static int usr_uid = -1;
|
||||
static char *usr_s = NULL;
|
||||
struct passwd *pwd;
|
||||
static int usr_uid = -1;
|
||||
static const char *usr_name = "unknown";
|
||||
static const char *usr_home = "/tmp";
|
||||
static const char *usr_shell = "/bin/sh";
|
||||
|
||||
if (usr_uid < 0)
|
||||
usr_uid = getuid();
|
||||
if ((uid == usr_uid) && (usr_s))
|
||||
return Estrdup(usr_s);
|
||||
pwd = getpwuid(uid);
|
||||
if (pwd)
|
||||
{
|
||||
s = Estrdup(pwd->pw_name);
|
||||
if (uid == usr_uid)
|
||||
usr_s = Estrdup(s);
|
||||
return s;
|
||||
}
|
||||
return Estrdup("unknown");
|
||||
}
|
||||
|
||||
char *
|
||||
homedir(int uid)
|
||||
static void
|
||||
_user_init(void)
|
||||
{
|
||||
static int usr_uid = -1;
|
||||
static char *usr_s = NULL;
|
||||
char *s;
|
||||
const char *ss;
|
||||
struct passwd *pwd;
|
||||
|
||||
if (usr_uid < 0)
|
||||
usr_uid = getuid();
|
||||
if ((uid == usr_uid) && (usr_s))
|
||||
usr_uid = getuid();
|
||||
pwd = getpwuid(usr_uid);
|
||||
|
||||
if (!pwd)
|
||||
{
|
||||
return Estrdup(usr_s);
|
||||
ss = getenv("TMPDIR");
|
||||
if (ss)
|
||||
usr_home = ss;
|
||||
}
|
||||
pwd = getpwuid(uid);
|
||||
if (pwd)
|
||||
|
||||
ss = Estrdup(pwd->pw_name);
|
||||
if (ss)
|
||||
usr_name = ss;
|
||||
ss = Estrdup(pwd->pw_dir);
|
||||
if (ss)
|
||||
usr_home = ss;
|
||||
if (canexec(pwd->pw_shell))
|
||||
{
|
||||
s = Estrdup(pwd->pw_dir);
|
||||
if (uid == usr_uid)
|
||||
usr_s = Estrdup(s);
|
||||
return s;
|
||||
ss = Estrdup(pwd->pw_shell);
|
||||
if (ss)
|
||||
usr_shell = ss;
|
||||
}
|
||||
ss = getenv("TMPDIR");
|
||||
if (!ss)
|
||||
ss = "/tmp";
|
||||
return Estrdup(ss);
|
||||
}
|
||||
|
||||
char *
|
||||
usershell(int uid)
|
||||
const char *
|
||||
username(void)
|
||||
{
|
||||
char *s;
|
||||
static int usr_uid = -1;
|
||||
static char *usr_s = NULL;
|
||||
struct passwd *pwd;
|
||||
|
||||
if (usr_uid < 0)
|
||||
usr_uid = getuid();
|
||||
if ((uid == usr_uid) && (usr_s))
|
||||
return Estrdup(usr_s);
|
||||
pwd = getpwuid(uid);
|
||||
if (pwd)
|
||||
{
|
||||
if (!pwd->pw_shell)
|
||||
return Estrdup("/bin/sh");
|
||||
if (strlen(pwd->pw_shell) < 1)
|
||||
return Estrdup("/bin/sh");
|
||||
if (!(canexec(pwd->pw_shell)))
|
||||
return Estrdup("/bin/sh");
|
||||
s = Estrdup(pwd->pw_shell);
|
||||
if (uid == usr_uid)
|
||||
usr_s = Estrdup(s);
|
||||
return s;
|
||||
}
|
||||
return Estrdup("/bin/sh");
|
||||
_user_init();
|
||||
return usr_name;
|
||||
}
|
||||
|
||||
const char *
|
||||
userhome(void)
|
||||
{
|
||||
if (usr_uid < 0)
|
||||
_user_init();
|
||||
return usr_home;
|
||||
}
|
||||
|
||||
const char *
|
||||
usershell(void)
|
||||
{
|
||||
if (usr_uid < 0)
|
||||
_user_init();
|
||||
return usr_shell;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
|
||||
* Copyright (C) 2012 Kim Woelders
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
|
@ -23,8 +24,8 @@
|
|||
#ifndef _USER_H_
|
||||
#define _USER_H_
|
||||
|
||||
char *username(int uid);
|
||||
char *homedir(int uid);
|
||||
char *usershell(int uid);
|
||||
const char *username(void);
|
||||
const char *userhome(void);
|
||||
const char *usershell(void);
|
||||
|
||||
#endif /* _USER_H_ */
|
||||
|
|
Loading…
Reference in New Issue