Set active groups from a list of group ids.
(groups)
| 483 | |
| 484 | |
| 485 | def setgroups(groups): |
| 486 | """Set active groups from a list of group ids.""" |
| 487 | max_groups = None |
| 488 | try: |
| 489 | max_groups = os.sysconf('SC_NGROUPS_MAX') |
| 490 | except Exception: # pylint: disable=broad-except |
| 491 | pass |
| 492 | try: |
| 493 | return _setgroups_hack(groups[:max_groups]) |
| 494 | except OSError as exc: |
| 495 | if exc.errno != errno.EPERM: |
| 496 | raise |
| 497 | if any(group not in groups for group in os.getgroups()): |
| 498 | # we shouldn't be allowed to change to this group. |
| 499 | raise |
| 500 | |
| 501 | |
| 502 | def initgroups(uid, gid): |