prewikka/master: Define initial administrative user in the configuration file.

[email protected] Thu, 4 Jun 2009 11:48:41 +0200 (CEST)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit 6287335d4d146e82352bdb54cc23f96690529f2e
Author: Yoann Vandoorselaere <[email protected]>
Date:   Thu Jun 4 11:45:48 2009 +0200

    Define initial administrative user in the configuration file.
    
    Until now, the default user that was automatically created by Prewikka if
    there was no administrative user was "admin". As of now you can define the
    initial administrative username and password from the configuration file.
    
    Close #289.


========================================

 conf/prewikka.conf                                 |    4 ++++
 .../modules/auth/loginpassword/loginpassword.py    |   13 ++++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)

========================================

diff --git a/conf/prewikka.conf b/conf/prewikka.conf
index 0a77a8b..7bb07f5 100644
--- a/conf/prewikka.conf
+++ b/conf/prewikka.conf
@@ -77,6 +77,10 @@ name: prewikka
 # Standard login / password authentication:
 [auth loginpassword]
 expiration: 60
+# If there is no user with administrative right defined in the database,
+# the initial user will be created according to these settings:
+initial_admin_user: admin
+initial_admin_pass: admin
 
 
 # Rely on webserver for user authentication:
diff --git a/prewikka/modules/auth/loginpassword/loginpassword.py b/prewikka/modules/auth/loginpassword/loginpassword.py
index 3b4bd82..de81d8d 100644
--- a/prewikka/modules/auth/loginpassword/loginpassword.py
+++ b/prewikka/modules/auth/loginpassword/loginpassword.py
@@ -24,6 +24,9 @@ from prewikka import Auth, User, Database
 
 class MyLoginPasswordAuth(Auth.LoginPasswordAuth):
     def __init__(self, env, config):
+        user = config.getOptionValue("initial_admin_user", User.ADMIN_LOGIN)
+        passwd = config.getOptionValue("initial_admin_pass", User.ADMIN_LOGIN)
+
         expiration = int(config.getOptionValue("expiration", 60)) * 60
         Auth.LoginPasswordAuth.__init__(self, env, expiration)
 
@@ -35,13 +38,13 @@ class MyLoginPasswordAuth(Auth.LoginPasswordAuth):
                 break
 
         if not has_user_manager:
-            if not self.db.hasUser(User.ADMIN_LOGIN):
-                self.db.createUser(User.ADMIN_LOGIN)
+            if not self.db.hasUser(user):
+                self.db.createUser(user)
 
-            if not self.db.hasPassword(User.ADMIN_LOGIN):
-                self.setPassword(User.ADMIN_LOGIN, User.ADMIN_LOGIN)
+            if not self.db.hasPassword(user):
+                self.setPassword(user, passwd)
 
-            self.db.setPermissions(User.ADMIN_LOGIN, User.ALL_PERMISSIONS)
+            self.db.setPermissions(user, User.ALL_PERMISSIONS)
 
     def _hash(self, data):
         return md5.new(data).hexdigest()
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.