Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ironically, I have just run into this very same need earlier today.</p> <p>In my case, the answer came down to what level of permission granularity I need on Windows, versus Linux. In my case, I only care about User, Group, and Other permission on Linux. On Windows, the basic Read/Write All permission leftover from DOS is good enough for me, i.e. I don't need to deal with ACL on Windows.</p> <p>Generally speaking, Windows has two privilege models: the basic DOS model and the newer access control model. Under the DOS model there is one type of privilege: write privilege. All files can be read, so there is no way to turn off read permission (because it doesn't exist). There is also no concept of execute permission. If a file can be read (answer is yes) and it is binary, then it can be executed; otherwise it can't.</p> <p>The basic DOS model is sufficient for most Windows environments, i.e. environments where the system is used by a single user in a physical location that can be considered relatively secure. The access control model is more complex by several orders of magnitude.</p> <p>The access control model uses access control lists (ACL) to grant privileges. Privileges can only be granted by a process with the necessary privileges. This model not only allows the control of User, Group, and Other with Read, Write, and Execute permission, but it also allows control of files over the network and between Windows domains. (You can also get this level of insanity on Unix systems with PAM.)</p> <p><em>Note: The Access Control model is only available on NTFS partitions, if you are using FAT partitions you are SOL.</em></p> <p>Using ACL is a big pain in the ass. It is not a trivial undertaking and it will require you to learn not just ACL but also all about Security Descriptors, Access Tokens, and a whole lot of other advanced Windows security concepts.</p> <p>Fortunately for me, for my current needs, I don't need the true security that the access control model provides. I can get by with basically pretending to set permissions on Windows, as long as I really set permissions on Linux.</p> <p>Windows supports what they call an "ISO C++ conformant" version of chmod(2). This API is called _chmod, and it is similar to chmod(2), but more limited and not type or name compatible (of course). Windows also has a deprecated chmod, so you can't simply add chmod to Windows and use the straight chmod(2) on Linux.</p> <p>I wrote the following:</p> <pre><code>#include &lt;sys/stat.h&gt; #include &lt;sys/types.h&gt; #ifdef _WIN32 # include &lt;io.h&gt; typedef int mode_t; /// @Note If STRICT_UGO_PERMISSIONS is not defined, then setting Read for any /// of User, Group, or Other will set Read for User and setting Write /// will set Write for User. Otherwise, Read and Write for Group and /// Other are ignored. /// /// @Note For the POSIX modes that do not have a Windows equivalent, the modes /// defined here use the POSIX values left shifted 16 bits. static const mode_t S_ISUID = 0x08000000; ///&lt; does nothing static const mode_t S_ISGID = 0x04000000; ///&lt; does nothing static const mode_t S_ISVTX = 0x02000000; ///&lt; does nothing static const mode_t S_IRUSR = mode_t(_S_IREAD); ///&lt; read by user static const mode_t S_IWUSR = mode_t(_S_IWRITE); ///&lt; write by user static const mode_t S_IXUSR = 0x00400000; ///&lt; does nothing # ifndef STRICT_UGO_PERMISSIONS static const mode_t S_IRGRP = mode_t(_S_IREAD); ///&lt; read by *USER* static const mode_t S_IWGRP = mode_t(_S_IWRITE); ///&lt; write by *USER* static const mode_t S_IXGRP = 0x00080000; ///&lt; does nothing static const mode_t S_IROTH = mode_t(_S_IREAD); ///&lt; read by *USER* static const mode_t S_IWOTH = mode_t(_S_IWRITE); ///&lt; write by *USER* static const mode_t S_IXOTH = 0x00010000; ///&lt; does nothing # else static const mode_t S_IRGRP = 0x00200000; ///&lt; does nothing static const mode_t S_IWGRP = 0x00100000; ///&lt; does nothing static const mode_t S_IXGRP = 0x00080000; ///&lt; does nothing static const mode_t S_IROTH = 0x00040000; ///&lt; does nothing static const mode_t S_IWOTH = 0x00020000; ///&lt; does nothing static const mode_t S_IXOTH = 0x00010000; ///&lt; does nothing # endif static const mode_t MS_MODE_MASK = 0x0000ffff; ///&lt; low word static inline int my_chmod(const char * path, mode_t mode) { int result = _chmod(path, (mode &amp; MS_MODE_MASK)); if (result != 0) { result = errno; } return (result); } #else static inline int my_chmod(const char * path, mode_t mode) { int result = chmod(path, mode); if (result != 0) { result = errno; } return (result); } #endif </code></pre> <p>It's important to remember that my solution only provides DOS type security. This is also known as no security, but it is the amount of security that most apps give you on Windows.</p> <p>Also, under my solution, if you don't define STRICT_UGO_PERMISSIONS, when you give a permission to group or other (or remove it for that matter), you are really changing the owner. If you didn't want to do that, but you still didn't need full Windows ACL permissions, just define STRICT_UGO_PERMISSIONS.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload