Ejemplo n.º 1
0
 def _create_user(self, container_auth, host_auth):
     """If we need to create a new user then we first
     copy /etc/passwd and /etc/group to new files and them
     we add the user account into these copied files which
     later are binding/mapped/passed to the container. So
     setup this binding as well via hostauth.
     """
     if self.opt["containerauth"]:
         tmp_passwd = container_auth.passwd_file
         tmp_group = container_auth.group_file
         self.opt["hostauth"] = False
     else:
         FileUtil().umask(0o077)
         tmp_passwd = FileUtil("passwd").mktmp()
         tmp_group = FileUtil("group").mktmp()
         if self.opt["hostauth"]:
             FileUtil("/etc/passwd").copyto(tmp_passwd)
             FileUtil("/etc/group").copyto(tmp_group)
         else:
             FileUtil(container_auth.passwd_file).copyto(tmp_passwd)
             FileUtil(container_auth.group_file).copyto(tmp_group)
         FileUtil().umask()
     if not (self.opt["containerauth"] or self.opt["hostauth"]):
         Msg().out("Warning: non-existing user will be created",
                   l=Msg.DBG)
         self._fill_user()
         new_auth = NixAuthentication(tmp_passwd, tmp_group)
         new_auth.add_user(self.opt["user"], 'x',
                           self.opt["uid"], self.opt["gid"],
                           self.opt["gecos"], self.opt["home"],
                           self.opt["shell"])
         (group, dummy, dummy) = host_auth.get_group(self.opt["gid"])
         if not group:
             new_auth.add_group(self.opt["user"], self.opt["gid"])
         for sup_gid in os.getgroups():
             new_auth.add_group('G' + str(sup_gid), str(sup_gid),
                                [self.opt["user"], ])
     if not self.opt["containerauth"]:
         self.opt["hostauth"] = True
         self.hostauth_list = (tmp_passwd + ":/etc/passwd",
                               tmp_group + ":/etc/group")
     return True
Ejemplo n.º 2
0
 def test_10_add_group(self):
     """Test10 NixAuthentication().add_group()."""
     auth = NixAuthentication()
     with patch(BUILTINS + '.open', mock_open()):
         status = auth.add_group("root", 0)
         self.assertTrue(status)