]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/extended.c
Per ITS#419, don't require SLAPD_RLOOKUPS when HAVE_TCPD
[openldap] / servers / slapd / extended.c
index dd48d4bee2a0d5b78bc04e06ea675d4956d334de..a1c5c8a293a6cb64d6a04e97d287ac0b8485d506 100644 (file)
@@ -42,6 +42,23 @@ typedef struct extop_list_t {
 
 extop_list_t *supp_ext_list = NULL;
 
+/* this list of built-in extops is for extops that are not part
+ * of backends or in external modules.  essentially, this is
+ * just a way to get built-in extops onto the extop list without
+ * having a separate init routine for each built-in extop.
+ */
+struct {
+       char *oid;
+       SLAP_EXTOP_MAIN_FN ext_main;
+} builtin_extops[] = {
+#ifdef HAVE_TLS
+               { LDAP_EXOP_START_TLS, starttls_extop },
+#endif
+               { LDAP_EXOP_X_MODIFY_PASSWD, passwd_extop },
+               { NULL, NULL }
+       };
+
+
 static extop_list_t *find_extop( extop_list_t *list, char *oid );
 
 static int extop_callback(
@@ -69,17 +86,20 @@ do_extended(
 )
 {
        int rc = LDAP_SUCCESS;
-       char* oid;
+       char* reqoid;
        struct berval *reqdata;
        ber_tag_t tag;
        ber_len_t len;
        extop_list_t *ext;
        char *text;
+       struct berval **refs;
+       char *rspoid;
        struct berval *rspdata;
+       LDAPControl **rspctrls;
 
        Debug( LDAP_DEBUG_TRACE, "do_extended\n", 0, 0, 0 );
 
-       oid = NULL;
+       reqoid = NULL;
        reqdata = NULL;
 
        if( op->o_protocol < LDAP_VERSION3 ) {
@@ -91,7 +111,7 @@ do_extended(
                goto done;
        }
 
-       if ( ber_scanf( op->o_ber, "{a" /*}*/, &oid ) == LBER_ERROR ) {
+       if ( ber_scanf( op->o_ber, "{a" /*}*/, &reqoid ) == LBER_ERROR ) {
                Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 );
                send_ldap_disconnect( conn, op,
                        LDAP_PROTOCOL_ERROR, "decoding error" );
@@ -99,9 +119,9 @@ do_extended(
                goto done;
        }
 
-       if( !(ext = find_extop(supp_ext_list, oid)) ) {
+       if( !(ext = find_extop(supp_ext_list, reqoid)) ) {
                Debug( LDAP_DEBUG_ANY, "do_extended: unsupported operation \"%s\"\n",
-                       oid, 0 ,0 );
+                       reqoid, 0 ,0 );
                send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
                        NULL, "unsupported extended operation", NULL, NULL );
                goto done;
@@ -124,17 +144,29 @@ do_extended(
                return rc;
        } 
 
-       Debug( LDAP_DEBUG_ARGS, "do_extended: oid=%s\n", oid, 0 ,0 );
+       Debug( LDAP_DEBUG_ARGS, "do_extended: oid=%s\n", reqoid, 0 ,0 );
 
+       rspoid = NULL;
        rspdata = NULL;
+       rspctrls = NULL;
        text = NULL;
+       refs = NULL;
 
        rc = (ext->ext_main)( extop_callback, conn, op,
-               oid, reqdata, &rspdata, &text );
+               reqoid, reqdata,
+               &rspoid, &rspdata, &rspctrls, &text, &refs );
 
        if( rc != SLAPD_ABANDON ) {
-               send_ldap_extended( conn, op, rc, NULL, text,
-                       oid, rspdata );
+               if (rc == LDAP_REFERRAL) {
+                       refs = default_referral;
+               }
+
+               send_ldap_extended( conn, op, rc, NULL, text, refs,
+                       rspoid, rspdata, rspctrls );
+       }
+
+       if ( rspoid != NULL ) {
+               free( rspoid );
        }
 
        if ( rspdata != NULL )
@@ -147,8 +179,8 @@ done:
        if ( reqdata != NULL ) {
                ber_bvfree( reqdata );
        }
-       if ( oid != NULL ) {
-               free( oid );
+       if ( reqoid != NULL ) {
+               free( reqoid );
        }
 
        return rc;
@@ -182,6 +214,31 @@ load_extop(
        return(0);
 }
 
+int
+extops_init (void)
+{
+       int i;
+
+       for (i = 0; builtin_extops[i].oid != NULL; i++) {
+               load_extop(builtin_extops[i].oid, builtin_extops[i].ext_main);
+       }
+       return(0);
+}
+
+int
+extops_kill (void)
+{
+       extop_list_t *ext;
+
+       /* we allocated the memory, so we have to free it, too. */
+       while ((ext = supp_ext_list) != NULL) {
+               supp_ext_list = ext->next;
+               if (ext->oid != NULL)
+                       ch_free(ext->oid);
+               ch_free(ext);
+       }
+       return(0);
+}
 
 static extop_list_t *
 find_extop( extop_list_t *list, char *oid )