From 5dd40b61a2349da5aa6bc9b9d31149e63d54b8e3 Mon Sep 17 00:00:00 2001 From: "Bala.FA" Date: Fri, 5 Aug 2011 12:54:14 +0530 Subject: add_user_cifs_all.py and add_user_cifs.py support to ignore existing user on given server list. This enables password reset and adding user to newly added servers on existing storage clusters. Signed-off-by: Bala.FA --- .../WebContent/scripts/add_user_cifs_all.py | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/com.gluster.storage.management.gateway/WebContent/scripts') diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py index 02855cd7..f1e899ec 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py @@ -18,6 +18,22 @@ defaultUid = 1024000 cifsUserFile = "/opt/glustermg/etc/users.cifs" +def getUid(userName): + try: + fp = open(cifsUserFile) + content = fp.read() + fp.close() + except IOError, e: + Utils.log("failed to read file %s: %s" % (cifsUserFile, str(e))) + return False + + for line in content.strip().split(): + tokens = line.split(":") + if tokens[1] == UserName: + return int(tokens[0]) + return None + + def getLastUid(): if not os.path.exists(cifsUserFile): return defaultUid @@ -55,13 +71,20 @@ def main(): userName = sys.argv[2] password = sys.argv[3] - uid = getLastUid() + existingUser = False + uid = getUid(userName) if not uid: - sys.exit(10) - - uid += 1 + uid = getLastUid() + if not uid: + sys.exit(10) + uid += 1 + else: + existingUser = True rv = Utils.runCommand("grun.py %s add_user_cifs.py %s %s %s" % (serverFile, uid, userName, password)) + if existingUser: + sys.exit(rv) + if rv == 0: if not setUid(uid, userName): sys.exit(11) -- cgit