ldap-users/sbin/update_passwd_and_group

26 lines
631 B
Python
Executable File

#!/usr/bin/env python
import sys
sys.path.insert(0, "/center/lib/center")
from ldap_core import LDAPCore
name = "Manager"
domain = "tilde.center"
etc = "/center/etc"
with open("%s/secrets/ldap.secret" % etc, "r") as secret:
pswd = secret.read().strip()
root = (name, pswd)
core = LDAPCore(root, domain)
passwd_file = "%s/passwd" % etc
group_file = "%s/group" % etc
with open(passwd_file, "w") as passwd:
passwd.write("\n".join(core.users()) + "\n")
with open(group_file, "w") as group:
group.write("\n".join(core.groups()) + "\n")
core.close()
print("Successfully updated %s and %s!" % (passwd_file, group_file))