[svn] commit: r1560 - /trunk/src/bin/bindctl/bindcmd.py

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Mar 19 00:10:28 UTC 2010


Author: jelte
Date: Fri Mar 19 00:10:27 2010
New Revision: 1560

Log:
changed default_user.csv file used to store the bindctl user from $cwd to ~/.bind10/default_user.csv
if the directory cannot be make or the file cannot be written the default isn't stored (an error is printed but the session continues)
read/write permissions are for user only

Modified:
    trunk/src/bin/bindctl/bindcmd.py

Modified: trunk/src/bin/bindctl/bindcmd.py
==============================================================================
--- trunk/src/bin/bindctl/bindcmd.py (original)
+++ trunk/src/bin/bindctl/bindcmd.py Fri Mar 19 00:10:27 2010
@@ -115,7 +115,12 @@
         csvfile = None
         bsuccess = False
         try:
-            csvfile = open('default_user.csv')
+            cvsfilepath = ""
+            if ('HOME' in os.environ):
+                cvsfilepath = os.environ['HOME']
+                cvsfilepath += os.sep + '.bind10' + os.sep
+            cvsfilepath += 'default_user.csv'
+            csvfile = open(cvsfilepath)
             users = csv.reader(csvfile)
             for row in users:
                 param = {'username': row[0], 'password' : row[1]}
@@ -151,10 +156,23 @@
             print(data)
             
             if response.status == http.client.OK:
-                csvfile = open('default_user.csv', 'w')
-                writer = csv.writer(csvfile)
-                writer.writerow([username, passwd])
-                csvfile.close()
+                cvsfilepath = ""
+                try:
+                    if ('HOME' in os.environ):
+                        cvsfilepath = os.environ['HOME']
+                        cvsfilepath += os.sep + '.bind10' + os.sep
+                        if not os.path.exists(cvsfilepath):
+                                os.mkdir(cvsfilepath, 0o700)
+                    cvsfilepath += 'default_user.csv'
+                    csvfile = open(cvsfilepath, 'w')
+                    os.chmod(cvsfilepath, 0o600)
+                    writer = csv.writer(csvfile)
+                    writer.writerow([username, passwd])
+                    csvfile.close()
+                except Exception as e:
+                    # just not store it
+                    print("Cannot write ~/.bind10/default_user.csv; default user is not stored")
+                    print(e)
                 return True
 
 




More information about the bind10-changes mailing list