本文整理汇总了Python中os.geteuid方法的典型用法代码示例。如果您正苦于以下问题:Python os.geteuid方法的具体用法?Python os.geteuid怎么用?Python os.geteuid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.geteuid方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: verify_environment
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
def verify_environment(pids_to_show):
if os.geteuid() != 0 and not pids_to_show:
sys.stderr.write("Sorry, root permission required, or specify pids with -p\n")
sys.stderr.close()
sys.exit(1)
try:
kernel_ver()
except (IOError, OSError):
val = sys.exc_info()[1]
if val.errno == errno.ENOENT:
sys.stderr.write(
"Couldn't access " + proc.path('') + "\n"
"Only GNU/Linux and FreeBSD (with linprocfs) are supported\n")
sys.exit(2)
else:
raise
示例2: chown
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
def chown(self, tarinfo, targetpath):
"""Set owner of targetpath according to tarinfo.
"""
if pwd and hasattr(os, "geteuid") and os.geteuid() == 0:
# We have to be root to do so.
try:
g = grp.getgrnam(tarinfo.gname)[2]
except KeyError:
g = tarinfo.gid
try:
u = pwd.getpwnam(tarinfo.uname)[2]
except KeyError:
u = tarinfo.uid
try:
if tarinfo.issym() and hasattr(os, "lchown"):
os.lchown(targetpath, u, g)
else:
if sys.platform != "os2emx":
os.chown(targetpath, u, g)
except EnvironmentError as e:
raise ExtractError("could not change owner")
示例3: Pro_request
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
def Pro_request(self):
self.time_control = None
if self.time_scan.currentText() == "10s":self.time_control = 300
elif self.time_scan.currentText() == "20s":self.time_control = 400
elif self.time_scan.currentText() == "30s":self.time_control = 600
if self.get_placa.currentText() == "":
QMessageBox.information(self, "Network Adapter", 'Network Adapter Not found try again.')
else:
if not geteuid() == 0:
QMessageBox.information(self, "Permission Denied", 'the tool must be run as root try again.')
else:
comando = "ifconfig"
proc = Popen(comando,stdout=PIPE, shell=True)
data = proc.communicate()[0]
if search(self.interface, data):
sniff(iface=self.interface,prn=self.sniff_probe, count=self.time_control)
system("clear")
else:
system("airmon-ng start %s" %(self.get_placa.currentText()))
sniff(iface=self.interface,prn=self.sniff_probe, count=self.time_control)
system("clear")
示例4: ffwHonggmode
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
def ffwHonggmode(configManager, args):
config = configManager.config
if not configManager.checkFuzzRequirements(config, 'hongg'):
return False
if args.honggcov == "hw" or config["honggcov"] == "hw":
config["honggmode_option"] = "--linux_perf_bts_edge"
if os.geteuid() != 0:
logging.error('"--honggcov hw" hardware coverage requires root')
return
elif args.honggcov == "sw" or config["honggcov"] == "sw":
config["honggmode_option"] = None # sw is default
else:
config["honggmode_option"] = None
honggMaster = HonggMaster(config)
utils.setupTmpfs(config, enable=True)
honggMaster.doFuzz()
utils.setupTmpfs(config, enable=False)
示例5: check_path_owner
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
def check_path_owner(path):
# If we don't have a way to check the effective uid of this process, then
# we'll just assume that we own the directory.
if not hasattr(os, "geteuid"):
return True
previous = None
while path != previous:
if os.path.lexists(path):
# Check if path is writable by current user.
if os.geteuid() == 0:
# Special handling for root user in order to handle properly
# cases where users use sudo without -H flag.
try:
path_uid = get_path_uid(path)
except OSError:
return False
return path_uid == 0
else:
return os.access(path, os.W_OK)
else:
previous, path = path, os.path.dirname(path)
示例6: username
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
def username(self):
"""
str: Some services require authentication in order to connect to the
service, in which case the appropriate username can be specified. If not
specified at instantiation, your local login name will be used. If `True`
was provided, you will be prompted to type your username at runtime as
necessary. If `False` was provided, then `None` will be returned. You can
specify a different username at runtime using: `duct.username = '<username>'`.
"""
if self._username is True:
if 'username' not in self.__cached_auth:
self.__cached_auth['username'] = input("Enter username for '{}':".format(self.name))
return self.__cached_auth['username']
elif self._username is False:
return None
elif not self._username:
try:
username = os.getlogin()
except OSError:
username = pwd.getpwuid(os.geteuid()).pw_name
return username
return self._username
示例7: tearDown
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
def tearDown(self):
dist_coverage_path = os.path.join(MARS_ROOT, '.dist-coverage')
if os.path.exists(dist_coverage_path):
# change ownership of coverage files
if find_executable('sudo'):
proc = subprocess.Popen(['sudo', '-n', 'chown', '-R', '%d:%d' % (os.geteuid(), os.getegid()),
dist_coverage_path], shell=False)
proc.wait()
# rewrite paths in coverage result files
for fn in glob.glob(os.path.join(dist_coverage_path, '.coverage.*')):
if 'COVERAGE_FILE' in os.environ:
new_cov_file = os.environ['COVERAGE_FILE'] \
+ os.path.basename(fn).replace('.coverage', '')
else:
new_cov_file = fn.replace('.dist-coverage' + os.sep, '')
shutil.copyfile(fn, new_cov_file)
shutil.rmtree(dist_coverage_path)
示例8: tearDown
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
def tearDown(self):
time.sleep(5)
dist_coverage_path = os.path.join(MARS_ROOT, '.dist-coverage')
if os.path.exists(dist_coverage_path):
# change ownership of coverage files
if find_executable('sudo'):
proc = subprocess.Popen(['sudo', '-n', 'chown', '-R', '%d:%d' % (os.geteuid(), os.getegid()),
dist_coverage_path], shell=False)
proc.wait()
# rewrite paths in coverage result files
for fn in glob.glob(os.path.join(dist_coverage_path, '.coverage.*')):
cov_db = sqlite3.connect(fn)
c = cov_db.cursor()
c.execute('UPDATE file SET path=REPLACE(path, \'%s\', \'\')' % (MARS_ROOT + os.path.sep))
cov_db.commit()
cov_db.close()
if 'COVERAGE_FILE' in os.environ:
new_cov_file = os.environ['COVERAGE_FILE'] \
+ os.path.basename(fn).replace('.coverage', '')
else:
new_cov_file = fn.replace('.dist-coverage' + os.sep, '')
shutil.copyfile(fn, new_cov_file)
shutil.rmtree(dist_coverage_path)
示例9: check_enableusersite
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
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
示例10: chown
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
def chown(self, tarinfo, targetpath):
"""Set owner of targetpath according to tarinfo.
"""
if pwd and hasattr(os, "geteuid") and os.geteuid() == 0:
# We have to be root to do so.
try:
g = grp.getgrnam(tarinfo.gname)[2]
except KeyError:
g = tarinfo.gid
try:
u = pwd.getpwnam(tarinfo.uname)[2]
except KeyError:
u = tarinfo.uid
try:
if tarinfo.issym() and hasattr(os, "lchown"):
os.lchown(targetpath, u, g)
else:
if sys.platform != "os2emx":
os.chown(targetpath, u, g)
except EnvironmentError, e:
raise ExtractError("could not change owner")
示例11: chown
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
def chown(self, tarinfo, targetpath, numeric_owner):
"""Set owner of targetpath according to tarinfo. If numeric_owner
is True, use .gid/.uid instead of .gname/.uname.
"""
if pwd and hasattr(os, "geteuid") and os.geteuid() == 0:
# We have to be root to do so.
if numeric_owner:
g = tarinfo.gid
u = tarinfo.uid
else:
try:
g = grp.getgrnam(tarinfo.gname)[2]
except KeyError:
g = tarinfo.gid
try:
u = pwd.getpwnam(tarinfo.uname)[2]
except KeyError:
u = tarinfo.uid
try:
if tarinfo.issym() and hasattr(os, "lchown"):
os.lchown(targetpath, u, g)
else:
os.chown(targetpath, u, g)
except OSError as e:
raise ExtractError("could not change owner")
示例12: check_enableusersite
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
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
示例13: current_username
# 需要导入模块: import os [as 别名]
# 或者: from os import geteuid [as 别名]
def current_username():
"""Retrieve the username of the current user.
:rtype: str
:return: The username of the current user.
>>> from dpa.user import current_username
>>> username = current_username()
>>> print username
'jtomlin'
"""
# see this StackOverflow thread for a discussion on a portable way to
# get the current user name: http://tinyurl.com/ykecvzc
if pwd:
return pwd.getpwuid(os.geteuid()).pw_name
else:
return getpass.getuser()
# -----------------------------------------------------------------------------
# Public Classes:
# -----------------------------------------------------------------------------