Changeset 21325 for trunk/src/advapi32/security.c
- Timestamp:
- Jul 3, 2009, 11:59:02 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/advapi32/security.c
r10272 r21325 9 9 #include "heap.h" 10 10 #include "ntddk.h" 11 #include "ntstatus.h" 11 12 #include "ntsecapi.h" 13 #include "sddl.h" 14 //#include "wine/debug.h" 12 15 #include "debugtools.h" 16 #include "wine/unicode.h" 13 17 14 18 #ifdef __WIN32OS2__ 15 #include <heapstring.h> 19 //#include <heapstring.h> 20 LPWSTR WIN32API HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str ); 16 21 #endif 17 22 18 DEFAULT_DEBUG_CHANNEL(advapi); 19 20 #define CallWin32ToNt(func) \ 21 { NTSTATUS ret; \ 22 ret = (func); \ 23 if (ret !=STATUS_SUCCESS) \ 24 { SetLastError (RtlNtStatusToDosError(ret)); return FALSE; } \ 25 return TRUE; \ 23 WINE_DEFAULT_DEBUG_CHANNEL(advapi); 24 25 26 /* set last error code from NT status and get the proper boolean return value */ 27 /* used for functions that are a simple wrapper around the corresponding ntdll API */ 28 static inline BOOL set_ntstatus( NTSTATUS status ) 29 { 30 if (status) SetLastError( RtlNtStatusToDosError( status )); 31 return !status; 26 32 } 27 33 … … 30 36 if (oa) 31 37 { 32 TRACE("\n\tlength=%lu, rootdir= 0x%08x, objectname=%s\n\tattr=0x%08lx, sid=%p qos=%p\n",38 TRACE("\n\tlength=%lu, rootdir=%p, objectname=%s\n\tattr=0x%08lx, sid=%p qos=%p\n", 33 39 oa->Length, oa->RootDirectory, 34 40 oa->ObjectName?debugstr_w(oa->ObjectName->Buffer):"null", … … 44 50 /****************************************************************************** 45 51 * OpenProcessToken [ADVAPI32.@] 46 * Opens the access token associated with a process 52 * Opens the access token associated with a process handle. 47 53 * 48 54 * PARAMS … … 51 57 * TokenHandle [O] Pointer to handle of open access token 52 58 * 53 * RETURNS STD 59 * RETURNS 60 * Success: TRUE. TokenHandle contains the access token. 61 * Failure: FALSE. 62 * 63 * NOTES 64 * See NtOpenProcessToken. 54 65 */ 55 66 BOOL WINAPI … … 57 68 HANDLE *TokenHandle ) 58 69 { 59 CallWin32ToNt(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));70 return set_ntstatus(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle )); 60 71 } 61 72 … … 63 74 * OpenThreadToken [ADVAPI32.@] 64 75 * 65 * PARAMS 66 * thread [] 67 * desiredaccess [] 68 * openasself [] 69 * thandle [] 76 * Opens the access token associated with a thread handle. 77 * 78 * PARAMS 79 * ThreadHandle [I] Handle to process 80 * DesiredAccess [I] Desired access to the thread 81 * OpenAsSelf [I] ??? 82 * TokenHandle [O] Destination for the token handle 83 * 84 * RETURNS 85 * Success: TRUE. TokenHandle contains the access token. 86 * Failure: FALSE. 87 * 88 * NOTES 89 * See NtOpenThreadToken. 70 90 */ 71 91 BOOL WINAPI … … 73 93 BOOL OpenAsSelf, HANDLE *TokenHandle) 74 94 { 75 CallWin32ToNt (NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));95 return set_ntstatus( NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle)); 76 96 } 77 97 … … 79 99 * AdjustTokenPrivileges [ADVAPI32.@] 80 100 * 81 * PARAMS 82 * TokenHandle [] 83 * DisableAllPrivileges [] 84 * NewState [] 85 * BufferLength [] 86 * PreviousState [] 87 * ReturnLength [] 101 * Adjust the privileges of an open token handle. 102 * 103 * PARAMS 104 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken() 105 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState 106 * NewState [I] Desired new privileges of the token 107 * BufferLength [I] Length of NewState 108 * PreviousState [O] Destination for the previous state 109 * ReturnLength [I/O] Size of PreviousState 110 * 111 * 112 * RETURNS 113 * Success: TRUE. Privileges are set to NewState and PreviousState is updated. 114 * Failure: FALSE. 115 * 116 * NOTES 117 * See NtAdjustPrivilegesToken. 88 118 */ 89 119 BOOL WINAPI … … 92 122 LPVOID PreviousState, LPDWORD ReturnLength ) 93 123 { 94 CallWin32ToNt(NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength)); 124 return set_ntstatus( NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges, 125 NewState, BufferLength, PreviousState, 126 ReturnLength)); 95 127 } 96 128 … … 98 130 * CheckTokenMembership [ADVAPI32.@] 99 131 * 100 * PARAMS 101 * TokenHandle [] 102 * SidToCheck [] 103 * IsMember [] 132 * Determine if an access token is a member of a SID. 133 * 134 * PARAMS 135 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken() 136 * SidToCheck [I] SID that possibly contains the token 137 * IsMember [O] Destination for result. 138 * 139 * RETURNS 140 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise. 141 * Failure: FALSE. 104 142 */ 105 143 BOOL WINAPI … … 107 145 PBOOL IsMember ) 108 146 { 109 FIXME("( 0x%08x%p %p) stub!\n", TokenHandle, SidToCheck, IsMember);147 FIXME("(%p %p %p) stub!\n", TokenHandle, SidToCheck, IsMember); 110 148 111 149 *IsMember = TRUE; … … 117 155 * 118 156 * PARAMS 119 * token [] 120 * tokeninfoclass [] 121 * tokeninfo [] 122 * tokeninfolength [] 123 * retlen [] 124 * 157 * token [I] Handle from OpenProcessToken() or OpenThreadToken() 158 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h" 159 * tokeninfo [O] Destination for token information 160 * tokeninfolength [I] Length of tokeninfo 161 * retlen [O] Destination for returned token information length 162 * 163 * RETURNS 164 * Success: TRUE. tokeninfo contains retlen bytes of token information 165 * Failure: FALSE. 166 * 167 * NOTES 168 * See NtQueryInformationToken. 125 169 */ 126 170 BOOL WINAPI … … 128 172 LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen ) 129 173 { 130 CallWin32ToNt(NtQueryInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength, retlen));174 return set_ntstatus (NtQueryInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength, retlen)); 131 175 } 132 176 … … 134 178 * SetThreadToken [ADVAPI32.@] 135 179 * 136 * Assigns an "impersonation token" to a thread so it can assume the 137 * security privledges of another thread or process. Can also remove 138 * a previously assigned token. Only supported on NT - it's a stub 139 * exactly like this one on Win9X. 140 * 141 */ 142 180 * Assigns an 'impersonation token' to a thread so it can assume the 181 * security privileges of another thread or process. Can also remove 182 * a previously assigned token. 183 * 184 * PARAMS 185 * thread [O] Handle to thread to set the token for 186 * token [I] Token to set 187 * 188 * RETURNS 189 * Success: TRUE. The threads access token is set to token 190 * Failure: FALSE. 191 * 192 * NOTES 193 * Only supported on NT or higher. On Win9X this function does nothing. 194 * See SetTokenInformation. 195 */ 143 196 BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token) 144 197 { … … 344 397 */ 345 398 BOOL WINAPI 346 InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr, DWORD revision ) 347 { 348 CallWin32ToNt (RtlCreateSecurityDescriptor(pDescr, revision )); 349 } 399 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr, DWORD revision ) 400 { 401 return set_ntstatus( RtlCreateSecurityDescriptor(pDescr, revision )); 402 } 403 350 404 351 405 /****************************************************************************** 352 406 * GetSecurityDescriptorLength [ADVAPI32.@] 353 407 */ 354 DWORD WINAPI GetSecurityDescriptorLength( SECURITY_DESCRIPTOR *pDescr)355 { 356 return (RtlLengthSecurityDescriptor(pDescr));408 DWORD WINAPI GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr) 409 { 410 return RtlLengthSecurityDescriptor(pDescr); 357 411 } 358 412 … … 365 419 */ 366 420 BOOL WINAPI 367 GetSecurityDescriptorOwner( SECURITY_DESCRIPTOR *pDescr, PSID *pOwner,421 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr, PSID *pOwner, 368 422 LPBOOL lpbOwnerDefaulted ) 369 423 { 370 CallWin32ToNt (RtlGetOwnerSecurityDescriptor( pDescr, pOwner, (PBOOLEAN)lpbOwnerDefaulted )); 424 BOOLEAN defaulted; 425 BOOL ret = set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr, pOwner, &defaulted )); 426 *lpbOwnerDefaulted = defaulted; 427 return ret; 371 428 } 372 429 … … 379 436 PSID pOwner, BOOL bOwnerDefaulted) 380 437 { 381 CallWin32ToNt (RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));438 return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted)); 382 439 } 383 440 /****************************************************************************** … … 389 446 LPBOOL GroupDefaulted) 390 447 { 391 CallWin32ToNt (RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, (PBOOLEAN)GroupDefaulted)); 448 BOOLEAN defaulted; 449 BOOL ret = set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, &defaulted )); 450 *GroupDefaulted = defaulted; 451 return ret; 392 452 } 393 453 /****************************************************************************** … … 397 457 PSID Group, BOOL GroupDefaulted) 398 458 { 399 CallWin32ToNt (RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));459 return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted)); 400 460 } 401 461 … … 409 469 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor ) 410 470 { 411 CallWin32ToNt (RtlValidSecurityDescriptor(SecurityDescriptor));471 return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor)); 412 472 } 413 473 … … 421 481 OUT LPBOOL lpbDaclDefaulted) 422 482 { 423 CallWin32ToNt (RtlGetDaclSecurityDescriptor(pSecurityDescriptor, (PBOOLEAN)lpbDaclPresent, 424 pDacl, (PBOOLEAN)lpbDaclDefaulted)); 483 BOOLEAN present, defaulted; 484 BOOL ret = set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor, &present, pDacl, &defaulted)); 485 *lpbDaclPresent = present; 486 *lpbDaclDefaulted = defaulted; 487 return ret; 425 488 } 426 489 … … 435 498 BOOL dacldefaulted ) 436 499 { 437 CallWin32ToNt (RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ));500 return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ) ); 438 501 } 439 502 /****************************************************************************** … … 446 509 OUT LPBOOL lpbSaclDefaulted) 447 510 { 448 CallWin32ToNt (RtlGetSaclSecurityDescriptor(lpsd, 449 (PBOOLEAN)lpbSaclPresent, pSacl, (PBOOLEAN)lpbSaclDefaulted)); 511 BOOLEAN present, defaulted; 512 BOOL ret = set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd, &present, pSacl, &defaulted) ); 513 *lpbSaclPresent = present; 514 *lpbSaclDefaulted = defaulted; 515 return ret; 450 516 } 451 517 … … 459 525 BOOL sacldefaulted) 460 526 { 461 CallWin32ToNt(RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));527 return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted)); 462 528 } 463 529 /****************************************************************************** … … 475 541 IN OUT LPDWORD lpdwBufferLength) 476 542 { 477 CallWin32ToNt (RtlMakeSelfRelativeSD(pAbsoluteSecurityDescriptor,pSelfRelativeSecurityDescriptor, lpdwBufferLength)); 543 return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor, 544 pSelfRelativeSecurityDescriptor, lpdwBufferLength)); 478 545 } 479 546 … … 485 552 PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision) 486 553 { 487 CallWin32ToNt(RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));554 return set_ntstatus (RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision)); 488 555 } 489 556 … … 496 563 * InitializeAcl [ADVAPI32.@] 497 564 */ 498 DWORD WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev) 499 { 500 CallWin32ToNt (RtlCreateAcl(acl, size, rev)); 501 } 502 565 BOOL WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev) 566 { 567 return set_ntstatus( RtlCreateAcl(acl, size, rev)); 568 } 569 570 /****************************************************************************** 571 * AddAccessAllowedAceEx [ADVAPI32.@] 572 */ 573 BOOL WINAPI AddAccessAllowedAceEx( 574 IN OUT PACL pAcl, 575 IN DWORD dwAceRevision, 576 IN DWORD AceFlags, 577 IN DWORD AccessMask, 578 IN PSID pSid) 579 { 580 FIXME("AddAccessAllowedAceEx (%x, %x, %x, %x, %x): stub\n", pAcl, dwAceRevision, AceFlags, AccessMask, pSid); 581 return FALSE; 582 // return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid)); 583 } 584 585 /****************************************************************************** 586 * GetAce [ADVAPI32.@] 587 */ 588 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce ) 589 { 590 return set_ntstatus(RtlGetAce(pAcl, dwAceIndex, pAce)); 591 } 503 592 /* ############################## 504 593 ###### MISC FUNCTIONS ###### … … 547 636 * GetFileSecurityA [ADVAPI32.@] 548 637 * 549 * Obtains Specified information about the security of a file or directory 550 * The information obtained is constrained by the callers access rights and 551 * privileges 638 * Obtains Specified information about the security of a file or directory. 639 * 640 * PARAMS 641 * lpFileName [I] Name of the file to get info for 642 * RequestedInformation [I] SE_ flags from "winnt.h" 643 * pSecurityDescriptor [O] Destination for security information 644 * nLength [I] Length of pSecurityDescriptor 645 * lpnLengthNeeded [O] Destination for length of returned security information 646 * 647 * RETURNS 648 * Success: TRUE. pSecurityDescriptor contains the requested information. 649 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info. 650 * 651 * NOTES 652 * The information returned is constrained by the callers access rights and 653 * privileges. 552 654 */ 553 655 BOOL WINAPI … … 557 659 DWORD nLength, LPDWORD lpnLengthNeeded ) 558 660 { 559 FIXME("(%s) : stub\n", debugstr_a(lpFileName)); 560 return TRUE; 661 DWORD len; 662 BOOL r; 663 LPWSTR name = NULL; 664 665 if( lpFileName ) 666 { 667 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 ); 668 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); 669 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len ); 670 } 671 672 r = GetFileSecurityW( name, RequestedInformation, pSecurityDescriptor, 673 nLength, lpnLengthNeeded ); 674 HeapFree( GetProcessHeap(), 0, name ); 675 676 return r; 561 677 } 562 678 … … 564 680 * GetFileSecurityW [ADVAPI32.@] 565 681 * 566 * Obtains Specified information about the security of a file or directory 567 * The information obtained is constrained by the callers access rights and 568 * privileges 569 * 570 * PARAMS 571 * lpFileName [] 572 * RequestedInformation [] 573 * pSecurityDescriptor [] 574 * nLength [] 575 * lpnLengthNeeded [] 682 * See GetFileSecurityA. 576 683 */ 577 684 BOOL WINAPI … … 725 832 * 726 833 * PARAMS 727 * x1 []728 * x2 []729 * x3 []730 * x4 []834 * SystemName [I] 835 * ObjectAttributes [I] 836 * DesiredAccess [I] 837 * PolicyHandle [I/O] 731 838 */ 732 839 NTSTATUS WINAPI … … 742 849 dumpLsaAttributes(ObjectAttributes); 743 850 if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe; 744 return TRUE;851 return STATUS_SUCCESS; 745 852 } 746 853 … … 907 1014 LPBOOL AccessStatus) 908 1015 { 909 CallWin32ToNt(NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,1016 return set_ntstatus (NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess, 910 1017 GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, (PBOOLEAN)AccessStatus)); 911 1018 } … … 919 1026 IN PSECURITY_DESCRIPTOR SecurityDescriptor ) 920 1027 { 921 CallWin32ToNt (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor)); 922 } 1028 return set_ntstatus (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor)); 1029 } 1030 923 1031 924 1032 /****************************************************************************** … … 952 1060 953 1061 /****************************************************************************** 954 * GetAce [ADVAPI32.@] 955 */ 956 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce ) 957 { 958 CallWin32ToNt(RtlGetAce(pAcl, dwAceIndex, pAce)); 959 } 1062 * ConvertSidToStringSidW [ADVAPI32.@] 1063 * 1064 * format of SID string is: 1065 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>... 1066 * where 1067 * <rev> is the revision of the SID encoded as decimal 1068 * <auth> is the identifier authority encoded as hex 1069 * <subauthN> is the subauthority id encoded as decimal 1070 */ 1071 BOOL WINAPI ConvertSidToStringSidW( PSID pSid, LPWSTR *pstr ) 1072 { 1073 DWORD sz, i; 1074 LPWSTR str; 1075 WCHAR fmt[] = { 'S','-','%','u','-','%','d',0 }; 1076 WCHAR subauthfmt[] = { '-','%','u',0 }; 1077 SID* pisid=pSid; 1078 1079 TRACE("%p %p\n", pSid, pstr ); 1080 1081 if( !IsValidSid( pSid ) ) 1082 return FALSE; 1083 1084 if (pisid->Revision != SDDL_REVISION) 1085 return FALSE; 1086 if (pisid->IdentifierAuthority.Value[0] || 1087 pisid->IdentifierAuthority.Value[1]) 1088 { 1089 FIXME("not matching MS' bugs\n"); 1090 return FALSE; 1091 } 1092 1093 sz = 14 + pisid->SubAuthorityCount * 11; 1094 str = LocalAlloc( 0, sz*sizeof(WCHAR) ); 1095 sprintfW( str, fmt, pisid->Revision, MAKELONG( 1096 MAKEWORD( pisid->IdentifierAuthority.Value[5], 1097 pisid->IdentifierAuthority.Value[4] ), 1098 MAKEWORD( pisid->IdentifierAuthority.Value[3], 1099 pisid->IdentifierAuthority.Value[2] ) ) ); 1100 for( i=0; i<pisid->SubAuthorityCount; i++ ) 1101 sprintfW( str + strlenW(str), subauthfmt, pisid->SubAuthority[i] ); 1102 *pstr = str; 1103 1104 return TRUE; 1105 } 1106 1107 /****************************************************************************** 1108 * ConvertSidToStringSidA [ADVAPI32.@] 1109 */ 1110 BOOL WINAPI ConvertSidToStringSidA(PSID pSid, LPSTR *pstr) 1111 { 1112 LPWSTR wstr = NULL; 1113 LPSTR str; 1114 UINT len; 1115 1116 TRACE("%p %p\n", pSid, pstr ); 1117 1118 if( !ConvertSidToStringSidW( pSid, &wstr ) ) 1119 return FALSE; 1120 1121 len = WideCharToMultiByte( CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL ); 1122 str = LocalAlloc( 0, len ); 1123 WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, len, NULL, NULL ); 1124 LocalFree( wstr ); 1125 1126 *pstr = str; 1127 1128 return TRUE; 1129 }
Note:
See TracChangeset
for help on using the changeset viewer.