1N/A * Copyright (c) 1998-2001 by Sun Microsystems, Inc. 1N/A * All rights reserved. 1N/A#
pragma ident "%Z%%M% %I% %E% SMI" 1N/A * Copyright (c) 1990 Regents of the University of Michigan. 1N/A * All rights reserved. 1N/Astatic char copyright[] =
"@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
1N/A#
endif /* NEEDPROTOS */ 1N/A * Create the search request. It looks like this: 1N/A * SearchRequest := [APPLICATION 3] SEQUENCE { 1N/A * baseObject DistinguishedName, 1N/A * scope ENUMERATED { 1N/A * derefAliases ENUMERATED { 1N/A * neverDerefaliases (0), 1N/A * derefInSearching (1), 1N/A * derefFindingBaseObj (2), 1N/A * alwaysDerefAliases (3) 1N/A * sizelimit INTEGER (0 .. 65535), 1N/A * timelimit INTEGER (0 .. 65535), 1N/A * attrsOnly BOOLEAN, 1N/A * attributes SEQUENCE OF AttributeType 1N/A * wrapped in an ldap message. 1N/A /* create a message to send */ 1N/A /* Code controls if any */ 1N/A /* Otherwise, is there any global server ctrls ? */ 1N/A * ldap_search - initiate an ldap (and X.500) search operation. Parameters: 1N/A * ld LDAP descriptor 1N/A * base DN of the base object 1N/A * scope the search scope - one of LDAP_SCOPE_BASE, 1N/A * LDAP_SCOPE_ONELEVEL, LDAP_SCOPE_SUBTREE 1N/A * filter a string containing the search filter 1N/A * (e.g., "(|(cn=bob)(sn=bob))") 1N/A * attrs list of attribute types to return for matches 1N/A * attrsonly 1 => attributes only 0 => attributes and values 1N/A * char *attrs[] = { "mail", "title", 0 }; 1N/A * msgid = ldap_search( ld, "c=us@o=UM", LDAP_SCOPE_SUBTREE, "cn~=bob", 1N/A * attrs, attrsonly ); 1N/A#
endif /* NO_CACHE */ 1N/A /* send the message */ 1N/A * We have (x(filter)...) with str sitting on 1N/A * the x. We have to find the paren matching 1N/A * the one before the x and put the intervening 1N/A * filters by calling put_filter_list(). 1N/A /* put explicit tag */ 1N/A if (!not && ber_printf(ber, "{") == -1) 1N/A /* flush explicit tagged thang */ 1N/A if (!not && ber_printf(ber, "}") == -1) 1N/A * A Filter looks like this: 1N/A * Filter ::= CHOICE { 1N/A * and [0] SET OF Filter, 1N/A * or [1] SET OF Filter, 1N/A * equalityMatch [3] AttributeValueAssertion, 1N/A * substrings [4] SubstringFilter, 1N/A * greaterOrEqual [5] AttributeValueAssertion, 1N/A * lessOrEqual [6] AttributeValueAssertion, 1N/A * present [7] AttributeType, 1N/A * approxMatch [8] AttributeValueAssertion, 1N/A * extensibleMatch [9] MatchingRuleAssertion 1N/A * SubstringFilter ::= SEQUENCE { 1N/A * type AttributeType, 1N/A * SEQUENCE OF CHOICE { 1N/A * initial [0] IA5String, 1N/A * any [1] IA5String, 1N/A * final [2] IA5String 1N/A * MatchingRuleAssertion ::= SEQUENCE { 1N/A * matchingRule [1] MatchingRuleId OPTIONAL, 1N/A * type [2] AttributeDescription OPTIONAL, 1N/A * matchValue [3] AssertionValue, 1N/A * dnAttributes [4] BOOLEAN DEFAULT FALSE 1N/A * Note: tags in a choice are always explicit 1N/A "put_filter \"%s\"\n"),
str, 0, 0);
1N/A 244,
"put_filter: AND\n"), 0, 0, 0);
1N/A 245,
"put_filter: OR\n"), 0, 0, 0);
1N/A 246,
"put_filter: NOT\n"), 0, 0, 0);
1N/A 402,
"put_filter: Double Parentheses\n"),
1N/A 247,
"put_filter: simple\n"), 0, 0, 0);
1N/A "put_filter: end\n"), 0, 0, 0);
1N/A default:
/* assume it's a simple type=value filter */ 1N/A "put_filter: default\n"), 0, 0, 0);
1N/A * Put a list of filters like this "(filter1)(filter2)..." 1N/A "put_filter_list \"%s\"\n"),
str, 0, 0);
1N/A /* now we have "(filter)" with str pointing to it */ 1N/A "put_simple_filter \"%s\"\n"),
str, 0, 0);
1N/A /* LDAP V3 : New extensible matching */ 1N/A "put_substring_filter \"%1$s=%2$s\"\n"),
type,
val, 0);
1N/A "put_extensible_filter \"%1$s=%2$s\"\n"),
type,
val, 0);
1N/A /* type is off form : attr:dn:matchingrule: or :dn:matchingrule: */ 1N/A /* type ends with ':', suppress it */ 1N/A /* Search first ':dn' */ 1N/A /* if there's a : its separating type and matching rule */ 1N/A/* LDAPv3 API EXTENSIONS */ 1N/A "ldap_search\n"), 0, 0, 0);
1N/A#
endif /* NO_CACHE */ 1N/A /* send the message */ 1N/A * Search string for ascii '*' (asterisk) character. 1N/A * RFC 1960 permits an escaped asterisk to pass through. 1N/A * RFC 2254 adds the definition of encoded characters: 1N/A * Character ASCII value 1N/A * --------------------------- 1N/A * No distinction of escaped characters is made here. 1N/A break;
/* input string exahausted */ 1N/A ++
str;
/* Assume RFC 1960 escaped character */ 1N/A /* Check for RFC 2254 hex encoding */ 1N/A str++;
/* skip over RFC 2254 hex encoding */ 1N/A * Return integer value of hexadecimal character or (-1) if character is 1N/A * not a hexadecimal digit [0-9A-Fa-f]. 1N/A if (c >=
'0' && c <=
'9') {
1N/A }
else if (c >=
'A' && c <=
'F') {
1N/A }
else if (c >=
'a' && c <=
'f') {
1N/A * Modifys passed string converting escaped hexadecimal characters as 1N/A * per RFC 2254 and un-escapes escaped characters. Returns length of 1N/A * modified string as it may contain null characters as per RFC 2254. 1N/A break;
/* input string exahausted */ 1N/A * Assume *read is simple RFC 1960 escaped character. 1N/A * However check for RFC 2254 hex encoding.