Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 89a42b588b97950b6807dacc7e016f881a500f3d
Ticket: 1193497fffffffffffffffffffffffffffffffff
file writable lies for certain XP directories
User & Date: jfg118 on 2005-10-21 06:08:44
Changes

  1. icomment:
    Logged In: YES 
    user_id=1266631
    
    Below is a patch generated against the Tcl 8.4.11 source.
    The specific file is win/tclWinFile.c rev 1.44.2.12 .  The
    patch implements and "NativeIsWritable" function.  The
    function needs to have the wide char implementation added.
    The only call which needs to be updated is the
    GetFileSecurity function which needs an entry in the
    tclWinProcs defnition.  The patch falls back to the old
    implementation for wide char paths. 
    
    <     if ((mode & W_OK) && (attr & FILE_ATTRIBUTE_READONLY)) {
    ---
    >     if ((mode & W_OK) && !NativeIsWritable(nativePath)) {
    1365a1367,1442
    >  * NativeIsWritable --
    >  *
    >  *Determines if a path is writable.  On windows this 
    >  *requires more than a simple read only flag check for
    directories
    >  *      because windows uses this as a flag to customize
    the folder
    >  *      options.  BUG 1193497
    >  *
    >  * Results:
    >  *1 = writable, 0 = not.
    >  *
    > 
    *----------------------------------------------------------------------
    >  */
    > static int
    > NativeIsWritable(nativePath)
    >     CONST TCHAR *nativePath;
    > {
    >   char psd_buf[1024], *psd_ptr = psd_buf, *psd_alloc = 0;
    >   DWORD sd_rlen;
    >   HANDLE hToken = NULL;
    >   int retVal = 0;
    > 
    >   if (tclWinProcs->useWide) {
    >     /* not implemented  -- fall back to old implementation */
    >     return
    ((*tclWinProcs->getFileAttributesProc)(nativePath) &
    FILE_ATTRIBUTE_READONLY) ? 0 : 1;
    >   }
    > 
    >   if (!GetFileSecurity(nativePath,
    >                        OWNER_SECURITY_INFORMATION
    >                        | GROUP_SECURITY_INFORMATION
    >                        | DACL_SECURITY_INFORMATION,
    >                        psd_buf, sizeof(psd_buf), &sd_rlen)) {
    >     return 0; /* Failed ... */
    >   }
    >   if (sizeof(psd_buf) < sd_rlen) {
    >     DWORD psd_alloc_rlen;
    >     psd_alloc = (char *)ckalloc(sd_rlen);
    >     if (!GetFileSecurity(nativePath,
    >                          OWNER_SECURITY_INFORMATION
    >                          | GROUP_SECURITY_INFORMATION
    >                          | DACL_SECURITY_INFORMATION,
    >                          psd_alloc, sd_rlen, &psd_alloc_rlen)
    >         || sd_rlen  < psd_alloc_rlen) {
    >       ckfree(psd_alloc);
    >       return 0; /* Failed .... */
    >     }
    >     psd_ptr = psd_alloc;
    >     sd_rlen = psd_alloc_rlen;
    >   }
    >   if ( OpenProcessToken ( GetCurrentProcess ( ),
    TOKEN_DUPLICATE, &hToken ) ) {
    >     HANDLE hIToken = NULL;
    >     BOOL status = DuplicateToken (hToken,
    SecurityIdentification, &hIToken);
    >     CloseHandle (hToken);
    >     
    >     if (status) {
    >       GENERIC_MAPPING mapping = { FILE_GENERIC_READ,
    >                                   FILE_GENERIC_WRITE,
    >                                   FILE_GENERIC_EXECUTE,
    >                                   FILE_ALL_ACCESS };
    >       char pbuf[sizeof (PRIVILEGE_SET) + 3 * sizeof
    (LUID_AND_ATTRIBUTES)];
    >       DWORD plength = sizeof(pbuf), granted; 
    >       retVal = AccessCheck (psd_ptr, hIToken,
    FILE_WRITE_DATA, &mapping,
    >                             (PPRIVILEGE_SET) pbuf,
    &plength, &granted, &status) ? 1 : 0;
    >       
    >       CloseHandle(hIToken);
    >     }
    >   }
    > 
    >   if (psd_alloc)
    >     ckfree(psd_alloc);
    > 
    >   return retVal;
    > }
    > /*
    > 
    *----------------------------------------------------------------------
    >  *
    
    
    
  2. login: "jfg118"
  3. mimetype: "text/plain"
  4. username: "jfg118"