mirror of
https://github.com/samba-team/samba.git
synced 2025-03-10 12:58:35 +03:00
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>
This commit is contained in:
parent
374b2cfde7
commit
8eae8d28bc
@ -622,6 +622,15 @@ _PUBLIC_ time_t file_modtime(const char *fname);
|
|||||||
**/
|
**/
|
||||||
_PUBLIC_ bool directory_exist(const char *dname);
|
_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.
|
* Try to create the specified directory if it didn't exist.
|
||||||
*
|
*
|
||||||
|
@ -121,6 +121,50 @@ _PUBLIC_ time_t file_modtime(const char *fname)
|
|||||||
return(st.st_mtime);
|
return(st.st_mtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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.
|
Check if a directory exists.
|
||||||
**/
|
**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user