Add some utilities all ports might use in a ramdisk root.
This commit is contained in:
parent
3f7621c16a
commit
f75c79d821
|
@ -0,0 +1,5 @@
|
|||
# $NetBSD: Makefile,v 1.1.1.1 1995/10/08 23:08:46 gwr Exp $
|
||||
|
||||
SUBDIR= dd ftp init libpw rsh ssh tftp tls
|
||||
|
||||
.include <bsd.subdir.mk>
|
|
@ -0,0 +1,8 @@
|
|||
# $NetBSD: Makefile.inc,v 1.1.1.1 1995/10/08 23:08:46 gwr Exp $
|
||||
# utils one might want in a crunched binary
|
||||
|
||||
LDSTATIC= -static
|
||||
|
||||
install:
|
||||
@echo "install not expected"
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
From: "Gordon W. Ross" <gwr>
|
||||
Date: Tue, 3 Oct 95 16:37:39 EDT
|
||||
Subject: New ramdisk, tiny shell, etc.
|
||||
[ edited since the original mail ]
|
||||
|
||||
As part of my efforts to build a RAM-disk root kernel for the
|
||||
sun3 port, I've developed some things that others may want:
|
||||
(Also, please see my questions at the end.)
|
||||
|
||||
New RAM-disk: [ see sys/dev/ramdisk.c ]
|
||||
|
||||
New "small/tiny" tools, to replace some of the larger
|
||||
programs that one usually wants on a ramdisk root:
|
||||
|
||||
ssh: (small shell)
|
||||
* Consumes only about 8K of memory on an m68k!
|
||||
(saves about 100K in the ramdisk...)
|
||||
* Can run programs, possibly with I/O redirection
|
||||
* Just enough to let you run the programs needed
|
||||
while partitioning and copying miniroot to swap.
|
||||
|
||||
tls: (tiny ls)
|
||||
* Consumes only about 4K of memory on an m68k!
|
||||
(saves about 10K in the ramdisk...)
|
||||
* Long format only, nothing fancy.
|
||||
|
||||
Also, in the new "src/distrib/utils" area, I've made build
|
||||
directories for some programs that build smaller versions,
|
||||
usually by adding special CFLAGS
|
||||
|
||||
init_s: (built with -DLETS_GET_SMALL)
|
||||
* Forces single-user mode
|
||||
* Eliminates unnecessary code
|
||||
|
||||
libhack: small implementation of some libc functions
|
||||
* Needs only /etc/passwd (not pwd.db, spwd.db)
|
||||
* Reduces size of an m68k crunched binary about 64K
|
||||
|
||||
x_dd: built with -DNO_CONV (no conv=* options)
|
||||
|
||||
x_ifconfig: supports inet only
|
||||
|
||||
The x_ prefix on the above is to make the names unique so
|
||||
crunchgen will not confuse them with the real sources.
|
|
@ -0,0 +1,18 @@
|
|||
# $NetBSD: Makefile,v 1.1.1.1 1995/10/08 23:08:47 gwr Exp $
|
||||
# Build a "small init" (i.e. for boot media)
|
||||
|
||||
PROG= init
|
||||
NOMAN=
|
||||
|
||||
# Need -lutil for: logout, logwtmp, login_tty
|
||||
DPADD= ${LIBUTIL}
|
||||
LDADD= -lutil
|
||||
|
||||
SRCDIR=/usr/src/sbin/init
|
||||
CFLAGS+= -DLETS_GET_SMALL -I${SRCDIR}
|
||||
|
||||
.PATH: ${SRCDIR}
|
||||
|
||||
all: ${PROG}
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -0,0 +1,15 @@
|
|||
# $NetBSD: Makefile,v 1.1.1.1 1995/10/08 23:08:48 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
|
||||
|
||||
.include <bsd.lib.mk>
|
|
@ -0,0 +1,21 @@
|
|||
# $NetBSD: Makefile.inc,v 1.1.1.1 1995/10/08 23:08:48 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
|
|
@ -0,0 +1,185 @@
|
|||
/* $NetBSD: getgrent.c,v 1.1.1.1 1995/10/08 23:08:48 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.
|
||||
*/
|
||||
|
||||
|
||||
#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 */
|
||||
}
|
|
@ -0,0 +1,269 @@
|
|||
/* $NetBSD: gethost.c,v 1.1.1.1 1995/10/08 23:08:48 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--
|
||||
*/
|
||||
|
||||
|
||||
#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();
|
||||
register struct hostent *hp;
|
||||
char lookups[MAXDNSLUS];
|
||||
|
||||
/*
|
||||
* 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;
|
||||
register struct hostent *hp;
|
||||
char qbuf[MAXDNAME];
|
||||
extern struct hostent *_gethtbyaddr();
|
||||
char lookups[MAXDNSLUS];
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/* $NetBSD: getnetgr.c,v 1.1.1.1 1995/10/08 23:08:48 gwr Exp $ */
|
||||
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
/* $NetBSD: getpwent.c,v 1.1.1.1 1995/10/08 23:08:48 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()
|
||||
{
|
||||
register char *p;
|
||||
char *fv[MAXFIELD];
|
||||
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;
|
||||
|
||||
/* Read the next line... */
|
||||
readnext:
|
||||
if (fgets(pw_line, sizeof(pw_line), pw_fp) == NULL)
|
||||
return PWNULL;
|
||||
|
||||
/* ...and parse it. */
|
||||
p = pw_line;
|
||||
fc = 0;
|
||||
while (fc < MAXFIELD) {
|
||||
/* end of line? */
|
||||
if (*p == '\n') {
|
||||
*p = '\0';
|
||||
break;
|
||||
}
|
||||
if (*p == '\0')
|
||||
break;
|
||||
/* save start of field */
|
||||
fv[fc++] = p;
|
||||
/* find end of field */
|
||||
while (*p) {
|
||||
if (*p == '\n') {
|
||||
*p = '\0';
|
||||
goto eol;
|
||||
}
|
||||
if (*p == ':') {
|
||||
*p++ = '\0';
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
eol:
|
||||
|
||||
/* Need at least 0..5 */
|
||||
if (fc < 6)
|
||||
goto readnext;
|
||||
while (fc < MAXFIELD)
|
||||
fv[fc++] = "";
|
||||
|
||||
/* Build the pw entrt... */
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
# $NetBSD: Makefile,v 1.1.1.1 1995/10/08 23:08:46 gwr Exp $
|
||||
# Small Shell (i.e. for boot media)
|
||||
|
||||
PROG= ssh
|
||||
NOMAN=
|
||||
|
||||
all: ${PROG}
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -0,0 +1,608 @@
|
|||
/* $NetBSD: ssh.c,v 1.1.1.1 1995/10/08 23:08:46 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Small Shell - Nothing fancy. Just runs programs.
|
||||
* The RAMDISK root uses this to save space.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
/* XXX - SunOS hacks... */
|
||||
#ifndef WCOREDUMP
|
||||
#define WCOREDUMP(x) ((x) & 0200)
|
||||
#endif
|
||||
|
||||
#ifndef __P
|
||||
#ifdef __STDC__
|
||||
#define __P(x) x
|
||||
#else /* STDC */
|
||||
#define __P(x) ()
|
||||
#endif /* STDC */
|
||||
#endif /* __P */
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind, opterr;
|
||||
|
||||
#define MAXLINE 256
|
||||
#define MAXARGS 32
|
||||
|
||||
#define MAXPATH 256
|
||||
char cur_path[MAXPATH] = "PATH=/bin:/usr/bin";
|
||||
|
||||
char rc_name[] = ".sshrc";
|
||||
char *prompt = "ssh: ";
|
||||
|
||||
int eflag; /* exit on cmd failure */
|
||||
int iflag; /* interactive mode (catch interrupts) */
|
||||
int sflag; /* read from stdin (ignore file arg) */
|
||||
int xflag; /* execution trace */
|
||||
|
||||
/* Command file: name, line number, arg count, arg vector */
|
||||
char *cf_name;
|
||||
int cf_line;
|
||||
int cf_argc;
|
||||
char **cf_argv;
|
||||
|
||||
int def_omode = 0666;
|
||||
int run_bg_pid;
|
||||
|
||||
jmp_buf next_cmd;
|
||||
|
||||
void catchsig __P((int sig));
|
||||
void child_newfd __P((int setfd, char *file, int otype));
|
||||
int find_in_path __P((char *cmd, char *filebuf));
|
||||
void print_termsig __P((FILE *fp, int cstat));
|
||||
int runfile __P((FILE *fp));
|
||||
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
struct sigaction sa;
|
||||
FILE *cfp; /* command file ptr */
|
||||
int c, sig;
|
||||
int error = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "eisx")) != -1) {
|
||||
switch (c) {
|
||||
case 'e':
|
||||
eflag++;
|
||||
break;
|
||||
case 'i':
|
||||
eflag++;
|
||||
break;
|
||||
case 's':
|
||||
sflag++;
|
||||
break;
|
||||
case 'x':
|
||||
xflag++;
|
||||
break;
|
||||
case '?':
|
||||
error++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
fprintf(stderr, "usage: ssh [-eisx] [cmd_file [...]]\n");
|
||||
exit(1);
|
||||
}
|
||||
cf_argc = argc - optind;
|
||||
cf_argv = &argv[optind];
|
||||
|
||||
/* If this is a login shell, run the rc file. */
|
||||
if (argv[0] && argv[0][0] == '-') {
|
||||
cf_line = 0;
|
||||
cf_name = rc_name;
|
||||
if ((cfp = fopen(cf_name, "r")) != NULL) {
|
||||
error = runfile(cfp);
|
||||
fclose(cfp);
|
||||
}
|
||||
}
|
||||
|
||||
/* If no file names, read commands from stdin. */
|
||||
if (cf_argc == 0)
|
||||
sflag++;
|
||||
/* If stdin is a tty, be interactive. */
|
||||
if (sflag && isatty(fileno(stdin)))
|
||||
iflag++;
|
||||
|
||||
/* Maybe run a command file... */
|
||||
if (!sflag && cf_argc) {
|
||||
cf_line = 0;
|
||||
cf_name = cf_argv[0];
|
||||
cfp = fopen(cf_name, "r");
|
||||
if (cfp == NULL) {
|
||||
perror(cf_name);
|
||||
exit(1);
|
||||
}
|
||||
error = runfile(cfp);
|
||||
fclose(cfp);
|
||||
exit(error);
|
||||
}
|
||||
|
||||
/* Read commands from stdin. */
|
||||
cf_line = 0;
|
||||
cf_name = "(stdin)";
|
||||
if (iflag) {
|
||||
eflag = 0; /* don't kill shell on error. */
|
||||
sig = setjmp(next_cmd);
|
||||
if (sig == 0) {
|
||||
/* Initialization... */
|
||||
sa.sa_handler = catchsig;
|
||||
sa.sa_flags = 0;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sigaction(SIGINT, &sa, NULL);
|
||||
sigaction(SIGQUIT, &sa, NULL);
|
||||
sigaction(SIGTERM, &sa, NULL);
|
||||
} else {
|
||||
/* Got here via longjmp. */
|
||||
fprintf(stderr, " signal %d\n", sig);
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sigprocmask(SIG_SETMASK, &sa.sa_mask, NULL);
|
||||
}
|
||||
}
|
||||
error = runfile(stdin);
|
||||
exit (error);
|
||||
}
|
||||
|
||||
void
|
||||
catchsig(sig)
|
||||
int sig;
|
||||
{
|
||||
longjmp(next_cmd, sig);
|
||||
}
|
||||
|
||||
/*
|
||||
* Run command from the passed stdio file pointer.
|
||||
* Returns exit status.
|
||||
*/
|
||||
int
|
||||
runfile(cfp)
|
||||
FILE *cfp;
|
||||
{
|
||||
char ibuf[MAXLINE];
|
||||
char *argv[MAXARGS];
|
||||
char *p;
|
||||
int i, argc, exitcode, cpid, cstat;
|
||||
|
||||
/* The command loop. */
|
||||
exitcode = 0;
|
||||
for (;;) {
|
||||
if (iflag) {
|
||||
fprintf(stderr, prompt);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
if ((fgets(ibuf, sizeof(ibuf), cfp)) == NULL)
|
||||
break;
|
||||
cf_line++;
|
||||
|
||||
argc = 0;
|
||||
p = ibuf;
|
||||
|
||||
while (argc < MAXARGS-1) {
|
||||
/* skip blanks or tabs */
|
||||
while ((*p == ' ') || (*p == '\t')) {
|
||||
next_token:
|
||||
*p++ = '\0';
|
||||
}
|
||||
/* end of line? */
|
||||
if ((*p == '\n') || (*p == '#')) {
|
||||
*p = '\0';
|
||||
break; /* to eol */
|
||||
}
|
||||
if (*p == '\0')
|
||||
break;
|
||||
/* save start of token */
|
||||
argv[argc++] = p;
|
||||
/* find end of token */
|
||||
while (*p) {
|
||||
if ((*p == '\n') || (*p == '#')) {
|
||||
*p = '\0';
|
||||
goto eol;
|
||||
}
|
||||
if ((*p == ' ') || (*p == '\t'))
|
||||
goto next_token;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
eol:
|
||||
|
||||
if (argc > 0) {
|
||||
if (xflag) {
|
||||
fprintf(stderr, "x");
|
||||
for (i = 0; i < argc; i++) {
|
||||
fprintf(stderr, " %s", argv[i]);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
argv[argc] = NULL;
|
||||
exitcode = cmd_eval(argc, argv);
|
||||
}
|
||||
|
||||
/* Collect children. */
|
||||
while ((cpid = waitpid(0, &cstat, WNOHANG)) > 0) {
|
||||
if (iflag) {
|
||||
fprintf(stderr, "[%d] ", cpid);
|
||||
if (WTERMSIG(cstat)) {
|
||||
print_termsig(stderr, cstat);
|
||||
} else {
|
||||
fprintf(stderr, "Exited, status %d\n",
|
||||
WEXITSTATUS(cstat));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (exitcode && eflag)
|
||||
break;
|
||||
}
|
||||
/* return status of last command */
|
||||
return (exitcode);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* Table of buildin commands
|
||||
* for cmd_eval() to search...
|
||||
****************************************************************/
|
||||
|
||||
struct cmd {
|
||||
char *name;
|
||||
int (*func)();
|
||||
char *help;
|
||||
};
|
||||
struct cmd cmd_table[];
|
||||
|
||||
/*
|
||||
* Evaluate a command named as argv[0]
|
||||
* with arguments argv[1],argv[2]...
|
||||
* Returns exit status.
|
||||
*/
|
||||
int
|
||||
cmd_eval(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
struct cmd *cp;
|
||||
|
||||
/*
|
||||
* Do linear search for a builtin command.
|
||||
* Performance does not matter here.
|
||||
*/
|
||||
for (cp = cmd_table; cp->name; cp++) {
|
||||
if (!strcmp(cp->name, argv[0])) {
|
||||
/* Pass only args to builtin. */
|
||||
--argc; argv++;
|
||||
return (cp->func(argc, argv));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If no matching builtin, let "run ..."
|
||||
* have a chance to try an external.
|
||||
*/
|
||||
return (cmd_run(argc, argv));
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
* Here are the actual commands. For these,
|
||||
* the command name has been skipped, so
|
||||
* argv[0] is the first arg (if any args).
|
||||
* All return an exit status.
|
||||
****************************************************************/
|
||||
|
||||
char help_cd[] = "cd [dir]";
|
||||
|
||||
int
|
||||
cmd_cd(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
char *dir;
|
||||
int err;
|
||||
|
||||
if (argc > 0)
|
||||
dir = argv[0];
|
||||
else {
|
||||
dir = getenv("HOME");
|
||||
if (dir == NULL)
|
||||
dir = "/";
|
||||
}
|
||||
if (chdir(dir)) {
|
||||
perror(dir);
|
||||
return (1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
char help_exit[] = "exit [n]";
|
||||
|
||||
int
|
||||
cmd_exit(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int val = 0;
|
||||
|
||||
if (argc > 0)
|
||||
val = atoi(argv[0]);
|
||||
exit(val);
|
||||
}
|
||||
|
||||
char help_help[] = "help [command]";
|
||||
|
||||
int
|
||||
cmd_help(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
struct cmd *cp;
|
||||
|
||||
if (argc > 0) {
|
||||
for (cp = cmd_table; cp->name; cp++) {
|
||||
if (!strcmp(cp->name, argv[0])) {
|
||||
printf("usage: %s\n", cp->help);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
printf("%s: no such command\n", argv[0]);
|
||||
}
|
||||
|
||||
printf("Builtin commands: ");
|
||||
for (cp = cmd_table; cp->name; cp++) {
|
||||
printf(" %s", cp->name);
|
||||
}
|
||||
printf("\nFor specific usage: help [command]\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
char help_path[] = "path [dir1:dir2:...]";
|
||||
|
||||
int
|
||||
cmd_path(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int i;
|
||||
|
||||
if (argc <= 0) {
|
||||
printf("%s\n", cur_path);
|
||||
return(0);
|
||||
}
|
||||
|
||||
strncpy(cur_path+5, argv[0], MAXPATH-6);
|
||||
putenv(cur_path);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
* The "run" command is the big one.
|
||||
* Does fork/exec/wait, redirection...
|
||||
* Returns exit status of child
|
||||
* (or zero for a background job)
|
||||
****************************************************************/
|
||||
|
||||
char help_run[] = "\
|
||||
run [-bg] [-i ifile] [-o ofile] [-e efile] program [args...]\n\
|
||||
or simply: program [args...]";
|
||||
|
||||
int
|
||||
cmd_run(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
struct sigaction sa;
|
||||
int pid, err, cstat, fd;
|
||||
char file[MAXPATHLEN];
|
||||
int background;
|
||||
char *opt, *ifile, *ofile, *efile;
|
||||
extern char **environ;
|
||||
|
||||
/*
|
||||
* Parse options:
|
||||
* -b : background
|
||||
* -i : input file
|
||||
* -o : output file
|
||||
* -e : error file
|
||||
*/
|
||||
background = 0;
|
||||
ifile = ofile = efile = NULL;
|
||||
while ((argc > 0) && (argv[0][0] == '-')) {
|
||||
opt = argv[0];
|
||||
--argc; argv++;
|
||||
switch (opt[1]) {
|
||||
case 'b':
|
||||
background++;
|
||||
break;
|
||||
case 'i':
|
||||
ifile = argv[0];
|
||||
goto shift;
|
||||
case 'o':
|
||||
ofile = argv[0];
|
||||
goto shift;
|
||||
case 'e':
|
||||
efile = argv[0];
|
||||
goto shift;
|
||||
default:
|
||||
fprintf(stderr, "run %s: bad option\n", opt);
|
||||
return (1);
|
||||
shift:
|
||||
--argc; argv++;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc <= 0) {
|
||||
fprintf(stderr, "%s:%d run: missing command\n",
|
||||
cf_name, cf_line);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Commands containing '/' get no path search. */
|
||||
if (strchr(argv[0], '/')) {
|
||||
strncpy(file, argv[0], sizeof(file)-1);
|
||||
if (access(file, X_OK)) {
|
||||
perror(file);
|
||||
return (1);
|
||||
}
|
||||
} else {
|
||||
if (find_in_path(argv[0], file)) {
|
||||
fprintf(stderr, "%s: command not found\n", argv[0]);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
/* child runs this */
|
||||
/* handle redirection options... */
|
||||
if (ifile)
|
||||
child_newfd(0, ifile, O_RDONLY);
|
||||
if (ofile)
|
||||
child_newfd(1, ofile, O_WRONLY|O_CREAT);
|
||||
if (efile)
|
||||
child_newfd(2, efile, O_WRONLY|O_CREAT);
|
||||
if (background) {
|
||||
/* Ignore SIGINT, SIGQUIT */
|
||||
sa.sa_handler = SIG_IGN;
|
||||
sa.sa_flags = 0;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sigaction(SIGINT, &sa, NULL);
|
||||
sigaction(SIGQUIT, &sa, NULL);
|
||||
}
|
||||
err = execve(file, argv, environ);
|
||||
perror(argv[0]);
|
||||
return (1);
|
||||
}
|
||||
/* parent */
|
||||
/* Handle background option... */
|
||||
if (background) {
|
||||
fprintf(stderr, "[%d]\n", pid);
|
||||
run_bg_pid = pid;
|
||||
return (0);
|
||||
}
|
||||
if (waitpid(pid, &cstat, 0) < 0) {
|
||||
perror("waitpid");
|
||||
return (1);
|
||||
}
|
||||
if (WTERMSIG(cstat)) {
|
||||
print_termsig(stderr, cstat);
|
||||
}
|
||||
return (WEXITSTATUS(cstat));
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
* table of builtin commands
|
||||
****************************************************************/
|
||||
struct cmd cmd_table[] = {
|
||||
{ "cd", cmd_cd, help_cd },
|
||||
{ "exit", cmd_exit, help_exit },
|
||||
{ "help", cmd_help, help_help },
|
||||
{ "path", cmd_path, help_path },
|
||||
{ "run", cmd_run, help_run },
|
||||
{ 0 },
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
* helper functions for the "run" command
|
||||
****************************************************************/
|
||||
|
||||
int
|
||||
find_in_path(cmd, filebuf)
|
||||
char *cmd;
|
||||
char *filebuf;
|
||||
{
|
||||
char *dirp, *endp, *bufp; /* dir, end */
|
||||
|
||||
dirp = cur_path + 5;
|
||||
while (*dirp) {
|
||||
endp = dirp;
|
||||
bufp = filebuf;
|
||||
while (*endp && (*endp != ':'))
|
||||
*bufp++ = *endp++;
|
||||
*bufp++ = '/';
|
||||
strcpy(bufp, cmd);
|
||||
if (access(filebuf, X_OK) == 0)
|
||||
return (0);
|
||||
if (*endp == ':')
|
||||
endp++;
|
||||
dirp = endp; /* next dir */
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the file descriptor SETFD to FILE,
|
||||
* which was opened with OTYPE and MODE.
|
||||
*/
|
||||
void
|
||||
child_newfd(setfd, file, otype)
|
||||
int setfd; /* what to set (i.e. 0,1,2) */
|
||||
char *file;
|
||||
int otype; /* O_RDONLY, etc. */
|
||||
{
|
||||
int newfd;
|
||||
|
||||
close(setfd);
|
||||
if ((newfd = open(file, otype, def_omode)) < 0) {
|
||||
perror(file);
|
||||
exit(1);
|
||||
}
|
||||
if (newfd != setfd) {
|
||||
dup2(newfd, setfd);
|
||||
close(newfd);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
print_termsig(fp, cstat)
|
||||
FILE *fp;
|
||||
int cstat;
|
||||
{
|
||||
fprintf(fp, "Terminated, signal %d",
|
||||
WTERMSIG(cstat));
|
||||
if (WCOREDUMP(cstat))
|
||||
fprintf(fp, " (core dumped)");
|
||||
fprintf(fp, "\n");
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
# $NetBSD: Makefile,v 1.1.1.1 1995/10/08 23:08:47 gwr Exp $
|
||||
# Tiny ls (i.e. for boot media)
|
||||
|
||||
PROG= tls
|
||||
NOMAN=
|
||||
|
||||
all: ${PROG}
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -0,0 +1,154 @@
|
|||
/* $NetBSD: tls.c,v 1.1.1.1 1995/10/08 23:08:47 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
int iflag;
|
||||
|
||||
void show_long(char *fname);
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
DIR *dfp;
|
||||
struct dirent *d;
|
||||
|
||||
/* If given an arg, just cd there first. */
|
||||
if (argc > 1) {
|
||||
if (chdir(argv[1])) {
|
||||
perror(argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (argc > 2)
|
||||
fprintf(stderr, "extra args ignored\n");
|
||||
|
||||
dfp = opendir(".");
|
||||
if (dfp == NULL) {
|
||||
perror("opendir");
|
||||
return;
|
||||
}
|
||||
|
||||
while ((d = readdir(dfp)) != NULL)
|
||||
show_long(d->d_name);
|
||||
|
||||
closedir(dfp);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* XXX - This is system dependent... */
|
||||
char ifmt_name[16] = {
|
||||
'?', /* 0: nothing */
|
||||
'P', /* 1: fifo (pipe) */
|
||||
'C', /* 2: chr device */
|
||||
'?', /* 3: ? */
|
||||
'D', /* 4: dir */
|
||||
'?', /* 5: ? */
|
||||
'B', /* 6: blk device */
|
||||
'?', /* 7: ? */
|
||||
'F', /* 8: file */
|
||||
'?', /* 9: ? */
|
||||
'L', /* A: link */
|
||||
'?', /* B: ? */
|
||||
'S', /* C: socket */
|
||||
'?', /* D: ? */
|
||||
'W', /* E: whiteout */
|
||||
'?' /* F: ? */
|
||||
};
|
||||
|
||||
void
|
||||
show_long(fname)
|
||||
char *fname;
|
||||
{
|
||||
struct stat st;
|
||||
int ifmt;
|
||||
char ifmt_c;
|
||||
char *date;
|
||||
|
||||
if (lstat(fname, &st)) {
|
||||
perror(fname);
|
||||
return;
|
||||
}
|
||||
ifmt = (st.st_mode >> 12) & 15;
|
||||
ifmt_c = ifmt_name[ifmt];
|
||||
|
||||
if (iflag) {
|
||||
/* inode number */
|
||||
printf("%6d ", st.st_ino);
|
||||
}
|
||||
|
||||
/* fmt/mode */
|
||||
printf("%c:", ifmt_c);
|
||||
printf("%04o ", st.st_mode & 07777);
|
||||
|
||||
/* nlinks, uid, gid */
|
||||
printf("%2d ", st.st_nlink);
|
||||
printf("%4d ", st.st_uid);
|
||||
printf("%4d ", st.st_gid);
|
||||
|
||||
/* size or major/minor */
|
||||
if ((ifmt_c == 'B') || (ifmt_c == 'C')) {
|
||||
printf("%2d, ", major(st.st_rdev));
|
||||
printf("%3d ", minor(st.st_rdev));
|
||||
} else {
|
||||
printf("%7d ", (int) st.st_size);
|
||||
}
|
||||
|
||||
/* date */
|
||||
date = ctime(&st.st_mtime);
|
||||
date += 4; /* skip day-of-week */
|
||||
date[12] = '\0'; /* to the minute */
|
||||
printf("%s ", date);
|
||||
|
||||
/* name */
|
||||
printf("%s", fname);
|
||||
|
||||
if (ifmt_c == 'L') {
|
||||
char linkto[256];
|
||||
int n;
|
||||
|
||||
n = readlink(fname, linkto, sizeof(linkto)-1);
|
||||
if (n < 0) {
|
||||
perror(fname);
|
||||
return;
|
||||
}
|
||||
linkto[n] = '\0';
|
||||
printf(" -> %s", linkto);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
# $NetBSD: Makefile,v 1.1.1.1 1995/10/08 23:08:47 gwr Exp $
|
||||
# Build a smaller dd (i.e. for boot media)
|
||||
|
||||
PROG= dd
|
||||
NOMAN=
|
||||
|
||||
SRCDIR=/usr/src/bin/dd
|
||||
|
||||
SRCS= args.c conv.c dd.c misc.c position.c
|
||||
# SRCS+= conv_tab.c (not used)
|
||||
|
||||
CFLAGS+= -DNO_CONV -I${SRCDIR}
|
||||
|
||||
.PATH: ${SRCDIR}
|
||||
|
||||
all: ${PROG}
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -0,0 +1,14 @@
|
|||
# $NetBSD: Makefile,v 1.1.1.1 1995/10/08 23:08:47 gwr Exp $
|
||||
# Build a smaller ifconfig (i.e. for boot media)
|
||||
|
||||
PROG= ifconfig
|
||||
NOMAN=
|
||||
|
||||
SRCDIR=/usr/src/sbin/ifconfig
|
||||
CFLAGS+= -DINET_ONLY -I${SRCDIR}
|
||||
|
||||
.PATH: ${SRCDIR}
|
||||
|
||||
all: ${PROG}
|
||||
|
||||
.include <bsd.prog.mk>
|
Loading…
Reference in New Issue