3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include <sys/systeminfo.h>
30 #include <strings.h>
31 #include <rpcsvc/nis.h>
32
33 #include "nis_parse_ldap_conf.h"
34
35 #include "ldap_attr.h"
36 #include "ldap_util.h"
37 #include "ldap_structs.h"
38
39
40 /*
41 * If 'name' doesn't end in a trailing dot, return a copy with the
42 * value of "nisplusLDAPbaseDomain" appended. Otherwise, return a
43 * copy of 'name'. If deallocate!=0, free 'name'.
44 */
45 char *
46 fullObjName(int deallocate, char *name) {
47 int l;
48 char *full;
198 char *str, *filter, *tmp;
199 char *myself = "makeFilter";
200
201 if (attr == 0 || (len = strlen(attr)) == 0)
202 return (0);
203
204 /* Assume already of appropriate form if first char is '(' */
205 if (len > 1 && attr[0] == '(' && attr[len-1] == ')')
206 return (sdup(myself, T, attr));
207
208 str = sdup(myself, T, attr);
209 if (str == 0)
210 return (0);
211 filter = sdup(myself, T, "(&");
212 if (filter == 0) {
213 free(str);
214 return (0);
215 }
216 for (s = c = 0; s < len; s = e+1) {
217 /* Skip blank space, if any */
218 for (0; str[s] == ' ' || str[s] == '\t'; s++);
219 /* Find delimiter (comma) or end of string */
220 for (e = s; str[e] != '\0' && str[e] != ','; e++);
221 str[e] = '\0';
222 tmp = scat(myself, T, sdup(myself, T, "("),
223 scat(myself, F, &str[s], ")"));
224 if (tmp == 0) {
225 sfree(filter);
226 return (0);
227 }
228 c++;
229 filter = scat(myself, T, filter, tmp);
230 }
231
232 /*
233 * If there's just one component, we return it as is. This
234 * means we avoid turning "objectClass=posixAccount" into
235 * "(&(objectClass=posixAccount))".
236 */
237 if (c == 1) {
238 sfree(filter);
268 if (comp == 0)
269 return (0);
270 comp[0] = sdup(myself, T, filter);
271 if (comp[0] == 0) {
272 sfree(comp);
273 return (0);
274 }
275 if (numComps != 0)
276 *numComps = 1;
277 return (comp);
278 }
279
280 if (filter != 0 && (len = strlen(filter)) != 0 && len > 2 &&
281 filter[0] == '(' && filter[1] == '&' &&
282 filter[len-1] == ')') {
283 str = sdup(myself, T, filter);
284 if (str == 0)
285 return (0);
286 for (s = 2; s < len; s = e+1) {
287 /* Skip past the '(' */
288 for (0; s < len && str[s] != '('; s++);
289 s++;
290 if (s >= len)
291 break;
292 for (e = s; str[e] != '\0' && str[e] != ')'; e++);
293 str[e] = '\0';
294 new = realloc(comp, (nc+1) * sizeof (comp[nc]));
295 if (new == 0) {
296 if (comp != 0) {
297 for (i = 0; i < nc; i++)
298 sfree(comp[i]);
299 free(comp);
300 comp = 0;
301 }
302 nc = 0;
303 break;
304 }
305 comp = new;
306 comp[nc] = sdup(myself, T, &str[s]);
307 if (comp[nc] == 0) {
308 for (i = 0; i < nc; i++)
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2015 Gary Mills
24 * Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 #include <sys/systeminfo.h>
29 #include <strings.h>
30 #include <rpcsvc/nis.h>
31
32 #include "nis_parse_ldap_conf.h"
33
34 #include "ldap_attr.h"
35 #include "ldap_util.h"
36 #include "ldap_structs.h"
37
38
39 /*
40 * If 'name' doesn't end in a trailing dot, return a copy with the
41 * value of "nisplusLDAPbaseDomain" appended. Otherwise, return a
42 * copy of 'name'. If deallocate!=0, free 'name'.
43 */
44 char *
45 fullObjName(int deallocate, char *name) {
46 int l;
47 char *full;
197 char *str, *filter, *tmp;
198 char *myself = "makeFilter";
199
200 if (attr == 0 || (len = strlen(attr)) == 0)
201 return (0);
202
203 /* Assume already of appropriate form if first char is '(' */
204 if (len > 1 && attr[0] == '(' && attr[len-1] == ')')
205 return (sdup(myself, T, attr));
206
207 str = sdup(myself, T, attr);
208 if (str == 0)
209 return (0);
210 filter = sdup(myself, T, "(&");
211 if (filter == 0) {
212 free(str);
213 return (0);
214 }
215 for (s = c = 0; s < len; s = e+1) {
216 /* Skip blank space, if any */
217 for (; str[s] == ' ' || str[s] == '\t'; s++);
218 /* Find delimiter (comma) or end of string */
219 for (e = s; str[e] != '\0' && str[e] != ','; e++);
220 str[e] = '\0';
221 tmp = scat(myself, T, sdup(myself, T, "("),
222 scat(myself, F, &str[s], ")"));
223 if (tmp == 0) {
224 sfree(filter);
225 return (0);
226 }
227 c++;
228 filter = scat(myself, T, filter, tmp);
229 }
230
231 /*
232 * If there's just one component, we return it as is. This
233 * means we avoid turning "objectClass=posixAccount" into
234 * "(&(objectClass=posixAccount))".
235 */
236 if (c == 1) {
237 sfree(filter);
267 if (comp == 0)
268 return (0);
269 comp[0] = sdup(myself, T, filter);
270 if (comp[0] == 0) {
271 sfree(comp);
272 return (0);
273 }
274 if (numComps != 0)
275 *numComps = 1;
276 return (comp);
277 }
278
279 if (filter != 0 && (len = strlen(filter)) != 0 && len > 2 &&
280 filter[0] == '(' && filter[1] == '&' &&
281 filter[len-1] == ')') {
282 str = sdup(myself, T, filter);
283 if (str == 0)
284 return (0);
285 for (s = 2; s < len; s = e+1) {
286 /* Skip past the '(' */
287 for (; s < len && str[s] != '('; s++);
288 s++;
289 if (s >= len)
290 break;
291 for (e = s; str[e] != '\0' && str[e] != ')'; e++);
292 str[e] = '\0';
293 new = realloc(comp, (nc+1) * sizeof (comp[nc]));
294 if (new == 0) {
295 if (comp != 0) {
296 for (i = 0; i < nc; i++)
297 sfree(comp[i]);
298 free(comp);
299 comp = 0;
300 }
301 nc = 0;
302 break;
303 }
304 comp = new;
305 comp[nc] = sdup(myself, T, &str[s]);
306 if (comp[nc] == 0) {
307 for (i = 0; i < nc; i++)
|