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:
Carsten Haitzler 2020-04-22 14:26:34 +01:00
parent 0c79c6317b
commit dfed5c2718
3 changed files with 46 additions and 2 deletions

View File

@ -100,6 +100,8 @@ extern Eina_Bool alert_backlight_reset;
extern uid_t uid;
extern gid_t gid;
extern char *user_name;
extern char *group_name;
void e_system_inout_init(void);
void e_system_inout_shutdown(void);

View File

@ -4,6 +4,8 @@ Eina_Bool alert_backlight_reset = EINA_FALSE;
uid_t uid = -1; // uid of person running me
gid_t gid = -1; // gid of person running me
char *user_name = NULL;
char *group_name = NULL;
static int
_conf_allow_deny(const char *cmd, const char *glob)
@ -110,11 +112,47 @@ static void
setuid_setup(void)
{
struct passwd *pwent;
struct group *grent;
static char buf[PATH_MAX];
uid = getuid();
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)
{
ERR("Unable to assume root user privileges\n");

View File

@ -87,7 +87,7 @@ _mkdir(const char *path, uid_t u, gid_t g)
}
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_TRUE;
@ -96,7 +96,7 @@ _mkdir(const char *path, uid_t u, gid_t g)
static Eina_Bool
_store_mount_verify(const char *mnt)
{
char *tmnt, *p;
char *tmnt, *p, *pp;
const char *s;
struct stat st;
@ -133,6 +133,10 @@ _store_mount_verify(const char *mnt)
p = strchr(p + 1, '/');
if (!p) goto malformed;
*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;
*p = '/';