summaryrefslogtreecommitdiffstats
path: root/lib/util
diff options
context:
space:
mode:
authorBjörn Baumbach <bb@sernet.de>2013-10-29 17:43:17 +0100
committerKarolin Seeger <kseeger@samba.org>2013-11-11 11:14:36 +0100
commit8eae8d28bce2c3f6a323d3dc48ed10c2e6bb1ba5 (patch)
tree31adc5132c009c0ae2f3b935e59287492a01b922 /lib/util
parent374b2cfde74e0c61f4b2da724b30d0e430596092 (diff)
downloadsamba-8eae8d28bce2c3f6a323d3dc48ed10c2e6bb1ba5.tar.gz
samba-8eae8d28bce2c3f6a323d3dc48ed10c2e6bb1ba5.tar.xz
samba-8eae8d28bce2c3f6a323d3dc48ed10c2e6bb1ba5.zip
CVE-2013-4476: lib-util: add file_check_permissions()
Bug: https://bugzilla.samba.org/show_bug.cgi?id=10234 Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/samba_util.h9
-rw-r--r--lib/util/util.c44
2 files changed, 53 insertions, 0 deletions
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index 89aa9aa7d8..f98cf6066a 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -623,6 +623,15 @@ _PUBLIC_ time_t file_modtime(const char *fname);
_PUBLIC_ bool directory_exist(const char *dname);
/**
+ Check file permissions.
+**/
+struct stat;
+_PUBLIC_ bool file_check_permissions(const char *fname,
+ uid_t uid,
+ mode_t file_perms,
+ struct stat *pst);
+
+/**
* Try to create the specified directory if it didn't exist.
*
* @retval true if the directory already existed and has the right permissions
diff --git a/lib/util/util.c b/lib/util/util.c
index f0ed7f645b..3e9047ca91 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -122,6 +122,50 @@ _PUBLIC_ time_t file_modtime(const char *fname)
}
/**
+ Check file permissions.
+**/
+
+_PUBLIC_ bool file_check_permissions(const char *fname,
+ uid_t uid,
+ mode_t file_perms,
+ struct stat *pst)
+{
+ int ret;
+ struct stat st;
+
+ if (pst == NULL) {
+ pst = &st;
+ }
+
+ ZERO_STRUCTP(pst);
+
+ ret = stat(fname, pst);
+ if (ret != 0) {
+ DEBUG(0, ("stat failed on file '%s': %s\n",
+ fname, strerror(errno)));
+ return false;
+ }
+
+ if (pst->st_uid != uid && !uwrap_enabled()) {
+ DEBUG(0, ("invalid ownership of file '%s': "
+ "owned by uid %u, should be %u\n",
+ fname, (unsigned int)pst->st_uid,
+ (unsigned int)uid));
+ return false;
+ }
+
+ if ((pst->st_mode & 0777) != file_perms) {
+ DEBUG(0, ("invalid permissions on file "
+ "'%s': has 0%o should be 0%o\n", fname,
+ (unsigned int)(pst->st_mode & 0777),
+ (unsigned int)file_perms));
+ return false;
+ }
+
+ return true;
+}
+
+/**
Check if a directory exists.
**/