2 * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "krb5_locl.h"
35 RCSID("$Id: config_file_netinfo.c,v 1.3 2001/05/14 06:14:45 assar Exp $");
38 * Netinfo implementation from Luke Howard <lukeh@xedoc.com.au>
42 #include <netinfo/ni.h>
44 ni_proplist2binding(ni_proplist *pl, krb5_config_section **ret)
47 krb5_config_section **next = NULL;
49 for (i = 0; i < pl->ni_proplist_len; i++) {
50 if (!strcmp(pl->nipl_val[i].nip_name, "name"))
53 for (j = 0; j < pl->nipl_val[i].nip_val.ni_namelist_len; j++) {
54 krb5_config_binding *b;
56 b = malloc(sizeof(*b));
61 b->type = krb5_config_string;
62 b->name = ni_name_dup(pl->nipl_val[i].nip_name);
63 b->u.string = ni_name_dup(pl->nipl_val[i].nip_val.ninl_val[j]);
77 ni_idlist2binding(void *ni, ni_idlist *idlist, krb5_config_section **ret)
81 krb5_config_section **next;
83 for (i = 0; i < idlist->ni_idlist_len; i++) {
87 krb5_config_binding *b;
91 nid.nii_object = idlist->ni_idlist_val[i];
93 nis = ni_read(ni, &nid, &pl);
98 index = ni_proplist_match(pl, "name", NULL);
99 b = malloc(sizeof(*b));
100 if (b == NULL) return NI_FAILED;
108 b->type = krb5_config_list;
109 b->name = ni_name_dup(pl.nipl_val[index].nip_val.ninl_val[0]);
113 /* get the child directories */
114 nis = ni_children(ni, &nid, &children);
116 nis = ni_idlist2binding(ni, &children, &b->u.list);
122 nis = ni_proplist2binding(&pl, b->u.list == NULL ? &b->u.list : &b->u.list->next);
123 ni_proplist_free(&pl);
129 ni_idlist_free(idlist);
134 krb5_config_parse_file (krb5_context context,
136 krb5_config_section **res)
138 void *ni = NULL, *lastni = NULL;
144 krb5_config_section *s;
149 for (i = 0; i < 256; i++) {
151 nis = ni_open(NULL, ".", &ni);
153 if (lastni != NULL) ni_free(lastni);
155 nis = ni_open(lastni, "..", &ni);
159 nis = ni_pathsearch(ni, &nid, "/locations/kerberos");
161 nis = ni_children(ni, &nid, &children);
164 nis = ni_idlist2binding(ni, &children, &s);
169 if (ni != NULL) ni_free(ni);
170 if (ni != lastni && lastni != NULL) ni_free(lastni);
172 ret = (nis == NI_OK) ? 0 : -1;
180 #endif /* HAVE_NETINFO */