diff options
-rw-r--r-- | Changelog | 12 | ||||
-rw-r--r-- | debian/changelog | 7 | ||||
-rw-r--r-- | debian/patches/000_resolv-conf.patch | 32 | ||||
-rw-r--r-- | debian/patches/000_ubuntu_init_resolvconf.patch | 153 | ||||
-rw-r--r-- | debian/patches/001-strip-init-d.patch | 36 | ||||
-rw-r--r-- | debian/patches/001_ubuntu_agent_startup.patch | 22 | ||||
-rw-r--r-- | debian/patches/series | 4 | ||||
-rw-r--r-- | debian/postinst | 4 | ||||
-rwxr-xr-x | debian/rules | 7 | ||||
-rw-r--r-- | debian/upstart | 26 | ||||
-rw-r--r-- | waagent | 156 |
11 files changed, 180 insertions, 279 deletions
diff --git a/Changelog b/Changelog new file mode 100644 index 0000000..13bd00e --- /dev/null +++ b/Changelog @@ -0,0 +1,12 @@ +WALinuxAgent Changelog +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| + +09 Nov 2012, WALinuxAgent 1.1 + . Added sock.settimeout in DoDhcpWork() to properly timeout sock.recv + . Added missingDefaultRoute to handle routing issues when DHCP responses not + handled properly + . Added Children.append to avoid zombies + . Fixed ifrenew for compatibility + . Fixed shadow password file for correct SELinux context + . Minor cleanup work + . Added Changelog :) diff --git a/debian/changelog b/debian/changelog index ba4f985..f5be404 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +walinuxagent (1.1-0ubuntu1) raring; urgency=low + + * New upstream version (LP: #1078074, #1077147). + * Moved upstart job to be managed by packaging. + + -- Ben Howard <ben.howard@ubuntu.com> Wed, 14 Nov 2012 10:59:37 -0700 + walinuxagent (1.0~git20120606.c16f5e9-0ubuntu2) quantal; urgency=low * Restrict target architectures to i386 and amd64. diff --git a/debian/patches/000_resolv-conf.patch b/debian/patches/000_resolv-conf.patch new file mode 100644 index 0000000..23404da --- /dev/null +++ b/debian/patches/000_resolv-conf.patch @@ -0,0 +1,32 @@ +Index: wa-new/waagent +=================================================================== +--- wa-new.orig/waagent 2012-11-14 11:06:12.227371000 -0700 ++++ wa-new/waagent 2012-11-14 11:07:53.093401274 -0700 +@@ -2262,7 +2262,26 @@ + Run("rm -f " + a + "/*") + + # Clear LibDir, remove nameserver and root bash history +- for f in os.listdir(LibDir) + ["/etc/resolv.conf", "/root/.bash_history", "/var/log/waagent.log"]: ++ fileBlackList = [ "/root/.bash_history", "/var/log/waagent.log" ] ++ ++ if IsUbuntu(): ++ # Ubuntu uses resolv.conf by default, so removing /etc/resolv.conf will ++ # break resolvconf. Therefore, we check to see if resolvconf is in use, ++ # and if so, we remove the resolvconf artifacts. ++ ++ if os.path.realpath('/etc/resolv.conf') != '/run/resolvconf/resolv.conf': ++ Log("resolvconf is not configured. Removing /etc/resolv.conf") ++ fileBlackList.append('/etc/resolv.conf') ++ else: ++ Log("resolvconf is enabled; leaving /etc/resolv.conf intact") ++ resolvConfD = '/etc/resolvconf/resolv.conf.d/' ++ fileBlackList.extend([resolvConfD + 'tail', resolvConfD + 'originial' ]) ++ else: ++ fileBlackList.append(os.listdir(LibDir) + '/etc/resolv.conf') ++ ++ ++ # Clear LibDir, remove nameserver and root bash history ++ for f in os.listdir(LibDir) + fileBlackList: + try: + os.remove(f) + except: diff --git a/debian/patches/000_ubuntu_init_resolvconf.patch b/debian/patches/000_ubuntu_init_resolvconf.patch deleted file mode 100644 index 70c0097..0000000 --- a/debian/patches/000_ubuntu_init_resolvconf.patch +++ /dev/null @@ -1,153 +0,0 @@ -Description: Microsoft provided walinuxagent does not include the - required UFS module, is not resolvconf aware, and does not provide - an upstart script; this patch fixes all of that. -Author: Ben Howard <ben.howard@ubuntu.com> -Bug-Ubuntu: https://bugs.launchpad.net/bugs/1014864 -Forwarded: yes - ---- a/waagent -+++ b/waagent -@@ -1970,6 +1970,26 @@ esac - exit $RETVAL - """ - -+Init_Ubuntu = """\ -+#walinuxagent - start Windows Azure agent -+ -+description "walinuxagent" -+author "Ben Howard <ben.howard@canonical.com>" -+ -+start on (filesystem and started rsyslog) -+ -+pre-start script -+ if [ ! -x /usr/sbin/waagent ]; then -+ exit 1 -+ fi -+ -+ #Load the udf module -+ modprobe -b udf -+end script -+ -+exec /usr/sbin/waagent -daemon -+""" -+ - Init_Debian = """\ - #!/bin/sh - ### BEGIN INIT INFO -@@ -2135,18 +2155,30 @@ def Install(): - os.remove(GetLastPathElement(a)) - shutil.move(a, ".") - Warn("Moved " + a + " -> " + LibDir + "/" + GetLastPathElement(a) ) -- filename = "waagent" -- filepath = "/etc/init.d/" + filename -- distro = IsRedHat() + IsDebian() * 2 + IsSuse() * 3 -- if distro == 0: -- Error("Unable to detect Linux Distribution.") -- return 1 -- init = [[Init_RedHat, "chkconfig --add " + filename], -- [Init_Debian, "update-rc.d " + filename + " defaults"], -- [Init_Suse, "insserv " + filename]][distro - 1] -- SetFileContents(filepath, init[0]) -- os.chmod(filepath, 0755) -- Run(init[1]) -+ -+ if IsUbuntu(): -+ # Support for Ubuntu's upstart configuration -+ filename="waagent.conf" -+ filepath = "/etc/init/" + filename -+ SetFileContents(filepath, Init_Ubuntu) -+ os.chmod(filepath, 0644) -+ -+ else: -+ # Regular init.d configurations -+ filename = "waagent" -+ filepath = "/etc/init.d/" + filename -+ -+ distro = IsRedHat() + IsDebian() * 2 + IsSuse() -+ if distro == 0: -+ Error("Unable to detect Linux Distribution.") -+ return 1 -+ init = [[Init_RedHat, "chkconfig --add " + filename], -+ [Init_Debian, "update-rc.d " + filename + " defaults"], -+ [Init_Suse, "insserv " + filename]][distro - 1] -+ SetFileContents(filepath, init[0]) -+ os.chmod(filepath, 0755) -+ Run(init[1]) -+ - if os.path.isfile("/etc/waagent.conf"): - try: - os.remove("/etc/waagent.conf.old") -@@ -2179,17 +2211,26 @@ def Uninstall(): - Warn("Moved " + LibDir + "/" + GetLastPathElement(a) + " -> " + a ) - except: - pass -+ -+ filepath = "/etc/init.d/" - filename = "waagent" -- a = IsRedHat() + IsDebian() * 2 + IsSuse() * 3 -- if a == 0: -- Error("Unable to detect Linux Distribution.") -- return 1 -- Run("service " + filename + " stop") -- cmd = ["chkconfig --del " + filename, -- "update-rc.d -f " + filename + " remove", -- "insserv -r " + filename][a - 1] -- Run(cmd) -- for f in os.listdir(LibDir) + ["/etc/init.d/" + filename, "/etc/waagent.conf", "/etc/logrotate.d/waagent", "/etc/sudoers.d/waagent"]: -+ -+ if IsUbuntu(): -+ Run("stop " + filename) -+ filepath = "/etc/init/" -+ filename = "waagent.conf" -+ else: -+ a = IsRedHat() + IsDebian() * 2 + IsSuse() * 3 -+ if a == 0: -+ Error("Unable to detect Linux Distribution.") -+ return 1 -+ Run("service " + filename + " stop") -+ cmd = ["chkconfig --del " + filename, -+ "update-rc.d -f " + filename + " remove", -+ "insserv -r " + filename][a - 1] -+ Run(cmd) -+ -+ for f in os.listdir(LibDir) + [filepath + filename, "/etc/waagent.conf", "/etc/logrotate.d/waagent", "/etc/sudoers.d/waagent"]: - try: - os.remove(f) - except: -@@ -2217,7 +2258,12 @@ def Deprovision(force, deluser): - - print("WARNING! The waagent service will be stopped.") - print("WARNING! All SSH host key pairs will be deleted.") -- print("WARNING! Nameserver configuration in /etc/resolv.conf will be deleted.") -+ -+ if IsUbuntu(): -+ print("WARNING! Nameserver configuration in /etc/resolvconf/resolv.conf.d/{tail,originial} will be deleted.") -+ else: -+ print("WARNING! Nameserver configuration in /etc/resolv.conf will be deleted.") -+ - print("WARNING! Cached DHCP leases will be deleted.") - - delRootPass = Config.get("Provisioning.DeleteRootPassword") -@@ -2253,7 +2299,21 @@ def Deprovision(force, deluser): - Run("rm -f " + a + "/*") - - # Clear LibDir, remove nameserver and root bash history -- for f in os.listdir(LibDir) + ["/etc/resolv.conf", "/root/.bash_history", "/var/log/waagent.log"]: -+ fileBlackList = [ "/root/.bash_history", "/var/log/waagent.log" ] -+ -+ # Ubuntu uses resolvconf, so we want to preserve the ability to use resolvconf -+ if IsUbuntu(): -+ if os.path.realpath('/etc/resolv.conf') != '/run/resolvconf/resolv.conf': -+ Log("resolvconf is not configured. Removing /etc/resolv.conf") -+ fileBlackList.append('/etc/resolv.conf') -+ else: -+ Log("resolvconf is enabled; leaving /etc/resolv.conf intact") -+ resolvConfD = '/etc/resolvconf/resolv.conf.d/' -+ fileBlackList.extend([resolvConfD + 'tail', resolvConfD + 'originial' ]) -+ else: -+ fileBlackList.append(os.listdir(LibDir) + '/etc/resolv.conf') -+ -+ for f in os.listdir(LibDir) + fileBlackList: - try: - os.remove(f) - except: diff --git a/debian/patches/001-strip-init-d.patch b/debian/patches/001-strip-init-d.patch new file mode 100644 index 0000000..0d88fe4 --- /dev/null +++ b/debian/patches/001-strip-init-d.patch @@ -0,0 +1,36 @@ +--- a/waagent ++++ b/waagent +@@ -2141,18 +2141,21 @@ def Install(): + os.remove(GetLastPathElement(a)) + shutil.move(a, ".") + Warn("Moved " + a + " -> " + LibDir + "/" + GetLastPathElement(a) ) +- filename = "waagent" +- filepath = "/etc/init.d/" + filename +- distro = IsRedHat() + IsDebian() * 2 + IsSuse() * 3 +- if distro == 0: +- Error("Unable to detect Linux Distribution.") +- return 1 +- init = [[Init_RedHat, "chkconfig --add " + filename], +- [Init_Debian, "update-rc.d " + filename + " defaults"], +- [Init_Suse, "insserv " + filename]][distro - 1] +- SetFileContents(filepath, init[0]) +- os.chmod(filepath, 0755) +- Run(init[1]) ++ ++ if not IsUbuntu(): ++ filename = "waagent" ++ filepath = "/etc/init.d/" + filename ++ distro = IsRedHat() + IsDebian() * 2 + IsSuse() * 3 ++ if distro == 0: ++ Error("Unable to detect Linux Distribution.") ++ return 1 ++ init = [[Init_RedHat, "chkconfig --add " + filename], ++ [Init_Debian, "update-rc.d " + filename + " defaults"], ++ [Init_Suse, "insserv " + filename]][distro - 1] ++ SetFileContents(filepath, init[0]) ++ os.chmod(filepath, 0755) ++ Run(init[1]) ++ + if os.path.isfile("/etc/waagent.conf"): + try: + os.remove("/etc/waagent.conf.old") diff --git a/debian/patches/001_ubuntu_agent_startup.patch b/debian/patches/001_ubuntu_agent_startup.patch deleted file mode 100644 index 118bdb0..0000000 --- a/debian/patches/001_ubuntu_agent_startup.patch +++ /dev/null @@ -1,22 +0,0 @@ -Description: Enablement/disablement via /etc/default/waagent - Allow users to control the startup of waagent via /etc/default/waagent. - Setting "WAAGENT_ENABLED=0" will turn off the agent at boot time. -Author: Ben Howard <ben.howard@ubuntu.com> -Bug-Ubuntu: https://bugs.launchpad.net/bugs/1014864 - ---- a/waagent -+++ b/waagent -@@ -1979,6 +1979,13 @@ author "Ben Howard <ben.howard@canonical - start on (filesystem and started rsyslog) - - pre-start script -+ -+ [ -r /etc/default/walinuxagent ] && . /etc/default/walinuxagent -+ -+ if [ "$WALINUXAGENT_ENABLED" != "1" ]; then -+ exit 1 -+ fi -+ - if [ ! -x /usr/sbin/waagent ]; then - exit 1 - fi diff --git a/debian/patches/series b/debian/patches/series index 233ee46..96a325a 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,2 +1,2 @@ -000_ubuntu_init_resolvconf.patch -001_ubuntu_agent_startup.patch +000_resolv-conf.patch +001-strip-init-d.patch diff --git a/debian/postinst b/debian/postinst index b18aa8e..263f5a6 100644 --- a/debian/postinst +++ b/debian/postinst @@ -6,8 +6,8 @@ case "$1" in ;; abort-upgrade|abort-remove|abort-deconfigure) - if [ -f /etc/init/waagent ]; then - rm /etc/init/waagent + if [ -f /etc/init.d/waagent ]; then + rm /etc/init.d/waagent fi ;; diff --git a/debian/rules b/debian/rules index 7923b65..cbb7be8 100755 --- a/debian/rules +++ b/debian/rules @@ -1,14 +1,13 @@ #!/usr/bin/make -f -DEB_UPSTREAM_VERSION=$(shell dpkg-parsechangelog | sed -rne 's,^Version: ([^-]+).*,\1,p') -ORIG_COMMIT=$(shell echo $(DEB_UPSTREAM_VERSION) | cut -f3 -d\. ) +DEB_VERSION=$(shell dpkg-parsechangelog | sed -rne 's,^Version: ([^-]+).*,\1,p') ORIG_SRC=https://github.com/Windows-Azure/WALinuxAgent get-packaged-orig-source: git clone --separate-git-dir=.git \ $(ORIG_SRC) orig_source - git archive --format=tar.gz $(ORIG_COMMIT) \ - -o walinuxagent_$(DEB_UPSTREAM_VERSION).orig.tar.gz + git archive --format=tar.gz WALinuxAgent-$(DEB_VERSION) \ + -o walinuxagent_$(DEB_VERSION).orig.tar.gz %: dh $@ --with python2 diff --git a/debian/upstart b/debian/upstart new file mode 100644 index 0000000..860d43a --- /dev/null +++ b/debian/upstart @@ -0,0 +1,26 @@ +#walinuxagent - start Windows Azure agent + +description "walinuxagent" +author "Ben Howard <ben.howard@canonical.com>" + +start on mounted MOUNTPOINT=/ +stop on runlevel [!2345] + +pre-start script + + [ -r /etc/default/walinuxagent ] && . /etc/default/walinuxagent + + if [ "$WALINUXAGENT_ENABLED" != "1" ]; then + stop ; exit 0 + fi + + if [ ! -x /usr/sbin/waagent ]; then + stop ; exit 0 + fi + + #Load the udf module + modprobe -b udf + +end script + +exec /usr/sbin/waagent -daemon @@ -35,6 +35,7 @@ import shutil import socket import SocketServer import struct +import subprocess import sys import tempfile import textwrap @@ -45,7 +46,7 @@ import xml.dom.minidom GuestAgentName = "WALinuxAgent" GuestAgentLongName = "Windows Azure Linux Agent" -GuestAgentVersion = "rd_wala.120504-1323" +GuestAgentVersion = "WALinuxAgent-1.1" ProtocolVersion = "2011-12-31" Config = None @@ -54,6 +55,7 @@ Verbose = False WaAgent = None DiskActivated = False Openssl = "openssl" +Children = [] PossibleEthernetInterfaces = ["seth0", "seth1", "eth0", "eth1"] RulesFiles = [ "/lib/udev/rules.d/75-persistent-net-generator.rules", @@ -437,9 +439,9 @@ def DeviceForIdePort(n): g0 = "00000001" n = n - 2 device = None - path="/sys/bus/vmbus/devices/" + path = "/sys/bus/vmbus/devices/" for vmbus in os.listdir(path): - guid=GetFileContents(path + vmbus + "/device_id").lstrip('{').split('-') + guid = GetFileContents(path + vmbus + "/device_id").lstrip('{').split('-') if guid[0] == g0 and guid[1] == "000" + str(n): for root, dirs, files in os.walk(path + vmbus): if root.endswith("/block"): @@ -531,9 +533,6 @@ def LoadBalancerProbeServer(port): class T(object): def __init__(self, port): - enabled = Config.get("LBProbeResponder") - if enabled != None and enabled.lower().startswith("n"): - return self.ProbeCounter = 0 self.server = SocketServer.TCPServer((GetIpv4Address(), port), TCPHandler) self.server_thread = threading.Thread(target = self.server.serve_forever) @@ -541,9 +540,6 @@ def LoadBalancerProbeServer(port): self.server_thread.start() def shutdown(self): - global EnableLoadBalancerProbes - if not EnableLoadBalancerProbes: - return self.server.shutdown() class TCPHandler(SocketServer.BaseRequestHandler): @@ -629,6 +625,9 @@ class EnvMonitor(object): Log("EnvMonitor: Detected dhcp client restart. Restoring routing table.") WaAgent.RestoreRoutes() dhcppid = pid + for child in Children: + if child.poll() != None: + Children.remove(child) time.sleep(5) def SetHostName(self, name): @@ -640,7 +639,7 @@ class EnvMonitor(object): def IsNamePublished(self): return self.published - def shutdown(self): + def ShutdownService(self): self.shutdown = True self.server_thread.join() @@ -797,7 +796,7 @@ class SharedConfig(object): return None program = Config.get("Role.TopologyConsumer") if program != None: - os.spawnl(os.P_NOWAIT, program, program, LibDir + "/SharedConfig.xml") + Children.append(subprocess.Popen([program, LibDir + "/SharedConfig.xml"])) return self class HostingEnvironmentConfig(object): @@ -943,7 +942,7 @@ class HostingEnvironmentConfig(object): if User != "root" and User != "" and Pass != "": CreateAccount(User, Pass, Expiration, Thumbprint) else: - Error("Not creating user account: user=" + User + " pass=" + Pass) + Error("Not creating user account: " + User) for c in self.Certificates: cname = c.getAttribute("name") csha1 = c.getAttribute("certificateId").split(':')[1].upper() @@ -955,7 +954,7 @@ class HostingEnvironmentConfig(object): Log("Public cert with thumbprint: " + csha1 + " was retrieved.") program = Config.get("Role.ConfigurationConsumer") if program != None: - os.spawnl(os.P_NOWAIT, program, program, LibDir + "/HostingEnvironmentConfig.xml") + Children.append(subprocess.Popen([program, LibDir + "/HostingEnvironmentConfig.xml"])) class GoalState(Util): # @@ -1202,7 +1201,7 @@ class OvfEnv(object): def NumberToBytes(self, i): result = [] while i: - result.append(chr(i&0xFF)) + result.append(chr(i & 0xFF)) i >>= 8 result.reverse() return ''.join(result) @@ -1585,13 +1584,22 @@ class Agent(Util): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - if IsSuse(): + missingDefaultRoute = True + try: + for line in os.popen("route -n").read().split('\n'): + if line.startswith("0.0.0.0 "): + missingDefaultRoute = False + except: + pass + if missingDefaultRoute: # This is required because sending after binding to 0.0.0.0 fails with # network unreachable when the default gateway is not set up. sock.bind((GetIpv4Address(), 68)) else: sock.bind(("0.0.0.0", 68)) sock.sendto(sendData, ("<broadcast>", 67)) + sock.settimeout(30) + LogIfVerbose("DoDhcpWork: Setting socket.timeout=10, entering recv") receiveBuffer = sock.recv(1024) sock.close() endpoint = self.HandleDhcpResponse(sendData, receiveBuffer) @@ -1617,10 +1625,7 @@ class Agent(Util): Log("Setting host name: " + name) UpdateAndPublishHostNameCommon(name) for ethernetInterface in PossibleEthernetInterfaces: - if IsSuse(): - Run("ifrenew " + ethernetInterface) - else: - Run("ifdown " + ethernetInterface + " && ifup " + ethernetInterface) + Run("ifdown " + ethernetInterface + " && ifup " + ethernetInterface) self.RestoreRoutes() def RestoreRoutes(self): @@ -1800,7 +1805,11 @@ class Agent(Util): goalState = None # self.GoalState, instance of GoalState provisioned = os.path.exists(LibDir + "/provisioned") program = Config.get("Role.StateConsumer") - provisionError = None + provisionError = None + lbProbeResponder = True + setting = Config.get("LBProbeResponder") + if setting != None and setting.lower().startswith("n"): + lbProbeResponder = False while True: if (goalState == None) or (incarnation == None) or (goalState.Incarnation != incarnation): goalState = self.UpdateGoalState() @@ -1823,18 +1832,18 @@ class Agent(Util): if currentPort != goalPort: self.LoadBalancerProbeServer_Shutdown() currentPort = goalPort - if currentPort != None: + if currentPort != None and lbProbeResponder == True: self.LoadBalancerProbeServer = LoadBalancerProbeServer(currentPort) if program != None and DiskActivated == True: - os.spawnl(os.P_NOWAIT, program, program, "Ready") + Children.append(subprocess.Popen([program, "Ready"])) program = None if goalState.ExpectedState == "Stopped": program = Config.get("Role.StateConsumer") if program != None: Run(program + " Shutdown") - self.EnvMonitor.shutdown() + self.EnvMonitor.ShutdownService() self.LoadBalancerProbeServer_Shutdown() command = ["/sbin/shutdown -hP now", "shutdown /s /t 5"][IsWindows()] Run(command) @@ -1842,13 +1851,10 @@ class Agent(Util): sleepToReduceAccessDenied = 3 time.sleep(sleepToReduceAccessDenied) - i = None if provisionError != None: - i = self.ReportNotReady("ProvisioningFailed", provisionError) + incarnation = self.ReportNotReady("ProvisioningFailed", provisionError) else: - i = self.ReportReady() - if i != None: - incarnation = i + incarnation = self.ReportReady() time.sleep(25 - sleepToReduceAccessDenied) Init_Suse = """\ @@ -1970,33 +1976,6 @@ esac exit $RETVAL """ -Init_Ubuntu = """\ -#walinuxagent - start Windows Azure agent - -description "walinuxagent" -author "Ben Howard <ben.howard@canonical.com>" - -start on (filesystem and started rsyslog) - -pre-start script - - [ -r /etc/default/walinuxagent ] && . /etc/default/walinuxagent - - if [ "$WALINUXAGENT_ENABLED" != "1" ]; then - exit 1 - fi - - if [ ! -x /usr/sbin/waagent ]; then - exit 1 - fi - - #Load the udf module - modprobe -b udf -end script - -exec /usr/sbin/waagent -daemon -""" - Init_Debian = """\ #!/bin/sh ### BEGIN INIT INFO @@ -2163,19 +2142,10 @@ def Install(): shutil.move(a, ".") Warn("Moved " + a + " -> " + LibDir + "/" + GetLastPathElement(a) ) - if IsUbuntu(): - # Support for Ubuntu's upstart configuration - filename="waagent.conf" - filepath = "/etc/init/" + filename - SetFileContents(filepath, Init_Ubuntu) - os.chmod(filepath, 0644) - - else: - # Regular init.d configurations + if not IsUbuntu(): filename = "waagent" filepath = "/etc/init.d/" + filename - - distro = IsRedHat() + IsDebian() * 2 + IsSuse() + distro = IsRedHat() + IsDebian() * 2 + IsSuse() * 3 if distro == 0: Error("Unable to detect Linux Distribution.") return 1 @@ -2218,26 +2188,17 @@ def Uninstall(): Warn("Moved " + LibDir + "/" + GetLastPathElement(a) + " -> " + a ) except: pass - - filepath = "/etc/init.d/" filename = "waagent" - - if IsUbuntu(): - Run("stop " + filename) - filepath = "/etc/init/" - filename = "waagent.conf" - else: - a = IsRedHat() + IsDebian() * 2 + IsSuse() * 3 - if a == 0: - Error("Unable to detect Linux Distribution.") - return 1 - Run("service " + filename + " stop") - cmd = ["chkconfig --del " + filename, - "update-rc.d -f " + filename + " remove", - "insserv -r " + filename][a - 1] - Run(cmd) - - for f in os.listdir(LibDir) + [filepath + filename, "/etc/waagent.conf", "/etc/logrotate.d/waagent", "/etc/sudoers.d/waagent"]: + a = IsRedHat() + IsDebian() * 2 + IsSuse() * 3 + if a == 0: + Error("Unable to detect Linux Distribution.") + return 1 + Run("service " + filename + " stop") + cmd = ["chkconfig --del " + filename, + "update-rc.d -f " + filename + " remove", + "insserv -r " + filename][a - 1] + Run(cmd) + for f in os.listdir(LibDir) + ["/etc/init.d/" + filename, "/etc/waagent.conf", "/etc/logrotate.d/waagent", "/etc/sudoers.d/waagent"]: try: os.remove(f) except: @@ -2246,10 +2207,13 @@ def Uninstall(): return 0 def DeleteRootPassword(): - SetFileContents("/etc/shadow-temp", "") - os.chmod("/etc/shadow-temp", 0000) - Run("(echo root:*LOCK*:14600:::::: && grep -v ^root /etc/shadow ) > /etc/shadow-temp") - Run("mv -f /etc/shadow-temp /etc/shadow") + filepath="/etc/shadow" + ReplaceFileContentsAtomic(filepath, "root:*LOCK*:14600::::::\n" + "\n".join(filter(lambda a: not + a.startswith("root:"), + GetFileContents(filepath).split('\n')))) + os.chmod(filepath, 0000) + if IsRedHat(): + Run("chcon system_u:object_r:shadow_t:s0 " + filepath) Log("Root password deleted.") def Deprovision(force, deluser): @@ -2265,12 +2229,7 @@ def Deprovision(force, deluser): print("WARNING! The waagent service will be stopped.") print("WARNING! All SSH host key pairs will be deleted.") - - if IsUbuntu(): - print("WARNING! Nameserver configuration in /etc/resolvconf/resolv.conf.d/{tail,originial} will be deleted.") - else: - print("WARNING! Nameserver configuration in /etc/resolv.conf will be deleted.") - + print("WARNING! Nameserver configuration in /etc/resolv.conf will be deleted.") print("WARNING! Cached DHCP leases will be deleted.") delRootPass = Config.get("Provisioning.DeleteRootPassword") @@ -2308,8 +2267,11 @@ def Deprovision(force, deluser): # Clear LibDir, remove nameserver and root bash history fileBlackList = [ "/root/.bash_history", "/var/log/waagent.log" ] - # Ubuntu uses resolvconf, so we want to preserve the ability to use resolvconf if IsUbuntu(): + # Ubuntu uses resolv.conf by default, so removing /etc/resolv.conf will + # break resolvconf. Therefore, we check to see if resolvconf is in use, + # and if so, we remove the resolvconf artifacts. + if os.path.realpath('/etc/resolv.conf') != '/run/resolvconf/resolv.conf': Log("resolvconf is not configured. Removing /etc/resolv.conf") fileBlackList.append('/etc/resolv.conf') @@ -2320,6 +2282,8 @@ def Deprovision(force, deluser): else: fileBlackList.append(os.listdir(LibDir) + '/etc/resolv.conf') + + # Clear LibDir, remove nameserver and root bash history for f in os.listdir(LibDir) + fileBlackList: try: os.remove(f) |