| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eccfe78 commit 21e6cb0
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -161,6 +161,25 @@ def collect_builtins(info_add): | |||
| 161 | 161 | info_add('builtins.float.double_format', float.__getformat__("double")) | |
| 162 | 162 | ||
| 163 | 163 | ||
| 164 | + def collect_urandom(info_add): | ||
| 165 | + import os | ||
| 166 | + | ||
| 167 | + if hasattr(os, 'getrandom'): | ||
| 168 | + # PEP 524: Check if system urandom is initialized | ||
| 169 | + try: | ||
| 170 | + try: | ||
| 171 | + os.getrandom(1, os.GRND_NONBLOCK) | ||
| 172 | + state = 'ready (initialized)' | ||
| 173 | + except BlockingIOError as exc: | ||
| 174 | + state = 'not seeded yet (%s)' % exc | ||
| 175 | + info_add('os.getrandom', state) | ||
| 176 | + except OSError as exc: | ||
| 177 | + # Python was compiled on a more recent Linux version | ||
| 178 | + # than the current Linux kernel: ignore OSError(ENOSYS) | ||
| 179 | + if exc.errno != errno.ENOSYS: | ||
| 180 | + raise | ||
| 181 | + | ||
| 182 | + | ||
| 164 | 183 | def collect_os(info_add): | |
| 165 | 184 | import os | |
| 166 | 185 | ||
@@ -180,16 +199,16 @@ def format_attr(attr, value): | |||
| 180 | 199 | ) | |
| 181 | 200 | copy_attributes(info_add, os, 'os.%s', attributes, formatter=format_attr) | |
| 182 | 201 | ||
| 183 | - call_func(info_add, 'os.cwd', os, 'getcwd') | ||
| 202 | + call_func(info_add, 'os.getcwd', os, 'getcwd') | ||
| 184 | 203 | ||
| 185 | - call_func(info_add, 'os.uid', os, 'getuid') | ||
| 186 | - call_func(info_add, 'os.gid', os, 'getgid') | ||
| 204 | + call_func(info_add, 'os.getuid', os, 'getuid') | ||
| 205 | + call_func(info_add, 'os.getgid', os, 'getgid') | ||
| 187 | 206 | call_func(info_add, 'os.uname', os, 'uname') | |
| 188 | 207 | ||
| 189 | 208 | def format_groups(groups): | |
| 190 | 209 | return ', '.join(map(str, groups)) | |
| 191 | 210 | ||
| 192 | - call_func(info_add, 'os.groups', os, 'getgroups', formatter=format_groups) | ||
| 211 | + call_func(info_add, 'os.getgroups', os, 'getgroups', formatter=format_groups) | ||
| 193 | 212 | ||
| 194 | 213 | if hasattr(os, 'getlogin'): | |
| 195 | 214 | try: | |
@@ -202,7 +221,7 @@ def format_groups(groups): | |||
| 202 | 221 | info_add("os.login", login) | |
| 203 | 222 | ||
| 204 | 223 | call_func(info_add, 'os.cpu_count', os, 'cpu_count') | |
| 205 | - call_func(info_add, 'os.loadavg', os, 'getloadavg') | ||
| 224 | + call_func(info_add, 'os.getloadavg', os, 'getloadavg') | ||
| 206 | 225 | ||
| 207 | 226 | # Environment variables used by the stdlib and tests. Don't log the full | |
| 208 | 227 | # environment: filter to list to not leak sensitive information. | |
@@ -286,20 +305,32 @@ def format_groups(groups): | |||
| 286 | 305 | os.umask(mask) | |
| 287 | 306 | info_add("os.umask", '%03o' % mask) | |
| 288 | 307 | ||
| 289 | - if hasattr(os, 'getrandom'): | ||
| 290 | - # PEP 524: Check if system urandom is initialized | ||
| 291 | - try: | ||
| 292 | - try: | ||
| 293 | - os.getrandom(1, os.GRND_NONBLOCK) | ||
| 294 | - state = 'ready (initialized)' | ||
| 295 | - except BlockingIOError as exc: | ||
| 296 | - state = 'not seeded yet (%s)' % exc | ||
| 297 | - info_add('os.getrandom', state) | ||
| 298 | - except OSError as exc: | ||
| 299 | - # Python was compiled on a more recent Linux version | ||
| 300 | - # than the current Linux kernel: ignore OSError(ENOSYS) | ||
| 301 | - if exc.errno != errno.ENOSYS: | ||
| 302 | - raise | ||
| 308 | + | ||
| 309 | + def collect_pwd(info_add): | ||
| 310 | + try: | ||
| 311 | + import pwd | ||
| 312 | + except ImportError: | ||
| 313 | + return | ||
| 314 | + import os | ||
| 315 | + | ||
| 316 | + uid = os.getuid() | ||
| 317 | + try: | ||
| 318 | + entry = pwd.getpwuid(uid) | ||
| 319 | + except KeyError: | ||
| 320 | + entry = None | ||
| 321 | + | ||
| 322 | + info_add('pwd.getpwuid(%s)'% uid, | ||
| 323 | + entry if entry is not None else '<KeyError>') | ||
| 324 | + | ||
| 325 | + if entry is None: | ||
| 326 | + # there is nothing interesting to read if the current user identifier | ||
| 327 | + # is not the password database | ||
| 328 | + return | ||
| 329 | + | ||
| 330 | + if hasattr(os, 'getgrouplist'): | ||
| 331 | + groups = os.getgrouplist(entry.pw_name, entry.pw_gid) | ||
| 332 | + groups = ', '.join(map(str, groups)) | ||
| 333 | + info_add('os.getgrouplist', groups) | ||
| 303 | 334 | ||
| 304 | 335 | ||
| 305 | 336 | def collect_readline(info_add): | |
@@ -625,31 +656,35 @@ def collect_info(info): | |||
| 625 | 656 | info_add = info.add | |
| 626 | 657 | ||
| 627 | 658 | for collect_func in ( | |
| 628 | - # collect_os() should be the first, to check the getrandom() status | ||
| 629 | - collect_os, | ||
| 659 | + # collect_urandom() must be the first, to check the getrandom() status. | ||
| 660 | + # Other functions may block on os.urandom() indirectly and so change | ||
| 661 | + # its state. | ||
| 662 | + collect_urandom, | ||
| 630 | 663 | ||
| 631 | 664 | collect_builtins, | |
| 665 | + collect_cc, | ||
| 666 | + collect_datetime, | ||
| 667 | + collect_decimal, | ||
| 668 | + collect_expat, | ||
| 632 | 669 | collect_gdb, | |
| 670 | + collect_gdbm, | ||
| 671 | + collect_get_config, | ||
| 633 | 672 | collect_locale, | |
| 673 | + collect_os, | ||
| 634 | 674 | collect_platform, | |
| 675 | + collect_pwd, | ||
| 635 | 676 | collect_readline, | |
| 677 | + collect_resource, | ||
| 636 | 678 | collect_socket, | |
| 637 | 679 | collect_sqlite, | |
| 638 | 680 | collect_ssl, | |
| 681 | + collect_subprocess, | ||
| 639 | 682 | collect_sys, | |
| 640 | 683 | collect_sysconfig, | |
| 684 | + collect_testcapi, | ||
| 641 | 685 | collect_time, | |
| 642 | - collect_datetime, | ||
| 643 | 686 | collect_tkinter, | |
| 644 | 687 | collect_zlib, | |
| 645 | - collect_expat, | ||
| 646 | - collect_decimal, | ||
| 647 | - collect_testcapi, | ||
| 648 | - collect_resource, | ||
| 649 | - collect_cc, | ||
| 650 | - collect_gdbm, | ||
| 651 | - collect_get_config, | ||
| 652 | - collect_subprocess, | ||
| 653 | 688 | ||
| 654 | 689 | # Collecting from tests should be last as they have side effects. | |
| 655 | 690 | collect_test_socket, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments