diff options
author | Andrew Bartlett <abartlet@samba.org> | 2009-10-21 15:20:26 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2009-10-21 22:43:56 +1100 |
commit | bd53628c7a7d430878588666372dc73f1a88b7de (patch) | |
tree | be122150ebd4b648905e71de06e3f8307f05194c /source4/lib/ldb/common/ldb_controls.c | |
parent | fcbe6163f65ae9e4fce9228434c447ad34943010 (diff) | |
download | samba-bd53628c7a7d430878588666372dc73f1a88b7de.tar.gz samba-bd53628c7a7d430878588666372dc73f1a88b7de.tar.bz2 samba-bd53628c7a7d430878588666372dc73f1a88b7de.zip |
s4:ldb Add new function to create a cut down list of controls
This I hope will be useful for removing controls from the ldb_reply
Andrew Bartlett
Diffstat (limited to 'source4/lib/ldb/common/ldb_controls.c')
-rw-r--r-- | source4/lib/ldb/common/ldb_controls.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/source4/lib/ldb/common/ldb_controls.c b/source4/lib/ldb/common/ldb_controls.c index 0ecb1eb62c..5276ac091d 100644 --- a/source4/lib/ldb/common/ldb_controls.c +++ b/source4/lib/ldb/common/ldb_controls.c @@ -102,6 +102,47 @@ int save_controls(struct ldb_control *exclude, struct ldb_request *req, struct l return 1; } +/* Returns a list of controls, except the one specified. Included + * controls become a child of returned list if they were children of + * controls_in */ +struct ldb_control **controls_except_specified(struct ldb_control **controls_in, + TALLOC_CTX *mem_ctx, + struct ldb_control *exclude) +{ + struct ldb_control **lcs = NULL; + int i, j; + + for (i = 0; controls_in && controls_in[i]; i++); + + if (i == 0) { + return NULL; + } + + for (i = 0, j = 0; controls_in && controls_in[i]; i++) { + if (exclude == controls_in[i]) continue; + + if (!lcs) { + /* Allocate here so if we remove the only + * control, or there were no controls, we + * don't allocate at all, and just return + * NULL */ + lcs = talloc_array(mem_ctx, struct ldb_control *, i); + if (!lcs) { + return NULL; + } + } + + lcs[j] = controls_in[i]; + talloc_reparent(controls_in, lcs, lcs[j]); + j++; + } + if (lcs) { + lcs[j] = NULL; + } + + return lcs; +} + /* check if there's any control marked as critical in the list */ /* return True if any, False if none */ int check_critical_controls(struct ldb_control **controls) |