Пример #1
0
 def GetExpectedUser(self, algo, user_store, group_store):
   user = rdf_client.KnowledgeBaseUser(username="******", full_name="User",
                                       uid="1001", gid="1001",
                                       homedir="/home/user", shell="/bin/bash")
   user.pw_entry = rdf_client.PwEntry(store=user_store, hash_type=algo)
   user.gids = [1001]
   grp = rdf_client.Group(gid=1001, members=["user"], name="user")
   grp.pw_entry = rdf_client.PwEntry(store=group_store, hash_type=algo)
   return user, grp
Пример #2
0
    def ParseGshadowEntry(self, line):
        """Extract the members of each group from /etc/gshadow.

    Identifies the groups in /etc/gshadow and several attributes of the group,
    including how the password is crypted (if set).

    gshadow files have the format group_name:passwd:admins:members
    admins are both group members and can manage passwords and memberships.

    Args:
      line: An entry in gshadow.
    """
        fields = ("name", "passwd", "administrators", "members")
        if line:
            rslt = dict(zip(fields, line.split(":")))
            # Add the shadow state to the internal store.
            name = rslt["name"]
            pw_entry = self.shadow.setdefault(name, client.PwEntry())
            pw_entry.store = self.shadow_store
            pw_entry.hash_type = self.GetHashType(rslt["passwd"])
            # Add the members to the internal store.
            members = self.gshadow_members.setdefault(name, set())
            for accts in rslt["administrators"], rslt["members"]:
                if accts:
                    members.update(accts.split(","))
Пример #3
0
    def ParseShadowEntry(self, line):
        """Extract the user accounts in /etc/shadow.

    Identifies the users in /etc/shadow and several attributes of their account,
    including how their password is crypted and password aging characteristics.

    Args:
      line: An entry of the shadow file.
    """
        fields = ("login", "passwd", "last_change", "min_age", "max_age",
                  "warn_time", "inactivity", "expire", "reserved")
        if line:
            rslt = dict(zip(fields, line.split(":")))
            pw_entry = self.shadow.setdefault(rslt["login"], client.PwEntry())
            pw_entry.store = self.shadow_store
            pw_entry.hash_type = self.GetHashType(rslt["passwd"])
            pw_entry.age = int(rslt["last_change"])
            pw_entry.max_age = int(rslt["max_age"])