Net-LDAPxs

 view release on metacpan or  search on metacpan

LDAPxs.xs  view on Meta::CPAN


SV *
_bind(ld, opt)
		LDAP *ld
		HV *opt
	PREINIT:
		SV** svp;
		int rc;
		char *binddn, *bindpasswd;
		int async;
		int msgid;
		struct berval   passwd = { 0, NULL };

		char *matched = NULL, *errmsg = NULL; 
		char **referrals;
		LDAPControl **resultctrls = NULL;
		LDAPMessage *result;
		struct berval       *servercredp;
	CODE:
		if ((svp = hv_fetch(opt, "binddn", 6, FALSE)) && SvPOK(*svp)) {
			binddn = (char *)SvPV_nolen(*svp);
		}else{
			croak("_bind(binddn): not a string");
		}
		if (hv_exists(opt, "bindpw", 6)) {
			if ((svp = hv_fetch(opt, "bindpw", 6, FALSE)) && SvPOK(*svp)) {
				bindpasswd = (char *)SvPV_nolen(*svp);
				passwd.bv_val = ber_strdup( bindpasswd );
				passwd.bv_len = strlen( passwd.bv_val );
			}else{
				croak("_bind(bindpw): not a string");
			}
		}else{
			bindpasswd = "0";
			passwd.bv_val = ber_strdup( bindpasswd );
			passwd.bv_len = strlen( passwd.bv_val );
		}
		if ((svp = hv_fetch(opt, "async", 5, FALSE)) && SvIOK(*svp)) {
			async = SvIV(*svp);
		}else{
			croak("_bind(async): not a number");
		}

		ldap_set_option( ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON );

		if (async == 0) {
			rc = ldap_sasl_bind_s( ld, binddn, LDAP_SASL_SIMPLE, &passwd, NULL, NULL, &servercredp );
		}else if(async == 1) {
			/* The asynchronous version of this API only supports the LDAP_SASL_SIMPLE mechanism. */
			rc = ldap_sasl_bind( ld, binddn, LDAP_SASL_SIMPLE, &passwd, NULL, NULL, &msgid );
			ldap_result( ld, msgid, LDAP_MSG_ALL, NULL, &result );
			ldap_parse_result( ld, result, &rc, &matched, &errmsg, &referrals, &resultctrls, 0 ); 
		}else{ }
		RETVAL = rc_exception(rc);
	OUTPUT:
		RETVAL

void
_unbind(ld)
		LDAP* ld
	PPCODE:
		ldap_unbind_ext(ld, NULL, NULL);

void
_search(ld, opt)
		LDAP *ld
		HV *opt
	PREINIT:
		int rc;
		SV** svp;

		char *base;
		int scope;
		char *filter;
		int sizelimit;
		int async;

		SV** elem;
		AV* avref;
		int len = 0;
		char **attrs = NULL;
		LDAPMessage *result;
		AV* entries;

		HV* ctrl;
		int type = 0;
		char *value;
		int critical = 0;

		char *matched = NULL, *errmsg = NULL; 
		char **referrals;
		LDAPControl *sortctrl = NULL;
		LDAPControl *requestctrls[2];
		LDAPControl **resultctrls = NULL;
		LDAPSortKey **sortkeylist;
		int msgid;

		HV* search_result;
		HV* stash;
		SV* blessed_result;
	PPCODE:
		if ((svp = hv_fetch(opt, "base", 4, FALSE)) && SvPOK(*svp)) {
			base = (char *)SvPV_nolen(*svp);
		}else{
			croak("_search(base): not a string");
		}
		if ((svp = hv_fetch(opt, "scope", 5, FALSE)) && SvIOK(*svp)) {
			scope = SvIV(*svp);
		}else{
			croak("_search(scope): not a number");
		}
		if ((svp = hv_fetch(opt, "filter", 6, FALSE)) && SvPOK(*svp)) {
			filter = (char *)SvPV_nolen(*svp);
		}else{
			croak("_search(filter): not a string");
		}
		if ((svp = hv_fetch(opt, "sizelimit", 9, FALSE)) && SvIOK(*svp)) {
			sizelimit = SvIV(*svp);
		}else{
			croak("_search(sizelimit): not a number");
		}
		if ((svp = hv_fetch(opt, "async", 5, FALSE)) && SvIOK(*svp)) {
			async = SvIV(*svp);
		}else{
			croak("_search(async): not a number");
		}

		if ((svp = hv_fetch(opt, "attrs", 5, FALSE)) && SvROK(*svp)) {
			int i;
			avref = (AV*)SvRV(*svp);
			len = av_len(avref) + 1;
			if (len == 0) {
				attrs = NULL;
			}else{
				attrs = (char **)malloc((len+1)*sizeof(char *));
				for (i = 0; i < len; i++) {
					elem = av_fetch(avref, i, 0);
					if (elem != NULL) {
						attrs[i] = (char *)SvPV_nolen(*elem);
					}
				}
				attrs[i] = NULL;
			}
		}else{
			attrs = NULL;
		}
		if ((svp = hv_fetch(opt, "control", 7, FALSE))) {
			/* there is a control request */
			if (SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) {
				ctrl = (HV*)SvRV(*svp);
				if ((svp = hv_fetch(ctrl, "type", 4, FALSE)) && SvIOK(*svp)) {
					type = SvIV(*svp);
				}else{
					croak("_search(ctrl-type): not a number");
				}
				if ((svp = hv_fetch(ctrl, "value", 5, FALSE)) && SvPOK(*svp)) {
					value = (char *)SvPV_nolen(*svp);
				}else{
					croak("_search(ctrl-value): not a string");
				}
				if ((svp = hv_fetch(ctrl, "critical", 8, FALSE)) && SvIOK(*svp)) {



( run in 0.903 second using v1.01-cache-2.11-cpan-71847e10f99 )