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("$Heimdal: config_file_netinfo.c 13863 2004-05-25 21:46:46Z lha $"
39 * Netinfo implementation from Luke Howard <lukeh@xedoc.com.au>
43 #include <netinfo/ni.h>
45 ni_proplist2binding(ni_proplist
*pl
, krb5_config_section
**ret
)
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"))
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
));
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
]);
78 ni_idlist2binding(void *ni
, ni_idlist
*idlist
, krb5_config_section
**ret
)
82 krb5_config_section
**next
;
84 for (i
= 0; i
< idlist
->ni_idlist_len
; i
++) {
88 krb5_config_binding
*b
;
92 nid
.nii_object
= idlist
->ni_idlist_val
[i
];
94 nis
= ni_read(ni
, &nid
, &pl
);
99 index
= ni_proplist_match(pl
, "name", NULL
);
100 b
= malloc(sizeof(*b
));
101 if (b
== NULL
) return NI_FAILED
;
109 b
->type
= krb5_config_list
;
110 b
->name
= ni_name_dup(pl
.nipl_val
[index
].nip_val
.ninl_val
[0]);
114 /* get the child directories */
115 nis
= ni_children(ni
, &nid
, &children
);
117 nis
= ni_idlist2binding(ni
, &children
, &b
->u
.list
);
123 nis
= ni_proplist2binding(&pl
, b
->u
.list
== NULL
? &b
->u
.list
: &b
->u
.list
->next
);
124 ni_proplist_free(&pl
);
130 ni_idlist_free(idlist
);
134 krb5_error_code KRB5_LIB_FUNCTION
135 krb5_config_parse_file (krb5_context context
,
137 krb5_config_section
**res
)
139 void *ni
= NULL
, *lastni
= NULL
;
145 krb5_config_section
*s
;
150 for (i
= 0; i
< 256; i
++) {
152 nis
= ni_open(NULL
, ".", &ni
);
154 if (lastni
!= NULL
) ni_free(lastni
);
156 nis
= ni_open(lastni
, "..", &ni
);
160 nis
= ni_pathsearch(ni
, &nid
, "/locations/kerberos");
162 nis
= ni_children(ni
, &nid
, &children
);
165 nis
= ni_idlist2binding(ni
, &children
, &s
);
170 if (ni
!= NULL
) ni_free(ni
);
171 if (ni
!= lastni
&& lastni
!= NULL
) ni_free(lastni
);
173 ret
= (nis
== NI_OK
) ? 0 : -1;
181 #endif /* HAVE_NETINFO */