LBER_ALIGNED_BUFFER(OPERATION_BUFFER_SIZE), as discussed in ITS#4078.
Add a corresponding SyncOperationBuffer in overlays/syncprov.c.
Connection conn = {0};
OperationBuffer opbuf;
- Operation *op = (Operation *) &opbuf;
+ Operation *op;
DBC *curs;
DBT key, data;
int rc, getnext = 1;
int i;
- connection_fake_init( &conn, op, ctx );
+ connection_fake_init( &conn, &opbuf, ctx );
+ op = &opbuf.ob_op;
op->o_bd = be;
return -1;
}
- op = (Operation *) &opbuf;
thrctx = ldap_pvt_thread_pool_context();
- connection_fake_init( &conn, op, thrctx );
+ connection_fake_init( &conn, &opbuf, thrctx );
+ op = &opbuf.ob_op;
op->o_tag = LDAP_REQ_SEARCH;
SQLHDBC dbh = SQL_NULL_HDBC;
struct berbuf bb = BB_NULL;
- OperationBuffer opbuf;
- Operation* op = (Operation *) &opbuf;
+ OperationBuffer opbuf;
+ Operation* op;
Debug( LDAP_DEBUG_TRACE, "==>backsql_db_open(): "
"testing RDBMS connection\n", 0, 0, 0 );
}
/* This should just be to force schema loading */
- op->o_hdr = (Opheader *)&op[ 1 ];
+ op = &opbuf.ob_op;
+ op->o_hdr = &opbuf.ob_hdr;
op->o_connid = (unsigned long)(-1);
op->o_bd = bd;
if ( backsql_get_db_conn( op, &dbh ) != LDAP_SUCCESS ) {
backsql_connection_destroy( Backend *bd, Connection *c )
{
OperationBuffer opbuf;
- Operation* op = (Operation *) &opbuf;
+ Operation* op = &opbuf.ob_op;
- op->o_hdr = (Opheader *)&op[ 1 ];
+ op->o_hdr = &opbuf.ob_hdr;
op->o_connid = c->c_connid;
op->o_bd = bd;
void *thrctx = ldap_pvt_thread_pool_context();
int prev_DN_strict;
- op = (Operation *) &opbuf;
- connection_fake_init( &conn, op, thrctx );
+ connection_fake_init( &conn, &opbuf, thrctx );
+ op = &opbuf.ob_op;
filter.f_desc = slap_schema.si_ad_objectClass;
}
thrctx = ldap_pvt_thread_pool_context();
- op = (Operation *) &opbuf;
- connection_fake_init( &conn, op, thrctx );
+ connection_fake_init( &conn, &opbuf, thrctx );
+ op = &opbuf.ob_op;
op->o_tag = LDAP_REQ_ADD;
op->o_callback = &cb;
ca.bi->bi_type);
ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
&CFOC_DATABASE, ca.be->be_cf_ocs );
- op = (Operation *) &opbuf;
thrctx = ldap_pvt_thread_pool_context();
- connection_fake_init2( &conn, op, thrctx,0 );
+ connection_fake_init2( &conn, &opbuf, thrctx,0 );
+ op = &opbuf.ob_op;
op->o_bd = &cfb->cb_db;
op->o_tag = LDAP_REQ_ADD;
op->ora_e = ce;
ca.be->be_cf_ocs );
if ( ! op ) {
thrctx = ldap_pvt_thread_pool_context();
- op = (Operation *) &opbuf;
- connection_fake_init2( &conn, op, thrctx,0 );
+ connection_fake_init2( &conn, &opbuf, thrctx,0 );
+ op = &opbuf.ob_op;
op->o_bd = &cfb->cb_db;
op->o_tag = LDAP_REQ_ADD;
op->o_dn = be->be_rootdn;
void
connection_fake_init(
Connection *conn,
- Operation *op,
+ OperationBuffer *opbuf,
void *ctx )
{
- connection_fake_init2( conn, op, ctx, 1 );
+ connection_fake_init2( conn, opbuf, ctx, 1 );
}
void
connection_fake_init2(
Connection *conn,
- Operation *op,
+ OperationBuffer *opbuf,
void *ctx,
int newmem )
{
+ Operation *op = (Operation *) opbuf;
+
conn->c_connid = -1;
conn->c_send_ldap_result = slap_send_ldap_result;
conn->c_send_search_entry = slap_send_search_entry;
conn->c_peer_domain = slap_empty_bv;
conn->c_peer_name = slap_empty_bv;
- memset(op, 0, OPERATION_BUFFER_SIZE);
- op->o_hdr = (Opheader *)(op+1);
- op->o_controls = (void **)(op->o_hdr+1);
+ memset( opbuf, 0, sizeof( *opbuf ));
+ op->o_hdr = &opbuf->ob_hdr;
+ op->o_controls = opbuf->ob_controls;
+
/* set memory context */
op->o_tmpmemctx = slap_sl_mem_create(SLAP_SLAB_SIZE, SLAP_SLAB_STACK, ctx,
newmem );
void
slap_op_free( Operation *op )
{
+ OperationBuffer *opbuf;
+
assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );
if ( op->o_ber != NULL ) {
#endif /* defined( LDAP_SLAPI ) */
- memset( op, 0, sizeof(Operation) + sizeof(Opheader) + SLAP_MAX_CIDS * sizeof(void *) );
- op->o_hdr = (Opheader *)(op+1);
- op->o_controls = (void **)(op->o_hdr+1);
+ opbuf = (OperationBuffer *) op;
+ memset( opbuf, 0, sizeof(*opbuf) );
+ op->o_hdr = &opbuf->ob_hdr;
+ op->o_controls = opbuf->ob_controls;
ldap_pvt_thread_mutex_lock( &slap_op_mutex );
LDAP_STAILQ_INSERT_HEAD( &slap_free_ops, op, o_next );
ldap_pvt_thread_mutex_unlock( &slap_op_mutex );
if (!op) {
- op = (Operation *) ch_calloc( 1, sizeof(Operation)
- + sizeof(Opheader) + SLAP_MAX_CIDS * sizeof(void *) );
- op->o_hdr = (Opheader *)(op + 1);
- op->o_controls = (void **)(op->o_hdr+1);
+ op = (Operation *) ch_calloc( 1, sizeof(OperationBuffer) );
+ op->o_hdr = &((OperationBuffer *) op)->ob_hdr;
+ op->o_controls = ((OperationBuffer *) op)->ob_controls;
}
op->o_ber = ber;
Connection conn = {0};
OperationBuffer opbuf;
- Operation *op = (Operation *) &opbuf;
+ Operation *op;
SlapReply rs = {REP_RESULT};
slap_callback cb = { NULL, log_old_lookup, NULL, NULL };
Filter f;
char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
time_t old = slap_get_time();
- connection_fake_init( &conn, op, ctx );
+ connection_fake_init( &conn, &opbuf, ctx );
+ op = &opbuf.ob_op;
f.f_choice = LDAP_FILTER_LE;
f.f_ava = &ava;
Connection conn = {0};
OperationBuffer opbuf;
- Operation *op = (Operation *) &opbuf;
+ Operation *op;
Entry *e;
int rc;
- connection_fake_init( &conn, op, ctx );
+ connection_fake_init( &conn, &opbuf, ctx );
+ op = &opbuf.ob_op;
op->o_bd = li->li_db;
op->o_dn = li->li_db->be_rootdn;
op->o_ndn = li->li_db->be_rootndn;
int ndeletes, ntotdeletes;
- op = (Operation *)&opbuf;
- connection_fake_init( &conn, op, ctx );
+ connection_fake_init( &conn, &opbuf, ctx );
+ op = &opbuf.ob_op;
op->o_tag = LDAP_REQ_SEARCH;
memset( &op->oq_search, 0, sizeof( op->oq_search ) );
slap_callback sc = { 0 };
SlapReply rs = { REP_RESULT };
- op = (Operation *)&opbuf;
- connection_fake_init( &conn, op, ctx );
+ connection_fake_init( &conn, &opbuf, ctx );
+ op = &opbuf.ob_op;
op->o_tag = LDAP_REQ_SEARCH;
memset( &op->oq_search, 0, sizeof( op->oq_search ) );
int return_val, pause = 1;
QueryTemplate* templ;
- op = (Operation *) &opbuf;
- connection_fake_init( &conn, op, ctx );
+ connection_fake_init( &conn, &opbuf, ctx );
+ op = &opbuf.ob_op;
op->o_bd = &cm->db;
op->o_dn = cm->db.be_rootdn;
refint_attrs *ra, *ip;
int rc;
- op = (Operation *) &opbuf;
- connection_fake_init( &conn, op, ctx );
+ connection_fake_init( &conn, &opbuf, ctx );
+ op = &opbuf.ob_op;
/*
** build a search filter for all configured attributes;
BackendDB be;
int rc;
- op = (Operation *) &opbuf;
+ op = &opbuf.ob_op;
*op = *so->s_op;
- op->o_hdr = (Opheader *)(op+1);
- op->o_controls = (void **)(op->o_hdr+1);
- memset( op->o_controls, 0, SLAP_MAX_CIDS * sizeof(void *));
+ op->o_hdr = &opbuf.ob_hdr;
+ op->o_controls = opbuf.ob_controls;
+ memset( op->o_controls, 0, sizeof(opbuf.ob_controls) );
*op->o_hdr = *so->s_op->o_hdr;
return 0;
}
+typedef struct SyncOperationBuffer {
+ Operation sob_op;
+ Opheader sob_hdr;
+ AttributeName sob_extra; /* not always present */
+ /* Further data allocated here */
+} SyncOperationBuffer;
+
static void
syncprov_detach_op( Operation *op, syncops *so, slap_overinst *on )
{
+ SyncOperationBuffer *sopbuf2;
Operation *op2;
int i, alen = 0;
size_t size;
alen += op->ors_attrs[i].an_name.bv_len + 1;
}
/* Make a new copy of the operation */
- size = sizeof(Operation) + sizeof(Opheader) +
+ size = offsetof( SyncOperationBuffer, sob_extra ) +
(i ? ( (i+1) * sizeof(AttributeName) + alen) : 0) +
op->o_req_dn.bv_len + 1 +
op->o_req_ndn.bv_len + 1 +
op->o_ndn.bv_len + 1 +
so->s_filterstr.bv_len + 1;
- op2 = (Operation *)ch_calloc( 1, size );
- op2->o_hdr = (Opheader *)(op2+1);
+ sopbuf2 = ch_calloc( 1, size );
+ op2 = &sopbuf2->sob_op;
+ op2->o_hdr = &sopbuf2->sob_hdr;
/* Copy the fields we care about explicitly, leave the rest alone */
*op2->o_hdr = *op->o_hdr;
op2->o_request = op->o_request;
op2->o_private = on;
+ ptr = (char *) sopbuf2 + offsetof( SyncOperationBuffer, sob_extra );
if ( i ) {
- op2->ors_attrs = (AttributeName *)(op2->o_hdr + 1);
- ptr = (char *)(op2->ors_attrs+i+1);
+ op2->ors_attrs = (AttributeName *) ptr;
+ ptr = (char *) &op2->ors_attrs[i+1];
for (i=0; !BER_BVISNULL( &op->ors_attrs[i].an_name ); i++) {
op2->ors_attrs[i] = op->ors_attrs[i];
op2->ors_attrs[i].an_name.bv_val = ptr;
ptr = lutil_strcopy( ptr, op->ors_attrs[i].an_name.bv_val ) + 1;
}
BER_BVZERO( &op2->ors_attrs[i].an_name );
- } else {
- ptr = (char *)(op2->o_hdr + 1);
}
+
op2->o_authz = op->o_authz;
op2->o_ndn.bv_val = ptr;
ptr = lutil_strcopy(ptr, op->o_ndn.bv_val) + 1;
syncprov_info_t *si = (syncprov_info_t *)on->on_bi.bi_private;
Connection conn = { 0 };
- OperationBuffer opbuf = { 0 };
- Operation *op = (Operation *) &opbuf;
+ OperationBuffer opbuf;
+ Operation *op;
Entry *e = NULL;
Attribute *a;
int rc;
}
thrctx = ldap_pvt_thread_pool_context();
- connection_fake_init( &conn, op, thrctx );
+ connection_fake_init( &conn, &opbuf, thrctx );
+ op = &opbuf.ob_op;
op->o_bd = be;
op->o_dn = be->be_rootdn;
op->o_ndn = be->be_rootndn;
if ( si->si_numops ) {
Connection conn;
OperationBuffer opbuf;
- Operation *op = (Operation *) &opbuf;
+ Operation *op;
SlapReply rs = {REP_RESULT};
void *thrctx;
thrctx = ldap_pvt_thread_pool_context();
- connection_fake_init( &conn, op, thrctx );
+ connection_fake_init( &conn, &opbuf, thrctx );
+ op = &opbuf.ob_op;
op->o_bd = be;
op->o_dn = be->be_rootdn;
op->o_ndn = be->be_rootndn;
LDAP_SLAPD_F (void) connection2anonymous LDAP_P((Connection *));
LDAP_SLAPD_F (void) connection_fake_init LDAP_P((
Connection *conn,
- Operation *op,
+ OperationBuffer *opbuf,
void *threadctx ));
LDAP_SLAPD_F (void) connection_fake_init2 LDAP_P((
Connection *conn,
- Operation *op,
+ OperationBuffer *opbuf,
void *threadctx,
int newmem ));
LDAP_SLAPD_F (void) connection_assign_nextid LDAP_P((Connection *));
int rc;
thrctx = ldap_pvt_thread_pool_context();
- op = (Operation *)&opbuf;
- connection_fake_init2( &conn, op, thrctx, 0 );
+ connection_fake_init2( &conn, &opbuf, thrctx, 0 );
+ op = &opbuf.ob_op;
op->o_tag = LDAP_REQ_SEARCH;
op->o_req_dn = op->o_req_ndn = sl->base;
LDAP_STAILQ_ENTRY(Operation) o_next; /* next operation in list */
};
-#define OPERATION_BUFFER_SIZE ( sizeof(Operation) + sizeof(Opheader) + \
- SLAP_MAX_CIDS*sizeof(void *) )
-
-typedef LBER_ALIGNED_BUFFER(operation_buffer_u,OPERATION_BUFFER_SIZE)
- OperationBuffer;
+typedef struct OperationBuffer {
+ Operation ob_op;
+ Opheader ob_hdr;
+ void *ob_controls[SLAP_MAX_CIDS];
+} OperationBuffer;
#define send_ldap_error( op, rs, err, text ) do { \
(rs)->sr_err = err; (rs)->sr_text = text; \
argv = &argv[ optind ];
argc -= optind;
- op = (Operation *) &opbuf;
- connection_fake_init( &conn, op, &conn );
+ connection_fake_init( &conn, &opbuf, &conn );
+ op = &opbuf.ob_op;
conn.c_listener = &listener;
conn.c_listener_url = listener_url;
slap_tool_init( progname, SLAPADD, argc, argv );
memset( &opbuf, 0, sizeof(opbuf) );
- op = (Operation *) &opbuf;
- op->o_hdr = (Opheader *)(op+1);
+ op = &opbuf.ob_op;
+ op->o_hdr = &opbuf.ob_hdr;
if( !be->be_entry_open ||
!be->be_entry_close ||
argv = &argv[ optind ];
argc -= optind;
- op = (Operation *) &opbuf;
- connection_fake_init( &conn, op, &conn );
+ connection_fake_init( &conn, &opbuf, &conn );
+ op = &opbuf.ob_op;
conn.c_sasl_bind_mech = mech;
LDAP_STAILQ_INIT( &conn->c_pending_ops );
- op = (Operation *) slapi_ch_calloc( 1, OPERATION_BUFFER_SIZE );
- op->o_hdr = (Opheader *)(op + 1);
- op->o_controls = (void **)(op->o_hdr + 1);
+ op = (Operation *) slapi_ch_calloc( 1, sizeof(OperationBuffer) );
+ op->o_hdr = &((OperationBuffer *) op)->ob_hdr;
+ op->o_controls = ((OperationBuffer *) op)->ob_controls;
op->o_callback = (slap_callback *) slapi_ch_calloc( 1, sizeof(slap_callback) );
op->o_callback->sc_response = slapi_int_response;
return NULL;
}
- op = (Operation *) &opbuf;
- connection_fake_init( &conn, op, ctx );
+ connection_fake_init( &conn, &opbuf, ctx );
+ op = &opbuf.ob_op;
/* use global malloc for now */
op->o_tmpmemctx = NULL;