#!/usr/bin/env python
# -*- mode: python -*-
# Checks a directory against the passwd file assuming it is the home
# directory directory

from __future__ import print_function

import pwd
import os
import sys

for x in os.listdir(sys.argv[1]):
   try:
      User = pwd.getpwnam(x)
      st = os.stat(sys.argv[1] + x)
      if User[2] != st[4] or User[3] != st[5]:
         print("Bad ownership", x)
   except Exception:
      print("Failed", x, "==> %s: %s" % sys.exc_info[:2])
