If a 'localclient' entry is not in the auth file, then have the daemon add one.

This commit is contained in:
Andrew Resch 2009-06-10 18:11:14 +00:00
commit 853138e4ee

View file

@ -86,16 +86,22 @@ class AuthManager(component.Component):
return 0 return 0
def __load_auth_file(self): def __create_localclient_account(self):
auth_file = configmanager.get_config_dir("auth") """
# Check for auth file and create if necessary Returns the string.
if not os.path.exists(auth_file): """
# We create a 'localclient' account with a random password # We create a 'localclient' account with a random password
try: try:
from hashlib import sha1 as sha_hash from hashlib import sha1 as sha_hash
except ImportError: except ImportError:
from sha import new as sha_hash from sha import new as sha_hash
open(auth_file, "w").write("localclient:" + sha_hash(str(random.random())).hexdigest() + ":" + str(AUTH_LEVEL_ADMIN) + "\n") return "localclient:" + sha_hash(str(random.random())).hexdigest() + ":" + str(AUTH_LEVEL_ADMIN) + "\n"
def __load_auth_file(self):
auth_file = configmanager.get_config_dir("auth")
# Check for auth file and create if necessary
if not os.path.exists(auth_file):
open(auth_file, "w").write(self.__create_localclient_account())
# Change the permissions on the file so only this user can read/write it # Change the permissions on the file so only this user can read/write it
os.chmod(auth_file, stat.S_IREAD | stat.S_IWRITE) os.chmod(auth_file, stat.S_IREAD | stat.S_IWRITE)
@ -121,3 +127,7 @@ class AuthManager(component.Component):
continue continue
self.__auth[username.strip()] = (password.strip(), level) self.__auth[username.strip()] = (password.strip(), level)
f.close()
if "localclient" not in self.__auth:
open(auth_file, "a").write(self.__create_localclient_account())