Exemplo n.º 1
0
 def GetExpectedUser(self, algo, user_store, group_store):
     user = rdf_client.User(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
Exemplo n.º 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, rdf_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(","))
Exemplo n.º 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"], rdf_client.PwEntry())
      pw_entry.store = self.shadow_store
      pw_entry.hash_type = self.GetHashType(rslt["passwd"])
      # Treat carefully here in case these values aren't set.
      last_change = rslt.get("last_change")
      if last_change:
        pw_entry.age = int(last_change)
      max_age = rslt.get("max_age")
      if max_age:
        pw_entry.max_age = int(max_age)