1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate * All rights reserved.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include "ldap_scheme.h"
30*0Sstevel@tonic-gate #include "ldap_util.h"
31*0Sstevel@tonic-gate #include "ldap_nisdbquery.h"
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate /*
35*0Sstevel@tonic-gate * Input: A db_query where the 'which_index' fields refer to the schema
36*0Sstevel@tonic-gate * columns.
37*0Sstevel@tonic-gate * Output: A db_query where the 'which_index' fields refer to the table
38*0Sstevel@tonic-gate * columns.
39*0Sstevel@tonic-gate */
40*0Sstevel@tonic-gate db_query *
schemeQuery2Query(db_query * qin,db_scheme * s)41*0Sstevel@tonic-gate schemeQuery2Query(db_query *qin, db_scheme *s) {
42*0Sstevel@tonic-gate db_query *q;
43*0Sstevel@tonic-gate int i;
44*0Sstevel@tonic-gate char *myself = "schemeQuery2Query";
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate q = cloneQuery(qin, 0);
47*0Sstevel@tonic-gate if (q == 0 || s == 0)
48*0Sstevel@tonic-gate return (q);
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate for (i = 0; i < q->components.components_len; i++) {
51*0Sstevel@tonic-gate int index = q->components.components_val[i].which_index;
52*0Sstevel@tonic-gate if (index >= s->keys.keys_len) {
53*0Sstevel@tonic-gate logmsg(MSG_NOTIMECHECK, LOG_ERR,
54*0Sstevel@tonic-gate "%s: query index %d out-of-range (%d)",
55*0Sstevel@tonic-gate myself, index, s->keys.keys_len-1);
56*0Sstevel@tonic-gate freeQuery(q);
57*0Sstevel@tonic-gate return (0);
58*0Sstevel@tonic-gate }
59*0Sstevel@tonic-gate q->components.components_val[i].which_index =
60*0Sstevel@tonic-gate s->keys.keys_val[index].column_number - 1;
61*0Sstevel@tonic-gate }
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate return (q);
64*0Sstevel@tonic-gate }
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate static const char *dirCol = "name";
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate /*
69*0Sstevel@tonic-gate * Input: A db_query where the 'which_index' fields refer to the scheme
70*0Sstevel@tonic-gate * columns, space for a nis_attr array with at least q->components->
71*0Sstevel@tonic-gate * components_len elements, a scheme, and a __nis_table_mapping_t
72*0Sstevel@tonic-gate * (for column names).
73*0Sstevel@tonic-gate * Output: A nis_attr structure with the searchable columns.
74*0Sstevel@tonic-gate */
75*0Sstevel@tonic-gate nis_attr *
schemeQuery2nisAttr(db_query * q,nis_attr * space,db_scheme * s,__nis_table_mapping_t * t,int * numAttr)76*0Sstevel@tonic-gate schemeQuery2nisAttr(db_query *q, nis_attr *space, db_scheme *s,
77*0Sstevel@tonic-gate __nis_table_mapping_t *t, int *numAttr) {
78*0Sstevel@tonic-gate nis_attr *a;
79*0Sstevel@tonic-gate int na, i, nc;
80*0Sstevel@tonic-gate char **col;
81*0Sstevel@tonic-gate char *myself = "schemeQuery2nisAttr";
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate if (q == 0 || space == 0 || s == 0 || t == 0 || numAttr == 0)
84*0Sstevel@tonic-gate return (0);
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate /*
87*0Sstevel@tonic-gate * A table will have the column names stored in the mapping
88*0Sstevel@tonic-gate * structure, while a directory only has a single column
89*0Sstevel@tonic-gate * called "name". The latter isn't stored in the mapping,
90*0Sstevel@tonic-gate * so we create a column name array for a directory.
91*0Sstevel@tonic-gate */
92*0Sstevel@tonic-gate if (t->numColumns > 0) {
93*0Sstevel@tonic-gate col = t->column;
94*0Sstevel@tonic-gate nc = t->numColumns;
95*0Sstevel@tonic-gate } else {
96*0Sstevel@tonic-gate if (t->objType == NIS_DIRECTORY_OBJ) {
97*0Sstevel@tonic-gate col = (char **)&dirCol;
98*0Sstevel@tonic-gate nc = 1;
99*0Sstevel@tonic-gate } else {
100*0Sstevel@tonic-gate return (0);
101*0Sstevel@tonic-gate }
102*0Sstevel@tonic-gate }
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate a = space;
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate for (i = 0, na = 0; i < q->components.components_len; i++) {
107*0Sstevel@tonic-gate int index;
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gate if (q->components.components_val[i].which_index >=
110*0Sstevel@tonic-gate s->keys.keys_len) {
111*0Sstevel@tonic-gate logmsg(MSG_NOTIMECHECK, LOG_ERR,
112*0Sstevel@tonic-gate "%s: query index %d out-of-range (%d)",
113*0Sstevel@tonic-gate myself,
114*0Sstevel@tonic-gate q->components.components_val[i].which_index,
115*0Sstevel@tonic-gate s->keys.keys_len-1);
116*0Sstevel@tonic-gate return (0);
117*0Sstevel@tonic-gate }
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gate index = s->keys.keys_val[i].column_number - 1;
120*0Sstevel@tonic-gate if (index >= nc) {
121*0Sstevel@tonic-gate logmsg(MSG_NOTIMECHECK, LOG_ERR,
122*0Sstevel@tonic-gate "%s: column index out-of-range (%d >= %d)",
123*0Sstevel@tonic-gate myself, index, nc);
124*0Sstevel@tonic-gate return (0);
125*0Sstevel@tonic-gate }
126*0Sstevel@tonic-gate
127*0Sstevel@tonic-gate a[na].zattr_ndx = col[index];
128*0Sstevel@tonic-gate a[na].zattr_val.zattr_val_val = q->components.
129*0Sstevel@tonic-gate components_val[i].index_value->itemvalue.itemvalue_val;
130*0Sstevel@tonic-gate a[na].zattr_val.zattr_val_len = q->components.
131*0Sstevel@tonic-gate components_val[i].index_value->itemvalue.itemvalue_len;
132*0Sstevel@tonic-gate na++;
133*0Sstevel@tonic-gate }
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate *numAttr = na;
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate return (a);
138*0Sstevel@tonic-gate }
139