]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/extended.c
Happy New Year
[openldap] / libraries / libldap / extended.c
index af69bbf64aea82ef95e0f97578d7b5c7792496ce..200288905394e0e080d26703f82938c0bf900869 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2015 The OpenLDAP Foundation.
+ * Copyright 1998-2018 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include "ldap-int.h"
 #include "ldap_log.h"
 
+BerElement *
+ldap_build_extended_req(
+       LDAP                    *ld,
+       LDAP_CONST char *reqoid,
+       struct berval   *reqdata,
+       LDAPControl             **sctrls,
+       LDAPControl             **cctrls,
+       ber_int_t               *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 );
+       if ( reqdata != NULL ) {
+               rc = ber_printf( ber, "{it{tstON}", /* '}' */
+                       *msgidp, LDAP_REQ_EXTENDED,
+                       LDAP_TAG_EXOP_REQ_OID, reqoid,
+                       LDAP_TAG_EXOP_REQ_VALUE, reqdata );
+
+       } else {
+               rc = ber_printf( ber, "{it{tsN}", /* '}' */
+                       *msgidp, LDAP_REQ_EXTENDED,
+                       LDAP_TAG_EXOP_REQ_OID, reqoid );
+       }
+
+       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 );
+}
+
 /*
  * LDAPv3 Extended Operation Request
  *     ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
@@ -52,7 +103,6 @@ ldap_extended_operation(
        int                             *msgidp )
 {
        BerElement *ber;
-       int rc;
        ber_int_t id;
 
        Debug( LDAP_DEBUG_TRACE, "ldap_extended_operation\n", 0, 0, 0 );
@@ -68,42 +118,10 @@ ldap_extended_operation(
                return( ld->ld_errno );
        }
 
-       /* 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 );
-       if ( reqdata != NULL ) {
-               rc = ber_printf( ber, "{it{tstON}", /* '}' */
-                       id, LDAP_REQ_EXTENDED,
-                       LDAP_TAG_EXOP_REQ_OID, reqoid,
-                       LDAP_TAG_EXOP_REQ_VALUE, reqdata );
-
-       } else {
-               rc = ber_printf( ber, "{it{tsN}", /* '}' */
-                       id, LDAP_REQ_EXTENDED,
-                       LDAP_TAG_EXOP_REQ_OID, reqoid );
-       }
-
-       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 );
-               return ld->ld_errno;
-       }
-
-       if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
-               ld->ld_errno = LDAP_ENCODING_ERROR;
-               ber_free( ber, 1 );
+       ber = ldap_build_extended_req( ld, reqoid, reqdata,
+               sctrls, cctrls, &id );
+       if ( !ber )
                return( ld->ld_errno );
-       }
 
        /* send the message */
        *msgidp = ldap_send_initial_request( ld, LDAP_REQ_EXTENDED, NULL, ber, id );