From 3d674925fd911748df6b516b05899e02cec27463 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Nov 28 2016 03:20:04 +0000 Subject: New method has_creds has_creds helps to determine if credential cache collection contains any credentials, whatever DIR: or FILE: is used. Signed-off-by: Chenxiong Qi --- diff --git a/cccolutils.c b/cccolutils.c index 058feb5..aff1c8d 100644 --- a/cccolutils.c +++ b/cccolutils.c @@ -19,6 +19,8 @@ krb5_context kcontext; +static PyObject *has_creds(PyObject *self, PyObject *args); + static PyObject * get_username(PyObject *self, PyObject *args) { @@ -65,8 +67,29 @@ get_username(PyObject *self, PyObject *args) Py_RETURN_NONE; } +static PyObject * +has_creds(PyObject *self, PyObject *args) +{ + krb5_error_code code; + code = krb5_cccol_have_content(kcontext); + if (code == 0) + { + Py_RETURN_TRUE; + } + else if (code == KRB5_CC_NOTFOUND) + { + Py_RETURN_FALSE; + } + else + { + PyErr_SetString(PyExc_RuntimeError, "Error checking content of credential cache."); + return NULL; + } +} + static PyMethodDef CCColUtilsMethods[] = { {"get_user_for_realm", get_username, METH_VARARGS, "Get username for a realm"}, + {"has_creds", has_creds, METH_NOARGS, "Check if there is any credentials."}, {NULL, NULL, 0, NULL} };