Code cleanup

This commit is contained in:
Pierre Pronchery 2004-07-21 15:56:08 +00:00
parent bfc49c794a
commit f424be094f

View File

@ -149,12 +149,10 @@ static int _is_string_not_empty(char * string)
return *string == '\0' ? 0 : 1; return *string == '\0' ? 0 : 1;
} }
static int _file_rwx_g(mode_t g);
static int _is_file_rwx(char * pathname, mode_t u, mode_t g, mode_t o) static int _is_file_rwx(char * pathname, mode_t u, mode_t g, mode_t o)
{ {
struct stat st; struct stat st;
struct group * group;
struct passwd * passwd;
char ** p;
if(stat(pathname, &st) != 0) if(stat(pathname, &st) != 0)
return 0; return 0;
@ -163,12 +161,7 @@ static int _is_file_rwx(char * pathname, mode_t u, mode_t g, mode_t o)
return 1; return 1;
if((st.st_mode & g) != 0) if((st.st_mode & g) != 0)
{ {
if((passwd = getpwuid(geteuid())) == NULL) if(_file_rwx_g(st.st_gid) == 1)
return 0;
if((group = getgrgid(st.st_gid)) == NULL)
return 0;
for(p = group->gr_mem; *p != NULL; p++)
if(strcmp(passwd->pw_name, *p) == 0)
return 1; return 1;
if(geteuid() == st.st_uid) if(geteuid() == st.st_uid)
return 0; return 0;
@ -176,6 +169,22 @@ static int _is_file_rwx(char * pathname, mode_t u, mode_t g, mode_t o)
return (st.st_mode & o) != 0 ? 1 : 0; return (st.st_mode & o) != 0 ? 1 : 0;
} }
static int _file_rwx_g(gid_t gid)
{
struct passwd * passwd;
struct group * group;
char ** p;
if((passwd = getpwuid(geteuid())) == NULL)
return 0;
if((group = getgrgid(gid)) == NULL)
return 0;
for(p = group->gr_mem; *p != NULL; p++)
if(strcmp(passwd->pw_name, *p) == 0)
return 1;
return 0;
}
static int _is_file_readable(char * pathname) static int _is_file_readable(char * pathname)
{ {
return _is_file_rwx(pathname, S_IRUSR, S_IRGRP, S_IROTH); return _is_file_rwx(pathname, S_IRUSR, S_IRGRP, S_IROTH);