jdk/src/share/classes/com/sun/jndi/ldap/Filter.java
author xuelei
Thu, 25 Feb 2010 13:32:40 +0800
changeset 4978 6bee79de5db6
parent 3325 0e7d9c6c9994
child 5506 202f599c92aa
permissions -rw-r--r--
6916202: More cases of invalid ldap filters accepted and processed Reviewed-by: vinnie, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
     2
 * Copyright 1999-2010 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        if ((filterStr == null) || (filterStr.equals(""))) {
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * if 'c' is not a hexidecimal digit [0-9A-Fa-f], -1 is returned.
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
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   430
                    if (filter[i] != '-' &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   431
                        !(filter[i] >= '0' && filter[i] <= '9') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   432
                        !(filter[i] >= 'A' && filter[i] <= 'Z') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   433
                        !(filter[i] >= 'a' && filter[i] <= 'z')) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   434
                        throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   435
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   436
                    }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   437
                }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   438
            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   439
        } else if (ftype == LDAP_FILTER_EXT && filter[typeStart] == ':') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   440
            // extensible matching
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   441
            extensibleStart = typeStart;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   442
        } else {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   443
            throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   444
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   445
        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   446
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   447
        // check attribute options
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   448
        if (optionsStart > 0) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   449
            for (int i = optionsStart + 1; i < typeEnd; i++) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   450
                if (filter[i] == ';') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   451
                    if (filter[i - 1] == ';') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   452
                        throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   453
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   454
                    }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   455
                    continue;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   456
                }
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
                // ':' is an indicator of extensible rules
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   459
                if (filter[i] == ':' && ftype == LDAP_FILTER_EXT) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   460
                    if (filter[i - 1] == ';') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   461
                        throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   462
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   463
                    }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   464
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   465
                    // extensible matching
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   466
                    extensibleStart = i;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   467
                    break;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   468
                }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   469
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   470
                if (filter[i] != '-' &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   471
                        !(filter[i] >= '0' && filter[i] <= '9') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   472
                        !(filter[i] >= 'A' && filter[i] <= 'Z') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   473
                        !(filter[i] >= 'a' && filter[i] <= 'z')) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   474
                    throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   475
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   476
                }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   477
            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   478
        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   479
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   480
        // check extensible matching
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   481
        if (extensibleStart > 0) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   482
            boolean isMatchingRule = false;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   483
            for (int i = extensibleStart + 1; i < typeEnd; i++) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   484
                if (filter[i] == ':') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   485
                    throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   486
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   487
                } else if ((filter[i] >= '0' && filter[i] <= '9') ||
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   488
                           (filter[i] >= 'A' && filter[i] <= 'Z') ||
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   489
                           (filter[i] >= 'a' && filter[i] <= 'z')) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   490
                    boolean isNumericOid = filter[i] >= '0' && filter[i] <= '9';
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   491
                    i++;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   492
                    for (int j = i; j < typeEnd; j++, i++) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   493
                        // allows no more than two extensible rules
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   494
                        if (filter[j] == ':') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   495
                            if (isMatchingRule) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   496
                                throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   497
                                            "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   498
                            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   499
                            if (isNumericOid && filter[j - 1] == '.') {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   500
                                throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   501
                                            "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   502
                            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   503
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   504
                            isMatchingRule = true;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   505
                            break;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   506
                        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   507
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   508
                        if (isNumericOid) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   509
                            // numeric object identifier
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   510
                            if ((filter[j] == '.' && filter[j - 1] == '.') ||
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   511
                                (filter[j] != '.' &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   512
                                    !(filter[j] >= '0' && filter[j] <= '9'))) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   513
                                throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   514
                                            "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   515
                            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   516
                        } else {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   517
                            // descriptor
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   518
                            if (filter[j] != '-' &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   519
                                !(filter[j] >= '0' && filter[j] <= '9') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   520
                                !(filter[j] >= 'A' && filter[j] <= 'Z') &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   521
                                !(filter[j] >= 'a' && filter[j] <= 'z')) {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   522
                                throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   523
                                            "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   524
                            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   525
                        }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   526
                    }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   527
                } else {
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   528
                    throw new InvalidSearchFilterException(
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   529
                                    "invalid attribute description");
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   530
                }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   531
            }
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   532
        }
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
        // ensure the latest byte is not isolated
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   535
        if (filter[typeEnd - 1] == '.' || filter[typeEnd - 1] == ';' ||
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   536
                                          filter[typeEnd - 1] == ':') {
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
        if (typeEnd == eq) { // filter type is of "equal"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            if (findUnescaped(filter, '*', valueStart, valueEnd) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                ftype = LDAP_FILTER_EQUALITY;
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   544
            } else if (filter[valueStart] == '*' &&
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   545
                            valueStart == (valueEnd - 1)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                ftype = LDAP_FILTER_PRESENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                encodeSubstringFilter(ber, filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    typeStart, typeEnd, valueStart, valueEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        if (ftype == LDAP_FILTER_PRESENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            ber.encodeOctetString(filter, ftype, typeStart, typeEnd-typeStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        } else if (ftype == LDAP_FILTER_EXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            encodeExtensibleMatch(ber, filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                typeStart, typeEnd, valueStart, valueEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            ber.beginSeq(ftype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                ber.encodeOctetString(filter, Ber.ASN_OCTET_STR,
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   562
                    typeStart, typeEnd - typeStart);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                ber.encodeOctetString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                    unescapeFilterValue(filter, valueStart, valueEnd),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    Ber.ASN_OCTET_STR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            dbgIndent--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    private static void encodeSubstringFilter(BerEncoder ber, byte[] filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        int typeStart, int typeEnd, int valueStart, int valueEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        throws IOException, NamingException {
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
            dprint("encSubstringFilter: type ", filter, typeStart, typeEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            dprint(", val : ", filter, valueStart, valueEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            dbgIndent++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        ber.beginSeq(LDAP_FILTER_SUBSTRINGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            ber.encodeOctetString(filter, Ber.ASN_OCTET_STR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    typeStart, typeEnd-typeStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            ber.beginSeq(LdapClient.LBER_SEQUENCE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                int previndex = valueStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                while ((index = findUnescaped(filter, '*', previndex, valueEnd)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    if (previndex == valueStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                      if (previndex < index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                          if (dbg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                              System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                                  "initial: " + previndex + "," + index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                        ber.encodeOctetString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                            unescapeFilterValue(filter, previndex, index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                            LDAP_SUBSTRING_INITIAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    } else {
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("any: " + previndex + "," + index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                        ber.encodeOctetString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                            unescapeFilterValue(filter, previndex, index),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                            LDAP_SUBSTRING_ANY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    previndex = index + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                if (previndex < valueEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    if (dbg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                        System.err.println("final: " + previndex + "," + valueEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                  ber.encodeOctetString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                      unescapeFilterValue(filter, previndex, valueEnd),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                      LDAP_SUBSTRING_FINAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            dbgIndent--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    private static void encodeComplexFilter(BerEncoder ber, byte[] filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        int filterType, int filtOffset[], int filtEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        throws IOException, NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        // We have a complex filter of type "&(type=val)(type=val)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        // with filtOffset[0] pointing to the &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            dprint("encComplexFilter: ", filter, filtOffset[0], filtEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            dprint(", type: " + Integer.toString(filterType, 16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            dbgIndent++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        filtOffset[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        ber.beginSeq(filterType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            int[] parens = findRightParen(filter, filtOffset, filtEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            encodeFilterList(ber, filter, parens[0], parens[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            dbgIndent--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    // filter at filtOffset[0] - 1 points to a (. Find ) that matches it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    // and return substring between the parens. Adjust filtOffset[0] to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    // point to char after right paren
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    private static int[] findRightParen(byte[] filter, int filtOffset[], int end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    throws IOException, NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        int balance = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        boolean escape = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        int nextOffset = filtOffset[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        while (nextOffset < end && balance > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            if (!escape) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                if (filter[nextOffset] == '(')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    balance++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                else if (filter[nextOffset] == ')')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    balance--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            if (filter[nextOffset] == '\\' && !escape)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                escape = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                escape = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if (balance > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                nextOffset++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        if (balance != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            throw new InvalidSearchFilterException("Unbalanced parenthesis");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        // String tmp = filter.substring(filtOffset[0], nextOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        int[] tmp = new int[] {filtOffset[0], nextOffset};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        filtOffset[0] = nextOffset + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        return tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    // Encode filter list of type "(filter1)(filter2)..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    private static void encodeFilterList(BerEncoder ber, byte[] filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        int start, int end) throws IOException, NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            dprint("encFilterList: ", filter, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            dbgIndent++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        int filtOffset[] = new int[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        for (filtOffset[0] = start; filtOffset[0] < end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                                                            filtOffset[0]++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            if (Character.isSpaceChar((char)filter[filtOffset[0]]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            if (filter[filtOffset[0]] == '(') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                continue;
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[] parens = findRightParen(filter, filtOffset, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            // add enclosing parens
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            int len = parens[1]-parens[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            byte[] newfilter = new byte[len+2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            System.arraycopy(filter, parens[0], newfilter, 1, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            newfilter[0] = (byte)'(';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            newfilter[len+1] = (byte)')';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            encodeFilter(ber, newfilter, 0, newfilter.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        if (dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            dbgIndent--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    // Encode extensible match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    private static void encodeExtensibleMatch(BerEncoder ber, byte[] filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        int matchStart, int matchEnd, int valueStart, int valueEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        throws IOException, NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        boolean matchDN = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        int colon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        int colon2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        ber.beginSeq(LDAP_FILTER_EXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            // test for colon separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            if ((colon = indexOf(filter, ':', matchStart, matchEnd)) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                // test for match DN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                if ((i = indexOf(filter, ":dn", colon, matchEnd)) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                    matchDN = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                // test for matching rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                if (((colon2 = indexOf(filter, ':', colon + 1, matchEnd)) >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                    || (i == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                    if (i == colon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                        ber.encodeOctetString(filter, LDAP_FILTER_EXT_RULE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                            colon2 + 1, matchEnd - (colon2 + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                    } else if ((i == colon2) && (i >= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                        ber.encodeOctetString(filter, LDAP_FILTER_EXT_RULE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                            colon + 1, colon2 - (colon + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                        ber.encodeOctetString(filter, LDAP_FILTER_EXT_RULE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                            colon + 1, matchEnd - (colon + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                // test for attribute type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                if (colon > matchStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    ber.encodeOctetString(filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                        LDAP_FILTER_EXT_TYPE, matchStart, colon - matchStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                ber.encodeOctetString(filter, LDAP_FILTER_EXT_TYPE, matchStart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    matchEnd - matchStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            ber.encodeOctetString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                unescapeFilterValue(filter, valueStart, valueEnd),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                LDAP_FILTER_EXT_VAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
             * This element is defined in RFC-2251 with an ASN.1 DEFAULT tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
             * However, for Active Directory interoperability it is transmitted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
             * even when FALSE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            ber.encodeBoolean(matchDN, LDAP_FILTER_EXT_DN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        ber.endSeq();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    ////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    // some debug print code that does indenting. Useful for debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    // the filter generation code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    ////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
4978
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   806
    // private static final boolean dbg = false;
6bee79de5db6 6916202: More cases of invalid ldap filters accepted and processed
xuelei
parents: 3325
diff changeset
   807
    private static final boolean dbg = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    private static int dbgIndent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    private static void dprint(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        dprint(msg, new byte[0], 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    private static void dprint(String msg, byte[] str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        dprint(msg, str, 0, str.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    private static void dprint(String msg, byte[] str, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        String dstr = "  ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        int i = dbgIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        while (i-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            dstr += "  ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        dstr += msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        System.err.print(dstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        for (int j = start; j < end; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            System.err.print((char)str[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    /////////////// Constants used for encoding filter //////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    static final int LDAP_FILTER_AND = 0xa0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    static final int LDAP_FILTER_OR = 0xa1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    static final int LDAP_FILTER_NOT = 0xa2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    static final int LDAP_FILTER_EQUALITY = 0xa3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    static final int LDAP_FILTER_SUBSTRINGS = 0xa4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    static final int LDAP_FILTER_GE = 0xa5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    static final int LDAP_FILTER_LE = 0xa6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    static final int LDAP_FILTER_PRESENT = 0x87;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    static final int LDAP_FILTER_APPROX = 0xa8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    static final int LDAP_FILTER_EXT = 0xa9;            // LDAPv3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    static final int LDAP_FILTER_EXT_RULE = 0x81;       // LDAPv3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    static final int LDAP_FILTER_EXT_TYPE = 0x82;       // LDAPv3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    static final int LDAP_FILTER_EXT_VAL = 0x83;        // LDAPv3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    static final int LDAP_FILTER_EXT_DN = 0x84;         // LDAPv3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    static final int LDAP_SUBSTRING_INITIAL = 0x80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    static final int LDAP_SUBSTRING_ANY = 0x81;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    static final int LDAP_SUBSTRING_FINAL = 0x82;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
}