129088Smarkm/*- 229088Smarkm * Copyright (c) 1991, 1993 329088Smarkm * The Regents of the University of California. All rights reserved. 429088Smarkm * 529088Smarkm * Redistribution and use in source and binary forms, with or without 629088Smarkm * modification, are permitted provided that the following conditions 729088Smarkm * are met: 829088Smarkm * 1. Redistributions of source code must retain the above copyright 929088Smarkm * notice, this list of conditions and the following disclaimer. 1029088Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1129088Smarkm * notice, this list of conditions and the following disclaimer in the 1229088Smarkm * documentation and/or other materials provided with the distribution. 13351432Semaste * 3. Neither the name of the University nor the names of its contributors 1429088Smarkm * may be used to endorse or promote products derived from this software 1529088Smarkm * without specific prior written permission. 1629088Smarkm * 1729088Smarkm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1829088Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1929088Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2029088Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2129088Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2229088Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2329088Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2429088Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2529088Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2629088Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2729088Smarkm * SUCH DAMAGE. 2829088Smarkm */ 2929088Smarkm 3084305Smarkm#include <sys/cdefs.h> 3187139Smarkm 3284305Smarkm__FBSDID("$FreeBSD: stable/11/contrib/telnet/libtelnet/getent.c 351432 2019-08-23 17:40:47Z emaste $"); 3384305Smarkm 3429088Smarkm#ifndef lint 3563248Speter#if 0 3629088Smarkmstatic char sccsid[] = "@(#)getent.c 8.2 (Berkeley) 12/15/93"; 3763248Speter#endif 3829088Smarkm#endif /* not lint */ 3929088Smarkm 4081965Smarkm#include <stdlib.h> 4187139Smarkm#include <string.h> 4281965Smarkm 4387139Smarkm#include "misc-proto.h" 4487139Smarkm 4529088Smarkmstatic char *area; 4687139Smarkmstatic char gettytab[] = "/etc/gettytab"; 4729088Smarkm 4829088Smarkm/*ARGSUSED*/ 4981965Smarkmint 5087139Smarkmgetent(char *cp __unused, const char *name) 5129088Smarkm{ 5287139Smarkm int retval; 5387139Smarkm char *tempnam, *dba[2] = { gettytab, NULL }; 5429088Smarkm 5587139Smarkm tempnam = strdup(name); 5687139Smarkm retval = cgetent(&area, dba, tempnam) == 0 ? 1 : 0; 5787139Smarkm free(tempnam); 5887139Smarkm return(retval); 5929088Smarkm} 6029088Smarkm 6129088Smarkm/*ARGSUSED*/ 6229088Smarkmchar * 6387139SmarkmGetstr(const char *id, char **cpp __unused) 6429088Smarkm{ 6587139Smarkm int retval; 6687139Smarkm char *answer, *tempid; 6787139Smarkm 6887139Smarkm tempid = strdup(id); 6987139Smarkm retval = cgetstr(area, tempid, &answer); 7087139Smarkm free(tempid); 7187139Smarkm return((retval > 0) ? answer : NULL); 7229088Smarkm} 73