Corrected superuser behavior of Sfile_lookup_permissions()

This commit is contained in:
Thomas Schmitt 2007-12-30 20:34:37 +00:00
parent 481d191986
commit cb1346097e
2 changed files with 14 additions and 6 deletions

View File

@ -345,33 +345,39 @@ int Sfile_type(char *filename, int flag)
int Sfile_lookup_permissions(char *fname, int *perms, mode_t *st_mode,int flag)
/* perms: bit0= r , bit1= w , bit2= x */
/* @param perms bit0= r , bit1= w , bit2= x */
/* return: <0 fatal error, 0= file nonexistent, 1=owner, 2=group, 3=other */
{
struct stat stbuf;
int is_root;
*perms= 0;
if(stat(fname,&stbuf)==-1)
return(0);
*st_mode= stbuf.st_mode;
if(geteuid()==stbuf.st_uid || geteuid()==0) {
is_root= (geteuid()==0);
if(is_root) /* root can always read and write */
*perms= 3;
if(is_root || geteuid()==stbuf.st_uid) {
if(stbuf.st_mode & S_IRUSR)
(*perms)|= 1;
if(stbuf.st_mode & S_IWUSR)
(*perms)|= 2;
if(stbuf.st_mode & S_IXUSR)
(*perms)|= 4;
return(1);
if(!is_root)
return(1);
}
/* group membership is a complicated thing */
if(Sfile_being_group_member(&stbuf,0)>0) {
if(is_root || Sfile_being_group_member(&stbuf,0)>0) {
if(stbuf.st_mode & S_IRGRP)
(*perms)|= 1;
if(stbuf.st_mode & S_IWGRP)
(*perms)|= 2;
if(stbuf.st_mode & S_IXGRP)
(*perms)|= 4;
return(2);
if(!is_root)
return(2);
}
if(stbuf.st_mode & S_IROTH)
(*perms)|= 1;
@ -379,6 +385,8 @@ int Sfile_lookup_permissions(char *fname, int *perms, mode_t *st_mode,int flag)
(*perms)|= 2;
if(stbuf.st_mode & S_IXOTH)
(*perms)|= 4;
if(is_root)
return(1);
return(3);
}

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.12.30.190138"
#define Xorriso_timestamP "2007.12.30.203336"