Set active groups from a list of group ids.
(groups)
| 547 | |
| 548 | |
| 549 | def setgroups(groups): |
| 550 | """Set active groups from a list of group ids.""" |
| 551 | max_groups = None |
| 552 | try: |
| 553 | max_groups = os.sysconf('SC_NGROUPS_MAX') |
| 554 | except Exception: # pylint: disable=broad-except |
| 555 | pass |
| 556 | try: |
| 557 | return _setgroups_hack(groups[:max_groups]) |
| 558 | except OSError as exc: |
| 559 | if exc.errno != errno.EPERM: |
| 560 | raise |
| 561 | if any(group not in groups for group in os.getgroups()): |
| 562 | # we shouldn't be allowed to change to this group. |
| 563 | raise |
| 564 | |
| 565 | |
| 566 | def initgroups(uid, gid): |