OT - file permission checks on Windows

Thomas Heller theller at python.net
Mon Mar 4 14:39:40 EST 2002


"Skip Montanaro" <> wrote in message news:mailman.1015266376.28131.python-list at python.org...
>
> Sorry for the off-topic post.  My entire C programming world these days is
> in the Python community, so I'm completely disconnected from other C
> programming resources.  (Pointer to information about porting Unix code to
> MSVC would be much appreciated.)
>
> Given this simple file access permission code:
>
>     mode_check(struct stat *buf, uid_t uid, uid_t gid,
>                unsigned int umask, unsigned int gmask, unsigned int omask)
>     {
>         /* root always gets to go */
>         if (uid == 0) return 1;
>
>         if (uid == buf->st_uid) return buf->st_mode & umask;
>
>         if (gid == buf->st_gid) return buf->st_mode & gmask;
>
>         return buf->st_mode & omask;
>     }
>
> how would I do this under Windows?  Is the permission model there even
> remotely similar to what I'm used to on Unix systems?

No, I don't think so.

>  I poked around
> posixmodule.c, but it makes next to no use of uids and gids.  As far as I
> can tell, Windows doesn't know about uid_t or gid_t, though it has a struct
> _stat type whose st_uid and st_gid fields are shorts, so I can work around
> the missing types.
>
st_uid and st_gid are always set zo zero under Win NT:
http://msdn.microsoft.com/library/en-us/vclib/html/_crt__stat.2c_._wstat.2c_._stati64.2c_._wstati64.asp

Are you maybe looking for the _access function?
http://msdn.microsoft.com/library/en-us/vclib/html/_crt__access.2c_._waccess.asp

HTH,

Thomas





More information about the Python-list mailing list