samba_dnsupdate: tmp file cleanup on exception

Jean Raby jraby at inverse.ca
Wed Apr 10 19:36:27 MDT 2013


On 13-04-10 7:00 PM, Andrew Bartlett wrote:
> Any chance of getting that to me as a git patch?
of course, here it is.

Thanks!

-- 
Jean Raby
jraby at inverse.ca  ::  +1.514.447.4918 (x120) ::  www.inverse.ca
Inverse inc. :: Leaders behind SOGo (www.sogo.nu) and PacketFence 
(www.packetfence.org)
-------------- next part --------------
From 8fe9adba45614478b4d714da1180ebcbb1637bb6 Mon Sep 17 00:00:00 2001
From: Jean Raby <jraby at inverse.ca>
Date: Wed, 10 Apr 2013 21:33:34 -0400
Subject: [PATCH] Avoid leaking temp file if an exception is raised

---
 source4/scripting/bin/samba_dnsupdate | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/source4/scripting/bin/samba_dnsupdate b/source4/scripting/bin/samba_dnsupdate
index 33c16ec..68b0f72 100755
--- a/source4/scripting/bin/samba_dnsupdate
+++ b/source4/scripting/bin/samba_dnsupdate
@@ -116,7 +116,11 @@ def get_credentials(lp):
     creds.set_machine_account(lp)
     creds.set_krb_forwardable(credentials.NO_KRB_FORWARDABLE)
     (tmp_fd, ccachename) = tempfile.mkstemp()
-    creds.get_named_ccache(lp, ccachename)
+    try:
+        creds.get_named_ccache(lp, ccachename)
+    except RuntimeError as e:
+        os.unlink(ccachename)
+        raise e
 
 
 class dnsobj(object):
-- 
1.8.0


More information about the samba-technical mailing list