From be3f03e7d8e7f732ec7985939679c921a9aaf8c4 Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Mon, 17 Sep 2012 02:08:56 -0400 Subject: [PATCH] kinit when creating a MoiraList object This allows group/diffs.py to work without kinit'ing outside the script, fixing the key deficiency in ac9b167bcf85a9f723e27967649c2c033f2259da. --- __init__.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index 8f9356d..0771531 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,6 @@ import os import subprocess +import tempfile import ldap import ldap.filter @@ -12,7 +13,7 @@ from django.contrib import auth from django.core.exceptions import ObjectDoesNotExist from django.core.validators import URLValidator, ValidationError -import settings +from django.conf import settings def zephyr(msg, clas='message', instance='log', rcpt='nobody',): proc = subprocess.Popen( @@ -56,6 +57,18 @@ def pag_check_call(args, **kwargs): def pag_check_output(args, **kwargs): return pag_check_helper(subprocess.check_output, args, **kwargs) +def kinit(keytab=None, principal=None, autodelete=True, ): + if not keytab: + keytab = settings.KRB_KEYTAB + if not principal: + principal = settings.KRB_PRINCIPAL + assert keytab and principal + fd = tempfile.NamedTemporaryFile(mode='rb', prefix="krb5cc_djmit_", delete=autodelete, ) + env = dict(KRB5CCNAME=fd.name) + kinit_cmd = ['kinit', '-k', '-t', keytab, principal, ] + subprocess.check_call(kinit_cmd, env=env) + return fd + class ScriptsRemoteUserMiddleware(RemoteUserMiddleware): header = 'SSL_CLIENT_S_DN_Email' -- 2.45.0