diff options
| author | Tim <timothyasir@gluster.com> | 2011-08-10 17:04:12 +0530 |
|---|---|---|
| committer | Shireesh Anjal <shireesh@gluster.com> | 2011-08-10 18:48:55 +0530 |
| commit | f92d1a0524b7c7cf4aee9f736f6833d29a163a8b (patch) | |
| tree | 3b3f079a85b4a8658578183ac876d138632de765 /src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py | |
| parent | c34d9abeefcae4ba87cc6b54eed8644d37714c8a (diff) | |
Restructured backend gateway scripts
Diffstat (limited to 'src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py')
| -rwxr-xr-x | src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py | 93 |
1 files changed, 0 insertions, 93 deletions
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 deleted file mode 100755 index 29c182aa..00000000 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/python -# Copyright (C) 2011 Gluster, Inc. <http://www.gluster.com> -# This file is part of Gluster Management Gateway. -# - -import os -import sys -p1 = os.path.abspath(os.path.dirname(sys.argv[0])) -p2 = "%s/common" % os.path.dirname(p1) -if not p1 in sys.path: - sys.path.append(p1) -if not p2 in sys.path: - sys.path.append(p2) -import Globals -import Utils - - -def getUid(userName): - try: - fp = open(Globals.CIFS_USER_FILE) - content = fp.read() - fp.close() - except IOError, e: - Utils.log("failed to read file %s: %s" % (Globals.CIFS_USER_FILE, 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(Globals.CIFS_USER_FILE): - return Globals.DEFAULT_UID - try: - fp = open(Globals.CIFS_USER_FILE) - content = fp.read() - fp.close() - except IOError, e: - Utils.log("failed to read file %s: %s" % (Globals.CIFS_USER_FILE, str(e))) - return False - - lines = content.strip().split() - if not lines: - return Globals.DEFAULT_UID - return int(lines[-1].split(":")[0]) - - -def setUid(uid, userName): - try: - fp = open(Globals.CIFS_USER_FILE, "a") - fp.write("%s:%s\n" % (uid, userName)) - fp.close() - return True - except IOError, e: - Utils.log("failed to write file %s: %s" % (Globals.CIFS_USER_FILE, str(e))) - return False - - -def main(): - if len(sys.argv) < 4: - sys.stderr.write("usage: %s SERVER_FILE USERNAME PASSWORD\n" % os.path.basename(sys.argv[0])) - sys.exit(-1) - - serverFile = sys.argv[1] - userName = sys.argv[2] - password = sys.argv[3] - - existingUser = False - uid = getUid(userName) - if not uid: - 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.stderr.write("Failed to add the user\n") - sys.exit(11) - sys.exit(rv) - - -if __name__ == "__main__": - main() |
