2007-09-07 20:02:43 +08:00
|
|
|
/* config.c - sock backend configuration file routine */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2012-01-01 23:07:45 +08:00
|
|
|
* Copyright 2007-2012 The OpenLDAP Foundation.
|
2007-09-07 20:02:43 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
2007-09-07 20:20:24 +08:00
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Brian Candler for inclusion
|
2007-12-24 13:18:25 +08:00
|
|
|
* in OpenLDAP Software. Dynamic config support by Howard Chu.
|
2007-09-07 20:20:24 +08:00
|
|
|
*/
|
2007-09-07 20:02:43 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
2007-12-24 13:18:25 +08:00
|
|
|
#include "config.h"
|
2007-09-07 20:02:43 +08:00
|
|
|
#include "back-sock.h"
|
|
|
|
|
2007-12-24 13:18:25 +08:00
|
|
|
static ConfigDriver bs_cf_gen;
|
2011-02-04 04:17:23 +08:00
|
|
|
static int sock_over_setup();
|
2011-02-04 05:24:26 +08:00
|
|
|
static slap_response sock_over_response;
|
2007-09-07 20:02:43 +08:00
|
|
|
|
2007-12-24 13:18:25 +08:00
|
|
|
enum {
|
2011-02-04 18:52:34 +08:00
|
|
|
BS_EXT = 1,
|
|
|
|
BS_OPS,
|
|
|
|
BS_RESP
|
2007-12-24 13:18:25 +08:00
|
|
|
};
|
2007-09-07 20:02:43 +08:00
|
|
|
|
2011-02-04 18:52:34 +08:00
|
|
|
/* The number of overlay-only config attrs */
|
|
|
|
#define NUM_OV_ATTRS 2
|
|
|
|
|
2007-12-24 13:18:25 +08:00
|
|
|
static ConfigTable bscfg[] = {
|
2011-02-04 18:52:34 +08:00
|
|
|
{ "sockops", "ops", 2, 0, 0, ARG_MAGIC|BS_OPS,
|
|
|
|
bs_cf_gen, "( OLcfgDbAt:7.3 NAME 'olcOvSocketOps' "
|
|
|
|
"DESC 'Operation types to forward' "
|
|
|
|
"EQUALITY caseIgnoreMatch "
|
|
|
|
"SYNTAX OMsDirectoryString )", NULL, NULL },
|
|
|
|
{ "sockresps", "resps", 2, 0, 0, ARG_MAGIC|BS_RESP,
|
|
|
|
bs_cf_gen, "( OLcfgDbAt:7.4 NAME 'olcOvSocketResps' "
|
|
|
|
"DESC 'Response types to forward' "
|
|
|
|
"EQUALITY caseIgnoreMatch "
|
|
|
|
"SYNTAX OMsDirectoryString )", NULL, NULL },
|
|
|
|
|
2007-12-24 13:18:25 +08:00
|
|
|
{ "socketpath", "pathname", 2, 2, 0, ARG_STRING|ARG_OFFSET,
|
|
|
|
(void *)offsetof(struct sockinfo, si_sockpath),
|
|
|
|
"( OLcfgDbAt:7.1 NAME 'olcDbSocketPath' "
|
|
|
|
"DESC 'Pathname for Unix domain socket' "
|
|
|
|
"EQUALITY caseExactMatch "
|
|
|
|
"SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
|
|
|
|
{ "extensions", "ext", 2, 0, 0, ARG_MAGIC|BS_EXT,
|
|
|
|
bs_cf_gen, "( OLcfgDbAt:7.2 NAME 'olcDbSocketExtensions' "
|
|
|
|
"DESC 'binddn, peername, or ssf' "
|
|
|
|
"EQUALITY caseIgnoreMatch "
|
|
|
|
"SYNTAX OMsDirectoryString )", NULL, NULL },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static ConfigOCs bsocs[] = {
|
|
|
|
{ "( OLcfgDbOc:7.1 "
|
|
|
|
"NAME 'olcDbSocketConfig' "
|
|
|
|
"DESC 'Socket backend configuration' "
|
|
|
|
"SUP olcDatabaseConfig "
|
|
|
|
"MUST olcDbSocketPath "
|
|
|
|
"MAY olcDbSocketExtensions )",
|
2011-02-04 18:52:34 +08:00
|
|
|
Cft_Database, bscfg+NUM_OV_ATTRS },
|
2007-12-24 13:18:25 +08:00
|
|
|
{ NULL, 0, NULL }
|
|
|
|
};
|
|
|
|
|
2011-02-04 04:17:23 +08:00
|
|
|
static ConfigOCs osocs[] = {
|
2011-02-04 05:54:11 +08:00
|
|
|
{ "( OLcfgDbOc:7.2 "
|
2011-02-04 04:17:23 +08:00
|
|
|
"NAME 'olcOvSocketConfig' "
|
|
|
|
"DESC 'Socket overlay configuration' "
|
|
|
|
"SUP olcOverlayConfig "
|
|
|
|
"MUST olcDbSocketPath "
|
2011-02-04 18:52:34 +08:00
|
|
|
"MAY ( olcDbSocketExtensions $ "
|
|
|
|
" olcOvSocketOps $ olcOvSocketResps ) )",
|
2011-02-04 04:17:23 +08:00
|
|
|
Cft_Overlay, bscfg },
|
|
|
|
{ NULL, 0, NULL }
|
|
|
|
};
|
|
|
|
|
2011-02-04 18:52:34 +08:00
|
|
|
#define SOCK_OP_BIND 0x001
|
|
|
|
#define SOCK_OP_UNBIND 0x002
|
|
|
|
#define SOCK_OP_SEARCH 0x004
|
|
|
|
#define SOCK_OP_COMPARE 0x008
|
|
|
|
#define SOCK_OP_MODIFY 0x010
|
|
|
|
#define SOCK_OP_MODRDN 0x020
|
|
|
|
#define SOCK_OP_ADD 0x040
|
|
|
|
#define SOCK_OP_DELETE 0x080
|
|
|
|
|
|
|
|
#define SOCK_REP_RESULT 0x001
|
|
|
|
#define SOCK_REP_SEARCH 0x002
|
|
|
|
|
2007-12-24 13:18:25 +08:00
|
|
|
static slap_verbmasks bs_exts[] = {
|
|
|
|
{ BER_BVC("binddn"), SOCK_EXT_BINDDN },
|
|
|
|
{ BER_BVC("peername"), SOCK_EXT_PEERNAME },
|
|
|
|
{ BER_BVC("ssf"), SOCK_EXT_SSF },
|
2011-02-04 04:47:38 +08:00
|
|
|
{ BER_BVC("connid"), SOCK_EXT_CONNID },
|
2007-12-24 13:18:25 +08:00
|
|
|
{ BER_BVNULL, 0 }
|
|
|
|
};
|
|
|
|
|
2011-02-04 18:52:34 +08:00
|
|
|
static slap_verbmasks ov_ops[] = {
|
|
|
|
{ BER_BVC("bind"), SOCK_OP_BIND },
|
|
|
|
{ BER_BVC("unbind"), SOCK_OP_UNBIND },
|
|
|
|
{ BER_BVC("search"), SOCK_OP_SEARCH },
|
|
|
|
{ BER_BVC("compare"), SOCK_OP_COMPARE },
|
|
|
|
{ BER_BVC("modify"), SOCK_OP_MODIFY },
|
|
|
|
{ BER_BVC("modrdn"), SOCK_OP_MODRDN },
|
|
|
|
{ BER_BVC("add"), SOCK_OP_ADD },
|
|
|
|
{ BER_BVC("delete"), SOCK_OP_DELETE },
|
|
|
|
{ BER_BVNULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static slap_verbmasks ov_resps[] = {
|
|
|
|
{ BER_BVC("result"), SOCK_REP_RESULT },
|
|
|
|
{ BER_BVC("search"), SOCK_REP_SEARCH },
|
|
|
|
{ BER_BVNULL, 0 }
|
|
|
|
};
|
|
|
|
|
2007-12-24 13:18:25 +08:00
|
|
|
static int
|
|
|
|
bs_cf_gen( ConfigArgs *c )
|
|
|
|
{
|
2011-02-04 04:17:23 +08:00
|
|
|
struct sockinfo *si;
|
2007-12-24 13:18:25 +08:00
|
|
|
int rc;
|
2007-09-07 20:02:43 +08:00
|
|
|
|
2011-02-04 04:17:23 +08:00
|
|
|
if ( c->be && c->table == Cft_Database )
|
|
|
|
si = c->be->be_private;
|
|
|
|
else if ( c->bi )
|
|
|
|
si = c->bi->bi_private;
|
|
|
|
else
|
|
|
|
return ARG_BAD_CONF;
|
|
|
|
|
2007-12-24 13:18:25 +08:00
|
|
|
if ( c->op == SLAP_CONFIG_EMIT ) {
|
|
|
|
switch( c->type ) {
|
|
|
|
case BS_EXT:
|
|
|
|
return mask_to_verbs( bs_exts, si->si_extensions, &c->rvalue_vals );
|
2011-02-04 18:52:34 +08:00
|
|
|
case BS_OPS:
|
|
|
|
return mask_to_verbs( ov_ops, si->si_ops, &c->rvalue_vals );
|
|
|
|
case BS_RESP:
|
|
|
|
return mask_to_verbs( ov_resps, si->si_resps, &c->rvalue_vals );
|
2007-12-24 13:18:25 +08:00
|
|
|
}
|
|
|
|
} else if ( c->op == LDAP_MOD_DELETE ) {
|
|
|
|
switch( c->type ) {
|
|
|
|
case BS_EXT:
|
|
|
|
if ( c->valx < 0 ) {
|
|
|
|
si->si_extensions = 0;
|
2007-12-24 13:32:13 +08:00
|
|
|
rc = 0;
|
2007-12-24 13:18:25 +08:00
|
|
|
} else {
|
2007-12-24 13:32:13 +08:00
|
|
|
slap_mask_t dels = 0;
|
|
|
|
rc = verbs_to_mask( c->argc, c->argv, bs_exts, &dels );
|
|
|
|
if ( rc == 0 )
|
|
|
|
si->si_extensions ^= dels;
|
2007-09-07 20:02:43 +08:00
|
|
|
}
|
2007-12-24 13:32:13 +08:00
|
|
|
return rc;
|
2011-02-04 18:52:34 +08:00
|
|
|
case BS_OPS:
|
|
|
|
if ( c->valx < 0 ) {
|
|
|
|
si->si_ops = 0;
|
|
|
|
rc = 0;
|
|
|
|
} else {
|
|
|
|
slap_mask_t dels = 0;
|
|
|
|
rc = verbs_to_mask( c->argc, c->argv, ov_ops, &dels );
|
|
|
|
if ( rc == 0 )
|
|
|
|
si->si_ops ^= dels;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
case BS_RESP:
|
|
|
|
if ( c->valx < 0 ) {
|
|
|
|
si->si_resps = 0;
|
|
|
|
rc = 0;
|
|
|
|
} else {
|
|
|
|
slap_mask_t dels = 0;
|
|
|
|
rc = verbs_to_mask( c->argc, c->argv, ov_resps, &dels );
|
|
|
|
if ( rc == 0 )
|
|
|
|
si->si_resps ^= dels;
|
|
|
|
}
|
|
|
|
return rc;
|
2007-09-07 20:02:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2007-12-24 13:18:25 +08:00
|
|
|
switch( c->type ) {
|
|
|
|
case BS_EXT:
|
|
|
|
return verbs_to_mask( c->argc, c->argv, bs_exts, &si->si_extensions );
|
2011-02-04 18:52:34 +08:00
|
|
|
case BS_OPS:
|
|
|
|
return verbs_to_mask( c->argc, c->argv, ov_ops, &si->si_ops );
|
|
|
|
case BS_RESP:
|
|
|
|
return verbs_to_mask( c->argc, c->argv, ov_resps, &si->si_resps );
|
2007-12-24 13:18:25 +08:00
|
|
|
}
|
2007-09-07 20:02:43 +08:00
|
|
|
}
|
2007-12-24 13:18:25 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sock_back_init_cf( BackendInfo *bi )
|
|
|
|
{
|
2011-02-04 04:17:23 +08:00
|
|
|
int rc;
|
2007-12-24 13:18:25 +08:00
|
|
|
bi->bi_cf_ocs = bsocs;
|
2007-09-07 20:02:43 +08:00
|
|
|
|
2011-02-04 04:17:23 +08:00
|
|
|
rc = config_register_schema( bscfg, bsocs );
|
|
|
|
if ( !rc )
|
|
|
|
rc = sock_over_setup();
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sock overlay wrapper */
|
|
|
|
static slap_overinst sockover;
|
|
|
|
|
|
|
|
static int sock_over_db_init( Backend *be, struct config_reply_s *cr );
|
|
|
|
static int sock_over_db_destroy( Backend *be, struct config_reply_s *cr );
|
|
|
|
|
|
|
|
static BI_op_bind *sockfuncs[] = {
|
|
|
|
sock_back_bind,
|
|
|
|
sock_back_unbind,
|
|
|
|
sock_back_search,
|
|
|
|
sock_back_compare,
|
|
|
|
sock_back_modify,
|
|
|
|
sock_back_modrdn,
|
|
|
|
sock_back_add,
|
|
|
|
sock_back_delete
|
|
|
|
};
|
|
|
|
|
2011-02-04 18:52:34 +08:00
|
|
|
static const int sockopflags[] = {
|
|
|
|
SOCK_OP_BIND,
|
|
|
|
SOCK_OP_UNBIND,
|
|
|
|
SOCK_OP_SEARCH,
|
|
|
|
SOCK_OP_COMPARE,
|
|
|
|
SOCK_OP_MODIFY,
|
|
|
|
SOCK_OP_MODRDN,
|
|
|
|
SOCK_OP_ADD,
|
|
|
|
SOCK_OP_DELETE
|
|
|
|
};
|
|
|
|
|
2011-02-04 04:17:23 +08:00
|
|
|
static int sock_over_op(
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs
|
|
|
|
)
|
|
|
|
{
|
|
|
|
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
|
|
|
|
void *private = op->o_bd->be_private;
|
2011-02-04 18:52:34 +08:00
|
|
|
slap_callback *sc;
|
|
|
|
struct sockinfo *si;
|
2011-02-04 04:17:23 +08:00
|
|
|
slap_operation_t which;
|
|
|
|
|
|
|
|
switch (op->o_tag) {
|
|
|
|
case LDAP_REQ_BIND: which = op_bind; break;
|
|
|
|
case LDAP_REQ_UNBIND: which = op_unbind; break;
|
|
|
|
case LDAP_REQ_SEARCH: which = op_search; break;
|
|
|
|
case LDAP_REQ_COMPARE: which = op_compare; break;
|
|
|
|
case LDAP_REQ_MODIFY: which = op_modify; break;
|
|
|
|
case LDAP_REQ_MODRDN: which = op_modrdn; break;
|
|
|
|
case LDAP_REQ_ADD: which = op_add; break;
|
|
|
|
case LDAP_REQ_DELETE: which = op_delete; break;
|
|
|
|
default:
|
|
|
|
return SLAP_CB_CONTINUE;
|
|
|
|
}
|
2011-02-04 18:52:34 +08:00
|
|
|
si = on->on_bi.bi_private;
|
|
|
|
if ( !(si->si_ops & sockopflags[which]))
|
|
|
|
return SLAP_CB_CONTINUE;
|
|
|
|
|
|
|
|
op->o_bd->be_private = si;
|
|
|
|
sc = op->o_callback;
|
|
|
|
op->o_callback = NULL;
|
2011-02-05 01:36:49 +08:00
|
|
|
sockfuncs[which]( op, rs );
|
2011-02-04 04:17:23 +08:00
|
|
|
op->o_bd->be_private = private;
|
2011-02-04 18:52:34 +08:00
|
|
|
op->o_callback = sc;
|
2011-02-05 01:36:49 +08:00
|
|
|
return rs->sr_err;
|
2011-02-04 04:17:23 +08:00
|
|
|
}
|
|
|
|
|
2011-02-04 04:47:38 +08:00
|
|
|
static int
|
2011-02-04 05:24:26 +08:00
|
|
|
sock_over_response( Operation *op, SlapReply *rs )
|
2011-02-04 04:47:38 +08:00
|
|
|
{
|
|
|
|
slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
|
|
|
|
struct sockinfo *si = (struct sockinfo *)on->on_bi.bi_private;
|
2011-02-04 05:24:26 +08:00
|
|
|
FILE *fp;
|
2011-02-04 04:47:38 +08:00
|
|
|
|
2011-02-04 18:52:34 +08:00
|
|
|
if ( rs->sr_type == REP_RESULT ) {
|
|
|
|
if ( !( si->si_resps & SOCK_REP_RESULT ))
|
|
|
|
return SLAP_CB_CONTINUE;
|
|
|
|
} else if ( rs->sr_type == REP_SEARCH ) {
|
|
|
|
if ( !( si->si_resps & SOCK_REP_SEARCH ))
|
|
|
|
return SLAP_CB_CONTINUE;
|
|
|
|
} else
|
2011-02-04 05:24:26 +08:00
|
|
|
return SLAP_CB_CONTINUE;
|
|
|
|
|
|
|
|
if (( fp = opensock( si->si_sockpath )) == NULL )
|
|
|
|
return SLAP_CB_CONTINUE;
|
|
|
|
|
2011-02-04 18:52:34 +08:00
|
|
|
if ( rs->sr_type == REP_RESULT ) {
|
|
|
|
/* write out the result */
|
|
|
|
fprintf( fp, "RESULT\n" );
|
|
|
|
fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
|
|
|
|
sock_print_conn( fp, op->o_conn, si );
|
|
|
|
fprintf( fp, "code: %d\n", rs->sr_err );
|
|
|
|
if ( rs->sr_matched )
|
|
|
|
fprintf( fp, "matched: %s\n", rs->sr_matched );
|
|
|
|
if (rs->sr_text )
|
|
|
|
fprintf( fp, "info: %s\n", rs->sr_text );
|
|
|
|
} else {
|
|
|
|
/* write out the search entry */
|
|
|
|
int len;
|
|
|
|
fprintf( fp, "ENTRY\n" );
|
|
|
|
fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
|
|
|
|
sock_print_conn( fp, op->o_conn, si );
|
|
|
|
ldap_pvt_thread_mutex_lock( &entry2str_mutex );
|
|
|
|
fprintf( fp, "%s", entry2str( rs->sr_entry, &len ) );
|
|
|
|
ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
|
|
|
|
}
|
2011-02-04 05:24:26 +08:00
|
|
|
fprintf( fp, "\n" );
|
|
|
|
fclose( fp );
|
|
|
|
|
|
|
|
return SLAP_CB_CONTINUE;
|
2011-02-04 04:47:38 +08:00
|
|
|
}
|
|
|
|
|
2011-02-04 04:17:23 +08:00
|
|
|
static int
|
|
|
|
sock_over_setup()
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
sockover.on_bi.bi_type = "sock";
|
|
|
|
sockover.on_bi.bi_db_init = sock_over_db_init;
|
|
|
|
sockover.on_bi.bi_db_destroy = sock_over_db_destroy;
|
|
|
|
|
|
|
|
sockover.on_bi.bi_op_bind = sock_over_op;
|
|
|
|
sockover.on_bi.bi_op_unbind = sock_over_op;
|
|
|
|
sockover.on_bi.bi_op_search = sock_over_op;
|
|
|
|
sockover.on_bi.bi_op_compare = sock_over_op;
|
|
|
|
sockover.on_bi.bi_op_modify = sock_over_op;
|
|
|
|
sockover.on_bi.bi_op_modrdn = sock_over_op;
|
|
|
|
sockover.on_bi.bi_op_add = sock_over_op;
|
|
|
|
sockover.on_bi.bi_op_delete = sock_over_op;
|
2011-02-04 04:47:38 +08:00
|
|
|
sockover.on_response = sock_over_response;
|
2011-02-04 04:17:23 +08:00
|
|
|
|
|
|
|
sockover.on_bi.bi_cf_ocs = osocs;
|
|
|
|
|
|
|
|
rc = config_register_schema( bscfg, osocs );
|
|
|
|
if ( rc ) return rc;
|
|
|
|
|
|
|
|
return overlay_register( &sockover );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sock_over_db_init(
|
|
|
|
Backend *be,
|
|
|
|
struct config_reply_s *cr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
slap_overinst *on = (slap_overinst *)be->bd_info;
|
|
|
|
void *private = be->be_private;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
be->be_private = NULL;
|
|
|
|
rc = sock_back_db_init( be, cr );
|
|
|
|
on->on_bi.bi_private = be->be_private;
|
|
|
|
be->be_private = private;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sock_over_db_destroy(
|
|
|
|
Backend *be,
|
|
|
|
struct config_reply_s *cr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
slap_overinst *on = (slap_overinst *)be->bd_info;
|
|
|
|
void *private = be->be_private;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
be->be_private = on->on_bi.bi_private;
|
|
|
|
rc = sock_back_db_destroy( be, cr );
|
|
|
|
on->on_bi.bi_private = be->be_private;
|
|
|
|
be->be_private = private;
|
|
|
|
return rc;
|
2007-09-07 20:02:43 +08:00
|
|
|
}
|