Created
January 24, 2024 22:18
-
-
Save matu3ba/36d43da504a05927cdf0570ff103254c to your computer and use it in GitHub Desktop.
Minimal ACL. but ugly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// zig run acl_min.zig | |
pub const DWORD = c_ulong; | |
pub const HANDLE = ?*anyopaque; | |
pub const PVOID = ?*anyopaque; | |
pub const PSID = PVOID; | |
pub const PSECURITY_DESCRIPTOR = PVOID; | |
pub const enum__SE_OBJECT_TYPE = c_uint; | |
pub const SE_OBJECT_TYPE = enum__SE_OBJECT_TYPE; | |
pub const wchar_t = c_ushort; | |
pub const SE_FILE_OBJECT: c_int = 1; | |
pub const WCHAR = wchar_t; | |
pub const LPCWSTR = [*c]const WCHAR; | |
pub const BYTE = u8; | |
pub const WORD = c_ushort; | |
pub const struct__ACL = extern struct { | |
AclRevision: BYTE = @import("std").mem.zeroes(BYTE), | |
Sbz1: BYTE = @import("std").mem.zeroes(BYTE), | |
AclSize: WORD = @import("std").mem.zeroes(WORD), | |
AceCount: WORD = @import("std").mem.zeroes(WORD), | |
Sbz2: WORD = @import("std").mem.zeroes(WORD), | |
}; | |
pub const ACL = struct__ACL; | |
pub const PACL = [*c]ACL; | |
pub const LPVOID = ?*anyopaque; | |
pub const WINBOOL = c_int; | |
pub const SECURITY_INFORMATION = DWORD; | |
pub const struct__SECURITY_ATTRIBUTES = extern struct { | |
nLength: DWORD = @import("std").mem.zeroes(DWORD), | |
lpSecurityDescriptor: LPVOID = @import("std").mem.zeroes(LPVOID), | |
bInheritHandle: WINBOOL = @import("std").mem.zeroes(WINBOOL), | |
}; | |
pub const LPSECURITY_ATTRIBUTES = [*c]struct__SECURITY_ATTRIBUTES; | |
pub extern fn GetLastError() DWORD; | |
pub extern fn GetSecurityInfo(handle: HANDLE, ObjectType: SE_OBJECT_TYPE, SecurityInfo: SECURITY_INFORMATION, ppsidOwner: [*c]PSID, ppsidGroup: [*c]PSID, ppDacl: [*c]PACL, ppSacl: [*c]PACL, ppSecurityDescriptor: [*c]PSECURITY_DESCRIPTOR) DWORD; | |
const std = @import("std"); | |
pub fn main() !void { | |
var st: DWORD = 0; | |
var pSidOwner: PSID = null; | |
var pSD: PSECURITY_DESCRIPTOR = null; | |
const tmpDir = std.testing.tmpDir; | |
var tmp = tmpDir(.{}); | |
defer tmp.cleanup(); | |
const file_user = try tmp.dir.createFile("file_user", .{ .read = true }); | |
defer file_user.close(); | |
var file_user_h: ?std.fs.File.Handle = null; | |
file_user_h = file_user.handle; | |
st = GetSecurityInfo(file_user_h, @as(c_uint, @bitCast(SE_FILE_OBJECT)), @as(SECURITY_INFORMATION, @bitCast(@as(c_long, 1))), &pSidOwner, null, null, null, &pSD); | |
if (st != @as(DWORD, @bitCast(@as(c_long, 0)))) { | |
var dwErrorCode: DWORD = 0; | |
dwErrorCode = GetLastError(); | |
std.debug.print("GetSecurityInfo error = {d}\n", .{ dwErrorCode }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment