]> eyrie.org Git - kerberos/krb5-sync.git/commitdiff
Rename all of the internal functions
authorRuss Allbery <eagle@eyrie.org>
Thu, 21 Nov 2013 03:13:38 +0000 (19:13 -0800)
committerRuss Allbery <eagle@eyrie.org>
Thu, 21 Nov 2013 03:13:38 +0000 (19:13 -0800)
Use the much shorter sync_ prefix instead of pwupdate, and don't
care internally about pre-commit vs. post-commit.  We handle that
entirely in the module glue layer now.  Remove the empty and
never-called postcommit password function.

plugin/ad.c
plugin/api.c
plugin/heimdal.c
plugin/instance.c
plugin/internal.h
plugin/mit.c
plugin/queue.c
tests/plugin/queue-only-t.c
tests/plugin/queuing-t.c
tools/krb5-sync.c

index 61cb7fa5dd20c9b8dd1b92b3cb71beee195ee497..9a4cd4f5132b8ed9553dc2b52e64fdff012dd468 100644 (file)
@@ -182,9 +182,9 @@ get_ad_principal(kadm5_hook_modinfo *config, krb5_context ctx,
  * length.  Returns a Kerberos error code.
  */
 krb5_error_code
-pwupdate_ad_change(kadm5_hook_modinfo *config, krb5_context ctx,
-                   krb5_principal principal, const char *password,
-                   int pwlen UNUSED)
+sync_ad_chpass(kadm5_hook_modinfo *config, krb5_context ctx,
+               krb5_principal principal, const char *password,
+               int pwlen UNUSED)
 {
     krb5_error_code code;
     char *target = NULL;
@@ -261,8 +261,8 @@ ad_interact_sasl(LDAP *ld UNUSED, unsigned flags UNUSED,
  * length.
  */
 krb5_error_code
-pwupdate_ad_status(kadm5_hook_modinfo *config, krb5_context ctx,
-                   krb5_principal principal, int enabled)
+sync_ad_status(kadm5_hook_modinfo *config, krb5_context ctx,
+               krb5_principal principal, int enabled)
 {
     krb5_ccache ccache;
     krb5_principal ad_principal = NULL;
index f232e42d96406a0670b85de23534cddd724bee2a..1778025c3e4b7c8fd7ff0027e63da0d7a6828256 100644 (file)
@@ -37,7 +37,7 @@
  * This function returns failure only if it could not allocate memory.
  */
 krb5_error_code
-pwupdate_init(krb5_context ctx, kadm5_hook_modinfo **result)
+sync_init(krb5_context ctx, kadm5_hook_modinfo **result)
 {
     kadm5_hook_modinfo *config;
 
@@ -76,7 +76,7 @@ pwupdate_init(krb5_context ctx, kadm5_hook_modinfo **result)
  * since we don't store any other local state.
  */
 void
-pwupdate_close(kadm5_hook_modinfo *config)
+sync_close(kadm5_hook_modinfo *config)
 {
     free(config->ad_keytab);
     free(config->ad_principal);
@@ -160,8 +160,8 @@ principal_allowed(kadm5_hook_modinfo *config, krb5_context ctx,
      * Otherwise, if the principal is multi-part, check the instance.
      */
     if (pwchange && ncomp == 1 && config->ad_base_instance != NULL) {
-        okay = !pwupdate_instance_exists(config, ctx, principal,
-                                         config->ad_base_instance);
+        okay = !sync_instance_exists(config, ctx, principal,
+                                     config->ad_base_instance);
         if (!okay) {
             code = krb5_unparse_name(ctx, principal, &display);
             if (code != 0)
@@ -210,9 +210,8 @@ principal_allowed(kadm5_hook_modinfo *config, krb5_context ctx,
  * Currently, we can't do anything in that case, so just skip it.
  */
 krb5_error_code
-pwupdate_precommit_password(kadm5_hook_modinfo *config, krb5_context ctx,
-                            krb5_principal principal,
-                            const char *password, int pwlen)
+sync_chpass(kadm5_hook_modinfo *config, krb5_context ctx,
+            krb5_principal principal, const char *password, int pwlen)
 {
     krb5_error_code code;
     const char *message;
@@ -223,11 +222,11 @@ pwupdate_precommit_password(kadm5_hook_modinfo *config, krb5_context ctx,
         return 0;
     if (!principal_allowed(config, ctx, principal, 1))
         return 0;
-    if (pwupdate_queue_conflict(config, ctx, principal, "ad", "password"))
+    if (sync_queue_conflict(config, ctx, principal, "ad", "password"))
         goto queue;
     if (config->ad_queue_only)
         goto queue;
-    code = pwupdate_ad_change(config, ctx, principal, password, pwlen);
+    code = sync_ad_chpass(config, ctx, principal, password, pwlen);
     if (code != 0) {
         message = krb5_get_error_message(ctx, code);
         syslog(LOG_INFO, "krb5-sync: AD password change failed, queuing: %s",
@@ -238,22 +237,8 @@ pwupdate_precommit_password(kadm5_hook_modinfo *config, krb5_context ctx,
     return 0;
 
 queue:
-    return pwupdate_queue_write(config, ctx, principal, "ad", "password",
-                                password);
-}
-
-
-/*
- * Actions to take after the password is changed in the local database.
- * Currently, there are none.
- */
-krb5_error_code
-pwupdate_postcommit_password(kadm5_hook_modinfo *config UNUSED,
-                             krb5_context ctx UNUSED,
-                             krb5_principal principal UNUSED,
-                             const char *password UNUSED, int pwlen UNUSED)
-{
-    return 0;
+    return sync_queue_write(config, ctx, principal, "ad", "password",
+                            password);
 }
 
 
@@ -267,8 +252,8 @@ pwupdate_postcommit_password(kadm5_hook_modinfo *config UNUSED,
  * queue it for later processing.
  */
 krb5_error_code
-pwupdate_postcommit_status(kadm5_hook_modinfo *config, krb5_context ctx,
-                           krb5_principal principal, int enabled)
+sync_status(kadm5_hook_modinfo *config, krb5_context ctx,
+            krb5_principal principal, int enabled)
 {
     krb5_error_code code;
 
@@ -279,16 +264,16 @@ pwupdate_postcommit_status(kadm5_hook_modinfo *config, krb5_context ctx,
         return 0;
     if (!principal_allowed(config, ctx, principal, 0))
         return 0;
-    if (pwupdate_queue_conflict(config, ctx, principal, "ad", "enable"))
+    if (sync_queue_conflict(config, ctx, principal, "ad", "enable"))
         goto queue;
     if (config->ad_queue_only)
         goto queue;
-    code = pwupdate_ad_status(config, ctx, principal, enabled);
+    code = sync_ad_status(config, ctx, principal, enabled);
     if (code != 0)
         goto queue;
     return 0;
 
 queue:
-    return pwupdate_queue_write(config, ctx, principal, "ad",
-                                enabled ? "enable" : "disable", NULL);
+    return sync_queue_write(config, ctx, principal, "ad",
+                            enabled ? "enable" : "disable", NULL);
 }
index 75ba563d170adecda1299521f2fff49f58f819e1..da50a84038aaa62725d6dc1fd682d19da1abc89e 100644 (file)
@@ -55,7 +55,7 @@ typedef struct kadm5_hook {
 static krb5_error_code
 init(krb5_context ctx, void **data)
 {
-    return pwupdate_init(ctx, (kadm5_hook_modinfo **) data);
+    return sync_init(ctx, (kadm5_hook_modinfo **) data);
 }
 
 
@@ -65,7 +65,7 @@ init(krb5_context ctx, void **data)
 static void
 fini(krb5_context ctx UNUSED, void *data)
 {
-    pwupdate_close(data);
+    sync_close(data);
 }
 
 
@@ -90,10 +90,7 @@ chpass(krb5_context ctx, void *data, enum kadm5_hook_stage stage,
 
     /* Dispatch to the appropriate function. */
     if (stage == KADM5_HOOK_STAGE_PRECOMMIT)
-        code = pwupdate_precommit_password(data, ctx, princ, password, length);
-    else if (stage == KADM5_HOOK_STAGE_POSTCOMMIT)
-        code = pwupdate_postcommit_password(data, ctx, princ, password,
-                                            length);
+        code = sync_chpass(data, ctx, princ, password, length);
     return code;
 }
 
@@ -128,8 +125,7 @@ modify(krb5_context ctx, void *data, enum kadm5_hook_stage stage,
 
     if (mask & KADM5_ATTRIBUTES && stage == KADM5_HOOK_STAGE_POSTCOMMIT) {
         enabled = !(entry->attributes & KRB5_KDB_DISALLOW_ALL_TIX);
-        return pwupdate_postcommit_status(data, ctx, entry->principal,
-                                          enabled);
+        return sync_status(data, ctx, entry->principal, enabled);
     }
     return 0;
 }
index 2c1fd7bcbf8c465256d3cca2c45294eee6155e4a..ba91d338e54593efe1f8b8c15d57d0fd0ed5bedd 100644 (file)
@@ -28,9 +28,8 @@
  * or on any other error.
  */
 int
-pwupdate_instance_exists(kadm5_hook_modinfo *config UNUSED,
-                         krb5_context ctx, krb5_principal base,
-                         const char *instance)
+sync_instance_exists(kadm5_hook_modinfo *config UNUSED, krb5_context ctx,
+                     krb5_principal base, const char *instance)
 {
     krb5_principal princ = NULL;
     krb5_error_code code;
index d61686201e3f3d3e8fadf100e03e3904a4d8546a..fe6f49d8c7c2aa4e09fade76fec6f0e9694249f9 100644 (file)
@@ -50,42 +50,44 @@ BEGIN_DECLS
 /* Default to a hidden visibility for all internal functions. */
 #pragma GCC visibility push(hidden)
 
-/* General public API. */
-krb5_error_code pwupdate_init(krb5_context, kadm5_hook_modinfo **);
-void pwupdate_close(kadm5_hook_modinfo *);
-krb5_error_code pwupdate_precommit_password(kadm5_hook_modinfo *,
-                                            krb5_context, krb5_principal,
-                                            const char *password,
-                                            int pwlen);
-krb5_error_code pwupdate_postcommit_password(kadm5_hook_modinfo *,
-                                             krb5_context, krb5_principal,
-                                             const char *password,
-                                             int pwlen);
-krb5_error_code pwupdate_postcommit_status(kadm5_hook_modinfo *,
-                                           krb5_context, krb5_principal,
-                                           int enabled);
-
-/* Password changing. */
-krb5_error_code pwupdate_ad_change(kadm5_hook_modinfo *, krb5_context,
-                                   krb5_principal, const char *password,
-                                   int pwlen);
-
-/* Account status update. */
-krb5_error_code pwupdate_ad_status(kadm5_hook_modinfo *, krb5_context,
-                                   krb5_principal, int enabled);
-
-/* Instance lookups. */
-int pwupdate_instance_exists(kadm5_hook_modinfo *, krb5_context,
-                             krb5_principal, const char *instance);
-
-/* Queuing. */
-int pwupdate_queue_conflict(kadm5_hook_modinfo *, krb5_context,
-                            krb5_principal, const char *domain,
-                            const char *operation);
-krb5_error_code pwupdate_queue_write(kadm5_hook_modinfo *, krb5_context,
-                                     krb5_principal, const char *domain,
-                                     const char *operation,
-                                     const char *password);
+/* Initialize the plugin and set up configuration. */
+krb5_error_code sync_init(krb5_context, kadm5_hook_modinfo **);
+
+/* Free the internal plugin state. */
+void sync_close(kadm5_hook_modinfo *);
+
+/* Handle a password change. */
+krb5_error_code sync_chpass(kadm5_hook_modinfo *, krb5_context,
+                            krb5_principal, const char *password, int pwlen);
+
+/* Handle an account status change. */
+krb5_error_code sync_status(kadm5_hook_modinfo *, krb5_context,
+                            krb5_principal, int enabled);
+
+/* Password changing in Active Directory. */
+krb5_error_code sync_ad_chpass(kadm5_hook_modinfo *, krb5_context,
+                               krb5_principal, const char *password,
+                               int pwlen);
+
+/* Account status update in Active Directory. */
+krb5_error_code sync_ad_status(kadm5_hook_modinfo *, krb5_context,
+                               krb5_principal, int enabled);
+
+/*
+ * Returns true if the principal has only one component and two-component
+ * principal with instance added exists in the Kerberos database.
+ */
+int sync_instance_exists(kadm5_hook_modinfo *, krb5_context, krb5_principal,
+                         const char *instance);
+
+/* Returns true if there is a queue conflict for this operation. */
+int sync_queue_conflict(kadm5_hook_modinfo *, krb5_context, krb5_principal,
+                        const char *domain, const char *operation);
+
+/* Writes an operation to the queue. */
+krb5_error_code sync_queue_write(kadm5_hook_modinfo *, krb5_context,
+                                 krb5_principal, const char *domain,
+                                 const char *operation, const char *password);
 
 /*
  * Obtain configuration settings from krb5.conf.  These are wrappers around
index b5893ac45cd502b3a683b85e06eafa3af8ee9c02..2c52d8c637d125336752720b3041e2fa289f2d56 100644 (file)
@@ -49,7 +49,7 @@ krb5_error_code kadm5_hook_krb5_sync_initvt(krb5_context, int, int,
 static kadm5_ret_t
 init(krb5_context ctx, kadm5_hook_modinfo **data)
 {
-    return pwupdate_init(ctx, data);
+    return sync_init(ctx, data);
 }
 
 
@@ -59,7 +59,7 @@ init(krb5_context ctx, kadm5_hook_modinfo **data)
 static void
 fini(krb5_context ctx UNUSED, kadm5_hook_modinfo *data)
 {
-    pwupdate_close(data);
+    sync_close(data);
 }
 
 
@@ -86,10 +86,7 @@ chpass(krb5_context ctx, kadm5_hook_modinfo *data, int stage,
     /* Dispatch to the appropriate function. */
     length = strlen(password);
     if (stage == KADM5_HOOK_STAGE_PRECOMMIT)
-        code = pwupdate_precommit_password(data, ctx, princ, password, length);
-    else if (stage == KADM5_HOOK_STAGE_POSTCOMMIT)
-        code = pwupdate_postcommit_password(data, ctx, princ, password,
-                                            length);
+        code = sync_chpass(data, ctx, princ, password, length);
     return code;
 }
 
@@ -125,8 +122,7 @@ modify(krb5_context ctx, kadm5_hook_modinfo *data, int stage,
 
     if (mask & KADM5_ATTRIBUTES && stage == KADM5_HOOK_STAGE_POSTCOMMIT) {
         enabled = !(entry->attributes & KRB5_KDB_DISALLOW_ALL_TIX);
-        return pwupdate_postcommit_status(data, ctx, entry->principal,
-                                          enabled);
+        return sync_status(data, ctx, entry->principal, enabled);
     }
     return 0;
 }
index 8cfdccf1bc599237b8f70c95d1798f45740b67c3..84f9329f58754386a4eaab9cd4728a4150b4fdca 100644 (file)
@@ -159,9 +159,9 @@ queue_timestamp(void)
  * On failure, return -1 (still true but distinguished).
  */
 int
-pwupdate_queue_conflict(kadm5_hook_modinfo *config, krb5_context ctx,
-                        krb5_principal principal, const char *domain,
-                        const char *operation)
+sync_queue_conflict(kadm5_hook_modinfo *config, krb5_context ctx,
+                    krb5_principal principal, const char *domain,
+                    const char *operation)
 {
     int lock = -1;
     char *prefix = NULL;
@@ -207,9 +207,9 @@ fail:
  * enable and disable).  Returns a Kerberos error code.
  */
 krb5_error_code
-pwupdate_queue_write(kadm5_hook_modinfo *config, krb5_context ctx,
-                     krb5_principal principal, const char *domain,
-                     const char *operation, const char *password)
+sync_queue_write(kadm5_hook_modinfo *config, krb5_context ctx,
+                 krb5_principal principal, const char *domain,
+                 const char *operation, const char *password)
 {
     char *prefix = NULL, *timestamp = NULL, *path = NULL, *user = NULL;
     char *p;
index 60f2461272232c521f03a5b47c156307d129d97e..19e603c4cfc30cf041a8b675164a8160ae2fb6c7 100644 (file)
@@ -60,13 +60,12 @@ main(void)
     plan(24);
 
     /* Test init. */
-    is_int(0, pwupdate_init(ctx, &config), "pwupdate_init succeeds");
+    is_int(0, sync_init(ctx, &config), "sync_init succeeds");
     ok(config != NULL, "...and config is non-NULL");
 
     /* Create a password change and be sure it's queued. */
-    code = pwupdate_precommit_password(config, ctx, princ, "foobar",
-                                       strlen("foobar"));
-    is_int(0, code, "pwupdate_precommit_password succeeds");
+    code = sync_chpass(config, ctx, princ, "foobar", strlen("foobar"));
+    is_int(0, code, "sync_chpass succeeds");
     queue = NULL;
     now = time(NULL);
     for (try = now - 1; try <= now; try++) {
@@ -108,8 +107,8 @@ main(void)
     free(queue);
 
     /* Test queuing of enable. */
-    code = pwupdate_postcommit_status(config, ctx, princ, 1);
-    is_int(0, code, "pwupdate_postcommit_status enable succeeds");
+    code = sync_status(config, ctx, princ, 1);
+    is_int(0, code, "sync_status enable succeeds");
     queue = NULL;
     now = time(NULL);
     for (try = now - 1; try <= now; try++) {
@@ -143,8 +142,8 @@ main(void)
     ok(unlink(queue) == 0, "Remove queued enable");
 
     /* Test queuing of disable. */
-    code = pwupdate_postcommit_status(config, ctx, princ, 0);
-    is_int(0, code, "pwupdate_postcommit_status disable succeeds");
+    code = sync_status(config, ctx, princ, 0);
+    is_int(0, code, "sync_status disable succeeds");
     queue = NULL;
     now = time(NULL);
     for (try = now - 1; try <= now; try++) {
@@ -183,7 +182,7 @@ main(void)
     ok(rmdir("queue") == 0, "No other files in queue directory");
 
     /* Shut down the plugin. */
-    pwupdate_close(config);
+    sync_close(config);
 
     /* Clean up. */
     krb5_free_principal(ctx, princ);
index be6cd83d141a5647129c563f464a3f157898265a..5f7259df51fc269bfbfb2a036ad94bede15406b0 100644 (file)
@@ -62,10 +62,10 @@ main(void)
     if (code != 0)
         bail("cannot parse principal: %s", krb5_get_error_message(ctx, code));
 
-    plan(36);
+    plan(35);
 
     /* Test init. */
-    is_int(0, pwupdate_init(ctx, &data), "pwupdate_init succeeds");
+    is_int(0, sync_init(ctx, &data), "pwupdate_init succeeds");
     ok(data != NULL, "...and data is non-NULL");
 
     /* Block processing for our test user and then test password change. */
@@ -74,8 +74,7 @@ main(void)
     if (fd < 0)
         sysbail("cannot create fake queue file");
     close(fd);
-    code = pwupdate_precommit_password(data, ctx, princ, "foobar",
-                                       strlen("foobar"));
+    code = sync_chpass(data, ctx, princ, "foobar", strlen("foobar"));
     is_int(0, code, "pwupdate_precommit_password succeeds");
     ok(access("queue/.lock", F_OK) == 0, "...lock file now exists");
     queue = NULL;
@@ -116,11 +115,6 @@ main(void)
         fclose(file);
     }
 
-    /* pwupdate_postcommit_password should do nothing, silently. */
-    code = pwupdate_postcommit_password(data, ctx, princ, "foobar",
-                                        strlen("foobar"));
-    is_int(0, code, "pwupdate_postcommit_password succeeds");
-
     /* Clean up password change queue files. */
     ok(unlink("queue/test-ad-password-19700101T000000Z") == 0,
        "Sentinel file still exists");
@@ -133,8 +127,8 @@ main(void)
     if (fd < 0)
         sysbail("cannot create fake queue file");
     close(fd);
-    code = pwupdate_postcommit_status(data, ctx, princ, 1);
-    is_int(0, code, "pwupdate_postcommit_status enable succeeds");
+    code = sync_status(data, ctx, princ, 1);
+    is_int(0, code, "sync_status enable succeeds");
     queue = NULL;
     now = time(NULL);
     for (try = now - 1; try <= now; try++) {
@@ -172,8 +166,8 @@ main(void)
      * Do the same thing for disables, which should still be blocked by the
      * same marker.
      */
-    code = pwupdate_postcommit_status(data, ctx, princ, 0);
-    is_int(0, code, "pwupdate_postcommit_status disable succeeds");
+    code = sync_status(data, ctx, princ, 0);
+    is_int(0, code, "sync_status disable succeeds");
     queue = NULL;
     now = time(NULL);
     for (try = now - 1; try <= now; try++) {
@@ -214,24 +208,21 @@ main(void)
     ok(rmdir("queue") == 0, "No other files in queue directory");
 
     /* Check failure when there's no queue directory. */
-    code = pwupdate_precommit_password(data, ctx, princ, "foobar",
-                                       strlen("foobar"));
-    is_int(ENOENT, code,
-           "pwupdate_precommit_password fails with no queue");
+    code = sync_chpass(data, ctx, princ, "foobar", strlen("foobar"));
+    is_int(ENOENT, code, "sync_chpass fails with no queue");
     message = krb5_get_error_message(ctx, code);
     is_int(strncmp("cannot lock queue", message, strlen("cannot lock queue")),
            0, "...with correct error message");
     krb5_free_error_message(ctx, message);
-    code = pwupdate_postcommit_status(data, ctx, princ, 0);
-    is_int(ENOENT, code,
-           "pwupdate_postcommit_status disable fails with no queue");
+    code = sync_status(data, ctx, princ, 0);
+    is_int(ENOENT, code, "sync_status disable fails with no queue");
     message = krb5_get_error_message(ctx, code);
     is_int(strncmp("cannot lock queue", message, strlen("cannot lock queue")),
            0, "...with correct error message");
     krb5_free_error_message(ctx, message);
 
     /* Shut down the plugin. */
-    pwupdate_close(data);
+    sync_close(data);
 
     /*
      * Change to an empty Kerberos configuration file, and then make sure the
@@ -254,13 +245,12 @@ main(void)
     code = krb5_parse_name(ctx, "test@EXAMPLE.COM", &princ);
     if (code != 0)
         bail("cannot parse principal: %s", krb5_get_error_message(ctx, code));
-    is_int(0, pwupdate_init(ctx, &data), "pwupdate_init succeeds");
+    is_int(0, sync_init(ctx, &data), "sync_init succeeds");
     ok(data != NULL, "...and data is non-NULL");
-    code = pwupdate_precommit_password(data, ctx, princ, "foobar",
-                                       strlen("foobar"));
-    is_int(0, code, "pwupdate_precommit_password succeeds");
-    code = pwupdate_postcommit_status(data, ctx, princ, 0);
-    is_int(0, code, "pwupdate_postcommit_status disable succeeds");
+    code = sync_chpass(data, ctx, princ, "foobar", strlen("foobar"));
+    is_int(0, code, "sync_chpass succeeds");
+    code = sync_status(data, ctx, princ, 0);
+    is_int(0, code, "sync_status disable succeeds");
 
     /* Clean up. */
     krb5_free_principal(ctx, princ);
index ad5901b483bec0a23584b8109960c7b086605c34..f2842487e2e6ff5ec4182e570c9db69f9c8817af 100644 (file)
@@ -38,8 +38,7 @@ ad_password(kadm5_hook_modinfo *config, krb5_context ctx,
 {
     krb5_error_code code;
 
-    code = pwupdate_ad_change(config, ctx, principal, password,
-                              strlen(password));
+    code = sync_ad_chpass(config, ctx, principal, password, strlen(password));
     if (code != 0)
         die_krb5(ctx, code, "AD password change for %s failed", user);
     notice("AD password change for %s succeeded", user);
@@ -56,7 +55,7 @@ ad_status(kadm5_hook_modinfo *config, krb5_context ctx,
 {
     krb5_error_code code;
 
-    code = pwupdate_ad_status(config, ctx, principal, enable);
+    code = sync_ad_status(config, ctx, principal, enable);
     if (code != 0)
         die_krb5(ctx, code, "AD status change for %s failed", user);
     notice("AD status change for %s succeeded", user);
@@ -208,7 +207,7 @@ main(int argc, char *argv[])
         die_krb5(ctx, code, "cannot initialize Kerberos context");
 
     /* Initialize the plugin. */
-    code = pwupdate_init(ctx, &config);
+    code = sync_init(ctx, &config);
     if (code != 0)
         die_krb5(ctx, code, "plugin initialization failed");