tangled
alpha
login
or
join now
huwcampbell.com
/
reactos
0
fork
atom
Reactos
0
fork
atom
overview
issues
pulls
pipelines
[KERNEL32] Reformat K32CreateDBMonMutex().
Hermès Bélusca-Maïto
3 years ago
9f938ea3
75da7ad2
+87
-122
1 changed file
expand all
collapse all
unified
split
dll
win32
kernel32
client
debugger.c
+87
-122
dll/win32/kernel32/client/debugger.c
···
33
33
34
34
/* PRIVATE FUNCTIONS *********************************************************/
35
35
36
36
-
static
37
37
-
HANDLE
38
38
-
K32CreateDBMonMutex(void)
36
36
+
static HANDLE
37
37
+
K32CreateDBMonMutex(VOID)
39
38
{
40
39
static SID_IDENTIFIER_AUTHORITY siaNTAuth = {SECURITY_NT_AUTHORITY};
41
40
static SID_IDENTIFIER_AUTHORITY siaWorldAuth = {SECURITY_WORLD_SID_AUTHORITY};
42
41
HANDLE hMutex;
42
42
+
NTSTATUS Status;
43
43
44
44
/* SIDs to be used in the DACL */
45
45
PSID psidSystem = NULL;
46
46
PSID psidAdministrators = NULL;
47
47
PSID psidEveryone = NULL;
48
48
49
49
-
/* buffer for the DACL */
49
49
+
/* Buffer for the DACL */
50
50
PVOID pDaclBuf = NULL;
51
51
52
52
-
/* minimum size of the DACL: an ACL descriptor and three ACCESS_ALLOWED_ACE
53
53
-
headers. We'll add the size of SIDs when we'll know it
54
54
-
*/
52
52
+
/* Minimum size of the DACL: an ACL descriptor and three ACCESS_ALLOWED_ACE
53
53
+
* headers. We will add the size of SIDs when they are known. */
55
54
SIZE_T nDaclBufSize =
56
56
-
sizeof(ACL) + (sizeof(ACCESS_ALLOWED_ACE) -
57
57
-
sizeof(((ACCESS_ALLOWED_ACE*)0)->SidStart)) * 3;
55
55
+
sizeof(ACL) + 3 * FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart);
58
56
59
59
-
/* security descriptor of the mutex */
57
57
+
/* Security descriptor and attributes of the mutex */
60
58
SECURITY_DESCRIPTOR sdMutexSecurity;
61
61
-
62
62
-
/* attributes of the mutex object we'll create */
63
59
SECURITY_ATTRIBUTES saMutexAttribs = {sizeof(saMutexAttribs),
64
60
&sdMutexSecurity,
65
61
TRUE};
66
62
67
67
-
NTSTATUS nErrCode;
68
68
-
69
69
-
/* first, try to open the mutex */
70
70
-
hMutex = OpenMutexW (SYNCHRONIZE | READ_CONTROL | MUTANT_QUERY_STATE,
71
71
-
TRUE,
72
72
-
L"DBWinMutex");
73
73
-
63
63
+
/* Try to open the mutex */
64
64
+
hMutex = OpenMutexW(SYNCHRONIZE | READ_CONTROL | MUTANT_QUERY_STATE,
65
65
+
TRUE,
66
66
+
L"DBWinMutex");
74
67
if (hMutex != NULL)
75
68
{
76
76
-
/* success */
69
69
+
/* Success */
77
70
return hMutex;
78
71
}
79
79
-
/* error other than the mutex not being found */
72
72
+
/* Error other than the mutex not being found */
80
73
else if (GetLastError() != ERROR_FILE_NOT_FOUND)
81
74
{
82
82
-
/* failure */
75
75
+
/* Failure */
83
76
return NULL;
84
77
}
85
78
86
86
-
/* if the mutex doesn't exist, create it */
79
79
+
/* If the mutex does not exist, set up its security, then create it */
87
80
88
88
-
/* first, set up the mutex security */
89
89
-
/* allocate the NT AUTHORITY\SYSTEM SID */
90
90
-
nErrCode = RtlAllocateAndInitializeSid(&siaNTAuth,
91
91
-
1,
92
92
-
SECURITY_LOCAL_SYSTEM_RID,
93
93
-
0,
94
94
-
0,
95
95
-
0,
96
96
-
0,
97
97
-
0,
98
98
-
0,
99
99
-
0,
100
100
-
&psidSystem);
81
81
+
/* Allocate the NT AUTHORITY\SYSTEM SID */
82
82
+
Status = RtlAllocateAndInitializeSid(&siaNTAuth,
83
83
+
1,
84
84
+
SECURITY_LOCAL_SYSTEM_RID,
85
85
+
0, 0, 0, 0, 0, 0, 0,
86
86
+
&psidSystem);
87
87
+
if (!NT_SUCCESS(Status))
88
88
+
goto Cleanup;
101
89
102
102
-
/* failure */
103
103
-
if (!NT_SUCCESS(nErrCode)) goto l_Cleanup;
104
104
-
105
105
-
/* allocate the BUILTIN\Administrators SID */
106
106
-
nErrCode = RtlAllocateAndInitializeSid(&siaNTAuth,
107
107
-
2,
108
108
-
SECURITY_BUILTIN_DOMAIN_RID,
109
109
-
DOMAIN_ALIAS_RID_ADMINS,
110
110
-
0,
111
111
-
0,
112
112
-
0,
113
113
-
0,
114
114
-
0,
115
115
-
0,
116
116
-
&psidAdministrators);
90
90
+
/* Allocate the BUILTIN\Administrators SID */
91
91
+
Status = RtlAllocateAndInitializeSid(&siaNTAuth,
92
92
+
2,
93
93
+
SECURITY_BUILTIN_DOMAIN_RID,
94
94
+
DOMAIN_ALIAS_RID_ADMINS,
95
95
+
0, 0, 0, 0, 0, 0,
96
96
+
&psidAdministrators);
97
97
+
if (!NT_SUCCESS(Status))
98
98
+
goto Cleanup;
117
99
118
118
-
/* failure */
119
119
-
if (!NT_SUCCESS(nErrCode)) goto l_Cleanup;
100
100
+
/* Allocate the Everyone SID */
101
101
+
Status = RtlAllocateAndInitializeSid(&siaWorldAuth,
102
102
+
1,
103
103
+
SECURITY_WORLD_RID,
104
104
+
0, 0, 0, 0, 0, 0, 0,
105
105
+
&psidEveryone);
106
106
+
if (!NT_SUCCESS(Status))
107
107
+
goto Cleanup;
120
108
121
121
-
/* allocate the Everyone SID */
122
122
-
nErrCode = RtlAllocateAndInitializeSid(&siaWorldAuth,
123
123
-
1,
124
124
-
0,
125
125
-
0,
126
126
-
0,
127
127
-
0,
128
128
-
0,
129
129
-
0,
130
130
-
0,
131
131
-
0,
132
132
-
&psidEveryone);
133
133
-
134
134
-
/* failure */
135
135
-
if (!NT_SUCCESS(nErrCode)) goto l_Cleanup;
136
136
-
137
137
-
/* allocate space for the SIDs too */
109
109
+
/* Allocate space for the SIDs too */
138
110
nDaclBufSize += RtlLengthSid(psidSystem);
139
111
nDaclBufSize += RtlLengthSid(psidAdministrators);
140
112
nDaclBufSize += RtlLengthSid(psidEveryone);
141
113
142
142
-
/* allocate the buffer for the DACL */
114
114
+
/* Allocate the buffer for the DACL */
143
115
pDaclBuf = GlobalAlloc(GMEM_FIXED, nDaclBufSize);
144
144
-
145
145
-
/* failure */
146
146
-
if (pDaclBuf == NULL) goto l_Cleanup;
147
147
-
148
148
-
/* create the DACL */
149
149
-
nErrCode = RtlCreateAcl(pDaclBuf, nDaclBufSize, ACL_REVISION);
150
150
-
151
151
-
/* failure */
152
152
-
if (!NT_SUCCESS(nErrCode)) goto l_Cleanup;
153
153
-
154
154
-
/* grant the minimum required access to Everyone */
155
155
-
nErrCode = RtlAddAccessAllowedAce(pDaclBuf,
156
156
-
ACL_REVISION,
157
157
-
SYNCHRONIZE |
158
158
-
READ_CONTROL |
159
159
-
MUTANT_QUERY_STATE,
160
160
-
psidEveryone);
161
161
-
162
162
-
/* failure */
163
163
-
if (!NT_SUCCESS(nErrCode)) goto l_Cleanup;
164
164
-
165
165
-
/* grant full access to BUILTIN\Administrators */
166
166
-
nErrCode = RtlAddAccessAllowedAce(pDaclBuf,
167
167
-
ACL_REVISION,
168
168
-
MUTANT_ALL_ACCESS,
169
169
-
psidAdministrators);
170
170
-
171
171
-
/* failure */
172
172
-
if (!NT_SUCCESS(nErrCode)) goto l_Cleanup;
116
116
+
if (pDaclBuf == NULL)
117
117
+
goto Cleanup;
173
118
174
174
-
/* grant full access to NT AUTHORITY\SYSTEM */
175
175
-
nErrCode = RtlAddAccessAllowedAce(pDaclBuf,
176
176
-
ACL_REVISION,
177
177
-
MUTANT_ALL_ACCESS,
178
178
-
psidSystem);
119
119
+
/* Create the DACL */
120
120
+
Status = RtlCreateAcl(pDaclBuf, nDaclBufSize, ACL_REVISION);
121
121
+
if (!NT_SUCCESS(Status))
122
122
+
goto Cleanup;
179
123
180
180
-
/* failure */
181
181
-
if (!NT_SUCCESS(nErrCode)) goto l_Cleanup;
124
124
+
/* Grant the minimum required access to Everyone */
125
125
+
Status = RtlAddAccessAllowedAce(pDaclBuf,
126
126
+
ACL_REVISION,
127
127
+
SYNCHRONIZE |
128
128
+
READ_CONTROL |
129
129
+
MUTANT_QUERY_STATE,
130
130
+
psidEveryone);
131
131
+
if (!NT_SUCCESS(Status))
132
132
+
goto Cleanup;
182
133
183
183
-
/* create the security descriptor */
184
184
-
nErrCode = RtlCreateSecurityDescriptor(&sdMutexSecurity,
185
185
-
SECURITY_DESCRIPTOR_REVISION);
134
134
+
/* Grant full access to BUILTIN\Administrators */
135
135
+
Status = RtlAddAccessAllowedAce(pDaclBuf,
136
136
+
ACL_REVISION,
137
137
+
MUTANT_ALL_ACCESS,
138
138
+
psidAdministrators);
139
139
+
if (!NT_SUCCESS(Status))
140
140
+
goto Cleanup;
186
141
187
187
-
/* failure */
188
188
-
if (!NT_SUCCESS(nErrCode)) goto l_Cleanup;
142
142
+
/* Grant full access to NT AUTHORITY\SYSTEM */
143
143
+
Status = RtlAddAccessAllowedAce(pDaclBuf,
144
144
+
ACL_REVISION,
145
145
+
MUTANT_ALL_ACCESS,
146
146
+
psidSystem);
147
147
+
if (!NT_SUCCESS(Status))
148
148
+
goto Cleanup;
189
149
190
190
-
/* set the descriptor's DACL to the ACL we created */
191
191
-
nErrCode = RtlSetDaclSecurityDescriptor(&sdMutexSecurity,
192
192
-
TRUE,
193
193
-
pDaclBuf,
194
194
-
FALSE);
150
150
+
/* Create the security descriptor */
151
151
+
Status = RtlCreateSecurityDescriptor(&sdMutexSecurity,
152
152
+
SECURITY_DESCRIPTOR_REVISION);
153
153
+
if (!NT_SUCCESS(Status))
154
154
+
goto Cleanup;
195
155
196
196
-
/* failure */
197
197
-
if (!NT_SUCCESS(nErrCode)) goto l_Cleanup;
156
156
+
/* Set the descriptor's DACL to the created ACL */
157
157
+
Status = RtlSetDaclSecurityDescriptor(&sdMutexSecurity,
158
158
+
TRUE,
159
159
+
pDaclBuf,
160
160
+
FALSE);
161
161
+
if (!NT_SUCCESS(Status))
162
162
+
goto Cleanup;
198
163
199
199
-
/* create the mutex */
164
164
+
/* Create the mutex */
200
165
hMutex = CreateMutexW(&saMutexAttribs, FALSE, L"DBWinMutex");
201
166
202
202
-
l_Cleanup:
203
203
-
/* free the buffers */
167
167
+
Cleanup:
168
168
+
/* Free the buffers */
204
169
if (pDaclBuf) GlobalFree(pDaclBuf);
205
170
if (psidEveryone) RtlFreeSid(psidEveryone);
206
171
if (psidAdministrators) RtlFreeSid(psidAdministrators);