[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: Operational attribute plugins
Thanks to some generous help from Sun, I've ditched the
proprietary virtual attribute support that I hacked
together yesterday and replaced it with one compatible
with Sun ONE DS 5.x. Being able to target a single
plugin to both directory servers is a huge boon for us.
Here's a reimplementation of the plugin I sent yesterday,
which adds the "distinguishedName" attribute to each
entry:
int dnt_opattr_init(Slapi_PBlock *pb);
static Slapi_PluginDesc pluginDescription = {
"dnt-plugin",
"PADL",
"1.0",
"Sample Computed Attribute plugin"
};
/*
* Add the distinguishedName "operational" attribute to
* the entry.
*/
static int dnt_compute(computed_attr_context *c,
char *type,
Slapi_Entry *e,
slapi_compute_output_t outputfn)
{
Slapi_Entry *entry;
Slapi_Value *value;
Slapi_Attr *attr;
char *dn;
int rc = -1; /* no attribute found */
if (strcasecmp(type, "distinguishedName") == 0 ||
strcmp(type, "*") == 0 /* naughty */ ) {
rc = 1; /* error */
dn = slapi_entry_get_dn(entry);
attr = slapi_attr_new();
attr = slapi_attr_init(attr, "distinguishedName");
if (attr == NULL) {
goto done;
}
value = slapi_value_new_string(dn);
if (slapi_attr_add_value(attr, value) == 0) {
rc = (*outputfn)(c, attr, e);
}
slapi_attr_free(&attr);
slapi_value_free(&value);
}
done:
return rc;
}
int dnt_opattr_init(Slapi_PBlock *pb)
{
if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &pluginDescription) != 0 ||
slapi_compute_add_evaluator(dnt_compute) != 0) {
slapi_log_error(SLAPI_LOG_PLUGIN, "dnt_opattr_init",
"Error registering Sample Distinguished Name plugin\n");
return -1;
}
return 0;
}
-- Luke
--
Luke Howard | PADL Software Pty Ltd | www.padl.com