Tcl Source Code

Check-in [a4746b4c9f]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:win: repair test command "testchmod": correct load module (ADVAPI32 for x86/x64) and fix readonly mask (don't deny DELETE mask, test cleanup should be able to delete entry)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-7a9dc52b29
Files: files | file ages | folders
SHA3-256:a4746b4c9f544c34bfa11296194796495ddd1524461778083f390d467fa9973e
User & Date: sebres 2018-11-21 10:00:54
Context
2018-11-22
12:45
prepare merge: TclJoinPath is in internal API (MODULE_SCOPE) since 8.6 and static (used locally in t... Closed-Leaf check-in: fba9c8383c user: sebres tags: bug-7a9dc52b29
2018-11-21
10:00
win: repair test command "testchmod": correct load module (ADVAPI32 for x86/x64) and fix readonly ma... check-in: a4746b4c9f user: sebres tags: bug-7a9dc52b29
2018-11-20
20:56
win: fixed pwd-related test-cases in winPipe.test: several test-cases expect current directory equal... check-in: 8125c3109a user: sebres tags: bug-7a9dc52b29
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to win/tclWinTest.c.

416
417
418
419
420
421
422

423
424
425

426
427
428
429
430
431
432
...
462
463
464
465
466
467
468


469

470
471
472
473
474
475
476
...
657
658
659
660
661
662
663
664

665
666
667
668

669
670
671
672
673
674
675
    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
	    | FILE_ADD_SUBDIRECTORY | FILE_WRITE_EA | FILE_APPEND_DATA
	    | FILE_WRITE_DATA | DELETE;


    /*
     * References to security functions (only available on NT and later).
     */

    static getSidLengthRequiredDef getSidLengthRequiredProc;
    static initializeSidDef initializeSidProc;
................................................................................
     * One time initialization, dynamically load Windows NT features
     */

    if (!initialized) {
	TCL_DECLARE_MUTEX(initializeMutex)
	Tcl_MutexLock(&initializeMutex);
	if (!initialized) {


	    HMODULE handle = GetModuleHandle(TEXT("ADVAPI"));


	    if (handle != NULL) {
		setNamedSecurityInfoProc = (setNamedSecurityInfoADef)
			GetProcAddress(handle, "SetNamedSecurityInfoA");
		getFileSecurityProc = (getFileSecurityADef)
			GetProcAddress(handle, "GetFileSecurityA");
		getAceProc = (getAceDef)
................................................................................
	if (!addAceProc(newAcl, ACL_REVISION, MAXDWORD, (PACL *)pACE2,
		((PACE_HEADER) pACE2)->AceSize)) {
	    goto done;
	}
    }

    /*
     * Apply the new ACL.

     */

    if (set_readOnly == acl_readOnly_found || setNamedSecurityInfoProc(
	    (LPSTR) nativePath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,

	    NULL, NULL, newAcl, NULL) == ERROR_SUCCESS) {
	res = 0;
    }

  done:
    if (secDesc) {
	ckfree((char *) secDesc);







>


|
>







 







>
>
|
>







 







|
>



|
>







416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
...
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
...
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
    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;
    /* don't deny DELETE mask (reset writable only, allow test-cases cleanup) */
    static const DWORD readOnlyMask = FILE_DELETE_CHILD | FILE_ADD_FILE
	    | FILE_ADD_SUBDIRECTORY | FILE_WRITE_EA | FILE_APPEND_DATA
	    | FILE_WRITE_DATA
	    /* | DELETE */;

    /*
     * References to security functions (only available on NT and later).
     */

    static getSidLengthRequiredDef getSidLengthRequiredProc;
    static initializeSidDef initializeSidProc;
................................................................................
     * One time initialization, dynamically load Windows NT features
     */

    if (!initialized) {
	TCL_DECLARE_MUTEX(initializeMutex)
	Tcl_MutexLock(&initializeMutex);
	if (!initialized) {
	    HMODULE handle = GetModuleHandle(TEXT("ADVAPI32"));
	    if (handle == NULL) {
	    	handle = GetModuleHandle(TEXT("ADVAPI"));
	    }

	    if (handle != NULL) {
		setNamedSecurityInfoProc = (setNamedSecurityInfoADef)
			GetProcAddress(handle, "SetNamedSecurityInfoA");
		getFileSecurityProc = (getFileSecurityADef)
			GetProcAddress(handle, "GetFileSecurityA");
		getAceProc = (getAceDef)
................................................................................
	if (!addAceProc(newAcl, ACL_REVISION, MAXDWORD, (PACL *)pACE2,
		((PACE_HEADER) pACE2)->AceSize)) {
	    goto done;
	}
    }

    /*
     * Apply the new ACL. Note PROTECTED_DACL_SECURITY_INFORMATION can be used
     * to remove inherited ACL (we need to overwrite the default ACL's in this case)
     */

    if (set_readOnly == acl_readOnly_found || setNamedSecurityInfoProc(
	    (LPSTR) nativePath, SE_FILE_OBJECT, 
	    DACL_SECURITY_INFORMATION /*| PROTECTED_DACL_SECURITY_INFORMATION*/,
	    NULL, NULL, newAcl, NULL) == ERROR_SUCCESS) {
	res = 0;
    }

  done:
    if (secDesc) {
	ckfree((char *) secDesc);