2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1992, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A *
2N/A * files/bootparams_getbyname.c -- "files" backend for
2N/A * nsswitch "bootparams" database.
2N/A */
2N/A
2N/Astatic const char *bootparams = "/etc/bootparams";
2N/A
2N/A#include "files_common.h"
2N/A#include <stdlib.h>
2N/A#include <ctype.h>
2N/A#include <strings.h>
2N/A
2N/Astatic nss_status_t _nss_files_XY_bootparams(files_backend_ptr_t,
2N/A nss_XbyY_args_t *, const char *);
2N/A
2N/Astatic nss_status_t
2N/Agetbyname(be, a)
2N/A files_backend_ptr_t be;
2N/A void *a;
2N/A{
2N/A nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
2N/A nss_status_t res;
2N/A
2N/A /* bootparams_getbyname() has not set/endent; rewind on each call */
2N/A if ((res = _nss_files_setent(be, 0)) != NSS_SUCCESS) {
2N/A return (res);
2N/A }
2N/A return (_nss_files_XY_bootparams(be, argp, argp->key.name));
2N/A}
2N/A
2N/Astatic files_backend_op_t bootparams_ops[] = {
2N/A _nss_files_destr,
2N/A getbyname
2N/A};
2N/A
2N/A/*ARGSUSED*/
2N/Anss_backend_t *
2N/A_nss_files_bootparams_constr(dummy1, dummy2, dummy3)
2N/A const char *dummy1, *dummy2, *dummy3;
2N/A{
2N/A return (_nss_files_constr(bootparams_ops,
2N/A sizeof (bootparams_ops) / sizeof (bootparams_ops[0]),
2N/A bootparams,
2N/A NSS_LINELEN_BOOTPARAMS,
2N/A NULL, 0));
2N/A}
2N/A
2N/A/*
2N/A * bootparams has the hostname as part of the data in the file, but the other
2N/A * backends don't include it in the data passed to the backend. For this
2N/A * reason, we process everything here and don't bother calling the backend.
2N/A */
2N/A/*ARGSUSED*/
2N/Astatic nss_status_t
2N/A_nss_files_XY_bootparams(be, args, filter)
2N/A files_backend_ptr_t be;
2N/A nss_XbyY_args_t *args;
2N/A const char *filter;
2N/A /*
2N/A * filter not useful here since the key
2N/A * we are looking for is the first "word"
2N/A * on the line and we can be fast enough.
2N/A */
2N/A{
2N/A nss_status_t res;
2N/A
2N/A if (be->buf == 0 &&
2N/A (be->buf = (char *)malloc(be->minbuf)) == 0) {
2N/A (void) _nss_files_endent(be, 0);
2N/A return (NSS_UNAVAIL); /* really panic, malloc failed */
2N/A }
2N/A
2N/A res = NSS_NOTFOUND;
2N/A
2N/A /*CONSTCOND*/
2N/A while (1) {
2N/A char *instr = be->buf;
2N/A char *p, *host, *limit;
2N/A int linelen;
2N/A
2N/A /*
2N/A * _nss_files_read_line does process the '\' that are used
2N/A * in /etc/bootparams for continuation and gives one long
2N/A * buffer.
2N/A *
2N/A * linelen counts the characters up to but excluding the '\n'
2N/A */
2N/A if ((linelen = _nss_files_read_line(be, instr,
2N/A be->minbuf)) < 0) {
2N/A /* End of file */
2N/A args->returnval = 0;
2N/A args->returnlen = 0;
2N/A break;
2N/A }
2N/A
2N/A /*
2N/A * we need to strip off the host name before returning it.
2N/A */
2N/A p = instr;
2N/A limit = p + linelen;
2N/A
2N/A /* Skip over leading whitespace */
2N/A while (p < limit && isspace(*p)) {
2N/A p++;
2N/A }
2N/A host = p;
2N/A
2N/A /* Skip over the hostname */
2N/A while (p < limit && !isspace(*p)) {
2N/A p++;
2N/A }
2N/A *p++ = '\0';
2N/A
2N/A if (strcasecmp(args->key.name, host) != 0) {
2N/A continue;
2N/A }
2N/A
2N/A /* Skip over whitespace between name and first datum */
2N/A while (p < limit && isspace(*p)) {
2N/A p++;
2N/A }
2N/A if (p >= limit) {
2N/A /* Syntax error -- no data! Just skip it. */
2N/A continue;
2N/A }
2N/A
2N/A linelen -= (p - instr);
2N/A if (args->buf.buflen <= linelen) { /* not enough buffer */
2N/A args->erange = 1;
2N/A break;
2N/A }
2N/A (void) memcpy(args->buf.buffer, p, linelen);
2N/A args->buf.buffer[linelen] = '\0';
2N/A args->returnval = args->buf.result;
2N/A args->returnlen = linelen;
2N/A res = NSS_SUCCESS;
2N/A break;
2N/A }
2N/A (void) _nss_files_endent(be, 0);
2N/A return (res);
2N/A}