Ejemplo n.º 1
0
static VALUE rldap_bind(int argc, VALUE *argv, VALUE obj)
{
	RLDAP_WRAP *wrapper;
	char *bind_dn = NULL, *bind_password = NULL;
	int retval;
	VALUE rdn, rpassword;
	
	rb_scan_args(argc, argv, "02", &rdn, &rpassword);
	
	if (NIL_P(rdn))
		bind_dn = NULL;
	else
		bind_dn = StringValuePtr(rdn);
	if (NIL_P(rpassword))
		bind_password = NULL;
	else
		bind_password = StringValuePtr(rpassword);
	
	wrapper = get_wrapper(obj);

	retval = ldap_bind_s(wrapper->ld, bind_dn, bind_password, LDAP_AUTH_SIMPLE);
	
	if (retval != LDAP_SUCCESS)
		rldap_raise(retval);
	else
		return Qtrue;
}
Ejemplo n.º 2
0
static VALUE rldap_set_option(VALUE obj, VALUE roption, VALUE rvalue)
{
	RLDAP_WRAP *wrapper;
	int retval;
	int option;
	int ival;
	char *sval;
	void *val;
	
	wrapper = get_wrapper(obj);
	option = FIX2INT(roption);
	
	if (TYPE(rvalue) == T_STRING) {
		sval = StringValuePtr(rvalue);
		val = &sval;
	} else {
		ival = FIX2INT(rvalue);
		val = &ival;
	}
	
	retval = ldap_set_option(wrapper->ld, option, val);
	
	if (retval == LDAP_OPT_SUCCESS)
		return Qtrue;
	else
		return Qfalse;
}
Ejemplo n.º 3
0
int rldap_errno_c(VALUE obj)
{
	RLDAP_WRAP *wrapper;
	int errno;

	wrapper = get_wrapper(obj);
	ldap_get_option(wrapper->ld, LDAP_OPT_RESULT_CODE, &errno);
	return errno;
}
Ejemplo n.º 4
0
static VALUE rldap_uri(VALUE obj)
{
	RLDAP_WRAP *wrapper;
	char *uri;
	VALUE ruri;
	
	wrapper = get_wrapper(obj);
	ldap_get_option(wrapper->ld, LDAP_OPT_URI, &uri);
	
	return rb_str_new2(uri);
}
Ejemplo n.º 5
0
static VALUE rldap_start_tls(VALUE obj)
{
	RLDAP_WRAP *wrapper;
	int retval;

	wrapper = get_wrapper(obj);
	retval = ldap_start_tls_s(wrapper->ld, NULL, NULL);
	if (retval == LDAP_SUCCESS)
		return Qtrue;
	else
		rldap_raise(retval);
}
Ejemplo n.º 6
0
static VALUE rldap_unbind(VALUE obj)
{
	RLDAP_WRAP *wrapper;
	int retval;
	
	wrapper = get_wrapper(obj);
	retval = ldap_unbind_s(wrapper->ld);
	if (retval != LDAP_SUCCESS)
		rldap_raise(retval);
	else
		return Qtrue;
}
Ejemplo n.º 7
0
void PbContainer2::insert(Constraint *p, const Machine::PTransition *t, Constraint *c){
  assert(dynamic_cast<PbConstraint*>(c));
  assert(dynamic_cast<PbConstraint*>(p));
  wrapper_t *w = insert_in_f(static_cast<PbConstraint*>(c));
  if(w){
    f_size++;
    insert_in_q(w);
    wrapper_t *pw = get_wrapper(static_cast<PbConstraint*>(p));
    w->parent.transition = t;
    w->parent.target = pw;
    pw->children.push_back(wrapper_t::trans_t(t,w));
  }
};
Ejemplo n.º 8
0
void CoAP_RD_Resource::handler_post(CoAPCallback &callback)
{
    std::string ep_identifier = "";
    std::string ep_domain = "hisilicion";

    if (get_wrapper() != 0)
        get_wrapper()->get_domain_and_endpointIdentifier(callback, ep_domain, ep_identifier);

    if (ep_identifier.empty())
    {
        get_wrapper()->bad_request(callback);

        return;
    }

    CoAPResource *r = find_resource_from_cache_by_ep(ep_domain, ep_identifier);

    if (r)
    {
        r->update(callback);
        get_wrapper()->changed_request(callback);
    }
    else
    {
        r = create_node_resource(callback, ep_domain, ep_identifier);

        if (r)
        {
            void *rd;
            std::string payload;
            
            add_node_to_cache(r);
            
            r->update(callback);
            rd = r->Create();
            r->SetCoAPResource(rd);

            get_wrapper()->get_payload(callback, payload);
            r->set_payload(payload);

            response_ok(r, callback);
        }
        else
        {
            get_wrapper()->internal_err_request(callback);
        }
    }
        
}
Ejemplo n.º 9
0
static VALUE rldap_initialize(int argc, VALUE *argv, VALUE obj)
{
	VALUE rhost, rport;
	char *host;
	int port;
	RLDAP_WRAP *wrapper;

	rb_scan_args(argc, argv, "11", &rhost, &rport);

	if (NIL_P(rport))
		rport = INT2FIX(LDAP_PORT);

	wrapper = get_wrapper(obj);
	host = StringValuePtr(rhost);
	port = FIX2INT(rport);

	wrapper->ld = (LDAP *)ldap_init(host, port);

	return obj;
}
Ejemplo n.º 10
0
static VALUE rldap_sasl_bind(int argc, VALUE *argv, VALUE obj)
{
	RLDAP_WRAP *wrapper;
	char *bind_dn = NULL, *passwd = NULL, *sasl_mech = NULL,
		*sasl_realm = NULL, *sasl_authz_id = NULL, *sasl_authc_id = NULL;
	VALUE rbind_dn, rpasswd, rsasl_mech, rsasl_realm,
		rsasl_authz_id, rsasl_authc_id, rprops;
	int retval;
	RLDAP_BICTX *ctx;
	
	wrapper = get_wrapper(obj);
	rb_scan_args(argc, argv, "07", &rbind_dn, &rpasswd, &rsasl_mech, &rsasl_realm, &rsasl_authz_id, &rsasl_authc_id, &rprops);
	
	if (!NIL_P(rprops))
		ldap_set_option(wrapper->ld, LDAP_OPT_X_SASL_SECPROPS, StringValuePtr(rprops));
	
	if (!NIL_P(rbind_dn))
		bind_dn = StringValuePtr(rbind_dn);
	if (!NIL_P(rpasswd))
		passwd = StringValuePtr(rpasswd);
	if (!NIL_P(rsasl_mech))
		sasl_mech = StringValuePtr(rsasl_mech);
	if (!NIL_P(rsasl_realm))
		sasl_realm = StringValuePtr(rsasl_realm);
	if (!NIL_P(rsasl_authz_id))
		sasl_authz_id = StringValuePtr(rsasl_authz_id);
	if (!NIL_P(rsasl_authc_id))
		sasl_authc_id = StringValuePtr(rsasl_authc_id);
	
	ctx = _rldap_sasl_setdefs(wrapper->ld, sasl_mech, sasl_realm, sasl_authc_id, passwd, sasl_authz_id);
	
	retval = ldap_sasl_interactive_bind_s(wrapper->ld, bind_dn, ctx->mech, NULL, NULL, LDAP_SASL_AUTOMATIC, _rldap_sasl_interact, ctx);
	
	_rldap_sasl_freedefs(ctx);
	
	if (retval != LDAP_SUCCESS)
		rldap_raise(retval);
	else
		return Qtrue;
}
Ejemplo n.º 11
0
Trace *PbContainer2::clear_and_get_trace(Constraint *cc){
  assert(dynamic_cast<PbConstraint*>(cc));
  PbConstraint *c = static_cast<PbConstraint*>(cc);
  assert(pointer_in_f(c));
  /* Create the trace */
  wrapper_t *w = get_wrapper(c);
  Trace *trace = new Trace(c);
  w->constraint = 0; // Remove reference to constraint to avoid later deallocation
  while(w->parent.target){
    trace->push_back(*w->parent.transition,w->parent.target->constraint);
    w = w->parent.target;
    /* Remove reference to constraint to avoid later deallocation */
    w->constraint = 0;
  }

  /* Clear */
  clear();

  Log::msg << "Trace length: " << trace->size() << "\n";

  return trace;
};
Ejemplo n.º 12
0
CoAPResource *CoAP_RD_Resource::create_node_resource(CoAPCallback &callback, 
                                                 std::string &domain, 
                                                 std::string &ep)
{
    CoAPRDNodeResource *node = new CoAPRDNodeResource(get_wrapper());

    if (node == 0)
        return 0;

    std::string tmp = create_node_uri(uri());
    
    node->SetURI(tmp);

    CoAP_Attr attr;

    attr.insert(std::make_pair("d",domain.c_str()));
    attr.insert(std::make_pair("ep",ep.c_str()));
    
    node->SetAttr(attr);
    
    return node;
}
Ejemplo n.º 13
0
Archivo: main.cpp Proyecto: CCJY/coliru
 T*        get () const { return const_cast<T*> (static_cast<T const*> (get_wrapper ()->ptr)); }
