[9992] | 1 | /* $Id: sec.c,v 1.5 2003-04-08 12:47:07 sandervl Exp $ */
|
---|
[9684] | 2 |
|
---|
| 3 | /*
|
---|
| 4 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 5 | * Win32 NT Runtime / NTDLL for OS/2
|
---|
| 6 | *
|
---|
| 7 | * Copyright 1998 original WINE Author
|
---|
| 8 | * Copyright 1998, 1999 Patrick Haller (phaller@gmx.net)
|
---|
| 9 | *
|
---|
| 10 | * Security functions
|
---|
| 11 | *
|
---|
| 12 | * Copyright 1996-1998 Marcus Meissner
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | #include <windows.h>
|
---|
| 16 | #include <stdlib.h>
|
---|
| 17 | #include <string.h>
|
---|
[9986] | 18 |
|
---|
[9684] | 19 | #include <time.h>
|
---|
| 20 | #include <ctype.h>
|
---|
| 21 | #include <math.h>
|
---|
| 22 | #include "ntdll.h"
|
---|
| 23 | #include <debugtools.h>
|
---|
| 24 |
|
---|
| 25 | ODINDEBUGCHANNEL(NTDLL-SEC)
|
---|
| 26 |
|
---|
| 27 | /*
|
---|
| 28 | * SID FUNCTIONS
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | /******************************************************************************
|
---|
| 32 | * RtlAllocateAndInitializeSid [NTDLL.265]
|
---|
| 33 | *
|
---|
| 34 | */
|
---|
| 35 | BOOLEAN WINAPI RtlAllocateAndInitializeSid ( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
|
---|
| 36 | BYTE nSubAuthorityCount,
|
---|
| 37 | DWORD nSubAuthority0,
|
---|
| 38 | DWORD nSubAuthority1,
|
---|
| 39 | DWORD nSubAuthority2,
|
---|
| 40 | DWORD nSubAuthority3,
|
---|
| 41 | DWORD nSubAuthority4,
|
---|
| 42 | DWORD nSubAuthority5,
|
---|
| 43 | DWORD nSubAuthority6,
|
---|
| 44 | DWORD nSubAuthority7,
|
---|
| 45 | PSID *pSid)
|
---|
| 46 | {
|
---|
| 47 | dprintf(("NTDLL: RtlAllocateAndInitializeSid(%08xh,%08xh,%08xh,"
|
---|
| 48 | "%08xh,%08xh,%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)",
|
---|
| 49 | pIdentifierAuthority,
|
---|
| 50 | nSubAuthorityCount,
|
---|
| 51 | nSubAuthority0,
|
---|
| 52 | nSubAuthority1,
|
---|
| 53 | nSubAuthority2,
|
---|
| 54 | nSubAuthority3,
|
---|
| 55 | nSubAuthority4,
|
---|
| 56 | nSubAuthority5,
|
---|
| 57 | nSubAuthority6,
|
---|
| 58 | nSubAuthority7,
|
---|
| 59 | pSid));
|
---|
| 60 |
|
---|
| 61 | *pSid = (PSID)Heap_Alloc(sizeof(SID)+nSubAuthorityCount*sizeof(DWORD));
|
---|
| 62 | if(*pSid == NULL) {
|
---|
| 63 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
| 64 | return FALSE;
|
---|
| 65 | }
|
---|
| 66 | (*pSid)->Revision = SID_REVISION;
|
---|
| 67 | (*pSid)->SubAuthorityCount = nSubAuthorityCount;
|
---|
| 68 |
|
---|
| 69 | if (nSubAuthorityCount > 0)
|
---|
| 70 | (*pSid)->SubAuthority[0] = nSubAuthority0;
|
---|
| 71 | if (nSubAuthorityCount > 1)
|
---|
| 72 | (*pSid)->SubAuthority[1] = nSubAuthority1;
|
---|
| 73 | if (nSubAuthorityCount > 2)
|
---|
| 74 | (*pSid)->SubAuthority[2] = nSubAuthority2;
|
---|
| 75 | if (nSubAuthorityCount > 3)
|
---|
| 76 | (*pSid)->SubAuthority[3] = nSubAuthority3;
|
---|
| 77 | if (nSubAuthorityCount > 4)
|
---|
| 78 | (*pSid)->SubAuthority[4] = nSubAuthority4;
|
---|
| 79 | if (nSubAuthorityCount > 5)
|
---|
| 80 | (*pSid)->SubAuthority[5] = nSubAuthority5;
|
---|
| 81 | if (nSubAuthorityCount > 6)
|
---|
| 82 | (*pSid)->SubAuthority[6] = nSubAuthority6;
|
---|
| 83 | if (nSubAuthorityCount > 7)
|
---|
| 84 | (*pSid)->SubAuthority[7] = nSubAuthority7;
|
---|
| 85 |
|
---|
| 86 | if(pIdentifierAuthority)
|
---|
| 87 | memcpy((PVOID)&(*pSid)->IdentifierAuthority, (PVOID)pIdentifierAuthority, sizeof(SID_IDENTIFIER_AUTHORITY));
|
---|
| 88 | return TRUE;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | /******************************************************************************
|
---|
| 93 | * RtlEqualSid [NTDLL.352]
|
---|
| 94 | *
|
---|
| 95 | */
|
---|
| 96 | BOOL WINAPI RtlEqualSid(PSID pSid1, PSID pSid2)
|
---|
| 97 | {
|
---|
| 98 | dprintf(("NTDLL: RtlEqualSid(%08x, %08x)",
|
---|
| 99 | pSid1,
|
---|
| 100 | pSid2));
|
---|
| 101 |
|
---|
| 102 | if (!RtlValidSid(pSid1) || !RtlValidSid(pSid2))
|
---|
| 103 | return FALSE;
|
---|
| 104 |
|
---|
| 105 | if (*RtlSubAuthorityCountSid(pSid1) != *RtlSubAuthorityCountSid(pSid2))
|
---|
| 106 | return FALSE;
|
---|
| 107 |
|
---|
| 108 | if (memcmp(pSid1, pSid2, RtlLengthSid(pSid1)) != 0)
|
---|
| 109 | return FALSE;
|
---|
| 110 |
|
---|
| 111 | return TRUE;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | /******************************************************************************
|
---|
| 116 | * RtlEqualPrefixSid [NTDLL.351]
|
---|
| 117 | */
|
---|
| 118 | BOOL WINAPI RtlEqualPrefixSid (PSID pSid1, PSID pSid2)
|
---|
| 119 | {
|
---|
| 120 | if (!RtlValidSid(pSid1) || !RtlValidSid(pSid2))
|
---|
| 121 | return FALSE;
|
---|
| 122 |
|
---|
| 123 | if (*RtlSubAuthorityCountSid(pSid1) != *RtlSubAuthorityCountSid(pSid2))
|
---|
| 124 | return FALSE;
|
---|
| 125 |
|
---|
| 126 | if (memcmp(pSid1, pSid2, RtlLengthRequiredSid(pSid1->SubAuthorityCount - 1)) != 0)
|
---|
| 127 | return FALSE;
|
---|
| 128 |
|
---|
| 129 | return TRUE;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | /******************************************************************************
|
---|
| 133 | * RtlFreeSid [NTDLL.376]
|
---|
| 134 | */
|
---|
| 135 | VOID* WINAPI RtlFreeSid(PSID pSid)
|
---|
| 136 | {
|
---|
| 137 | dprintf(("NTDLL: RtlFreeSid(%08xh)", pSid));
|
---|
| 138 |
|
---|
| 139 | Heap_Free(pSid);
|
---|
| 140 | return NULL;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | /**************************************************************************
|
---|
| 145 | * RtlLengthRequiredSid [NTDLL.427]
|
---|
| 146 | */
|
---|
| 147 | DWORD WINAPI RtlLengthRequiredSid(DWORD nrofsubauths)
|
---|
| 148 | {
|
---|
| 149 | dprintf (("NTDLL: RtlLengthRequiredSid(%08xh)\n",
|
---|
| 150 | nrofsubauths));
|
---|
| 151 |
|
---|
| 152 | return sizeof(DWORD)*nrofsubauths+sizeof(SID);
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | /**************************************************************************
|
---|
| 157 | * RtlLengthSid [NTDLL.429]
|
---|
| 158 | */
|
---|
| 159 | DWORD WINAPI RtlLengthSid(PSID sid)
|
---|
| 160 | {
|
---|
| 161 | dprintf(("NTDLL: RtlLengthSid(%08xh)\n",
|
---|
| 162 | sid));
|
---|
| 163 |
|
---|
| 164 | if (!sid)
|
---|
| 165 | return FALSE;
|
---|
| 166 |
|
---|
| 167 | return sizeof(DWORD)*sid->SubAuthorityCount+sizeof(SID);
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 |
|
---|
| 171 | /**************************************************************************
|
---|
| 172 | * RtlInitializeSid [NTDLL.410]
|
---|
| 173 | */
|
---|
| 174 | DWORD WINAPI RtlInitializeSid(
|
---|
| 175 | PSID psid,
|
---|
| 176 | PSID_IDENTIFIER_AUTHORITY psidauth,
|
---|
| 177 | DWORD c)
|
---|
| 178 | {
|
---|
| 179 | BYTE a = c & 0xff;
|
---|
| 180 |
|
---|
| 181 | if (a>=SID_MAX_SUB_AUTHORITIES)
|
---|
| 182 | return a;
|
---|
| 183 |
|
---|
| 184 | psid->SubAuthorityCount = a;
|
---|
| 185 | psid->Revision = SID_REVISION;
|
---|
| 186 | memcpy(&(psid->IdentifierAuthority),
|
---|
| 187 | psidauth,
|
---|
| 188 | sizeof(SID_IDENTIFIER_AUTHORITY));
|
---|
| 189 |
|
---|
| 190 | return STATUS_SUCCESS;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | /******************************************************************************
|
---|
| 195 | * RtlIdentifierAuthoritySid [NTDLL.395]
|
---|
| 196 | *
|
---|
| 197 | * PARAMS
|
---|
| 198 | * pSid []
|
---|
| 199 | */
|
---|
| 200 | PSID_IDENTIFIER_AUTHORITY WINAPI RtlIdentifierAuthoritySid( PSID pSid )
|
---|
| 201 | {
|
---|
| 202 | return &pSid->IdentifierAuthority;
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | /**************************************************************************
|
---|
| 206 | * RtlSubAuthoritySid [NTDLL.497]
|
---|
| 207 | */
|
---|
| 208 | LPDWORD WINAPI RtlSubAuthoritySid(PSID psid, DWORD nr)
|
---|
| 209 | {
|
---|
| 210 | return &(psid->SubAuthority[nr]);
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 |
|
---|
| 214 | /**************************************************************************
|
---|
| 215 | * RtlSubAuthorityCountSid [NTDLL.496]
|
---|
| 216 | */
|
---|
| 217 |
|
---|
| 218 | LPBYTE WINAPI RtlSubAuthorityCountSid(PSID psid)
|
---|
| 219 | {
|
---|
| 220 | dprintf2(("NTDLL: RtlSubAUthorityCountSid(%08xh)\n",
|
---|
| 221 | psid));
|
---|
| 222 |
|
---|
| 223 | return ((LPBYTE)psid)+1;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 |
|
---|
| 227 | /**************************************************************************
|
---|
| 228 | * RtlCopySid [NTDLL.302]
|
---|
| 229 | */
|
---|
| 230 | DWORD WINAPI RtlCopySid(DWORD nDestinationSidLength,
|
---|
| 231 | PSID pDestinationSid,
|
---|
| 232 | PSID pSourceSid)
|
---|
| 233 | {
|
---|
| 234 | dprintf(("NTDLL: RtlCopySid(%08xh,%08xh,%08xh)\n",
|
---|
| 235 | nDestinationSidLength,
|
---|
| 236 | pDestinationSid,
|
---|
| 237 | pSourceSid));
|
---|
| 238 |
|
---|
| 239 | if (!RtlValidSid(pSourceSid))
|
---|
| 240 | return STATUS_INVALID_PARAMETER;
|
---|
| 241 |
|
---|
| 242 | if (nDestinationSidLength < RtlLengthSid(pSourceSid))
|
---|
| 243 | return STATUS_BUFFER_TOO_SMALL;
|
---|
| 244 |
|
---|
| 245 | memcpy(pDestinationSid, pSourceSid, RtlLengthSid(pSourceSid));
|
---|
| 246 |
|
---|
| 247 | return STATUS_SUCCESS;
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 |
|
---|
| 251 | /******************************************************************************
|
---|
| 252 | * RtlValidSid [NTDLL.523]
|
---|
| 253 | *
|
---|
| 254 | * PARAMS
|
---|
| 255 | * pSid []
|
---|
| 256 | */
|
---|
| 257 | BOOL WINAPI RtlValidSid( PSID pSid )
|
---|
| 258 | {
|
---|
| 259 | if (IsBadReadPtr(pSid, 4))
|
---|
| 260 | {
|
---|
| 261 | return FALSE;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | if (pSid->SubAuthorityCount > SID_MAX_SUB_AUTHORITIES)
|
---|
| 265 | return FALSE;
|
---|
| 266 |
|
---|
| 267 | if (!pSid || pSid->Revision != SID_REVISION)
|
---|
| 268 | return FALSE;
|
---|
| 269 |
|
---|
| 270 | return TRUE;
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | /*
|
---|
| 274 | * security descriptor functions
|
---|
| 275 | */
|
---|
| 276 |
|
---|
| 277 | /**************************************************************************
|
---|
| 278 | * RtlCreateSecurityDescriptor [NTDLL.313]
|
---|
| 279 | *
|
---|
| 280 | * RETURNS:
|
---|
| 281 | * 0 success,
|
---|
| 282 | * STATUS_INVALID_OWNER, STATUS_PRIVILEGE_NOT_HELD, STATUS_NO_INHERITANCE,
|
---|
| 283 | * STATUS_NO_MEMORY
|
---|
| 284 | */
|
---|
| 285 | NTSTATUS WINAPI RtlCreateSecurityDescriptor(PSECURITY_DESCRIPTOR lpsd,
|
---|
| 286 | DWORD rev)
|
---|
| 287 | {
|
---|
| 288 | dprintf(("NTDLL: RtlCreateSecurityDescriptor(%08xh,%08xh)\n",
|
---|
| 289 | lpsd,
|
---|
| 290 | rev));
|
---|
| 291 |
|
---|
| 292 | if (rev!=SECURITY_DESCRIPTOR_REVISION)
|
---|
| 293 | return STATUS_UNKNOWN_REVISION;
|
---|
| 294 |
|
---|
| 295 | memset(lpsd,
|
---|
| 296 | '\0',
|
---|
| 297 | sizeof(*lpsd));
|
---|
| 298 |
|
---|
| 299 | lpsd->Revision = SECURITY_DESCRIPTOR_REVISION;
|
---|
| 300 |
|
---|
| 301 | return STATUS_SUCCESS;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 |
|
---|
| 305 | /**************************************************************************
|
---|
| 306 | * RtlValidSecurityDescriptor [NTDLL.313]
|
---|
| 307 | *
|
---|
| 308 | */
|
---|
| 309 | NTSTATUS WINAPI RtlValidSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor)
|
---|
| 310 | {
|
---|
| 311 | dprintf(("NTDLL: RtlValidSecurityDescriptor(%08xh)\n",
|
---|
| 312 | SecurityDescriptor));
|
---|
| 313 |
|
---|
| 314 | if ( ! SecurityDescriptor )
|
---|
| 315 | return STATUS_INVALID_SECURITY_DESCR;
|
---|
| 316 |
|
---|
| 317 | if ( SecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION )
|
---|
| 318 | return STATUS_UNKNOWN_REVISION;
|
---|
| 319 |
|
---|
| 320 | return STATUS_SUCCESS;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 |
|
---|
| 324 | /**************************************************************************
|
---|
| 325 | * RtlLengthSecurityDescriptor [NTDLL]
|
---|
| 326 | */
|
---|
| 327 | ULONG WINAPI RtlLengthSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor)
|
---|
| 328 | {
|
---|
| 329 | ULONG Size;
|
---|
| 330 |
|
---|
| 331 | dprintf(("NTDLL: RtlLengthSecurityDescriptor(%08xh)\n",
|
---|
| 332 | SecurityDescriptor));
|
---|
| 333 |
|
---|
| 334 | Size = SECURITY_DESCRIPTOR_MIN_LENGTH;
|
---|
| 335 | if ( SecurityDescriptor == NULL )
|
---|
| 336 | return 0;
|
---|
| 337 |
|
---|
| 338 | if ( SecurityDescriptor->Owner != NULL )
|
---|
| 339 | Size += SecurityDescriptor->Owner->SubAuthorityCount;
|
---|
| 340 | if ( SecurityDescriptor->Group != NULL )
|
---|
| 341 | Size += SecurityDescriptor->Group->SubAuthorityCount;
|
---|
| 342 |
|
---|
| 343 |
|
---|
| 344 | if ( SecurityDescriptor->Sacl != NULL )
|
---|
| 345 | Size += SecurityDescriptor->Sacl->AclSize;
|
---|
| 346 | if ( SecurityDescriptor->Dacl != NULL )
|
---|
| 347 | Size += SecurityDescriptor->Dacl->AclSize;
|
---|
| 348 |
|
---|
| 349 | return Size;
|
---|
| 350 | }
|
---|
| 351 |
|
---|
| 352 | /******************************************************************************
|
---|
| 353 | * RtlGetDaclSecurityDescriptor [NTDLL]
|
---|
| 354 | *
|
---|
| 355 | */
|
---|
| 356 | NTSTATUS WINAPI RtlGetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor,
|
---|
| 357 | PBOOLEAN lpbDaclPresent,
|
---|
| 358 | PACL *pDacl,
|
---|
| 359 | PBOOLEAN lpbDaclDefaulted)
|
---|
| 360 | {
|
---|
| 361 | dprintf(("NTDLL: RtlGetDaclSecurityDescriptor(%08xh,%08xh,%08xh,%08xh)\n",
|
---|
| 362 | pSecurityDescriptor,
|
---|
| 363 | lpbDaclPresent,
|
---|
| 364 | pDacl,
|
---|
| 365 | lpbDaclDefaulted));
|
---|
| 366 |
|
---|
| 367 | if (pSecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION)
|
---|
| 368 | return STATUS_UNKNOWN_REVISION ;
|
---|
| 369 |
|
---|
| 370 | *lpbDaclPresent = (SE_DACL_PRESENT & pSecurityDescriptor->Control);
|
---|
| 371 | if (*lpbDaclPresent ? 1 : 0)
|
---|
| 372 | {
|
---|
| 373 | if ( SE_SELF_RELATIVE & pSecurityDescriptor->Control)
|
---|
| 374 | {
|
---|
| 375 | *pDacl = (PACL) ((LPBYTE)pSecurityDescriptor + (DWORD)pSecurityDescriptor->Dacl);
|
---|
| 376 | }
|
---|
| 377 | else
|
---|
| 378 | {
|
---|
| 379 | *pDacl = pSecurityDescriptor->Dacl;
|
---|
| 380 | }
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | *lpbDaclDefaulted = (( SE_DACL_DEFAULTED & pSecurityDescriptor->Control ) ? 1 : 0);
|
---|
| 384 |
|
---|
| 385 | return STATUS_SUCCESS;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 |
|
---|
| 389 | /**************************************************************************
|
---|
| 390 | * RtlSetDaclSecurityDescriptor [NTDLL.483]
|
---|
| 391 | */
|
---|
| 392 | NTSTATUS WINAPI RtlSetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR lpsd,
|
---|
| 393 | BOOLEAN daclpresent,
|
---|
| 394 | PACL dacl,
|
---|
| 395 | BOOLEAN dacldefaulted)
|
---|
| 396 | {
|
---|
| 397 | dprintf(("NTDLL: RtlSetDaclSecurityDescriptor(%08xh,%08xh,%08xh,%08xh)\n",
|
---|
| 398 | lpsd,
|
---|
| 399 | daclpresent,
|
---|
| 400 | dacl,
|
---|
| 401 | dacldefaulted));
|
---|
| 402 |
|
---|
| 403 | if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
|
---|
| 404 | return STATUS_UNKNOWN_REVISION;
|
---|
| 405 | if (lpsd->Control & SE_SELF_RELATIVE)
|
---|
| 406 | return STATUS_INVALID_SECURITY_DESCR;
|
---|
| 407 |
|
---|
| 408 | if (!daclpresent)
|
---|
| 409 | {
|
---|
| 410 | lpsd->Control &= ~SE_DACL_PRESENT;
|
---|
| 411 | return TRUE;
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | lpsd->Control |= SE_DACL_PRESENT;
|
---|
| 415 | lpsd->Dacl = dacl;
|
---|
| 416 |
|
---|
| 417 | if (dacldefaulted)
|
---|
| 418 | lpsd->Control |= SE_DACL_DEFAULTED;
|
---|
| 419 | else
|
---|
| 420 | lpsd->Control &= ~SE_DACL_DEFAULTED;
|
---|
| 421 |
|
---|
| 422 | return STATUS_SUCCESS;
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 |
|
---|
| 426 | /******************************************************************************
|
---|
| 427 | * RtlGetSaclSecurityDescriptor [NTDLL]
|
---|
| 428 | *
|
---|
| 429 | */
|
---|
| 430 | NTSTATUS WINAPI RtlGetSaclSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor,
|
---|
| 431 | PBOOLEAN lpbSaclPresent,
|
---|
| 432 | PACL *pSacl,
|
---|
| 433 | PBOOLEAN lpbSaclDefaulted)
|
---|
| 434 | {
|
---|
| 435 | dprintf(("NTDLL: RtlGetSaclSecurityDescriptor(%08xh,%08xh,%08xh,%08xh)\n",
|
---|
| 436 | pSecurityDescriptor,
|
---|
| 437 | lpbSaclPresent,
|
---|
| 438 | pSacl,
|
---|
| 439 | lpbSaclDefaulted));
|
---|
| 440 |
|
---|
| 441 | if (pSecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION)
|
---|
| 442 | return STATUS_UNKNOWN_REVISION ;
|
---|
| 443 |
|
---|
| 444 | *lpbSaclPresent = (SE_SACL_PRESENT & pSecurityDescriptor->Control);
|
---|
| 445 | if (*lpbSaclPresent ? 1 : 0)
|
---|
| 446 | {
|
---|
| 447 | if ( SE_SELF_RELATIVE & pSecurityDescriptor->Control)
|
---|
| 448 | {
|
---|
| 449 | *pSacl = (PACL) ((LPBYTE)pSecurityDescriptor + (DWORD)pSecurityDescriptor->Sacl);
|
---|
| 450 | }
|
---|
| 451 | else
|
---|
| 452 | {
|
---|
| 453 | *pSacl = pSecurityDescriptor->Sacl;
|
---|
| 454 | }
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | *lpbSaclDefaulted = (( SE_SACL_DEFAULTED & pSecurityDescriptor->Control ) ? 1 : 0);
|
---|
| 458 |
|
---|
| 459 | return STATUS_SUCCESS;
|
---|
| 460 | }
|
---|
| 461 |
|
---|
| 462 |
|
---|
| 463 | /**************************************************************************
|
---|
| 464 | * RtlSetSaclSecurityDescriptor [NTDLL.488]
|
---|
| 465 | */
|
---|
| 466 | NTSTATUS WINAPI RtlSetSaclSecurityDescriptor (PSECURITY_DESCRIPTOR lpsd,
|
---|
| 467 | BOOLEAN saclpresent,
|
---|
| 468 | PACL sacl,
|
---|
| 469 | BOOLEAN sacldefaulted)
|
---|
| 470 | {
|
---|
| 471 | dprintf(("NTDLL: RtlSetSaclSecurityDescriptor(%08xh,%08xh,%08xh,%08xh)\n",
|
---|
| 472 | lpsd,
|
---|
| 473 | saclpresent,
|
---|
| 474 | sacl,
|
---|
| 475 | sacldefaulted));
|
---|
| 476 |
|
---|
| 477 | if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
|
---|
| 478 | return STATUS_UNKNOWN_REVISION;
|
---|
| 479 |
|
---|
| 480 | if (lpsd->Control & SE_SELF_RELATIVE)
|
---|
| 481 | return STATUS_INVALID_SECURITY_DESCR;
|
---|
| 482 |
|
---|
| 483 | if (!saclpresent)
|
---|
| 484 | {
|
---|
| 485 | lpsd->Control &= ~SE_SACL_PRESENT;
|
---|
| 486 | return 0;
|
---|
| 487 | }
|
---|
| 488 |
|
---|
| 489 | lpsd->Control |= SE_SACL_PRESENT;
|
---|
| 490 | lpsd->Sacl = sacl;
|
---|
| 491 |
|
---|
| 492 | if (sacldefaulted)
|
---|
| 493 | lpsd->Control |= SE_SACL_DEFAULTED;
|
---|
| 494 | else
|
---|
| 495 | lpsd->Control &= ~SE_SACL_DEFAULTED;
|
---|
| 496 |
|
---|
| 497 | return STATUS_SUCCESS;
|
---|
| 498 | }
|
---|
| 499 |
|
---|
| 500 |
|
---|
| 501 | /**************************************************************************
|
---|
| 502 | * RtlGetOwnerSecurityDescriptor [NTDLL.488]
|
---|
| 503 | */
|
---|
| 504 | NTSTATUS WINAPI RtlGetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
|
---|
| 505 | PSID *Owner,
|
---|
| 506 | PBOOLEAN OwnerDefaulted)
|
---|
| 507 | {
|
---|
| 508 | dprintf(("NTDLL: RtlGetOwnerSecurityDescriptor(%08xh,%08xh,%08xh)\n",
|
---|
| 509 | SecurityDescriptor,
|
---|
| 510 | Owner,
|
---|
| 511 | OwnerDefaulted));
|
---|
| 512 |
|
---|
| 513 | if ( !SecurityDescriptor || !Owner || !OwnerDefaulted )
|
---|
| 514 | return STATUS_INVALID_PARAMETER;
|
---|
| 515 |
|
---|
| 516 | *Owner = SecurityDescriptor->Owner;
|
---|
| 517 | if ( *Owner != NULL )
|
---|
| 518 | {
|
---|
| 519 | if ( SecurityDescriptor->Control & SE_OWNER_DEFAULTED )
|
---|
| 520 | *OwnerDefaulted = TRUE;
|
---|
| 521 | else
|
---|
| 522 | *OwnerDefaulted = FALSE;
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | return STATUS_SUCCESS;
|
---|
| 526 | }
|
---|
| 527 |
|
---|
| 528 |
|
---|
| 529 | /**************************************************************************
|
---|
| 530 | * RtlSetOwnerSecurityDescriptor [NTDLL.487]
|
---|
| 531 | */
|
---|
| 532 | NTSTATUS WINAPI RtlSetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR lpsd,
|
---|
| 533 | PSID owner,
|
---|
| 534 | BOOLEAN ownerdefaulted)
|
---|
| 535 | {
|
---|
| 536 | dprintf(("NTDLL: RtlSetOwnerSecurityDescriptor(%08x,%08xh,%08xh)\n",
|
---|
| 537 | lpsd,
|
---|
| 538 | owner,
|
---|
| 539 | ownerdefaulted));
|
---|
| 540 |
|
---|
| 541 | if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
|
---|
| 542 | return STATUS_UNKNOWN_REVISION;
|
---|
| 543 | if (lpsd->Control & SE_SELF_RELATIVE)
|
---|
| 544 | return STATUS_INVALID_SECURITY_DESCR;
|
---|
| 545 |
|
---|
| 546 | lpsd->Owner = owner;
|
---|
| 547 | if (ownerdefaulted)
|
---|
| 548 | lpsd->Control |= SE_OWNER_DEFAULTED;
|
---|
| 549 | else
|
---|
| 550 | lpsd->Control &= ~SE_OWNER_DEFAULTED;
|
---|
| 551 |
|
---|
| 552 | return STATUS_SUCCESS;
|
---|
| 553 | }
|
---|
| 554 |
|
---|
| 555 |
|
---|
| 556 | /**************************************************************************
|
---|
| 557 | * RtlSetGroupSecurityDescriptor [NTDLL.485]
|
---|
| 558 | */
|
---|
| 559 | NTSTATUS WINAPI RtlSetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR lpsd,
|
---|
| 560 | PSID group,
|
---|
| 561 | BOOLEAN groupdefaulted)
|
---|
| 562 | {
|
---|
| 563 | dprintf(("NTDLL: RtlSetGroupSecurityDescriptor(%08xh,%08xh,%08xh)\n",
|
---|
| 564 | lpsd,
|
---|
| 565 | group,
|
---|
| 566 | groupdefaulted));
|
---|
| 567 |
|
---|
| 568 | if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
|
---|
| 569 | return STATUS_UNKNOWN_REVISION;
|
---|
| 570 | if (lpsd->Control & SE_SELF_RELATIVE)
|
---|
| 571 | return STATUS_INVALID_SECURITY_DESCR;
|
---|
| 572 |
|
---|
| 573 | lpsd->Group = group;
|
---|
| 574 | if (groupdefaulted)
|
---|
| 575 | lpsd->Control |= SE_GROUP_DEFAULTED;
|
---|
| 576 | else
|
---|
| 577 | lpsd->Control &= ~SE_GROUP_DEFAULTED;
|
---|
| 578 |
|
---|
| 579 | return STATUS_SUCCESS;
|
---|
| 580 | }
|
---|
| 581 |
|
---|
| 582 |
|
---|
| 583 | /**************************************************************************
|
---|
| 584 | * RtlGetGroupSecurityDescriptor [NTDLL]
|
---|
| 585 | */
|
---|
| 586 | NTSTATUS WINAPI RtlGetGroupSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
|
---|
| 587 | PSID *Group,
|
---|
| 588 | PBOOLEAN GroupDefaulted)
|
---|
| 589 | {
|
---|
| 590 | dprintf(("NTDLL: RtlGetGroupSecurityDescriptor(%08xh,%08xh,%08xh)\n",
|
---|
| 591 | SecurityDescriptor,
|
---|
| 592 | Group,
|
---|
| 593 | GroupDefaulted));
|
---|
| 594 |
|
---|
| 595 | if ( !SecurityDescriptor || !Group || !GroupDefaulted )
|
---|
| 596 | return STATUS_INVALID_PARAMETER;
|
---|
| 597 |
|
---|
| 598 | *Group = SecurityDescriptor->Group;
|
---|
| 599 | if ( *Group != NULL )
|
---|
| 600 | {
|
---|
| 601 | if ( SecurityDescriptor->Control & SE_GROUP_DEFAULTED )
|
---|
| 602 | *GroupDefaulted = TRUE;
|
---|
| 603 | else
|
---|
| 604 | *GroupDefaulted = FALSE;
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | return STATUS_SUCCESS;
|
---|
| 608 | }
|
---|
| 609 |
|
---|
| 610 |
|
---|
| 611 | /*
|
---|
| 612 | * access control list's
|
---|
| 613 | */
|
---|
| 614 |
|
---|
| 615 | /**************************************************************************
|
---|
| 616 | * RtlCreateAcl [NTDLL.306]
|
---|
| 617 | *
|
---|
| 618 | * NOTES
|
---|
| 619 | * This should return NTSTATUS
|
---|
| 620 | */
|
---|
| 621 | DWORD WINAPI RtlCreateAcl(PACL acl,
|
---|
| 622 | DWORD size,
|
---|
| 623 | DWORD rev)
|
---|
| 624 | {
|
---|
| 625 | dprintf(("NTDLL: RtlCreateAcl(%08xh,%08xh,%08xh)\n",
|
---|
| 626 | acl,
|
---|
| 627 | size,
|
---|
| 628 | rev));
|
---|
| 629 |
|
---|
| 630 | if (rev!=ACL_REVISION)
|
---|
| 631 | return STATUS_INVALID_PARAMETER;
|
---|
| 632 | if (size<sizeof(ACL))
|
---|
| 633 | return STATUS_BUFFER_TOO_SMALL;
|
---|
| 634 | if (size>0xFFFF)
|
---|
| 635 | return STATUS_INVALID_PARAMETER;
|
---|
| 636 |
|
---|
| 637 | memset(acl,'\0',sizeof(ACL));
|
---|
| 638 | acl->AclRevision = rev;
|
---|
| 639 | acl->AclSize = size;
|
---|
| 640 | acl->AceCount = 0;
|
---|
| 641 |
|
---|
| 642 | return 0;
|
---|
| 643 | }
|
---|
| 644 |
|
---|
| 645 |
|
---|
| 646 | /**************************************************************************
|
---|
| 647 | * RtlFirstFreeAce [NTDLL.370]
|
---|
| 648 | * looks for the AceCount+1 ACE, and if it is still within the alloced
|
---|
| 649 | * ACL, return a pointer to it
|
---|
| 650 | */
|
---|
| 651 | BOOLEAN WINAPI RtlFirstFreeAce(PACL acl,
|
---|
| 652 | PACE_HEADER *x)
|
---|
| 653 | {
|
---|
| 654 | PACE_HEADER ace;
|
---|
| 655 | int i;
|
---|
| 656 |
|
---|
| 657 | dprintf(("NTDLL: RtlFirstFreeAct(%08xh,%08xh)\n",
|
---|
| 658 | acl,
|
---|
| 659 | x));
|
---|
| 660 |
|
---|
| 661 | *x = 0;
|
---|
| 662 | ace = (PACE_HEADER)(acl+1);
|
---|
| 663 | for (i=0;
|
---|
| 664 | i<acl->AceCount;
|
---|
| 665 | i++)
|
---|
| 666 | {
|
---|
| 667 | if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
|
---|
| 668 | return 0;
|
---|
| 669 |
|
---|
| 670 | ace = (PACE_HEADER)(((BYTE*)ace)+ace->AceSize);
|
---|
| 671 | }
|
---|
| 672 |
|
---|
| 673 | if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
|
---|
| 674 | return 0;
|
---|
| 675 |
|
---|
| 676 | *x = ace;
|
---|
| 677 | return 1;
|
---|
| 678 | }
|
---|
| 679 |
|
---|
| 680 |
|
---|
| 681 | /**************************************************************************
|
---|
| 682 | * RtlAddAce [NTDLL.260]
|
---|
| 683 | */
|
---|
| 684 | NTSTATUS WINAPI RtlAddAce(PACL acl,
|
---|
| 685 | DWORD rev,
|
---|
| 686 | DWORD xnrofaces,
|
---|
| 687 | PACE_HEADER acestart,
|
---|
| 688 | DWORD acelen)
|
---|
| 689 | {
|
---|
| 690 | PACE_HEADER ace,targetace;
|
---|
| 691 | int nrofaces;
|
---|
| 692 |
|
---|
| 693 | dprintf(("NTDLL: RtlAddAce(%08xh,%08xh,%08xh,%08xh,%08xh)\n",
|
---|
| 694 | acl,
|
---|
| 695 | rev,
|
---|
| 696 | xnrofaces,
|
---|
| 697 | acestart,
|
---|
| 698 | acelen));
|
---|
| 699 |
|
---|
| 700 | if (acl->AclRevision != ACL_REVISION)
|
---|
| 701 | return STATUS_INVALID_PARAMETER;
|
---|
| 702 |
|
---|
| 703 | if (!RtlFirstFreeAce(acl,&targetace))
|
---|
| 704 | return STATUS_INVALID_PARAMETER;
|
---|
| 705 |
|
---|
| 706 | nrofaces=0;
|
---|
| 707 | ace=acestart;
|
---|
| 708 |
|
---|
| 709 | while (((DWORD)ace-(DWORD)acestart)<acelen)
|
---|
| 710 | {
|
---|
| 711 | nrofaces++;
|
---|
| 712 | ace = (PACE_HEADER)(((BYTE*)ace)+ace->AceSize);
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | if ((DWORD)targetace+acelen>(DWORD)acl+acl->AclSize) /* too much aces */
|
---|
| 716 | return STATUS_INVALID_PARAMETER;
|
---|
| 717 |
|
---|
| 718 | memcpy((LPBYTE)targetace,acestart,acelen);
|
---|
| 719 | acl->AceCount+=nrofaces;
|
---|
| 720 |
|
---|
| 721 | return STATUS_SUCCESS;
|
---|
| 722 | }
|
---|
| 723 |
|
---|
| 724 |
|
---|
| 725 | /******************************************************************************
|
---|
| 726 | * RtlAddAccessAllowedAce [NTDLL]
|
---|
| 727 | */
|
---|
| 728 | BOOL WINAPI RtlAddAccessAllowedAce(IN OUT PACL pAcl, IN DWORD dwAceRevision,
|
---|
| 729 | IN DWORD AccessMask, IN PSID pSid)
|
---|
| 730 | {
|
---|
| 731 | dprintf(("NTDLL: RtlAddAccessAllowedAce(%08xh,%08xh,%08xh,%08xh) not implemented.\n",
|
---|
| 732 | pAcl,
|
---|
| 733 | dwAceRevision,
|
---|
| 734 | AccessMask,
|
---|
| 735 | pSid));
|
---|
| 736 |
|
---|
| 737 | return TRUE;
|
---|
| 738 | }
|
---|
| 739 |
|
---|
| 740 |
|
---|
| 741 | /******************************************************************************
|
---|
| 742 | * RtlGetAce [NTDLL]
|
---|
| 743 | */
|
---|
| 744 | NTSTATUS WINAPI RtlGetAce(PACL pAcl,
|
---|
| 745 | DWORD dwAceIndex,
|
---|
| 746 | LPVOID *pAce )
|
---|
| 747 | {
|
---|
| 748 | PACE_HEADER ace;
|
---|
| 749 | int i;
|
---|
| 750 |
|
---|
| 751 | dprintf(("NTDLL: RtlGetAce(%08x,%08x,%08x) test implementation",
|
---|
| 752 | pAcl,
|
---|
| 753 | dwAceIndex,
|
---|
| 754 | pAce));
|
---|
| 755 |
|
---|
| 756 |
|
---|
| 757 | *pAce = 0;
|
---|
| 758 | if(dwAceIndex > pAcl->AceCount) {
|
---|
| 759 | dprintf(("index out of range"));
|
---|
| 760 | return STATUS_INVALID_PARAMETER;
|
---|
| 761 | }
|
---|
| 762 | ace = (PACE_HEADER)(pAcl+1);
|
---|
| 763 |
|
---|
| 764 | for (i=0;
|
---|
| 765 | i<dwAceIndex;
|
---|
| 766 | i++)
|
---|
| 767 | {
|
---|
| 768 | if ((DWORD)ace>=(((DWORD)pAcl)+pAcl->AclSize))
|
---|
| 769 | return STATUS_BUFFER_OVERFLOW;
|
---|
| 770 |
|
---|
| 771 | ace = (PACE_HEADER)(((BYTE*)ace)+ace->AceSize);
|
---|
| 772 | }
|
---|
| 773 |
|
---|
| 774 | if ((DWORD)ace>=(((DWORD)pAcl)+pAcl->AclSize))
|
---|
| 775 | return STATUS_BUFFER_OVERFLOW;
|
---|
| 776 |
|
---|
| 777 | *pAce = ace;
|
---|
| 778 | return STATUS_SUCCESS;
|
---|
| 779 | }
|
---|
| 780 |
|
---|
| 781 |
|
---|
| 782 | /*
|
---|
| 783 | * misc
|
---|
| 784 | */
|
---|
| 785 |
|
---|
| 786 | /******************************************************************************
|
---|
| 787 | * RtlAdjustPrivilege [NTDLL]
|
---|
| 788 | */
|
---|
| 789 | DWORD WINAPI RtlAdjustPrivilege(DWORD x1,
|
---|
| 790 | DWORD x2,
|
---|
| 791 | DWORD x3,
|
---|
| 792 | DWORD x4)
|
---|
| 793 | {
|
---|
| 794 | dprintf(("NTDLL: RtlAdjustPrivilege(%08xh,%08xh,%08xh,%08xh) not implemented.\n",
|
---|
| 795 | x1,
|
---|
| 796 | x2,
|
---|
| 797 | x3,
|
---|
| 798 | x4));
|
---|
| 799 |
|
---|
| 800 | return 0;
|
---|
| 801 | }
|
---|
| 802 |
|
---|
| 803 |
|
---|
| 804 | /******************************************************************************
|
---|
| 805 | * RtlImpersonateSelf [NTDLL.@]
|
---|
| 806 | */
|
---|
| 807 | BOOL WINAPI
|
---|
| 808 | RtlImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
|
---|
| 809 | {
|
---|
| 810 | FIXME("(%08x), stub\n", ImpersonationLevel);
|
---|
| 811 | return TRUE;
|
---|
| 812 | }
|
---|
| 813 |
|
---|
| 814 | /******************************************************************************
|
---|
| 815 | * NtAccessCheck [NTDLL.@]
|
---|
| 816 | */
|
---|
| 817 | NTSTATUS WINAPI
|
---|
| 818 | NtAccessCheck(
|
---|
| 819 | IN PSECURITY_DESCRIPTOR SecurityDescriptor,
|
---|
| 820 | IN HANDLE ClientToken,
|
---|
| 821 | IN ACCESS_MASK DesiredAccess,
|
---|
| 822 | IN PGENERIC_MAPPING GenericMapping,
|
---|
| 823 | OUT PPRIVILEGE_SET PrivilegeSet,
|
---|
| 824 | OUT PULONG ReturnLength,
|
---|
| 825 | OUT PULONG GrantedAccess,
|
---|
| 826 | OUT PBOOLEAN AccessStatus)
|
---|
| 827 | {
|
---|
| 828 | FIXME("(%p, %04x, %08lx, %p, %p, %p, %p, %p), stub\n",
|
---|
| 829 | SecurityDescriptor, ClientToken, DesiredAccess, GenericMapping,
|
---|
| 830 | PrivilegeSet, ReturnLength, GrantedAccess, AccessStatus);
|
---|
| 831 | *AccessStatus = TRUE;
|
---|
| 832 | return STATUS_SUCCESS;
|
---|
| 833 | }
|
---|
| 834 |
|
---|
| 835 | /******************************************************************************
|
---|
| 836 | * NtSetSecurityObject [NTDLL.@]
|
---|
| 837 | */
|
---|
| 838 | NTSTATUS WINAPI
|
---|
| 839 | NtSetSecurityObject(
|
---|
| 840 | IN HANDLE Handle,
|
---|
| 841 | IN SECURITY_INFORMATION SecurityInformation,
|
---|
| 842 | IN PSECURITY_DESCRIPTOR SecurityDescriptor)
|
---|
| 843 | {
|
---|
| 844 | FIXME("0x%08x 0x%08lx %p\n", Handle, SecurityInformation, SecurityDescriptor);
|
---|
| 845 | return STATUS_SUCCESS;
|
---|
| 846 | }
|
---|
| 847 |
|
---|
| 848 | /******************************************************************************
|
---|
| 849 | * RtlGetControlSecurityDescriptor (NTDLL.@)
|
---|
| 850 | */
|
---|
| 851 |
|
---|
| 852 | NTSTATUS WINAPI RtlGetControlSecurityDescriptor(
|
---|
| 853 | PSECURITY_DESCRIPTOR pSecurityDescriptor,
|
---|
| 854 | PSECURITY_DESCRIPTOR_CONTROL pControl,
|
---|
| 855 | LPDWORD lpdwRevision)
|
---|
| 856 | {
|
---|
| 857 | FIXME("(%p,%p,%p),stub!\n",pSecurityDescriptor,pControl,lpdwRevision);
|
---|
| 858 | return STATUS_SUCCESS;
|
---|
| 859 | }
|
---|
| 860 |
|
---|
| 861 | /**************************************************************************
|
---|
| 862 | * RtlMakeSelfRelativeSD [NTDLL.@]
|
---|
| 863 | */
|
---|
| 864 | NTSTATUS WINAPI RtlMakeSelfRelativeSD(
|
---|
| 865 | IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
|
---|
| 866 | IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
|
---|
| 867 | IN OUT LPDWORD lpdwBufferLength)
|
---|
| 868 | {
|
---|
| 869 | FIXME("(%p,%p,%p(%lu))\n", pAbsoluteSecurityDescriptor,
|
---|
| 870 | pSelfRelativeSecurityDescriptor, lpdwBufferLength,*lpdwBufferLength);
|
---|
| 871 | return STATUS_SUCCESS;
|
---|
| 872 | }
|
---|