From f5adadec0bf8467c79a5b61d129e8e733f330906 Mon Sep 17 00:00:00 2001 From: Robert Gogolok Date: Wed, 9 Jan 2008 22:08:01 +0000 Subject: bcfg-admin init: generate random password if no password specified git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4228 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Admin/Init.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/lib/Server/Admin/Init.py') diff --git a/src/lib/Server/Admin/Init.py b/src/lib/Server/Admin/Init.py index 048a65647..0a1c631c8 100644 --- a/src/lib/Server/Admin/Init.py +++ b/src/lib/Server/Admin/Init.py @@ -1,4 +1,4 @@ -import getpass, os, socket +import getpass, os, random, socket, string import Bcfg2.Server.Admin import Bcfg2.Options @@ -95,12 +95,11 @@ class Init(Bcfg2.Server.Admin.Mode): if repopath == '': repopath = opts['repo'] - password = '' - while ( password == '' ): - password = getpass.getpass( + password = getpass.getpass( "Input password used for communication verification " - "(without echoing): " - ) + "(without echoing; leave blank for a random): ") + if len(password.strip()) == 0: + password = self.genPassword() server = "https://%s:6789" % socket.getfqdn() rs = raw_input( "Input the server location [%s]: " % server) @@ -116,6 +115,13 @@ class Init(Bcfg2.Server.Admin.Mode): self.initializeRepo(configfile, repopath, server, password, os_sel, opts) print "Repository created successfuly in %s" % (repopath) + def genPassword(self): + chars = string.letters + string.digits + newpasswd = '' + for i in range(8): + newpasswd = newpasswd + random.choice(chars) + return newpasswd + def initializeRepo(self, configfile, repo, server_uri, password, os_selection, opts): '''Setup a new repo''' keypath = os.path.dirname(os.path.abspath(configfile)) -- cgit v1.2.3-1-g7c22