}
-/*
- * ldap_add_ext - initiate an ldap extended add operation. Parameters:
- *
- * ld LDAP descriptor
- * dn DN of the entry to add
- * mods List of attributes for the entry. This is a null-
- * terminated array of pointers to LDAPMod structures.
- * only the type and values in the structures need be
- * filled in.
- * sctrl Server Controls
- * cctrl Client Controls
- * msgidp Message ID pointer
- *
- * Example:
- * LDAPMod *attrs[] = {
- * { 0, "cn", { "babs jensen", "babs", 0 } },
- * { 0, "sn", { "jensen", 0 } },
- * { 0, "objectClass", { "person", 0 } },
- * 0
- * }
- * rc = ldap_add_ext( ld, dn, attrs, NULL, NULL, &msgid );
- */
-int
-ldap_add_ext(
+BerElement *
+ldap_build_add_req(
LDAP *ld,
- LDAP_CONST char *dn,
+ const char *dn,
LDAPMod **attrs,
LDAPControl **sctrls,
LDAPControl **cctrls,
- int *msgidp )
+ ber_int_t *msgidp )
{
- BerElement *ber;
- int i, rc;
- ber_int_t id;
-
- Debug( LDAP_DEBUG_TRACE, "ldap_add_ext\n", 0, 0, 0 );
- assert( ld != NULL );
- assert( LDAP_VALID( ld ) );
- assert( dn != NULL );
- assert( msgidp != NULL );
-
- /* check client controls */
- rc = ldap_int_client_controls( ld, cctrls );
- if( rc != LDAP_SUCCESS ) return rc;
+ BerElement *ber;
+ int i, rc;
/* create a message to send */
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return ld->ld_errno;
+ return( NULL );
}
- LDAP_NEXT_MSGID(ld, id);
+ LDAP_NEXT_MSGID(ld, *msgidp);
rc = ber_printf( ber, "{it{s{", /* '}}}' */
- id, LDAP_REQ_ADD, dn );
+ *msgidp, LDAP_REQ_ADD, dn );
if ( rc == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
/* allow attrs to be NULL ("touch"; should fail...) */
if ( attrs[i]->mod_bvalues == NULL ) {
ld->ld_errno = LDAP_PARAM_ERROR;
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
for ( j = 0; attrs[i]->mod_bvalues[ j ] != NULL; j++ ) {
if ( attrs[i]->mod_bvalues[ j ]->bv_val == NULL ) {
ld->ld_errno = LDAP_PARAM_ERROR;
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
}
if ( attrs[i]->mod_values == NULL ) {
ld->ld_errno = LDAP_PARAM_ERROR;
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
rc = ber_printf( ber, "{s[v]N}", attrs[i]->mod_type,
if ( rc == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
}
}
if ( ber_printf( ber, /*{{*/ "N}N}" ) == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
/* Put Server Controls */
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
+ return( ber );
+}
+
+/*
+ * ldap_add_ext - initiate an ldap extended add operation. Parameters:
+ *
+ * ld LDAP descriptor
+ * dn DN of the entry to add
+ * mods List of attributes for the entry. This is a null-
+ * terminated array of pointers to LDAPMod structures.
+ * only the type and values in the structures need be
+ * filled in.
+ * sctrl Server Controls
+ * cctrl Client Controls
+ * msgidp Message ID pointer
+ *
+ * Example:
+ * LDAPMod *attrs[] = {
+ * { 0, "cn", { "babs jensen", "babs", 0 } },
+ * { 0, "sn", { "jensen", 0 } },
+ * { 0, "objectClass", { "person", 0 } },
+ * 0
+ * }
+ * rc = ldap_add_ext( ld, dn, attrs, NULL, NULL, &msgid );
+ */
+int
+ldap_add_ext(
+ LDAP *ld,
+ LDAP_CONST char *dn,
+ LDAPMod **attrs,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ int *msgidp )
+{
+ BerElement *ber;
+ int i, rc;
+ ber_int_t id;
+
+ Debug( LDAP_DEBUG_TRACE, "ldap_add_ext\n", 0, 0, 0 );
+ assert( ld != NULL );
+ assert( LDAP_VALID( ld ) );
+ assert( dn != NULL );
+ assert( msgidp != NULL );
+
+ /* check client controls */
+ rc = ldap_int_client_controls( ld, cctrls );
+ if( rc != LDAP_SUCCESS ) return rc;
+
+ ber = ldap_build_add_req( ld, dn, attrs, sctrls, cctrls, &id );
+ if( !ber )
+ return ld->ld_errno;
+
/* send the message */
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_ADD, dn, ber, id );
* }
*/
+BerElement *
+ldap_build_compare_req(
+ LDAP *ld,
+ LDAP_CONST char *dn,
+ LDAP_CONST char *attr,
+ struct berval *bvalue,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ int *msgidp )
+{
+ BerElement *ber;
+ int rc;
+
+ /* create a message to send */
+ if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
+ return( NULL );
+ }
+
+ LDAP_NEXT_MSGID(ld, *msgidp);
+ rc = ber_printf( ber, "{it{s{sON}N}", /* '}' */
+ *msgidp,
+ LDAP_REQ_COMPARE, dn, attr, bvalue );
+ if ( rc == -1 )
+ {
+ ld->ld_errno = LDAP_ENCODING_ERROR;
+ ber_free( ber, 1 );
+ return( NULL );
+ }
+
+ /* Put Server Controls */
+ if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
+ ber_free( ber, 1 );
+ return( NULL );
+ }
+
+ if( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
+ ld->ld_errno = LDAP_ENCODING_ERROR;
+ ber_free( ber, 1 );
+ return( NULL );
+ }
+}
+
/*
* ldap_compare_ext - perform an ldap extended compare operation. The dn
* of the entry to compare to and the attribute and value to compare (in
rc = ldap_int_client_controls( ld, cctrls );
if( rc != LDAP_SUCCESS ) return rc;
- /* create a message to send */
- if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
- return( LDAP_NO_MEMORY );
- }
-
- LDAP_NEXT_MSGID(ld, id);
- rc = ber_printf( ber, "{it{s{sON}N}", /* '}' */
- id,
- LDAP_REQ_COMPARE, dn, attr, bvalue );
- if ( rc == -1 )
- {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( ld->ld_errno );
- }
-
- /* Put Server Controls */
- if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
- ber_free( ber, 1 );
+ ber = ldap_build_compare_req(
+ ld, dn, attr, bvalue, sctrls, cctrls, &id );
+ if( !ber )
return ld->ld_errno;
- }
-
- if( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( ld->ld_errno );
- }
-
/* send the message */
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber, id );
* DelRequet ::= DistinguishedName,
*/
+BerElement *
+ldap_build_delete_req(
+ LDAP *ld,
+ LDAP_CONST char *dn,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ int *msgidp )
+{
+ BerElement *ber;
+ int rc;
+
+ /* create a message to send */
+ if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
+ return( NULL );
+ }
+
+ LDAP_NEXT_MSGID( ld, *msgidp );
+ rc = ber_printf( ber, "{its", /* '}' */
+ *msgidp, LDAP_REQ_DELETE, dn );
+ if ( rc == -1 )
+ {
+ ld->ld_errno = LDAP_ENCODING_ERROR;
+ ber_free( ber, 1 );
+ return( NULL );
+ }
+
+ /* Put Server Controls */
+ if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
+ ber_free( ber, 1 );
+ return( NULL );
+ }
+
+ if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
+ ld->ld_errno = LDAP_ENCODING_ERROR;
+ ber_free( ber, 1 );
+ return( NULL );
+ }
+
+ return( ber );
+}
/*
* ldap_delete_ext - initiate an ldap extended delete operation. Parameters:
rc = ldap_int_client_controls( ld, cctrls );
if( rc != LDAP_SUCCESS ) return rc;
- /* create a message to send */
- if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return( ld->ld_errno );
- }
-
- LDAP_NEXT_MSGID( ld, id );
- rc = ber_printf( ber, "{its", /* '}' */
- id, LDAP_REQ_DELETE, dn );
- if ( rc == -1 )
- {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( ld->ld_errno );
- }
-
- /* Put Server Controls */
- if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
- ber_free( ber, 1 );
+ ber = ldap_build_delete_req( ld, dn, sctrls, cctrls, &id );
+ if( !ber )
return ld->ld_errno;
- }
-
- if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( ld->ld_errno );
- }
/* send the message */
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_DELETE, dn, ber, id );
LDAP_F (int)
ldap_int_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx );
+/*
+ * in add.c
+ */
+
+LDAP_F (BerElement *) ldap_build_add_req LDAP_P((
+ LDAP *ld,
+ const char *dn,
+ LDAPMod **attrs,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ ber_int_t *msgidp ));
+
+/*
+ * in compare.c
+ */
+
+LDAP_F (BerElement *) ldap_build_compare_req LDAP_P((
+ LDAP *ld,
+ const char *dn,
+ const char *attr,
+ struct berval *bvalue,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ ber_int_t *msgidp ));
+
+/*
+ * in delete.c
+ */
+
+LDAP_F (BerElement *) ldap_build_delete_req LDAP_P((
+ LDAP *ld,
+ const char *dn,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ ber_int_t *msgidp ));
+
/*
* in init.c
*/
*/
LDAP_F (void) ldap_int_error_init( void );
+/*
+ * in modify.c
+ */
+
+LDAP_F (BerElement *) ldap_build_modify_req LDAP_P((
+ LDAP *ld,
+ const char *dn,
+ LDAPMod **mods,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ ber_int_t *msgidp ));
+
+/*
+ * in modrdn.c
+ */
+
+LDAP_F (BerElement *) ldap_build_moddn_req LDAP_P((
+ LDAP *ld,
+ const char *dn,
+ const char *newrdn,
+ const char *newSuperior,
+ int deleteoldrdn,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ ber_int_t *msgidp ));
+
/*
* in unit-int.c
*/
const char **rmech,
int *msgid ));
+/* in sasl.c */
+
+LDAP_F (BerElement *) ldap_build_bind_req LDAP_P((
+ LDAP *ld,
+ const char *dn,
+ const char *mech,
+ struct berval *cred,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ ber_int_t *msgidp ));
+
/* in schema.c */
LDAP_F (char *) ldap_int_parse_numericoid LDAP_P((
const char **sp,
* (Source: RFC 4511)
*/
-
-/*
- * ldap_modify_ext - initiate an ldap extended modify operation.
- *
- * Parameters:
- *
- * ld LDAP descriptor
- * dn DN of the object to modify
- * mods List of modifications to make. This is null-terminated
- * array of struct ldapmod's, specifying the modifications
- * to perform.
- * sctrls Server Controls
- * cctrls Client Controls
- * msgidp Message ID pointer
- *
- * Example:
- * LDAPMod *mods[] = {
- * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
- * { LDAP_MOD_REPLACE, "sn", { "babs jensen", "babs", 0 } },
- * { LDAP_MOD_DELETE, "ou", 0 },
- * { LDAP_MOD_INCREMENT, "uidNumber, { "1", 0 } }
- * 0
- * }
- * rc= ldap_modify_ext( ld, dn, mods, sctrls, cctrls, &msgid );
- */
-int
-ldap_modify_ext( LDAP *ld,
+BerElement *
+ldap_build_modify_req(
+ LDAP *ld,
LDAP_CONST char *dn,
LDAPMod **mods,
LDAPControl **sctrls,
LDAPControl **cctrls,
- int *msgidp )
+ ber_int_t *msgidp )
{
BerElement *ber;
int i, rc;
- ber_int_t id;
-
- Debug( LDAP_DEBUG_TRACE, "ldap_modify_ext\n", 0, 0, 0 );
-
- /* check client controls */
- rc = ldap_int_client_controls( ld, cctrls );
- if( rc != LDAP_SUCCESS ) return rc;
/* create a message to send */
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
- return( LDAP_NO_MEMORY );
+ return( NULL );
}
- LDAP_NEXT_MSGID( ld, id );
- rc = ber_printf( ber, "{it{s{" /*}}}*/, id, LDAP_REQ_MODIFY, dn );
+ LDAP_NEXT_MSGID( ld, *msgidp );
+ rc = ber_printf( ber, "{it{s{" /*}}}*/, *msgidp, LDAP_REQ_MODIFY, dn );
if ( rc == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return( ld->ld_errno );
+ return( NULL );
}
/* allow mods to be NULL ("touch") */
if ( rc == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return( ld->ld_errno );
+ return( NULL );
}
}
}
if ( ber_printf( ber, /*{{*/ "N}N}" ) == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return( ld->ld_errno );
+ return( NULL );
}
/* Put Server Controls */
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return( ld->ld_errno );
+ return( NULL );
}
+ return( ber );
+}
+
+/*
+ * ldap_modify_ext - initiate an ldap extended modify operation.
+ *
+ * Parameters:
+ *
+ * ld LDAP descriptor
+ * dn DN of the object to modify
+ * mods List of modifications to make. This is null-terminated
+ * array of struct ldapmod's, specifying the modifications
+ * to perform.
+ * sctrls Server Controls
+ * cctrls Client Controls
+ * msgidp Message ID pointer
+ *
+ * Example:
+ * LDAPMod *mods[] = {
+ * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
+ * { LDAP_MOD_REPLACE, "sn", { "babs jensen", "babs", 0 } },
+ * { LDAP_MOD_DELETE, "ou", 0 },
+ * { LDAP_MOD_INCREMENT, "uidNumber, { "1", 0 } }
+ * 0
+ * }
+ * rc= ldap_modify_ext( ld, dn, mods, sctrls, cctrls, &msgid );
+ */
+int
+ldap_modify_ext( LDAP *ld,
+ LDAP_CONST char *dn,
+ LDAPMod **mods,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ int *msgidp )
+{
+ BerElement *ber;
+ int i, rc;
+ ber_int_t id;
+
+ Debug( LDAP_DEBUG_TRACE, "ldap_modify_ext\n", 0, 0, 0 );
+
+ /* check client controls */
+ rc = ldap_int_client_controls( ld, cctrls );
+ if( rc != LDAP_SUCCESS ) return rc;
+
+ ber = ldap_build_modify_req( ld, dn, mods, sctrls, cctrls, &id );
+ if( !ber )
+ return ld->ld_errno;
+
/* send the message */
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber, id );
return( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
* to perform.
*
* Example:
- * LDAPMod *mods[] = {
+ * LDAPMod *mods[] = {
* { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
* { LDAP_MOD_REPLACE, "sn", { "babs jensen", "babs", 0 } },
* { LDAP_MOD_DELETE, "ou", 0 },
* }
*/
-
-/*
- * ldap_rename - initiate an ldap extended modifyDN operation.
- *
- * Parameters:
- * ld LDAP descriptor
- * dn DN of the object to modify
- * newrdn RDN to give the object
- * deleteoldrdn nonzero means to delete old rdn values from the entry
- * newSuperior DN of the new parent if applicable
- *
- * Returns the LDAP error code.
- */
-
-int
-ldap_rename(
+BerElement *
+ldap_build_moddn_req(
LDAP *ld,
LDAP_CONST char *dn,
LDAP_CONST char *newrdn,
int deleteoldrdn,
LDAPControl **sctrls,
LDAPControl **cctrls,
- int *msgidp )
+ ber_int_t *msgidp )
{
BerElement *ber;
int rc;
- ber_int_t id;
-
- Debug( LDAP_DEBUG_TRACE, "ldap_rename\n", 0, 0, 0 );
-
- /* check client controls */
- rc = ldap_int_client_controls( ld, cctrls );
- if( rc != LDAP_SUCCESS ) return rc;
/* create a message to send */
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
- return( LDAP_NO_MEMORY );
+ return( NULL );
}
- LDAP_NEXT_MSGID( ld, id );
+ LDAP_NEXT_MSGID( ld, *msgidp );
if( newSuperior != NULL ) {
/* must be version 3 (or greater) */
if ( ld->ld_version < LDAP_VERSION3 ) {
ld->ld_errno = LDAP_NOT_SUPPORTED;
ber_free( ber, 1 );
- return( ld->ld_errno );
+ return( NULL );
}
rc = ber_printf( ber, "{it{ssbtsN}", /* '}' */
- id, LDAP_REQ_MODDN,
+ *msgidp, LDAP_REQ_MODDN,
dn, newrdn, (ber_int_t) deleteoldrdn,
LDAP_TAG_NEWSUPERIOR, newSuperior );
} else {
rc = ber_printf( ber, "{it{ssbN}", /* '}' */
- id, LDAP_REQ_MODDN,
+ *msgidp, LDAP_REQ_MODDN,
dn, newrdn, (ber_int_t) deleteoldrdn );
}
if ( rc < 0 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return( ld->ld_errno );
+ return( NULL );
}
/* Put Server Controls */
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
rc = ber_printf( ber, /*{*/ "N}" );
if ( rc < 0 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return( ld->ld_errno );
+ return( NULL );
}
+ return( ber );
+}
+
+/*
+ * ldap_rename - initiate an ldap extended modifyDN operation.
+ *
+ * Parameters:
+ * ld LDAP descriptor
+ * dn DN of the object to modify
+ * newrdn RDN to give the object
+ * deleteoldrdn nonzero means to delete old rdn values from the entry
+ * newSuperior DN of the new parent if applicable
+ *
+ * Returns the LDAP error code.
+ */
+
+int
+ldap_rename(
+ LDAP *ld,
+ LDAP_CONST char *dn,
+ LDAP_CONST char *newrdn,
+ LDAP_CONST char *newSuperior,
+ int deleteoldrdn,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ int *msgidp )
+{
+ BerElement *ber;
+ int rc;
+ ber_int_t id;
+
+ Debug( LDAP_DEBUG_TRACE, "ldap_rename\n", 0, 0, 0 );
+
+ /* check client controls */
+ rc = ldap_int_client_controls( ld, cctrls );
+ if( rc != LDAP_SUCCESS ) return rc;
+
+ ber = ldap_build_moddn_req( ld, dn, newrdn, newSuperior,
+ deleteoldrdn, sctrls, cctrls, &id );
+ if( !ber )
+ return ld->ld_errno;
+
/* send the message */
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber, id );
#include "ldap-int.h"
-/*
- * ldap_sasl_bind - bind to the ldap server (and X.500).
- * The dn (usually NULL), mechanism, and credentials are provided.
- * The message id of the request initiated is provided upon successful
- * (LDAP_SUCCESS) return.
- *
- * Example:
- * ldap_sasl_bind( ld, NULL, "mechanism",
- * cred, NULL, NULL, &msgid )
- */
-
-int
-ldap_sasl_bind(
+BerElement *
+ldap_build_bind_req(
LDAP *ld,
LDAP_CONST char *dn,
LDAP_CONST char *mechanism,
struct berval *cred,
LDAPControl **sctrls,
LDAPControl **cctrls,
- int *msgidp )
+ ber_int_t *msgidp )
{
BerElement *ber;
int rc;
- ber_int_t id;
-
- Debug( LDAP_DEBUG_TRACE, "ldap_sasl_bind\n", 0, 0, 0 );
-
- assert( ld != NULL );
- assert( LDAP_VALID( ld ) );
- assert( msgidp != NULL );
-
- /* check client controls */
- rc = ldap_int_client_controls( ld, cctrls );
- if( rc != LDAP_SUCCESS ) return rc;
if( mechanism == LDAP_SASL_SIMPLE ) {
if( dn == NULL && cred != NULL && cred->bv_len ) {
} else if( ld->ld_version < LDAP_VERSION3 ) {
ld->ld_errno = LDAP_NOT_SUPPORTED;
- return ld->ld_errno;
+ return( NULL );
}
if ( dn == NULL ) {
/* create a message to send */
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return ld->ld_errno;
+ return( NULL );
}
- assert( LBER_VALID( ber ) );
-
- LDAP_NEXT_MSGID( ld, id );
+ LDAP_NEXT_MSGID( ld, *msgidp );
if( mechanism == LDAP_SASL_SIMPLE ) {
/* simple bind */
rc = ber_printf( ber, "{it{istON}" /*}*/,
- id, LDAP_REQ_BIND,
+ *msgidp, LDAP_REQ_BIND,
ld->ld_version, dn, LDAP_AUTH_SIMPLE,
cred );
} else if ( cred == NULL || cred->bv_val == NULL ) {
/* SASL bind w/o credentials */
rc = ber_printf( ber, "{it{ist{sN}N}" /*}*/,
- id, LDAP_REQ_BIND,
+ *msgidp, LDAP_REQ_BIND,
ld->ld_version, dn, LDAP_AUTH_SASL,
mechanism );
} else {
/* SASL bind w/ credentials */
rc = ber_printf( ber, "{it{ist{sON}N}" /*}*/,
- id, LDAP_REQ_BIND,
+ *msgidp, LDAP_REQ_BIND,
ld->ld_version, dn, LDAP_AUTH_SASL,
mechanism, cred );
}
if( rc == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return( -1 );
+ return( NULL );
}
/* Put Server Controls */
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return ld->ld_errno;
+ return( NULL );
}
+ return( ber );
+}
+
+/*
+ * ldap_sasl_bind - bind to the ldap server (and X.500).
+ * The dn (usually NULL), mechanism, and credentials are provided.
+ * The message id of the request initiated is provided upon successful
+ * (LDAP_SUCCESS) return.
+ *
+ * Example:
+ * ldap_sasl_bind( ld, NULL, "mechanism",
+ * cred, NULL, NULL, &msgid )
+ */
+
+int
+ldap_sasl_bind(
+ LDAP *ld,
+ LDAP_CONST char *dn,
+ LDAP_CONST char *mechanism,
+ struct berval *cred,
+ LDAPControl **sctrls,
+ LDAPControl **cctrls,
+ int *msgidp )
+{
+ BerElement *ber;
+ int rc;
+ ber_int_t id;
+
+ Debug( LDAP_DEBUG_TRACE, "ldap_sasl_bind\n", 0, 0, 0 );
+
+ assert( ld != NULL );
+ assert( LDAP_VALID( ld ) );
+ assert( msgidp != NULL );
+
+ /* check client controls */
+ rc = ldap_int_client_controls( ld, cctrls );
+ if( rc != LDAP_SUCCESS ) return rc;
+
+ ber = ldap_build_bind_req( ld, dn, mechanism, cred, sctrls, cctrls, &id );
+ if( !ber )
+ return ld->ld_errno;
/* send the message */
*msgidp = ldap_send_initial_request( ld, LDAP_REQ_BIND, dn, ber, id );