From b319cc1da002d7b800364414798a52cbdb5b3296 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 25 Feb 2015 13:01:35 +0100 Subject: [PATCH 1/2] [displaymanager] Explicitly unset autologin if not checked. --- src/modules/displaymanager/main.py | 67 +++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/src/modules/displaymanager/main.py b/src/modules/displaymanager/main.py index b9aa007be..891442e8b 100644 --- a/src/modules/displaymanager/main.py +++ b/src/modules/displaymanager/main.py @@ -4,7 +4,7 @@ # === This file is part of Calamares - === # # Copyright 2014-2015, Philip Müller -# Copyright 2014, Teo Mrnjavac +# Copyright 2014-2015, Teo Mrnjavac # Copyright 2014, Kevin Kofler # # Calamares is free software: you can redistribute it and/or modify @@ -88,15 +88,21 @@ def set_autologin(username, displaymanagers, default_desktop_environment, with open(mdm_conf_path, 'w') as mdm_conf: for line in text: if '[daemon]' in line: - line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=True\n".format(username) + if do_autologin: + line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=True\n".format(username) + else: + line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=False\n".format(username) mdm_conf.write(line) else: with open(mdm_conf_path, 'w') as mdm_conf: mdm_conf.write( - '# Calamares - Enable automatic login for user\n') + '# Calamares - Configure automatic login for user\n') mdm_conf.write('[daemon]\n') mdm_conf.write("AutomaticLogin={!s}\n".format(username)) - mdm_conf.write('AutomaticLoginEnable=True\n') + if do_autologin: + mdm_conf.write('AutomaticLoginEnable=True\n') + else: + mdm_conf.write('AutomaticLoginEnable=False\n') if "gdm" in displaymanagers: # Systems with GDM as Desktop Manager @@ -107,7 +113,10 @@ def set_autologin(username, displaymanagers, default_desktop_environment, with open(gdm_conf_path, 'w') as gdm_conf: for line in text: if '[daemon]' in line: - line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=True\n".format(username) + if do_autologin: + line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=True\n".format(username) + else: + line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=False\n".format(username) gdm_conf.write(line) else: with open(gdm_conf_path, 'w') as gdm_conf: @@ -115,7 +124,10 @@ def set_autologin(username, displaymanagers, default_desktop_environment, '# Calamares - Enable automatic login for user\n') gdm_conf.write('[daemon]\n') gdm_conf.write("AutomaticLogin={!s}\n".format(username)) - gdm_conf.write('AutomaticLoginEnable=True\n') + if do_autologin: + mdm_conf.write('AutomaticLoginEnable=True\n') + else: + mdm_conf.write('AutomaticLoginEnable=False\n') if os.path.exists("{!s}/var/lib/AccountsService/users".format(root_mount_point)): os.system( "echo \"[User]\" > {!s}/var/lib/AccountsService/users/{!s}".format( @@ -138,8 +150,11 @@ def set_autologin(username, displaymanagers, default_desktop_environment, text = kdm_conf.readlines() with open(kdm_conf_path, 'w') as kdm_conf: for line in text: - if '#AutoLoginEnable=true' in line: - line = 'AutoLoginEnable=true\n' + if 'AutoLoginEnable=' in line: + if do_autologin: + line = 'AutoLoginEnable=true\n' + else: + line = 'AutoLoginEnable=false\n' if 'AutoLoginUser=' in line: line = "AutoLoginUser={!s}\n".format(username) kdm_conf.write(line) @@ -155,8 +170,11 @@ def set_autologin(username, displaymanagers, default_desktop_environment, text = lxdm_conf.readlines() with open(lxdm_conf_path, 'w') as lxdm_conf: for line in text: - if '# autologin=dgod' in line: - line = "autologin={!s}\n".format(username) + if 'autologin=' in line: + if do_autologin: + line = "autologin={!s}\n".format(username) + else: + line = "# autologin={!s}\n".format(username) lxdm_conf.write(line) else: return "Cannot write LXDM configuration file", "LXDM config file {!s} does not exist".format(lxdm_conf_path) @@ -174,8 +192,11 @@ def set_autologin(username, displaymanagers, default_desktop_environment, text = lightdm_conf.readlines() with open(lightdm_conf_path, 'w') as lightdm_conf: for line in text: - if '#autologin-user=' in line: - line = "autologin-user={!s}\n".format(username) + if 'autologin-user=' in line: + if do_autologin: + line = "autologin-user={!s}\n".format(username) + else: + line = "#autologin-user={!s}\n".format(username) lightdm_conf.write(line) else: return "Cannot write LightDM configuration file", "LightDM config file {!s} does not exist".format(lightdm_conf_path) @@ -190,7 +211,10 @@ def set_autologin(username, displaymanagers, default_desktop_environment, with open(slim_conf_path, 'w') as slim_conf: for line in text: if 'auto_login' in line: - line = 'auto_login yes\n' + if do_autologin: + line = 'auto_login yes\n' + else: + line = 'auto_login no\n' if 'default_user' in line: line = "default_user {!s}\n".format(username) slim_conf.write(line) @@ -211,11 +235,17 @@ def set_autologin(username, displaymanagers, default_desktop_environment, for line in text: # User= line, possibly commented out if re.match('\\s*(?:#\\s*)?User=', line): - line = 'User={}\n'.format(username) + if do_autologin: + line = 'User={}\n'.format(username) + else: + line = '#User={}\n'.format(username) # Session= line, commented out or with empty value if re.match('\\s*#\\s*Session=|\\s*Session=$', line): if default_desktop_environment is not None: - line = 'Session={}.desktop\n'.format(default_desktop_environment.desktop_file) + if do_autologin: + line = 'Session={}.desktop\n'.format(default_desktop_environment.desktop_file) + else: + line = '#Session={}.desktop\n'.format(default_desktop_environment.desktop_file) sddm_conf.write(line) return None @@ -372,6 +402,11 @@ def run(): if username is not None: libcalamares.utils.debug( "Setting up autologin for user {!s}.".format(username)) - return set_autologin(username, displaymanagers, default_desktop_environment, root_mount_point) + return set_autologin(username, displaymanagers, default_desktop_environment, root_mount_point, True) + else: + libcalamares.utils.debug( + "Unsetting autologin for user {!s}.".format(username)) + return set_autologin(username, displaymanagers, default_desktop_environment, root_mount_point, False) + return None From 67ed53caeb035abaeed5929f54bce7c0d3cc9995 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 25 Feb 2015 17:54:38 +0100 Subject: [PATCH 2/2] Do not try to set the username if it's None. --- src/modules/displaymanager/main.py | 33 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/modules/displaymanager/main.py b/src/modules/displaymanager/main.py index 891442e8b..7fe761dc3 100644 --- a/src/modules/displaymanager/main.py +++ b/src/modules/displaymanager/main.py @@ -79,6 +79,11 @@ def set_autologin(username, displaymanagers, default_desktop_environment, :param default_desktop_environment: :param root_mount_point: """ + + do_autologin = True + if username is None: + do_autologin = False + if "mdm" in displaymanagers: # Systems with MDM as Desktop Manager mdm_conf_path = os.path.join(root_mount_point, "etc/mdm/custom.conf") @@ -91,15 +96,15 @@ def set_autologin(username, displaymanagers, default_desktop_environment, if do_autologin: line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=True\n".format(username) else: - line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=False\n".format(username) + line = "[daemon]\nAutomaticLoginEnable=False\n" mdm_conf.write(line) else: with open(mdm_conf_path, 'w') as mdm_conf: mdm_conf.write( '# Calamares - Configure automatic login for user\n') mdm_conf.write('[daemon]\n') - mdm_conf.write("AutomaticLogin={!s}\n".format(username)) if do_autologin: + mdm_conf.write("AutomaticLogin={!s}\n".format(username)) mdm_conf.write('AutomaticLoginEnable=True\n') else: mdm_conf.write('AutomaticLoginEnable=False\n') @@ -116,19 +121,19 @@ def set_autologin(username, displaymanagers, default_desktop_environment, if do_autologin: line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=True\n".format(username) else: - line = "[daemon]\nAutomaticLogin={!s}\nAutomaticLoginEnable=False\n".format(username) + line = "[daemon]\nAutomaticLoginEnable=False\n" gdm_conf.write(line) else: with open(gdm_conf_path, 'w') as gdm_conf: gdm_conf.write( '# Calamares - Enable automatic login for user\n') gdm_conf.write('[daemon]\n') - gdm_conf.write("AutomaticLogin={!s}\n".format(username)) if do_autologin: + gdm_conf.write("AutomaticLogin={!s}\n".format(username)) mdm_conf.write('AutomaticLoginEnable=True\n') else: mdm_conf.write('AutomaticLoginEnable=False\n') - if os.path.exists("{!s}/var/lib/AccountsService/users".format(root_mount_point)): + if do_autologin and os.path.exists("{!s}/var/lib/AccountsService/users".format(root_mount_point)): os.system( "echo \"[User]\" > {!s}/var/lib/AccountsService/users/{!s}".format( root_mount_point, username)) @@ -155,7 +160,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment, line = 'AutoLoginEnable=true\n' else: line = 'AutoLoginEnable=false\n' - if 'AutoLoginUser=' in line: + if do_autologin and 'AutoLoginUser=' in line: line = "AutoLoginUser={!s}\n".format(username) kdm_conf.write(line) else: @@ -174,7 +179,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment, if do_autologin: line = "autologin={!s}\n".format(username) else: - line = "# autologin={!s}\n".format(username) + line = "# autologin=\n" lxdm_conf.write(line) else: return "Cannot write LXDM configuration file", "LXDM config file {!s} does not exist".format(lxdm_conf_path) @@ -196,7 +201,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment, if do_autologin: line = "autologin-user={!s}\n".format(username) else: - line = "#autologin-user={!s}\n".format(username) + line = "#autologin-user=\n" lightdm_conf.write(line) else: return "Cannot write LightDM configuration file", "LightDM config file {!s} does not exist".format(lightdm_conf_path) @@ -215,7 +220,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment, line = 'auto_login yes\n' else: line = 'auto_login no\n' - if 'default_user' in line: + if do_autologin and 'default_user' in line: line = "default_user {!s}\n".format(username) slim_conf.write(line) else: @@ -238,7 +243,7 @@ def set_autologin(username, displaymanagers, default_desktop_environment, if do_autologin: line = 'User={}\n'.format(username) else: - line = '#User={}\n'.format(username) + line = '#User=\n' # Session= line, commented out or with empty value if re.match('\\s*#\\s*Session=|\\s*Session=$', line): if default_desktop_environment is not None: @@ -402,11 +407,7 @@ def run(): if username is not None: libcalamares.utils.debug( "Setting up autologin for user {!s}.".format(username)) - return set_autologin(username, displaymanagers, default_desktop_environment, root_mount_point, True) else: - libcalamares.utils.debug( - "Unsetting autologin for user {!s}.".format(username)) - return set_autologin(username, displaymanagers, default_desktop_environment, root_mount_point, False) + libcalamares.utils.debug("Unsetting autologin.") - - return None + return set_autologin(username, displaymanagers, default_desktop_environment, root_mount_point)