diff options
author | nijtmans <nijtmans> | 2010-10-11 12:11:53 (GMT) |
---|---|---|
committer | nijtmans <nijtmans> | 2010-10-11 12:11:53 (GMT) |
commit | 9cc6e0ec345b6410eb72acc698971044188e5936 (patch) | |
tree | 0673bfb7a6a4e8f65b8fea6ebeafeff0d60af4fd /win/tclWinTest.c | |
parent | d4669031a30c54543be0a0633b29ee1065484c76 (diff) | |
download | tcl-9cc6e0ec345b6410eb72acc698971044188e5936.zip tcl-9cc6e0ec345b6410eb72acc698971044188e5936.tar.gz tcl-9cc6e0ec345b6410eb72acc698971044188e5936.tar.bz2 |
[FRQ 2965056]: Windows build with -DUNICODE
Add netapi32 to the windows link line, so we no longer have to use LoadLibrary to access those functions.
Diffstat (limited to 'win/tclWinTest.c')
-rw-r--r-- | win/tclWinTest.c | 139 |
1 files changed, 20 insertions, 119 deletions
diff --git a/win/tclWinTest.c b/win/tclWinTest.c index 1a1c9d2..6b37f48 100644 --- a/win/tclWinTest.c +++ b/win/tclWinTest.c @@ -8,15 +8,9 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinTest.c,v 1.27 2010/08/30 09:19:38 nijtmans Exp $ + * RCS: @(#) $Id: tclWinTest.c,v 1.28 2010/10/11 12:11:53 nijtmans Exp $ */ -/* TODO: This file does not compile in UNICODE mode. - * See [Freq 2965056]: Windows build with -DUNICODE - */ -#undef UNICODE -#undef _UNICODE - #ifndef USE_TCL_STUBS # define USE_TCL_STUBS #endif @@ -486,28 +480,6 @@ TestplatformChmod( const char *nativePath, int pmode) { - typedef DWORD (WINAPI *getSidLengthRequiredDef)(UCHAR); - typedef BOOL (WINAPI *initializeSidDef)(PSID, PSID_IDENTIFIER_AUTHORITY, - BYTE); - typedef PDWORD (WINAPI *getSidSubAuthorityDef)(PSID, DWORD); - typedef DWORD (WINAPI *setNamedSecurityInfoADef)(IN LPSTR, - IN SE_OBJECT_TYPE, IN SECURITY_INFORMATION, IN PSID, IN PSID, - IN PACL, IN PACL); - typedef BOOL (WINAPI *getAceDef)(PACL, DWORD, LPVOID *); - typedef BOOL (WINAPI *addAceDef)(PACL, DWORD, DWORD, LPVOID, DWORD); - typedef BOOL (WINAPI *equalSidDef)(PSID, PSID); - typedef BOOL (WINAPI *addAccessDeniedAceDef)(PACL, DWORD, DWORD, PSID); - typedef BOOL (WINAPI *initializeAclDef)(PACL, DWORD, DWORD); - typedef DWORD (WINAPI *getLengthSidDef)(PSID); - typedef BOOL (WINAPI *getAclInformationDef)(PACL, LPVOID, DWORD, - ACL_INFORMATION_CLASS); - typedef BOOL (WINAPI *getSecurityDescriptorDaclDef)(PSECURITY_DESCRIPTOR, - LPBOOL, PACL *, LPBOOL); - typedef BOOL (WINAPI *lookupAccountNameADef)(LPCSTR, LPCSTR, PSID, - PDWORD, LPSTR, LPDWORD, PSID_NAME_USE); - typedef BOOL (WINAPI *getFileSecurityADef)(LPCSTR, SECURITY_INFORMATION, - PSECURITY_DESCRIPTOR, DWORD, LPDWORD); - static const SECURITY_INFORMATION infoBits = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION; static const DWORD readOnlyMask = FILE_DELETE_CHILD | FILE_ADD_FILE @@ -518,22 +490,6 @@ TestplatformChmod( * References to security functions (only available on NT and later). */ - static getSidLengthRequiredDef getSidLengthRequiredProc; - static initializeSidDef initializeSidProc; - static getSidSubAuthorityDef getSidSubAuthorityProc; - static setNamedSecurityInfoADef setNamedSecurityInfoProc; - static getAceDef getAceProc; - static addAceDef addAceProc; - static equalSidDef equalSidProc; - static addAccessDeniedAceDef addAccessDeniedAceProc; - static initializeAclDef initializeAclProc; - static getLengthSidDef getLengthSidProc; - static getAclInformationDef getAclInformationProc; - static getSecurityDescriptorDaclDef getSecurityDescriptorDaclProc; - static lookupAccountNameADef lookupAccountNameProc; - static getFileSecurityADef getFileSecurityProc; - static int initialized = 0; - const BOOL set_readOnly = !(pmode & 0222); BOOL acl_readOnly_found = FALSE, curAclPresent, curAclDefaulted; SID_IDENTIFIER_AUTHORITY userSidAuthority = { @@ -545,72 +501,18 @@ TestplatformChmod( PACL curAcl, newAcl = 0; WORD j; SID *userSid = 0; - TCHAR *userDomain = 0; + char *userDomain = 0; int res = 0; /* * One time initialization, dynamically load Windows NT features */ - if (!initialized) { - TCL_DECLARE_MUTEX(initializeMutex) - Tcl_MutexLock(&initializeMutex); - if (!initialized) { - HINSTANCE hInstance = LoadLibrary("Advapi32"); - - if (hInstance != NULL) { - setNamedSecurityInfoProc = (setNamedSecurityInfoADef) - GetProcAddress(hInstance, "SetNamedSecurityInfoA"); - getFileSecurityProc = (getFileSecurityADef) - GetProcAddress(hInstance, "GetFileSecurityA"); - getAceProc = (getAceDef) - GetProcAddress(hInstance, "GetAce"); - addAceProc = (addAceDef) - GetProcAddress(hInstance, "AddAce"); - equalSidProc = (equalSidDef) - GetProcAddress(hInstance, "EqualSid"); - addAccessDeniedAceProc = (addAccessDeniedAceDef) - GetProcAddress(hInstance, "AddAccessDeniedAce"); - initializeAclProc = (initializeAclDef) - GetProcAddress(hInstance, "InitializeAcl"); - getLengthSidProc = (getLengthSidDef) - GetProcAddress(hInstance, "GetLengthSid"); - getAclInformationProc = (getAclInformationDef) - GetProcAddress(hInstance, "GetAclInformation"); - getSecurityDescriptorDaclProc = (getSecurityDescriptorDaclDef) - GetProcAddress(hInstance, "GetSecurityDescriptorDacl"); - lookupAccountNameProc = (lookupAccountNameADef) - GetProcAddress(hInstance, "LookupAccountNameA"); - getSidLengthRequiredProc = (getSidLengthRequiredDef) - GetProcAddress(hInstance, "GetSidLengthRequired"); - initializeSidProc = (initializeSidDef) - GetProcAddress(hInstance, "InitializeSid"); - getSidSubAuthorityProc = (getSidSubAuthorityDef) - GetProcAddress(hInstance, "GetSidSubAuthority"); - - if (setNamedSecurityInfoProc && getAceProc && addAceProc - && equalSidProc && addAccessDeniedAceProc - && initializeAclProc && getLengthSidProc - && getAclInformationProc - && getSecurityDescriptorDaclProc - && lookupAccountNameProc && getFileSecurityProc - && getSidLengthRequiredProc && initializeSidProc - && getSidSubAuthorityProc) { - initialized = 1; - } - } - if (!initialized) { - initialized = -1; - } - } - Tcl_MutexUnlock(&initializeMutex); - } - /* * Process the chmod request. */ - attr = GetFileAttributes(nativePath); + attr = GetFileAttributesA(nativePath); /* * nativePath not found @@ -622,11 +524,10 @@ TestplatformChmod( } /* - * If no ACL API is present or nativePath is not a directory, there is no - * special handling. + * If nativePath is not a directory, there is no special handling. */ - if (initialized < 0 || !(attr & FILE_ATTRIBUTE_DIRECTORY)) { + if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) { goto done; } @@ -642,7 +543,7 @@ TestplatformChmod( * obtains the size of the security descriptor. */ - if (!getFileSecurityProc(nativePath, infoBits, NULL, 0, &secDescLen)) { + if (!GetFileSecurityA(nativePath, infoBits, NULL, 0, &secDescLen)) { DWORD secDescLen2 = 0; if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { @@ -650,7 +551,7 @@ TestplatformChmod( } secDesc = (BYTE *) ckalloc(secDescLen); - if (!getFileSecurityProc(nativePath, infoBits, + if (!GetFileSecurityA(nativePath, infoBits, (PSECURITY_DESCRIPTOR) secDesc, secDescLen, &secDescLen2) || (secDescLen < secDescLen2)) { goto done; @@ -661,22 +562,22 @@ TestplatformChmod( * Get the World SID. */ - userSid = (SID *) ckalloc(getSidLengthRequiredProc((UCHAR) 1)); - initializeSidProc(userSid, &userSidAuthority, (BYTE) 1); - *(getSidSubAuthorityProc(userSid, 0)) = SECURITY_WORLD_RID; + userSid = (SID *) ckalloc(GetSidLengthRequired((UCHAR) 1)); + InitializeSid(userSid, &userSidAuthority, (BYTE) 1); + *(GetSidSubAuthority(userSid, 0)) = SECURITY_WORLD_RID; /* * If curAclPresent == false then curAcl and curAclDefaulted not valid. */ - if (!getSecurityDescriptorDaclProc((PSECURITY_DESCRIPTOR) secDesc, + if (!GetSecurityDescriptorDacl((PSECURITY_DESCRIPTOR) secDesc, &curAclPresent, &curAcl, &curAclDefaulted)) { goto done; } if (!curAclPresent || !curAcl) { ACLSize.AclBytesInUse = 0; ACLSize.AceCount = 0; - } else if (!getAclInformationProc(curAcl, &ACLSize, sizeof(ACLSize), + } else if (!GetAclInformation(curAcl, &ACLSize, sizeof(ACLSize), AclSizeInformation)) { goto done; } @@ -686,14 +587,14 @@ TestplatformChmod( */ newAclSize = ACLSize.AclBytesInUse + sizeof(ACCESS_DENIED_ACE) - + getLengthSidProc(userSid) - sizeof(DWORD); + + GetLengthSid(userSid) - sizeof(DWORD); newAcl = (ACL *) ckalloc(newAclSize); /* * Initialize the new ACL. */ - if (!initializeAclProc(newAcl, newAclSize, ACL_REVISION)) { + if (!InitializeAcl(newAcl, newAclSize, ACL_REVISION)) { goto done; } @@ -701,7 +602,7 @@ TestplatformChmod( * Add denied to make readonly, this will be known as a "read-only tag". */ - if (set_readOnly && !addAccessDeniedAceProc(newAcl, ACL_REVISION, + if (set_readOnly && !AddAccessDeniedAce(newAcl, ACL_REVISION, readOnlyMask, userSid)) { goto done; } @@ -711,7 +612,7 @@ TestplatformChmod( LPVOID pACE2; ACE_HEADER *phACE2; - if (!getAceProc(curAcl, j, &pACE2)) { + if (!GetAce(curAcl, j, &pACE2)) { goto done; } @@ -734,7 +635,7 @@ TestplatformChmod( ACCESS_DENIED_ACE *pACEd = (ACCESS_DENIED_ACE *) phACE2; if (pACEd->Mask == readOnlyMask - && equalSidProc(userSid, (PSID) &pACEd->SidStart)) { + && EqualSid(userSid, (PSID) &pACEd->SidStart)) { acl_readOnly_found = TRUE; continue; } @@ -744,7 +645,7 @@ TestplatformChmod( * Copy the current ACE from the old to the new ACL. */ - if (!addAceProc(newAcl, ACL_REVISION, MAXDWORD, (PACL *) pACE2, + if (!AddAce(newAcl, ACL_REVISION, MAXDWORD, (PACL *) pACE2, ((PACE_HEADER) pACE2)->AceSize)) { goto done; } @@ -754,7 +655,7 @@ TestplatformChmod( * Apply the new ACL. */ - if (set_readOnly == acl_readOnly_found || setNamedSecurityInfoProc( + if (set_readOnly == acl_readOnly_found || SetNamedSecurityInfoA( (LPSTR) nativePath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, newAcl, NULL) == ERROR_SUCCESS) { res = 0; @@ -771,7 +672,7 @@ TestplatformChmod( ckfree((char *) userSid); } if (userDomain) { - ckfree(userDomain); + ckfree((char *) userDomain); } if (res != 0) { |