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 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
23*0Sstevel@tonic-gate * Use is subject to license terms.
24*0Sstevel@tonic-gate */
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate #include <stdio.h>
29*0Sstevel@tonic-gate #include <string.h>
30*0Sstevel@tonic-gate #include <ctype.h>
31*0Sstevel@tonic-gate #include <sys/types.h>
32*0Sstevel@tonic-gate #include <nss_dbdefs.h>
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate static int str2bootent(const char *, int, void *, char *, int);
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate static DEFINE_NSS_DB_ROOT(db_root);
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate static void
_nss_initf_bootparams(nss_db_params_t * p)39*0Sstevel@tonic-gate _nss_initf_bootparams(nss_db_params_t *p)
40*0Sstevel@tonic-gate {
41*0Sstevel@tonic-gate p->name = NSS_DBNAM_BOOTPARAMS;
42*0Sstevel@tonic-gate p->default_config = NSS_DEFCONF_BOOTPARAMS;
43*0Sstevel@tonic-gate }
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gate int
bootparams_getbyname(char * name,char * linebuf,int linelen)46*0Sstevel@tonic-gate bootparams_getbyname(
47*0Sstevel@tonic-gate char *name, /* lookup key */
48*0Sstevel@tonic-gate char *linebuf, /* buffer to put the answer in */
49*0Sstevel@tonic-gate int linelen /* max # of bytes to put into linebuf */
50*0Sstevel@tonic-gate )
51*0Sstevel@tonic-gate {
52*0Sstevel@tonic-gate nss_XbyY_args_t arg;
53*0Sstevel@tonic-gate nss_status_t res;
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate NSS_XbyY_INIT(&arg, linebuf, linebuf, linelen, str2bootent);
56*0Sstevel@tonic-gate arg.key.name = name;
57*0Sstevel@tonic-gate res = nss_search(&db_root, _nss_initf_bootparams,
58*0Sstevel@tonic-gate NSS_DBOP_BOOTPARAMS_BYNAME, &arg);
59*0Sstevel@tonic-gate (void) NSS_XbyY_FINI(&arg);
60*0Sstevel@tonic-gate return (arg.status = res);
61*0Sstevel@tonic-gate }
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate /*
64*0Sstevel@tonic-gate * Return values: 0 = success, 1 = parse error, 2 = erange ...
65*0Sstevel@tonic-gate * The structure pointer passed in is a buffer in the caller's space.
66*0Sstevel@tonic-gate * instring and buffer should be separate areas.
67*0Sstevel@tonic-gate * The calling routine does all the real parsing; we just check limits and
68*0Sstevel@tonic-gate * store the entry in the buffer we were passed by the caller.
69*0Sstevel@tonic-gate * NOTE: we expect the data we're passed (in instr) has had the host's name
70*0Sstevel@tonic-gate * stripped off the begining.
71*0Sstevel@tonic-gate */
72*0Sstevel@tonic-gate /* ARGSUSED */
73*0Sstevel@tonic-gate static int
str2bootent(const char * instr,int lenstr,void * ent,char * buffer,int buflen)74*0Sstevel@tonic-gate str2bootent(
75*0Sstevel@tonic-gate const char *instr,
76*0Sstevel@tonic-gate int lenstr,
77*0Sstevel@tonic-gate void *ent, /* really (char *) */
78*0Sstevel@tonic-gate char *buffer,
79*0Sstevel@tonic-gate int buflen
80*0Sstevel@tonic-gate )
81*0Sstevel@tonic-gate {
82*0Sstevel@tonic-gate const char *p, *limit;
83*0Sstevel@tonic-gate
84*0Sstevel@tonic-gate if ((instr >= buffer && (buffer + buflen) > instr) ||
85*0Sstevel@tonic-gate (buffer >= instr && (instr + lenstr) > buffer)) {
86*0Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE);
87*0Sstevel@tonic-gate }
88*0Sstevel@tonic-gate p = instr;
89*0Sstevel@tonic-gate limit = p + lenstr;
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate /* Skip over leading whitespace */
92*0Sstevel@tonic-gate while (p < limit && isspace(*p)) {
93*0Sstevel@tonic-gate p++;
94*0Sstevel@tonic-gate }
95*0Sstevel@tonic-gate if (p >= limit) {
96*0Sstevel@tonic-gate /* Syntax error -- no data! */
97*0Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE);
98*0Sstevel@tonic-gate }
99*0Sstevel@tonic-gate lenstr -= (p - instr);
100*0Sstevel@tonic-gate if (buflen <= lenstr) { /* not enough buffer */
101*0Sstevel@tonic-gate return (NSS_STR_PARSE_ERANGE);
102*0Sstevel@tonic-gate }
103*0Sstevel@tonic-gate (void) memcpy(buffer, p, lenstr);
104*0Sstevel@tonic-gate buffer[lenstr] = '\0';
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS);
107*0Sstevel@tonic-gate }
108