mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
bpo-37400: pythoninfo logs getpwuid and getgrouplist (GH-14373)
test.pythoninfo now also logs pwd.getpwuid(os.getuid()) and os.getgrouplist(). Extract also os.getrandom() test to run it first.
This commit is contained in:
parent
de9b606c90
commit
9cb274114c
1 changed files with 65 additions and 30 deletions
|
@ -161,6 +161,25 @@ def collect_builtins(info_add):
|
||||||
info_add('builtins.float.double_format', float.__getformat__("double"))
|
info_add('builtins.float.double_format', float.__getformat__("double"))
|
||||||
|
|
||||||
|
|
||||||
|
def collect_urandom(info_add):
|
||||||
|
import os
|
||||||
|
|
||||||
|
if hasattr(os, 'getrandom'):
|
||||||
|
# PEP 524: Check if system urandom is initialized
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
os.getrandom(1, os.GRND_NONBLOCK)
|
||||||
|
state = 'ready (initialized)'
|
||||||
|
except BlockingIOError as exc:
|
||||||
|
state = 'not seeded yet (%s)' % exc
|
||||||
|
info_add('os.getrandom', state)
|
||||||
|
except OSError as exc:
|
||||||
|
# Python was compiled on a more recent Linux version
|
||||||
|
# than the current Linux kernel: ignore OSError(ENOSYS)
|
||||||
|
if exc.errno != errno.ENOSYS:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
def collect_os(info_add):
|
def collect_os(info_add):
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -180,16 +199,16 @@ def collect_os(info_add):
|
||||||
)
|
)
|
||||||
copy_attributes(info_add, os, 'os.%s', attributes, formatter=format_attr)
|
copy_attributes(info_add, os, 'os.%s', attributes, formatter=format_attr)
|
||||||
|
|
||||||
call_func(info_add, 'os.cwd', os, 'getcwd')
|
call_func(info_add, 'os.getcwd', os, 'getcwd')
|
||||||
|
|
||||||
call_func(info_add, 'os.uid', os, 'getuid')
|
call_func(info_add, 'os.getuid', os, 'getuid')
|
||||||
call_func(info_add, 'os.gid', os, 'getgid')
|
call_func(info_add, 'os.getgid', os, 'getgid')
|
||||||
call_func(info_add, 'os.uname', os, 'uname')
|
call_func(info_add, 'os.uname', os, 'uname')
|
||||||
|
|
||||||
def format_groups(groups):
|
def format_groups(groups):
|
||||||
return ', '.join(map(str, groups))
|
return ', '.join(map(str, groups))
|
||||||
|
|
||||||
call_func(info_add, 'os.groups', os, 'getgroups', formatter=format_groups)
|
call_func(info_add, 'os.getgroups', os, 'getgroups', formatter=format_groups)
|
||||||
|
|
||||||
if hasattr(os, 'getlogin'):
|
if hasattr(os, 'getlogin'):
|
||||||
try:
|
try:
|
||||||
|
@ -202,7 +221,7 @@ def collect_os(info_add):
|
||||||
info_add("os.login", login)
|
info_add("os.login", login)
|
||||||
|
|
||||||
call_func(info_add, 'os.cpu_count', os, 'cpu_count')
|
call_func(info_add, 'os.cpu_count', os, 'cpu_count')
|
||||||
call_func(info_add, 'os.loadavg', os, 'getloadavg')
|
call_func(info_add, 'os.getloadavg', os, 'getloadavg')
|
||||||
|
|
||||||
# Environment variables used by the stdlib and tests. Don't log the full
|
# Environment variables used by the stdlib and tests. Don't log the full
|
||||||
# environment: filter to list to not leak sensitive information.
|
# environment: filter to list to not leak sensitive information.
|
||||||
|
@ -286,20 +305,32 @@ def collect_os(info_add):
|
||||||
os.umask(mask)
|
os.umask(mask)
|
||||||
info_add("os.umask", '%03o' % mask)
|
info_add("os.umask", '%03o' % mask)
|
||||||
|
|
||||||
if hasattr(os, 'getrandom'):
|
|
||||||
# PEP 524: Check if system urandom is initialized
|
def collect_pwd(info_add):
|
||||||
try:
|
try:
|
||||||
try:
|
import pwd
|
||||||
os.getrandom(1, os.GRND_NONBLOCK)
|
except ImportError:
|
||||||
state = 'ready (initialized)'
|
return
|
||||||
except BlockingIOError as exc:
|
import os
|
||||||
state = 'not seeded yet (%s)' % exc
|
|
||||||
info_add('os.getrandom', state)
|
uid = os.getuid()
|
||||||
except OSError as exc:
|
try:
|
||||||
# Python was compiled on a more recent Linux version
|
entry = pwd.getpwuid(uid)
|
||||||
# than the current Linux kernel: ignore OSError(ENOSYS)
|
except KeyError:
|
||||||
if exc.errno != errno.ENOSYS:
|
entry = None
|
||||||
raise
|
|
||||||
|
info_add('pwd.getpwuid(%s)'% uid,
|
||||||
|
entry if entry is not None else '<KeyError>')
|
||||||
|
|
||||||
|
if entry is None:
|
||||||
|
# there is nothing interesting to read if the current user identifier
|
||||||
|
# is not the password database
|
||||||
|
return
|
||||||
|
|
||||||
|
if hasattr(os, 'getgrouplist'):
|
||||||
|
groups = os.getgrouplist(entry.pw_name, entry.pw_gid)
|
||||||
|
groups = ', '.join(map(str, groups))
|
||||||
|
info_add('os.getgrouplist', groups)
|
||||||
|
|
||||||
|
|
||||||
def collect_readline(info_add):
|
def collect_readline(info_add):
|
||||||
|
@ -625,31 +656,35 @@ def collect_info(info):
|
||||||
info_add = info.add
|
info_add = info.add
|
||||||
|
|
||||||
for collect_func in (
|
for collect_func in (
|
||||||
# collect_os() should be the first, to check the getrandom() status
|
# collect_urandom() must be the first, to check the getrandom() status.
|
||||||
collect_os,
|
# Other functions may block on os.urandom() indirectly and so change
|
||||||
|
# its state.
|
||||||
|
collect_urandom,
|
||||||
|
|
||||||
collect_builtins,
|
collect_builtins,
|
||||||
|
collect_cc,
|
||||||
|
collect_datetime,
|
||||||
|
collect_decimal,
|
||||||
|
collect_expat,
|
||||||
collect_gdb,
|
collect_gdb,
|
||||||
|
collect_gdbm,
|
||||||
|
collect_get_config,
|
||||||
collect_locale,
|
collect_locale,
|
||||||
|
collect_os,
|
||||||
collect_platform,
|
collect_platform,
|
||||||
|
collect_pwd,
|
||||||
collect_readline,
|
collect_readline,
|
||||||
|
collect_resource,
|
||||||
collect_socket,
|
collect_socket,
|
||||||
collect_sqlite,
|
collect_sqlite,
|
||||||
collect_ssl,
|
collect_ssl,
|
||||||
|
collect_subprocess,
|
||||||
collect_sys,
|
collect_sys,
|
||||||
collect_sysconfig,
|
collect_sysconfig,
|
||||||
|
collect_testcapi,
|
||||||
collect_time,
|
collect_time,
|
||||||
collect_datetime,
|
|
||||||
collect_tkinter,
|
collect_tkinter,
|
||||||
collect_zlib,
|
collect_zlib,
|
||||||
collect_expat,
|
|
||||||
collect_decimal,
|
|
||||||
collect_testcapi,
|
|
||||||
collect_resource,
|
|
||||||
collect_cc,
|
|
||||||
collect_gdbm,
|
|
||||||
collect_get_config,
|
|
||||||
collect_subprocess,
|
|
||||||
|
|
||||||
# Collecting from tests should be last as they have side effects.
|
# Collecting from tests should be last as they have side effects.
|
||||||
collect_test_socket,
|
collect_test_socket,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue