Example #1
0
 def test_initgroupsForcePython(self):
     """
     If we fake the absence of the C extension, the Python implementation is
     called instead, calling C{os.setgroups}.
     """
     util._c_initgroups = None
     calls = []
     util.setgroups = calls.append
     util.initgroups(os.getuid(), os.getgid())
     # Something should be in the calls, we don't really care what
     self.assertTrue(calls)
Example #2
0
 def test_initgroupsInC(self):
     """
     If the C extension is present, it's called instead of the Python
     version.  We check that by making sure C{os.setgroups} is not called.
     """
     calls = []
     util.setgroups = calls.append
     try:
         util.initgroups(os.getuid(), os.getgid())
     except OSError:
         pass
     self.assertFalse(calls)
Example #3
0
 def test_initgroupsInC(self):
     """
     If the C extension is present, it's called instead of the Python
     version.  We check that by making sure C{os.setgroups} is not called.
     """
     calls = []
     util.setgroups = calls.append
     try:
         util.initgroups(os.getuid(), os.getgid())
     except OSError:
         pass
     self.assertFalse(calls)
    def test_initgroupsForceC(self):
        """
        If we fake the presence of the C extension, it's called instead of the
        Python implementation.
        """
        calls = []
        util._c_initgroups = lambda x, y: calls.append((x, y))
        setgroupsCalls = []
        util.setgroups = calls.append

        util.initgroups(os.getuid(), 4)
        self.assertEqual(calls, [(pwd.getpwuid(os.getuid())[0], 4)])
        self.assertFalse(setgroupsCalls)
Example #5
0
    def test_initgroupsForceC(self):
        """
        If we fake the presence of the C extension, it's called instead of the
        Python implementation.
        """
        calls = []
        util._c_initgroups = lambda x, y: calls.append((x, y))
        setgroupsCalls = []
        util.setgroups = calls.append

        util.initgroups(os.getuid(), 4)
        self.assertEquals(calls, [(pwd.getpwuid(os.getuid())[0], 4)])
        self.assertFalse(setgroupsCalls)
    def test_initgroupsInStdlib(self):
        """
        Calling L{util.initgroups} will call the underlying stdlib
        implmentation.
        """
        calls = []
        util._initgroups = lambda x, y: calls.append((x, y))
        setgroupsCalls = []
        util.setgroups = setgroupsCalls.append

        util.initgroups(os.getuid(), 4)
        self.assertEqual(calls, [(pwd.getpwuid(os.getuid())[0], 4)])
        self.assertFalse(setgroupsCalls)
Example #7
0
    def test_initgroupsInStdlib(self):
        """
        Calling L{util.initgroups} will call the underlying stdlib
        implmentation.
        """
        calls = []
        util._initgroups = lambda x, y: calls.append((x, y))
        setgroupsCalls = []
        util.setgroups = setgroupsCalls.append

        util.initgroups(os.getuid(), 4)
        self.assertEqual(calls, [(pwd.getpwuid(os.getuid())[0], 4)])
        self.assertFalse(setgroupsCalls)
Example #8
0
    def test_initgroupsInStdlib(self):
        """
        Calling L{util.initgroups} will call the underlying stdlib
        implmentation.
        """
        calls = []

        def mockInitgroups(x, y):
            calls.append((x, y))

        self.patch(util, "_initgroups", mockInitgroups)
        setgroupsCalls = []
        self.patch(util, "setgroups", setgroupsCalls.append)

        util.initgroups(os.getuid(), 4)
        self.assertEqual(calls, [(pwd.getpwuid(os.getuid()).pw_name, 4)])
        self.assertFalse(setgroupsCalls)
Example #9
0
def dropprivs(user):
  uid, gid = pwd.getpwnam(user)[2:4]
  initgroups(uid, gid)
  os.setregid(gid, gid)
  os.setreuid(uid, uid)
  return (uid, gid)
Example #10
0
def dropprivs(user):
    uid, gid = pwd.getpwnam(user)[2:4]
    initgroups(uid, gid)
    os.setregid(gid, gid)
    os.setreuid(uid, uid)
    return (uid, gid)
Example #11
0
def dropprivs(user):
  uid, gid = platform.getpwnam(user)
  initgroups(uid, gid)
  os.setregid(gid, gid)
  os.setreuid(uid, uid)
  return (uid, gid)