Example #1
0
static unsigned long autoPosixIds_next_available( Operation *op ) {

	slap_overinst* on = (slap_overinst *)op->o_bd->bd_info;
	autoPosixIds_data* ad = on->on_bi.bi_private;

	Operation nop = *op;
	SlapReply nrs = { REP_RESULT };
	Filter* filter = NULL;
	slap_callback cb = { NULL, autoPosixIds_search_cb, NULL, ad };
	struct berval fstr = BER_BVNULL;
	struct berval rootstr = BER_BVNULL;
  	int rc;

	// if max uid is known don't bother searching the tree
	if( ad->max_uid_number == 0 ) {

	    nop.o_callback = &cb;
	    op->o_bd->bd_info = (BackendInfo *) on->on_info;
	    nop.o_tag = LDAP_REQ_SEARCH;
	    nop.o_ctrls = NULL;
		
	    filter = str2filter( "(uidNumber=*)" );
	    filter2bv( filter, &fstr );

	    nop.ors_scope = LDAP_SCOPE_SUBTREE;
	    nop.ors_deref = LDAP_DEREF_NEVER;
	    nop.ors_slimit = -1;//SLAP_NO_LIMIT;
	    nop.ors_tlimit = -1;//SLAP_NO_LIMIT;
	    nop.ors_attrsonly = 1;
	    nop.ors_attrs = slap_anlist_no_attrs;
	    nop.ors_filter = filter;
	    nop.ors_filterstr = fstr;

	    memset( &nrs, 0, sizeof(nrs) );
	    nrs.sr_type = REP_RESULT;
	    nrs.sr_err = LDAP_SUCCESS;
	    nrs.sr_entry = NULL;
	    nrs.sr_flags |= REP_ENTRY_MUSTBEFREED;
	    nrs.sr_text = NULL;

	    nop.o_req_dn = rootstr;
	    nop.o_req_ndn = rootstr;

	    if( nop.o_bd->be_search ) {
		rc = nop.o_bd->be_search( &nop, &nrs );
		Debug( LDAP_DEBUG_TRACE, "%s: finished searching for entries with uidNumber\n", autoPosixIds.on_bi.bi_type, 0, 0 );
	    }
	    else {
		Debug( LDAP_DEBUG_ANY, "%s: backend missing search function\n", autoPosixIds.on_bi.bi_type, 0, 0 );
	    }

	    if( filter ) filter_free( filter );
	    if( fstr.bv_val ) ch_free( fstr.bv_val );
	}
	return ++(ad->max_uid_number);
}
Example #2
0
static int example_search(Operation *op, char *attrcontent) {
  slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
  example_data *ex = on->on_bi.bi_private;
  Operation nop = *op;
  slap_callback cb = { NULL, example_callback, NULL, NULL, ex};
  SlapReply nrs = { REP_RESULT };
  int rc;
  Filter *filter = NULL;
  struct berval fstr = BER_BVNULL;
  char *buffer;
  size_t len;

  len = strlen(ex->principalattr) + 5;
  buffer = (char *)malloc(sizeof(char) * len);
  if (!buffer) {
    nop.o_bd->bd_info = (BackendInfo *)(on->on_info);
    send_ldap_error(&nop, &nrs, LDAP_OTHER,
		    "Cannot allocate memory in example_search()");
    return nrs.sr_err;
  }
  snprintf(buffer, len, "(krbPrincipalName=%s@%s)", attrcontent, ex->exampledomain) ;
  filter = str2filter(buffer);
  filter2bv(filter, &fstr);

  nop.o_callback = &cb;
  op->o_bd->bd_info = (BackendInfo *) on->on_info;
  nop.o_tag = LDAP_REQ_SEARCH;
  nop.o_ctrls = NULL;
  nop.ors_scope = LDAP_SCOPE_SUBTREE;
  nop.ors_deref = LDAP_DEREF_NEVER;
  nop.ors_slimit = SLAP_NO_LIMIT;
  nop.ors_tlimit = SLAP_NO_LIMIT;
  nop.ors_attrsonly = 1;
  nop.ors_attrs = slap_anlist_no_attrs;
  nop.ors_filter = filter;
  nop.ors_filterstr = fstr;

  if (nop.o_bd->be_search) rc = nop.o_bd->be_search(&nop, &nrs);
  free(buffer);
  if (filter) filter_free(filter);
  if (fstr.bv_val) ch_free(fstr.bv_val);

  return SLAP_CB_CONTINUE;
}