X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/python-afs.git/blobdiff_plain/b96524d6b92de2d8aeb8b1aa5f83f2dbc822f5f2..94a09d55edd7d3c1b53424ee1a39245db751c5e9:/afs/_pts.pyx?ds=sidebyside diff --git a/afs/_pts.pyx b/afs/_pts.pyx index 107bf85..3c10b70 100644 --- a/afs/_pts.pyx +++ b/afs/_pts.pyx @@ -1,7 +1,8 @@ -from afs cimport * -from afs import pyafs_error +from afs._util cimport * +from afs._util import pyafs_error +import re -cdef import from "afs/ptuser.h": +cdef extern from "afs/ptuser.h": enum: PR_MAXNAMELEN PRGRP @@ -67,17 +68,17 @@ cdef import from "afs/ptuser.h": int ubik_PR_ListEntries(ubik_client *, afs_int32, afs_int32, afs_int32, prentries *, afs_int32 *) int ubik_PR_SetFieldsEntry(ubik_client *, afs_int32, afs_int32, afs_int32, afs_int32, afs_int32, afs_int32, afs_int32, afs_int32) -cdef import from "afs/pterror.h": +cdef extern from "afs/pterror.h": enum: PRNOENT -cdef import from "krb5/krb5.h": +cdef extern from "krb5/krb5.h": struct _krb5_context: pass struct krb5_principal_data: pass - ctypedef _krb5_context krb5_context + ctypedef _krb5_context * krb5_context ctypedef krb5_principal_data * krb5_principal ctypedef long krb5_int32 @@ -138,6 +139,28 @@ cdef int _ptentry_to_c(prcheckentry * c_entry, PTEntry p_entry) except -1: strncpy(c_entry.name, p_entry.name, sizeof(c_entry.name)) return 0 +cdef object kname_re = re.compile(r'^([^.].*?)(?malloc(40) + k4_name[0] = '\0' + k4_inst = malloc(40) + k4_inst[0] = '\0' + k4_realm = malloc(40) + k4_realm[0] = '\0' + + code = krb5_init_context(&ctx) + try: + pyafs_error(code) + + code = krb5_parse_name(ctx, krb5_name, &k5_princ) + try: + pyafs_error(code) + + code = krb5_524_conv_principal(ctx, k5_princ, k4_name, k4_inst, k4_realm) + pyafs_error(code) + + afs_princ = kname_unparse(k4_name, k4_inst, k4_realm) + afs_name, afs_realm = afs_princ.rsplit('@', 1) + + if k4_realm == self.realm: + return afs_name + else: + return '%s@%s' % (afs_name, afs_realm.lower()) + finally: + if k5_princ is not NULL: + krb5_free_principal(ctx, k5_princ) + finally: + if ctx is not NULL: + krb5_free_context(ctx)