1*7348b5c5SDavid van Moolenbroek /* $NetBSD: getent.c,v 1.11 2012/03/21 05:33:27 matt Exp $ */
2*7348b5c5SDavid van Moolenbroek
3*7348b5c5SDavid van Moolenbroek /*-
4*7348b5c5SDavid van Moolenbroek * Copyright (c) 1991, 1993
5*7348b5c5SDavid van Moolenbroek * The Regents of the University of California. All rights reserved.
6*7348b5c5SDavid van Moolenbroek *
7*7348b5c5SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
8*7348b5c5SDavid van Moolenbroek * modification, are permitted provided that the following conditions
9*7348b5c5SDavid van Moolenbroek * are met:
10*7348b5c5SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
11*7348b5c5SDavid van Moolenbroek * notice, this list of conditions and the following disclaimer.
12*7348b5c5SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce the above copyright
13*7348b5c5SDavid van Moolenbroek * notice, this list of conditions and the following disclaimer in the
14*7348b5c5SDavid van Moolenbroek * documentation and/or other materials provided with the distribution.
15*7348b5c5SDavid van Moolenbroek * 3. Neither the name of the University nor the names of its contributors
16*7348b5c5SDavid van Moolenbroek * may be used to endorse or promote products derived from this software
17*7348b5c5SDavid van Moolenbroek * without specific prior written permission.
18*7348b5c5SDavid van Moolenbroek *
19*7348b5c5SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*7348b5c5SDavid van Moolenbroek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*7348b5c5SDavid van Moolenbroek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*7348b5c5SDavid van Moolenbroek * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*7348b5c5SDavid van Moolenbroek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*7348b5c5SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*7348b5c5SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*7348b5c5SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*7348b5c5SDavid van Moolenbroek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*7348b5c5SDavid van Moolenbroek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*7348b5c5SDavid van Moolenbroek * SUCH DAMAGE.
30*7348b5c5SDavid van Moolenbroek */
31*7348b5c5SDavid van Moolenbroek
32*7348b5c5SDavid van Moolenbroek #include <sys/cdefs.h>
33*7348b5c5SDavid van Moolenbroek #ifndef lint
34*7348b5c5SDavid van Moolenbroek #if 0
35*7348b5c5SDavid van Moolenbroek static char sccsid[] = "@(#)getent.c 8.2 (Berkeley) 12/15/93";
36*7348b5c5SDavid van Moolenbroek #else
37*7348b5c5SDavid van Moolenbroek __RCSID("$NetBSD: getent.c,v 1.11 2012/03/21 05:33:27 matt Exp $");
38*7348b5c5SDavid van Moolenbroek #endif
39*7348b5c5SDavid van Moolenbroek #endif /* not lint */
40*7348b5c5SDavid van Moolenbroek
41*7348b5c5SDavid van Moolenbroek #include <stdlib.h>
42*7348b5c5SDavid van Moolenbroek #include "misc-proto.h"
43*7348b5c5SDavid van Moolenbroek
44*7348b5c5SDavid van Moolenbroek static char *area;
45*7348b5c5SDavid van Moolenbroek
46*7348b5c5SDavid van Moolenbroek int getent(char *, char *);
47*7348b5c5SDavid van Moolenbroek char *getstr(char *, char **);
48*7348b5c5SDavid van Moolenbroek
49*7348b5c5SDavid van Moolenbroek /*ARGSUSED*/
50*7348b5c5SDavid van Moolenbroek int
getent(char * cp,char * name)51*7348b5c5SDavid van Moolenbroek getent(char *cp, char *name)
52*7348b5c5SDavid van Moolenbroek {
53*7348b5c5SDavid van Moolenbroek #ifdef HAS_CGETENT
54*7348b5c5SDavid van Moolenbroek const char *dba[2];
55*7348b5c5SDavid van Moolenbroek
56*7348b5c5SDavid van Moolenbroek dba[0] = "/etc/gettytab";
57*7348b5c5SDavid van Moolenbroek dba[1] = 0;
58*7348b5c5SDavid van Moolenbroek return((cgetent(&area, dba, name) == 0) ? 1 : 0);
59*7348b5c5SDavid van Moolenbroek #else
60*7348b5c5SDavid van Moolenbroek return(0);
61*7348b5c5SDavid van Moolenbroek #endif
62*7348b5c5SDavid van Moolenbroek }
63*7348b5c5SDavid van Moolenbroek
64*7348b5c5SDavid van Moolenbroek #ifndef SOLARIS
65*7348b5c5SDavid van Moolenbroek /*ARGSUSED*/
66*7348b5c5SDavid van Moolenbroek char *
getstr(char * id,char ** cpp)67*7348b5c5SDavid van Moolenbroek getstr(char *id, char **cpp)
68*7348b5c5SDavid van Moolenbroek {
69*7348b5c5SDavid van Moolenbroek # ifdef HAS_CGETENT
70*7348b5c5SDavid van Moolenbroek char *answer;
71*7348b5c5SDavid van Moolenbroek return((cgetstr(area, id, &answer) > 0) ? answer : 0);
72*7348b5c5SDavid van Moolenbroek # else
73*7348b5c5SDavid van Moolenbroek return(0);
74*7348b5c5SDavid van Moolenbroek # endif
75*7348b5c5SDavid van Moolenbroek }
76*7348b5c5SDavid van Moolenbroek #endif
77