summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin@dahyabhai.net>2008-05-13 22:36:28 -0400
committerNalin Dahyabhai <nalin@dahyabhai.net>2008-05-13 22:36:28 -0400
commit2d7f8b5fd3e843a44bac311f2c6fe802ef48333b (patch)
tree61b3a18bd84ea75c94549065e01a6bbb00ce9548 /src
parent6e7e1d4736f9daa94a4fd2fe195aa835dd05aeeb (diff)
downloadslapi-nis-2d7f8b5fd3e843a44bac311f2c6fe802ef48333b.tar.gz
slapi-nis-2d7f8b5fd3e843a44bac311f2c6fe802ef48333b.tar.xz
slapi-nis-2d7f8b5fd3e843a44bac311f2c6fe802ef48333b.zip
- add a "deref" function:
%deref("uniqueMember", "uidNumber")
Diffstat (limited to 'src')
-rw-r--r--src/format.c89
1 files changed, 88 insertions, 1 deletions
diff --git a/src/format.c b/src/format.c
index d1bbd83..842048b 100644
--- a/src/format.c
+++ b/src/format.c
@@ -106,7 +106,8 @@ format_echo(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
return ret;
}
-/* Echo the parameter text. */
+/* Create a list of the values of the attributes which are passed as arguments,
+ * joined by a separator given as the first argument. */
static int
format_list(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
const char *args, char *outbuf, int outbuf_len,
@@ -153,6 +154,91 @@ format_list(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
return ret;
}
+/* Look up the entry matching a DN stored in the attribute named by the first
+ * argument, pull out the values for the attribute named by the second
+ * argument, and create a list separated by either "," or the third argument,
+ * if a third argument is given. */
+static int
+format_deref(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
+ const char *args, char *outbuf, int outbuf_len,
+ char ***visited_ndns)
+{
+ int i, j, len, ret, count, argc;
+ Slapi_Entry *ref;
+ Slapi_DN *refdn;
+ char **argv, **values, **refs, *attrs[3];
+ const char *sep;
+ ret = format_parse_args(state, args, &argc, &argv);
+ if (ret != 0) {
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "deref: error parsing arguments\n");
+ return -1;
+ }
+ if (argc < 2) {
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "deref: requires 2 arguments\n");
+ format_free_parsed_args(argv);
+ return -1;
+ }
+ refs = slapi_entry_attr_get_charray(e, argv[0]);
+ attrs[0] = argv[0];
+ attrs[1] = argv[1];
+ attrs[2] = NULL;
+ for (i = 0, count = 0; (refs != NULL) && (refs[i] != NULL); i++) {
+ refdn = slapi_sdn_new_dn_byval(refs[i]);
+ if (refdn == NULL) {
+ continue;
+ }
+ slapi_search_internal_get_entry(refdn, attrs, &ref,
+ state->plugin_identity);
+ if (ref == NULL) {
+ slapi_sdn_free(&refdn);
+ continue;
+ }
+ slapi_sdn_free(&refdn);
+ values = slapi_entry_attr_get_charray(ref, argv[1]);
+ for (j = 0;
+ (values != NULL) && (values[j] != NULL);
+ j++) {
+ if (count > 0) {
+ sep = (argc > 2) ? argv[2] : ",";
+ len = strlen(sep);
+ if (ret + len > outbuf_len) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "deref: out of space\n");
+ slapi_ch_array_free(values);
+ slapi_entry_free(ref);
+ slapi_ch_array_free(refs);
+ format_free_parsed_args(argv);
+ return -1;
+ }
+ memcpy(outbuf + ret, sep, len);
+ ret += len;
+ }
+ len = strlen(values[j]);
+ if (ret + len > outbuf_len) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "deref: out of space\n");
+ slapi_ch_array_free(values);
+ slapi_entry_free(ref);
+ slapi_ch_array_free(refs);
+ format_free_parsed_args(argv);
+ return -1;
+ }
+ memcpy(outbuf + ret, values[j], len);
+ ret += len;
+ count++;
+ }
+ slapi_ch_array_free(values);
+ slapi_entry_free(ref);
+ }
+ slapi_ch_array_free(refs);
+ format_free_parsed_args(argv);
+ return ret;
+}
+
/* Choose a formatting function by name. */
static void *
format_lookup_fn(const char *fnname)
@@ -168,6 +254,7 @@ format_lookup_fn(const char *fnname)
} fns[] = {
{"echo", format_echo},
{"list", format_list},
+ {"deref", format_deref},
};
for (i = 0; i < sizeof(fns) / sizeof(fns[0]); i++) {
if ((fns[i].name != NULL) &&