mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 14:07:59 +00:00
Added isc_fsaccess_changeowner function similar to the code to set file access attributes
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: fsaccess.c,v 1.10 2001/11/13 05:07:57 mayer Exp $ */
|
||||
/* $Id: fsaccess.c,v 1.11 2002/02/02 01:01:15 mayer Exp $ */
|
||||
|
||||
/*
|
||||
* Note that Win32 does not have the concept of files having access
|
||||
@@ -29,6 +29,8 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <aclapi.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <io.h>
|
||||
@@ -320,3 +322,54 @@ isc_fsaccess_set(const char *path, isc_fsaccess_t access) {
|
||||
else
|
||||
return (FAT_fsaccess_set(path, access));
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_fsaccess_changeowner(const char *filename, const char *user) {
|
||||
SECURITY_DESCRIPTOR psd;
|
||||
BYTE sidBuffer[500];
|
||||
BYTE groupBuffer[500];
|
||||
PSID psid=(PSID) &sidBuffer;
|
||||
DWORD sidBufferSize = sizeof(sidBuffer);
|
||||
char domainBuffer[100];
|
||||
DWORD domainBufferSize = sizeof(domainBuffer);
|
||||
SID_NAME_USE snu;
|
||||
PSID pSidGroup = (PSID) &groupBuffer;
|
||||
DWORD groupBufferSize = sizeof(groupBuffer);
|
||||
|
||||
|
||||
/*
|
||||
* Determine if this is a FAT or NTFS disk and
|
||||
* call the appropriate function to set the ownership
|
||||
* FAT disks do not have ownership attributes so it's
|
||||
* a noop.
|
||||
*/
|
||||
if (is_ntfs(filename) == FALSE)
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
if (!InitializeSecurityDescriptor(&psd, SECURITY_DESCRIPTOR_REVISION))
|
||||
return (ISC_R_NOPERM);
|
||||
|
||||
if (!LookupAccountName(0, user, psid, &sidBufferSize, domainBuffer,
|
||||
&domainBufferSize, &snu))
|
||||
return (ISC_R_NOPERM);
|
||||
|
||||
/* Make sure administrators can get to it */
|
||||
domainBufferSize = sizeof(domainBuffer);
|
||||
if (!LookupAccountName(0, "Administrators", pSidGroup,
|
||||
&groupBufferSize, domainBuffer, &domainBufferSize, &snu))
|
||||
return (ISC_R_NOPERM);
|
||||
|
||||
if (!SetSecurityDescriptorOwner(&psd, psid, FALSE))
|
||||
return (ISC_R_NOPERM);
|
||||
|
||||
if (!SetSecurityDescriptorGroup(&psd, pSidGroup, FALSE))
|
||||
return (ISC_R_NOPERM);
|
||||
|
||||
if (!SetFileSecurity(filename,
|
||||
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION,
|
||||
&psd))
|
||||
return (ISC_R_NOPERM);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user