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 enabl
()
| 240 | |
| 241 | |
| 242 | def check_enableusersite(): |
| 243 | """Check if user site directory is safe for inclusion |
| 244 | |
| 245 | The function tests for the command line flag (including environment var), |
| 246 | process uid/gid equal to effective uid/gid. |
| 247 | |
| 248 | None: Disabled for security reasons |
| 249 | False: Disabled by user (command line option) |
| 250 | True: Safe and enabled |
| 251 | """ |
| 252 | if sys.flags.no_user_site: |
| 253 | return False |
| 254 | |
| 255 | if hasattr(os, "getuid") and hasattr(os, "geteuid"): |
| 256 | # check process uid == effective uid |
| 257 | if os.geteuid() != os.getuid(): |
| 258 | return None |
| 259 | if hasattr(os, "getgid") and hasattr(os, "getegid"): |
| 260 | # check process gid == effective gid |
| 261 | if os.getegid() != os.getgid(): |
| 262 | return None |
| 263 | |
| 264 | return True |
| 265 | |
| 266 | |
| 267 | # NOTE: sysconfig and it's dependencies are relatively large but site module |