Reactos

[KERNEL32] Reformat K32CreateDBMonMutex().

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