Ejemplo n.º 14
0
Archivo: main.cpp Proyecto: CCJY/coliru
 shared_ptr (T const* ptr)
   : e (std::make_exception_ptr<value_wrapper> (value_wrapper (ptr)))
 {
   get_wrapper ()->d = true;
 }
Ejemplo n.º 15
0
static VALUE rldap_search(int argc, VALUE *argv, VALUE obj)
{
	RLDAP_WRAP *wrapper;
	char *base, *filter;
	int retval, count, i, scope;
	LDAPMessage *res, *msg;
	VALUE ary, rbase, rfilter, rscope;
	ID iscope;
	
	rb_scan_args(argc, argv, "21", &rbase, &rfilter, &rscope);

	switch(TYPE(rscope)) {
		case T_NIL:
			scope = LDAP_SCOPE_SUBTREE;
			break;
		case T_FIXNUM:
			scope = FIX2INT(rscope);
			break;
		case T_SYMBOL:
		case T_STRING:
			iscope = rb_to_id(rscope);
			if (iscope == rb_intern("subtree"))
				scope = LDAP_SCOPE_SUBTREE;
			if (iscope == rb_intern("base"))
				scope = LDAP_SCOPE_BASE;
			if (iscope == rb_intern("one"))
				scope = LDAP_SCOPE_ONE;
			break;
		default:
			rb_raise(rb_eTypeError, "not a valid scope");
			break;
	}
	
	wrapper = get_wrapper(obj);
	base = StringValuePtr(rbase);
	filter = StringValuePtr(rfilter);

	retval = ldap_search_ext_s(wrapper->ld, base, scope, filter, NULL, 0, NULL, NULL, NULL, 0, &res);

	if (retval != LDAP_SUCCESS)
		rldap_raise(retval);

	count = ldap_count_entries(wrapper->ld, res);
	
	if (count == -1) {
		int errno;
		ldap_get_option(wrapper->ld, LDAP_OPT_RESULT_CODE, &errno);
		rldap_raise(errno);
	}
	
	ary = rb_ary_new2((long)count);
	
	msg = ldap_first_entry(wrapper->ld, res);
	
	for (i=0; i<count; i++) {
		rb_ary_store(ary, (long)i, ldapmessage2obj(wrapper->ld, msg));
		msg = ldap_next_entry(wrapper->ld, msg);
	}
	
	return ary;
}