No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / lib / krb5 / config_file_netinfo.c
blob583fff5b25955e82becbcdba6573123587db8a6f
1 /*
2 * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
31 * SUCH DAMAGE.
34 #include "krb5_locl.h"
35 __RCSID("$Heimdal: config_file_netinfo.c 13863 2004-05-25 21:46:46Z lha $"
36 "$NetBSD$");
39 * Netinfo implementation from Luke Howard <lukeh@xedoc.com.au>
42 #ifdef HAVE_NETINFO
43 #include <netinfo/ni.h>
44 static ni_status
45 ni_proplist2binding(ni_proplist *pl, krb5_config_section **ret)
47 int i, j;
48 krb5_config_section **next = NULL;
50 for (i = 0; i < pl->ni_proplist_len; i++) {
51 if (!strcmp(pl->nipl_val[i].nip_name, "name"))
52 continue;
54 for (j = 0; j < pl->nipl_val[i].nip_val.ni_namelist_len; j++) {
55 krb5_config_binding *b;
57 b = malloc(sizeof(*b));
58 if (b == NULL)
59 return NI_FAILED;
61 b->next = NULL;
62 b->type = krb5_config_string;
63 b->name = ni_name_dup(pl->nipl_val[i].nip_name);
64 b->u.string = ni_name_dup(pl->nipl_val[i].nip_val.ninl_val[j]);
66 if (next == NULL) {
67 *ret = b;
68 } else {
69 *next = b;
71 next = &b->next;
74 return NI_OK;
77 static ni_status
78 ni_idlist2binding(void *ni, ni_idlist *idlist, krb5_config_section **ret)
80 int i;
81 ni_status nis;
82 krb5_config_section **next;
84 for (i = 0; i < idlist->ni_idlist_len; i++) {
85 ni_proplist pl;
86 ni_id nid;
87 ni_idlist children;
88 krb5_config_binding *b;
89 ni_index index;
91 nid.nii_instance = 0;
92 nid.nii_object = idlist->ni_idlist_val[i];
94 nis = ni_read(ni, &nid, &pl);
96 if (nis != NI_OK) {
97 return nis;
99 index = ni_proplist_match(pl, "name", NULL);
100 b = malloc(sizeof(*b));
101 if (b == NULL) return NI_FAILED;
103 if (i == 0) {
104 *ret = b;
105 } else {
106 *next = b;
109 b->type = krb5_config_list;
110 b->name = ni_name_dup(pl.nipl_val[index].nip_val.ninl_val[0]);
111 b->next = NULL;
112 b->u.list = NULL;
114 /* get the child directories */
115 nis = ni_children(ni, &nid, &children);
116 if (nis == NI_OK) {
117 nis = ni_idlist2binding(ni, &children, &b->u.list);
118 if (nis != NI_OK) {
119 return nis;
123 nis = ni_proplist2binding(&pl, b->u.list == NULL ? &b->u.list : &b->u.list->next);
124 ni_proplist_free(&pl);
125 if (nis != NI_OK) {
126 return nis;
128 next = &b->next;
130 ni_idlist_free(idlist);
131 return NI_OK;
134 krb5_error_code KRB5_LIB_FUNCTION
135 krb5_config_parse_file (krb5_context context,
136 const char *fname,
137 krb5_config_section **res)
139 void *ni = NULL, *lastni = NULL;
140 int i;
141 ni_status nis;
142 ni_id nid;
143 ni_idlist children;
145 krb5_config_section *s;
146 int ret;
148 s = NULL;
150 for (i = 0; i < 256; i++) {
151 if (i == 0) {
152 nis = ni_open(NULL, ".", &ni);
153 } else {
154 if (lastni != NULL) ni_free(lastni);
155 lastni = ni;
156 nis = ni_open(lastni, "..", &ni);
158 if (nis != NI_OK)
159 break;
160 nis = ni_pathsearch(ni, &nid, "/locations/kerberos");
161 if (nis == NI_OK) {
162 nis = ni_children(ni, &nid, &children);
163 if (nis != NI_OK)
164 break;
165 nis = ni_idlist2binding(ni, &children, &s);
166 break;
170 if (ni != NULL) ni_free(ni);
171 if (ni != lastni && lastni != NULL) ni_free(lastni);
173 ret = (nis == NI_OK) ? 0 : -1;
174 if (ret == 0) {
175 *res = s;
176 } else {
177 *res = NULL;
179 return ret;
181 #endif /* HAVE_NETINFO */