From: Philippe E. <ph...@us...> - 2005-08-10 16:47:27
|
Update of /cvsroot/oprofile/oprofile/libutil++ In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27002/libutil++ Modified Files: file_manip.cpp file_manip.h Log Message: when copying a file we must try to preserve file attributes and owner else an admin can give inadvertently read access to binary a simple user has no right to read, this affected running oparchive with root right. Problem started in cvs the 2005-08-07 Index: file_manip.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libutil++/file_manip.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -u -p -d -r1.29 -r1.30 --- file_manip.cpp 7 Aug 2005 16:43:17 -0000 1.29 +++ file_manip.cpp 10 Aug 2005 16:47:17 -0000 1.30 @@ -51,6 +51,13 @@ bool copy_file(string const & source, st if (utime(destination.c_str(), &utim)) return false; + if (chmod(destination.c_str(), buf.st_mode & ~S_IFMT)) + return false; + + // ignore error here: a simple user can copy a root.root 744 file + // but can't chown the copied file to root. + chown(destination.c_str(), buf.st_uid, buf.st_gid); + return true; } Index: file_manip.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/libutil++/file_manip.h,v retrieving revision 1.24 retrieving revision 1.25 diff -u -p -d -r1.24 -r1.25 --- file_manip.h 7 Aug 2005 16:43:17 -0000 1.24 +++ file_manip.h 10 Aug 2005 16:47:17 -0000 1.25 @@ -17,12 +17,12 @@ /** - * copy_file - copy a file or subtree + * copy_file - copy a file. * @param source filename to copy from * @param destination filename to copy into * - * the last modification time of the source file is preserved, return true if - * copying successful + * the last modification time of the source file is preserved, file attribute + * and owner are preserved if possible. Return true if copying successful. */ bool copy_file(std::string const & source, std::string const & destination); |