Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: base/file_util_posix.cc

Issue 7718021: Add external extensions json source in proper mac location. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rev Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <fnmatch.h> 10 #include <fnmatch.h>
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 933
934 if (HANDLE_EINTR(close(infile)) < 0) 934 if (HANDLE_EINTR(close(infile)) < 0)
935 result = false; 935 result = false;
936 if (HANDLE_EINTR(close(outfile)) < 0) 936 if (HANDLE_EINTR(close(outfile)) < 0)
937 result = false; 937 result = false;
938 938
939 return result; 939 return result;
940 } 940 }
941 #endif // defined(OS_MACOSX) 941 #endif // defined(OS_MACOSX)
942 942
943 // Test that a path is owned by a specific user, and not writable
944 // by all users. This is useful for checking that a config file
945 // is administrator-controlled. All components of |path| after |base|
946 // are checked. Note that |base| is not checked, and |base| must be a
947 // parent of |path|.
Evan Martin 2011/08/24 22:38:53 These comments belong in the header.
Sam Kerner (Chrome) 2011/08/25 14:04:37 Done.
948 bool IsPathControlledByUser(const FilePath& base,
949 const FilePath& path,
950 uid_t owner_uid) {
951 if (path == base)
TVL 2011/08/25 14:07:28 do you need to sanity check that base is the prefi
Sam Kerner (Chrome) 2011/08/26 19:59:15 Sanity checks added. Unit test IsPathControlledBy
952 return true;
953
954
Evan Martin 2011/08/24 22:38:53 Is the double-newline here intentional?
Sam Kerner (Chrome) 2011/08/25 14:04:37 No. Removed.
955 if (!IsPathControlledByUser(base, path.DirName(), owner_uid))
TVL 2011/08/25 14:07:28 could this be done with a loop to avoid the recurs
Sam Kerner (Chrome) 2011/08/26 19:59:15 Done.
956 return false;
957
958 stat_wrapper_t stat_info;
959 if (CallStat(path.value().c_str(), &stat_info) != 0) {
960 LOG(ERROR) << "Failed to get information on path " << path.value();
Evan Martin 2011/08/24 22:38:53 Use PLOG() for functions like this that use errno
Sam Kerner (Chrome) 2011/08/25 14:04:37 Done.
961 return false;
962 }
963
964 if (stat_info.st_uid != owner_uid) {
965 LOG(ERROR) << "Path " << path.value()
966 << " is owned by the wrong user.";
967 return false;
968 }
969
970 if (stat_info.st_mode & S_IWOTH) {
971 LOG(ERROR) << "Path "<< path.value() << " is writable by any user.";
972 return false;
973 }
974
975 return true;
976 }
977
978 bool IsPathControlledByAdmin(const FilePath& path) {
979 const unsigned kRootUid = 0;
980 const FilePath kFileSystemRoot(FILE_PATH_LITERAL("/"));
Evan Martin 2011/08/24 22:38:53 Since this is in POSIX code, you can use "/" witho
Sam Kerner (Chrome) 2011/08/25 14:04:37 Done.
981 return IsPathControlledByUser(kFileSystemRoot, path, kRootUid);
982 }
983
943 } // namespace file_util 984 } // namespace file_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698