summaryrefslogtreecommitdiff
path: root/utils/nslcd.py
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2013-03-30 22:59:57 +0100
committerArthur de Jong <arthur@arthurdejong.org>2013-03-30 23:09:30 +0100
commit012b18554e5e6a408a11a7157a30c5d068f2d3d1 (patch)
tree50c70342106c2674d61b5559f7dfa89dc1f506bc /utils/nslcd.py
parentd0482fb56654037d01feb0f7a27206aefacf7112 (diff)
Initial version of a chsh.ldap utility
Diffstat (limited to 'utils/nslcd.py')
-rw-r--r--utils/nslcd.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/utils/nslcd.py b/utils/nslcd.py
index 06165cc..65e5822 100644
--- a/utils/nslcd.py
+++ b/utils/nslcd.py
@@ -111,3 +111,26 @@ class NslcdClient(object):
def __del__(self):
self.close()
+
+
+def usermod(username, asroot=False, password=None, args=None):
+ # open a connection to nslcd
+ con = NslcdClient(constants.NSLCD_ACTION_USERMOD)
+ # write the request information
+ con.write_string(username)
+ con.write_int32(1 if asroot else 0)
+ con.write_string(password)
+ for k, v in args.items():
+ con.write_int32(k)
+ con.write_string(v)
+ con.write_int32(constants.NSLCD_USERMOD_END)
+ # read the response
+ assert con.get_response() == constants.NSLCD_RESULT_BEGIN
+ response = {}
+ while True:
+ key = con.read_int32()
+ if key == constants.NSLCD_USERMOD_END:
+ break
+ response[key] = con.read_string()
+ # return the response
+ return response