#3 New method has_creds
Merged 8 years ago by puiterwijk. Opened 8 years ago by cqi.
cqi/cccolutils new-method-has_creds  into  master

file modified
+23
@@ -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 @@ 

      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}

  };

  

has_creds helps to determine if credential cache collection contains any
credentials, whatever DIR: or FILE: is used.

Signed-off-by: Chenxiong Qi cqi@redhat.com

rebased

8 years ago

With this patch, no need to fix anything for the following question mentioned in comment https://pagure.io/cccolutils/issue/1#comment-43433

Do you mean you want a different output between "there are no caches" and "there are caches, but none with the correct realm"?

Pull-Request has been merged by puiterwijk

8 years ago
Metadata