]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Add rename method to kadm5_hook
authorGreg Hudson <ghudson@mit.edu>
Sat, 4 Jul 2015 00:13:43 +0000 (20:13 -0400)
committerGreg Hudson <ghudson@mit.edu>
Mon, 6 Jul 2015 19:07:52 +0000 (15:07 -0400)
Bump the minor version of the kadm5_hook interface to 2 and add a
rename method.  Invoke the rename method in kadm5_rename_principal()
like we do for other libkadm5srv operations.

Partly based on a patch from John Hascall.

ticket: 8171

doc/plugindev/kadm5_hook.rst
src/include/krb5/kadm5_hook_plugin.h
src/lib/kadm5/server_internal.h
src/lib/kadm5/srv/kadm5_hook.c
src/lib/kadm5/srv/svr_principal.c
src/plugins/kadm5_hook/test/main.c
src/tests/t_kadm5_hook.py

index f7c46b4e6dfaa4ba98bb895d25c499b6ea5f4bd2..ece3eacfc7b4c3075567134c02085120476db281 100644 (file)
@@ -8,8 +8,9 @@ changes are made to the Kerberos database through :ref:`kadmin(1)`.
 For a detailed description of the kadm5_hook interface, see the header
 file ``<krb5/kadm5_hook_plugin.h>``.
 
-The kadm5_hook interface has four primary methods: **chpass**,
-**create**, **modify**, and **remove**.  Each of these methods is
+The kadm5_hook interface has five primary methods: **chpass**,
+**create**, **modify**, **remove**, and **rename**.  (The **rename**
+method was introduced in release 1.14.)  Each of these methods is
 called twice when the corresponding administrative action takes place,
 once before the action is committed and once afterwards.  A module can
 prevent the action from taking place by returning an error code during
index c95c17f38c537df9d3e5ab45be8bd48ea951411f..f4f3730f4dfcaf0159fe8e5ac5cd5b63cf884225 100644 (file)
@@ -46,6 +46,9 @@
  * This interface depends on kadm5/admin.h. As such, the interface
  * does not provide strong guarantees of ABI stability.
  *
+ * The kadm5_hook interface currently has only one supported major version,
+ * which is 1.  Major version 1 has a current minor version number of 2.
+ *
  * kadm5_hook plugins should:
  * kadm5_hook_<modulename>_initvt, matching the signature:
  *
@@ -138,6 +141,14 @@ typedef struct kadm5_hook_vtable_1_st {
                           int stage, krb5_principal);
 
     /* End of minor version 1. */
+
+    /** Indicate a principal is renamed. */
+    kadm5_ret_t (*rename)(krb5_context,
+                          kadm5_hook_modinfo *modinfo,
+                          int stage, krb5_principal, krb5_principal);
+
+    /* End of minor version 2. */
+
 } kadm5_hook_vftable_1;
 
 #endif /*H_KRB5_KADM5_HOOK_PLUGIN*/
index 623187dd56559f1d929ffda3c13d94ebfd1fa741..dc79c786b91eeef6f3cf4829aa8c621b3f383b46 100644 (file)
@@ -255,6 +255,13 @@ k5_kadm5_hook_remove (krb5_context context,
                       int stage,
                       krb5_principal princ);
 
+/** Call rename kadm5_hook entry point. */
+kadm5_ret_t
+k5_kadm5_hook_rename (krb5_context context,
+                      kadm5_hook_handle *handles,
+                      int stage,
+                      krb5_principal oprinc, krb5_principal nprinc);
+
 /** @}*/
 
 #endif /* __KADM5_SERVER_INTERNAL_H__ */
index 62f3bffcea5d833d84c8097dafacbbb02cee1316..13f454fcd0e5517b26b92790ad5234dd43ecfa79 100644 (file)
@@ -64,7 +64,7 @@ k5_kadm5_hook_load(krb5_context context,
         handle = k5alloc(sizeof(*handle), &ret);
         if (handle == NULL)
             goto cleanup;
-        ret = (*mod)(context, 1, 1, (krb5_plugin_vtable)&handle->vt);
+        ret = (*mod)(context, 1, 2, (krb5_plugin_vtable)&handle->vt);
         if (ret != 0) {         /* Failed vtable init is non-fatal. */
             free(handle);
             handle = NULL;
@@ -168,6 +168,14 @@ k5_kadm5_hook_modify(krb5_context context, kadm5_hook_handle *handles,
     return 0;
 }
 
+kadm5_ret_t
+k5_kadm5_hook_rename(krb5_context context, kadm5_hook_handle *handles,
+                     int stage, krb5_principal oprinc, krb5_principal nprinc)
+{
+    ITERATE(rename, (context, h->data, stage, oprinc, nprinc));
+    return 0;
+}
+
 kadm5_ret_t
 k5_kadm5_hook_remove(krb5_context context, kadm5_hook_handle *handles,
                      int stage, krb5_principal princ)
index 27f8eba2d908e4f76f9a1392e11e0dffd8592026..5b95fa3e13de925ad826016e86209e17ec40ef16 100644 (file)
@@ -835,9 +835,17 @@ kadm5_rename_principal(void *server_handle,
         goto done;
     }
 
+    ret = k5_kadm5_hook_rename(handle->context, handle->hook_handles,
+                               KADM5_HOOK_STAGE_PRECOMMIT, source, target);
+    if (ret)
+        goto done;
+
     if ((ret = kdb_put_entry(handle, kdb, &adb)))
         goto done;
 
+    (void) k5_kadm5_hook_rename(handle->context, handle->hook_handles,
+                                KADM5_HOOK_STAGE_POSTCOMMIT, source, target);
+
     ret = kdb_delete_entry(handle, source);
 
 done:
index 48b549c1306a9bf835e5effea1c827acf2459980..1ac2cb08abbad87eefc228ae6cee1fd5bbf233e2 100644 (file)
@@ -81,6 +81,13 @@ create(krb5_context context,
     return 0;
 }
 
+static kadm5_ret_t
+rename_hook(krb5_context context, kadm5_hook_modinfo *modinfo, int stage,
+            krb5_principal oprinc, krb5_principal nprinc)
+{
+    log_call(context, "rename", stage, oprinc);
+    return 0;
+}
 
 krb5_error_code
 kadm5_hook_test_initvt(krb5_context context, int maj_ver, int min_ver,
@@ -97,5 +104,6 @@ kadm5_hook_test_initvt(krb5_context context, int maj_ver, int min_ver,
     vt->name = "test";
     vt->chpass = chpass;
     vt->create = create;
+    vt->rename = rename_hook;
     return 0;
 }
index b0de25c6ffc4f778af0f2a67c94b08b9945796e3..708e328b000b790d79157b79262ad136392e218c 100755 (executable)
@@ -11,4 +11,8 @@ output = realm.run([kadminl, 'addprinc', '-randkey', 'test'])
 if "create: stage precommit" not in output:
     fail('kadm5_hook test output not found')
 
+output = realm.run([kadminl, 'renprinc', 'test', 'test2'])
+if "rename: stage precommit" not in output:
+    fail('kadm5_hook test output not found')
+
 success('kadm5_hook')