def EnumerateUsersFromClient(args):
  """Enumerates all the users on this system."""

  del args  # Unused

  users = _ParseWtmp()
  for user, last_login in iteritems(users):

    # Lose the null termination
    username, _ = user.split(b"\x00", 1)
    username = username.decode("utf-8")

    if username:
      # Somehow the last login time can be < 0. There is no documentation
      # what this means so we just set it to 0 (the rdfvalue field is
      # unsigned so we can't send negative values).
      if last_login < 0:
        last_login = 0

      result = rdf_client.User(
          username=username, last_logon=last_login * 1000000)

      try:
        pwdict = pwd.getpwnam(username)
        result.homedir = utils.SmartUnicode(pwdict.pw_dir)
        result.full_name = utils.SmartUnicode(pwdict.pw_gecos)
        result.uid = pwdict.pw_uid
        result.gid = pwdict.pw_gid
        result.shell = utils.SmartUnicode(pwdict.pw_shell)
      except KeyError:
        pass

      yield result
def EnumerateUsersFromClient ( args ) : del args users = _ParseWtmp ( ) for user , last_login in iteritems ( users ) : username , _ = user . split ( b"\x00" , 1 ) username = username . decode ( "utf-8" ) if username : if last_login < 0 : last_login = 0 result = rdf_client . User ( username = username , last_logon = last_login * 1000000 ) try : pwdict = pwd . getpwnam ( username ) result . homedir = utils . SmartUnicode ( pwdict . pw_dir ) result . full_name = utils . SmartUnicode ( pwdict . pw_gecos ) result . uid = pwdict . pw_uid result . gid = pwdict . pw_gid result . shell = utils . SmartUnicode ( pwdict . pw_shell ) except KeyError : pass yield result
Enumerates all the users on this system.