From cb1346097edab674eede603aac588b3bbf6569c0 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sun, 30 Dec 2007 20:34:37 +0000 Subject: [PATCH] Corrected superuser behavior of Sfile_lookup_permissions() --- libisoburn/trunk/test/xorriso.c | 18 +++++++++++++----- libisoburn/trunk/test/xorriso_timestamp.h | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libisoburn/trunk/test/xorriso.c b/libisoburn/trunk/test/xorriso.c index da0f00ed..c29641f1 100644 --- a/libisoburn/trunk/test/xorriso.c +++ b/libisoburn/trunk/test/xorriso.c @@ -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); } diff --git a/libisoburn/trunk/test/xorriso_timestamp.h b/libisoburn/trunk/test/xorriso_timestamp.h index 2dcf1499..9b8dc271 100644 --- a/libisoburn/trunk/test/xorriso_timestamp.h +++ b/libisoburn/trunk/test/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2007.12.30.190138" +#define Xorriso_timestamP "2007.12.30.203336"