Python os.getgid() Examples
The following are 30
code examples of os.getgid().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: site.py From telegram-robot-rss with Mozilla Public License 2.0 | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if hasattr(sys, 'flags') and getattr(sys.flags, 'no_user_site', False): return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #2
Source File: site.py From ironpython2 with Apache License 2.0 | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if sys.flags.no_user_site: return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #3
Source File: test_posix.py From ironpython2 with Apache License 2.0 | 6 votes |
def testNoArgFunctions(self): # test posix functions which take no arguments and have # no side-effects which we need to cleanup (e.g., fork, wait, abort) NO_ARG_FUNCTIONS = [ "ctermid", "getcwd", "getcwdu", "uname", "times", "getloadavg", "tmpnam", "getegid", "geteuid", "getgid", "getgroups", "getpid", "getpgrp", "getppid", "getuid", ] with warnings.catch_warnings(): warnings.filterwarnings("ignore", "", DeprecationWarning) for name in NO_ARG_FUNCTIONS: posix_func = getattr(posix, name, None) if posix_func is not None: posix_func() self.assertRaises(TypeError, posix_func, 1)
Example #4
Source File: site.py From meddle with MIT License | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if sys.flags.no_user_site: return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #5
Source File: site.py From kobo-predict with BSD 2-Clause "Simplified" License | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if hasattr(sys, 'flags') and getattr(sys.flags, 'no_user_site', False): return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #6
Source File: downloader.py From polyglot with GNU General Public License v3.0 | 6 votes |
def is_writable(path): # Ensure that it exists. if not os.path.exists(path): return False # If we're on a posix system, check its permissions. if hasattr(os, 'getuid'): statdata = os.stat(path) perm = stat.S_IMODE(statdata.st_mode) # is it world-writable? if (perm & 0o002): return True # do we own it? elif statdata.st_uid == os.getuid() and (perm & 0o200): return True # are we in a group that can write to it? elif (statdata.st_gid in [os.getgid()] + os.getgroups()) and (perm & 0o020): return True # otherwise, we can't write to it. else: return False # Otherwise, we'll assume it's writable. # [xx] should we do other checks on other platforms? return True
Example #7
Source File: util.py From black-widow with GNU General Public License v3.0 | 6 votes |
def whoami(check_sudo: bool = True) -> dict: """ Get the dictionary of current user info :param check_sudo: True, if you want get the user which executed sudo command :return: A dictionary with current user info """ name = None uid = None gid = None sudo = True if check_sudo: name = os.environ.get('SUDO_USER') uid = os.environ.get('SUDO_UID') gid = os.environ.get('SUDO_GID') if name is None: sudo = False name = getpass.getuser() uid = os.getuid() gid = os.getgid() return { 'name': str(name), 'uid': int(uid), 'gid': int(gid), 'sudo': sudo }
Example #8
Source File: evaluator.py From armory with MIT License | 6 votes |
def _run_jupyter(self, runner: ArmoryInstance, ports: dict) -> None: user_id = os.getuid() if os.name != "nt" else 0 group_id = os.getgid() if os.name != "nt" else 0 port = list(ports.keys())[0] lines = [ "About to launch jupyter.", bold("*** To connect on the command line as well, in a new terminal, run:"), bold( f" docker exec -it -u {user_id}:{group_id} {runner.docker_container.short_id} bash" ), bold("*** To gracefully shut down container, press: Ctrl-C"), "", "Jupyter notebook log:", ] logger.info("\n".join(lines)) runner.exec_cmd( f"jupyter lab --ip=0.0.0.0 --port {port} --no-browser --allow-root", user="root", )
Example #9
Source File: test_posix.py From BinderFilter with MIT License | 6 votes |
def testNoArgFunctions(self): # test posix functions which take no arguments and have # no side-effects which we need to cleanup (e.g., fork, wait, abort) NO_ARG_FUNCTIONS = [ "ctermid", "getcwd", "getcwdu", "uname", "times", "getloadavg", "tmpnam", "getegid", "geteuid", "getgid", "getgroups", "getpid", "getpgrp", "getppid", "getuid", ] with warnings.catch_warnings(): warnings.filterwarnings("ignore", "", DeprecationWarning) for name in NO_ARG_FUNCTIONS: posix_func = getattr(posix, name, None) if posix_func is not None: posix_func() self.assertRaises(TypeError, posix_func, 1)
Example #10
Source File: site.py From BinderFilter with MIT License | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if sys.flags.no_user_site: return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #11
Source File: test_posix.py From oss-ftp with MIT License | 6 votes |
def testNoArgFunctions(self): # test posix functions which take no arguments and have # no side-effects which we need to cleanup (e.g., fork, wait, abort) NO_ARG_FUNCTIONS = [ "ctermid", "getcwd", "getcwdu", "uname", "times", "getloadavg", "tmpnam", "getegid", "geteuid", "getgid", "getgroups", "getpid", "getpgrp", "getppid", "getuid", ] with warnings.catch_warnings(): warnings.filterwarnings("ignore", "", DeprecationWarning) for name in NO_ARG_FUNCTIONS: posix_func = getattr(posix, name, None) if posix_func is not None: posix_func() self.assertRaises(TypeError, posix_func, 1)
Example #12
Source File: site.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if hasattr(sys, 'flags') and getattr(sys.flags, 'no_user_site', False): return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #13
Source File: site.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if hasattr(sys, 'flags') and getattr(sys.flags, 'no_user_site', False): return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #14
Source File: site.py From deepWordBug with Apache License 2.0 | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if hasattr(sys, "flags") and getattr(sys.flags, "no_user_site", False): return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #15
Source File: site.py From oss-ftp with MIT License | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if sys.flags.no_user_site: return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #16
Source File: site.py From scylla with Apache License 2.0 | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if hasattr(sys, 'flags') and getattr(sys.flags, 'no_user_site', False): return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #17
Source File: site.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if sys.flags.no_user_site: return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #18
Source File: test_read.py From gitfs with Apache License 2.0 | 6 votes |
def test_get_correct_stats(self): filename = "{}/testing".format(self.current_path) stats = os.stat(filename) filename = "{}/testing".format(self.repo_path) real_stats = os.stat(filename) attrs = { "st_uid": os.getuid(), "st_gid": os.getgid(), "st_mode": 0o100644, "st_ctime": real_stats.st_ctime, "st_mtime": real_stats.st_mtime, "st_atime": real_stats.st_atime, } for name, value in iteritems(attrs): assert getattr(stats, name) == value
Example #19
Source File: test_read.py From gitfs with Apache License 2.0 | 6 votes |
def test_stats(self): commit = self.get_commits_by_date()[0] directory = "{}/history/{}/{}".format(self.mount_path, self.today, commit) filename = "{}/testing".format(directory) stats = os.stat(filename) attrs = {"st_uid": os.getuid(), "st_gid": os.getgid(), "st_mode": 0o100444} for name, value in iteritems(attrs): assert getattr(stats, name) == value st_time = "{} {}".format(self.today, "-".join(commit.split("-")[:-1])) format = "%Y-%m-%d %H-%M-%S" ctime = datetime.fromtimestamp(stats.st_ctime).strftime(format) mtime = datetime.fromtimestamp(stats.st_ctime).strftime(format) assert ctime == st_time assert mtime == st_time
Example #20
Source File: test_checkers.py From validator-collection with MIT License | 6 votes |
def test_is_readable(fs, value, fails, allow_empty): """Test checkers.is_readable()""" expects = not fails if value: fs.create_file(value) if fails and sys.platform in ['linux', 'linux2', 'darwin']: if value: real_uid = os.getuid() real_gid = os.getgid() fake_uid = real_uid fake_gid = real_gid while fake_uid == real_uid: fake_uid = int(random.random() * 100) while fake_gid == real_gid: fake_gid = int(random.random() * 100) os.chown(value, fake_uid, fake_gid) os.chmod(value, 0o027) elif fails and sys.platform in ['win32', 'cygwin']: expects = bool(value) result = checkers.is_readable(value) assert result == expects
Example #21
Source File: site.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if hasattr(sys, 'flags') and getattr(sys.flags, 'no_user_site', False): return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #22
Source File: acehttp.py From HTTPAceProxy with GNU General Public License v3.0 | 6 votes |
def drop_privileges(uid_name='nobody', gid_name='nogroup'): try: import pwd, grp except ImportError: return False # Windows # Get the uid/gid from the name running_uid = pwd.getpwnam(uid_name).pw_uid running_uid_home = pwd.getpwnam(uid_name).pw_dir running_gid = grp.getgrnam(gid_name).gr_gid # Remove group privileges os.setgroups([]) # Try setting the new uid/gid os.setgid(running_gid) os.setuid(running_uid) # Ensure a very conservative umask old_umask = os.umask(int('077', 8)) value = (os.getuid() == running_uid and os.getgid() == running_gid) if value: # could be useful os.environ['HOME'] = running_uid_home logger.info('Changed permissions to: %s: %i, %s, %i' % (uid_name, running_uid, gid_name, running_gid)) return value
Example #23
Source File: site.py From pmatic with GNU General Public License v2.0 | 6 votes |
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if sys.flags.no_user_site: return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
Example #24
Source File: oxfs.py From oxfs with MIT License | 6 votes |
def fuse_main(self, mount_point): self.__class__.__name__ = 'oxfs' if 'Darwin' == self.sys: fuse = FUSE(self, mount_point, foreground=True, nothreads=True, allow_other=True, auto_cache=True, uid=os.getuid(), gid=os.getgid(), defer_permissions=True, kill_on_unmount=True, noappledouble=True, noapplexattr=True, nosuid=True, nobrowse=True, volname=self.host) elif 'Linux' == self.sys: fuse = FUSE(self, mount_point, foreground=True, nothreads=True, allow_other=True, auto_cache=True, uid=os.getuid(), gid=os.getgid(), auto_unmount=True) else: self.logger.error('not supported system, {}'.format(self.sys)) sys.exit()
Example #25
Source File: set_style.py From kano-settings with GNU General Public License v2.0 | 6 votes |
def restore_lxpanel_configuration(self): userid = os.getuid() groupid = os.getgid() original_lxpanel_path = '/etc/skel/.config/lxpanel/' user_lxpanel_path = os.path.join('/home/' + os.getenv('SUDO_USER'), '.config/lxpanel') # remove the current local copy shutil.rmtree(user_lxpanel_path, ignore_errors=True) # re-create the copy from the skeleton shutil.copytree(original_lxpanel_path, user_lxpanel_path, symlinks=False, ignore=None) for root, dirs, files in os.walk(user_lxpanel_path): for name in files: os.chown(os.path.join(root, name), userid, groupid) run_cmd('lxpanelctl restart')
Example #26
Source File: drop_privs_server.py From Pyro5 with MIT License | 5 votes |
def who_is_server(self): return os.getuid(), os.getgid(), pwd.getpwuid(os.getuid()).pw_name
Example #27
Source File: conda.py From the-littlest-jupyterhub with BSD 3-Clause "New" or "Revised" License | 5 votes |
def fix_permissions(prefix): """Fix permissions in the install prefix For all files in the prefix, ensure that: - everything is owned by current user:group - nothing is world-writeable Run after each install command. """ utils.run_subprocess( ["chown", "-R", "{}:{}".format(os.getuid(), os.getgid()), prefix] ) utils.run_subprocess(["chmod", "-R", "o-w", prefix])
Example #28
Source File: _unix.py From django-ftpserver with MIT License | 5 votes |
def __init__(self, file_access_user): self.file_access_user = file_access_user self.gid = os.getgid() self.uid = os.getuid()
Example #29
Source File: test_sftp.py From mock-ssh-server with MIT License | 5 votes |
def test_chown(sftp_client, tmp_dir): test_file = os.path.join(tmp_dir, "foo") open(test_file, "w").write("X") # test process probably can't change file uids # so just test if no exception occurs sftp_client.chown(test_file, os.getuid(), os.getgid())
Example #30
Source File: cli.py From hadoop-test-cluster with BSD 3-Clause "New" or "Revised" License | 5 votes |
def htcluster_startup(image, config, mount=()): image, config = parse_image_config(image.lower(), config.lower()) env = dict(HADOOP_TESTING_FIXUID=str(os.getuid()), HADOOP_TESTING_FIXGID=str(os.getgid()), HADOOP_TESTING_IMAGE=image, HADOOP_TESTING_CONFIG=config) command = ['docker-compose', '-f', COMPOSE_FILE] with map_directories(mount) as extra_args: command.extend(extra_args) command.extend(['up', '-d']) print("Starting cluster with image %s, config %s ..." % (image, config)) dispatch_and_exit(command, env)