summaryrefslogtreecommitdiff
path: root/distrib/utils/libhack
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1995-10-18 08:53:40 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1995-10-18 08:53:40 +0000
commitd6583bb2a13f329cf0332ef2570eb8bb8fc0e39c (patch)
treeece253b876159b39c620e62b6c9b1174642e070e /distrib/utils/libhack
initial import of NetBSD tree
Diffstat (limited to 'distrib/utils/libhack')
-rw-r--r--distrib/utils/libhack/Makefile19
-rw-r--r--distrib/utils/libhack/Makefile.inc25
-rw-r--r--distrib/utils/libhack/getgrent.c187
-rw-r--r--distrib/utils/libhack/gethost.c266
-rw-r--r--distrib/utils/libhack/getnetgr.c33
-rw-r--r--distrib/utils/libhack/getpwent.c171
-rw-r--r--distrib/utils/libhack/yplib.c222
7 files changed, 923 insertions, 0 deletions
diff --git a/distrib/utils/libhack/Makefile b/distrib/utils/libhack/Makefile
new file mode 100644
index 00000000000..907ee043651
--- /dev/null
+++ b/distrib/utils/libhack/Makefile
@@ -0,0 +1,19 @@
+# $NetBSD: Makefile,v 1.2 1995/10/13 18:10:19 gwr Exp $
+#
+# Stubs to kill off some things from libc:
+# This save space on a boot system.
+#
+
+LIB= hack
+SRCS= getgrent.c gethost.c getnetgr.c getpwent.c
+
+NOPIC=
+NOPROFILE=
+
+all: libhack.a
+
+tpwent: getpwent.c
+ $(CC) -g -o $@.o -DTEST_MAIN -c getpwent.c
+ $(CC) -o $@ $@.o
+
+.include <bsd.lib.mk>
diff --git a/distrib/utils/libhack/Makefile.inc b/distrib/utils/libhack/Makefile.inc
new file mode 100644
index 00000000000..586153eda55
--- /dev/null
+++ b/distrib/utils/libhack/Makefile.inc
@@ -0,0 +1,25 @@
+# $NetBSD: Makefile.inc,v 1.2 1995/10/13 18:10:20 gwr Exp $
+# Include this fragment to build libhack.o
+# It is .o and not .a to make sure these are the
+# objects you get (and not the ones in libc.a)
+
+HACKOBJS= gethost.o getpwent.o getgrent.o getnetgr.o
+
+libhack.o : $(HACKOBJS)
+ $(LD) -r -o $@ $(HACKOBJS)
+
+gethost.o : ${HACKSRC}/gethost.c
+ $(CC) -c ${HACKSRC}/gethost.c
+
+getpwent.o : ${HACKSRC}/getpwent.c
+ $(CC) -c ${HACKSRC}/getpwent.c
+
+getgrent.o : ${HACKSRC}/getgrent.c
+ $(CC) -c ${HACKSRC}/getgrent.c
+
+getnetgr.o : ${HACKSRC}/getnetgr.c
+ $(CC) -c ${HACKSRC}/getnetgr.c
+
+yplib.o : ${HACKSRC}/yplib.c
+ $(CC) -c ${HACKSRC}/yplib.c
+
diff --git a/distrib/utils/libhack/getgrent.c b/distrib/utils/libhack/getgrent.c
new file mode 100644
index 00000000000..66e65987609
--- /dev/null
+++ b/distrib/utils/libhack/getgrent.c
@@ -0,0 +1,187 @@
+/* $NetBSD: getgrent.c,v 1.2 1995/10/13 18:10:23 gwr Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * Portions Copyright (c) 1994, Jason Downs. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copied from: lib/libc/gen/getgrent.c
+ * and then gutted, leaving only /etc/group support.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grp.h>
+
+static FILE *_gr_fp;
+static struct group _gr_group;
+static int _gr_stayopen;
+static int grscan(), start_gr();
+
+#define MAXGRP 200
+static char *members[MAXGRP];
+#define MAXLINELENGTH 1024
+static char line[MAXLINELENGTH];
+
+struct group *
+getgrent()
+{
+ if (!_gr_fp && !start_gr() || !grscan(0, 0, NULL))
+ return(NULL);
+ return(&_gr_group);
+}
+
+struct group *
+getgrnam(name)
+ const char *name;
+{
+ int rval;
+
+ if (!start_gr())
+ return(NULL);
+ rval = grscan(1, 0, name);
+ if (!_gr_stayopen)
+ endgrent();
+ return(rval ? &_gr_group : NULL);
+}
+
+struct group *
+#ifdef __STDC__
+getgrgid(gid_t gid)
+#else
+getgrgid(gid)
+ gid_t gid;
+#endif
+{
+ int rval;
+
+ if (!start_gr())
+ return(NULL);
+ rval = grscan(1, gid, NULL);
+ if (!_gr_stayopen)
+ endgrent();
+ return(rval ? &_gr_group : NULL);
+}
+
+static int
+start_gr()
+{
+ if (_gr_fp) {
+ rewind(_gr_fp);
+ return(1);
+ }
+ return((_gr_fp = fopen(_PATH_GROUP, "r")) ? 1 : 0);
+}
+
+void
+setgrent()
+{
+ (void) setgroupent(0);
+}
+
+int
+setgroupent(stayopen)
+ int stayopen;
+{
+ if (!start_gr())
+ return(0);
+ _gr_stayopen = stayopen;
+ return(1);
+}
+
+void
+endgrent()
+{
+ if (_gr_fp) {
+ (void)fclose(_gr_fp);
+ _gr_fp = NULL;
+ }
+}
+
+static int
+grscan(search, gid, name)
+ register int search, gid;
+ register char *name;
+{
+ register char *cp, **m;
+ char *bp;
+
+ for (;;) {
+ if (!fgets(line, sizeof(line), _gr_fp))
+ return(0);
+ bp = line;
+ /* skip lines that are too big */
+ if (!strchr(line, '\n')) {
+ int ch;
+
+ while ((ch = getc(_gr_fp)) != '\n' && ch != EOF)
+ ;
+ continue;
+ }
+ _gr_group.gr_name = strsep(&bp, ":\n");
+ if (search && name && strcmp(_gr_group.gr_name, name))
+ continue;
+ _gr_group.gr_passwd = strsep(&bp, ":\n");
+ if (!(cp = strsep(&bp, ":\n")))
+ continue;
+ _gr_group.gr_gid = atoi(cp);
+ if (search && name == NULL && _gr_group.gr_gid != gid)
+ continue;
+ cp = NULL;
+ if (bp == NULL)
+ continue;
+ for (m = _gr_group.gr_mem = members;; bp++) {
+ if (m == &members[MAXGRP - 1])
+ break;
+ if (*bp == ',') {
+ if (cp) {
+ *bp = '\0';
+ *m++ = cp;
+ cp = NULL;
+ }
+ } else if (*bp == '\0' || *bp == '\n' || *bp == ' ') {
+ if (cp) {
+ *bp = '\0';
+ *m++ = cp;
+ }
+ break;
+ } else if (cp == NULL)
+ cp = bp;
+ }
+ *m = NULL;
+ return(1);
+ }
+ /* NOTREACHED */
+}
diff --git a/distrib/utils/libhack/gethost.c b/distrib/utils/libhack/gethost.c
new file mode 100644
index 00000000000..8a2d3649e35
--- /dev/null
+++ b/distrib/utils/libhack/gethost.c
@@ -0,0 +1,266 @@
+/* $NetBSD: gethost.c,v 1.2 1995/10/13 18:10:25 gwr Exp $ */
+
+/*-
+ * Copyright (c) 1985, 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+/*
+ * Copied from: lib/libc/net/gethostnamadr.c
+ * and then gutted, leaving only /etc/hosts support.
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+
+#define MAXALIASES 35
+#define MAXADDRS 35
+
+static char *h_addr_ptrs[MAXADDRS + 1];
+
+static struct hostent host;
+static char *host_aliases[MAXALIASES];
+static char hostbuf[BUFSIZ+1];
+static struct in_addr host_addr;
+static FILE *hostf = NULL;
+static int stayopen = 0;
+
+#if PACKETSZ > 1024
+#define MAXPACKET PACKETSZ
+#else
+#define MAXPACKET 1024
+#endif
+
+extern int h_errno;
+
+struct hostent *
+gethostbyname(name)
+ const char *name;
+{
+ register const char *cp;
+ int n, i;
+ extern struct hostent *_gethtbyname();
+
+ /*
+ * disallow names consisting only of digits/dots, unless
+ * they end in a dot.
+ */
+ if (isdigit(name[0]))
+ for (cp = name;; ++cp) {
+ if (!*cp) {
+ if (*--cp == '.')
+ break;
+ /*
+ * All-numeric, no dot at the end.
+ * Fake up a hostent as if we'd actually
+ * done a lookup.
+ */
+ if (!inet_aton(name, &host_addr)) {
+ h_errno = HOST_NOT_FOUND;
+ return((struct hostent *) NULL);
+ }
+ host.h_name = (char *)name;
+ host.h_aliases = host_aliases;
+ host_aliases[0] = NULL;
+ host.h_addrtype = AF_INET;
+ host.h_length = sizeof(u_int32_t);
+ h_addr_ptrs[0] = (char *)&host_addr;
+ h_addr_ptrs[1] = NULL;
+ host.h_addr_list = h_addr_ptrs;
+ return (&host);
+ }
+ if (!isdigit(*cp) && *cp != '.')
+ break;
+ }
+
+ /* XXX - Force host table lookup. */
+ return (_gethtbyname(name));
+}
+
+struct hostent *
+gethostbyaddr(addr, len, type)
+ const char *addr;
+ int len, type;
+{
+ int n, i;
+ char qbuf[MAXDNAME];
+ extern struct hostent *_gethtbyaddr();
+
+ if (type != AF_INET)
+ return ((struct hostent *) NULL);
+ (void)sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
+ ((unsigned)addr[3] & 0xff),
+ ((unsigned)addr[2] & 0xff),
+ ((unsigned)addr[1] & 0xff),
+ ((unsigned)addr[0] & 0xff));
+
+ /* XXX - Force host table lookup. */
+ return (_gethtbyaddr(addr, len, type));
+}
+
+void
+_sethtent(f)
+ int f;
+{
+ if (hostf == NULL)
+ hostf = fopen(_PATH_HOSTS, "r" );
+ else
+ rewind(hostf);
+ stayopen = f;
+}
+
+void
+_endhtent()
+{
+ if (hostf && !stayopen) {
+ (void) fclose(hostf);
+ hostf = NULL;
+ }
+}
+
+struct hostent *
+_gethtent()
+{
+ char *p;
+ register char *cp, **q;
+
+ if (hostf == NULL && (hostf = fopen(_PATH_HOSTS, "r" )) == NULL)
+ return (NULL);
+again:
+ if ((p = fgets(hostbuf, BUFSIZ, hostf)) == NULL)
+ return (NULL);
+ if (*p == '#')
+ goto again;
+ cp = strpbrk(p, "#\n");
+ if (cp == NULL)
+ goto again;
+ *cp = '\0';
+ cp = strpbrk(p, " \t");
+ if (cp == NULL)
+ goto again;
+ *cp++ = '\0';
+ /* THIS STUFF IS INTERNET SPECIFIC */
+ h_addr_ptrs[0] = (char *)&host_addr;
+ h_addr_ptrs[1] = NULL;
+ (void) inet_aton(p, &host_addr);
+ host.h_addr_list = h_addr_ptrs;
+ host.h_length = sizeof(u_int32_t);
+ host.h_addrtype = AF_INET;
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+ host.h_name = cp;
+ q = host.h_aliases = host_aliases;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ while (cp && *cp) {
+ if (*cp == ' ' || *cp == '\t') {
+ cp++;
+ continue;
+ }
+ if (q < &host_aliases[MAXALIASES - 1])
+ *q++ = cp;
+ cp = strpbrk(cp, " \t");
+ if (cp != NULL)
+ *cp++ = '\0';
+ }
+ *q = NULL;
+ return (&host);
+}
+
+struct hostent *
+_gethtbyname(name)
+ char *name;
+{
+ register struct hostent *p;
+ register char **cp;
+
+ _sethtent(0);
+ while (p = _gethtent()) {
+ if (strcasecmp(p->h_name, name) == 0)
+ break;
+ for (cp = p->h_aliases; *cp != 0; cp++)
+ if (strcasecmp(*cp, name) == 0)
+ goto found;
+ }
+found:
+ _endhtent();
+ if (p==NULL)
+ h_errno = HOST_NOT_FOUND;
+ return (p);
+}
+
+struct hostent *
+_gethtbyaddr(addr, len, type)
+ const char *addr;
+ int len, type;
+{
+ register struct hostent *p;
+
+ _sethtent(0);
+ while (p = _gethtent())
+ if (p->h_addrtype == type && !bcmp(p->h_addr, addr, len))
+ break;
+ _endhtent();
+ if (p==NULL)
+ h_errno = HOST_NOT_FOUND;
+ return (p);
+}
+
diff --git a/distrib/utils/libhack/getnetgr.c b/distrib/utils/libhack/getnetgr.c
new file mode 100644
index 00000000000..31a928c1e45
--- /dev/null
+++ b/distrib/utils/libhack/getnetgr.c
@@ -0,0 +1,33 @@
+/* $NetBSD: getnetgr.c,v 1.2 1995/10/13 18:10:26 gwr Exp $ */
+
+/*
+ * Just stub these out, so it looks like
+ * we are not in any any netgroups.
+ */
+
+void
+endnetgrent()
+{
+}
+
+void
+setnetgrent(ng)
+ const char *ng;
+{
+}
+
+int
+getnetgrent(host, user, domain)
+ const char **host;
+ const char **user;
+ const char **domain;
+{
+ return 0;
+}
+
+int
+innetgr(grp, host, user, domain)
+ const char *grp, *host, *user, *domain;
+{
+ return 0;
+}
diff --git a/distrib/utils/libhack/getpwent.c b/distrib/utils/libhack/getpwent.c
new file mode 100644
index 00000000000..2d730bd6abf
--- /dev/null
+++ b/distrib/utils/libhack/getpwent.c
@@ -0,0 +1,171 @@
+/* $NetBSD: getpwent.c,v 1.2 1995/10/13 18:10:27 gwr Exp $ */
+
+/*
+ * Copyright (c) 1995 Gordon W. Ross
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ * 4. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Gordon W. Ross
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Smaller replacement for: libc/gen/getpwent.c
+ * Needed by programs like: rsh, rlogin
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <pwd.h>
+
+#define PWNULL (struct passwd *)0
+#define MAXFIELD 8
+
+static char *pw_file = "/etc/passwd";
+static FILE *pw_fp;
+static char pw_line[128];
+static struct passwd pw_ent;
+
+/*
+ * Open passwd file if necessary, and
+ * get the next entry.
+ */
+struct passwd *
+getpwent()
+{
+ char *fv[MAXFIELD];
+ char *p;
+ int fc;
+
+ /* Open passwd file if not already. */
+ if (pw_fp == NULL)
+ pw_fp = fopen(pw_file, "r");
+ /* Still NULL. No passwd file? */
+ if (pw_fp == NULL)
+ return PWNULL;
+
+readnext:
+ /* Read the next line... */
+ if (fgets(pw_line, sizeof(pw_line), pw_fp) == NULL)
+ return PWNULL;
+
+ /* ...and parse it. */
+ p = pw_line;
+ fc = 0;
+ while (fc < MAXFIELD) {
+ fv[fc] = strsep(&p, ":\n");
+ if (fv[fc] == NULL)
+ break;
+ fc++;
+ }
+
+ /* Need at least 0..5 */
+ if (fc < 6)
+ goto readnext;
+ while (fc < MAXFIELD)
+ fv[fc++] = "";
+
+ /* Build the pw entry... */
+ pw_ent.pw_name = fv[0];
+ pw_ent.pw_passwd = fv[1];
+ pw_ent.pw_uid = atoi(fv[2]);
+ pw_ent.pw_gid = atoi(fv[3]);
+ pw_ent.pw_gecos = fv[4];
+ pw_ent.pw_dir = fv[5];
+ pw_ent.pw_shell = fv[6];
+
+ return (&pw_ent);
+}
+
+/* internal for setpwent() */
+int
+setpassent(stayopen)
+ int stayopen;
+{
+ if (pw_fp)
+ rewind(pw_fp);
+}
+
+/* rewind to the beginning. */
+void
+setpwent()
+{
+ (void) setpassent(0);
+}
+
+/* done with the passwd file */
+void
+endpwent()
+{
+ if (pw_fp) {
+ fclose(pw_fp);
+ pw_fp = NULL;
+ }
+}
+
+struct passwd *
+getpwnam(name)
+ const char *name;
+{
+ struct passwd *pw;
+
+ setpwent();
+ while ((pw = getpwent()) != PWNULL)
+ if (!strcmp(pw->pw_name, name))
+ break;
+
+ endpwent();
+ return(pw);
+}
+
+struct passwd *
+getpwuid(uid)
+ uid_t uid;
+{
+ struct passwd *pw;
+
+ setpwent();
+ while ((pw = getpwent()) != PWNULL)
+ if (pw->pw_uid == uid)
+ break;
+
+ endpwent();
+ return(pw);
+}
+
+#ifdef TEST_MAIN
+main() {
+ struct passwd *pw;
+
+ printf("#name, password, uid, gid, comment, dir, shell\n");
+
+ while ((pw = getpwent()) != NULL) {
+ printf("%s:%s:", pw->pw_name, pw->pw_passwd);
+ printf("%d:%d:", pw->pw_uid, pw->pw_gid);
+ printf("%s:", pw->pw_gecos);
+ printf("%s:", pw->pw_dir);
+ printf("%s\n", pw->pw_shell);
+ }
+}
+#endif
diff --git a/distrib/utils/libhack/yplib.c b/distrib/utils/libhack/yplib.c
new file mode 100644
index 00000000000..4b787e056a9
--- /dev/null
+++ b/distrib/utils/libhack/yplib.c
@@ -0,0 +1,222 @@
+/* $NetBSD: yplib.c,v 1.1.1.1 1995/10/08 23:08:48 gwr Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Theo de Raadt.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * This file provides "stubs" for all the YP library functions.
+ * It is not needed unless you pull in things that call YP, and
+ * if you use all the get* files here then the YP stuff should
+ * not get dragged in. But if it does, one can use this.
+ *
+ * This was copied from:
+ * lib/libc/yp/yplib.c
+ * (and then completely gutted! 8^)
+ */
+
+#include <sys/types.h>
+
+/* #include <rpcsvc/yp_prot.h> */
+#define YP_TRUE ((long)1) /* general purpose success code */
+#define YP_FALSE ((long)0) /* general purpose failure code */
+
+/* #include <rpcsvc/ypclnt.h> */
+#define YPERR_DOMAIN 3 /* can't bind to a server for domain */
+#define YPERR_YPERR 6 /* some internal YP server or client error */
+#define YPERR_YPBIND 10 /* can't communicate with ypbind */
+#define YPERR_NODOM 12 /* local domain name not set */
+
+#ifndef NULL
+#define NULL (void*)0
+#endif
+
+
+static char _yp_domain[256];
+
+int
+_yp_dobind(dom, ypdb)
+ const char *dom;
+ void **ypdb;
+{
+ return YPERR_YPBIND;
+}
+
+int
+yp_bind(dom)
+ const char *dom;
+{
+ return _yp_dobind(dom, NULL);
+}
+
+void
+yp_unbind(dom)
+ const char *dom;
+{
+}
+
+int
+yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen)
+ const char *indomain;
+ const char *inmap;
+ const char *inkey;
+ int inkeylen;
+ char **outval;
+ int *outvallen;
+{
+ *outval = NULL;
+ *outvallen = 0;
+
+ return YPERR_DOMAIN;
+}
+
+int
+yp_get_default_domain(domp)
+ char **domp;
+{
+ *domp = NULL;
+ if (_yp_domain[0] == '\0')
+ if (getdomainname(_yp_domain, sizeof(_yp_domain)))
+ return YPERR_NODOM;
+ *domp = _yp_domain;
+ return 0;
+}
+
+int
+yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen)
+ const char *indomain;
+ const char *inmap;
+ char **outkey;
+ int *outkeylen;
+ char **outval;
+ int *outvallen;
+{
+
+ *outkey = *outval = NULL;
+ *outkeylen = *outvallen = 0;
+
+ return YPERR_DOMAIN;
+}
+
+int
+yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen)
+ const char *indomain;
+ const char *inmap;
+ const char *inkey;
+ int inkeylen;
+ char **outkey;
+ int *outkeylen;
+ char **outval;
+ int *outvallen;
+{
+ *outkey = *outval = NULL;
+ *outkeylen = *outvallen = 0;
+
+ return YPERR_DOMAIN;
+}
+
+int
+yp_all(indomain, inmap, incallback)
+ const char *indomain;
+ const char *inmap;
+ void *incallback;
+{
+ return YPERR_DOMAIN;
+}
+
+int
+yp_order(indomain, inmap, outorder)
+ const char *indomain;
+ const char *inmap;
+ int *outorder;
+{
+ return YPERR_DOMAIN;
+}
+
+int
+yp_master(indomain, inmap, outname)
+ const char *indomain;
+ const char *inmap;
+ char **outname;
+{
+ return YPERR_DOMAIN;
+}
+
+int
+yp_maplist(indomain, outmaplist)
+ const char *indomain;
+ struct ypmaplist **outmaplist;
+{
+ return YPERR_DOMAIN;
+}
+
+char *
+yperr_string(incode)
+ int incode;
+{
+ static char err[80];
+
+ if (incode == 0)
+ return "Success";
+
+ sprintf(err, "YP FAKE error %d\n", incode);
+ return err;
+}
+
+int
+ypprot_err(incode)
+ unsigned int incode;
+{
+ switch (incode) {
+ case YP_TRUE: /* success */
+ return 0;
+ case YP_FALSE: /* failure */
+ return YPERR_YPBIND;
+ }
+ return YPERR_YPERR;
+}
+
+int
+_yp_check(dom)
+ char **dom;
+{
+ char *unused;
+
+ if (_yp_domain[0] == '\0')
+ if (yp_get_default_domain(&unused))
+ return 0;
+
+ if (dom)
+ *dom = _yp_domain;
+
+ if (yp_bind(_yp_domain) == 0)
+ return 1;
+ return 0;
+}