Corrected superuser behavior of Sfile_lookup_permissions()

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

View File

@ -345,32 +345,38 @@ int Sfile_type(char *filename, int flag)
int Sfile_lookup_permissions(char *fname, int *perms, mode_t *st_mode,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 */ /* return: <0 fatal error, 0= file nonexistent, 1=owner, 2=group, 3=other */
{ {
struct stat stbuf; struct stat stbuf;
int is_root;
*perms= 0; *perms= 0;
if(stat(fname,&stbuf)==-1) if(stat(fname,&stbuf)==-1)
return(0); return(0);
*st_mode= stbuf.st_mode; *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) if(stbuf.st_mode & S_IRUSR)
(*perms)|= 1; (*perms)|= 1;
if(stbuf.st_mode & S_IWUSR) if(stbuf.st_mode & S_IWUSR)
(*perms)|= 2; (*perms)|= 2;
if(stbuf.st_mode & S_IXUSR) if(stbuf.st_mode & S_IXUSR)
(*perms)|= 4; (*perms)|= 4;
if(!is_root)
return(1); return(1);
} }
/* group membership is a complicated thing */ /* 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) if(stbuf.st_mode & S_IRGRP)
(*perms)|= 1; (*perms)|= 1;
if(stbuf.st_mode & S_IWGRP) if(stbuf.st_mode & S_IWGRP)
(*perms)|= 2; (*perms)|= 2;
if(stbuf.st_mode & S_IXGRP) if(stbuf.st_mode & S_IXGRP)
(*perms)|= 4; (*perms)|= 4;
if(!is_root)
return(2); return(2);
} }
if(stbuf.st_mode & S_IROTH) if(stbuf.st_mode & S_IROTH)
@ -379,6 +385,8 @@ int Sfile_lookup_permissions(char *fname, int *perms, mode_t *st_mode,int flag)
(*perms)|= 2; (*perms)|= 2;
if(stbuf.st_mode & S_IXOTH) if(stbuf.st_mode & S_IXOTH)
(*perms)|= 4; (*perms)|= 4;
if(is_root)
return(1);
return(3); return(3);
} }

View File

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