summaryrefslogtreecommitdiffstats
path: root/ipapython
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2015-06-04 11:59:22 +0000
committerJan Cholasta <jcholast@redhat.com>2015-06-08 15:33:36 +0000
commit08229a0c5457d4e0c13d6b02a1f38f60ea787856 (patch)
tree7e0d0318cc2b33b4fdbfa235ad06d81ae013a3c0 /ipapython
parent4c70590c2a78b6d2cbfed585502442f733f26389 (diff)
downloadfreeipa-08229a0c5457d4e0c13d6b02a1f38f60ea787856.tar.gz
freeipa-08229a0c5457d4e0c13d6b02a1f38f60ea787856.tar.xz
freeipa-08229a0c5457d4e0c13d6b02a1f38f60ea787856.zip
install: Move private_ccache from ipaserver to ipapython
https://fedorahosted.org/freeipa/ticket/4468 Reviewed-By: Martin Basti <mbasti@redhat.com>
Diffstat (limited to 'ipapython')
-rw-r--r--ipapython/ipautil.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index abdb96d9b..f0c9c6b5a 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -38,6 +38,7 @@ import krbV
import pwd
from dns import resolver, rdatatype
from dns.exception import DNSException
+from contextlib import contextmanager
from ipapython.ipa_log_manager import *
from ipapython import ipavalidate
@@ -1300,3 +1301,26 @@ def restore_hostname(statestore):
run([paths.BIN_HOSTNAME, old_hostname])
except CalledProcessError, e:
print >>sys.stderr, "Failed to set this machine hostname back to %s: %s" % (old_hostname, str(e))
+
+
+@contextmanager
+def private_ccache(path=None):
+
+ if path is None:
+ (desc, path) = tempfile.mkstemp(prefix='krbcc')
+ os.close(desc)
+
+ original_value = os.environ.get('KRB5CCNAME', None)
+
+ os.environ['KRB5CCNAME'] = path
+
+ try:
+ yield
+ finally:
+ if original_value is not None:
+ os.environ['KRB5CCNAME'] = original_value
+ else:
+ os.environ.pop('KRB5CCNAME')
+
+ if os.path.exists(path):
+ os.remove(path)