src/java.naming/share/classes/com/sun/jndi/ldap/Filter.java
author rriggs
Fri, 07 Dec 2018 11:51:17 -0500
changeset 52902 e3398b2e1ab0
parent 47216 71c04702a3d5
permissions -rw-r--r--
8214971: Replace use of string.equals("") with isEmpty() Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4978
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4978
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4978
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4978
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4978
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.jndi.ldap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.naming.NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.naming.directory.InvalidSearchFilterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * LDAP (RFC-1960) and LDAPv3 (RFC-2254) search filters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
    36
 * @author Xuelei Fan
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author Vincent Ryan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author Jagane Sundar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
final class Filter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * First convert filter string into byte[].
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * For LDAP v3, the conversion uses Unicode -> UTF8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * For LDAP v2, the conversion uses Unicode -> ISO 8859 (Latin-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Then parse the byte[] as a filter, converting \hh to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * a single byte, and encoding the resulting filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * into the supplied BER buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static void encodeFilterString(BerEncoder ber, String filterStr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        boolean isLdapv3) throws IOException, NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
    56
        if ((filterStr == null) || (filterStr.isEmpty())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            throw new InvalidSearchFilterException("Empty filter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        byte[] filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        int filterLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (isLdapv3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            filter = filterStr.getBytes("UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            filter = filterStr.getBytes("8859_1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        filterLen = filter.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            dbgIndent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            System.err.println("String filter: " + filterStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            System.err.println("size: " + filterLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            dprint("original: ", filter, 0, filterLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        encodeFilter(ber, filter, 0, filterLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static void encodeFilter(BerEncoder ber, byte[] filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        int filterStart, int filterEnd) throws IOException, NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            dprint("encFilter: ",  filter, filterStart, filterEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            dbgIndent++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if ((filterEnd - filterStart) <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            throw new InvalidSearchFilterException("Empty filter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        int nextOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        int parens, balance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        boolean escape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        parens = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        int filtOffset[] = new int[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
3325
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
    97
        for (filtOffset[0] = filterStart; filtOffset[0] < filterEnd;) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            switch (filter[filtOffset[0]]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            case '(':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                filtOffset[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                parens++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                switch (filter[filtOffset[0]]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                case '&':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    encodeComplexFilter(ber, filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                        LDAP_FILTER_AND, filtOffset, filterEnd);
3325
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
   106
                    // filtOffset[0] has pointed to char after right paren
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    parens--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                case '|':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    encodeComplexFilter(ber, filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                        LDAP_FILTER_OR, filtOffset, filterEnd);
3325
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
   113
                    // filtOffset[0] has pointed to char after right paren
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    parens--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                case '!':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    encodeComplexFilter(ber, filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        LDAP_FILTER_NOT, filtOffset, filterEnd);
3325
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
   120
                    // filtOffset[0] has pointed to char after right paren
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    parens--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    balance = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    escape = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    nextOffset = filtOffset[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    while (nextOffset < filterEnd && balance > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        if (!escape) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                            if (filter[nextOffset] == '(')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                balance++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                            else if (filter[nextOffset] == ')')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                balance--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                        if (filter[nextOffset] == '\\' && !escape)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                            escape = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                            escape = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                        if (balance > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                            nextOffset++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    if (balance != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        throw new InvalidSearchFilterException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                  "Unbalanced parenthesis");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    encodeSimpleFilter(ber, filter, filtOffset[0], nextOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
3325
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
   148
                    // points to the char after right paren.
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
   149
                    filtOffset[0] = nextOffset + 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    parens--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            case ')':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                // End of sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                filtOffset[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                parens--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                filtOffset[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            default:    // assume simple type=value filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                encodeSimpleFilter(ber, filter, filtOffset[0], filterEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                filtOffset[0] = filterEnd; // force break from outer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
3325
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
   175
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
   176
            if (parens < 0) {
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
   177
                throw new InvalidSearchFilterException(
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
   178
                                                "Unbalanced parenthesis");
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
   179
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
3325
0e7d9c6c9994 6449574: Invalid ldap filter is accepted and processed
xuelei
parents: 2
diff changeset
   182
        if (parens != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            throw new InvalidSearchFilterException("Unbalanced parenthesis");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            dbgIndent--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * convert character 'c' that represents a hexadecimal digit to an integer.
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 10113
diff changeset
   194
     * if 'c' is not a hexadecimal digit [0-9A-Fa-f], -1 is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * otherwise the converted value is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    private static int hexchar2int( byte c ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if ( c >= '0' && c <= '9' ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return( c - '0' );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if ( c >= 'A' && c <= 'F' ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return( c - 'A' + 10 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if ( c >= 'a' && c <= 'f' ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return( c - 'a' + 10 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return( -1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    // called by the LdapClient.compare method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    static byte[] unescapeFilterValue(byte[] orig, int start, int end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        boolean escape = false, escStart = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        int ival;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        byte ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            dprint("unescape: " , orig, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        int len = end - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        byte tbuf[] = new byte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        for (int i = start; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            ch = orig[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            if (escape) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                // Try LDAP V3 escape (\xx)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                if ((ival = hexchar2int(ch)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                     * If there is no hex char following a '\' when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                     * parsing a LDAP v3 filter (illegal by v3 way)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                     * we fallback to the way we unescape in v2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    if (escStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                        // V2: \* \( \)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                        escape = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        tbuf[j++] = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        // escaping already started but we can't find 2nd hex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        throw new InvalidSearchFilterException("invalid escape sequence: " + orig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    if (escStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        tbuf[j] = (byte)(ival<<4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        escStart = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                        tbuf[j++] |= (byte)ival;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        escape = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            } else if (ch != '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                tbuf[j++] = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                escape = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                escStart = escape = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        byte[] answer = new byte[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        System.arraycopy(tbuf, 0, answer, 0, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (dbg) {
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   262
            Ber.dumpBER(System.err, "", answer, 0, j);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    private static int indexOf(byte[] str, char ch, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        for (int i = start; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            if (str[i] == ch)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private static int indexOf(byte[] str, String target, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        int where = indexOf(str, target.charAt(0), start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (where >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            for (int i = 1; i < target.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                if (str[where+i] != target.charAt(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return where;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    private static int findUnescaped(byte[] str, char ch, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        while (start < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            int where = indexOf(str, ch, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
             * Count the immediate preceding '\' to find out if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
             * this is an escaped '*'. This is a made-up way for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
             * parsing an escaped '*' in v2. This is how the other leading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
             * SDK vendors interpret v2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
             * For v3 we fallback to the way we parse "\*" in v2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
             * It's not legal in v3 to use "\*" to escape '*'; the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
             * way is to use "\2a" instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            int backSlashPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            int backSlashCnt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            for (backSlashPos = where - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    ((backSlashPos >= start) && (str[backSlashPos] == '\\'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    backSlashPos--, backSlashCnt++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            // if at start of string, or not there at all, or if not escaped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            if (where == start || where == -1 || ((backSlashCnt % 2) == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                return where;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            // start search after escaped star
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            start = where + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    private static void encodeSimpleFilter(BerEncoder ber, byte[] filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        int filtStart, int filtEnd) throws IOException, NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            dprint("encSimpleFilter: ", filter, filtStart, filtEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            dbgIndent++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        String type, value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        int valueStart, valueEnd, typeStart, typeEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        int eq;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if ((eq = indexOf(filter, '=', filtStart, filtEnd)) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            throw new InvalidSearchFilterException("Missing 'equals'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   334
        valueStart = eq + 1;        // value starts after equal sign
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        valueEnd = filtEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        typeStart = filtStart;      // beginning of string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        int ftype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        switch (filter[eq - 1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            ftype = LDAP_FILTER_LE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            typeEnd = eq - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            ftype = LDAP_FILTER_GE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            typeEnd = eq - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        case '~':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            ftype = LDAP_FILTER_APPROX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            typeEnd = eq - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        case ':':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            ftype = LDAP_FILTER_EXT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            typeEnd = eq - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            typeEnd = eq;
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   359
            //initializing ftype to make the compiler happy
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   360
            ftype = 0x00;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   361
            break;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   362
        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   363
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   364
        if (dbg) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   365
            System.err.println("type: " + typeStart + ", " + typeEnd);
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   366
            System.err.println("value: " + valueStart + ", " + valueEnd);
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   367
        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   368
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   369
        // check validity of type
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   370
        //
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   371
        // RFC4512 defines the type as the following ABNF:
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   372
        //     attr = attributedescription
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   373
        //     attributedescription = attributetype options
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   374
        //     attributetype = oid
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   375
        //     oid = descr / numericoid
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   376
        //     descr = keystring
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   377
        //     keystring = leadkeychar *keychar
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   378
        //     leadkeychar = ALPHA
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   379
        //     keychar = ALPHA / DIGIT / HYPHEN
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   380
        //     numericoid = number 1*( DOT number )
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   381
        //     number  = DIGIT / ( LDIGIT 1*DIGIT )
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   382
        //     options = *( SEMI option )
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   383
        //     option = 1*keychar
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   384
        //
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   385
        // And RFC4515 defines the extensible type as the following ABNF:
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   386
        //     attr [dnattrs] [matchingrule] / [dnattrs] matchingrule
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   387
        int optionsStart = -1;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   388
        int extensibleStart = -1;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   389
        if ((filter[typeStart] >= '0' && filter[typeStart] <= '9') ||
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   390
            (filter[typeStart] >= 'A' && filter[typeStart] <= 'Z') ||
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   391
            (filter[typeStart] >= 'a' && filter[typeStart] <= 'z')) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   392
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   393
            boolean isNumericOid =
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   394
                filter[typeStart] >= '0' && filter[typeStart] <= '9';
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   395
            for (int i = typeStart + 1; i < typeEnd; i++) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   396
                // ';' is an indicator of attribute options
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   397
                if (filter[i] == ';') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   398
                    if (isNumericOid && filter[i - 1] == '.') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   399
                        throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   400
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   401
                    }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   402
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   403
                    // attribute options
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   404
                    optionsStart = i;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   405
                    break;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   406
                }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   407
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   408
                // ':' is an indicator of extensible rules
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   409
                if (filter[i] == ':' && ftype == LDAP_FILTER_EXT) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   410
                    if (isNumericOid && filter[i - 1] == '.') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   411
                        throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   412
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   413
                    }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   414
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   415
                    // extensible matching
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   416
                    extensibleStart = i;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   417
                    break;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   418
                }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   419
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   420
                if (isNumericOid) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   421
                    // numeric object identifier
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   422
                    if ((filter[i] == '.' && filter[i - 1] == '.') ||
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   423
                        (filter[i] != '.' &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   424
                            !(filter[i] >= '0' && filter[i] <= '9'))) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   425
                        throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   426
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   427
                    }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   428
                } else {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   429
                    // descriptor
7520
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   430
                    // The underscore ("_") character is not allowed by
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   431
                    // the LDAP specification. We allow it here to
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   432
                    // tolerate the incorrect use in practice.
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   433
                    if (filter[i] != '-' && filter[i] != '_' &&
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   434
                        !(filter[i] >= '0' && filter[i] <= '9') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   435
                        !(filter[i] >= 'A' && filter[i] <= 'Z') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   436
                        !(filter[i] >= 'a' && filter[i] <= 'z')) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   437
                        throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   438
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   439
                    }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   440
                }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   441
            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   442
        } else if (ftype == LDAP_FILTER_EXT && filter[typeStart] == ':') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   443
            // extensible matching
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   444
            extensibleStart = typeStart;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   445
        } else {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   446
            throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   447
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   448
        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   449
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   450
        // check attribute options
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   451
        if (optionsStart > 0) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   452
            for (int i = optionsStart + 1; i < typeEnd; i++) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   453
                if (filter[i] == ';') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   454
                    if (filter[i - 1] == ';') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   455
                        throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   456
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   457
                    }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   458
                    continue;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   459
                }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   460
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   461
                // ':' is an indicator of extensible rules
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   462
                if (filter[i] == ':' && ftype == LDAP_FILTER_EXT) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   463
                    if (filter[i - 1] == ';') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   464
                        throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   465
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   466
                    }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   467
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   468
                    // extensible matching
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   469
                    extensibleStart = i;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   470
                    break;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   471
                }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   472
7520
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   473
                // The underscore ("_") character is not allowed by
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   474
                // the LDAP specification. We allow it here to
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   475
                // tolerate the incorrect use in practice.
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   476
                if (filter[i] != '-' && filter[i] != '_' &&
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   477
                        !(filter[i] >= '0' && filter[i] <= '9') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   478
                        !(filter[i] >= 'A' && filter[i] <= 'Z') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   479
                        !(filter[i] >= 'a' && filter[i] <= 'z')) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   480
                    throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   481
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   482
                }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   483
            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   484
        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   485
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   486
        // check extensible matching
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   487
        if (extensibleStart > 0) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   488
            boolean isMatchingRule = false;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   489
            for (int i = extensibleStart + 1; i < typeEnd; i++) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   490
                if (filter[i] == ':') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   491
                    throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   492
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   493
                } else if ((filter[i] >= '0' && filter[i] <= '9') ||
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   494
                           (filter[i] >= 'A' && filter[i] <= 'Z') ||
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   495
                           (filter[i] >= 'a' && filter[i] <= 'z')) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   496
                    boolean isNumericOid = filter[i] >= '0' && filter[i] <= '9';
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   497
                    i++;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   498
                    for (int j = i; j < typeEnd; j++, i++) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   499
                        // allows no more than two extensible rules
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   500
                        if (filter[j] == ':') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   501
                            if (isMatchingRule) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   502
                                throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   503
                                            "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   504
                            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   505
                            if (isNumericOid && filter[j - 1] == '.') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   506
                                throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   507
                                            "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   508
                            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   509
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   510
                            isMatchingRule = true;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   511
                            break;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   512
                        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   513
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   514
                        if (isNumericOid) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   515
                            // numeric object identifier
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   516
                            if ((filter[j] == '.' && filter[j - 1] == '.') ||
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   517
                                (filter[j] != '.' &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   518
                                    !(filter[j] >= '0' && filter[j] <= '9'))) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   519
                                throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   520
                                            "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   521
                            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   522
                        } else {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   523
                            // descriptor
7520
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   524
                            // The underscore ("_") character is not allowed by
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   525
                            // the LDAP specification. We allow it here to
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   526
                            // tolerate the incorrect use in practice.
05eaa49f406b 6979376: to have ldap filters tolerate underscore character in object identifier
xuelei
parents: 6127
diff changeset
   527
                            if (filter[j] != '-' && filter[j] != '_' &&
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   528
                                !(filter[j] >= '0' && filter[j] <= '9') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   529
                                !(filter[j] >= 'A' && filter[j] <= 'Z') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   530
                                !(filter[j] >= 'a' && filter[j] <= 'z')) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   531
                                throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   532
                                            "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   533
                            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   534
                        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   535
                    }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   536
                } else {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   537
                    throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   538
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   539
                }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   540
            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   541
        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   542
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   543
        // ensure the latest byte is not isolated
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   544
        if (filter[typeEnd - 1] == '.' || filter[typeEnd - 1] == ';' ||
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   545
                                          filter[typeEnd - 1] == ':') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   546
            throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   547
                "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   548
        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   549
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   550
        if (typeEnd == eq) { // filter type is of "equal"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            if (findUnescaped(filter, '*', valueStart, valueEnd) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                ftype = LDAP_FILTER_EQUALITY;
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   553
            } else if (filter[valueStart] == '*' &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   554
                            valueStart == (valueEnd - 1)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                ftype = LDAP_FILTER_PRESENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                encodeSubstringFilter(ber, filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    typeStart, typeEnd, valueStart, valueEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (ftype == LDAP_FILTER_PRESENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            ber.encodeOctetString(filter, ftype, typeStart, typeEnd-typeStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        } else if (ftype == LDAP_FILTER_EXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            encodeExtensibleMatch(ber, filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                typeStart, typeEnd, valueStart, valueEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            ber.beginSeq(ftype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                ber.encodeOctetString(filter, Ber.ASN_OCTET_STR,
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   571
                    typeStart, typeEnd - typeStart);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                ber.encodeOctetString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    unescapeFilterValue(filter, valueStart, valueEnd),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    Ber.ASN_OCTET_STR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            dbgIndent--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    private static void encodeSubstringFilter(BerEncoder ber, byte[] filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        int typeStart, int typeEnd, int valueStart, int valueEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        throws IOException, NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            dprint("encSubstringFilter: type ", filter, typeStart, typeEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            dprint(", val : ", filter, valueStart, valueEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            dbgIndent++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        ber.beginSeq(LDAP_FILTER_SUBSTRINGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            ber.encodeOctetString(filter, Ber.ASN_OCTET_STR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    typeStart, typeEnd-typeStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            ber.beginSeq(LdapClient.LBER_SEQUENCE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                int previndex = valueStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                while ((index = findUnescaped(filter, '*', previndex, valueEnd)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    if (previndex == valueStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                      if (previndex < index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                          if (dbg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                              System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                                  "initial: " + previndex + "," + index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                        ber.encodeOctetString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                            unescapeFilterValue(filter, previndex, index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                            LDAP_SUBSTRING_INITIAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                      if (previndex < index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                          if (dbg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                              System.err.println("any: " + previndex + "," + index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                        ber.encodeOctetString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                            unescapeFilterValue(filter, previndex, index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                            LDAP_SUBSTRING_ANY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    previndex = index + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                if (previndex < valueEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                    if (dbg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                        System.err.println("final: " + previndex + "," + valueEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                  ber.encodeOctetString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                      unescapeFilterValue(filter, previndex, valueEnd),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                      LDAP_SUBSTRING_FINAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            dbgIndent--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
10113
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   635
    // The complex filter types look like:
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   636
    //     "&(type=val)(type=val)"
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   637
    //     "|(type=val)(type=val)"
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   638
    //     "!(type=val)"
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   639
    //
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   640
    // The filtOffset[0] pointing to the '&', '|', or '!'.
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   641
    //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    private static void encodeComplexFilter(BerEncoder ber, byte[] filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        int filterType, int filtOffset[], int filtEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        throws IOException, NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            dprint("encComplexFilter: ", filter, filtOffset[0], filtEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            dprint(", type: " + Integer.toString(filterType, 16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            dbgIndent++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        filtOffset[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        ber.beginSeq(filterType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            int[] parens = findRightParen(filter, filtOffset, filtEnd);
10113
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   657
            encodeFilterList(ber, filter, filterType, parens[0], parens[1]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            dbgIndent--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    // filter at filtOffset[0] - 1 points to a (. Find ) that matches it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    // and return substring between the parens. Adjust filtOffset[0] to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    // point to char after right paren
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    private static int[] findRightParen(byte[] filter, int filtOffset[], int end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    throws IOException, NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        int balance = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        boolean escape = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        int nextOffset = filtOffset[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        while (nextOffset < end && balance > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            if (!escape) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                if (filter[nextOffset] == '(')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                    balance++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                else if (filter[nextOffset] == ')')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    balance--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            if (filter[nextOffset] == '\\' && !escape)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                escape = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                escape = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            if (balance > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                nextOffset++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        if (balance != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            throw new InvalidSearchFilterException("Unbalanced parenthesis");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        // String tmp = filter.substring(filtOffset[0], nextOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        int[] tmp = new int[] {filtOffset[0], nextOffset};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        filtOffset[0] = nextOffset + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        return tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    // Encode filter list of type "(filter1)(filter2)..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    private static void encodeFilterList(BerEncoder ber, byte[] filter,
10113
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   711
        int filterType, int start, int end) throws IOException, NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            dprint("encFilterList: ", filter, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            dbgIndent++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        int filtOffset[] = new int[1];
10113
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   719
        int listNumber = 0;
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   720
        for (filtOffset[0] = start; filtOffset[0] < end; filtOffset[0]++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            if (Character.isSpaceChar((char)filter[filtOffset[0]]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
10113
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   724
            if ((filterType == LDAP_FILTER_NOT) && (listNumber > 0)) {
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   725
                throw new InvalidSearchFilterException(
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   726
                    "Filter (!) cannot be followed by more than one filters");
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   727
            }
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   728
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            if (filter[filtOffset[0]] == '(') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            int[] parens = findRightParen(filter, filtOffset, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            // add enclosing parens
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            int len = parens[1]-parens[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            byte[] newfilter = new byte[len+2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            System.arraycopy(filter, parens[0], newfilter, 1, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            newfilter[0] = (byte)'(';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            newfilter[len+1] = (byte)')';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            encodeFilter(ber, newfilter, 0, newfilter.length);
10113
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   742
b51717fb633d 7041125: LDAP API does not catch malformed filters that contain two operands for the ! operator
coffeys
parents: 7520
diff changeset
   743
            listNumber++;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            dbgIndent--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    // Encode extensible match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    private static void encodeExtensibleMatch(BerEncoder ber, byte[] filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        int matchStart, int matchEnd, int valueStart, int valueEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        throws IOException, NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        boolean matchDN = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        int colon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        int colon2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        ber.beginSeq(LDAP_FILTER_EXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            // test for colon separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            if ((colon = indexOf(filter, ':', matchStart, matchEnd)) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                // test for match DN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                if ((i = indexOf(filter, ":dn", colon, matchEnd)) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                    matchDN = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                // test for matching rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                if (((colon2 = indexOf(filter, ':', colon + 1, matchEnd)) >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    || (i == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    if (i == colon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                        ber.encodeOctetString(filter, LDAP_FILTER_EXT_RULE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                            colon2 + 1, matchEnd - (colon2 + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    } else if ((i == colon2) && (i >= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                        ber.encodeOctetString(filter, LDAP_FILTER_EXT_RULE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                            colon + 1, colon2 - (colon + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                        ber.encodeOctetString(filter, LDAP_FILTER_EXT_RULE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                            colon + 1, matchEnd - (colon + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                // test for attribute type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                if (colon > matchStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                    ber.encodeOctetString(filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                        LDAP_FILTER_EXT_TYPE, matchStart, colon - matchStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                ber.encodeOctetString(filter, LDAP_FILTER_EXT_TYPE, matchStart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    matchEnd - matchStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            ber.encodeOctetString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                unescapeFilterValue(filter, valueStart, valueEnd),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                LDAP_FILTER_EXT_VAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
             * This element is defined in RFC-2251 with an ASN.1 DEFAULT tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
             * However, for Active Directory interoperability it is transmitted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
             * even when FALSE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            ber.encodeBoolean(matchDN, LDAP_FILTER_EXT_DN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    ////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    // some debug print code that does indenting. Useful for debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    // the filter generation code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    ////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
6127
4ae58033c829 6972409: Cease emitting LDAP filter debug messages
vinnie
parents: 5506
diff changeset
   823
    private static final boolean dbg = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    private static int dbgIndent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    private static void dprint(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        dprint(msg, new byte[0], 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    private static void dprint(String msg, byte[] str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        dprint(msg, str, 0, str.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    private static void dprint(String msg, byte[] str, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        String dstr = "  ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        int i = dbgIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        while (i-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            dstr += "  ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        dstr += msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        System.err.print(dstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        for (int j = start; j < end; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            System.err.print((char)str[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    /////////////// Constants used for encoding filter //////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    static final int LDAP_FILTER_AND = 0xa0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    static final int LDAP_FILTER_OR = 0xa1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    static final int LDAP_FILTER_NOT = 0xa2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    static final int LDAP_FILTER_EQUALITY = 0xa3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    static final int LDAP_FILTER_SUBSTRINGS = 0xa4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    static final int LDAP_FILTER_GE = 0xa5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    static final int LDAP_FILTER_LE = 0xa6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    static final int LDAP_FILTER_PRESENT = 0x87;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    static final int LDAP_FILTER_APPROX = 0xa8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    static final int LDAP_FILTER_EXT = 0xa9;            // LDAPv3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    static final int LDAP_FILTER_EXT_RULE = 0x81;       // LDAPv3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    static final int LDAP_FILTER_EXT_TYPE = 0x82;       // LDAPv3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    static final int LDAP_FILTER_EXT_VAL = 0x83;        // LDAPv3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    static final int LDAP_FILTER_EXT_DN = 0x84;         // LDAPv3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    static final int LDAP_SUBSTRING_INITIAL = 0x80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    static final int LDAP_SUBSTRING_ANY = 0x81;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    static final int LDAP_SUBSTRING_FINAL = 0x82;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
}