Skip to main content

os.access() alternative which can check access for other users

Project description

other_access

other_access is more flexible implementation of os.access().

While os.access() checks access for current user only, other_access / oaccess can check access for other users/groups. In other words, other_access will return same result, no matter which user runs it (Supposing current user can os.stat() that file).

For example, root user can use other_access.oaccess(path, os.R_OK, 'www-data') to ensure files are readable by www-data user.

Limitation

otheraccess does not supports filesystem ACL

Usage

other_access(path, mode, uid, gids=None) - main function. similar to os.access(), but checks for other user (uid) and list of groups (gids). User and group id's are integer (not names).

oaccess(path, mode, user, groups) - wrapper for other_access which takes names for user/groups, converts it to numerical uid/gids and calls other_access()

Examples

Lets use /etc/shadow for example:

-rw-r----- 1 root shadow 1841 Jun  2 04:07 /etc/shadow
import os
from other_access import oaccess

# user root can read and write
assert(oaccess('/etc/shadow', os.R_OK | os.W_OK, 'root') == True)

# group shadow can read
assert(oaccess('/etc/shadow', os.R_OK, 'nobody', ['shadow']) == True)

# Other can check existence of file, but cannot read
assert(oaccess('/etc/shadow', os.F_OK, 'nobody') == True)
assert(oaccess('/etc/shadow', os.R_OK, 'nobody') == False)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

other_access-0.0.2-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

Details for the file other_access-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: other_access-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 2.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.3

File hashes

Hashes for other_access-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8a29f685d31b836455ecae56142f75606094d1a4aca334cde1e73e98e9fc1fd0
MD5 2986abfff6ce541cce0ff4cdf6dd6a53
BLAKE2b-256 32ea88b3cb861bf1197dbe8b8e770703b81a3b20fe4ef614527e1ea156debb16

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page