Home > front end >  Windows folder permissions are changed when entering the tab "Customize", read by _wstat64
Windows folder permissions are changed when entering the tab "Customize", read by _wstat64

Time:01-20

The folder permissions on Windows 10 are changed when entering the properties tab "Customize".

Steps to reproduce:

  • Create a new empty folder, e.g. D:\folder_name.
  • Compile attached program: cl.exe stat_test.cxx
  • Run the compiled program: stat_test.exe D:\folder_name

The output is:

path D:\folder_name, st.st_mode & S_IWRITE = 128

Now right click on D:\folder_name, choose properties, and then choose the tab "Customize" and just click ok.

Run the compiled program:

stat_test.exe D:\folder_name

The output is:

path D:\folder_name, st.st_mode & S_IWRITE = 0

When looking at the ACL before and after the action they are identical! A new file desktop.ini is created inside D:\folder_name.

Now it is impossible to get the old behavior back (path D:\folder_name, st.st_mode & S_IWRITE = 128)

Only within msys64 using chmod 777 "D:\folder_name" is able to restore old behavior.

Can someone explain what Windows does here?

How can this be avoided? How can it be restored using Windows tools only?

Ps. We also tested with c 17 filelibrary with the same outcome.

C code to read file permissions:

//compile with cl.exe stat_test.cxx
#include <string>
#include <windows.h>

int main(int argc, char** argv) {
    std::string path = std::string(argv[1]);
    //get wide string size of path
    size_t requiredSize = MultiByteToWideChar(CP_UTF8, 0, path.c_str(), -1, NULL, 0);
    //initialize wide string to zero
    std::wstring wide(requiredSize, '\0');
    //convert path to wide string
    MultiByteToWideChar(CP_UTF8, 0, path.c_str(), -1, &wide[0], wide.size());

    //get stat status
    struct _stat64 st;
    _wstat64(wide.c_str(), &st);

    //check if writable
    int flag = st.st_mode & S_IWRITE;

    printf("path %s, st.st_mode & S_IWRITE = %d\n", argv[1], flag);
    return 0;
}

CodePudding user response:

A folder needs the read-only and/or system attribute to be set for the shell to parse the desktop.ini inside the folder.

  • Related