Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/PyKAdminObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,59 @@ static PyObject *PyKAdminObject_delete_principal(PyKAdminObject *self, PyObject
}


static PyObject *PyKAdminObject_rename_principal(PyKAdminObject *self, PyObject *args, PyObject *kwds) {

kadm5_ret_t retval = KADM5_OK;
krb5_error_code code = 0;
krb5_principal old_principal = NULL;
krb5_principal new_principal = NULL;

char *old_principal_name = NULL;
char *new_principal_name = NULL;

PyObject *result = Py_True;

if (!PyArg_ParseTuple(args, "ss", &old_principal_name, &new_principal_name))
return NULL;

if (self->server_handle) {

code = krb5_parse_name(self->context, old_principal_name, &old_principal);
if (code) {
PyKAdminError_raise_error(code, "krb5_parse_name");
result = NULL;
goto cleanup;
}

code = krb5_parse_name(self->context, new_principal_name, &new_principal);
if (code) {
PyKAdminError_raise_error(code, "krb5_parse_name");
result = NULL;
goto cleanup;
}

retval = kadm5_rename_principal(self->server_handle, old_principal, new_principal);
if (retval != KADM5_OK) {
PyKAdminError_raise_error(retval, "kadm5_rename_principal");
result = NULL;
goto cleanup;
}

}

cleanup:

if (old_principal)
krb5_free_principal(self->context, old_principal);
if (new_principal)
krb5_free_principal(self->context, new_principal);

Py_XINCREF(result);
return result;

}


static PyObject *PyKAdminObject_create_principal(PyKAdminObject *self, PyObject *args, PyObject *kwds) {

kadm5_ret_t retval = KADM5_OK;
Expand Down Expand Up @@ -511,6 +564,9 @@ static PyMethodDef PyKAdminObject_methods[] = {
{"principals", (PyCFunction)PyKAdminObject_principal_iter, (METH_VARARGS | METH_KEYWORDS), ""},
{"policies", (PyCFunction)PyKAdminObject_policy_iter, (METH_VARARGS | METH_KEYWORDS), ""},

{"renprinc", (PyCFunction)PyKAdminObject_rename_principal, METH_VARARGS, ""},
{"rename_principal", (PyCFunction)PyKAdminObject_rename_principal, METH_VARARGS, ""},

// todo implement
{"lock", (PyCFunction)NULL, METH_NOARGS, ""},
{"unlock", (PyCFunction)NULL, METH_NOARGS, ""},
Expand Down
14 changes: 14 additions & 0 deletions test/unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,20 @@ def test_delete(self):

delete_test_accounts()

def test_rename(self):
kadm = self.kadm

create_test_accounts()

account = TEST_ACCOUNTS[0]

kadm.rename_principal(account, 'other@EXAMPLE.COM')

try:
self.assertFalse(kadm.principal_exists(account))
self.assertTrue(kadm.principal_exists('other@EXAMPLE.COM'))
finally:
kadm.delprinc('other@EXAMPLE.COM')

def test_double_create(self):

Expand Down