181cb6ddcSMark Murray /*-
281cb6ddcSMark Murray * Copyright (c) 1991, 1993
381cb6ddcSMark Murray * The Regents of the University of California. All rights reserved.
481cb6ddcSMark Murray *
581cb6ddcSMark Murray * Redistribution and use in source and binary forms, with or without
681cb6ddcSMark Murray * modification, are permitted provided that the following conditions
781cb6ddcSMark Murray * are met:
881cb6ddcSMark Murray * 1. Redistributions of source code must retain the above copyright
981cb6ddcSMark Murray * notice, this list of conditions and the following disclaimer.
1081cb6ddcSMark Murray * 2. Redistributions in binary form must reproduce the above copyright
1181cb6ddcSMark Murray * notice, this list of conditions and the following disclaimer in the
1281cb6ddcSMark Murray * documentation and/or other materials provided with the distribution.
13*83129c0bSEd Maste * 3. Neither the name of the University nor the names of its contributors
1481cb6ddcSMark Murray * may be used to endorse or promote products derived from this software
1581cb6ddcSMark Murray * without specific prior written permission.
1681cb6ddcSMark Murray *
1781cb6ddcSMark Murray * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1881cb6ddcSMark Murray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1981cb6ddcSMark Murray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2081cb6ddcSMark Murray * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2181cb6ddcSMark Murray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2281cb6ddcSMark Murray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2381cb6ddcSMark Murray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2481cb6ddcSMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2581cb6ddcSMark Murray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2681cb6ddcSMark Murray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2781cb6ddcSMark Murray * SUCH DAMAGE.
2881cb6ddcSMark Murray */
2981cb6ddcSMark Murray
3081cb6ddcSMark Murray #ifndef lint
31ecece7e3SPeter Wemm #if 0
3281cb6ddcSMark Murray static char sccsid[] = "@(#)getent.c 8.2 (Berkeley) 12/15/93";
33ecece7e3SPeter Wemm #endif
3481cb6ddcSMark Murray #endif /* not lint */
3581cb6ddcSMark Murray
3621f083c0SMark Murray #include <stdlib.h>
378fa113e5SMark Murray #include <string.h>
388fa113e5SMark Murray
398fa113e5SMark Murray #include "misc-proto.h"
4021f083c0SMark Murray
4181cb6ddcSMark Murray static char *area;
428fa113e5SMark Murray static char gettytab[] = "/etc/gettytab";
4381cb6ddcSMark Murray
4481cb6ddcSMark Murray /*ARGSUSED*/
4521f083c0SMark Murray int
getent(char * cp __unused,const char * name)468fa113e5SMark Murray getent(char *cp __unused, const char *name)
4781cb6ddcSMark Murray {
488fa113e5SMark Murray int retval;
498fa113e5SMark Murray char *tempnam, *dba[2] = { gettytab, NULL };
5081cb6ddcSMark Murray
518fa113e5SMark Murray tempnam = strdup(name);
528fa113e5SMark Murray retval = cgetent(&area, dba, tempnam) == 0 ? 1 : 0;
538fa113e5SMark Murray free(tempnam);
548fa113e5SMark Murray return(retval);
5581cb6ddcSMark Murray }
5681cb6ddcSMark Murray
5781cb6ddcSMark Murray /*ARGSUSED*/
5881cb6ddcSMark Murray char *
Getstr(const char * id,char ** cpp __unused)598fa113e5SMark Murray Getstr(const char *id, char **cpp __unused)
6081cb6ddcSMark Murray {
618fa113e5SMark Murray int retval;
628fa113e5SMark Murray char *answer, *tempid;
638fa113e5SMark Murray
648fa113e5SMark Murray tempid = strdup(id);
658fa113e5SMark Murray retval = cgetstr(area, tempid, &answer);
668fa113e5SMark Murray free(tempid);
678fa113e5SMark Murray return((retval > 0) ? answer : NULL);
6881cb6ddcSMark Murray }
69