forked from enlightenment/enlightenment
e sys storage - also address media dirs to have to be user named
only allow media dirs to be /media/username/xxx ... fixes T8672
This commit is contained in:
parent
0c79c6317b
commit
dfed5c2718
|
@ -100,6 +100,8 @@ extern Eina_Bool alert_backlight_reset;
|
||||||
|
|
||||||
extern uid_t uid;
|
extern uid_t uid;
|
||||||
extern gid_t gid;
|
extern gid_t gid;
|
||||||
|
extern char *user_name;
|
||||||
|
extern char *group_name;
|
||||||
|
|
||||||
void e_system_inout_init(void);
|
void e_system_inout_init(void);
|
||||||
void e_system_inout_shutdown(void);
|
void e_system_inout_shutdown(void);
|
||||||
|
|
|
@ -4,6 +4,8 @@ Eina_Bool alert_backlight_reset = EINA_FALSE;
|
||||||
|
|
||||||
uid_t uid = -1; // uid of person running me
|
uid_t uid = -1; // uid of person running me
|
||||||
gid_t gid = -1; // gid of person running me
|
gid_t gid = -1; // gid of person running me
|
||||||
|
char *user_name = NULL;
|
||||||
|
char *group_name = NULL;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_conf_allow_deny(const char *cmd, const char *glob)
|
_conf_allow_deny(const char *cmd, const char *glob)
|
||||||
|
@ -110,11 +112,47 @@ static void
|
||||||
setuid_setup(void)
|
setuid_setup(void)
|
||||||
{
|
{
|
||||||
struct passwd *pwent;
|
struct passwd *pwent;
|
||||||
|
struct group *grent;
|
||||||
static char buf[PATH_MAX];
|
static char buf[PATH_MAX];
|
||||||
|
|
||||||
uid = getuid();
|
uid = getuid();
|
||||||
gid = getgid();
|
gid = getgid();
|
||||||
|
|
||||||
|
pwent = getpwuid(uid);
|
||||||
|
if (!pwent)
|
||||||
|
{
|
||||||
|
ERR("Unable to obtain passwd entry for calling user\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (!pwent->pw_name)
|
||||||
|
{
|
||||||
|
ERR("Blank username for user\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
user_name = strdup(pwent->pw_name);
|
||||||
|
if (!user_name)
|
||||||
|
{
|
||||||
|
ERR("Unable to allocate memory for username\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
grent = getgrgid(gid);
|
||||||
|
if (!grent)
|
||||||
|
{
|
||||||
|
ERR("Unable to obtain group entry for calling group\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (!grent->gr_name)
|
||||||
|
{
|
||||||
|
ERR("Blank groupname for group\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
group_name = strdup(grent->gr_name);
|
||||||
|
if (!group_name)
|
||||||
|
{
|
||||||
|
ERR("Unable to allocate memory for groupname\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (setuid(0) != 0)
|
if (setuid(0) != 0)
|
||||||
{
|
{
|
||||||
ERR("Unable to assume root user privileges\n");
|
ERR("Unable to assume root user privileges\n");
|
||||||
|
|
|
@ -87,7 +87,7 @@ _mkdir(const char *path, uid_t u, gid_t g)
|
||||||
}
|
}
|
||||||
if (chown(path, u, g) != 0)
|
if (chown(path, u, g) != 0)
|
||||||
{
|
{
|
||||||
ERR("Can't own [%s] to uid.gid %i.%i\n", path, uid, gid);
|
ERR("Can't own [%s] to uid.gid %i.%i\n", path, u, g);
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
@ -96,7 +96,7 @@ _mkdir(const char *path, uid_t u, gid_t g)
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_store_mount_verify(const char *mnt)
|
_store_mount_verify(const char *mnt)
|
||||||
{
|
{
|
||||||
char *tmnt, *p;
|
char *tmnt, *p, *pp;
|
||||||
const char *s;
|
const char *s;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
|
@ -133,6 +133,10 @@ _store_mount_verify(const char *mnt)
|
||||||
p = strchr(p + 1, '/');
|
p = strchr(p + 1, '/');
|
||||||
if (!p) goto malformed;
|
if (!p) goto malformed;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
pp = strrchr(tmnt, '/');
|
||||||
|
if (!pp) goto err;
|
||||||
|
// check if dir name is name of user...
|
||||||
|
if (strcmp(p + 1, user_name)) goto err;
|
||||||
if (!_mkdir(tmnt, 0, 0)) goto err;
|
if (!_mkdir(tmnt, 0, 0)) goto err;
|
||||||
*p = '/';
|
*p = '/';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue