Author: rmeggins
Update of /cvs/dirsec/ldapserver/ldap/servers/slapd
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv4163/ldapserver/ldap/servers/slapd
Modified Files:
charray.c control.c slapi-plugin.h
Log Message:
Resolves: bug 457846
Bug Description: The Windows Sync API should have plug-in points
Reviewed by: nkinder (Thanks!)
Fix Description: Several plug-in points have been added to the windows sync code,
available to regular plug-ins that register with the winsync api via the slapi api broker
interface. winsync-plugin.h documents the use of these along with some example plug-in
code. The windows private data structure has been extended to add two additional fields:
raw_entry - the raw entry read from AD - this is passed to several plug-in callbacks to
allow them to have access to all of the attributes and values in the entry in case further
processing is needed. This required a change to the function that reads the entry, to
have it save the raw entry read each time from AD, in addition to the "cooked"
entry it passes back to the caller.
api_cookie - this is the plug-in private data passed back to each plug-in callback and
allows the plug-in to specify some additional context
Both of these are stored in the private data field in the agreement, so some of the
existing functions had to be changed to pass in the connection object or the protocol
object in order to gain access to the agreement object.
There were several small memory leaks in the existing code that have been fixed - these
are the places where a free() function of some sort has been added. Also the usage of
slapi_sdn_init_dn_byval leaked - slapi_sdn_new_dn_byval must be used here instead - cannot
mix slapi_sdn_new with slapi_sdn_init*
I also cleaned up several compiler warnings.
The slapi changes are not strictly necessary, but they provide some conveniences to the
winsync code and to plug-in writers. The good thing is that they were already private
functions, so mostly just needed to have public api wrappers.
Platforms tested: RHEL5
Flag Day: no
Doc impact: no
Index: charray.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/charray.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- charray.c 27 Jun 2008 19:28:21 -0000 1.7
+++ charray.c 5 Aug 2008 20:26:22 -0000 1.8
@@ -246,6 +246,11 @@
charray_free (array);
}
+void
+slapi_ch_array_add( char ***a, char *s )
+{
+ charray_add(a, s);
+}
/* case insensitive search */
int
Index: control.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/control.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- control.c 10 Nov 2006 23:45:40 -0000 1.7
+++ control.c 5 Aug 2008 20:26:22 -0000 1.8
@@ -474,9 +474,14 @@
/*
* duplicate "newctrl" and add it to the array of controls "*ctrlsp"
* note that *ctrlsp may be reset and that it is okay to pass NULL for it.
+ * IF copy is true, a copy of the passed in control will be added - copy
+ * made with slapi_dup_control - if copy is false, the control
+ * will be used directly and may be free'd by ldap_controls_free - so
+ * make sure it is ok for the control array to own the pointer you
+ * pass in
*/
void
-add_control( LDAPControl ***ctrlsp, LDAPControl *newctrl )
+add_control_ext( LDAPControl ***ctrlsp, LDAPControl *newctrl, int copy )
{
int count;
@@ -491,10 +496,29 @@
*ctrlsp = (LDAPControl **)slapi_ch_realloc( (char *)*ctrlsp,
( count + 2 ) * sizeof(LDAPControl *));
- (*ctrlsp)[ count ] = slapi_dup_control( newctrl );
+ if (copy) {
+ (*ctrlsp)[ count ] = slapi_dup_control( newctrl );
+ } else {
+ (*ctrlsp)[ count ] = newctrl;
+ }
(*ctrlsp)[ ++count ] = NULL;
}
+/*
+ * duplicate "newctrl" and add it to the array of controls "*ctrlsp"
+ * note that *ctrlsp may be reset and that it is okay to pass NULL for it.
+ */
+void
+add_control( LDAPControl ***ctrlsp, LDAPControl *newctrl )
+{
+ add_control_ext(ctrlsp, newctrl, 1 /* copy */);
+}
+
+void
+slapi_add_control_ext( LDAPControl ***ctrlsp, LDAPControl *newctrl, int copy )
+{
+ add_control_ext(ctrlsp, newctrl, copy);
+}
/*
* return a malloc'd copy of "ctrl"
@@ -527,6 +551,14 @@
return( rctrl );
}
+void
+slapi_add_controls( LDAPControl ***ctrlsp, LDAPControl **newctrls, int copy )
+{
+ int ii;
+ for (ii = 0; newctrls && newctrls[ii]; ++ii) {
+ slapi_add_control_ext(ctrlsp, newctrls[ii], copy);
+ }
+}
int
slapi_build_control( char *oid, BerElement *ber,
Index: slapi-plugin.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/slapi-plugin.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- slapi-plugin.h 15 Jul 2008 16:49:42 -0000 1.26
+++ slapi-plugin.h 5 Aug 2008 20:26:22 -0000 1.27
@@ -835,6 +835,24 @@
int slapi_build_control_from_berval( char *oid, struct berval *bvp,
char iscritical, LDAPControl **ctrlp );
+/* Given an array of controls e.g. LDAPControl **ctrls, add the given
+ control to the end of the array, growing the array with realloc
+ e.g. slapi_add_control_ext(&ctrls, newctrl, 1);
+ if ctrls is NULL, the array will be created with malloc
+ if copy is true, the given control will be copied
+ if copy is false, the given control will be used and owned by the array
+ if copy is false, make sure the control can be freed by ldap_controls_free
+*/
+void slapi_add_control_ext( LDAPControl ***ctrlsp, LDAPControl *newctrl, int copy );
+
+/* Given an array of controls e.g. LDAPControl **ctrls, add all of the given
+ controls in the newctrls array to the end of ctrls, growing the array with realloc
+ if ctrls is NULL, the array will be created with malloc
+ if copy is true, each given control will be copied
+ if copy is false, each given control will be used and owned by the array
+ if copy is false, make sure each control can be freed by ldap_controls_free
+*/
+void slapi_add_controls( LDAPControl ***ctrlsp, LDAPControl **newctrls, int copy );
/*
* routines for dealing with extended operations
@@ -865,6 +883,13 @@
* routine for freeing the ch_arrays returned by the slapi_get*_copy functions above
*/
void slapi_ch_array_free( char **array );
+/*
+ * Add the given string to the given null terminated array.
+ * s is not copied, so if you want to add a copy of s to the
+ * array, use slapi_ch_strdup(s)
+ * if *a is NULL, a new array will be created
+ */
+void slapi_ch_array_add( char ***array, char *string );
/*