4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * files/bootparams_getbyname.c -- "files" backend for
26 * nsswitch "bootparams" database.
29 #pragma ident "%Z%%M% %I% %E% SMI"
31 static const char *bootparams
= "/etc/bootparams";
33 #include "files_common.h"
38 static nss_status_t
_nss_files_XY_bootparams(files_backend_ptr_t
,
39 nss_XbyY_args_t
*, const char *);
43 files_backend_ptr_t be
;
46 nss_XbyY_args_t
*argp
= (nss_XbyY_args_t
*)a
;
49 /* bootparams_getbyname() has not set/endent; rewind on each call */
50 if ((res
= _nss_files_setent(be
, 0)) != NSS_SUCCESS
) {
53 return (_nss_files_XY_bootparams(be
, argp
, argp
->key
.name
));
56 static files_backend_op_t bootparams_ops
[] = {
63 _nss_files_bootparams_constr(dummy1
, dummy2
, dummy3
)
64 const char *dummy1
, *dummy2
, *dummy3
;
66 return (_nss_files_constr(bootparams_ops
,
67 sizeof (bootparams_ops
) / sizeof (bootparams_ops
[0]),
69 NSS_LINELEN_BOOTPARAMS
,
74 * bootparams has the hostname as part of the data in the file, but the other
75 * backends don't include it in the data passed to the backend. For this
76 * reason, we process everything here and don't bother calling the backend.
80 _nss_files_XY_bootparams(be
, args
, filter
)
81 files_backend_ptr_t be
;
82 nss_XbyY_args_t
*args
;
85 * filter not useful here since the key
86 * we are looking for is the first "word"
87 * on the line and we can be fast enough.
93 (be
->buf
= (char *)malloc(be
->minbuf
)) == 0) {
94 (void) _nss_files_endent(be
, 0);
95 return (NSS_UNAVAIL
); /* really panic, malloc failed */
102 char *instr
= be
->buf
;
103 char *p
, *host
, *limit
;
107 * _nss_files_read_line does process the '\' that are used
108 * in /etc/bootparams for continuation and gives one long
111 * linelen counts the characters up to but excluding the '\n'
113 if ((linelen
= _nss_files_read_line(be
->f
, instr
,
122 * we need to strip off the host name before returning it.
127 /* Skip over leading whitespace */
128 while (p
< limit
&& isspace(*p
)) {
133 /* Skip over the hostname */
134 while (p
< limit
&& !isspace(*p
)) {
139 if (strcasecmp(args
->key
.name
, host
) != 0) {
143 /* Skip over whitespace between name and first datum */
144 while (p
< limit
&& isspace(*p
)) {
148 /* Syntax error -- no data! Just skip it. */
152 linelen
-= (p
- instr
);
153 if (args
->buf
.buflen
<= linelen
) { /* not enough buffer */
157 (void) memcpy(args
->buf
.buffer
, p
, linelen
);
158 args
->buf
.buffer
[linelen
] = '\0';
159 args
->returnval
= args
->buf
.result
;
160 args
->returnlen
= linelen
;
164 (void) _nss_files_endent(be
, 0);