]> wimlib.net Git - wimlib/blob - programs/imagex-win32.c
mount_image.c: add fallback definitions of RENAME_* constants
[wimlib] / programs / imagex-win32.c
1 /* Windows-specific code for wimlib-imagex.  */
2
3 #ifndef _WIN32
4 #  error "This file contains Windows code"
5 #endif
6
7 #include "imagex-win32.h"
8 #include <fcntl.h>
9 #include <io.h>
10 #include <stdio.h>
11 #include <windows.h>
12
13 /* Set a file descriptor to binary mode.  */
14 void set_fd_to_binary_mode(int fd)
15 {
16         _setmode(fd, _O_BINARY);
17 }
18
19 #include <sddl.h>
20
21 static wchar_t *
22 get_security_descriptor_string(PSECURITY_DESCRIPTOR desc)
23 {
24         wchar_t *str = NULL;
25         /* 52 characters!!!  */
26         ConvertSecurityDescriptorToStringSecurityDescriptorW(
27                         desc,
28                         SDDL_REVISION_1,
29                         OWNER_SECURITY_INFORMATION |
30                                 GROUP_SECURITY_INFORMATION |
31                                 DACL_SECURITY_INFORMATION |
32                                 SACL_SECURITY_INFORMATION,
33                         &str,
34                         NULL);
35         return str;
36 }
37
38 void
39 win32_print_security_descriptor(const uint8_t *sd, size_t size)
40 {
41         wchar_t *str;
42         const wchar_t *printstr;
43
44         /* 'size' is ignored here due to the crappy Windows APIs.  Oh well, this
45          * is just for debugging anyway.  */
46         str = get_security_descriptor_string((PSECURITY_DESCRIPTOR)sd);
47         if (str)
48                 printstr = str;
49         else
50                 printstr = L"(invalid)";
51
52         wprintf(L"Security Descriptor = %ls\n", printstr);
53
54         LocalFree(str);
55 }