pycredentials: Add get_name() for a credentials cache
authorAndrew Bartlett <abartlet@samba.org>
Thu, 6 Jul 2017 02:47:01 +0000 (14:47 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 27 Jul 2017 22:25:13 +0000 (00:25 +0200)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
auth/credentials/pycredentials.c

index 0a29c5863221143897a6262f247244a94338fe73..a55529141b58b6f0f2459b458f9b2f04618efb17 100644 (file)
@@ -31,6 +31,8 @@
 #include <tevent.h>
 #include "libcli/auth/libcli_auth.h"
 #include "auth/credentials/credentials_internal.h"
+#include "system/kerberos.h"
+#include "auth/kerberos/kerberos.h"
 
 void initcredentials(void);
 
@@ -793,10 +795,38 @@ PyTypeObject PyCredentials = {
        .tp_methods = py_creds_methods,
 };
 
+static PyObject *py_ccache_name(PyObject *self, PyObject *unused)
+{
+       struct ccache_container *ccc = NULL;
+       char *name = NULL;
+       PyObject *py_name = NULL;
+       int ret;
+
+       ccc = pytalloc_get_type(self, struct ccache_container);
+
+       ret = krb5_cc_get_full_name(ccc->smb_krb5_context->krb5_context,
+                                   ccc->ccache, &name);
+       if (ret == 0) {
+               py_name = PyString_FromStringOrNULL(name);
+               SAFE_FREE(name);
+       } else {
+               PyErr_SetString(PyExc_RuntimeError,
+                               "Failed to get ccache name");
+               return NULL;
+       }
+       return py_name;
+}
+
+static PyMethodDef py_ccache_container_methods[] = {
+       { "get_name", py_ccache_name, METH_NOARGS,
+         "S.get_name() -> name\nObtain KRB5 credentials cache name." },
+       { NULL }
+};
 
 PyTypeObject PyCredentialCacheContainer = {
        .tp_name = "credentials.CredentialCacheContainer",
        .tp_flags = Py_TPFLAGS_DEFAULT,
+       .tp_methods = py_ccache_container_methods,
 };
 
 MODULE_INIT_FUNC(credentials)