| 72 | */ |
| 73 | |
| 74 | int my_security_attr_create(SECURITY_ATTRIBUTES **psa, const char **perror, |
| 75 | DWORD owner_rights, DWORD everyone_rights) |
| 76 | { |
| 77 | /* Top-level SID authority */ |
| 78 | SID_IDENTIFIER_AUTHORITY world_auth= SECURITY_WORLD_SID_AUTHORITY; |
| 79 | PSID everyone_sid= 0; |
| 80 | HANDLE htoken= 0; |
| 81 | SECURITY_ATTRIBUTES *sa= 0; |
| 82 | PACL dacl= 0; |
| 83 | DWORD owner_token_length, dacl_length; |
| 84 | SECURITY_DESCRIPTOR *sd; |
| 85 | PTOKEN_USER owner_token; |
| 86 | PSID owner_sid; |
| 87 | My_security_attr *attr; |
| 88 | |
| 89 | if (! is_nt()) |
| 90 | { |
| 91 | *psa= 0; |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | Get SID of Everyone group. Easier to retrieve all SIDs each time |
| 97 | this function is called than worry about thread safety. |
| 98 | */ |
| 99 | if (! AllocateAndInitializeSid(&world_auth, 1, SECURITY_WORLD_RID, |
| 100 | 0, 0, 0, 0, 0, 0, 0, &everyone_sid)) |
| 101 | { |
| 102 | *perror= "Failed to retrieve the SID of Everyone group"; |
| 103 | goto error; |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | Get SID of the owner. Using GetSecurityInfo this task can be done |
| 108 | in just one call instead of five, but GetSecurityInfo declared in |
| 109 | aclapi.h, so I hesitate to use it. |
| 110 | SIC: OpenThreadToken works only if there is an active impersonation |
| 111 | token, hence OpenProcessToken is used. |
| 112 | */ |
| 113 | if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &htoken)) |
| 114 | { |
| 115 | *perror= "Failed to retrieve thread access token"; |
| 116 | goto error; |
| 117 | } |
| 118 | GetTokenInformation(htoken, TokenUser, 0, 0, &owner_token_length); |
| 119 | |
| 120 | if (! my_multi_malloc(MYF(MY_WME), |
| 121 | &sa, ALIGN_SIZE(sizeof(SECURITY_ATTRIBUTES)) + |
| 122 | sizeof(My_security_attr), |
| 123 | &sd, sizeof(SECURITY_DESCRIPTOR), |
| 124 | &owner_token, owner_token_length, |
| 125 | 0)) |
| 126 | { |
| 127 | *perror= "Failed to allocate memory for SECURITY_ATTRIBUTES"; |
| 128 | goto error; |
| 129 | } |
| 130 | memset(owner_token, 0, owner_token_length); |
| 131 | if (! GetTokenInformation(htoken, TokenUser, owner_token, |
nothing calls this directly
no test coverage detected