From 259ea8a006112b795635b913f0525e0745c297a2 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 11 Nov 2016 21:32:13 +0100 Subject: Get service_base_dn from the plugin arguments --- service_passwords.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/service_passwords.c b/service_passwords.c index 656a9c6..05ae41e 100644 --- a/service_passwords.c +++ b/service_passwords.c @@ -9,6 +9,8 @@ extern int slapi_pw_find(struct berval **vals, struct berval *v); static Slapi_ComponentId *plugin_id = NULL; +static char *service_base_dn = NULL; + /** Get an entry specified by a DN and with the specified attributes. * * This functions get a entry specified by a \c DN. It's doing this with an @@ -457,14 +459,11 @@ static char *get_virtual_service(const char *dn) static char *get_service_dn(const char *service) { char *new_dn = NULL; - char *base_dn = NULL; Slapi_RDN *rdn = NULL; - /* TODO: Get base_dn */ - rdn = slapi_rdn_new(); slapi_rdn_add(rdn, "cn", service); - new_dn = slapi_dn_plus_rdn(base_dn, slapi_rdn_get_rdn(rdn)); + new_dn = slapi_dn_plus_rdn(service_base_dn, slapi_rdn_get_rdn(rdn)); slapi_rdn_free(&rdn); return new_dn; @@ -791,6 +790,44 @@ static int pre_search(Slapi_PBlock *pb) return rc; } +/** Check the supplied argument list. + * + * The \c base_dn for service accounts is the only argument that is required. + * + * @param[in] pb Parameter block of the plugin initialization. + * @return + * * 0 if the argument could be found + * * not 0 on any error + */ +static int check_arguments(Slapi_PBlock *pb) +{ + int rc = 0; + + int argc = 0; + char **argv; + char *fn = "check_arguments"; + + rc |= slapi_pblock_get(pb, SLAPI_PLUGIN_ARGC, &argc); + rc |= slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv); + + if (rc != 0 || argc < 1) { + slapi_log_error( + SLAPI_LOG_PLUGIN, fn, + "Could not get parameters (error %d, arvc=%d).\n", + rc, argc); + + return rc; + } + + service_base_dn = slapi_ch_strdup(argv[0]); + slapi_log_error( + SLAPI_LOG_PLUGIN, fn, + "Using '%s' as base_dn for service accounts.\n", + service_base_dn); + + return rc; +} + Slapi_PluginDesc bindpdesc = { .spd_id = "service_passwords", .spd_vendor = "spline", @@ -803,11 +840,13 @@ int service_passwords_init(Slapi_PBlock *pb) { int rc = 0; + rc |= check_arguments(pb); rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_CURRENT_VERSION); rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *) &bindpdesc); rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_BIND_FN, (void *) pre_bind); rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ENTRY_FN, (void *) pre_entry); rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_SEARCH_FN, (void *) pre_search); rc |= slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_id); + return rc; } -- cgit v1.2.3-1-g7c22