Remove picobsd build scripts and the remaining tinyware
Postings were sent to -arch@ on 2019/09/13 and 2019/10/01, proposing and confirming a removal of these scripts on 2019/10/31, due to significant work needed to bring this into the modern world and nobody having done this work in the past couple of years. No objections or proposed work was raised in response to these postings. The tinyware may see a resurrection into a separate repo for archival purposes if any users of it show interest in doing so. MFC after: never
This commit is contained in:
parent
74954211d6
commit
6d180b1360
@ -1 +0,0 @@
|
||||
VER=0.500
|
@ -1,117 +0,0 @@
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
# Line starting with #PicoBSD contains PicoBSD build parameters
|
||||
#marker def_sz init MFS_inodes floppy_inodes
|
||||
#PicoBSD 8000 init 8192 32768
|
||||
options MD_ROOT_SIZE=8000 # same as def_sz
|
||||
|
||||
hints "PICOBSD.hints"
|
||||
|
||||
# values accessible through getenv()
|
||||
# env "PICOBSD.env"
|
||||
|
||||
#cpu I486_CPU
|
||||
cpu I586_CPU
|
||||
cpu I686_CPU
|
||||
ident PICOBSD
|
||||
|
||||
options SMP
|
||||
device apic
|
||||
|
||||
options SCHED_4BSD # mandatory to have one scheduler
|
||||
#options MATH_EMULATE #Support for x87 emulation
|
||||
options INET #InterNETworking
|
||||
#options INET6
|
||||
options FFS #Berkeley Fast Filesystem
|
||||
#options BOOTP #Use BOOTP to obtain IP address/hostname
|
||||
options MD_ROOT #MD is a potential root device
|
||||
|
||||
#options NFS #Network Filesystem
|
||||
#options NFS_ROOT #NFS usable as root device, NFS required
|
||||
|
||||
#options MSDOSFS #MSDOS Filesystem
|
||||
#options CD9660 #ISO 9660 Filesystem
|
||||
#options CD9660_ROOT #CD-ROM usable as root, CD9660 required
|
||||
#options DEVFS #Device Filesystem
|
||||
#options PROCFS #Process filesystem
|
||||
options COMPAT_43 #Compatible with BSD 4.3 [KEEP THIS!]
|
||||
|
||||
#options DDB
|
||||
|
||||
options IPFIREWALL
|
||||
options IPFIREWALL_DEFAULT_TO_ACCEPT
|
||||
options IPDIVERT # divert (for natd)
|
||||
|
||||
# Support for bridging and bandwidth limiting
|
||||
options DUMMYNET
|
||||
device if_bridge
|
||||
# Running with less than 1000 seems to give poor timing on
|
||||
# qemu, so we set HZ explicitly.
|
||||
options HZ=1000
|
||||
|
||||
device pci
|
||||
|
||||
# Floppy drives
|
||||
device fdc
|
||||
|
||||
# ATA and ATAPI devices
|
||||
#device ata
|
||||
#device atadisk # ATA disk drives
|
||||
#device atapicd # ATAPI CDROM drives
|
||||
#options ATA_STATIC_ID #Static device numbering
|
||||
|
||||
# atkbdc0 controls both the keyboard and the PS/2 mouse
|
||||
device atkbdc # At keyboard controller
|
||||
device atkbd
|
||||
#device psm # do we need the mouse ??
|
||||
|
||||
device vga # VGA screen
|
||||
|
||||
# syscons is the default console driver, resembling an SCO console
|
||||
device sc
|
||||
|
||||
# Serial (COM) ports
|
||||
device uart
|
||||
|
||||
# Audio support
|
||||
#device pcm
|
||||
|
||||
# PCCARD (PCMCIA) support
|
||||
#device card # pccard bus
|
||||
#device pcic # PCMCIA bridge
|
||||
|
||||
# Parallel port
|
||||
#device ppc
|
||||
#device ppbus # Parallel port bus (required)
|
||||
#device lpt # Printer
|
||||
#device plip # TCP/IP over parallel
|
||||
#device ppi # Parallel port interface device
|
||||
|
||||
#
|
||||
# The following Ethernet NICs are all PCI devices.
|
||||
#
|
||||
device miibus
|
||||
device fxp # Intel EtherExpress PRO/100B (82557, 82558)
|
||||
device nfe # nVidia nForce MCP on-board Ethernet
|
||||
#device xl # 3Com
|
||||
device rl # RealTek 8129/8139
|
||||
device re # RealTek 8139C+/8169/8169S/8110S
|
||||
device sis # National/SiS
|
||||
device dc # DEC/Intel 21143 and various workalikes
|
||||
device ed
|
||||
|
||||
device loop # Network loopback
|
||||
device ether # Ethernet support
|
||||
device tun # Packet tunnel.
|
||||
#device vn #Vnode driver (turns a file into a device)
|
||||
device pty # Pseudo-ttys (telnet etc)
|
||||
device md # Memory "disks"
|
||||
#device gif 4 # IPv6 and IPv4 tunneling
|
||||
device tap
|
||||
|
||||
#options DEVICE_POLLING
|
||||
|
||||
# The `bpf' device enables the Berkeley Packet Filter.
|
||||
# Be aware of the administrative consequences of enabling this!
|
||||
device bpf # Berkeley packet filter
|
@ -1,39 +0,0 @@
|
||||
# $FreeBSD$
|
||||
hint.fdc.0.at="isa"
|
||||
hint.fdc.0.port="0x3F0"
|
||||
hint.fdc.0.irq="6"
|
||||
hint.fdc.0.drq="2"
|
||||
hint.fd.0.at="fdc0"
|
||||
hint.fd.0.drive="0"
|
||||
hint.ata.0.at="isa"
|
||||
hint.ata.0.port="0x1F0"
|
||||
hint.ata.0.irq="14"
|
||||
hint.ata.1.at="isa"
|
||||
hint.ata.1.port="0x170"
|
||||
hint.ata.1.irq="15"
|
||||
hint.atkbdc.0.at="isa"
|
||||
hint.atkbdc.0.port="0x060"
|
||||
hint.atkbd.0.at="atkbdc"
|
||||
hint.atkbd.0.irq="1"
|
||||
hint.psm.0.at="atkbdc"
|
||||
hint.psm.0.irq="12"
|
||||
hint.vga.0.at="isa"
|
||||
hint.sc.0.at="isa"
|
||||
hint.npx.0.at="nexus"
|
||||
hint.npx.0.port="0x0F0"
|
||||
hint.npx.0.irq="13"
|
||||
hint.uart.0.at="isa"
|
||||
hint.uart.0.port="0x3F8"
|
||||
hint.uart.0.flags="0x10"
|
||||
hint.uart.0.irq="4"
|
||||
hint.uart.1.at="isa"
|
||||
hint.uart.1.port="0x2F8"
|
||||
hint.uart.1.irq="3"
|
||||
hint.ed.0.at="isa"
|
||||
hint.ed.0.port="0x280"
|
||||
hint.ed.0.irq="5"
|
||||
hint.ed.0.maddr="0xd8000"
|
||||
hint.ed.1.at="isa"
|
||||
hint.ed.1.port="0x300"
|
||||
hint.ed.1.irq="5"
|
||||
hint.ed.1.maddr="0xd0000"
|
@ -1,6 +0,0 @@
|
||||
# configuration for picobsd build script.
|
||||
# $FreeBSD$
|
||||
# it should only contain variable definitions -- it is sourced
|
||||
# by the shell much like rc.conf* files
|
||||
|
||||
fd_size="4096"
|
@ -1,183 +0,0 @@
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
# Configuration file for "bridge" images..
|
||||
#
|
||||
# Depending on your needs, you will almost surely need to
|
||||
# add/remove/change programs according to your needs.
|
||||
# Remember that some programs require matching kernel options to
|
||||
# enable device drivers etc.
|
||||
#
|
||||
# To figure out how much space is used by each program, do
|
||||
#
|
||||
# size build_dir-bridge/crunch/*lo
|
||||
#
|
||||
# Remember that programs require libraries, which add up to the
|
||||
# total size. The final binary is build_dir-bridge/mfs.tree/stand/crunch
|
||||
# and you can check which libraries it uses with
|
||||
#
|
||||
# ldd build_dir-bridge/mfs.tree/stand/crunch
|
||||
|
||||
# crunchgen configuration to build the crunched binary, see "man crunchgen"
|
||||
# We need to specify generic build options, the places where to look
|
||||
# for sources, and the list of program and libraries we want to put
|
||||
# in the crunched binary.
|
||||
#
|
||||
# NOTE: the string "/usr/src" below will be automatically replaced with
|
||||
# the path set in the 'build' script.
|
||||
|
||||
# Default build options. Basically tell the Makefiles
|
||||
# that to use the most compact possible version of the code.
|
||||
|
||||
buildopts -DWITHOUT_PAM -DPPP_NO_NETGRAPH
|
||||
buildopts -DTRACEROUTE_NO_IPSEC -DNO_INET6
|
||||
buildopts -DWITHOUT_KERBEROS -DWITHOUT_OPENSSL
|
||||
|
||||
# Directories where to look for sources of various binaries.
|
||||
# @__CWD__@ is a magic keyword in the picobsd's (Makefile.conf)
|
||||
# which is replaced with the directory with the picobsd configuration
|
||||
# corresponding to your image. This way you can have custom sources
|
||||
# in that directory overriding system programs.
|
||||
|
||||
srcdirs @__CWD__@/src
|
||||
|
||||
# Some programs are especially written for PicoBSD and reside in
|
||||
# release/picobsd/tinyware.
|
||||
# Put this entry near the head of the list to override standard binaries.
|
||||
|
||||
srcdirs /usr/src/release/picobsd/tinyware
|
||||
|
||||
# Other standard locations for sources.
|
||||
# If a program uses its own source directory, add
|
||||
|
||||
srcdirs /usr/src/bin
|
||||
srcdirs /usr/src/sbin/i386
|
||||
srcdirs /usr/src/sbin
|
||||
srcdirs /usr/src/usr.bin
|
||||
srcdirs /usr/src/gnu/usr.bin
|
||||
srcdirs /usr/src/usr.sbin
|
||||
srcdirs /usr/src/libexec
|
||||
|
||||
# For programs that reside in different places, the best option
|
||||
# is to use the command "special XXX srcdir YYY" where XXX is the
|
||||
# program name and YYY is the directory path.
|
||||
# "special XXX ..." can be used to specify more options, see again
|
||||
# the crunchgen manpage.
|
||||
|
||||
#--- Basic configuraton
|
||||
# init is always necessary (unless you have a replacement, oinit)
|
||||
progs init
|
||||
|
||||
# fsck is almost always necessary, unless you have everything on the
|
||||
# image and use 'tar' or something similar to read/write raw blocks
|
||||
# from the floppy.
|
||||
|
||||
progs fsck
|
||||
|
||||
# ifconfig is needed if you want to configure interfaces.
|
||||
progs ifconfig
|
||||
|
||||
# You will also need a shell and a bunch of utilities.
|
||||
# The standard shell is not that large, but you need many
|
||||
# external programs. In fact most of them do not take much space
|
||||
# as they merely issue a system call, and print the result.
|
||||
# For a more compact version of shell and utilities, you could
|
||||
# try busybox, however most system management commands in busybox
|
||||
# will not work as they use linux-specific interfaces.
|
||||
|
||||
progs sh
|
||||
ln sh -sh
|
||||
|
||||
# the small utilities
|
||||
progs echo
|
||||
progs pwd mkdir rmdir
|
||||
progs chmod chown
|
||||
ln chown chgrp
|
||||
progs mv ln cp rm ls
|
||||
progs cat tail tee
|
||||
progs test
|
||||
ln test [
|
||||
|
||||
progs less
|
||||
ln less more
|
||||
progs mount
|
||||
progs minigzip
|
||||
ln minigzip gzip
|
||||
progs kill
|
||||
progs df
|
||||
progs ps
|
||||
progs ns # this is the picobsd version
|
||||
ln ns netstat
|
||||
progs vm
|
||||
progs hostname
|
||||
progs login
|
||||
progs getty
|
||||
progs stty
|
||||
progs w
|
||||
progs msg
|
||||
ln msg dmesg
|
||||
progs reboot
|
||||
|
||||
progs sysctl
|
||||
progs swapon
|
||||
progs pwd_mkdb
|
||||
progs umount
|
||||
progs du
|
||||
progs passwd
|
||||
|
||||
progs route
|
||||
|
||||
# If you want to run natd, remember the alias library
|
||||
#progs natd
|
||||
#libs_so -lalias # natd
|
||||
|
||||
# ppp is rather large. Note that as of Jan.01, RELEASE_CRUNCH
|
||||
# makes ppp not use libalias, so you cannot have aliasing.
|
||||
#progs ppp
|
||||
|
||||
# You need an editor. ee is relatively small, though there are
|
||||
# smaller ones. vi is much larger.
|
||||
# The editor also usually need a curses library.
|
||||
progs ee
|
||||
|
||||
progs arp
|
||||
|
||||
# these require libgeom
|
||||
# progs bsdlabel fdisk mdconfig
|
||||
|
||||
progs kldload kldunload kldstat
|
||||
progs kldxref
|
||||
#progs grep
|
||||
progs date
|
||||
progs ping
|
||||
#progs routed
|
||||
progs ipfw
|
||||
progs traceroute
|
||||
progs mdmfs
|
||||
ln mdmfs mount_mfs
|
||||
# Various filesystem support -- remember to enable the kernel parts
|
||||
# progs mount_msdosfs
|
||||
progs mount_nfs
|
||||
# progs mount_cd9660
|
||||
ln mount_nfs nfs
|
||||
ln mount_cd9660 cd9660
|
||||
#progs newfs
|
||||
#ln newfs mount_mfs
|
||||
# ln mount_msdosfs msdos
|
||||
|
||||
# For a small ssh client/server use dropbear
|
||||
|
||||
# Now the libraries
|
||||
libs_so -lc # the C library
|
||||
libs_so -ll # used by sh (really ?)
|
||||
libs_so -lufs # used by mount
|
||||
### ee uses ncurses but as a dependency
|
||||
#libs_so -lncurses
|
||||
libs_so -lm
|
||||
libs_so -ledit -lutil
|
||||
libs_so -lcrypt
|
||||
libs_so -lkvm
|
||||
libs_so -lz
|
||||
libs_so -lbsdxml
|
||||
libs_so -lsbuf
|
||||
libs_so -ljail # used by ifconfig
|
@ -1,2 +0,0 @@
|
||||
etc/snmpd.conf
|
||||
etc/ppp
|
@ -1,60 +0,0 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
# Makefile for building PICOBSD kernels and running crunchgen
|
||||
#
|
||||
# Needs SRC pointing to the source tree,
|
||||
# MY_TREE ponting to my tree
|
||||
# BUILDDIR pointing to the build directory
|
||||
# PICO_OBJ pointing to the object directory
|
||||
# When building a kernel, also need ${name} from the environment
|
||||
# and CONFIG may indicate an alternate config program
|
||||
|
||||
BINMAKE?=make
|
||||
SRC?=/usr/src
|
||||
CONFIG?=config
|
||||
MODULES?=-DNO_MODULES # do not build them as a default
|
||||
KERNCONF ?= PICOBSD
|
||||
|
||||
# caller will set MODULES to empty if modules are needed.
|
||||
# Indeed, it can be used to specify other Makefile options as well.
|
||||
|
||||
# These 3 variables determine where the kernel is built.
|
||||
# If config were smart enough, we could place the config
|
||||
# file in some other place than ${SRC}/sys/${TARGET_ARCH}/conf, but
|
||||
# at the moment (Oct.2001) this is not possible yet.
|
||||
CONF=${SRC}/sys/${TARGET_ARCH}/conf
|
||||
#CONF=${BUILDDIR}/conf # XXX does not work yet
|
||||
CONFFILE=PICOBSD-${name}
|
||||
|
||||
# We can, however, compile the kernel somewhere else
|
||||
#COMPILE=${CONF}/../compile/${CONFFILE}
|
||||
COMPILE=${BUILDDIR}/${CONFFILE}
|
||||
|
||||
KERNFILE=${COMPILE}/kernel
|
||||
|
||||
${BUILDDIR}/kernel: ${KERNFILE}
|
||||
cp -p ${.OODATE} ${.TARGET}
|
||||
strip ${.TARGET}
|
||||
strip --remove-section=.note --remove-section=.comment ${.TARGET}
|
||||
|
||||
${KERNFILE}: ${COMPILE} do_a_make_in_the_kernel_directory_anyways
|
||||
|
||||
do_a_make_in_the_kernel_directory_anyways:
|
||||
(cd ${COMPILE}; ${BINMAKE} KERNEL=kernel ${MODULES} )
|
||||
|
||||
${COMPILE}: ${CONF}/${CONFFILE}
|
||||
cd ${CONF}; ${CONFIG} -d ${COMPILE} ${CONFFILE}
|
||||
|
||||
${CONF}/${CONFFILE}: ${KERNCONF}
|
||||
# -mkdir -p ${CONF} # XXX not needed yet.
|
||||
cp ${.OODATE} ${.TARGET}
|
||||
[ -f PICOBSD.hints ] && cp PICOBSD.hints ${CONF}/
|
||||
|
||||
# This part creates crunch1.conf and crunch.mk from crunch.conf
|
||||
${BUILDDIR}/crunch.mk: ${BUILDDIR}/crunch1.conf
|
||||
-(cd ${BUILDDIR}/crunch ; \
|
||||
crunchgen -p ${PICO_OBJ} -o -m ${.TARGET} ${.OODATE} )
|
||||
|
||||
${BUILDDIR}/crunch1.conf: ${MY_TREE}/crunch.conf
|
||||
(cd ${BUILDDIR}/crunch ; cat ${.OODATE} | \
|
||||
sed -e "s@/usr/src@${SRC}@" -e "s+@__CWD__@+${MY_TREE}+" > ${.TARGET} )
|
@ -1,17 +0,0 @@
|
||||
# config variables for PicoBSD floppies.
|
||||
# This file is sourced by the main build script. It should
|
||||
# only contain assignment to shell variables.
|
||||
#
|
||||
# The type-specific "config" file is sourced after this one, so
|
||||
# you can override things there.
|
||||
|
||||
# STAND_LINKS contains the list of links to be created on the mfs image.
|
||||
# o_no_devfs is set to an empty string to inform the build script that
|
||||
# we are using devfs (this need to be done in a less confusing way sometime...)
|
||||
|
||||
STAND_LINKS=${STAND_LINKS:-"bin sbin usr/bin usr/sbin usr/libexec \
|
||||
usr/local/bin"}
|
||||
|
||||
o_no_devfs="" # we have devfs.
|
||||
|
||||
# fd_size="2880" # use this variable to set floppy sizes (in KBytes)
|
@ -1,72 +0,0 @@
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
/set type=dir uname=root gname=wheel mode=0755
|
||||
.
|
||||
cdrom
|
||||
..
|
||||
dev
|
||||
..
|
||||
dos
|
||||
..
|
||||
etc
|
||||
..
|
||||
fd
|
||||
..
|
||||
home
|
||||
user
|
||||
..
|
||||
..
|
||||
mnt
|
||||
..
|
||||
mnt1
|
||||
..
|
||||
mnt2
|
||||
..
|
||||
proc
|
||||
..
|
||||
root
|
||||
..
|
||||
stand
|
||||
..
|
||||
start_floppy
|
||||
..
|
||||
tftpboot
|
||||
..
|
||||
tmp mode=01777
|
||||
..
|
||||
usr
|
||||
local
|
||||
etc
|
||||
..
|
||||
lib
|
||||
snmp
|
||||
..
|
||||
..
|
||||
..
|
||||
share
|
||||
misc
|
||||
..
|
||||
locale
|
||||
..
|
||||
syscons
|
||||
..
|
||||
nls
|
||||
..
|
||||
..
|
||||
..
|
||||
var
|
||||
db
|
||||
..
|
||||
empty
|
||||
..
|
||||
run
|
||||
..
|
||||
spool
|
||||
lock
|
||||
..
|
||||
..
|
||||
..
|
||||
wd
|
||||
..
|
||||
..
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +0,0 @@
|
||||
# $FreeBSD$
|
||||
proc /proc procfs rw 0 0
|
||||
/dev/fd0c /fd ufs rw,noauto 0 0
|
||||
/dev/ad0s1 /dos msdosfs rw,noauto 0 0
|
||||
/dev/ad0s1a /wd ufs rw,noauto 0 0
|
||||
/dev/acd0c /cdrom cd9660 ro,noauto 0 0
|
@ -1,17 +0,0 @@
|
||||
# $FreeBSD$
|
||||
# This file contains ip <-> hostname mapping.
|
||||
# It is also used for autoconfiguration based on Ethernet address
|
||||
# and other things. The initial part is just a standard /etc/hosts
|
||||
# for local hosts that share this file.
|
||||
127.0.0.1 localhost localhost.mydomain.edu
|
||||
127.0.0.1 pico.mydomain.edu
|
||||
10.0.0.1 default
|
||||
192.168.254.1 vmrouter
|
||||
192.168.254.2 vm
|
||||
|
||||
#ethertable This line starts the ethernet->hostname mapping
|
||||
# main_ether hostname
|
||||
# 00:12:34:56:78:9a myaddress
|
||||
# 00:bd:* vm
|
||||
# default default
|
||||
|
@ -1,21 +0,0 @@
|
||||
#
|
||||
# Internet server configuration database
|
||||
#
|
||||
# @(#)inetd.conf 5.4 (Berkeley) 6/30/90
|
||||
#
|
||||
telnet stream tcp nowait root /usr/libexec/telnetd telnetd
|
||||
#
|
||||
# "Small servers" -- used to be standard on, but we're more conservative
|
||||
# about things due to Internet security concerns. Only turn on what you
|
||||
# need.
|
||||
#
|
||||
#daytime stream tcp nowait root internal
|
||||
#daytime dgram udp wait root internal
|
||||
#time stream tcp nowait root internal
|
||||
#time dgram udp wait root internal
|
||||
#echo stream tcp nowait root internal
|
||||
#echo dgram udp wait root internal
|
||||
#discard stream tcp nowait root internal
|
||||
#discard dgram udp wait root internal
|
||||
#chargen stream tcp nowait root internal
|
||||
#chargen dgram udp wait root internal
|
@ -1,11 +0,0 @@
|
||||
# $FreeBSD$
|
||||
root:$1$xOOaGnKU$U9QdsCI40XXcCUMBN.7Az.:0:0::0:0:Charlie &:/root:/bin/sh
|
||||
toor:*:0:0::0:0:Bourne-again Superuser:/root:
|
||||
daemon:*:1:1::0:0:Owner of many system processes:/root:/nonexistent
|
||||
operator:*:2:20::0:0:System &:/usr/guest/operator:/bin/csh
|
||||
bin:*:3:7::0:0:Binaries Commands and Source,,,:/:/nonexistent
|
||||
tty:*:4:65533::0:0:Tty Sandbox:/:/nonexistent
|
||||
sshd:*:22:22::0:0:Secure Shell Daemon:/var/empty:/usr/sbin/nologin
|
||||
nobody:*:65534:65534::0:0:Unprivileged user:/nonexistent:/nonexistent
|
||||
_dhcp:*:65:65::0:0:dhcp programs:/var/empty:/usr/sbin/nologin
|
||||
user:*:1002:1002:Sample User:0:0:user:/home/user:/bin/sh
|
@ -1,5 +0,0 @@
|
||||
# Sample networks file. Picobsd scripts will look for entries of the form
|
||||
# hostname-netmask 255.255.255.0
|
||||
# when searching for masks
|
||||
vm-netmask 255.255.255.0
|
||||
|
@ -1,9 +0,0 @@
|
||||
# $FreeBSD$
|
||||
# PPP Sample Configuration File
|
||||
# Written by Toshiharu OHNO
|
||||
default:
|
||||
set device /dev/cuau1
|
||||
set speed 38400
|
||||
disable lqr
|
||||
deny lqr
|
||||
set dial "ABORT BUSY ABORT NO\\sCARRIER TIMEOUT 5 \"\" ATE1Q0 OK-AT-OK \\dATDT\\T TIMEOUT 40 CONNECT"
|
@ -1,15 +0,0 @@
|
||||
# list of users disallowed any pppd access via 'system
|
||||
# password login'.
|
||||
# read by pppd(8).
|
||||
root
|
||||
toor
|
||||
daemon
|
||||
operator
|
||||
bin
|
||||
games
|
||||
news
|
||||
man
|
||||
ftp
|
||||
uucp
|
||||
xten
|
||||
ingres
|
@ -1,10 +0,0 @@
|
||||
# Example of ppp.linkup file
|
||||
#
|
||||
iij-demand:
|
||||
delete ALL
|
||||
add 0 0 HISADDR
|
||||
#
|
||||
# Otherwise, simply add peer as default gateway.
|
||||
#
|
||||
MYADDR:
|
||||
add 0 0 HISADDR
|
@ -1,23 +0,0 @@
|
||||
##################################################
|
||||
#
|
||||
# Example of ppp.secret file
|
||||
#
|
||||
# This file is used to authenticate incoming connections.
|
||||
# You must ``enable'' either PAP or CHAP in your ppp.conf file.
|
||||
# The peer may then use any of the Authname/Authkey pairs listed.
|
||||
# If an IP address is given, it will be assigned to the peer.
|
||||
#
|
||||
# If an entry exists for your local machine (as given by the
|
||||
# ``hostname -s'' command), the password specified will be
|
||||
# required for all server socket connections. Refer to the ppp(8)
|
||||
# and pppctl(8) man pages for further details.
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
##################################################
|
||||
|
||||
# Authname Authkey Peer's IP address
|
||||
|
||||
oscar OurSecretKey 192.244.184.34/24
|
||||
BigBird X4dWg9327 192.244.184.33/32
|
||||
tama localPasswdForControl
|
@ -1,5 +0,0 @@
|
||||
# System-wide .profile file for sh(1).
|
||||
BLOCKSIZE=K; export BLOCKSIZE
|
||||
PATH=/stand:.; export PATH
|
||||
EDITOR=ee; export EDITOR
|
||||
set -E
|
@ -1,10 +0,0 @@
|
||||
# Sample rc.conf file for PicoBSD
|
||||
# you should mostly set variables here, see rc.conf.defaults.
|
||||
|
||||
tcp_extensions=YES # enable rfc1323 and rfc1644
|
||||
|
||||
case ${hostname} in
|
||||
*)
|
||||
echo "processing rc.conf for ${hostname}"
|
||||
;;
|
||||
esac
|
@ -1,184 +0,0 @@
|
||||
#!/bin/sh
|
||||
# $FreeBSD$
|
||||
#
|
||||
# rc.conf for picobsd. This is sourced from /etc/rc1, and is supposed to
|
||||
# contain only shell functions that are used later in /etc/rc1.
|
||||
|
||||
# set default values for variables. Boolean values should be either
|
||||
# NO or YES -- other values are not guaranteed to work.
|
||||
|
||||
rc_conf_set_defaults() {
|
||||
hostname="" # Should not need to set it
|
||||
syslogd_enable="NO"
|
||||
pccard_enable="NO"
|
||||
swapfile="" # name of swapfile if aux swapfile desired.
|
||||
|
||||
# Network interface configurations: ifconfig_${interface}[_aliasNN]
|
||||
ifconfig_lo0="inet 127.0.0.1" # default loopback device configuration.
|
||||
#ifconfig_lo0_alias0="inet 127.0.0.254 netmask 0xffffffff" # Sample alias entry.
|
||||
|
||||
### Network daemons options: they are only run if present.
|
||||
sshd_enable="YES" # if present...
|
||||
inetd_enable="YES" # Run the network daemon dispatcher (or NO)
|
||||
inetd_flags="" # Optional flags to inetd
|
||||
snmpd_enable="NO" # Run the SNMP daemon (or NO)
|
||||
snmpd_flags="-C -c /etc/snmpd.conf" # Optional flags to snmpd
|
||||
|
||||
### Network routing options: ###
|
||||
defaultrouter="NO" # Set to default gateway (or NO).
|
||||
static_routes="" # Set to static route list (or leave empty).
|
||||
gateway_enable="NO" # Set to YES if this host will be a gateway.
|
||||
arpproxy_all="" # replaces obsolete kernel option ARP_PROXYALL.
|
||||
default_mask="0xffffff00"
|
||||
|
||||
### Other network features
|
||||
firewall_enable="NO"
|
||||
firewall_quiet="NO" # be quiet if set.
|
||||
firewall_type="" # Standard types or absolute pathname.
|
||||
tcp_extensions="NO" # Allow RFC1323 & RFC1644 extensions (or NO).
|
||||
|
||||
### Overrides for some files in /etc. Leave empty if no override,
|
||||
### set variable (remember to use multiple lines) to override content.
|
||||
|
||||
host_conf="hosts
|
||||
bind"
|
||||
resolv_conf=""
|
||||
}
|
||||
|
||||
# Try to identify the system by using the MAC address and name of the
|
||||
# first ethernet interface, made available as $main_eth $main_if
|
||||
find_system_id() {
|
||||
main_ether=""
|
||||
for main_if in `ifconfig -l` ; do
|
||||
set `ifconfig $main_if`
|
||||
while [ "$1" != "" ] ; do
|
||||
if [ $1 = "ether" ] ; then
|
||||
main_ether=$2
|
||||
break 2
|
||||
else
|
||||
shift
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# the following lets the user specify a name and ip for his system
|
||||
read_address() {
|
||||
echo "Please enter a hostname and IP address for your system $main_ether"
|
||||
read hostname the_ip
|
||||
if [ "${hostname}" != "" ] ; then
|
||||
echo "# $main_ether $hostname" >> /etc/hosts
|
||||
echo "$the_ip $hostname" >> /etc/hosts
|
||||
else
|
||||
hostname=default
|
||||
fi
|
||||
}
|
||||
|
||||
# set "ether" using $1 (interface name) as search key
|
||||
get_ether() {
|
||||
local key
|
||||
key=$1
|
||||
ether=""
|
||||
set `ifconfig ${key}`
|
||||
while [ "$1" != "" ] ; do
|
||||
if [ "$1" = "ether" ] ; then
|
||||
ether=$2
|
||||
break
|
||||
else
|
||||
shift
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# read content from /etc/hosts into a couple of arrays
|
||||
# (needed later in fetch_hostname)
|
||||
read_hosts() {
|
||||
local i a b c key junk
|
||||
i=""
|
||||
while read a b c junk ; do
|
||||
if [ "$a" = "#ethertable" ] ; then
|
||||
i=0
|
||||
elif [ "$i" != "" -a "$a" = "#" -a "$b" != "" ] ; then
|
||||
eval eth_${i}=$b
|
||||
eval eth_host_${i}=$c
|
||||
i=$(($i+1))
|
||||
fi
|
||||
done < /etc/hosts
|
||||
}
|
||||
|
||||
# set ${hostname} using $1 (MAC address) as search key in /etc/hosts
|
||||
# Returns empty value if $1 is empty
|
||||
fetch_hostname() {
|
||||
local i b key
|
||||
hostname=""
|
||||
[ "$1" = "" ] && return
|
||||
key=$1
|
||||
i=0
|
||||
b="x"
|
||||
[ "${eth_0}" = "" ] && read_hosts # fill cache.
|
||||
while [ "$b" != "" -a "${hostname}" = "" ] ; do
|
||||
eval b=\${eth_${i}}
|
||||
case X${key} in
|
||||
X${b} ) # so we can use wildcards
|
||||
eval hostname=\${eth_host_${i}}
|
||||
break
|
||||
;;
|
||||
esac
|
||||
i=$(($i+1))
|
||||
done
|
||||
echo "fetch_hostname for <${key}> returns <${hostname}>"
|
||||
}
|
||||
|
||||
# sets "mask" using $1 (netmask name) as the search key in /etc/networks
|
||||
fetch_mask() {
|
||||
local a b key junk
|
||||
key=$1 # search key, typically hostname-netmask
|
||||
mask=""
|
||||
while read a b junk; do # key mask otherstuff
|
||||
case X${key} in
|
||||
X${a} ) # The X is so we can use wildcards in ${a}
|
||||
mask=$b
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done < /etc/networks
|
||||
if [ "${mask}" = "" ] ; then
|
||||
mask=${default_mask}
|
||||
fi
|
||||
echo "fetch_mask for <${key}> returns <${mask}>"
|
||||
}
|
||||
|
||||
# set hostname, and ifconfig_${main_if} (whose MAC is ${main_ether})
|
||||
# if not found, read from console
|
||||
set_main_interface() {
|
||||
if [ -z "${hostname}" ] ; then
|
||||
if [ -z "${main_ether}" ] ; then
|
||||
echo "No ethernets found, using localhost"
|
||||
hostname=localhost
|
||||
return
|
||||
fi
|
||||
fetch_hostname ${main_ether}
|
||||
fi
|
||||
|
||||
[ -z "${hostname}" -o "${hostname}" = "." ] && read_address
|
||||
|
||||
fetch_mask ${hostname}-netmask
|
||||
|
||||
eval ifconfig_${main_if}=\" \${hostname} netmask \${mask}\"
|
||||
network_interfaces=`ifconfig -l`
|
||||
}
|
||||
|
||||
# set ifconfig_${interface} for all other interfaces
|
||||
set_all_interfaces() {
|
||||
local i ether hostname mask
|
||||
|
||||
for i in `ifconfig -l` ; do
|
||||
if [ "$i" != "${main_if}" ] ; then
|
||||
get_ether $i
|
||||
fetch_hostname ${ether}
|
||||
fetch_mask ${hostname}-netmask
|
||||
[ -n "${ether}" -a -n "${hostname}" ] && \
|
||||
eval ifconfig_${i}=\" \${hostname} netmask \${mask}\"
|
||||
fi
|
||||
done
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
# Setup system for firewall service, with some sample configurations.
|
||||
# Select one using ${firewall_type} which you can set in /etc/rc.conf.local.
|
||||
#
|
||||
# If you override this file with your own copy, you can use ${hostname}
|
||||
# as the key for the case statement. On entry, the firewall will be flushed
|
||||
# and $fwcmd will point to the appropriate command (usually /sbin/ipfw)
|
||||
#
|
||||
# Sample configurations are:
|
||||
# open - will allow anyone in
|
||||
# client - will try to protect just this machine (should be customized).
|
||||
# simple - will try to protect a whole network (should be customized).
|
||||
# closed - totally disables IP services except via lo0 interface
|
||||
# UNKNOWN - disables the loading of firewall rules.
|
||||
# filename - will load the rules in the given filename (full path required)
|
||||
#
|
||||
|
||||
############
|
||||
# Only in rare cases do you want to change these rules
|
||||
$fwcmd add 1000 pass all from any to any via lo0
|
||||
$fwcmd add 1010 deny all from 127.0.0.0/8 to 127.0.0.0/8
|
||||
|
||||
|
||||
# Prototype setups.
|
||||
case "${firewall_type}" in
|
||||
open|OPEN)
|
||||
$fwcmd add 65000 pass all from any to any
|
||||
;;
|
||||
|
||||
client)
|
||||
|
||||
############
|
||||
# This is a prototype setup that will protect your system somewhat against
|
||||
# people from outside your own network.
|
||||
############
|
||||
|
||||
# set these to your network and netmask and ip
|
||||
net="192.168.4.0"
|
||||
mask="255.255.255.0"
|
||||
ip="192.168.4.17"
|
||||
|
||||
# Allow any traffic to or from my own net.
|
||||
$fwcmd add pass all from ${ip} to ${net}:${mask}
|
||||
$fwcmd add pass all from ${net}:${mask} to ${ip}
|
||||
|
||||
# Allow TCP through if setup succeeded
|
||||
$fwcmd add pass tcp from any to any established
|
||||
|
||||
# Allow setup of incoming email
|
||||
$fwcmd add pass tcp from any to ${ip} 25 setup
|
||||
|
||||
# Allow setup of outgoing TCP connections only
|
||||
$fwcmd add pass tcp from ${ip} to any setup
|
||||
|
||||
# Disallow setup of all other TCP connections
|
||||
$fwcmd add deny tcp from any to any setup
|
||||
|
||||
# Allow DNS queries out in the world
|
||||
$fwcmd add pass udp from any 53 to ${ip}
|
||||
$fwcmd add pass udp from ${ip} to any 53
|
||||
|
||||
# Allow NTP queries out in the world
|
||||
$fwcmd add pass udp from any 123 to ${ip}
|
||||
$fwcmd add pass udp from ${ip} to any 123
|
||||
|
||||
# Everything else is denied as default.
|
||||
$fwcmd add 65000 deny all from any to any
|
||||
;;
|
||||
|
||||
simple)
|
||||
|
||||
############
|
||||
# This is a prototype setup for a simple firewall. Configure this machine
|
||||
# as a named server and ntp server, and point all the machines on the inside
|
||||
# at this machine for those services.
|
||||
############
|
||||
|
||||
# set these to your outside interface network and netmask and ip
|
||||
oif="ed0"
|
||||
onet="192.168.4.0"
|
||||
omask="255.255.255.0"
|
||||
oip="192.168.4.17"
|
||||
|
||||
# set these to your inside interface network and netmask and ip
|
||||
iif="ed1"
|
||||
inet="192.168.3.0"
|
||||
imask="255.255.255.0"
|
||||
iip="192.168.3.17"
|
||||
|
||||
# Stop spoofing
|
||||
$fwcmd add deny all from ${inet}:${imask} to any in via ${oif}
|
||||
$fwcmd add deny all from ${onet}:${omask} to any in via ${iif}
|
||||
|
||||
# Stop RFC1918 nets on the outside interface
|
||||
$fwcmd add deny all from 192.168.0.0:255.255.0.0 to any via ${oif}
|
||||
$fwcmd add deny all from 172.16.0.0:255.240.0.0 to any via ${oif}
|
||||
$fwcmd add deny all from 10.0.0.0:255.0.0.0 to any via ${oif}
|
||||
|
||||
# Allow TCP through if setup succeeded
|
||||
$fwcmd add pass tcp from any to any established
|
||||
|
||||
# Allow setup of incoming email
|
||||
$fwcmd add pass tcp from any to ${oip} 25 setup
|
||||
|
||||
# Allow access to our DNS
|
||||
$fwcmd add pass tcp from any to ${oip} 53 setup
|
||||
|
||||
# Allow access to our WWW
|
||||
$fwcmd add pass tcp from any to ${oip} 80 setup
|
||||
|
||||
# Reject&Log all setup of incoming connections from the outside
|
||||
$fwcmd add deny log tcp from any to any in via ${oif} setup
|
||||
|
||||
# Allow setup of any other TCP connection
|
||||
$fwcmd add pass tcp from any to any setup
|
||||
|
||||
# Allow DNS queries out in the world
|
||||
$fwcmd add pass udp from any 53 to ${oip}
|
||||
$fwcmd add pass udp from ${oip} to any 53
|
||||
|
||||
# Allow NTP queries out in the world
|
||||
$fwcmd add pass udp from any 123 to ${oip}
|
||||
$fwcmd add pass udp from ${oip} to any 123
|
||||
|
||||
# Everything else is denied as default.
|
||||
$fwcmd add 65000 deny all from any to any
|
||||
;;
|
||||
|
||||
UNKNOWN|"")
|
||||
echo "WARNING: firewall rules not loaded."
|
||||
;;
|
||||
|
||||
*) # an absolute pathname ?
|
||||
if [ -f "${firewall_type}" ] ; then
|
||||
$fwcmd ${firewall_type}
|
||||
else
|
||||
echo "WARNING: firewall config script (${firewall_type}) not found,"
|
||||
echo " firewall rules not loaded."
|
||||
fi
|
||||
;;
|
||||
esac
|
@ -1,63 +0,0 @@
|
||||
#!/bin/sh
|
||||
# $FreeBSD$
|
||||
### rc1, next stage 'rc' for PicoBSD -- THIS IS NOT THE NORMAL /etc/rc
|
||||
|
||||
. /etc/rc.conf.defaults # Load default procedures
|
||||
rc_conf_set_defaults # Assign default values to variables.
|
||||
find_system_id # Set $main_eth $main_if
|
||||
set_main_interface # Set ${hostname} and ${ifconfig_${main_if}}
|
||||
set_all_interfaces # Set ${ifconfig_${if}} for other interfaces.
|
||||
|
||||
# Now process local configurations if present. ${hostname} should be set now,
|
||||
# so rc.conf[.local] can make use of a case statement to set per-host things.
|
||||
|
||||
[ -f /etc/rc.conf ] && . /etc/rc.conf
|
||||
[ -f /etc/rc.conf.local ] && . /etc/rc.conf.local
|
||||
|
||||
### Now use some variables to override files in /etc ###
|
||||
( IFS=''
|
||||
[ -n "${host_conf}" ] && echo ${host_conf} > /etc/host.conf
|
||||
[ -n "${resolv_conf}" ] && echo ${resolv_conf} > /etc/resolv.conf
|
||||
[ -n "${rc_local}" ] && echo ${rc_local} > /etc/rc.local
|
||||
unset IFS
|
||||
)
|
||||
|
||||
rm -f /var/run/*
|
||||
if [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
|
||||
echo "Adding $swapfile as additional swap."
|
||||
vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
|
||||
else
|
||||
echo "No swap partition available!"
|
||||
fi
|
||||
# configure serial devices
|
||||
[ -f /etc/rc.serial ] && . /etc/rc.serial
|
||||
|
||||
# start up the initial network configuration.
|
||||
if [ -f /etc/rc.network ]; then
|
||||
. /etc/rc.network
|
||||
network_pass1
|
||||
fi
|
||||
mount -a -t nfs
|
||||
# clean up left-over files
|
||||
(cd /var/run && { cp /dev/null utmp; chmod 644 utmp; })
|
||||
|
||||
[ -n "$network_pass1_done" ] && network_pass2
|
||||
[ -n "$network_pass2_done" ] && network_pass3
|
||||
|
||||
pwd_mkdb -p ./master.passwd
|
||||
|
||||
[ -f /etc/syslog.conf -a -f /stand/syslogd ] && \
|
||||
{ echo "Starting syslogd."; syslogd ${syslogd_flags} ; }
|
||||
|
||||
[ "${inetd_enable}" = "YES" -a -f /stand/inetd ] && \
|
||||
{ echo "Starting inetd."; inetd ${inetd_flags} ; }
|
||||
|
||||
if [ "${sshd_enable}" = "YES" -a -f /usr/sbin/sshd ] ; then
|
||||
echo "Starting sshd..."
|
||||
chmod 600 /etc/ssh_host*key
|
||||
/usr/sbin/sshd -f /etc/sshd_config
|
||||
fi
|
||||
|
||||
echo ''
|
||||
cat /etc/motd
|
||||
exit 0
|
@ -1,58 +0,0 @@
|
||||
# load average checks
|
||||
|
||||
# load [1MAX=DEFMAXLOADAVE] [5MAX=DEFMAXLOADAVE] [15MAX=DEFMAXLOADAVE]
|
||||
#
|
||||
# 1MAX: If the 1 minute load average is above this limit at query
|
||||
# time, the errorFlag will be set.
|
||||
# 5MAX: Similar, but for 5 min average.
|
||||
# 15MAX: Similar, but for 15 min average.
|
||||
|
||||
# Check for loads:
|
||||
load 12 14 14
|
||||
|
||||
# % snmpwalk -v 1 localhost public .1.3.6.1.4.1.2021.10
|
||||
|
||||
# snmp agent errors
|
||||
|
||||
# % snmpwalk -v 1 localhost public .1.3.6.1.4.1.2021.101
|
||||
|
||||
# snmp version mib
|
||||
|
||||
# % snmpwalk -v 1 localhost public .1.3.6.1.4.1.2021.100
|
||||
|
||||
# System contact information
|
||||
|
||||
syslocation PicoBSD
|
||||
syscontact root <root@pico>
|
||||
|
||||
# Setting up the access control lists to the agent
|
||||
|
||||
# sec.name source community
|
||||
com2sec local localhost private
|
||||
com2sec public default public
|
||||
|
||||
# sec.model sec.name
|
||||
group local any local
|
||||
group public any public
|
||||
|
||||
# incl/excl subtree mask
|
||||
view all included .1 80
|
||||
view system included system fe
|
||||
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
|
||||
|
||||
# context sec.model sec.level prefix read write not
|
||||
access public "" any noauth 0 system none none
|
||||
access local "" any noauth 0 all all all
|
||||
|
||||
# If you want to get back to the functionality of previous versions,
|
||||
# where the public community could read anything from anywhere and the
|
||||
# private community could write anything from anywhere, use these
|
||||
# lines instead:
|
||||
#
|
||||
# com2sec public default public
|
||||
# com2sec private default private
|
||||
# group public any public
|
||||
# group private any private
|
||||
# view all included .1 80
|
||||
# access public "" any noauth 0 all none none
|
||||
# access private "" any noauth 0 all all none
|
@ -1,28 +0,0 @@
|
||||
# $FreeBSD$
|
||||
# minimal config for sshd on picobsd
|
||||
Port 22
|
||||
ListenAddress 0.0.0.0
|
||||
HostKey /etc/ssh_host_key
|
||||
#RandomSeed /etc/ssh_random_seed
|
||||
ServerKeyBits 768
|
||||
LoginGraceTime 600
|
||||
KeyRegenerationInterval 3600
|
||||
PermitRootLogin yes
|
||||
IgnoreRhosts no
|
||||
StrictModes yes
|
||||
X11Forwarding no
|
||||
X11DisplayOffset 10
|
||||
PrintMotd yes
|
||||
KeepAlive yes
|
||||
SyslogFacility AUTH
|
||||
RhostsRSAAuthentication yes
|
||||
RSAAuthentication yes
|
||||
PasswordAuthentication yes
|
||||
PermitEmptyPasswords no
|
||||
UseLogin no
|
||||
# CheckMail no
|
||||
# PidFile /u/zappa/.ssh/pid
|
||||
# AllowHosts *.our.com friend.other.com
|
||||
# DenyHosts lowsecurity.theirs.com *.evil.org evil.org
|
||||
# Umask 022
|
||||
# SilentDeny yes
|
@ -1,36 +0,0 @@
|
||||
#
|
||||
# @(#)ttys 5.1 (Berkeley) 4/17/89
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
# name getty type status comments
|
||||
#
|
||||
# This entry needed for asking password when init goes to single-user mode
|
||||
# If you want to be asked for password, change "secure" to "insecure" here
|
||||
#console none unknown off secure
|
||||
vga none xterm off secure
|
||||
#
|
||||
ttyv0 "/usr/libexec/getty Pc" xterm on secure
|
||||
# Virtual terminals
|
||||
ttyv1 "/usr/libexec/getty Pc" xterm on secure
|
||||
ttyv2 "/usr/libexec/getty Pc" xterm on secure
|
||||
ttyv3 "/usr/libexec/getty Pc" xterm on secure
|
||||
ttyv4 "/usr/libexec/getty Pc" xterm on secure
|
||||
ttyv5 "/usr/libexec/getty Pc" xterm on secure
|
||||
ttyv6 "/usr/libexec/getty Pc" xterm on secure
|
||||
ttyv7 "/usr/libexec/getty Pc" xterm on secure
|
||||
#ttyv8 "/usr/libexec/getty Pc" xterm on secure
|
||||
#ttyv9 "/usr/libexec/getty Pc" xterm on secure
|
||||
# Pseudo terminals
|
||||
ttyp0 none network secure
|
||||
ttyp1 none network secure
|
||||
ttyp2 none network secure
|
||||
ttyp3 none network secure
|
||||
ttyp4 none network secure
|
||||
ttyp5 none network secure
|
||||
ttyp6 none network secure
|
||||
ttyp7 none network secure
|
||||
ttyp8 none network secure
|
||||
ttyp9 none network secure
|
||||
ttyu0 "/usr/libexec/getty 3wire" dialup on secure
|
||||
ttyu1 "/usr/libexec/getty 3wire" dialup on secure
|
@ -1,384 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# $OpenBSD: dhclient-script,v 1.6 2004/05/06 18:22:41 claudio Exp $
|
||||
# $FreeBSD$
|
||||
#
|
||||
# Copyright (c) 2003 Kenneth R Westerback <krw@openbsd.org>
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
#
|
||||
#
|
||||
|
||||
ARP=/usr/sbin/arp
|
||||
HOSTNAME=/bin/hostname
|
||||
IFCONFIG='/sbin/ifconfig -n'
|
||||
|
||||
LOCALHOST=127.0.0.1
|
||||
|
||||
if [ -x /usr/bin/logger ]; then
|
||||
LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
|
||||
else
|
||||
LOGGER=echo
|
||||
fi
|
||||
|
||||
#
|
||||
# Helper functions that implement common actions.
|
||||
#
|
||||
|
||||
check_hostname() {
|
||||
current_hostname=`$HOSTNAME`
|
||||
if [ -z "$current_hostname" ]; then
|
||||
$LOGGER "New Hostname ($interface): $new_host_name"
|
||||
$HOSTNAME $new_host_name
|
||||
elif [ "$current_hostname" = "$old_host_name" -a \
|
||||
"$new_host_name" != "$old_host_name" ]; then
|
||||
$LOGGER "New Hostname ($interface): $new_host_name"
|
||||
$HOSTNAME $new_host_name
|
||||
fi
|
||||
}
|
||||
|
||||
arp_flush() {
|
||||
arp -an -i $interface | \
|
||||
sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' | \
|
||||
sh >/dev/null 2>&1
|
||||
}
|
||||
|
||||
delete_old_address() {
|
||||
eval "$IFCONFIG $interface inet -alias $old_ip_address $medium"
|
||||
}
|
||||
|
||||
add_new_address() {
|
||||
eval "$IFCONFIG $interface \
|
||||
inet $new_ip_address \
|
||||
netmask $new_subnet_mask \
|
||||
broadcast $new_broadcast_address \
|
||||
$medium"
|
||||
|
||||
$LOGGER "New IP Address ($interface): $new_ip_address"
|
||||
$LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
|
||||
$LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
|
||||
$LOGGER "New Routers ($interface): $new_routers"
|
||||
}
|
||||
|
||||
delete_old_alias() {
|
||||
if [ -n "$alias_ip_address" ]; then
|
||||
$IFCONFIG $interface inet -alias $alias_ip_address > /dev/null 2>&1
|
||||
#route delete $alias_ip_address $LOCALHOST > /dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
add_new_alias() {
|
||||
if [ -n "$alias_ip_address" ]; then
|
||||
$IFCONFIG $interface inet alias $alias_ip_address netmask \
|
||||
$alias_subnet_mask
|
||||
#route add $alias_ip_address $LOCALHOST
|
||||
fi
|
||||
}
|
||||
|
||||
fill_classless_routes() {
|
||||
set $1
|
||||
while [ $# -ge 5 ]; do
|
||||
if [ $1 -eq 0 ]; then
|
||||
route="default"
|
||||
elif [ $1 -le 8 ]; then
|
||||
route="$2.0.0.0/$1"
|
||||
shift
|
||||
elif [ $1 -le 16 ]; then
|
||||
route="$2.$3.0.0/$1"
|
||||
shift; shift
|
||||
elif [ $1 -le 24 ]; then
|
||||
route="$2.$3.$4.0/$1"
|
||||
shift; shift; shift
|
||||
else
|
||||
route="$2.$3.$4.$5/$1"
|
||||
shift; shift; shift; shift
|
||||
fi
|
||||
shift
|
||||
router="$1.$2.$3.$4"
|
||||
classless_routes="$classless_routes $route $router"
|
||||
shift; shift; shift; shift
|
||||
done
|
||||
}
|
||||
|
||||
delete_old_routes() {
|
||||
#route delete "$old_ip_address" $LOCALHOST >/dev/null 2>&1
|
||||
if [ -n "$old_classless_routes" ]; then
|
||||
fill_classless_routes "$old_classless_routes"
|
||||
set $classless_routes
|
||||
while [ $# -gt 1 ]; do
|
||||
route delete "$1" "$2"
|
||||
shift; shift
|
||||
done
|
||||
return 0;
|
||||
fi
|
||||
|
||||
# If we supported multiple default routes, we'd be removing each
|
||||
# one here. We don't so just delete the default route if it's
|
||||
# through our interface.
|
||||
if is_default_interface; then
|
||||
route delete default >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
if [ -n "$old_static_routes" ]; then
|
||||
set $old_static_routes
|
||||
while [ $# -gt 1 ]; do
|
||||
route delete "$1" "$2"
|
||||
shift; shift
|
||||
done
|
||||
fi
|
||||
|
||||
arp_flush
|
||||
}
|
||||
|
||||
add_new_routes() {
|
||||
#route add $new_ip_address $LOCALHOST >/dev/null 2>&1
|
||||
|
||||
# RFC 3442: If the DHCP server returns both a Classless Static
|
||||
# Routes option and a Router option, the DHCP client MUST ignore
|
||||
# the Router option.
|
||||
#
|
||||
# DHCP clients that support this option (Classless Static Routes)
|
||||
# MUST NOT install the routes specified in the Static Routes
|
||||
# option (option code 33) if both a Static Routes option and the
|
||||
# Classless Static Routes option are provided.
|
||||
|
||||
if [ -n "$new_classless_routes" ]; then
|
||||
fill_classless_routes "$new_classless_routes"
|
||||
$LOGGER "New Classless Static Routes ($interface): $classless_routes"
|
||||
set $classless_routes
|
||||
while [ $# -gt 1 ]; do
|
||||
if [ "0.0.0.0" = "$2" ]; then
|
||||
route add "$1" -iface "$interface"
|
||||
else
|
||||
route add "$1" "$2"
|
||||
fi
|
||||
shift; shift
|
||||
done
|
||||
return
|
||||
fi
|
||||
|
||||
for router in $new_routers; do
|
||||
if is_default_interface; then
|
||||
|
||||
if [ "$new_ip_address" = "$router" ]; then
|
||||
route add default -iface $router >/dev/null 2>&1
|
||||
else
|
||||
route add default $router >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
# 2nd and subsequent default routers error out, so explicitly
|
||||
# stop processing the list after the first one.
|
||||
break
|
||||
done
|
||||
|
||||
if [ -n "$new_static_routes" ]; then
|
||||
$LOGGER "New Static Routes ($interface): $new_static_routes"
|
||||
set $new_static_routes
|
||||
while [ $# -gt 1 ]; do
|
||||
route add $1 $2
|
||||
shift; shift
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
add_new_resolv_conf() {
|
||||
# XXX Old code did not create/update resolv.conf unless both
|
||||
# $new_domain_name and $new_domain_name_servers were provided. PR
|
||||
# #3135 reported some ISP's only provide $new_domain_name_servers and
|
||||
# thus broke the script. This code creates the resolv.conf if either
|
||||
# are provided.
|
||||
|
||||
local tmpres=/var/run/resolv.conf.${interface}
|
||||
rm -f $tmpres
|
||||
|
||||
if [ -n "$new_domain_name" ]; then
|
||||
echo "search $new_domain_name" >>$tmpres
|
||||
fi
|
||||
|
||||
if [ -n "$new_domain_name_servers" ]; then
|
||||
for nameserver in $new_domain_name_servers; do
|
||||
echo "nameserver $nameserver" >>$tmpres
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -f $tmpres ]; then
|
||||
if [ -f /etc/resolv.conf.tail ]; then
|
||||
cat /etc/resolv.conf.tail >>$tmpres
|
||||
fi
|
||||
|
||||
# When resolv.conf is not changed actually, we don't
|
||||
# need to update it.
|
||||
# If /usr is not mounted yet, we cannot use cmp, then
|
||||
# the following test fails. In such case, we simply
|
||||
# ignore an error and do update resolv.conf.
|
||||
if cmp -s $tmpres /etc/resolv.conf; then
|
||||
rm -f $tmpres
|
||||
return 0
|
||||
fi 2>/dev/null
|
||||
|
||||
# In case (e.g. during OpenBSD installs) /etc/resolv.conf
|
||||
# is a symbolic link, take care to preserve the link and write
|
||||
# the new data in the correct location.
|
||||
|
||||
if [ -f /etc/resolv.conf ]; then
|
||||
cat /etc/resolv.conf > /etc/resolv.conf.save
|
||||
fi
|
||||
cat $tmpres > /etc/resolv.conf
|
||||
rm -f $tmpres
|
||||
|
||||
# Try to ensure correct ownership and permissions.
|
||||
chown -RL root:wheel /etc/resolv.conf
|
||||
chmod -RL 644 /etc/resolv.conf
|
||||
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
|
||||
exit_with_hooks() {
|
||||
exit_status=$1
|
||||
if [ -f /etc/dhclient-exit-hooks ]; then
|
||||
. /etc/dhclient-exit-hooks
|
||||
fi
|
||||
# probably should do something with exit status of the local script
|
||||
exit $exit_status
|
||||
}
|
||||
|
||||
# Get the interface with the current ipv4 default route on it using only
|
||||
# commands that are available prior to /usr being mounted.
|
||||
is_default_interface()
|
||||
{
|
||||
routeget="`route -n get -inet default`"
|
||||
oldifs="$IFS"
|
||||
IFS="
|
||||
"
|
||||
defif=
|
||||
for line in $routeget ; do
|
||||
case $line in
|
||||
*interface:*)
|
||||
defif=${line##*: }
|
||||
;;
|
||||
esac
|
||||
done
|
||||
IFS=${oldifs}
|
||||
|
||||
if [ -z "$defif" -o "$defif" = "$interface" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Start of active code.
|
||||
#
|
||||
|
||||
# Invoke the local dhcp client enter hooks, if they exist.
|
||||
if [ -f /etc/dhclient-enter-hooks ]; then
|
||||
exit_status=0
|
||||
. /etc/dhclient-enter-hooks
|
||||
# allow the local script to abort processing of this state
|
||||
# local script must set exit_status variable to nonzero.
|
||||
if [ $exit_status -ne 0 ]; then
|
||||
exit $exit_status
|
||||
fi
|
||||
fi
|
||||
|
||||
case $reason in
|
||||
MEDIUM)
|
||||
eval "$IFCONFIG $interface $medium"
|
||||
eval "$IFCONFIG $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
|
||||
sleep 1
|
||||
;;
|
||||
|
||||
PREINIT)
|
||||
delete_old_alias
|
||||
$IFCONFIG $interface inet alias 0.0.0.0 netmask 0.0.0.0 broadcast 255.255.255.255 up
|
||||
;;
|
||||
|
||||
ARPCHECK|ARPSEND)
|
||||
;;
|
||||
|
||||
BOUND|RENEW|REBIND|REBOOT)
|
||||
check_hostname
|
||||
if [ -n "$old_ip_address" ]; then
|
||||
if [ "$old_ip_address" != "$alias_ip_address" ]; then
|
||||
delete_old_alias
|
||||
fi
|
||||
if [ "$old_ip_address" != "$new_ip_address" ]; then
|
||||
delete_old_address
|
||||
delete_old_routes
|
||||
fi
|
||||
fi
|
||||
if [ "$reason" = BOUND ] || \
|
||||
[ "$reason" = REBOOT ] || \
|
||||
[ -z "$old_ip_address" ] || \
|
||||
[ "$old_ip_address" != "$new_ip_address" ]; then
|
||||
add_new_address
|
||||
add_new_routes
|
||||
fi
|
||||
if [ "$new_ip_address" != "$alias_ip_address" ]; then
|
||||
add_new_alias
|
||||
fi
|
||||
if is_default_interface; then
|
||||
add_new_resolv_conf
|
||||
fi
|
||||
;;
|
||||
|
||||
EXPIRE|FAIL)
|
||||
delete_old_alias
|
||||
if [ -n "$old_ip_address" ]; then
|
||||
delete_old_address
|
||||
delete_old_routes
|
||||
fi
|
||||
if [ -x $ARP ]; then
|
||||
$ARP -d -a -i $interface
|
||||
fi
|
||||
# XXX Why add alias we just deleted above?
|
||||
add_new_alias
|
||||
if is_default_interface; then
|
||||
if [ -f /etc/resolv.conf.save ]; then
|
||||
cat /etc/resolv.conf.save > /etc/resolv.conf
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
|
||||
TIMEOUT)
|
||||
delete_old_alias
|
||||
add_new_address
|
||||
sleep 1
|
||||
if [ -n "$new_routers" ]; then
|
||||
$LOGGER "New Routers ($interface): $new_routers"
|
||||
set "$new_routers"
|
||||
if ping -q -c 1 -t 1 "$1"; then
|
||||
if [ "$new_ip_address" != "$alias_ip_address" ]; then
|
||||
add_new_alias
|
||||
fi
|
||||
add_new_routes
|
||||
if ! is_default_interface; then
|
||||
exit_with_hooks 0
|
||||
fi
|
||||
if add_new_resolv_conf; then
|
||||
exit_with_hooks 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
eval "$IFCONFIG $interface inet -alias $new_ip_address $medium"
|
||||
delete_old_routes
|
||||
exit_with_hooks 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit_with_hooks 0
|
@ -1,85 +0,0 @@
|
||||
# $FreeBSD$
|
||||
# Floppy formats:
|
||||
#
|
||||
# To make a filesystem on a floppy:
|
||||
# fdformat [-f <size>] fd<drive>[.<size>]
|
||||
# disklabel -B -r -w fd<drive>[.<size>] fd<size>
|
||||
# newfs <opts> fd<drive>[.<size>]
|
||||
#
|
||||
# with <opts>:
|
||||
# -t 2 - two heads
|
||||
# -u 9|15|18 - sectors per track
|
||||
# (using the default value of 1/4096 is not much useful for floppies)
|
||||
# -l 1 - interleave 1 (for most floppies)
|
||||
# -i 65536 - bytes of data per i-node
|
||||
# (the default -i value will render you with a floppy wasting way
|
||||
# too much space in i-node areas)
|
||||
|
||||
fd360:\
|
||||
:ty=floppy:se#512:nt#2:rm#300:ns#9:nc#40:\
|
||||
:pa#720:oa#0:ba#4096:fa#512:\
|
||||
:pb#720:ob#0:bb#4096:fb#512:\
|
||||
:pc#720:oc#0:bc#4096:fc#512:
|
||||
|
||||
fd720:\
|
||||
:ty=floppy:se#512:nt#2:rm#300:ns#9:nc#80:\
|
||||
:pa#1440:oa#0:ba#4096:fa#512:\
|
||||
:pb#1440:ob#0:bb#4096:fb#512:\
|
||||
:pc#1440:oc#0:bc#4096:fc#512:
|
||||
|
||||
fd1200|floppy5|5in|5.25in High Density Floppy:\
|
||||
:ty=floppy:se#512:nt#2:rm#360:ns#15:nc#80:\
|
||||
:pa#2400:oa#0:ba#4096:fa#512:\
|
||||
:pb#2400:ob#0:bb#4096:fb#512:\
|
||||
:pc#2400:oc#0:bc#4096:fc#512:
|
||||
|
||||
fd1440|floppy|floppy3|3in|3.5in High Density Floppy:\
|
||||
:ty=floppy:se#512:nt#2:rm#300:ns#18:nc#80:\
|
||||
:pa#2880:oa#0:ba#4096:fa#512:\
|
||||
:pb#2880:ob#0:bb#4096:fb#512:\
|
||||
:pc#2880:oc#0:bc#4096:fc#512:
|
||||
|
||||
fd1024|floppy0|3.5in Special Density Floppy:\
|
||||
:ty=floppy:se#512:nt#2:rm#300:ns#16:nc#64:\
|
||||
:pa#2048:oa#0:ba#4096:fa#512:\
|
||||
:pb#2048:ob#0:bb#4096:fb#512:\
|
||||
:pc#2048:oc#0:bc#4096:fc#512:
|
||||
|
||||
# a == root
|
||||
# b == swap
|
||||
# c == d == whole disk
|
||||
# e == /var
|
||||
# f == scratch
|
||||
# h == /usr
|
||||
|
||||
cp3100new|Connor Peripherals 100MB IDE, with a different configuration:\
|
||||
:dt=ST506:ty=winchester:se#512:nt#8:ns#33:nc#766: \
|
||||
:pa#15840:oa#0:ta=4.2BSD:ba#4096:fa#512: \
|
||||
:pb#24288:ob#15840:tb=swap: \
|
||||
:pc#202224:oc#0: \
|
||||
:pd#202224:od#0: \
|
||||
:pe#15840:oe#40128:te=4.2BSD:be#4096:fe#512: \
|
||||
:pg#15840:og#55968:tg=4.2BSD:bg#4096:fg#512: \
|
||||
:ph#130416:oh#71808:th=4.2BSD:bh#4096:fh#512:
|
||||
|
||||
sony650|Sony 650 MB MOD|\
|
||||
:ty=removable:dt=SCSI:se#512:nt#1:ns#31:nc#18600:ts#1:rm#4800:\
|
||||
:pc#576600:oc#0:\
|
||||
:pa#576600:oa#0:ta=4.2BSD:ba#8192:fa#1024:
|
||||
|
||||
mta3230|mo230|IBM MTA-3230 230 Meg 3.5inch Magneto-Optical:\
|
||||
:ty=removeable:dt=SCSI:rm#3600:\
|
||||
:se#512:nt#64:ns#32:nc#216:sc#2048:su#444384:\
|
||||
:pa#444384:oa#0:ba#4096:fa#0:ta=4.2BSD:\
|
||||
:pc#444384:oc#0:
|
||||
|
||||
minimum:ty=mfs:se#512:nt#1:rm#300:\
|
||||
:ns#2880:nc#1:\
|
||||
:pa#2880:oa#0:ba#4096:fa#512:\
|
||||
:pc#2880:oc#0:bc#4096:fc#512:
|
||||
|
||||
zip100|zip 100:\
|
||||
:ty=removable:se#512:nc#96:nt#64:ns#32:\
|
||||
:pa#196608:oa#0:ba#4096:fa#512:\
|
||||
:pb#196608:ob#0:bb#4096:fb#512:\
|
||||
:pc#196608:oc#0:bc#4096:fc#512:
|
@ -1,42 +0,0 @@
|
||||
# $FreeBSD$
|
||||
# from: @(#)gettytab 5.14 (Berkeley) 3/27/91
|
||||
#
|
||||
default:\
|
||||
:cb:ce:ck:lc:fd#1000:cl:im=\r\nPicoBSD (%h) (%t)\r\n\r\n:sp#1200:
|
||||
|
||||
# 20140527 add nc (no carrier) to the pc console entry to fix
|
||||
# devices with no handshake after svn 264175 (this also affects bhyve)
|
||||
P|Pc|Pc console|3wire:\
|
||||
:nc:\
|
||||
:ht:np:sp#115200:
|
||||
|
||||
# Fixed speed entries
|
||||
2|std.9600|9600-baud:\
|
||||
:nc:np:sp#9600:
|
||||
g|std.19200|19200-baud:\
|
||||
:np:sp#19200:
|
||||
std.38400|38400-baud:\
|
||||
:np:sp#38400:
|
||||
std.57600|57600-baud:\
|
||||
:np:sp#57600:
|
||||
std.115200|115200-baud:\
|
||||
:np:sp#115200:
|
||||
|
||||
# Entry specifying explicit device settings. See termios(4) and
|
||||
# /usr/include/termios.h, too. The entry forces the tty into
|
||||
# CLOCAL mode (so no DCD is required), and uses Xon/Xoff flow control.
|
||||
#
|
||||
# cflags: CLOCAL | HUPCL | CREAD | CS8
|
||||
# oflags: OPOST | ONLCR | OXTABS
|
||||
# iflags: IXOFF | IXON | ICRNL | IGNPAR
|
||||
# lflags: IEXTEN | ICANON | ISIG | ECHOCTL | ECHO | ECHOK | ECHOE | ECHOKE
|
||||
#
|
||||
# The `0' flags don't have input enabled. The `1' flags don't echo.
|
||||
# (Echoing is done inside getty itself.)
|
||||
#
|
||||
local.9600|CLOCAL tty @ 9600 Bd:\
|
||||
:c0#0x0000c300:c1#0x0000cb00:c2#0x0000cb00:\
|
||||
:o0#0x00000007:o1#0x00000002:o2#0x00000007:\
|
||||
:i0#0x00000704:i1#0x00000000:i2#0x00000704:\
|
||||
:l0#0x000005cf:l1#0x00000000:l2#0x000005cf:\
|
||||
:sp#9600:
|
@ -1,19 +0,0 @@
|
||||
wheel:*:0:root,user
|
||||
daemon:*:1:daemon
|
||||
kmem:*:2:root
|
||||
sys:*:3:root
|
||||
tty:*:4:root
|
||||
operator:*:5:root
|
||||
mail:*:6:
|
||||
bin:*:7:
|
||||
news:*:8:
|
||||
man:*:9:
|
||||
games:*:13:
|
||||
staff:*:20:root,user
|
||||
guest:*:31:root
|
||||
uucp:*:66:
|
||||
xten:*:67:xten
|
||||
dialer:*:68:
|
||||
network:*:69:
|
||||
nogroup:*:65533:
|
||||
nobody:*:65534:
|
@ -1,118 +0,0 @@
|
||||
# This file controls resource limits, accounting limits and
|
||||
# default user environment settings.
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
|
||||
|
||||
# Authentication methods
|
||||
|
||||
auth-defaults:\
|
||||
:auth=passwd:
|
||||
|
||||
auth-root-defaults:\
|
||||
:auth-login=passwd:\
|
||||
:auth-rlogin=passwd:\
|
||||
|
||||
auth-ftp-defaults:\
|
||||
:auth=passwd:
|
||||
|
||||
# Example defaults
|
||||
# These settings are used by login(1) by default for classless users
|
||||
# Note that entries like "cputime" set both "cputime-cur" and "cputime-max"
|
||||
|
||||
default:\
|
||||
:cputime=infinity:\
|
||||
:datasize-cur=22M:\
|
||||
:stacksize-cur=8M:\
|
||||
:memorylocked-cur=10M:\
|
||||
:memoryuse-cur=30M:\
|
||||
:filesize=infinity:\
|
||||
:coredumpsize=0:\
|
||||
:maxproc-cur=64:\
|
||||
:openfiles-cur=64:\
|
||||
:priority=0:\
|
||||
:requirehome@:\
|
||||
:umask=022:\
|
||||
:tc=auth-defaults:
|
||||
|
||||
# standard - standard user defaults
|
||||
#
|
||||
standard:\
|
||||
:copyright=/etc/COPYRIGHT:\
|
||||
:welcome=/etc/motd:\
|
||||
:setenv=MAIL=/var/mail/$,BLOCKSIZE=K,EDITOR=/usr/bin/ee:\
|
||||
:path=~/bin /bin /usr/bin:\
|
||||
:nologin=/var/run/nologin:\
|
||||
:cputime=1h30m:\
|
||||
:datasize=8M:\
|
||||
:stacksize=2M:\
|
||||
:memorylocked=4M:\
|
||||
:memoryuse=8M:\
|
||||
:filesize=8M:\
|
||||
:coredumpsize=0:\
|
||||
:openfiles=24:\
|
||||
:maxproc=32:\
|
||||
:priority=0:\
|
||||
:requirehome:\
|
||||
:passwordtime=90d:\
|
||||
:umask=002:\
|
||||
:ignoretime@:\
|
||||
:tc=default:
|
||||
#
|
||||
# Staff users - few restrictions and allow login anytime
|
||||
#
|
||||
staff:\
|
||||
:ignorenologin:\
|
||||
:ignoretime:\
|
||||
:requirehome@:\
|
||||
:accounted@:\
|
||||
:path=~/bin /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin:\
|
||||
:umask=022:\
|
||||
:tc=standard:
|
||||
|
||||
|
||||
#
|
||||
# root - fallback for root logins
|
||||
#
|
||||
root:\
|
||||
:path=~/bin /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin:\
|
||||
:cputime=infinity:\
|
||||
:datasize=infinity:\
|
||||
:stacksize=infinity:\
|
||||
:memorylocked=infinity:\
|
||||
:memoryuse=infinity:\
|
||||
:filesize=infinity:\
|
||||
:coredumpsize=0:\
|
||||
:openfiles=infinity:\
|
||||
:maxproc=infinity:\
|
||||
:memoryuse-cur=32M:\
|
||||
:maxproc-cur=64:\
|
||||
:openfiles-cur=1024:\
|
||||
:priority=0:\
|
||||
:requirehome@:\
|
||||
:umask=022:\
|
||||
:tc=auth-root-defaults:\
|
||||
#
|
||||
# Settings used by /etc/rc
|
||||
#
|
||||
daemon:\
|
||||
:coredumpsize@:\
|
||||
:coredumpsize-cur=0:\
|
||||
:datasize=infinity:\
|
||||
:datasize-cur@:\
|
||||
:maxproc=512:\
|
||||
:maxproc-cur@:\
|
||||
:memoryuse-cur=64M:\
|
||||
:memorylocked-cur=64M:\
|
||||
:openfiles=1024:\
|
||||
:openfiles-cur@:\
|
||||
:stacksize=16M:\
|
||||
:stacksize-cur@:\
|
||||
:tc=default:
|
||||
#
|
||||
# Polish Users Accounts. Setup proper environment variables.
|
||||
#
|
||||
polish:Polish Users Accounts:\
|
||||
:lang=pl_pl.ISO-8859-2:\
|
||||
:tc=default:
|
@ -1,9 +0,0 @@
|
||||
==============================================================
|
||||
|
||||
[31m)\_)\[37m Welcome to PicoBSD
|
||||
[31m([37m[1mo,o[m[31m)[37m
|
||||
[32m__ [31m\~/[37m
|
||||
[32m-->=[41m===[0m[31m\[37m
|
||||
[32m~~[37m [31md d[37m
|
||||
|
||||
==============================================================
|
@ -1,14 +0,0 @@
|
||||
# $FreeBSD$
|
||||
# Internet (IP) protocols
|
||||
ip 0 IP # internet protocol, pseudo protocol number
|
||||
icmp 1 ICMP # internet control message protocol
|
||||
igmp 2 IGMP # Internet Group Management
|
||||
tcp 6 TCP # transmission control protocol
|
||||
udp 17 UDP # user datagram protocol
|
||||
ipv6 41 IPV6 # ipv6
|
||||
gre 47 GRE # Generic Routing Encapsulation
|
||||
ah 51 AH # authentication header
|
||||
ospf 89 OSPFIGP # Open Shortest Path First IGP
|
||||
pim 103 PIM # Protocol Independent Multicast
|
||||
vrrp 112 VRRP # Virtual Router Redundancy Protocol
|
||||
pgm 113 PGM # PGM
|
@ -1,27 +0,0 @@
|
||||
#!/bin/sh
|
||||
# $FreeBSD$
|
||||
|
||||
stty status '^T'
|
||||
trap : 2
|
||||
trap : 3
|
||||
|
||||
HOME=/; export HOME
|
||||
PATH=/bin; export PATH
|
||||
dev=`sysctl -n machdep.guessed_bootdev`
|
||||
[ -c "${dev}" ] || dev="/dev/fd0"
|
||||
|
||||
trap "echo 'Reboot interrupted'; exit 1" 3
|
||||
set `df /`; mount -u $8 / # upgrade mount to rw
|
||||
echo "Loading /etc from MFS:/fd ..."
|
||||
cp -Rp /fd/* /
|
||||
echo "Updating /etc from ${dev}..."
|
||||
mount -o rdonly ${dev} /fd && \
|
||||
{ cd /fd; cp -Rp etc root / ; cd / ; umount /fd ; }
|
||||
cd /etc
|
||||
#rm files to stop overwrite warning
|
||||
for i in *; do
|
||||
[ -f $i.gz ] && rm $i
|
||||
done
|
||||
gzip -d *.gz
|
||||
. /etc/rc1
|
||||
exit 0
|
@ -1,83 +0,0 @@
|
||||
#!/bin/sh -
|
||||
# $FreeBSD$
|
||||
|
||||
network_pass1() {
|
||||
echo -n 'Doing initial network setup:'
|
||||
# Set the host name if it is not already set
|
||||
if [ -z "`hostname -s`" ] ; then
|
||||
hostname $hostname
|
||||
echo ' hostname'
|
||||
fi
|
||||
# Set up all the network interfaces, calling startup scripts if needed
|
||||
for ifn in ${network_interfaces}; do
|
||||
[ -e /etc/start_if.${ifn} ] && . /etc/start_if.${ifn}
|
||||
# Do the primary ifconfig if specified
|
||||
eval ifconfig_args=\$ifconfig_${ifn}
|
||||
[ -n "${ifconfig_args}" ] && ifconfig ${ifn} ${ifconfig_args}
|
||||
# Check to see if aliases need to be added
|
||||
alias=0
|
||||
while :
|
||||
do
|
||||
eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
|
||||
if [ -n "${ifconfig_args}" ]; then
|
||||
ifconfig ${ifn} ${ifconfig_args} alias
|
||||
alias=$((${alias} + 1))
|
||||
else
|
||||
break;
|
||||
fi
|
||||
done
|
||||
ifconfig ${ifn}
|
||||
done
|
||||
# Load the filters if required
|
||||
if [ -f /etc/rc.firewall -a "${firewall_enable}" = "YES" ] ; then
|
||||
# Set quiet mode if requested
|
||||
if [ "${firewall_quiet}" = "YES" ]; then
|
||||
fwcmd="/sbin/ipfw -q"
|
||||
else
|
||||
fwcmd="/sbin/ipfw"
|
||||
fi
|
||||
$fwcmd -f flush # Flush out the list before we begin.
|
||||
|
||||
. /etc/rc.firewall
|
||||
echo "Firewall rules loaded."
|
||||
else
|
||||
echo "Warning: kernel has firewall functionality, but firewall rules weren't loaded."
|
||||
echo " All ip services are ENABLED by default."
|
||||
fi
|
||||
# Configure routing
|
||||
if [ "x$defaultrouter" != "xNO" ] ; then
|
||||
static_routes="default ${static_routes}"
|
||||
route_default="default ${defaultrouter}"
|
||||
fi
|
||||
# Set up any static routes. This should be done before router discovery.
|
||||
if [ "x${static_routes}" != "x" ]; then
|
||||
for i in ${static_routes}; do
|
||||
eval route_args=\$route_${i}
|
||||
route add ${route_args}
|
||||
done
|
||||
fi
|
||||
echo -n 'Additional routing options:'
|
||||
if [ -n "$tcp_extensions" -a "x$tcp_extensions" != "xYES" ] ; then
|
||||
echo -n ' tcp_extensions=NO'
|
||||
sysctl net.inet.tcp.rfc1323=0 >/dev/null 2>&1
|
||||
sysctl net.inet.tcp.rfc1644=0 >/dev/null 2>&1
|
||||
fi
|
||||
if [ "X$gateway_enable" = X"YES" ]; then
|
||||
echo -n ' IP_gateway=YES'
|
||||
sysctl net.inet.ip.forwarding=1 >/dev/null 2>&1
|
||||
fi
|
||||
if [ "X$arpproxy_all" = X"YES" ]; then
|
||||
echo -n ' turning on ARP_PROXY_ALL: '
|
||||
sysctl net.link.ether.inet.proxyall=1 2>&1
|
||||
fi
|
||||
echo '.'
|
||||
network_pass1_done=YES # Let future generations know we made it.
|
||||
}
|
||||
|
||||
network_pass2() {
|
||||
network_pass2_done=YES
|
||||
}
|
||||
|
||||
network_pass3() {
|
||||
network_pass3_done=YES
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
#!/bin/sh
|
||||
# $FreeBSD$
|
||||
|
||||
# Change some defaults for serial devices.
|
||||
# Standard defaults are:
|
||||
# dtrwait 300 drainwait 0
|
||||
# initial cflag from <sys/ttydefaults.h> = cread cs8 hupcl
|
||||
# initial iflag, lflag and oflag all 0
|
||||
# speed 9600
|
||||
# special chars from <sys/ttydefaults.h>
|
||||
# nothing locked
|
||||
# except for serial consoles the initial iflag, lflag and oflag are from
|
||||
# <sys/ttydefaults.h> and clocal is locked on.
|
||||
|
||||
default() {
|
||||
# Reset everything changed by the other functions to initial defaults.
|
||||
|
||||
ci=$1; shift # call in device identifier
|
||||
co=$1; shift # call out device identifier
|
||||
|
||||
for i in $*
|
||||
do
|
||||
comcontrol /dev/tty$ci$i dtrwait 300 drainwait 0
|
||||
stty </dev/ttyi$ci$i -clocal crtscts hupcl 9600 reprint ^R
|
||||
stty </dev/ttyl$ci$i -clocal -crtscts -hupcl 0
|
||||
stty </dev/cuai$co$i -clocal crtscts hupcl 9600 reprint ^R
|
||||
stty </dev/cual$co$i -clocal -crtscts -hupcl 0
|
||||
done
|
||||
}
|
||||
|
||||
maybe() {
|
||||
# Special settings.
|
||||
|
||||
ci=$1; shift
|
||||
co=$1; shift
|
||||
|
||||
for i in $*
|
||||
do
|
||||
# Don't use ^R; it breaks bash's ^R when typed ahead.
|
||||
stty </dev/ttyi$ci$i reprint undef
|
||||
stty </dev/cuai$co$i reprint undef
|
||||
# Lock clocal off on dialin device for security.
|
||||
stty </dev/ttyl$ci$i clocal
|
||||
# Lock the speeds to use old binaries that don't support them.
|
||||
# Any legal speed works to lock the initial speed.
|
||||
stty </dev/ttyl$ci$i 300
|
||||
stty </dev/cual$co$i 300
|
||||
done
|
||||
}
|
||||
|
||||
modem() {
|
||||
# Modem that supports CTS and perhaps RTS handshaking.
|
||||
|
||||
ci=$1; shift
|
||||
co=$1; shift
|
||||
|
||||
for i in $*
|
||||
do
|
||||
# may depend on modem
|
||||
comcontrol /dev/tty$ci$i dtrwait 100 drainwait 180
|
||||
# Lock crtscts on.
|
||||
# Speed reasonable for V42bis.
|
||||
stty </dev/ttyi$ci$i crtscts 57600
|
||||
stty </dev/ttyl$ci$i crtscts
|
||||
stty </dev/cuai$co$i crtscts 57600
|
||||
stty </dev/cual$co$i crtscts
|
||||
done
|
||||
}
|
||||
|
||||
mouse() {
|
||||
# Mouse on either callin or callout port.
|
||||
|
||||
ci=$1; shift
|
||||
co=$1; shift
|
||||
|
||||
for i in $*
|
||||
do
|
||||
# Lock clocal on, hupcl off.
|
||||
# Standard speed for Microsoft mouse.
|
||||
stty </dev/ttyi$ci$i clocal -hupcl 1200
|
||||
stty </dev/ttyl$ci$i clocal hupcl
|
||||
stty </dev/cuai$co$i clocal -hupcl 1200
|
||||
stty </dev/cual$co$i clocal hupcl
|
||||
done
|
||||
}
|
||||
|
||||
terminal() {
|
||||
# Terminal that supports CTS and perhaps RTS handshaking
|
||||
# with the cable or terminal arranged so that DCD is on
|
||||
# at least while the terminal is on.
|
||||
# Also works for bidirectional communications to another pc
|
||||
# provided at most one side runs getty.
|
||||
# Same as modem() except we want a faster speed and no dtrwait.
|
||||
|
||||
ci=$1; shift
|
||||
co=$1; shift
|
||||
|
||||
modem $ci $co $*
|
||||
for i in $*
|
||||
do
|
||||
comcontrol /dev/tty$ci$i dtrwait 0
|
||||
stty </dev/ttyi$ci$i 115200
|
||||
stty </dev/cuai$co$i 115200
|
||||
done
|
||||
}
|
||||
|
||||
# Don't use anything from this file unless you have some buggy programs
|
||||
# that require it.
|
||||
|
||||
# Edit the functions and the examples to suit your system.
|
||||
# $1 is the call in device identifier, $2 is the call out device identifier
|
||||
# and the remainder of the line lists the device numbers.
|
||||
|
||||
# Initialize assorted 8250-16550 (sio) ports.
|
||||
# maybe d a 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v
|
||||
# mouse d a 2
|
||||
# modem d a 1
|
||||
# terminal d a 0
|
||||
|
||||
# Initialize all ports on a Cyclades-8yo.
|
||||
# modem c c 00 01 02 03 04 05 06 07
|
||||
|
||||
# Initialize all ports on a Cyclades-16ye.
|
||||
# modem c c 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
|
||||
|
||||
# Initialize all ports on a Digiboard 8.
|
||||
# modem D D 00 01 02 03 04 05 06 07
|
@ -1,50 +0,0 @@
|
||||
# @(#)remote 5.2 (Berkeley) 6/30/90
|
||||
# $FreeBSD$
|
||||
# remote -- remote host description file
|
||||
# see tip(1), remote(5)
|
||||
#
|
||||
# dv device to use for the tty
|
||||
# el EOL marks (default is NULL)
|
||||
# du make a call flag (dial up)
|
||||
# pn phone numbers (@ =>'s search phones file; possibly taken from
|
||||
# PHONES environment variable)
|
||||
# at ACU type
|
||||
# ie input EOF marks (default is NULL)
|
||||
# oe output EOF string (default is NULL)
|
||||
# cu call unit (default is dv)
|
||||
# br baud rate (defaults to 300)
|
||||
# fs frame size (default is BUFSIZ) -- used in buffering writes on
|
||||
# receive operations
|
||||
# tc to continue a capability
|
||||
|
||||
# Systems definitions
|
||||
netcom|Netcom Unix Access:\
|
||||
:pn=\@:tc=unix1200:
|
||||
omen|Omen BBS:\
|
||||
:pn=\@:tc=dos1200:
|
||||
|
||||
# UNIX system definitions
|
||||
unix1200|1200 Baud dial-out to a UNIX system:\
|
||||
:el=^U^C^R^O^D^S^Q:ie=%$:oe=^D:tc=dial1200:
|
||||
unix300|300 Baud dial-out to a UNIX system:\
|
||||
:el=^U^C^R^O^D^S^Q:ie=%$:oe=^D:tc=dial300:
|
||||
|
||||
# DOS system definitions
|
||||
dos1200|1200 Baud dial-out to a DOS system:\
|
||||
:el=^U^C^R^O^D^S^Q:ie=%$:oe=^Z:pa=none:tc=dial1200:
|
||||
|
||||
# General dialer definitions used below
|
||||
#
|
||||
# COURIER switch settings:
|
||||
# switch: 1 2 3 4 5 6 7 8 9 10
|
||||
# setting: D U D U D D U D U U
|
||||
# Rackmount: U U D U D U D D U D
|
||||
#
|
||||
dial2400|2400 Baud Hayes attributes:\
|
||||
:dv=/dev/cuau0:br#2400:cu=/dev/cuau0:at=hayes:du:
|
||||
dial1200|1200 Baud Hayes attributes:\
|
||||
:dv=/dev/cuau0:br#1200:cu=/dev/cuau0:at=hayes:du:
|
||||
|
||||
# Hardwired line
|
||||
cuau0b|cua0b:dv=/dev/cuau0:br#2400
|
||||
cuau0c|cua0c:dv=/dev/cuau0:br#9600
|
@ -1,94 +0,0 @@
|
||||
echo 4/ddp
|
||||
echo 7/tcp
|
||||
echo 7/udp
|
||||
discard 9/tcp
|
||||
discard 9/udp
|
||||
systat 11/tcp
|
||||
systat 11/udp
|
||||
daytime 13/tcp
|
||||
daytime 13/udp
|
||||
qotd 17/tcp
|
||||
qotd 17/udp
|
||||
chargen 19/tcp
|
||||
chargen 19/udp
|
||||
ftp-data 20/tcp
|
||||
ftp-data 20/udp
|
||||
ftp 21/tcp
|
||||
ftp 21/udp
|
||||
ssh 22/tcp
|
||||
ssh 22/udp
|
||||
telnet 23/tcp
|
||||
telnet 23/udp
|
||||
smtp 25/tcp
|
||||
smtp 25/udp
|
||||
time 37/tcp
|
||||
time 37/udp
|
||||
domain 53/tcp
|
||||
domain 53/udp
|
||||
tacacs-ds 65/tcp
|
||||
tacacs-ds 65/udp
|
||||
bootps 67/tcp
|
||||
bootps 67/udp
|
||||
bootpc 68/tcp
|
||||
bootpc 68/udp
|
||||
tftp 69/tcp
|
||||
tftp 69/udp
|
||||
gopher 70/tcp
|
||||
gopher 70/udp
|
||||
finger 79/tcp
|
||||
finger 79/udp
|
||||
http 80/tcp
|
||||
http 80/udp
|
||||
pop2 109/tcp
|
||||
pop2 109/udp
|
||||
pop3 110/tcp
|
||||
pop3 110/udp
|
||||
uucp-path 117/tcp
|
||||
uucp-path 117/udp
|
||||
nntp 119/tcp
|
||||
nntp 119/udp
|
||||
netbios-ns 137/tcp
|
||||
netbios-ns 137/udp
|
||||
netbios-dgm 138/tcp
|
||||
netbios-dgm 138/udp
|
||||
netbios-ssn 139/tcp
|
||||
netbios-ssn 139/udp
|
||||
imap 143/tcp
|
||||
imap 143/udp
|
||||
snmp 161/tcp
|
||||
snmp 161/udp
|
||||
snmptrap 162/tcp
|
||||
snmptrap 162/udp
|
||||
bgp 179/tcp
|
||||
bgp 179/udp
|
||||
irc 194/tcp
|
||||
irc 194/udp
|
||||
ipx 213/tcp
|
||||
ipx 213/udp
|
||||
imap3 220/tcp
|
||||
imap3 220/udp
|
||||
ldap 389/tcp
|
||||
ldap 389/udp
|
||||
netware-ip 396/tcp
|
||||
netware-ip 396/udp
|
||||
https 443/tcp
|
||||
https 443/udp
|
||||
exec 512/tcp
|
||||
biff 512/udp
|
||||
login 513/tcp
|
||||
who 513/udp
|
||||
cmd 514/tcp
|
||||
syslog 514/udp
|
||||
printer 515/tcp
|
||||
printer 515/udp
|
||||
talk 517/tcp
|
||||
talk 517/udp
|
||||
ntalk 518/tcp
|
||||
ntalk 518/udp
|
||||
timed 525/tcp
|
||||
timed 525/udp
|
||||
uucp 540/tcp
|
||||
uucp 540/udp
|
||||
uucp-rlogin 541/tcp
|
||||
uucp-rlogin 541/udp
|
||||
natd 8668/divert # Network Address Translation
|
@ -1,7 +0,0 @@
|
||||
# $FreeBSD$
|
||||
# List of acceptable shells for chpass(1).
|
||||
# Ftpd will not allow users to connect who are not using
|
||||
# one of these shells.
|
||||
|
||||
/bin/sh
|
||||
/bin/csh
|
@ -1,187 +0,0 @@
|
||||
# Copyright (c) 1980, 1985, 1989 The Regents of the University of California.
|
||||
# All rights reserved.
|
||||
# @(#)termcap.src 5.88 (Berkeley) 4/30/91
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
# for syscons
|
||||
# common entry without semigraphics
|
||||
cons25w|ansiw|ansi80x25-raw:\
|
||||
:al=\E[L:am:bs:NP:cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:co#80:\
|
||||
:dc=\E[P:dl=\E[M:do=\E[B:bt=\E[Z:ho=\E[H:ic=\E[@:li#25:cb=\E[1K:\
|
||||
:ms:nd=\E[C:pt:rs=\E[x\E[m\Ec:so=\E[7m:se=\E[m:up=\E[A:\
|
||||
:pa#64:Co#8:Sf=\E[3%dm:Sb=\E[4%dm:op=\E[37;40m:\
|
||||
:k1=\E[M:k2=\E[N:k3=\E[O:k4=\E[P:k5=\E[Q:k6=\E[R:k7=\E[S:k8=\E[T:\
|
||||
:k9=\E[U:k;=\E[V:F1=\E[W:F2=\E[X:K2=\E[E:nw=\E[E:ec=\E[%dX:\
|
||||
:kb=^H:kh=\E[H:ku=\E[A:kd=\E[B:kl=\E[D:kr=\E[C:le=^H:eo:sf=\E[S:sr=\E[T:\
|
||||
:kN=\E[G:kP=\E[I:@7=\E[F:kI=\E[L:kD=\E[K:kB=\E[Z:\
|
||||
:IC=\E[%d@:DC=\E[%dP:SF=\E[%dS:SR=\E[%dT:AL=\E[%dL:DL=\E[%dM:\
|
||||
:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:cv=\E[%i%dd:ch=\E[%i%d`:bw:\
|
||||
:mb=\E[5m:md=\E[1m:mh=\E[30;1m:mr=\E[7m:me=\E[m:bl=^G:ut:it#8:
|
||||
cons25|ansis|ansi80x25:\
|
||||
:ac=l\332m\300k\277j\331u\264t\303v\301w\302q\304x\263n\305`^Da\260f\370g\361~\371.^Y-^Xh\261I^U0\333y\363z\362:\
|
||||
:tc=cons25w:
|
||||
cons25-m|ansis-mono|ansi80x25-mono:\
|
||||
:pa@:Co@:Sf@:Sb@:op@:us=\E[4m:ue=\E[m:md@:mh@:tc=cons25:
|
||||
cons50|ansil|ansi80x50:\
|
||||
:li#50:tc=cons25:
|
||||
cons50-m|ansil-mono|ansi80x50-mono:\
|
||||
:li#50:tc=cons25-m:
|
||||
# 80x25 ISO 8859-1 FreeBSD console
|
||||
cons25l1|cons25-iso8859-1:\
|
||||
:ac=l\215m\216k\214j\213u\226t\225v\227w\230q\222x\231n\217o\220s\224p\221r\223`\201a\202f\207g\210~\237.^Y-^X+\253,\273I\247y\232z\233:\
|
||||
:tc=cons25w:
|
||||
cons25l1-m|cons25-iso8859-1-mono:\
|
||||
:pa@:Co@:Sf@:Sb@:op@:us=\E[4m:ue=\E[m:md@:mh@:tc=cons25l1:
|
||||
# 80x50 ISO 8859-1 FreeBSD console
|
||||
cons50l1|cons50-iso8859-1:\
|
||||
:li#50:tc=cons25l1:
|
||||
cons50l1-m|cons50-iso8859-1-mono:\
|
||||
:li#50:tc=cons25l1-m:
|
||||
dosansi|ANSI.SYS standard crt|ansi:\
|
||||
:am:bs:ce=\E[K:cl=\E[2J:cm=\E[%i%d;%dH:co#80:\
|
||||
:do=\E[B:li#25:mi:nd=\E[C:\
|
||||
:se=\E[m:so=\E[7m:up=\E[A:us=\E[4m:ue=\E[m:\
|
||||
:md=\E[1m:mh=\E[m:mb=\E[5m:me=\E[m:\
|
||||
:kh=\EG:kb=^h:ku=\EH:kd=\EP:kl=\EK:kr=\EM:\
|
||||
:k1=\E;:k2=\E<:k3=\E=:k4=\E>:k5=\E?:\
|
||||
:k6=\E@:k7=\EA:k8=\EB:k9=\EC:k0=\ED:
|
||||
vt200|vt220|vt220am|vt200am|dec-vt220|dec-vt200|dec vt200 series with jump scroll:\
|
||||
:@7=\E[4~:kD=\E[3~:kI=\E[2~:kN=\E[6~:kP=\E[5~:kh=\E[1~:\
|
||||
:k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:k;=\E[21~:\
|
||||
:k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~:k5=\E[15~:\
|
||||
:ve=\E[?25h:vi=\E[?25l:k0@:im@:ei@:\
|
||||
:F1=\E[23~:F2=\E[24~:ic=\E[@:IC=\E[%d@:ec=\E[%dX:tc=vt102:
|
||||
vt100|dec-vt100|vt100-am|vt100am|dec vt100:\
|
||||
:do=2\E[B:co#80:li#24:cl=50\E[H\E[J:sf=2*\ED:\
|
||||
:le=^H:bs:am:cm=5\E[%i%d;%dH:nd=2\E[C:up=2\E[A:\
|
||||
:ce=3\E[K:cd=50\E[J:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\E[m:\
|
||||
:md=2\E[1m:mr=2\E[7m:mb=2\E[5m:me=2\E[m:\
|
||||
:is=\E>\E[?1;3;4;5l\E[?7;8h\E[1;24r\E[24;1H:\
|
||||
:if=/usr/share/tabset/vt100:nw=2\EE:ho=\E[H:\
|
||||
:as=2\E(0:ae=2\E(B:ac=llmmkkjjuuttvvwwqqxxnnpprr``aa:\
|
||||
:rs=\E>\E[?1;3;4;5l\E[?7;8h:ks=\E[?1h\E=:ke=\E[?1l\E>:\
|
||||
:ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=\177:\
|
||||
:k0=\EOy:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k5=\EOt:\
|
||||
:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:@8=\EOM:\
|
||||
:K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:pt:sr=2*\EM:vt#3:xn:\
|
||||
:sc=2\E7:rc=2\E8:cs=5\E[%i%d;%dr:UP=2\E[%dA:DO=2\E[%dB:RI=2\E[%dC:\
|
||||
:LE=2\E[%dD:ct=2\E[3g:st=2\EH:ta=^I:ms:bl=^G:cr=^M:eo:it#8:ut:\
|
||||
:RA=\E[?7l:SA=\E[?7h:
|
||||
xterm|vs100|xterm terminal emulator (X window system):\
|
||||
:li#25:\
|
||||
:kh=\EOH:@7=\EOF:kb=^H:kD=^?:\
|
||||
:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:km:\
|
||||
:is=\E>\E[?1;3;4;5l\E[?7;8h\E[1;65r\E[65;1H:\
|
||||
:rs=\E>\E[?1;3;4;5l\E[?7;8h:\
|
||||
:tc=vt220:
|
||||
xterm-color|xterm-co|xterm with ANSI colors:\
|
||||
:pa#64:Co#8:AF=\E[3%dm:AB=\E[4%dm:op=\E[39;49m:tc=xterm:
|
||||
|
||||
|
||||
vt100-nam|dec-vt100-nam|vt100nam|vt100 w/no am:\
|
||||
:am@:xn@:\
|
||||
:is=\E>\E[?1;3;4;5;7l\E[?8h\E[1;24r\E[24;1H:\
|
||||
:rs=\E>\E[?1;3;4;5;7l\E[?8h:\
|
||||
:tc=vt100-am:
|
||||
vt100-np|dec-vt100-np|vt100 with no padding (for psl games):\
|
||||
:do=\E[B:cl=\E[H\E[J:sf=\ED:as=\E(0:ae=\E(B:\
|
||||
:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:nw=\EE:\
|
||||
:ce=\E[K:cd=\E[J:so=\E[7m:se=\E[m:us=\E[4m:ue=\E[m:\
|
||||
:md=\E[1m:mr=\E[7m:mb=\E[5m:me=\E[m:sr=\EM:\
|
||||
:sc=\E7:rc=\E8:cs=\E[%i%d;%dr:UP=\E[%dA:DO=\E[%dB:RI=\E[%dC:\
|
||||
:LE=\E[%dD:ct=\E[3g:st=\EH:tc=vt100-am:
|
||||
vt100-nac|dec-vt100-nac|vt100 without pseudographics and padding:\
|
||||
:as@:ae@:ac@:tc=vt100-np:
|
||||
vt102|dec-vt102-am|vt102am|vt100 w/adv. video:\
|
||||
:al=\E[L:dl=\E[M:im=\E[4h:ei=\E[4l:mi:dc=\E[P:\
|
||||
:AL=\E[%dL:DL=\E[%dM:DC=\E[%dP:tc=vt100-np:
|
||||
|
||||
# Note: this entry describes the "native"
|
||||
# capabilities of the PC monochrome display, without ANY emulation; most
|
||||
# communications packages (but NOT PC/IX connect) do some kind of emulation.
|
||||
pc|ibmpc|ibm pc PC/IX:\
|
||||
:li#24:co#80:am:bs:bw:eo:\
|
||||
:cd=\E[J:ce=\E[K:cl=\Ec:cm=\E[%i%2;%2H:do=\E[B:ho=\E[;H:\
|
||||
:nd=\E[C:up=\E[A:so=\E[7m:se=\E[0m:us=\E[4m:ue=\E[0m:
|
||||
pc3mono|IBM PC 386BSD Console with monochrome monitor:\
|
||||
:so=\E[0;1r\E[m:tc=pc3:
|
||||
pc3|ibmpc3|IBM PC 386BSD Console:\
|
||||
:Co#8:\
|
||||
:DO=\E[%dB:\
|
||||
:F1=\E[W:F2=\E[X:\
|
||||
:K1=\E[H:K2=\E[I:K3=\E[E:K4=\E[F:K5=\E[G:\
|
||||
:LE=\E[%dD:\
|
||||
:RI=\E[%dC:\
|
||||
:Sb=\E[1;%dx:\
|
||||
:Sf=\E[2;%dx:\
|
||||
:UP=\E[%dA:\
|
||||
:ac=l\332m\300k\277j\331u\264t\303v\301w\302q\304x\263n\305`^Da\260f\370g\361~\371.^Y-^Xh\261I^U0\333y\363z\362:\
|
||||
:am:\
|
||||
:bl=^G:\
|
||||
:bs:\
|
||||
:cb=\E[1K:\
|
||||
:cd=\E[J:\
|
||||
:ce=\E[K:\
|
||||
:cl=\E[H\E[J:\
|
||||
:cm=\E[%i%d;%dH:\
|
||||
:co#80:\
|
||||
:cr=^M:\
|
||||
:do=\E[B:\
|
||||
:ho=\E[H:\
|
||||
:is=\E[m:\
|
||||
:it#8:\
|
||||
:k;=\E[V:k1=\E[M:k2=\E[N:k3=\E[O:k4=\E[P:k5=\E[Q:k6=\E[R:k7=\E[S:k8=\E[T:k9=\E[U:\
|
||||
:kD=\177:\
|
||||
:@7=\E[F:\
|
||||
:kN=\E[G:\
|
||||
:kP=\E[I:\
|
||||
:kb=\177:\
|
||||
:kd=\E[B:\
|
||||
:kh=\E[H:\
|
||||
:kl=\E[D:\
|
||||
:kr=\E[C:\
|
||||
:ku=\E[A:\
|
||||
:le=^H:\
|
||||
:li#25:\
|
||||
:ms:\
|
||||
:nd=\E[C:\
|
||||
:op=\E[x:\
|
||||
:pa#64:\
|
||||
:rs=\E[m:\
|
||||
:se=\E[m:\
|
||||
:sf=\E[S:\
|
||||
:so=\E[7;1r\E[7m:\
|
||||
:sr=\E[T:\
|
||||
:ta=^I:\
|
||||
:te=\E[m:\
|
||||
:ti=\E[m:\
|
||||
:up=\E[A:\
|
||||
:ut:
|
||||
du|dialup:\
|
||||
:tc=unknown:
|
||||
dumb|un|unknown:\
|
||||
:am:co#80:do=^J:
|
||||
# SC,SW names needed for screen(1) ache
|
||||
SC|screen|VT 100/ANSI X3.64 virtual terminal:\
|
||||
:am:xn:ms:mi:G0:km:\
|
||||
:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:bs:bt=\E[Z:\
|
||||
:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:ct=\E[3g:\
|
||||
:do=^J:nd=\E[C:pt:rc=\E8:rs=\Ec:sc=\E7:st=\EH:up=\EM:\
|
||||
:le=^H:bl=^G:cr=^M:it#8:ho=\E[H:nw=\EE:ta=^I:is=\E)0:\
|
||||
:li#24:co#80:us=\E[4m:ue=\E[24m:so=\E[3m:se=\E[23m:\
|
||||
:mb=\E[5m:md=\E[1m:mr=\E[7m:me=\E[m:sr=\EM:al=\E[L:\
|
||||
:AL=\E[%dL:dl=\E[M:DL=\E[%dM:cs=\E[%i%d;%dr:dc=\E[P:\
|
||||
:DC=\E[%dP:ic=\E[@:IC=\E[%d@:\
|
||||
:ks=\E[?1h\E=:ke=\E[?1l\E>:vb=\Eg:\
|
||||
:ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\
|
||||
:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k5=\E[15~:k6=\E[17~:\
|
||||
:k7=\E[18~:k8=\E[19~:k9=\E[20~:k;=\E[21~:F1=\E[23~:F2=\E[24~:\
|
||||
:kh=\E[1~:kI=\E[2~:kD=\E[3~:kH=\E[4~:kP=\E[5~:kN=\E[6~:\
|
||||
:eA=\E(B\E)0:as=^N:ae=^O:\
|
||||
:vi=\E[?25l:ve=\E[34h\E[?25h:vs=\E[34l:\
|
||||
:Co#8:pa#64:AF=\E[3%dm:AB=\E[4%dm:op=\E[39;49m:AX:\
|
||||
:ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++,,hhii00:
|
||||
SW|screen-w|VT 100/ANSI X3.64 virtual terminal with 132 cols:\
|
||||
:co#132:tc=screen:
|
||||
|
@ -1,50 +0,0 @@
|
||||
#!/bin/sh
|
||||
# $FreeBSD$
|
||||
# script to edit and save some config file(s).
|
||||
# If called with no arguments, it edits 3 files in /etc
|
||||
thefiles=$*
|
||||
[ -z "$thefiles" ] && \
|
||||
thefiles="/etc/rc.conf /etc/rc.firewall /etc/master.passwd"
|
||||
dev=`sysctl -n machdep.guessed_bootdev`
|
||||
[ -c "${dev}" ] || dev="/dev/fd0"
|
||||
mount ${dev} /mnt
|
||||
if [ "$?" != "0" ] ; then
|
||||
echo ""
|
||||
echo "Cannot mount ${dev} read-write!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Updating ${thefiles} on ${dev}: "
|
||||
|
||||
for f in ${thefiles} ; do
|
||||
case $f in
|
||||
/etc )
|
||||
echo "Update all files in $f :"
|
||||
srcs=`ls $f`
|
||||
for i in $srcs ; do
|
||||
if [ -f /mnt${f}/${i}.gz ]; then
|
||||
echo -n "$i ..."
|
||||
gzip < $f/$i > /mnt${f}/${i}.gz
|
||||
fi
|
||||
done
|
||||
echo " Done."
|
||||
;;
|
||||
|
||||
passwd|master.passwd)
|
||||
mkdir -p /mnt/etc
|
||||
ee /etc/master.passwd
|
||||
pwd_mkdb /etc/master.passwd
|
||||
gzip < /etc/master.passwd > /mnt/etc/master.passwd.gz
|
||||
;;
|
||||
|
||||
/*) # only absolute pathnames are ok
|
||||
mkdir -p /mnt/etc /mnt/root
|
||||
[ -f $f ] && ee $f && gzip < $f > /mnt${f}.gz
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "File $f not recognised, you must use an absolute pathname."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
umount /mnt
|
@ -1,123 +0,0 @@
|
||||
#
|
||||
# $FreeBSD$
|
||||
# A configuration file to run tests on qemu.
|
||||
# We disable SMP because it does not work well with qemu, and set HZ=1000
|
||||
# to avoid it being overridden.
|
||||
#
|
||||
# Line starting with #PicoBSD contains PicoBSD build parameters
|
||||
#marker def_sz init MFS_inodes floppy_inodes
|
||||
#PicoBSD 18000 init 8192 32768
|
||||
options MD_ROOT_SIZE=18000 # same as def_sz
|
||||
|
||||
hints "PICOBSD.hints"
|
||||
|
||||
# values accessible through getenv()
|
||||
# env "PICOBSD.env"
|
||||
|
||||
#cpu I486_CPU
|
||||
cpu I586_CPU
|
||||
cpu I686_CPU
|
||||
ident PICOBSD
|
||||
|
||||
# SMP seems to be needed for kern_et
|
||||
options SMP
|
||||
device apic
|
||||
|
||||
options SCHED_ULE # mandatory to have one scheduler
|
||||
options PREEMPTION # needed for decent interrupt processing
|
||||
#options MATH_EMULATE #Support for x87 emulation
|
||||
options INET #InterNETworking
|
||||
#options INET6
|
||||
options FFS #Berkeley Fast Filesystem
|
||||
#options BOOTP #Use BOOTP to obtain IP address/hostname
|
||||
options MD_ROOT #MD is a potential root device
|
||||
|
||||
#options NFS #Network Filesystem
|
||||
#options NFS_ROOT #NFS usable as root device, NFS required
|
||||
|
||||
#options MSDOSFS #MSDOS Filesystem
|
||||
#options CD9660 #ISO 9660 Filesystem
|
||||
#options CD9660_ROOT #CD-ROM usable as root, CD9660 required
|
||||
#options DEVFS #Device Filesystem
|
||||
#options PROCFS #Process filesystem
|
||||
options COMPAT_43 #Compatible with BSD 4.3 [KEEP THIS!]
|
||||
|
||||
options KDB
|
||||
options DDB
|
||||
|
||||
options IPFIREWALL
|
||||
options IPFIREWALL_DEFAULT_TO_ACCEPT
|
||||
options IPDIVERT # divert (for natd)
|
||||
|
||||
# Support for bridging and bandwidth limiting
|
||||
options DUMMYNET
|
||||
device if_bridge
|
||||
# Running with less than 1000 seems to give poor timing on
|
||||
# qemu, so we set HZ explicitly.
|
||||
options HZ=1000
|
||||
|
||||
device pci
|
||||
|
||||
# Floppy drives
|
||||
device fdc
|
||||
|
||||
# ATA and ATAPI devices
|
||||
#device ata
|
||||
#device atadisk # ATA disk drives
|
||||
#device atapicd # ATAPI CDROM drives
|
||||
#options ATA_STATIC_ID #Static device numbering
|
||||
|
||||
# atkbdc0 controls both the keyboard and the PS/2 mouse
|
||||
device atkbdc # At keyboard controller
|
||||
device atkbd
|
||||
#device psm # do we need the mouse ??
|
||||
|
||||
device vga # VGA screen
|
||||
|
||||
# syscons is the default console driver, resembling an SCO console
|
||||
device sc
|
||||
|
||||
# Serial (COM) ports
|
||||
device uart
|
||||
|
||||
# Audio support
|
||||
#device pcm
|
||||
|
||||
# PCCARD (PCMCIA) support
|
||||
#device card # pccard bus
|
||||
#device pcic # PCMCIA bridge
|
||||
|
||||
# Parallel port
|
||||
#device ppc
|
||||
#device ppbus # Parallel port bus (required)
|
||||
#device lpt # Printer
|
||||
#device plip # TCP/IP over parallel
|
||||
#device ppi # Parallel port interface device
|
||||
|
||||
#
|
||||
# The following Ethernet NICs are all PCI devices.
|
||||
#
|
||||
device miibus
|
||||
device fxp # Intel EtherExpress PRO/100B (82557, 82558)
|
||||
device nfe # nVidia nForce MCP on-board Ethernet
|
||||
#device xl # 3Com
|
||||
device rl # RealTek 8129/8139
|
||||
device re # RealTek 8139C+/8169/8169S/8110S
|
||||
device sis # National/SiS
|
||||
device dc # DEC/Intel 21143 and various workalikes
|
||||
device ed
|
||||
|
||||
device loop # Network loopback
|
||||
device ether # Ethernet support
|
||||
device tun # Packet tunnel.
|
||||
device pty # Pseudo-ttys (telnet etc)
|
||||
device md # Memory "disks"
|
||||
#device gif 4 # IPv6 and IPv4 tunneling
|
||||
device tap
|
||||
|
||||
#options VIMAGE # soner or later we may want to test this
|
||||
#options DEVICE_POLLING
|
||||
|
||||
# The `bpf' device enables the Berkeley Packet Filter.
|
||||
# Be aware of the administrative consequences of enabling this!
|
||||
device bpf # Berkeley packet filter
|
@ -1,39 +0,0 @@
|
||||
# $FreeBSD$
|
||||
hint.fdc.0.at="isa"
|
||||
hint.fdc.0.port="0x3F0"
|
||||
hint.fdc.0.irq="6"
|
||||
hint.fdc.0.drq="2"
|
||||
hint.fd.0.at="fdc0"
|
||||
hint.fd.0.drive="0"
|
||||
hint.ata.0.at="isa"
|
||||
hint.ata.0.port="0x1F0"
|
||||
hint.ata.0.irq="14"
|
||||
hint.ata.1.at="isa"
|
||||
hint.ata.1.port="0x170"
|
||||
hint.ata.1.irq="15"
|
||||
hint.atkbdc.0.at="isa"
|
||||
hint.atkbdc.0.port="0x060"
|
||||
hint.atkbd.0.at="atkbdc"
|
||||
hint.atkbd.0.irq="1"
|
||||
hint.psm.0.at="atkbdc"
|
||||
hint.psm.0.irq="12"
|
||||
hint.vga.0.at="isa"
|
||||
hint.sc.0.at="isa"
|
||||
hint.npx.0.at="nexus"
|
||||
hint.npx.0.port="0x0F0"
|
||||
hint.npx.0.irq="13"
|
||||
hint.uart.0.at="isa"
|
||||
hint.uart.0.port="0x3F8"
|
||||
hint.uart.0.flags="0x10"
|
||||
hint.uart.0.irq="4"
|
||||
hint.uart.1.at="isa"
|
||||
hint.uart.1.port="0x2F8"
|
||||
hint.uart.1.irq="3"
|
||||
hint.ed.0.at="isa"
|
||||
hint.ed.0.port="0x280"
|
||||
hint.ed.0.irq="5"
|
||||
hint.ed.0.maddr="0xd8000"
|
||||
hint.ed.1.at="isa"
|
||||
hint.ed.1.port="0x300"
|
||||
hint.ed.1.irq="5"
|
||||
hint.ed.1.maddr="0xd0000"
|
@ -1,26 +0,0 @@
|
||||
# configuration for picobsd build script.
|
||||
# $FreeBSD$
|
||||
# it should only contain variable definitions -- it is sourced
|
||||
# by the shell much like rc.conf* files
|
||||
|
||||
fd_size="8192"
|
||||
|
||||
# To copy individual files you can use the function do_copyfiles_user
|
||||
# as below (find_progs locates the programs and their libraries,
|
||||
# then you manually copy them.
|
||||
#copy_files="
|
||||
#"
|
||||
do_copyfiles_user() {
|
||||
local dst=$1 # the destination root
|
||||
log "--- put the libraries in /usr/lib to avoid conflicts"
|
||||
mkdir -p ${dst}/usr/lib
|
||||
log "-- import dropbear from its build directory --"
|
||||
find_progs -L / -P /usr/ports/security/dropbear/work/dropbear-0.52 \
|
||||
dbclient dropbear
|
||||
cp -p ${u_progs} ${dst}/bin
|
||||
cp -p ${u_libs} ${dst}/usr/lib
|
||||
log "--- also import ssh, scp and sshd ---"
|
||||
find_progs -L / /usr/bin/ssh /usr/bin/scp /usr/sbin/sshd
|
||||
cp -p ${u_progs} ${dst}/bin
|
||||
cp -p ${u_libs} ${dst}/usr/lib
|
||||
}
|
@ -1,200 +0,0 @@
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
# Configuration file for "qemu" images..
|
||||
#
|
||||
# Depending on your needs, you will almost surely need to
|
||||
# add/remove/change programs according to your needs.
|
||||
# Remember that some programs require matching kernel options to
|
||||
# enable device drivers etc.
|
||||
#
|
||||
# To figure out how much space is used by each program, do
|
||||
#
|
||||
# size build_dir-bridge/crunch/*lo
|
||||
#
|
||||
# Remember that programs require libraries, which add up to the
|
||||
# total size. The final binary is build_dir-bridge/mfs.tree/stand/crunch
|
||||
# and you can check which libraries it uses with
|
||||
#
|
||||
# ldd build_dir-bridge/mfs.tree/stand/crunch
|
||||
|
||||
# crunchgen configuration to build the crunched binary, see "man crunchgen"
|
||||
# We need to specify generic build options, the places where to look
|
||||
# for sources, and the list of program and libraries we want to put
|
||||
# in the crunched binary.
|
||||
#
|
||||
# NOTE: the string "/usr/src" below will be automatically replaced with
|
||||
# the path set in the 'build' script.
|
||||
|
||||
# Default build options. Basically tell the Makefiles
|
||||
# that to use the most compact possible version of the code.
|
||||
|
||||
buildopts -DWITHOUT_PAM -DPPP_NO_NETGRAPH
|
||||
buildopts -DTRACEROUTE_NO_IPSEC -DNO_INET6
|
||||
buildopts -DWITHOUT_KERBEROS -DWITHOUT_OPENSSL
|
||||
|
||||
# Directories where to look for sources of various binaries.
|
||||
# @__CWD__@ is a magic keyword in the picobsd's (Makefile.conf)
|
||||
# which is replaced with the directory with the picobsd configuration
|
||||
# corresponding to your image. This way you can have custom sources
|
||||
# in that directory overriding system programs.
|
||||
|
||||
srcdirs @__CWD__@/src
|
||||
|
||||
# Some programs are especially written for PicoBSD and reside in
|
||||
# release/picobsd/tinyware.
|
||||
# Put this entry near the head of the list to override standard binaries.
|
||||
|
||||
srcdirs /usr/src/release/picobsd/tinyware
|
||||
|
||||
# Other standard locations for sources.
|
||||
# If a program uses its own source directory, add
|
||||
|
||||
srcdirs /usr/src/bin
|
||||
srcdirs /usr/src/sbin/i386
|
||||
srcdirs /usr/src/sbin
|
||||
srcdirs /usr/src/usr.bin
|
||||
srcdirs /usr/src/gnu/usr.bin
|
||||
srcdirs /usr/src/usr.sbin
|
||||
srcdirs /usr/src/libexec
|
||||
|
||||
# For programs that reside in different places, the best option
|
||||
# is to use the command "special XXX srcdir YYY" where XXX is the
|
||||
# program name and YYY is the directory path.
|
||||
# "special XXX ..." can be used to specify more options, see again
|
||||
# the crunchgen manpage.
|
||||
|
||||
#--- Basic configuraton
|
||||
# init is always necessary (unless you have a replacement, oinit)
|
||||
progs init
|
||||
|
||||
# fsck is almost always necessary, unless you have everything on the
|
||||
# image and use 'tar' or something similar to read/write raw blocks
|
||||
# from the floppy.
|
||||
|
||||
progs fsck
|
||||
|
||||
# ifconfig is needed if you want to configure interfaces.
|
||||
progs ifconfig
|
||||
|
||||
# You will also need a shell and a bunch of utilities.
|
||||
# The standard shell is not that large, but you need many
|
||||
# external programs. In fact most of them do not take much space
|
||||
# as they merely issue a system call, and print the result.
|
||||
# For a more compact version of shell and utilities, you could
|
||||
# try busybox, however most system management commands in busybox
|
||||
# will not work as they use linux-specific interfaces.
|
||||
|
||||
progs sh
|
||||
ln sh -sh
|
||||
|
||||
# the small utilities
|
||||
progs echo
|
||||
progs pwd mkdir rmdir
|
||||
progs chmod chown
|
||||
ln chown chgrp
|
||||
progs mv ln cp rm ls
|
||||
progs cat tail tee
|
||||
progs test
|
||||
ln test [
|
||||
|
||||
progs less
|
||||
ln less more
|
||||
progs mount
|
||||
progs minigzip
|
||||
ln minigzip gzip
|
||||
progs kill
|
||||
progs df
|
||||
progs ps
|
||||
progs ns # this is the picobsd version
|
||||
ln ns netstat
|
||||
progs vm
|
||||
progs hostname
|
||||
progs login
|
||||
progs getty
|
||||
progs stty
|
||||
progs w
|
||||
progs msg
|
||||
ln msg dmesg
|
||||
progs reboot
|
||||
|
||||
progs sysctl
|
||||
progs swapon
|
||||
progs pwd_mkdb
|
||||
progs umount
|
||||
progs du
|
||||
progs passwd
|
||||
|
||||
progs route
|
||||
|
||||
# If you want to run natd, remember the alias library
|
||||
progs natd
|
||||
libs_so -lalias # natd
|
||||
progs tcpdump
|
||||
special tcpdump srcdir /usr/src/usr.sbin/tcpdump/tcpdump
|
||||
libs_so -lpcap # used by tcpdump
|
||||
libs_so -lcrypto # used by tcpdump with inet6
|
||||
|
||||
# ppp is rather large. Note that as of Jan.01, RELEASE_CRUNCH
|
||||
# makes ppp not use libalias, so you cannot have aliasing.
|
||||
#progs ppp
|
||||
|
||||
# You need an editor. ee is relatively small, though there are
|
||||
# smaller ones. vi is much larger.
|
||||
# The editor also usually need a curses library.
|
||||
progs ee
|
||||
|
||||
progs arp
|
||||
|
||||
# these require libgeom
|
||||
# progs bsdlabel fdisk mdconfig
|
||||
|
||||
progs kldload kldunload kldstat
|
||||
progs kldxref
|
||||
progs grep
|
||||
libs_so -lgnuregex -lbz2
|
||||
# dhclient-script requires 'sed'
|
||||
progs dhclient
|
||||
progs sed
|
||||
progs date
|
||||
progs time
|
||||
progs ping
|
||||
progs ping6
|
||||
progs tar
|
||||
|
||||
#progs routed
|
||||
progs ipfw
|
||||
progs traceroute
|
||||
progs mdmfs
|
||||
ln mdmfs mount_mfs
|
||||
# Various filesystem support -- remember to enable the kernel parts
|
||||
# progs mount_msdosfs
|
||||
progs mount_nfs
|
||||
# progs mount_cd9660
|
||||
ln mount_nfs nfs
|
||||
ln mount_cd9660 cd9660
|
||||
#progs newfs
|
||||
#ln newfs mount_mfs
|
||||
# ln mount_msdosfs msdos
|
||||
|
||||
# For a small ssh client/server use dropbear
|
||||
progs jail jexec jls # why not...
|
||||
|
||||
|
||||
# Now the libraries
|
||||
libs_so -lc # the C library
|
||||
libs_so -ll # used by sh (really ?)
|
||||
libs_so -lufs # used by mount
|
||||
### ee uses ncurses but as a dependency
|
||||
#libs_so -lncurses
|
||||
libs_so -lm
|
||||
libs_so -ledit -lutil
|
||||
libs_so -lcrypt
|
||||
libs_so -lkvm
|
||||
libs_so -lz
|
||||
libs_so -lbsdxml
|
||||
libs_so -lsbuf
|
||||
libs_so -ljail # used by ifconfig
|
||||
libs_so -lipsec -lmd # used with ipv6
|
||||
libs_so -larchive -lbz2
|
||||
libs_so -llzma # added after 207840
|
@ -1,2 +0,0 @@
|
||||
etc/snmpd.conf
|
||||
etc/ppp
|
@ -1,9 +0,0 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
PROG=ps
|
||||
SRCS+=main.c
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
|
@ -1,19 +0,0 @@
|
||||
1998.07.12
|
||||
|
||||
This is a small 'ps' replacement, which uses information available via
|
||||
procfs(5) interface. It's primitive, but gives you the most important
|
||||
informations, i.e. how many processes are running and on which vty, and the
|
||||
pid number to kill some of them. :-)
|
||||
|
||||
When I have some time, I'll add usual switches and other functions that normal
|
||||
'ps' has...
|
||||
|
||||
Also, what I'm now inclined to think is that it should be reworked to use
|
||||
more general (and less complicated) sysctl(3).
|
||||
|
||||
<abial@freebsd.org>
|
||||
|
||||
(As of 1998.07.31 this program is no longer used in PicoBSD. See sps(1) in
|
||||
TinyWare collection).
|
||||
|
||||
$FreeBSD$
|
@ -1,101 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Andrzej Bialecki
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
/*
|
||||
* Ok, I could extract almost anything from /proc, but I'm too lazy...
|
||||
* I think it will suffice for now.
|
||||
*/
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
DIR *d;
|
||||
struct dirent *e;
|
||||
FILE *fd;
|
||||
char buf[100];
|
||||
char *tok, *sep=" ", *sep1=",";
|
||||
char *name, *pid, *ppid, *uid, *gid;
|
||||
char *pgid, *sid, *tty, *cred;
|
||||
char *major, *minor;
|
||||
char con[10];
|
||||
|
||||
d=opendir("/proc");
|
||||
printf(" PID PPID TTY COMMAND\n");
|
||||
while((e=readdir(d))!=NULL) {
|
||||
/* Skip '.' and '..' */
|
||||
if(e->d_name[0]=='.') continue;
|
||||
/* Skip 'curproc' - it's us */
|
||||
if(e->d_name[0]=='c') continue;
|
||||
sprintf(buf,"/proc/%s/status",e->d_name);
|
||||
fd=fopen(buf,"r");
|
||||
fgets(buf,99,fd);
|
||||
fclose(fd);
|
||||
name=strtok(buf,sep);
|
||||
pid=strtok(NULL,sep);
|
||||
ppid=strtok(NULL,sep);
|
||||
pgid=strtok(NULL,sep);
|
||||
sid=strtok(NULL,sep);
|
||||
tty=strtok(NULL,sep);
|
||||
tok=strtok(NULL,sep); /* flags */
|
||||
tok=strtok(NULL,sep); /* start */
|
||||
tok=strtok(NULL,sep); /* user time */
|
||||
tok=strtok(NULL,sep); /* system time */
|
||||
tok=strtok(NULL,sep); /* wchan */
|
||||
cred=strtok(NULL,sep); /* credentials */
|
||||
major=strtok(tty,sep1);
|
||||
minor=strtok(NULL,sep1);
|
||||
if(strcmp(minor,"-1")==0) {
|
||||
minor="?";
|
||||
}
|
||||
if(strcmp(major,"-1")==0) {
|
||||
major="?";
|
||||
} else if(strcmp(major,"12")==0) {
|
||||
major="v";
|
||||
} else if(strcmp(major,"0")==0) {
|
||||
major="con";
|
||||
minor="-";
|
||||
} else if(strcmp(major,"5")==0) {
|
||||
major="p";
|
||||
} else major="x";
|
||||
if((strcmp(major,"v")==0) && (strcmp(minor,"255")==0)) {
|
||||
major="con";
|
||||
minor="-";
|
||||
}
|
||||
sprintf(con,"%s%s",major,minor);
|
||||
printf("%5s %5s %4s (%s)\n",pid,ppid,con,name);
|
||||
|
||||
}
|
||||
closedir(d);
|
||||
exit(0);
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
PROG=help
|
||||
SRCS+=help.c
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
|
@ -1,8 +0,0 @@
|
||||
1998.02.20
|
||||
|
||||
This is work in progress. Eventually I'll prepare the help system for newbies,
|
||||
and these files are just the beginning of it...
|
||||
|
||||
<abial@freebsd.org>
|
||||
|
||||
$FreeBSD$
|
@ -1,157 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Eric P. Scott <eps@sirius.com>
|
||||
* Copyright (c) 1998 Andrzej Bialecki <abial@freebsd.org>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ar.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
int display(FILE *, const char *);
|
||||
|
||||
static int cnt, crt=-1;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
register int i, s;
|
||||
FILE *fd;
|
||||
struct ttysize ts;
|
||||
|
||||
if (!(fd=fopen("/help.a", "r"))) {
|
||||
(void)fputs("Couldn't open help archive.\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
cnt=0;
|
||||
if (ioctl(fileno(stdout), TIOCGWINSZ, &ts)>=0) {
|
||||
crt=ts.ts_lines-1;
|
||||
}
|
||||
if (crt<3) crt=23;
|
||||
s=display(fd, argc>1 ? argv[1] : "help");
|
||||
if (s<0) s=0;
|
||||
else for (i=2;i<argc;) {
|
||||
rewind(fd);
|
||||
s|=display(fd, argv[i++]);
|
||||
if (s<0) {
|
||||
s=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
(void)fclose(fd);
|
||||
exit(s);
|
||||
}
|
||||
|
||||
int
|
||||
more(void)
|
||||
{
|
||||
char buf[8];
|
||||
|
||||
(void)fflush(stdout);
|
||||
(void)fputs("\033[7mPress Enter to continue\033[m", stderr);
|
||||
(void)fflush(stderr);
|
||||
cnt=0;
|
||||
if (fgets(buf, sizeof buf, stdin)) return 0;
|
||||
(void)fputc('\n', stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
display(FILE *fd, const char *fname)
|
||||
{
|
||||
register char *p;
|
||||
register int c, n, o;
|
||||
struct ar_hdr ar;
|
||||
char aname[20];
|
||||
|
||||
if (!fgets(aname, sizeof aname, fd)) {
|
||||
return 1;
|
||||
}
|
||||
if (strncmp(aname, ARMAG, SARMAG)) return 1;
|
||||
(void)snprintf(aname, sizeof(aname), "%s/", fname);
|
||||
for (;;) {
|
||||
if (fread((void *)&ar, sizeof ar, 1, fd)!=1) return 1;
|
||||
if (strncmp(ar.ar_fmag, ARFMAG, 2)) return 1;
|
||||
n=0;
|
||||
p=ar.ar_size;
|
||||
do {
|
||||
if ((c=(int)(*p++-'0'))<0||c>9) break;
|
||||
n*=10; n+=c;
|
||||
} while (p<&ar.ar_size[sizeof ar.ar_size]);
|
||||
if (!strncmp(ar.ar_name, aname, strlen(aname))) break;
|
||||
if (fseek(fd, (long)n, SEEK_CUR)<0) return 1;
|
||||
if ((n&1)&&fgetc(fd)!='\n') return 1;
|
||||
}
|
||||
if (cnt>=crt&&more()) return -1;
|
||||
(void)fputc('\n', stdout);
|
||||
cnt++;
|
||||
o=0; while (o<n&&(c=fgetc(fd))!=EOF) {
|
||||
per:
|
||||
o++;
|
||||
(void)fputc(c, stdout);
|
||||
if (c!='\n') continue;
|
||||
if (++cnt<crt) continue;
|
||||
if (o>=n||(c=fgetc(fd))==EOF) break;
|
||||
if (more()) return -1;
|
||||
goto per;
|
||||
}
|
||||
if (cnt>=crt&&more()) return -1;
|
||||
(void)fputc('\n', stdout);
|
||||
cnt++;
|
||||
if (!strcmp(fname, "help")) {
|
||||
rewind(fd);
|
||||
(void)fgets(aname, sizeof aname, fd);
|
||||
if (cnt>=crt&&more()) return -1;
|
||||
(void)fputs("The following help items are available:\n",
|
||||
stdout);
|
||||
cnt++;
|
||||
o=0;
|
||||
while (fread((void *)&ar, sizeof ar, 1, fd)==1) {
|
||||
if (strncmp(ar.ar_fmag, ARFMAG, 2)) break;
|
||||
if ((o%6)==0) {
|
||||
(void)fputc('\n', stdout);
|
||||
if (++cnt>=crt&&more()) return -1;
|
||||
}
|
||||
*(index(ar.ar_name,'/'))=' ';
|
||||
(void)printf("%.13s", ar.ar_name);
|
||||
++o;
|
||||
n=0;
|
||||
p=ar.ar_size;
|
||||
do {
|
||||
if ((c=(int)(*p++-'0'))<0||c>9) break;
|
||||
n*=10; n+=c;
|
||||
} while (p<&ar.ar_size[sizeof ar.ar_size]);
|
||||
if (fseek(fd, (long)n, SEEK_CUR)<0) break;
|
||||
if ((n&1)&&fgetc(fd)!='\n') break;
|
||||
}
|
||||
if (cnt>=crt&&more()) return -1;
|
||||
(void)fputc('\n', stdout);
|
||||
cnt++;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
# From: @(#)Makefile 8.1 (Berkeley) 7/19/93
|
||||
# $FreeBSD$
|
||||
|
||||
.include <src.opts.mk>
|
||||
|
||||
.PATH: ${.CURDIR}/../../../../usr.bin/login
|
||||
|
||||
PROG= login
|
||||
SRCS= pico-login.c login_fbtab.c
|
||||
MAN= login.1
|
||||
|
||||
CFLAGS+=-DLOGALL
|
||||
|
||||
LIBADD= util crypt
|
||||
|
||||
.if ${MK_PAM_SUPPORT} != "no"
|
||||
CFLAGS+= -DUSE_PAM
|
||||
LIBADD+= pam
|
||||
.endif
|
||||
|
||||
BINOWN= root
|
||||
BINMODE=4555
|
||||
PRECIOUSPROG=
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,6 +0,0 @@
|
||||
$FreeBSD$
|
||||
|
||||
This is a modified login version for PicoBSD purposes, which does
|
||||
not demand PAM.
|
||||
The "login.c" file is replaced by pico-login.c in this directory,
|
||||
the remaining files are taken from usr.bin/login/
|
@ -1,45 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
*
|
||||
* Copyright (c) 1989, 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.
|
||||
*
|
||||
* @(#)pathnames.h 8.1 (Berkeley) 6/9/93
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <paths.h>
|
||||
|
||||
#define _PATH_HUSHLOGIN ".hushlogin"
|
||||
#define _PATH_MOTDFILE "/var/run/motd"
|
||||
#define _PATH_LOGACCESS "/etc/login.access"
|
||||
#define _PATH_FBTAB "/etc/fbtab"
|
||||
#define _PATH_LOGINDEVPERM "/etc/logindevperm"
|
File diff suppressed because it is too large
Load Diff
@ -1,9 +0,0 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
PROG=msg
|
||||
SRCS= msg.c
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
1998.09.14, Warsaw
|
||||
|
||||
This program replaces 'dmesg' utility, aand allows you to retrieve the
|
||||
system's message buffer without resorting to such dirty tricks as normal
|
||||
'dmesg' uses (using libkvm and /dev/kmem to directly read kernel
|
||||
memory.. *shudder*).
|
||||
|
||||
This utility uses sysctl(3) interface. The mib variable it uses was
|
||||
recently added to the kernel sources, so if you don't mind patching your
|
||||
kernel tree, contact me directly - the patches are very small and simple.
|
||||
|
||||
Andrzej Bialecki
|
||||
<abial@freebsd.org>
|
||||
|
||||
$FreeBSD$
|
@ -1,75 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Andrzej Bialecki <abial@freebsd.org>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Small replacement for 'dmesg'. It doesn't need libkvm nor /dev/kmem.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int len,i;
|
||||
char *buf,*p;
|
||||
char *mib="kern.msgbuf";
|
||||
|
||||
/* We use sysctlbyname, because the oid is unknown (OID_AUTO) */
|
||||
|
||||
/* get the buffer size */
|
||||
i=sysctlbyname(mib,NULL,&len,NULL,0);
|
||||
if(i) {
|
||||
perror("buffer sizing");
|
||||
exit(-1);
|
||||
}
|
||||
buf=(char *)malloc(len*sizeof(char));
|
||||
i=sysctlbyname(mib,buf,&len,NULL,0);
|
||||
if(i) {
|
||||
perror("retrieving data");
|
||||
exit(-1);
|
||||
}
|
||||
p=buf;
|
||||
i=0;
|
||||
while(p<(buf+len)) {
|
||||
switch(*p) {
|
||||
case '\0':
|
||||
/* skip initial NULLs */
|
||||
break;
|
||||
default:
|
||||
putchar(*p);
|
||||
}
|
||||
p++;
|
||||
}
|
||||
if(*--p!='\n') putchar('\n');
|
||||
free(buf);
|
||||
exit(0);
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
PROG=msh
|
||||
SRCS= sh1.c sh2.c sh3.c sh4.c sh5.c sh6.c
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
|
@ -1,13 +0,0 @@
|
||||
This is a port of Minix /bin/sh shell.
|
||||
|
||||
It's quite limited, but also quite small. One of most serious
|
||||
limitations is lack of support for user-defined functions. Also,
|
||||
globbing should be implemented with our glob(3) - the version in
|
||||
sh4.c is rather primitive.
|
||||
|
||||
This version is under BSD license.
|
||||
|
||||
Andrzej Bialecki
|
||||
<abial@FreeBSD.org>
|
||||
|
||||
$Id$
|
@ -1,260 +0,0 @@
|
||||
.TH SH 1
|
||||
.SH NAME
|
||||
sh, ., break, case, cd, continue, eval, exec, exit, export, for, if, read, readonly, set, shift, trap, umask, wait, while \- shell
|
||||
.SH SYNOPSIS
|
||||
\fBsh\fR [\fB\-eiknqstvxu\fR] [\fB\-c \fIstr\fR] \fB[\fIfile\fR]\fR
|
||||
.br
|
||||
.de FL
|
||||
.TP
|
||||
\\fB\\$1\\fR
|
||||
\\$2
|
||||
..
|
||||
.de EX
|
||||
.TP 20
|
||||
\\fB\\$1\\fR
|
||||
# \\$2
|
||||
..
|
||||
.SH OPTIONS
|
||||
.FL "\-c" "Execute the commands in \fIstr\fR"
|
||||
.FL "\-e" "Quit on error"
|
||||
.FL "\-i" "Interactive mode; ignore QUIT, TERMINATE, INTERRUPT"
|
||||
.FL "\-k" "Look for name=value everywhere on command line"
|
||||
.FL "\-n" "Do not execute commands"
|
||||
.FL "\-q" "Change qflag from sig_ign to sig_del"
|
||||
.FL "\-s" "Read commands from standard input"
|
||||
.FL "\-t" "Exit after reading and executing one command"
|
||||
.FL "\-v" "Echo input lines as they are read"
|
||||
.FL "\-x" "Trace"
|
||||
.FL "\-u" "Unset variables"
|
||||
.SH EXAMPLES
|
||||
.EX "sh script" "Run a shell script"
|
||||
.SH DESCRIPTION
|
||||
.I Sh
|
||||
is the shell, which forms the user's main interface with the system.
|
||||
On startup, the shell reads /etc/profile and $HOME/.profile, if they exist,
|
||||
and executes any commands they contain. The Minix shell has most of the
|
||||
features of the V7 (Bourne) shell, including redirection of input and output,
|
||||
pipes, magic characters, background processes, and shell scripts. A brief
|
||||
summary follows, but whole books have been written on shell programming alone.
|
||||
.LP
|
||||
Some of the more common notations are:
|
||||
.PP
|
||||
.in +2.45i
|
||||
.ta 2i 2.2i
|
||||
.ti -2.2i
|
||||
date # Regular command
|
||||
.ti -2.2i
|
||||
sort <file # Redirect \fIstdin\fR (standard input)
|
||||
.ti -2.2i
|
||||
sort <file1 >file2 # Redirect \fIstdin\fR and \fIstdout\fR
|
||||
.ti -2.2i
|
||||
cc file.c 2>error # Redirect \fIstderr\fR
|
||||
.ti -2.2i
|
||||
a.out >f 2>&1 # Combine standard output and standard error
|
||||
.ti -2.2i
|
||||
sort <file1 >>file2 # Append output to \fIfile2\fR
|
||||
.ti -2.2i
|
||||
sort <file1 >file2 & # Background job
|
||||
.ti -2.2i
|
||||
(ls \-l; a.out) & # Run two background commands sequentially
|
||||
.ti -2.2i
|
||||
sort <file | wc # Two-process pipeline
|
||||
.ti -2.2i
|
||||
sort <f | uniq | wc # Three-process pipeline
|
||||
.ti -2.2i
|
||||
ls \-l *.c # List all files ending in \fI.c\fR
|
||||
.ti -2.2i
|
||||
ls \-l [\fIa-c\fR]* # List all files beginning with \fIa\fR, \fIb\fR, or \fIc\fR
|
||||
.ti -2.2i
|
||||
ls \-l ? # List all one-character file names
|
||||
.ti -2.2i
|
||||
ls \e? # List the file whose name is question mark
|
||||
.ti -2.2i
|
||||
ls \(fm???\(fm # List the file whose name is three question marks
|
||||
.ti -2.2i
|
||||
v=/usr/ast # Set shell variable \fIv\fR
|
||||
.ti -2.2i
|
||||
ls \-l $v # Use shell variable \fIv\fR
|
||||
.ti -2.2i
|
||||
PS1=\(fmHi! \(fm # Change the primary prompt to \fIHi!\fR
|
||||
.ti -2.2i
|
||||
PS2=\(fmMore: \(fm # Change the secondary prompt to \fIMore:\fR
|
||||
.ti -2.2i
|
||||
ls \-l $HOME # List the home directory
|
||||
.ti -2.2i
|
||||
echo $PATH # Echo the search path
|
||||
.ti -2.2i
|
||||
echo $? # Echo exit status of previous command in decimal
|
||||
.ti -2.2i
|
||||
echo $$ # Echo shell's pid in decimal
|
||||
.ti -2.2i
|
||||
echo $! # Echo PID of last background process
|
||||
.ti -2.2i
|
||||
echo $# # Echo number of parameters (shell script)
|
||||
.ti -2.2i
|
||||
echo $2 # Echo second parameter (shell script)
|
||||
.ti -2.2i
|
||||
echo "$2" # Echo second parameter without expanding spaces
|
||||
.ti -2.2i
|
||||
echo $* # Echo all parameters (shell script)
|
||||
.ti -2.2i
|
||||
echo $@ # Echo all parameters (shell script)
|
||||
.ti -2.2i
|
||||
echo "$@" # Echo all parameters without expanding spaces
|
||||
.in -2.45i
|
||||
.LP
|
||||
The shell uses the following variables for specific purposes:
|
||||
.PP
|
||||
.in +2.25i
|
||||
.ta 2i
|
||||
.ti -2i
|
||||
SHELL the path of the current shell
|
||||
.ti -2i
|
||||
HOME the default value for the cd(1) command
|
||||
.ti -2i
|
||||
PATH the directories to be searched to find commands
|
||||
.ti -2i
|
||||
IFS the internal field separators for command strings
|
||||
.ti -2i
|
||||
PS1 the primary shell prompt
|
||||
.ti -2i
|
||||
PS2 the secondary shell prompt
|
||||
.in -2.25i
|
||||
.LP
|
||||
There are various forms of substitution on the shell command line:
|
||||
.PP
|
||||
.in +2.25i
|
||||
.ta 2i
|
||||
.ti -2i
|
||||
`...` Command string between back-quotes is replaced by its output
|
||||
.ti -2i
|
||||
"..." Permits variable substitution between quotes
|
||||
.ti -2i
|
||||
\&'...' Inhibits variable substitution between quotes
|
||||
.ti -2i
|
||||
$VAR Replaced by contents of variable VAR
|
||||
.ti -2i
|
||||
${VAR} Delimits variable VAR from any following string
|
||||
.in -2.25i
|
||||
.LP
|
||||
The expressions below depend on whether or not VAR has ever been set.
|
||||
If VAR has been set, they give:
|
||||
.PP
|
||||
.in +2.25i
|
||||
.ta 2i
|
||||
.ti -2i
|
||||
${VAR-str} Replace expression by VAR, else by str
|
||||
.ti -2i
|
||||
${VAR=str} Replace expression by VAR, else by str and set VAR to str
|
||||
.ti -2i
|
||||
${VAR?str} Replace expression by VAR, else print str and exit shell
|
||||
.ti -2i
|
||||
${VAR+str} Replace expression by str, else by null string
|
||||
.in -2.25i
|
||||
.LP
|
||||
If a colon is placed after VAR, the expressions depend on whether or not
|
||||
VAR is currently set and non-null.
|
||||
.LP
|
||||
The shell has a number of built-in commands:
|
||||
.PP
|
||||
.in +2.25i
|
||||
.ta 2i
|
||||
.ti -2i
|
||||
: return true status
|
||||
.ti -2i
|
||||
\&. fn execute shell script fn on current path
|
||||
.ti -2i
|
||||
break [n] break from a for, until or while loop; exit n levels
|
||||
.ti -2i
|
||||
continue [n] continue a for, until or while loop; resume nth loop
|
||||
.ti -2i
|
||||
cd [dir] change current working directory; move to $HOME
|
||||
.ti -2i
|
||||
eval cmd rescan cmd, performing substitutions
|
||||
.ti -2i
|
||||
eval rescan the current command line
|
||||
.ti -2i
|
||||
exec cmd execute cmd without creating a new process
|
||||
.ti -2i
|
||||
exec <|> with no command name, modify shell I/O
|
||||
.ti -2i
|
||||
exit [n] exit a shell program, with exit value n
|
||||
.ti -2i
|
||||
export [var] export var to shell's children; list exported variables
|
||||
.ti -2i
|
||||
pwd print the name of the current working directory
|
||||
.ti -2i
|
||||
read var read a line from stdin and assign to var
|
||||
.ti -2i
|
||||
readonly [var] make var readonly; list readonly variables
|
||||
.ti -2i
|
||||
set -f set shell flag (+f unsets flag)
|
||||
.ti -2i
|
||||
set str set positional parameter to str
|
||||
.ti -2i
|
||||
set show the current shell variables
|
||||
.ti -2i
|
||||
shift reassign positional parameters (except ${0}) one left
|
||||
.ti -2i
|
||||
times print accumulated user and system times for processes
|
||||
.ti -2i
|
||||
trap arg sigs trap signals sigs and run arg on receipt
|
||||
.ti -2i
|
||||
trap list trapped signals
|
||||
.ti -2i
|
||||
umask [n] set the user file creation mask; show the current umask
|
||||
.ti -2i
|
||||
wait [n] wait for process pid n; wait for all processes
|
||||
.in -2.25i
|
||||
.LP
|
||||
The shell also contains a programming language, which has the following
|
||||
operators and flow control statements:
|
||||
.PP
|
||||
.in +3.50i
|
||||
.ta 2i 3.25i
|
||||
.ti -3.25i
|
||||
# Comment The rest of the line is ignored
|
||||
.ti -3.25i
|
||||
= Assignment Set a shell variable
|
||||
.ti -3.25i
|
||||
&& Logical AND Execute second command only if first succeeds
|
||||
.ti -3.25i
|
||||
|| Logical OR Execute second command only if first fails
|
||||
.ti -3.25i
|
||||
(...) Group Execute enclosed commands before continuing
|
||||
.in -3.50i
|
||||
.PP
|
||||
.in +2.25i
|
||||
.ta 2i
|
||||
.ti -2i
|
||||
for For loop (for ... in ... do ... done)
|
||||
.ti -2i
|
||||
case Case statement ((case ... ) ... ;; ... esac)
|
||||
.ti -2i
|
||||
esac Case statement end
|
||||
.ti -2i
|
||||
while While loop (while ... do ... done)
|
||||
.ti -2i
|
||||
do Do/For/While loop start (do ... until ...)
|
||||
.ti -2i
|
||||
done For/While loop end
|
||||
.ti -2i
|
||||
if Conditional statement (if ... else ... elif ... fi)
|
||||
.ti -2i
|
||||
in For loop selection
|
||||
.ti -2i
|
||||
then Conditional statement start
|
||||
.ti -2i
|
||||
else Conditional statement alternative
|
||||
.ti -2i
|
||||
elif Conditional statement end
|
||||
.ti -2i
|
||||
until Do loop end
|
||||
.ti -2i
|
||||
fi Conditional statement end
|
||||
.in -2.25i
|
||||
.SH "SEE ALSO"
|
||||
.BR echo (1),
|
||||
.BR expr (1),
|
||||
.BR pwd (1),
|
||||
.BR true (1).
|
@ -1,388 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
/* Need a way to have void used for ANSI, nothing for K&R. */
|
||||
#ifndef _ANSI
|
||||
#undef _VOID
|
||||
#define _VOID
|
||||
#endif
|
||||
|
||||
/* -------- sh.h -------- */
|
||||
/*
|
||||
* shell
|
||||
*/
|
||||
|
||||
#define LINELIM 2100
|
||||
#define NPUSH 8 /* limit to input nesting */
|
||||
|
||||
#define NOFILE 20 /* Number of open files */
|
||||
#define NUFILE 10 /* Number of user-accessible files */
|
||||
#define FDBASE 10 /* First file usable by Shell */
|
||||
|
||||
/*
|
||||
* values returned by wait
|
||||
*/
|
||||
#define WAITSIG(s) ((s)&0177)
|
||||
#define WAITVAL(s) (((s)>>8)&0377)
|
||||
#define WAITCORE(s) (((s)&0200)!=0)
|
||||
|
||||
/*
|
||||
* library and system defintions
|
||||
*/
|
||||
#ifdef __STDC__
|
||||
typedef void xint; /* base type of jmp_buf, for not broken compilers */
|
||||
#else
|
||||
typedef char * xint; /* base type of jmp_buf, for broken compilers */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* shell components
|
||||
*/
|
||||
/* #include "area.h" */
|
||||
/* #include "word.h" */
|
||||
/* #include "io.h" */
|
||||
/* #include "var.h" */
|
||||
|
||||
#define QUOTE 0200
|
||||
|
||||
#define NOBLOCK ((struct op *)NULL)
|
||||
#define NOWORD ((char *)NULL)
|
||||
#define NOWORDS ((char **)NULL)
|
||||
#define NOPIPE ((int *)NULL)
|
||||
|
||||
/*
|
||||
* Description of a command or an operation on commands.
|
||||
* Might eventually use a union.
|
||||
*/
|
||||
struct op {
|
||||
int type; /* operation type, see below */
|
||||
char **words; /* arguments to a command */
|
||||
struct ioword **ioact; /* IO actions (eg, < > >>) */
|
||||
struct op *left;
|
||||
struct op *right;
|
||||
char *str; /* identifier for case and for */
|
||||
};
|
||||
|
||||
#define TCOM 1 /* command */
|
||||
#define TPAREN 2 /* (c-list) */
|
||||
#define TPIPE 3 /* a | b */
|
||||
#define TLIST 4 /* a [&;] b */
|
||||
#define TOR 5 /* || */
|
||||
#define TAND 6 /* && */
|
||||
#define TFOR 7
|
||||
#define TDO 8
|
||||
#define TCASE 9
|
||||
#define TIF 10
|
||||
#define TWHILE 11
|
||||
#define TUNTIL 12
|
||||
#define TELIF 13
|
||||
#define TPAT 14 /* pattern in case */
|
||||
#define TBRACE 15 /* {c-list} */
|
||||
#define TASYNC 16 /* c & */
|
||||
|
||||
/*
|
||||
* actions determining the environment of a process
|
||||
*/
|
||||
#define BIT(i) (1<<(i))
|
||||
#define FEXEC BIT(0) /* execute without forking */
|
||||
|
||||
/*
|
||||
* flags to control evaluation of words
|
||||
*/
|
||||
#define DOSUB 1 /* interpret $, `, and quotes */
|
||||
#define DOBLANK 2 /* perform blank interpretation */
|
||||
#define DOGLOB 4 /* interpret [?* */
|
||||
#define DOKEY 8 /* move words with `=' to 2nd arg. list */
|
||||
#define DOTRIM 16 /* trim resulting string */
|
||||
|
||||
#define DOALL (DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM)
|
||||
|
||||
Extern char **dolv;
|
||||
Extern int dolc;
|
||||
Extern int exstat;
|
||||
Extern char gflg;
|
||||
Extern int talking; /* interactive (talking-type wireless) */
|
||||
Extern int execflg;
|
||||
Extern int multiline; /* \n changed to ; */
|
||||
Extern struct op *outtree; /* result from parser */
|
||||
|
||||
Extern xint *failpt;
|
||||
Extern xint *errpt;
|
||||
|
||||
struct brkcon {
|
||||
jmp_buf brkpt;
|
||||
struct brkcon *nextlev;
|
||||
} ;
|
||||
Extern struct brkcon *brklist;
|
||||
Extern int isbreak;
|
||||
|
||||
/*
|
||||
* redirection
|
||||
*/
|
||||
struct ioword {
|
||||
short io_unit; /* unit affected */
|
||||
short io_flag; /* action (below) */
|
||||
char *io_name; /* file name */
|
||||
};
|
||||
#define IOREAD 1 /* < */
|
||||
#define IOHERE 2 /* << (here file) */
|
||||
#define IOWRITE 4 /* > */
|
||||
#define IOCAT 8 /* >> */
|
||||
#define IOXHERE 16 /* ${}, ` in << */
|
||||
#define IODUP 32 /* >&digit */
|
||||
#define IOCLOSE 64 /* >&- */
|
||||
|
||||
#define IODEFAULT (-1) /* token for default IO unit */
|
||||
|
||||
Extern struct wdblock *wdlist;
|
||||
Extern struct wdblock *iolist;
|
||||
|
||||
/*
|
||||
* parsing & execution environment
|
||||
*/
|
||||
extern struct env {
|
||||
char *linep;
|
||||
struct io *iobase;
|
||||
struct io *iop;
|
||||
xint *errpt;
|
||||
int iofd;
|
||||
struct env *oenv;
|
||||
} e;
|
||||
|
||||
/*
|
||||
* flags:
|
||||
* -e: quit on error
|
||||
* -k: look for name=value everywhere on command line
|
||||
* -n: no execution
|
||||
* -t: exit after reading and executing one command
|
||||
* -v: echo as read
|
||||
* -x: trace
|
||||
* -u: unset variables net diagnostic
|
||||
*/
|
||||
extern char *flag;
|
||||
|
||||
extern char *null; /* null value for variable */
|
||||
extern int intr; /* interrupt pending */
|
||||
|
||||
Extern char *trap[_NSIG+1];
|
||||
Extern char ourtrap[_NSIG+1];
|
||||
Extern int trapset; /* trap pending */
|
||||
|
||||
extern int heedint; /* heed interrupt signals */
|
||||
|
||||
Extern int yynerrs; /* yacc */
|
||||
|
||||
Extern char line[LINELIM];
|
||||
extern char *elinep;
|
||||
|
||||
/*
|
||||
* other functions
|
||||
*/
|
||||
#ifdef __STDC__
|
||||
int (*inbuilt(char *s ))(void);
|
||||
#else
|
||||
int (*inbuilt())();
|
||||
#endif
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#define _PROTOTYPE(x,y) x ## y
|
||||
#endif
|
||||
|
||||
_PROTOTYPE(char *rexecve , (char *c , char **v , char **envp ));
|
||||
_PROTOTYPE(char *space , (int n ));
|
||||
_PROTOTYPE(char *strsave , (char *s , int a ));
|
||||
_PROTOTYPE(char *evalstr , (char *cp , int f ));
|
||||
_PROTOTYPE(char *putn , (int n ));
|
||||
_PROTOTYPE(char *itoa , (unsigned u , int n ));
|
||||
_PROTOTYPE(char *unquote , (char *as ));
|
||||
_PROTOTYPE(struct var *lookup , (char *n ));
|
||||
_PROTOTYPE(int rlookup , (char *n ));
|
||||
_PROTOTYPE(struct wdblock *glob , (char *cp , struct wdblock *wb ));
|
||||
_PROTOTYPE(int subgetc , (int ec , int quoted ));
|
||||
_PROTOTYPE(char **makenv , (void));
|
||||
_PROTOTYPE(char **eval , (char **ap , int f ));
|
||||
_PROTOTYPE(int setstatus , (int s ));
|
||||
_PROTOTYPE(int waitfor , (int lastpid , int canintr ));
|
||||
|
||||
_PROTOTYPE(void onintr , (int s )); /* SIGINT handler */
|
||||
|
||||
_PROTOTYPE(int newenv , (int f ));
|
||||
_PROTOTYPE(void quitenv , (void));
|
||||
_PROTOTYPE(void err , (char *s ));
|
||||
_PROTOTYPE(int anys , (char *s1 , char *s2 ));
|
||||
_PROTOTYPE(int any , (int c , char *s ));
|
||||
_PROTOTYPE(void next , (int f ));
|
||||
_PROTOTYPE(void setdash , (void));
|
||||
_PROTOTYPE(void onecommand , (void));
|
||||
_PROTOTYPE(void runtrap , (int i ));
|
||||
_PROTOTYPE(void xfree , (char *s ));
|
||||
_PROTOTYPE(int letter , (int c ));
|
||||
_PROTOTYPE(int digit , (int c ));
|
||||
_PROTOTYPE(int letnum , (int c ));
|
||||
_PROTOTYPE(int gmatch , (char *s , char *p ));
|
||||
|
||||
/*
|
||||
* error handling
|
||||
*/
|
||||
_PROTOTYPE(void leave , (void)); /* abort shell (or fail in subshell) */
|
||||
_PROTOTYPE(void fail , (void)); /* fail but return to process next command */
|
||||
_PROTOTYPE(void warn , (char *s ));
|
||||
_PROTOTYPE(void sig , (int i )); /* default signal handler */
|
||||
|
||||
/* -------- var.h -------- */
|
||||
|
||||
struct var {
|
||||
char *value;
|
||||
char *name;
|
||||
struct var *next;
|
||||
char status;
|
||||
};
|
||||
#define COPYV 1 /* flag to setval, suggesting copy */
|
||||
#define RONLY 01 /* variable is read-only */
|
||||
#define EXPORT 02 /* variable is to be exported */
|
||||
#define GETCELL 04 /* name & value space was got with getcell */
|
||||
|
||||
Extern struct var *vlist; /* dictionary */
|
||||
|
||||
Extern struct var *homedir; /* home directory */
|
||||
Extern struct var *prompt; /* main prompt */
|
||||
Extern struct var *cprompt; /* continuation prompt */
|
||||
Extern struct var *path; /* search path for commands */
|
||||
Extern struct var *shell; /* shell to interpret command files */
|
||||
Extern struct var *ifs; /* field separators */
|
||||
|
||||
_PROTOTYPE(int yyparse , (void));
|
||||
_PROTOTYPE(struct var *lookup , (char *n ));
|
||||
_PROTOTYPE(void setval , (struct var *vp , char *val ));
|
||||
_PROTOTYPE(void nameval , (struct var *vp , char *val , char *name ));
|
||||
_PROTOTYPE(void export , (struct var *vp ));
|
||||
_PROTOTYPE(void ronly , (struct var *vp ));
|
||||
_PROTOTYPE(int isassign , (char *s ));
|
||||
_PROTOTYPE(int checkname , (char *cp ));
|
||||
_PROTOTYPE(int assign , (char *s , int cf ));
|
||||
_PROTOTYPE(void putvlist , (int f , int out ));
|
||||
_PROTOTYPE(int eqname , (char *n1 , char *n2 ));
|
||||
|
||||
_PROTOTYPE(int execute , (struct op *t , int *pin , int *pout , int act ));
|
||||
|
||||
/* -------- io.h -------- */
|
||||
/* io buffer */
|
||||
struct iobuf {
|
||||
unsigned id; /* buffer id */
|
||||
char buf[512]; /* buffer */
|
||||
char *bufp; /* pointer into buffer */
|
||||
char *ebufp; /* pointer to end of buffer */
|
||||
};
|
||||
|
||||
/* possible arguments to an IO function */
|
||||
struct ioarg {
|
||||
char *aword;
|
||||
char **awordlist;
|
||||
int afile; /* file descriptor */
|
||||
unsigned afid; /* buffer id */
|
||||
long afpos; /* file position */
|
||||
struct iobuf *afbuf; /* buffer for this file */
|
||||
};
|
||||
Extern struct ioarg ioargstack[NPUSH];
|
||||
#define AFID_NOBUF (~0)
|
||||
#define AFID_ID 0
|
||||
|
||||
/* an input generator's state */
|
||||
struct io {
|
||||
int (*iofn)(_VOID);
|
||||
struct ioarg *argp;
|
||||
int peekc;
|
||||
char prev; /* previous character read by readc() */
|
||||
char nlcount; /* for `'s */
|
||||
char xchar; /* for `'s */
|
||||
char task; /* reason for pushed IO */
|
||||
};
|
||||
Extern struct io iostack[NPUSH];
|
||||
#define XOTHER 0 /* none of the below */
|
||||
#define XDOLL 1 /* expanding ${} */
|
||||
#define XGRAVE 2 /* expanding `'s */
|
||||
#define XIO 3 /* file IO */
|
||||
|
||||
/* in substitution */
|
||||
#define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL)
|
||||
|
||||
/*
|
||||
* input generators for IO structure
|
||||
*/
|
||||
_PROTOTYPE(int nlchar , (struct ioarg *ap ));
|
||||
_PROTOTYPE(int strchar , (struct ioarg *ap ));
|
||||
_PROTOTYPE(int qstrchar , (struct ioarg *ap ));
|
||||
_PROTOTYPE(int filechar , (struct ioarg *ap ));
|
||||
_PROTOTYPE(int herechar , (struct ioarg *ap ));
|
||||
_PROTOTYPE(int linechar , (struct ioarg *ap ));
|
||||
_PROTOTYPE(int gravechar , (struct ioarg *ap , struct io *iop ));
|
||||
_PROTOTYPE(int qgravechar , (struct ioarg *ap , struct io *iop ));
|
||||
_PROTOTYPE(int dolchar , (struct ioarg *ap ));
|
||||
_PROTOTYPE(int wdchar , (struct ioarg *ap ));
|
||||
_PROTOTYPE(void scraphere , (void));
|
||||
_PROTOTYPE(void freehere , (int area ));
|
||||
_PROTOTYPE(void gethere , (void));
|
||||
_PROTOTYPE(void markhere , (char *s , struct ioword *iop ));
|
||||
_PROTOTYPE(int herein , (char *hname , int xdoll ));
|
||||
_PROTOTYPE(int run , (struct ioarg *argp , int (*f)(_VOID)));
|
||||
|
||||
/*
|
||||
* IO functions
|
||||
*/
|
||||
_PROTOTYPE(int eofc , (void));
|
||||
_PROTOTYPE(int getc , (int ec ));
|
||||
_PROTOTYPE(int readc , (void));
|
||||
_PROTOTYPE(void unget , (int c ));
|
||||
_PROTOTYPE(void ioecho , (int c ));
|
||||
_PROTOTYPE(void prs , (char *s ));
|
||||
_PROTOTYPE(void putc , (int c ));
|
||||
_PROTOTYPE(void prn , (unsigned u ));
|
||||
_PROTOTYPE(void closef , (int i ));
|
||||
_PROTOTYPE(void closeall , (void));
|
||||
|
||||
/*
|
||||
* IO control
|
||||
*/
|
||||
_PROTOTYPE(void pushio , (struct ioarg *argp , int (*fn)(_VOID)));
|
||||
_PROTOTYPE(int remap , (int fd ));
|
||||
_PROTOTYPE(int openpipe , (int *pv ));
|
||||
_PROTOTYPE(void closepipe , (int *pv ));
|
||||
_PROTOTYPE(struct io *setbase , (struct io *ip ));
|
||||
|
||||
extern struct ioarg temparg; /* temporary for PUSHIO */
|
||||
#define PUSHIO(what,arg,gen) ((temparg.what = (arg)),pushio(&temparg,(gen)))
|
||||
#define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen)))
|
||||
|
||||
/* -------- word.h -------- */
|
||||
#ifndef WORD_H
|
||||
#define WORD_H 1
|
||||
struct wdblock {
|
||||
short w_bsize;
|
||||
short w_nword;
|
||||
/* bounds are arbitrary */
|
||||
char *w_words[1];
|
||||
};
|
||||
|
||||
_PROTOTYPE(struct wdblock *addword , (char *wd , struct wdblock *wb ));
|
||||
_PROTOTYPE(struct wdblock *newword , (int nw ));
|
||||
_PROTOTYPE(char **getwords , (struct wdblock *wb ));
|
||||
#endif
|
||||
|
||||
/* -------- area.h -------- */
|
||||
|
||||
/*
|
||||
* storage allocation
|
||||
*/
|
||||
_PROTOTYPE(char *getcell , (unsigned nbytes ));
|
||||
_PROTOTYPE(void garbage , (void));
|
||||
_PROTOTYPE(void setarea , (char *cp , int a ));
|
||||
_PROTOTYPE(int getarea , (char *cp ));
|
||||
_PROTOTYPE(void freearea , (int a ));
|
||||
_PROTOTYPE(void freecell , (char *cp ));
|
||||
|
||||
Extern int areanum; /* current allocation area */
|
||||
|
||||
#define NEW(type) (type *)getcell(sizeof(type))
|
||||
#define DELETE(obj) freecell((char *)obj)
|
@ -1,953 +0,0 @@
|
||||
#define Extern extern
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#define _NSIG NSIG
|
||||
#include <errno.h>
|
||||
#include <setjmp.h>
|
||||
#include "sh.h"
|
||||
/* -------- sh.c -------- */
|
||||
/*
|
||||
* shell
|
||||
*/
|
||||
|
||||
/* #include "sh.h" */
|
||||
|
||||
int intr;
|
||||
int inparse;
|
||||
char flags['z'-'a'+1];
|
||||
char *flag = flags-'a';
|
||||
char *elinep = line+sizeof(line)-5;
|
||||
char *null = "";
|
||||
int heedint =1;
|
||||
struct env e ={line, iostack, iostack-1,
|
||||
(xint *)NULL, FDBASE, (struct env *)NULL};
|
||||
|
||||
extern char **environ; /* environment pointer */
|
||||
|
||||
/*
|
||||
* default shell, search rules
|
||||
*/
|
||||
char shellname[] = "/bin/sh";
|
||||
char search[] = ":/bin:/usr/bin";
|
||||
|
||||
_PROTOTYPE(void (*qflag), (int)) = SIG_IGN;
|
||||
|
||||
_PROTOTYPE(int main, (int argc, char **argv ));
|
||||
_PROTOTYPE(int newfile, (char *s ));
|
||||
_PROTOTYPE(static char *findeq, (char *cp ));
|
||||
_PROTOTYPE(static char *cclass, (char *p, int sub ));
|
||||
_PROTOTYPE(void initarea, (void));
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
register char **argv;
|
||||
{
|
||||
register int f;
|
||||
register char *s;
|
||||
int cflag;
|
||||
char *name, **ap;
|
||||
int (*iof)();
|
||||
|
||||
initarea();
|
||||
if ((ap = environ) != NULL) {
|
||||
while (*ap)
|
||||
assign(*ap++, !COPYV);
|
||||
for (ap = environ; *ap;)
|
||||
export(lookup(*ap++));
|
||||
}
|
||||
closeall();
|
||||
areanum = 1;
|
||||
|
||||
shell = lookup("SHELL");
|
||||
if (shell->value == null)
|
||||
setval(shell, shellname);
|
||||
export(shell);
|
||||
|
||||
homedir = lookup("HOME");
|
||||
if (homedir->value == null)
|
||||
setval(homedir, "/");
|
||||
export(homedir);
|
||||
|
||||
setval(lookup("$"), itoa(getpid(), 5));
|
||||
|
||||
path = lookup("PATH");
|
||||
if (path->value == null)
|
||||
setval(path, search);
|
||||
export(path);
|
||||
|
||||
ifs = lookup("IFS");
|
||||
if (ifs->value == null)
|
||||
setval(ifs, " \t\n");
|
||||
|
||||
prompt = lookup("PS1");
|
||||
if (prompt->value == null)
|
||||
#ifndef UNIXSHELL
|
||||
setval(prompt, "$ ");
|
||||
#else
|
||||
setval(prompt, "% ");
|
||||
#endif
|
||||
|
||||
if (geteuid() == 0) {
|
||||
setval(prompt, "# ");
|
||||
prompt->status &= ~EXPORT;
|
||||
}
|
||||
cprompt = lookup("PS2");
|
||||
if (cprompt->value == null)
|
||||
setval(cprompt, "> ");
|
||||
|
||||
iof = filechar;
|
||||
cflag = 0;
|
||||
name = *argv++;
|
||||
if (--argc >= 1) {
|
||||
if(argv[0][0] == '-' && argv[0][1] != '\0') {
|
||||
for (s = argv[0]+1; *s; s++)
|
||||
switch (*s) {
|
||||
case 'c':
|
||||
prompt->status &= ~EXPORT;
|
||||
cprompt->status &= ~EXPORT;
|
||||
setval(prompt, "");
|
||||
setval(cprompt, "");
|
||||
cflag = 1;
|
||||
if (--argc > 0)
|
||||
PUSHIO(aword, *++argv, iof = nlchar);
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
qflag = SIG_DFL;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
/* standard input */
|
||||
break;
|
||||
|
||||
case 't':
|
||||
prompt->status &= ~EXPORT;
|
||||
setval(prompt, "");
|
||||
iof = linechar;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
talking++;
|
||||
default:
|
||||
if (*s>='a' && *s<='z')
|
||||
flag[*s]++;
|
||||
}
|
||||
} else {
|
||||
argv--;
|
||||
argc++;
|
||||
}
|
||||
if (iof == filechar && --argc > 0) {
|
||||
setval(prompt, "");
|
||||
setval(cprompt, "");
|
||||
prompt->status &= ~EXPORT;
|
||||
cprompt->status &= ~EXPORT;
|
||||
if (newfile(name = *++argv))
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
setdash();
|
||||
if (e.iop < iostack) {
|
||||
PUSHIO(afile, 0, iof);
|
||||
if (isatty(0) && isatty(1) && !cflag)
|
||||
talking++;
|
||||
}
|
||||
signal(SIGQUIT, qflag);
|
||||
if (name && name[0] == '-') {
|
||||
talking++;
|
||||
if ((f = open(".profile", 0)) >= 0)
|
||||
next(remap(f));
|
||||
if ((f = open("/etc/profile", 0)) >= 0)
|
||||
next(remap(f));
|
||||
}
|
||||
if (talking)
|
||||
signal(SIGTERM, sig);
|
||||
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
|
||||
signal(SIGINT, onintr);
|
||||
dolv = argv;
|
||||
dolc = argc;
|
||||
dolv[0] = name;
|
||||
if (dolc > 1)
|
||||
for (ap = ++argv; --argc > 0;)
|
||||
if (assign(*ap = *argv++, !COPYV))
|
||||
dolc--; /* keyword */
|
||||
else
|
||||
ap++;
|
||||
setval(lookup("#"), putn((--dolc < 0) ? (dolc = 0) : dolc));
|
||||
|
||||
for (;;) {
|
||||
if (talking && e.iop <= iostack)
|
||||
prs(prompt->value);
|
||||
onecommand();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
setdash()
|
||||
{
|
||||
register char *cp, c;
|
||||
char m['z'-'a'+1];
|
||||
|
||||
cp = m;
|
||||
for (c='a'; c<='z'; c++)
|
||||
if (flag[c])
|
||||
*cp++ = c;
|
||||
*cp = 0;
|
||||
setval(lookup("-"), m);
|
||||
}
|
||||
|
||||
int
|
||||
newfile(s)
|
||||
register char *s;
|
||||
{
|
||||
register f;
|
||||
|
||||
if (strcmp(s, "-") != 0) {
|
||||
f = open(s, 0);
|
||||
if (f < 0) {
|
||||
prs(s);
|
||||
err(": cannot open");
|
||||
return(1);
|
||||
}
|
||||
} else
|
||||
f = 0;
|
||||
next(remap(f));
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
onecommand()
|
||||
{
|
||||
register i;
|
||||
jmp_buf m1;
|
||||
|
||||
while (e.oenv)
|
||||
quitenv();
|
||||
areanum = 1;
|
||||
freehere(areanum);
|
||||
freearea(areanum);
|
||||
garbage();
|
||||
wdlist = 0;
|
||||
iolist = 0;
|
||||
e.errpt = 0;
|
||||
e.linep = line;
|
||||
yynerrs = 0;
|
||||
multiline = 0;
|
||||
inparse = 1;
|
||||
intr = 0;
|
||||
execflg = 0;
|
||||
setjmp(failpt = m1); /* Bruce Evans' fix */
|
||||
if (setjmp(failpt = m1) || yyparse() || intr) {
|
||||
while (e.oenv)
|
||||
quitenv();
|
||||
scraphere();
|
||||
if (!talking && intr)
|
||||
leave();
|
||||
inparse = 0;
|
||||
intr = 0;
|
||||
return;
|
||||
}
|
||||
inparse = 0;
|
||||
brklist = 0;
|
||||
intr = 0;
|
||||
execflg = 0;
|
||||
if (!flag['n'])
|
||||
execute(outtree, NOPIPE, NOPIPE, 0);
|
||||
if (!talking && intr) {
|
||||
execflg = 0;
|
||||
leave();
|
||||
}
|
||||
if ((i = trapset) != 0) {
|
||||
trapset = 0;
|
||||
runtrap(i);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
fail()
|
||||
{
|
||||
longjmp(failpt, 1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void
|
||||
leave()
|
||||
{
|
||||
if (execflg)
|
||||
fail();
|
||||
scraphere();
|
||||
freehere(1);
|
||||
runtrap(0);
|
||||
exit(exstat);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void
|
||||
warn(s)
|
||||
register char *s;
|
||||
{
|
||||
if(*s) {
|
||||
prs(s);
|
||||
exstat = -1;
|
||||
}
|
||||
prs("\n");
|
||||
if (flag['e'])
|
||||
leave();
|
||||
}
|
||||
|
||||
void
|
||||
err(s)
|
||||
char *s;
|
||||
{
|
||||
warn(s);
|
||||
if (flag['n'])
|
||||
return;
|
||||
if (!talking)
|
||||
leave();
|
||||
if (e.errpt)
|
||||
longjmp(e.errpt, 1);
|
||||
closeall();
|
||||
e.iop = e.iobase = iostack;
|
||||
}
|
||||
|
||||
int
|
||||
newenv(f)
|
||||
int f;
|
||||
{
|
||||
register struct env *ep;
|
||||
|
||||
if (f) {
|
||||
quitenv();
|
||||
return(1);
|
||||
}
|
||||
ep = (struct env *) space(sizeof(*ep));
|
||||
if (ep == NULL) {
|
||||
while (e.oenv)
|
||||
quitenv();
|
||||
fail();
|
||||
}
|
||||
*ep = e;
|
||||
e.oenv = ep;
|
||||
e.errpt = errpt;
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
quitenv()
|
||||
{
|
||||
register struct env *ep;
|
||||
register fd;
|
||||
|
||||
if ((ep = e.oenv) != NULL) {
|
||||
fd = e.iofd;
|
||||
e = *ep;
|
||||
/* should close `'d files */
|
||||
DELETE(ep);
|
||||
while (--fd >= e.iofd)
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Is any character from s1 in s2?
|
||||
*/
|
||||
int
|
||||
anys(s1, s2)
|
||||
register char *s1, *s2;
|
||||
{
|
||||
while (*s1)
|
||||
if (any(*s1++, s2))
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Is character c in s?
|
||||
*/
|
||||
int
|
||||
any(c, s)
|
||||
register int c;
|
||||
register char *s;
|
||||
{
|
||||
while (*s)
|
||||
if (*s++ == c)
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
char *
|
||||
putn(n)
|
||||
register int n;
|
||||
{
|
||||
return(itoa(n, -1));
|
||||
}
|
||||
|
||||
char *
|
||||
itoa(u, n)
|
||||
register unsigned u;
|
||||
int n;
|
||||
{
|
||||
register char *cp;
|
||||
static char s[20];
|
||||
int m;
|
||||
|
||||
m = 0;
|
||||
if (n < 0 && (int) u < 0) {
|
||||
m++;
|
||||
u = -u;
|
||||
}
|
||||
cp = s+sizeof(s);
|
||||
*--cp = 0;
|
||||
do {
|
||||
*--cp = u%10 + '0';
|
||||
u /= 10;
|
||||
} while (--n > 0 || u);
|
||||
if (m)
|
||||
*--cp = '-';
|
||||
return(cp);
|
||||
}
|
||||
|
||||
void
|
||||
next(f)
|
||||
int f;
|
||||
{
|
||||
PUSHIO(afile, f, filechar);
|
||||
}
|
||||
|
||||
void
|
||||
onintr(s)
|
||||
int s; /* ANSI C requires a parameter */
|
||||
{
|
||||
signal(SIGINT, onintr);
|
||||
intr = 1;
|
||||
if (talking) {
|
||||
if (inparse) {
|
||||
prs("\n");
|
||||
fail();
|
||||
}
|
||||
}
|
||||
else if (heedint) {
|
||||
execflg = 0;
|
||||
leave();
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
letter(c)
|
||||
register c;
|
||||
{
|
||||
return((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_');
|
||||
}
|
||||
|
||||
int
|
||||
digit(c)
|
||||
register c;
|
||||
{
|
||||
return(c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
int
|
||||
letnum(c)
|
||||
register c;
|
||||
{
|
||||
return(letter(c) || digit(c));
|
||||
}
|
||||
|
||||
char *
|
||||
space(n)
|
||||
int n;
|
||||
{
|
||||
register char *cp;
|
||||
|
||||
if ((cp = getcell(n)) == 0)
|
||||
err("out of string space");
|
||||
return(cp);
|
||||
}
|
||||
|
||||
char *
|
||||
strsave(s, a)
|
||||
register char *s;
|
||||
int a;
|
||||
{
|
||||
register char *cp, *xp;
|
||||
|
||||
if ((cp = space(strlen(s)+1)) != NULL) {
|
||||
setarea((char *)cp, a);
|
||||
for (xp = cp; (*xp++ = *s++) != '\0';)
|
||||
;
|
||||
return(cp);
|
||||
}
|
||||
return("");
|
||||
}
|
||||
|
||||
void
|
||||
xfree(s)
|
||||
register char *s;
|
||||
{
|
||||
DELETE(s);
|
||||
}
|
||||
|
||||
/*
|
||||
* trap handling
|
||||
*/
|
||||
void
|
||||
sig(i)
|
||||
register int i;
|
||||
{
|
||||
trapset = i;
|
||||
signal(i, sig);
|
||||
}
|
||||
|
||||
void runtrap(i)
|
||||
int i;
|
||||
{
|
||||
char *trapstr;
|
||||
|
||||
if ((trapstr = trap[i]) == NULL)
|
||||
return;
|
||||
if (i == 0)
|
||||
trap[i] = 0;
|
||||
RUN(aword, trapstr, nlchar);
|
||||
}
|
||||
|
||||
/* -------- var.c -------- */
|
||||
/* #include "sh.h" */
|
||||
|
||||
/*
|
||||
* Find the given name in the dictionary
|
||||
* and return its value. If the name was
|
||||
* not previously there, enter it now and
|
||||
* return a null value.
|
||||
*/
|
||||
struct var *
|
||||
lookup(n)
|
||||
register char *n;
|
||||
{
|
||||
register struct var *vp;
|
||||
register char *cp;
|
||||
register int c;
|
||||
static struct var dummy;
|
||||
|
||||
if (digit(*n)) {
|
||||
dummy.name = n;
|
||||
for (c = 0; digit(*n) && c < 1000; n++)
|
||||
c = c*10 + *n-'0';
|
||||
dummy.status = RONLY;
|
||||
dummy.value = c <= dolc? dolv[c]: null;
|
||||
return(&dummy);
|
||||
}
|
||||
for (vp = vlist; vp; vp = vp->next)
|
||||
if (eqname(vp->name, n))
|
||||
return(vp);
|
||||
cp = findeq(n);
|
||||
vp = (struct var *)space(sizeof(*vp));
|
||||
if (vp == 0 || (vp->name = space((int)(cp-n)+2)) == 0) {
|
||||
dummy.name = dummy.value = "";
|
||||
return(&dummy);
|
||||
}
|
||||
for (cp = vp->name; (*cp = *n++) && *cp != '='; cp++)
|
||||
;
|
||||
if (*cp == 0)
|
||||
*cp = '=';
|
||||
*++cp = 0;
|
||||
setarea((char *)vp, 0);
|
||||
setarea((char *)vp->name, 0);
|
||||
vp->value = null;
|
||||
vp->next = vlist;
|
||||
vp->status = GETCELL;
|
||||
vlist = vp;
|
||||
return(vp);
|
||||
}
|
||||
|
||||
/*
|
||||
* give variable at `vp' the value `val'.
|
||||
*/
|
||||
void
|
||||
setval(vp, val)
|
||||
struct var *vp;
|
||||
char *val;
|
||||
{
|
||||
nameval(vp, val, (char *)NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* if name is not NULL, it must be
|
||||
* a prefix of the space `val',
|
||||
* and end with `='.
|
||||
* this is all so that exporting
|
||||
* values is reasonably painless.
|
||||
*/
|
||||
void
|
||||
nameval(vp, val, name)
|
||||
register struct var *vp;
|
||||
char *val, *name;
|
||||
{
|
||||
register char *cp, *xp;
|
||||
char *nv;
|
||||
int fl;
|
||||
|
||||
if (vp->status & RONLY) {
|
||||
for (xp = vp->name; *xp && *xp != '=';)
|
||||
putc(*xp++);
|
||||
err(" is read-only");
|
||||
return;
|
||||
}
|
||||
fl = 0;
|
||||
if (name == NULL) {
|
||||
xp = space(strlen(vp->name)+strlen(val)+2);
|
||||
if (xp == 0)
|
||||
return;
|
||||
/* make string: name=value */
|
||||
setarea((char *)xp, 0);
|
||||
name = xp;
|
||||
for (cp = vp->name; (*xp = *cp++) && *xp!='='; xp++)
|
||||
;
|
||||
if (*xp++ == 0)
|
||||
xp[-1] = '=';
|
||||
nv = xp;
|
||||
for (cp = val; (*xp++ = *cp++) != '\0';)
|
||||
;
|
||||
val = nv;
|
||||
fl = GETCELL;
|
||||
}
|
||||
if (vp->status & GETCELL)
|
||||
xfree(vp->name); /* form new string `name=value' */
|
||||
vp->name = name;
|
||||
vp->value = val;
|
||||
vp->status |= fl;
|
||||
}
|
||||
|
||||
void
|
||||
export(vp)
|
||||
struct var *vp;
|
||||
{
|
||||
vp->status |= EXPORT;
|
||||
}
|
||||
|
||||
void
|
||||
ronly(vp)
|
||||
struct var *vp;
|
||||
{
|
||||
if (letter(vp->name[0])) /* not an internal symbol ($# etc) */
|
||||
vp->status |= RONLY;
|
||||
}
|
||||
|
||||
int
|
||||
isassign(s)
|
||||
register char *s;
|
||||
{
|
||||
if (!letter((int)*s))
|
||||
return(0);
|
||||
for (; *s != '='; s++)
|
||||
if (*s == 0 || !letnum(*s))
|
||||
return(0);
|
||||
return(1);
|
||||
}
|
||||
|
||||
int
|
||||
assign(s, cf)
|
||||
register char *s;
|
||||
int cf;
|
||||
{
|
||||
register char *cp;
|
||||
struct var *vp;
|
||||
|
||||
if (!letter(*s))
|
||||
return(0);
|
||||
for (cp = s; *cp != '='; cp++)
|
||||
if (*cp == 0 || !letnum(*cp))
|
||||
return(0);
|
||||
vp = lookup(s);
|
||||
nameval(vp, ++cp, cf == COPYV? (char *)NULL: s);
|
||||
if (cf != COPYV)
|
||||
vp->status &= ~GETCELL;
|
||||
return(1);
|
||||
}
|
||||
|
||||
int
|
||||
checkname(cp)
|
||||
register char *cp;
|
||||
{
|
||||
if (!letter(*cp++))
|
||||
return(0);
|
||||
while (*cp)
|
||||
if (!letnum(*cp++))
|
||||
return(0);
|
||||
return(1);
|
||||
}
|
||||
|
||||
void
|
||||
putvlist(f, out)
|
||||
register int f, out;
|
||||
{
|
||||
register struct var *vp;
|
||||
|
||||
for (vp = vlist; vp; vp = vp->next)
|
||||
if (vp->status & f && letter(*vp->name)) {
|
||||
if (vp->status & EXPORT)
|
||||
write(out, "export ", 7);
|
||||
if (vp->status & RONLY)
|
||||
write(out, "readonly ", 9);
|
||||
write(out, vp->name, (int)(findeq(vp->name) - vp->name));
|
||||
write(out, "\n", 1);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
eqname(n1, n2)
|
||||
register char *n1, *n2;
|
||||
{
|
||||
for (; *n1 != '=' && *n1 != 0; n1++)
|
||||
if (*n2++ != *n1)
|
||||
return(0);
|
||||
return(*n2 == 0 || *n2 == '=');
|
||||
}
|
||||
|
||||
static char *
|
||||
findeq(cp)
|
||||
register char *cp;
|
||||
{
|
||||
while (*cp != '\0' && *cp != '=')
|
||||
cp++;
|
||||
return(cp);
|
||||
}
|
||||
|
||||
/* -------- gmatch.c -------- */
|
||||
/*
|
||||
* int gmatch(string, pattern)
|
||||
* char *string, *pattern;
|
||||
*
|
||||
* Match a pattern as in sh(1).
|
||||
*/
|
||||
|
||||
#define CMASK 0377
|
||||
#define QUOTE 0200
|
||||
#define QMASK (CMASK&~QUOTE)
|
||||
#define NOT '!' /* might use ^ */
|
||||
|
||||
int
|
||||
gmatch(s, p)
|
||||
register char *s, *p;
|
||||
{
|
||||
register int sc, pc;
|
||||
|
||||
if (s == NULL || p == NULL)
|
||||
return(0);
|
||||
while ((pc = *p++ & CMASK) != '\0') {
|
||||
sc = *s++ & QMASK;
|
||||
switch (pc) {
|
||||
case '[':
|
||||
if ((p = cclass(p, sc)) == NULL)
|
||||
return(0);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
if (sc == 0)
|
||||
return(0);
|
||||
break;
|
||||
|
||||
case '*':
|
||||
s--;
|
||||
do {
|
||||
if (*p == '\0' || gmatch(s, p))
|
||||
return(1);
|
||||
} while (*s++ != '\0');
|
||||
return(0);
|
||||
|
||||
default:
|
||||
if (sc != (pc&~QUOTE))
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
return(*s == 0);
|
||||
}
|
||||
|
||||
static char *
|
||||
cclass(p, sub)
|
||||
register char *p;
|
||||
register int sub;
|
||||
{
|
||||
register int c, d, not, found;
|
||||
|
||||
if ((not = *p == NOT) != 0)
|
||||
p++;
|
||||
found = not;
|
||||
do {
|
||||
if (*p == '\0')
|
||||
return((char *)NULL);
|
||||
c = *p & CMASK;
|
||||
if (p[1] == '-' && p[2] != ']') {
|
||||
d = p[2] & CMASK;
|
||||
p++;
|
||||
} else
|
||||
d = c;
|
||||
if (c == sub || (c <= sub && sub <= d))
|
||||
found = !not;
|
||||
} while (*++p != ']');
|
||||
return(found? p+1: (char *)NULL);
|
||||
}
|
||||
|
||||
/* -------- area.c -------- */
|
||||
#define REGSIZE sizeof(struct region)
|
||||
#define GROWBY 256
|
||||
#undef SHRINKBY 64
|
||||
#define FREE 32767
|
||||
#define BUSY 0
|
||||
#define ALIGN (sizeof(int)-1)
|
||||
|
||||
/* #include "area.h" */
|
||||
|
||||
struct region {
|
||||
struct region *next;
|
||||
int area;
|
||||
};
|
||||
|
||||
/*
|
||||
* All memory between (char *)areabot and (char *)(areatop+1) is
|
||||
* exclusively administered by the area management routines.
|
||||
* It is assumed that sbrk() and brk() manipulate the high end.
|
||||
*/
|
||||
static struct region *areabot; /* bottom of area */
|
||||
static struct region *areatop; /* top of area */
|
||||
static struct region *areanxt; /* starting point of scan */
|
||||
|
||||
void
|
||||
initarea()
|
||||
{
|
||||
while ((int)sbrk(0) & ALIGN)
|
||||
sbrk(1);
|
||||
areabot = (struct region *)sbrk(REGSIZE);
|
||||
areabot->next = areabot;
|
||||
areabot->area = BUSY;
|
||||
areatop = areabot;
|
||||
areanxt = areabot;
|
||||
}
|
||||
|
||||
char *
|
||||
getcell(nbytes)
|
||||
unsigned nbytes;
|
||||
{
|
||||
register int nregio;
|
||||
register struct region *p, *q;
|
||||
register i;
|
||||
|
||||
if (nbytes == 0)
|
||||
abort(); /* silly and defeats the algorithm */
|
||||
/*
|
||||
* round upwards and add administration area
|
||||
*/
|
||||
nregio = (nbytes+(REGSIZE-1))/REGSIZE + 1;
|
||||
for (p = areanxt;;) {
|
||||
if (p->area > areanum) {
|
||||
/*
|
||||
* merge free cells
|
||||
*/
|
||||
while ((q = p->next)->area > areanum && q != areanxt)
|
||||
p->next = q->next;
|
||||
/*
|
||||
* exit loop if cell big enough
|
||||
*/
|
||||
if (q >= p + nregio)
|
||||
goto found;
|
||||
}
|
||||
p = p->next;
|
||||
if (p == areanxt)
|
||||
break;
|
||||
}
|
||||
i = nregio >= GROWBY ? nregio : GROWBY;
|
||||
p = (struct region *)sbrk(i * REGSIZE);
|
||||
if (p == (struct region *)-1)
|
||||
return((char *)NULL);
|
||||
p--;
|
||||
if (p != areatop)
|
||||
abort(); /* allocated areas are contiguous */
|
||||
q = p + i;
|
||||
p->next = q;
|
||||
p->area = FREE;
|
||||
q->next = areabot;
|
||||
q->area = BUSY;
|
||||
areatop = q;
|
||||
found:
|
||||
/*
|
||||
* we found a FREE area big enough, pointed to by 'p', and up to 'q'
|
||||
*/
|
||||
areanxt = p + nregio;
|
||||
if (areanxt < q) {
|
||||
/*
|
||||
* split into requested area and rest
|
||||
*/
|
||||
if (areanxt+1 > q)
|
||||
abort(); /* insufficient space left for admin */
|
||||
areanxt->next = q;
|
||||
areanxt->area = FREE;
|
||||
p->next = areanxt;
|
||||
}
|
||||
p->area = areanum;
|
||||
return((char *)(p+1));
|
||||
}
|
||||
|
||||
void
|
||||
freecell(cp)
|
||||
char *cp;
|
||||
{
|
||||
register struct region *p;
|
||||
|
||||
if ((p = (struct region *)cp) != NULL) {
|
||||
p--;
|
||||
if (p < areanxt)
|
||||
areanxt = p;
|
||||
p->area = FREE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
freearea(a)
|
||||
register int a;
|
||||
{
|
||||
register struct region *p, *top;
|
||||
|
||||
top = areatop;
|
||||
for (p = areabot; p != top; p = p->next)
|
||||
if (p->area >= a)
|
||||
p->area = FREE;
|
||||
}
|
||||
|
||||
void
|
||||
setarea(cp,a)
|
||||
char *cp;
|
||||
int a;
|
||||
{
|
||||
register struct region *p;
|
||||
|
||||
if ((p = (struct region *)cp) != NULL)
|
||||
(p-1)->area = a;
|
||||
}
|
||||
|
||||
int
|
||||
getarea(cp)
|
||||
char *cp;
|
||||
{
|
||||
return ((struct region*)cp-1)->area;
|
||||
}
|
||||
|
||||
void
|
||||
garbage()
|
||||
{
|
||||
register struct region *p, *q, *top;
|
||||
|
||||
top = areatop;
|
||||
for (p = areabot; p != top; p = p->next) {
|
||||
if (p->area > areanum) {
|
||||
while ((q = p->next)->area > areanum)
|
||||
p->next = q->next;
|
||||
areanxt = p;
|
||||
}
|
||||
}
|
||||
#ifdef SHRINKBY
|
||||
if (areatop >= q + SHRINKBY && q->area > areanum) {
|
||||
brk((char *)(q+1));
|
||||
q->next = areabot;
|
||||
q->area = BUSY;
|
||||
areatop = q;
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,801 +0,0 @@
|
||||
#define Extern extern
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#define _NSIG NSIG
|
||||
#include <errno.h>
|
||||
#include <setjmp.h>
|
||||
#include "sh.h"
|
||||
|
||||
/* -------- csyn.c -------- */
|
||||
/*
|
||||
* shell: syntax (C version)
|
||||
*/
|
||||
|
||||
typedef union {
|
||||
char *cp;
|
||||
char **wp;
|
||||
int i;
|
||||
struct op *o;
|
||||
} YYSTYPE;
|
||||
#define WORD 256
|
||||
#define LOGAND 257
|
||||
#define LOGOR 258
|
||||
#define BREAK 259
|
||||
#define IF 260
|
||||
#define THEN 261
|
||||
#define ELSE 262
|
||||
#define ELIF 263
|
||||
#define FI 264
|
||||
#define CASE 265
|
||||
#define ESAC 266
|
||||
#define FOR 267
|
||||
#define WHILE 268
|
||||
#define UNTIL 269
|
||||
#define DO 270
|
||||
#define DONE 271
|
||||
#define IN 272
|
||||
#define YYERRCODE 300
|
||||
|
||||
/* flags to yylex */
|
||||
#define CONTIN 01 /* skip new lines to complete command */
|
||||
|
||||
/* #include "sh.h" */
|
||||
#define SYNTAXERR zzerr()
|
||||
static int startl;
|
||||
static int peeksym;
|
||||
static int nlseen;
|
||||
static int iounit = IODEFAULT;
|
||||
|
||||
static YYSTYPE yylval;
|
||||
|
||||
_PROTOTYPE(static struct op *pipeline, (int cf ));
|
||||
_PROTOTYPE(static struct op *andor, (void));
|
||||
_PROTOTYPE(static struct op *c_list, (void));
|
||||
_PROTOTYPE(static int synio, (int cf ));
|
||||
_PROTOTYPE(static void musthave, (int c, int cf ));
|
||||
_PROTOTYPE(static struct op *simple, (void));
|
||||
_PROTOTYPE(static struct op *nested, (int type, int mark ));
|
||||
_PROTOTYPE(static struct op *command, (int cf ));
|
||||
_PROTOTYPE(static struct op *dogroup, (int onlydone ));
|
||||
_PROTOTYPE(static struct op *thenpart, (void));
|
||||
_PROTOTYPE(static struct op *elsepart, (void));
|
||||
_PROTOTYPE(static struct op *caselist, (void));
|
||||
_PROTOTYPE(static struct op *casepart, (void));
|
||||
_PROTOTYPE(static char **pattern, (void));
|
||||
_PROTOTYPE(static char **wordlist, (void));
|
||||
_PROTOTYPE(static struct op *list, (struct op *t1, struct op *t2 ));
|
||||
_PROTOTYPE(static struct op *block, (int type, struct op *t1, struct op *t2, char **wp ));
|
||||
_PROTOTYPE(static struct op *newtp, (void));
|
||||
_PROTOTYPE(static struct op *namelist, (struct op *t ));
|
||||
_PROTOTYPE(static char **copyw, (void));
|
||||
_PROTOTYPE(static void word, (char *cp ));
|
||||
_PROTOTYPE(static struct ioword **copyio, (void));
|
||||
_PROTOTYPE(static struct ioword *io, (int u, int f, char *cp ));
|
||||
_PROTOTYPE(static void zzerr, (void));
|
||||
_PROTOTYPE(void yyerror, (char *s ));
|
||||
_PROTOTYPE(static int yylex, (int cf ));
|
||||
_PROTOTYPE(int collect, (int c, int c1 ));
|
||||
_PROTOTYPE(int dual, (int c ));
|
||||
_PROTOTYPE(static void diag, (int ec ));
|
||||
_PROTOTYPE(static char *tree, (unsigned size ));
|
||||
_PROTOTYPE(void printf, (char *s ));
|
||||
|
||||
int
|
||||
yyparse()
|
||||
{
|
||||
startl = 1;
|
||||
peeksym = 0;
|
||||
yynerrs = 0;
|
||||
outtree = c_list();
|
||||
musthave('\n', 0);
|
||||
return(yynerrs!=0);
|
||||
}
|
||||
|
||||
static struct op *
|
||||
pipeline(cf)
|
||||
int cf;
|
||||
{
|
||||
register struct op *t, *p;
|
||||
register int c;
|
||||
|
||||
t = command(cf);
|
||||
if (t != NULL) {
|
||||
while ((c = yylex(0)) == '|') {
|
||||
if ((p = command(CONTIN)) == NULL)
|
||||
SYNTAXERR;
|
||||
if (t->type != TPAREN && t->type != TCOM) {
|
||||
/* shell statement */
|
||||
t = block(TPAREN, t, NOBLOCK, NOWORDS);
|
||||
}
|
||||
t = block(TPIPE, t, p, NOWORDS);
|
||||
}
|
||||
peeksym = c;
|
||||
}
|
||||
return(t);
|
||||
}
|
||||
|
||||
static struct op *
|
||||
andor()
|
||||
{
|
||||
register struct op *t, *p;
|
||||
register int c;
|
||||
|
||||
t = pipeline(0);
|
||||
if (t != NULL) {
|
||||
while ((c = yylex(0)) == LOGAND || c == LOGOR) {
|
||||
if ((p = pipeline(CONTIN)) == NULL)
|
||||
SYNTAXERR;
|
||||
t = block(c == LOGAND? TAND: TOR, t, p, NOWORDS);
|
||||
}
|
||||
peeksym = c;
|
||||
}
|
||||
return(t);
|
||||
}
|
||||
|
||||
static struct op *
|
||||
c_list()
|
||||
{
|
||||
register struct op *t, *p;
|
||||
register int c;
|
||||
|
||||
t = andor();
|
||||
if (t != NULL) {
|
||||
if((peeksym = yylex(0)) == '&')
|
||||
t = block(TASYNC, t, NOBLOCK, NOWORDS);
|
||||
while ((c = yylex(0)) == ';' || c == '&' || (multiline && c == '\n')) {
|
||||
if ((p = andor()) == NULL)
|
||||
return(t);
|
||||
if((peeksym = yylex(0)) == '&')
|
||||
p = block(TASYNC, p, NOBLOCK, NOWORDS);
|
||||
t = list(t, p);
|
||||
}
|
||||
peeksym = c;
|
||||
}
|
||||
return(t);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
synio(cf)
|
||||
int cf;
|
||||
{
|
||||
register struct ioword *iop;
|
||||
register int i;
|
||||
register int c;
|
||||
|
||||
if ((c = yylex(cf)) != '<' && c != '>') {
|
||||
peeksym = c;
|
||||
return(0);
|
||||
}
|
||||
i = yylval.i;
|
||||
musthave(WORD, 0);
|
||||
iop = io(iounit, i, yylval.cp);
|
||||
iounit = IODEFAULT;
|
||||
if (i & IOHERE)
|
||||
markhere(yylval.cp, iop);
|
||||
return(1);
|
||||
}
|
||||
|
||||
static void
|
||||
musthave(c, cf)
|
||||
int c, cf;
|
||||
{
|
||||
if ((peeksym = yylex(cf)) != c)
|
||||
SYNTAXERR;
|
||||
peeksym = 0;
|
||||
}
|
||||
|
||||
static struct op *
|
||||
simple()
|
||||
{
|
||||
register struct op *t;
|
||||
|
||||
t = NULL;
|
||||
for (;;) {
|
||||
switch (peeksym = yylex(0)) {
|
||||
case '<':
|
||||
case '>':
|
||||
(void) synio(0);
|
||||
break;
|
||||
|
||||
case WORD:
|
||||
if (t == NULL) {
|
||||
t = newtp();
|
||||
t->type = TCOM;
|
||||
}
|
||||
peeksym = 0;
|
||||
word(yylval.cp);
|
||||
break;
|
||||
|
||||
default:
|
||||
return(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct op *
|
||||
nested(type, mark)
|
||||
int type, mark;
|
||||
{
|
||||
register struct op *t;
|
||||
|
||||
multiline++;
|
||||
t = c_list();
|
||||
musthave(mark, 0);
|
||||
multiline--;
|
||||
return(block(type, t, NOBLOCK, NOWORDS));
|
||||
}
|
||||
|
||||
static struct op *
|
||||
command(cf)
|
||||
int cf;
|
||||
{
|
||||
register struct op *t;
|
||||
struct wdblock *iosave;
|
||||
register int c;
|
||||
|
||||
iosave = iolist;
|
||||
iolist = NULL;
|
||||
if (multiline)
|
||||
cf |= CONTIN;
|
||||
while (synio(cf))
|
||||
cf = 0;
|
||||
switch (c = yylex(cf)) {
|
||||
default:
|
||||
peeksym = c;
|
||||
if ((t = simple()) == NULL) {
|
||||
if (iolist == NULL)
|
||||
return((struct op *)NULL);
|
||||
t = newtp();
|
||||
t->type = TCOM;
|
||||
}
|
||||
break;
|
||||
|
||||
case '(':
|
||||
t = nested(TPAREN, ')');
|
||||
break;
|
||||
|
||||
case '{':
|
||||
t = nested(TBRACE, '}');
|
||||
break;
|
||||
|
||||
case FOR:
|
||||
t = newtp();
|
||||
t->type = TFOR;
|
||||
musthave(WORD, 0);
|
||||
startl = 1;
|
||||
t->str = yylval.cp;
|
||||
multiline++;
|
||||
t->words = wordlist();
|
||||
if ((c = yylex(0)) != '\n' && c != ';')
|
||||
peeksym = c;
|
||||
t->left = dogroup(0);
|
||||
multiline--;
|
||||
break;
|
||||
|
||||
case WHILE:
|
||||
case UNTIL:
|
||||
multiline++;
|
||||
t = newtp();
|
||||
t->type = c == WHILE? TWHILE: TUNTIL;
|
||||
t->left = c_list();
|
||||
t->right = dogroup(1);
|
||||
t->words = NULL;
|
||||
multiline--;
|
||||
break;
|
||||
|
||||
case CASE:
|
||||
t = newtp();
|
||||
t->type = TCASE;
|
||||
musthave(WORD, 0);
|
||||
t->str = yylval.cp;
|
||||
startl++;
|
||||
multiline++;
|
||||
musthave(IN, CONTIN);
|
||||
startl++;
|
||||
t->left = caselist();
|
||||
musthave(ESAC, 0);
|
||||
multiline--;
|
||||
break;
|
||||
|
||||
case IF:
|
||||
multiline++;
|
||||
t = newtp();
|
||||
t->type = TIF;
|
||||
t->left = c_list();
|
||||
t->right = thenpart();
|
||||
musthave(FI, 0);
|
||||
multiline--;
|
||||
break;
|
||||
}
|
||||
while (synio(0))
|
||||
;
|
||||
t = namelist(t);
|
||||
iolist = iosave;
|
||||
return(t);
|
||||
}
|
||||
|
||||
static struct op *
|
||||
dogroup(onlydone)
|
||||
int onlydone;
|
||||
{
|
||||
register int c;
|
||||
register struct op *list;
|
||||
|
||||
c = yylex(CONTIN);
|
||||
if (c == DONE && onlydone)
|
||||
return((struct op *)NULL);
|
||||
if (c != DO)
|
||||
SYNTAXERR;
|
||||
list = c_list();
|
||||
musthave(DONE, 0);
|
||||
return(list);
|
||||
}
|
||||
|
||||
static struct op *
|
||||
thenpart()
|
||||
{
|
||||
register int c;
|
||||
register struct op *t;
|
||||
|
||||
if ((c = yylex(0)) != THEN) {
|
||||
peeksym = c;
|
||||
return((struct op *)NULL);
|
||||
}
|
||||
t = newtp();
|
||||
t->type = 0;
|
||||
t->left = c_list();
|
||||
if (t->left == NULL)
|
||||
SYNTAXERR;
|
||||
t->right = elsepart();
|
||||
return(t);
|
||||
}
|
||||
|
||||
static struct op *
|
||||
elsepart()
|
||||
{
|
||||
register int c;
|
||||
register struct op *t;
|
||||
|
||||
switch (c = yylex(0)) {
|
||||
case ELSE:
|
||||
if ((t = c_list()) == NULL)
|
||||
SYNTAXERR;
|
||||
return(t);
|
||||
|
||||
case ELIF:
|
||||
t = newtp();
|
||||
t->type = TELIF;
|
||||
t->left = c_list();
|
||||
t->right = thenpart();
|
||||
return(t);
|
||||
|
||||
default:
|
||||
peeksym = c;
|
||||
return((struct op *)NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static struct op *
|
||||
caselist()
|
||||
{
|
||||
register struct op *t;
|
||||
|
||||
t = NULL;
|
||||
while ((peeksym = yylex(CONTIN)) != ESAC)
|
||||
t = list(t, casepart());
|
||||
return(t);
|
||||
}
|
||||
|
||||
static struct op *
|
||||
casepart()
|
||||
{
|
||||
register struct op *t;
|
||||
|
||||
t = newtp();
|
||||
t->type = TPAT;
|
||||
t->words = pattern();
|
||||
musthave(')', 0);
|
||||
t->left = c_list();
|
||||
if ((peeksym = yylex(CONTIN)) != ESAC)
|
||||
musthave(BREAK, CONTIN);
|
||||
return(t);
|
||||
}
|
||||
|
||||
static char **
|
||||
pattern()
|
||||
{
|
||||
register int c, cf;
|
||||
|
||||
cf = CONTIN;
|
||||
do {
|
||||
musthave(WORD, cf);
|
||||
word(yylval.cp);
|
||||
cf = 0;
|
||||
} while ((c = yylex(0)) == '|');
|
||||
peeksym = c;
|
||||
word(NOWORD);
|
||||
return(copyw());
|
||||
}
|
||||
|
||||
static char **
|
||||
wordlist()
|
||||
{
|
||||
register int c;
|
||||
|
||||
if ((c = yylex(0)) != IN) {
|
||||
peeksym = c;
|
||||
return((char **)NULL);
|
||||
}
|
||||
startl = 0;
|
||||
while ((c = yylex(0)) == WORD)
|
||||
word(yylval.cp);
|
||||
word(NOWORD);
|
||||
peeksym = c;
|
||||
return(copyw());
|
||||
}
|
||||
|
||||
/*
|
||||
* supporting functions
|
||||
*/
|
||||
static struct op *
|
||||
list(t1, t2)
|
||||
register struct op *t1, *t2;
|
||||
{
|
||||
if (t1 == NULL)
|
||||
return(t2);
|
||||
if (t2 == NULL)
|
||||
return(t1);
|
||||
return(block(TLIST, t1, t2, NOWORDS));
|
||||
}
|
||||
|
||||
static struct op *
|
||||
block(type, t1, t2, wp)
|
||||
int type;
|
||||
struct op *t1, *t2;
|
||||
char **wp;
|
||||
{
|
||||
register struct op *t;
|
||||
|
||||
t = newtp();
|
||||
t->type = type;
|
||||
t->left = t1;
|
||||
t->right = t2;
|
||||
t->words = wp;
|
||||
return(t);
|
||||
}
|
||||
|
||||
struct res {
|
||||
char *r_name;
|
||||
int r_val;
|
||||
} restab[] = {
|
||||
"for", FOR,
|
||||
"case", CASE,
|
||||
"esac", ESAC,
|
||||
"while", WHILE,
|
||||
"do", DO,
|
||||
"done", DONE,
|
||||
"if", IF,
|
||||
"in", IN,
|
||||
"then", THEN,
|
||||
"else", ELSE,
|
||||
"elif", ELIF,
|
||||
"until", UNTIL,
|
||||
"fi", FI,
|
||||
|
||||
";;", BREAK,
|
||||
"||", LOGOR,
|
||||
"&&", LOGAND,
|
||||
"{", '{',
|
||||
"}", '}',
|
||||
|
||||
0,
|
||||
};
|
||||
|
||||
int
|
||||
rlookup(n)
|
||||
register char *n;
|
||||
{
|
||||
register struct res *rp;
|
||||
|
||||
for (rp = restab; rp->r_name; rp++)
|
||||
if (strcmp(rp->r_name, n) == 0)
|
||||
return(rp->r_val);
|
||||
return(0);
|
||||
}
|
||||
|
||||
static struct op *
|
||||
newtp()
|
||||
{
|
||||
register struct op *t;
|
||||
|
||||
t = (struct op *)tree(sizeof(*t));
|
||||
t->type = 0;
|
||||
t->words = NULL;
|
||||
t->ioact = NULL;
|
||||
t->left = NULL;
|
||||
t->right = NULL;
|
||||
t->str = NULL;
|
||||
return(t);
|
||||
}
|
||||
|
||||
static struct op *
|
||||
namelist(t)
|
||||
register struct op *t;
|
||||
{
|
||||
if (iolist) {
|
||||
iolist = addword((char *)NULL, iolist);
|
||||
t->ioact = copyio();
|
||||
} else
|
||||
t->ioact = NULL;
|
||||
if (t->type != TCOM) {
|
||||
if (t->type != TPAREN && t->ioact != NULL) {
|
||||
t = block(TPAREN, t, NOBLOCK, NOWORDS);
|
||||
t->ioact = t->left->ioact;
|
||||
t->left->ioact = NULL;
|
||||
}
|
||||
return(t);
|
||||
}
|
||||
word(NOWORD);
|
||||
t->words = copyw();
|
||||
return(t);
|
||||
}
|
||||
|
||||
static char **
|
||||
copyw()
|
||||
{
|
||||
register char **wd;
|
||||
|
||||
wd = getwords(wdlist);
|
||||
wdlist = 0;
|
||||
return(wd);
|
||||
}
|
||||
|
||||
static void
|
||||
word(cp)
|
||||
char *cp;
|
||||
{
|
||||
wdlist = addword(cp, wdlist);
|
||||
}
|
||||
|
||||
static struct ioword **
|
||||
copyio()
|
||||
{
|
||||
register struct ioword **iop;
|
||||
|
||||
iop = (struct ioword **) getwords(iolist);
|
||||
iolist = 0;
|
||||
return(iop);
|
||||
}
|
||||
|
||||
static struct ioword *
|
||||
io(u, f, cp)
|
||||
int u;
|
||||
int f;
|
||||
char *cp;
|
||||
{
|
||||
register struct ioword *iop;
|
||||
|
||||
iop = (struct ioword *) tree(sizeof(*iop));
|
||||
iop->io_unit = u;
|
||||
iop->io_flag = f;
|
||||
iop->io_name = cp;
|
||||
iolist = addword((char *)iop, iolist);
|
||||
return(iop);
|
||||
}
|
||||
|
||||
static void
|
||||
zzerr()
|
||||
{
|
||||
yyerror("syntax error");
|
||||
}
|
||||
|
||||
void
|
||||
yyerror(s)
|
||||
char *s;
|
||||
{
|
||||
yynerrs++;
|
||||
if (talking && e.iop <= iostack) {
|
||||
multiline = 0;
|
||||
while (eofc() == 0 && yylex(0) != '\n')
|
||||
;
|
||||
}
|
||||
err(s);
|
||||
fail();
|
||||
}
|
||||
|
||||
static int
|
||||
yylex(cf)
|
||||
int cf;
|
||||
{
|
||||
register int c, c1;
|
||||
int atstart;
|
||||
|
||||
if ((c = peeksym) > 0) {
|
||||
peeksym = 0;
|
||||
if (c == '\n')
|
||||
startl = 1;
|
||||
return(c);
|
||||
}
|
||||
nlseen = 0;
|
||||
e.linep = line;
|
||||
atstart = startl;
|
||||
startl = 0;
|
||||
yylval.i = 0;
|
||||
|
||||
loop:
|
||||
while ((c = getc(0)) == ' ' || c == '\t')
|
||||
;
|
||||
switch (c) {
|
||||
default:
|
||||
if (any(c, "0123456789")) {
|
||||
unget(c1 = getc(0));
|
||||
if (c1 == '<' || c1 == '>') {
|
||||
iounit = c - '0';
|
||||
goto loop;
|
||||
}
|
||||
*e.linep++ = c;
|
||||
c = c1;
|
||||
}
|
||||
break;
|
||||
|
||||
case '#':
|
||||
while ((c = getc(0)) != 0 && c != '\n')
|
||||
;
|
||||
unget(c);
|
||||
goto loop;
|
||||
|
||||
case 0:
|
||||
return(c);
|
||||
|
||||
case '$':
|
||||
*e.linep++ = c;
|
||||
if ((c = getc(0)) == '{') {
|
||||
if ((c = collect(c, '}')) != '\0')
|
||||
return(c);
|
||||
goto pack;
|
||||
}
|
||||
break;
|
||||
|
||||
case '`':
|
||||
case '\'':
|
||||
case '"':
|
||||
if ((c = collect(c, c)) != '\0')
|
||||
return(c);
|
||||
goto pack;
|
||||
|
||||
case '|':
|
||||
case '&':
|
||||
case ';':
|
||||
if ((c1 = dual(c)) != '\0') {
|
||||
startl = 1;
|
||||
return(c1);
|
||||
}
|
||||
startl = 1;
|
||||
return(c);
|
||||
case '^':
|
||||
startl = 1;
|
||||
return('|');
|
||||
case '>':
|
||||
case '<':
|
||||
diag(c);
|
||||
return(c);
|
||||
|
||||
case '\n':
|
||||
nlseen++;
|
||||
gethere();
|
||||
startl = 1;
|
||||
if (multiline || cf & CONTIN) {
|
||||
if (talking && e.iop <= iostack)
|
||||
prs(cprompt->value);
|
||||
if (cf & CONTIN)
|
||||
goto loop;
|
||||
}
|
||||
return(c);
|
||||
|
||||
case '(':
|
||||
case ')':
|
||||
startl = 1;
|
||||
return(c);
|
||||
}
|
||||
|
||||
unget(c);
|
||||
|
||||
pack:
|
||||
while ((c = getc(0)) != 0 && !any(c, "`$ '\"\t;&<>()|^\n"))
|
||||
if (e.linep >= elinep)
|
||||
err("word too long");
|
||||
else
|
||||
*e.linep++ = c;
|
||||
unget(c);
|
||||
if(any(c, "\"'`$"))
|
||||
goto loop;
|
||||
*e.linep++ = '\0';
|
||||
if (atstart && (c = rlookup(line))!=0) {
|
||||
startl = 1;
|
||||
return(c);
|
||||
}
|
||||
yylval.cp = strsave(line, areanum);
|
||||
return(WORD);
|
||||
}
|
||||
|
||||
int
|
||||
collect(c, c1)
|
||||
register c, c1;
|
||||
{
|
||||
char s[2];
|
||||
|
||||
*e.linep++ = c;
|
||||
while ((c = getc(c1)) != c1) {
|
||||
if (c == 0) {
|
||||
unget(c);
|
||||
s[0] = c1;
|
||||
s[1] = 0;
|
||||
prs("no closing "); yyerror(s);
|
||||
return(YYERRCODE);
|
||||
}
|
||||
if (talking && c == '\n' && e.iop <= iostack)
|
||||
prs(cprompt->value);
|
||||
*e.linep++ = c;
|
||||
}
|
||||
*e.linep++ = c;
|
||||
return(0);
|
||||
}
|
||||
|
||||
int
|
||||
dual(c)
|
||||
register c;
|
||||
{
|
||||
char s[3];
|
||||
register char *cp = s;
|
||||
|
||||
*cp++ = c;
|
||||
*cp++ = getc(0);
|
||||
*cp = 0;
|
||||
if ((c = rlookup(s)) == 0)
|
||||
unget(*--cp);
|
||||
return(c);
|
||||
}
|
||||
|
||||
static void
|
||||
diag(ec)
|
||||
register int ec;
|
||||
{
|
||||
register int c;
|
||||
|
||||
c = getc(0);
|
||||
if (c == '>' || c == '<') {
|
||||
if (c != ec)
|
||||
zzerr();
|
||||
yylval.i = ec == '>'? IOWRITE|IOCAT: IOHERE;
|
||||
c = getc(0);
|
||||
} else
|
||||
yylval.i = ec == '>'? IOWRITE: IOREAD;
|
||||
if (c != '&' || yylval.i == IOHERE)
|
||||
unget(c);
|
||||
else
|
||||
yylval.i |= IODUP;
|
||||
}
|
||||
|
||||
static char *
|
||||
tree(size)
|
||||
unsigned size;
|
||||
{
|
||||
register char *t;
|
||||
|
||||
if ((t = getcell(size)) == NULL) {
|
||||
prs("command line too complicated\n");
|
||||
fail();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
return(t);
|
||||
}
|
||||
|
||||
/* VARARGS1 */
|
||||
/* ARGSUSED */
|
||||
void
|
||||
printf(s) /* yyparse calls it */
|
||||
char *s;
|
||||
{
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,767 +0,0 @@
|
||||
#define Extern extern
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#define _NSIG NSIG
|
||||
#include <errno.h>
|
||||
#include <setjmp.h>
|
||||
#include "sh.h"
|
||||
|
||||
/* -------- eval.c -------- */
|
||||
/* #include "sh.h" */
|
||||
/* #include "word.h" */
|
||||
|
||||
/*
|
||||
* ${}
|
||||
* `command`
|
||||
* blank interpretation
|
||||
* quoting
|
||||
* glob
|
||||
*/
|
||||
|
||||
_PROTOTYPE(static int expand, (char *cp, struct wdblock **wbp, int f ));
|
||||
_PROTOTYPE(static char *blank, (int f ));
|
||||
_PROTOTYPE(static int dollar, (int quoted ));
|
||||
_PROTOTYPE(static int grave, (int quoted ));
|
||||
_PROTOTYPE(void globname, (char *we, char *pp ));
|
||||
_PROTOTYPE(static char *generate, (char *start1, char *end1, char *middle, char *end ));
|
||||
_PROTOTYPE(static int anyspcl, (struct wdblock *wb ));
|
||||
_PROTOTYPE(static int xstrcmp, (char *p1, char *p2 ));
|
||||
_PROTOTYPE(void glob0, (char *a0, unsigned int a1, int a2, int (*a3)(char *, char *)));
|
||||
_PROTOTYPE(void glob1, (char *base, char *lim ));
|
||||
_PROTOTYPE(void glob2, (char *i, char *j ));
|
||||
_PROTOTYPE(void glob3, (char *i, char *j, char *k ));
|
||||
_PROTOTYPE(char *memcopy, (char *ato, char *from, int nb ));
|
||||
|
||||
char **
|
||||
eval(ap, f)
|
||||
register char **ap;
|
||||
int f;
|
||||
{
|
||||
struct wdblock *wb;
|
||||
char **wp;
|
||||
char **wf;
|
||||
jmp_buf ev;
|
||||
|
||||
wp = NULL;
|
||||
wb = NULL;
|
||||
wf = NULL;
|
||||
if (newenv(setjmp(errpt = ev)) == 0) {
|
||||
while (*ap && isassign(*ap))
|
||||
expand(*ap++, &wb, f & ~DOGLOB);
|
||||
if (flag['k']) {
|
||||
for (wf = ap; *wf; wf++) {
|
||||
if (isassign(*wf))
|
||||
expand(*wf, &wb, f & ~DOGLOB);
|
||||
}
|
||||
}
|
||||
for (wb = addword((char *)0, wb); *ap; ap++) {
|
||||
if (!flag['k'] || !isassign(*ap))
|
||||
expand(*ap, &wb, f & ~DOKEY);
|
||||
}
|
||||
wb = addword((char *)0, wb);
|
||||
wp = getwords(wb);
|
||||
quitenv();
|
||||
} else
|
||||
gflg = 1;
|
||||
return(gflg? (char **)NULL: wp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make the exported environment from the exported
|
||||
* names in the dictionary. Keyword assignments
|
||||
* will already have been done.
|
||||
*/
|
||||
char **
|
||||
makenv()
|
||||
|
||||
{
|
||||
register struct wdblock *wb;
|
||||
register struct var *vp;
|
||||
|
||||
wb = NULL;
|
||||
for (vp = vlist; vp; vp = vp->next)
|
||||
if (vp->status & EXPORT)
|
||||
wb = addword(vp->name, wb);
|
||||
wb = addword((char *)0, wb);
|
||||
return(getwords(wb));
|
||||
}
|
||||
|
||||
char *
|
||||
evalstr(cp, f)
|
||||
register char *cp;
|
||||
int f;
|
||||
{
|
||||
struct wdblock *wb;
|
||||
|
||||
wb = NULL;
|
||||
if (expand(cp, &wb, f)) {
|
||||
if (wb == NULL || wb->w_nword == 0 || (cp = wb->w_words[0]) == NULL)
|
||||
cp = "";
|
||||
DELETE(wb);
|
||||
} else
|
||||
cp = NULL;
|
||||
return(cp);
|
||||
}
|
||||
|
||||
static int
|
||||
expand(cp, wbp, f)
|
||||
register char *cp;
|
||||
register struct wdblock **wbp;
|
||||
int f;
|
||||
{
|
||||
jmp_buf ev;
|
||||
|
||||
gflg = 0;
|
||||
if (cp == NULL)
|
||||
return(0);
|
||||
if (!anys("$`'\"", cp) &&
|
||||
!anys(ifs->value, cp) &&
|
||||
((f&DOGLOB)==0 || !anys("[*?", cp))) {
|
||||
cp = strsave(cp, areanum);
|
||||
if (f & DOTRIM)
|
||||
unquote(cp);
|
||||
*wbp = addword(cp, *wbp);
|
||||
return(1);
|
||||
}
|
||||
if (newenv(setjmp(errpt = ev)) == 0) {
|
||||
PUSHIO(aword, cp, strchar);
|
||||
e.iobase = e.iop;
|
||||
while ((cp = blank(f)) && gflg == 0) {
|
||||
e.linep = cp;
|
||||
cp = strsave(cp, areanum);
|
||||
if ((f&DOGLOB) == 0) {
|
||||
if (f & DOTRIM)
|
||||
unquote(cp);
|
||||
*wbp = addword(cp, *wbp);
|
||||
} else
|
||||
*wbp = glob(cp, *wbp);
|
||||
}
|
||||
quitenv();
|
||||
} else
|
||||
gflg = 1;
|
||||
return(gflg == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Blank interpretation and quoting
|
||||
*/
|
||||
static char *
|
||||
blank(f)
|
||||
int f;
|
||||
{
|
||||
register c, c1;
|
||||
register char *sp;
|
||||
int scanequals, foundequals;
|
||||
|
||||
sp = e.linep;
|
||||
scanequals = f & DOKEY;
|
||||
foundequals = 0;
|
||||
|
||||
loop:
|
||||
switch (c = subgetc('"', foundequals)) {
|
||||
case 0:
|
||||
if (sp == e.linep)
|
||||
return(0);
|
||||
*e.linep++ = 0;
|
||||
return(sp);
|
||||
|
||||
default:
|
||||
if (f & DOBLANK && any(c, ifs->value))
|
||||
goto loop;
|
||||
break;
|
||||
|
||||
case '"':
|
||||
case '\'':
|
||||
scanequals = 0;
|
||||
if (INSUB())
|
||||
break;
|
||||
for (c1 = c; (c = subgetc(c1, 1)) != c1;) {
|
||||
if (c == 0)
|
||||
break;
|
||||
if (c == '\'' || !any(c, "$`\""))
|
||||
c |= QUOTE;
|
||||
*e.linep++ = c;
|
||||
}
|
||||
c = 0;
|
||||
}
|
||||
unget(c);
|
||||
if (!letter(c))
|
||||
scanequals = 0;
|
||||
for (;;) {
|
||||
c = subgetc('"', foundequals);
|
||||
if (c == 0 ||
|
||||
f & (DOBLANK && any(c, ifs->value)) ||
|
||||
(!INSUB() && any(c, "\"'"))) {
|
||||
scanequals = 0;
|
||||
unget(c);
|
||||
if (any(c, "\"'"))
|
||||
goto loop;
|
||||
break;
|
||||
}
|
||||
if (scanequals)
|
||||
if (c == '=') {
|
||||
foundequals = 1;
|
||||
scanequals = 0;
|
||||
}
|
||||
else if (!letnum(c))
|
||||
scanequals = 0;
|
||||
*e.linep++ = c;
|
||||
}
|
||||
*e.linep++ = 0;
|
||||
return(sp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get characters, substituting for ` and $
|
||||
*/
|
||||
int
|
||||
subgetc(ec, quoted)
|
||||
register char ec;
|
||||
int quoted;
|
||||
{
|
||||
register char c;
|
||||
|
||||
again:
|
||||
c = getc(ec);
|
||||
if (!INSUB() && ec != '\'') {
|
||||
if (c == '`') {
|
||||
if (grave(quoted) == 0)
|
||||
return(0);
|
||||
e.iop->task = XGRAVE;
|
||||
goto again;
|
||||
}
|
||||
if (c == '$' && (c = dollar(quoted)) == 0) {
|
||||
e.iop->task = XDOLL;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
return(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Prepare to generate the string returned by ${} substitution.
|
||||
*/
|
||||
static int
|
||||
dollar(quoted)
|
||||
int quoted;
|
||||
{
|
||||
int otask;
|
||||
struct io *oiop;
|
||||
char *dolp;
|
||||
register char *s, c, *cp;
|
||||
struct var *vp;
|
||||
|
||||
c = readc();
|
||||
s = e.linep;
|
||||
if (c != '{') {
|
||||
*e.linep++ = c;
|
||||
if (letter(c)) {
|
||||
while ((c = readc())!=0 && letnum(c))
|
||||
if (e.linep < elinep)
|
||||
*e.linep++ = c;
|
||||
unget(c);
|
||||
}
|
||||
c = 0;
|
||||
} else {
|
||||
oiop = e.iop;
|
||||
otask = e.iop->task;
|
||||
e.iop->task = XOTHER;
|
||||
while ((c = subgetc('"', 0))!=0 && c!='}' && c!='\n')
|
||||
if (e.linep < elinep)
|
||||
*e.linep++ = c;
|
||||
if (oiop == e.iop)
|
||||
e.iop->task = otask;
|
||||
if (c != '}') {
|
||||
err("unclosed ${");
|
||||
gflg++;
|
||||
return(c);
|
||||
}
|
||||
}
|
||||
if (e.linep >= elinep) {
|
||||
err("string in ${} too long");
|
||||
gflg++;
|
||||
e.linep -= 10;
|
||||
}
|
||||
*e.linep = 0;
|
||||
if (*s)
|
||||
for (cp = s+1; *cp; cp++)
|
||||
if (any(*cp, "=-+?")) {
|
||||
c = *cp;
|
||||
*cp++ = 0;
|
||||
break;
|
||||
}
|
||||
if (s[1] == 0 && (*s == '*' || *s == '@')) {
|
||||
if (dolc > 1) {
|
||||
/* currently this does not distinguish $* and $@ */
|
||||
/* should check dollar */
|
||||
e.linep = s;
|
||||
PUSHIO(awordlist, dolv+1, dolchar);
|
||||
return(0);
|
||||
} else { /* trap the nasty ${=} */
|
||||
s[0] = '1';
|
||||
s[1] = 0;
|
||||
}
|
||||
}
|
||||
vp = lookup(s);
|
||||
if ((dolp = vp->value) == null) {
|
||||
switch (c) {
|
||||
case '=':
|
||||
if (digit(*s)) {
|
||||
err("cannot use ${...=...} with $n");
|
||||
gflg++;
|
||||
break;
|
||||
}
|
||||
setval(vp, cp);
|
||||
dolp = vp->value;
|
||||
break;
|
||||
|
||||
case '-':
|
||||
dolp = strsave(cp, areanum);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
if (*cp == 0) {
|
||||
prs("missing value for ");
|
||||
err(s);
|
||||
} else
|
||||
err(cp);
|
||||
gflg++;
|
||||
break;
|
||||
}
|
||||
} else if (c == '+')
|
||||
dolp = strsave(cp, areanum);
|
||||
if (flag['u'] && dolp == null) {
|
||||
prs("unset variable: ");
|
||||
err(s);
|
||||
gflg++;
|
||||
}
|
||||
e.linep = s;
|
||||
PUSHIO(aword, dolp, quoted ? qstrchar : strchar);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Run the command in `...` and read its output.
|
||||
*/
|
||||
static int
|
||||
grave(quoted)
|
||||
int quoted;
|
||||
{
|
||||
register char *cp;
|
||||
register int i;
|
||||
int pf[2];
|
||||
|
||||
for (cp = e.iop->argp->aword; *cp != '`'; cp++)
|
||||
if (*cp == 0) {
|
||||
err("no closing `");
|
||||
return(0);
|
||||
}
|
||||
if (openpipe(pf) < 0)
|
||||
return(0);
|
||||
if ((i = fork()) == -1) {
|
||||
closepipe(pf);
|
||||
err("try again");
|
||||
return(0);
|
||||
}
|
||||
if (i != 0) {
|
||||
e.iop->argp->aword = ++cp;
|
||||
close(pf[1]);
|
||||
PUSHIO(afile, remap(pf[0]), quoted? qgravechar: gravechar);
|
||||
return(1);
|
||||
}
|
||||
*cp = 0;
|
||||
/* allow trapped signals */
|
||||
for (i=0; i<=_NSIG; i++)
|
||||
if (ourtrap[i] && signal(i, SIG_IGN) != SIG_IGN)
|
||||
signal(i, SIG_DFL);
|
||||
dup2(pf[1], 1);
|
||||
closepipe(pf);
|
||||
flag['e'] = 0;
|
||||
flag['v'] = 0;
|
||||
flag['n'] = 0;
|
||||
cp = strsave(e.iop->argp->aword, 0);
|
||||
areanum = 1;
|
||||
freehere(areanum);
|
||||
freearea(areanum); /* free old space */
|
||||
e.oenv = NULL;
|
||||
e.iop = (e.iobase = iostack) - 1;
|
||||
unquote(cp);
|
||||
talking = 0;
|
||||
PUSHIO(aword, cp, nlchar);
|
||||
onecommand();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char *
|
||||
unquote(as)
|
||||
register char *as;
|
||||
{
|
||||
register char *s;
|
||||
|
||||
if ((s = as) != NULL)
|
||||
while (*s)
|
||||
*s++ &= ~QUOTE;
|
||||
return(as);
|
||||
}
|
||||
|
||||
/* -------- glob.c -------- */
|
||||
/* #include "sh.h" */
|
||||
|
||||
/*
|
||||
* glob
|
||||
*/
|
||||
|
||||
#define scopy(x) strsave((x), areanum)
|
||||
#define BLKSIZ 512
|
||||
#define NDENT ((BLKSIZ+sizeof(struct dirent)-1)/sizeof(struct dirent))
|
||||
|
||||
static struct wdblock *cl, *nl;
|
||||
static char spcl[] = "[?*";
|
||||
|
||||
struct wdblock *
|
||||
glob(cp, wb)
|
||||
char *cp;
|
||||
struct wdblock *wb;
|
||||
{
|
||||
register i;
|
||||
register char *pp;
|
||||
|
||||
if (cp == 0)
|
||||
return(wb);
|
||||
i = 0;
|
||||
for (pp = cp; *pp; pp++)
|
||||
if (any(*pp, spcl))
|
||||
i++;
|
||||
else if (!any(*pp & ~QUOTE, spcl))
|
||||
*pp &= ~QUOTE;
|
||||
if (i != 0) {
|
||||
for (cl = addword(scopy(cp), (struct wdblock *)0); anyspcl(cl); cl = nl) {
|
||||
nl = newword(cl->w_nword*2);
|
||||
for(i=0; i<cl->w_nword; i++) { /* for each argument */
|
||||
for (pp = cl->w_words[i]; *pp; pp++)
|
||||
if (any(*pp, spcl)) {
|
||||
globname(cl->w_words[i], pp);
|
||||
break;
|
||||
}
|
||||
if (*pp == '\0')
|
||||
nl = addword(scopy(cl->w_words[i]), nl);
|
||||
}
|
||||
for(i=0; i<cl->w_nword; i++)
|
||||
DELETE(cl->w_words[i]);
|
||||
DELETE(cl);
|
||||
}
|
||||
for(i=0; i<cl->w_nword; i++)
|
||||
unquote(cl->w_words[i]);
|
||||
glob0((char *)cl->w_words, cl->w_nword, sizeof(char *), xstrcmp);
|
||||
if (cl->w_nword) {
|
||||
for (i=0; i<cl->w_nword; i++)
|
||||
wb = addword(cl->w_words[i], wb);
|
||||
DELETE(cl);
|
||||
return(wb);
|
||||
}
|
||||
}
|
||||
wb = addword(unquote(cp), wb);
|
||||
return(wb);
|
||||
}
|
||||
|
||||
void
|
||||
globname(we, pp)
|
||||
char *we;
|
||||
register char *pp;
|
||||
{
|
||||
register char *np, *cp;
|
||||
char *name, *gp, *dp;
|
||||
int dn, j, n, k;
|
||||
DIR *dirp;
|
||||
struct dirent *de;
|
||||
char dname[NAME_MAX+1];
|
||||
struct stat dbuf;
|
||||
|
||||
for (np = we; np != pp; pp--)
|
||||
if (pp[-1] == '/')
|
||||
break;
|
||||
for (dp = cp = space((int)(pp-np)+3); np < pp;)
|
||||
*cp++ = *np++;
|
||||
*cp++ = '.';
|
||||
*cp = '\0';
|
||||
for (gp = cp = space(strlen(pp)+1); *np && *np != '/';)
|
||||
*cp++ = *np++;
|
||||
*cp = '\0';
|
||||
dirp = opendir(dp);
|
||||
if (dirp == 0) {
|
||||
DELETE(dp);
|
||||
DELETE(gp);
|
||||
return;
|
||||
}
|
||||
dname[NAME_MAX] = '\0';
|
||||
while ((de=readdir(dirp))!=NULL) {
|
||||
/* XXX Hmmm... What this could be? (abial) */
|
||||
/*
|
||||
if (ent[j].d_ino == 0)
|
||||
continue;
|
||||
*/
|
||||
strncpy(dname, de->d_name, NAME_MAX);
|
||||
if (dname[0] == '.')
|
||||
if (*gp != '.')
|
||||
continue;
|
||||
for(k=0; k<NAME_MAX; k++)
|
||||
if (any(dname[k], spcl))
|
||||
dname[k] |= QUOTE;
|
||||
if (gmatch(dname, gp)) {
|
||||
name = generate(we, pp, dname, np);
|
||||
if (*np && !anys(np, spcl)) {
|
||||
if (stat(name,&dbuf)) {
|
||||
DELETE(name);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
nl = addword(name, nl);
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
DELETE(dp);
|
||||
DELETE(gp);
|
||||
}
|
||||
|
||||
/*
|
||||
* generate a pathname as below.
|
||||
* start..end1 / middle end
|
||||
* the slashes come for free
|
||||
*/
|
||||
static char *
|
||||
generate(start1, end1, middle, end)
|
||||
char *start1;
|
||||
register char *end1;
|
||||
char *middle, *end;
|
||||
{
|
||||
char *p;
|
||||
register char *op, *xp;
|
||||
|
||||
p = op = space((int)(end1-start1)+strlen(middle)+strlen(end)+2);
|
||||
for (xp = start1; xp != end1;)
|
||||
*op++ = *xp++;
|
||||
for (xp = middle; (*op++ = *xp++) != '\0';)
|
||||
;
|
||||
op--;
|
||||
for (xp = end; (*op++ = *xp++) != '\0';)
|
||||
;
|
||||
return(p);
|
||||
}
|
||||
|
||||
static int
|
||||
anyspcl(wb)
|
||||
register struct wdblock *wb;
|
||||
{
|
||||
register i;
|
||||
register char **wd;
|
||||
|
||||
wd = wb->w_words;
|
||||
for (i=0; i<wb->w_nword; i++)
|
||||
if (anys(spcl, *wd++))
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int
|
||||
xstrcmp(p1, p2)
|
||||
char *p1, *p2;
|
||||
{
|
||||
return(strcmp(*(char **)p1, *(char **)p2));
|
||||
}
|
||||
|
||||
/* -------- word.c -------- */
|
||||
/* #include "sh.h" */
|
||||
/* #include "word.h" */
|
||||
|
||||
#define NSTART 16 /* default number of words to allow for initially */
|
||||
|
||||
struct wdblock *
|
||||
newword(nw)
|
||||
register int nw;
|
||||
{
|
||||
register struct wdblock *wb;
|
||||
|
||||
wb = (struct wdblock *) space(sizeof(*wb) + nw*sizeof(char *));
|
||||
wb->w_bsize = nw;
|
||||
wb->w_nword = 0;
|
||||
return(wb);
|
||||
}
|
||||
|
||||
struct wdblock *
|
||||
addword(wd, wb)
|
||||
char *wd;
|
||||
register struct wdblock *wb;
|
||||
{
|
||||
register struct wdblock *wb2;
|
||||
register nw;
|
||||
|
||||
if (wb == NULL)
|
||||
wb = newword(NSTART);
|
||||
if ((nw = wb->w_nword) >= wb->w_bsize) {
|
||||
wb2 = newword(nw * 2);
|
||||
memcopy((char *)wb2->w_words, (char *)wb->w_words, nw*sizeof(char *));
|
||||
wb2->w_nword = nw;
|
||||
DELETE(wb);
|
||||
wb = wb2;
|
||||
}
|
||||
wb->w_words[wb->w_nword++] = wd;
|
||||
return(wb);
|
||||
}
|
||||
|
||||
char **
|
||||
getwords(wb)
|
||||
register struct wdblock *wb;
|
||||
{
|
||||
register char **wd;
|
||||
register nb;
|
||||
|
||||
if (wb == NULL)
|
||||
return((char **)NULL);
|
||||
if (wb->w_nword == 0) {
|
||||
DELETE(wb);
|
||||
return((char **)NULL);
|
||||
}
|
||||
wd = (char **) space(nb = sizeof(*wd) * wb->w_nword);
|
||||
memcopy((char *)wd, (char *)wb->w_words, nb);
|
||||
DELETE(wb); /* perhaps should done by caller */
|
||||
return(wd);
|
||||
}
|
||||
|
||||
_PROTOTYPE(int (*func), (char *, char *));
|
||||
int globv;
|
||||
|
||||
void
|
||||
glob0(a0, a1, a2, a3)
|
||||
char *a0;
|
||||
unsigned a1;
|
||||
int a2;
|
||||
_PROTOTYPE(int (*a3), (char *, char *));
|
||||
{
|
||||
func = a3;
|
||||
globv = a2;
|
||||
glob1(a0, a0 + a1 * a2);
|
||||
}
|
||||
|
||||
void
|
||||
glob1(base, lim)
|
||||
char *base, *lim;
|
||||
{
|
||||
register char *i, *j;
|
||||
int v2;
|
||||
char *lptr, *hptr;
|
||||
int c;
|
||||
unsigned n;
|
||||
|
||||
|
||||
v2 = globv;
|
||||
|
||||
top:
|
||||
if ((n=(int)(lim-base)) <= v2)
|
||||
return;
|
||||
n = v2 * (n / (2*v2));
|
||||
hptr = lptr = base+n;
|
||||
i = base;
|
||||
j = lim-v2;
|
||||
for(;;) {
|
||||
if (i < lptr) {
|
||||
if ((c = (*func)(i, lptr)) == 0) {
|
||||
glob2(i, lptr -= v2);
|
||||
continue;
|
||||
}
|
||||
if (c < 0) {
|
||||
i += v2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
begin:
|
||||
if (j > hptr) {
|
||||
if ((c = (*func)(hptr, j)) == 0) {
|
||||
glob2(hptr += v2, j);
|
||||
goto begin;
|
||||
}
|
||||
if (c > 0) {
|
||||
if (i == lptr) {
|
||||
glob3(i, hptr += v2, j);
|
||||
i = lptr += v2;
|
||||
goto begin;
|
||||
}
|
||||
glob2(i, j);
|
||||
j -= v2;
|
||||
i += v2;
|
||||
continue;
|
||||
}
|
||||
j -= v2;
|
||||
goto begin;
|
||||
}
|
||||
|
||||
|
||||
if (i == lptr) {
|
||||
if (lptr-base >= lim-hptr) {
|
||||
glob1(hptr+v2, lim);
|
||||
lim = lptr;
|
||||
} else {
|
||||
glob1(base, lptr);
|
||||
base = hptr+v2;
|
||||
}
|
||||
goto top;
|
||||
}
|
||||
|
||||
|
||||
glob3(j, lptr -= v2, i);
|
||||
j = hptr -= v2;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
glob2(i, j)
|
||||
char *i, *j;
|
||||
{
|
||||
register char *index1, *index2, c;
|
||||
int m;
|
||||
|
||||
m = globv;
|
||||
index1 = i;
|
||||
index2 = j;
|
||||
do {
|
||||
c = *index1;
|
||||
*index1++ = *index2;
|
||||
*index2++ = c;
|
||||
} while(--m);
|
||||
}
|
||||
|
||||
void
|
||||
glob3(i, j, k)
|
||||
char *i, *j, *k;
|
||||
{
|
||||
register char *index1, *index2, *index3;
|
||||
int c;
|
||||
int m;
|
||||
|
||||
m = globv;
|
||||
index1 = i;
|
||||
index2 = j;
|
||||
index3 = k;
|
||||
do {
|
||||
c = *index1;
|
||||
*index1++ = *index3;
|
||||
*index3++ = *index2;
|
||||
*index2++ = c;
|
||||
} while(--m);
|
||||
}
|
||||
|
||||
char *
|
||||
memcopy(ato, from, nb)
|
||||
register char *ato, *from;
|
||||
register int nb;
|
||||
{
|
||||
register char *to;
|
||||
|
||||
to = ato;
|
||||
while (--nb >= 0)
|
||||
*to++ = *from++;
|
||||
return(ato);
|
||||
}
|
@ -1,675 +0,0 @@
|
||||
#define Extern extern
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#define _NSIG NSIG
|
||||
#include <errno.h>
|
||||
#include <setjmp.h>
|
||||
#include "sh.h"
|
||||
|
||||
/* -------- io.c -------- */
|
||||
/* #include "sh.h" */
|
||||
|
||||
/*
|
||||
* shell IO
|
||||
*/
|
||||
|
||||
static struct iobuf sharedbuf = {AFID_NOBUF};
|
||||
static struct iobuf mainbuf = {AFID_NOBUF};
|
||||
static unsigned bufid = AFID_ID; /* buffer id counter */
|
||||
|
||||
struct ioarg temparg = {0, 0, 0, AFID_NOBUF, 0};
|
||||
|
||||
_PROTOTYPE(static void readhere, (char **name, char *s, int ec ));
|
||||
_PROTOTYPE(void pushio, (struct ioarg *argp, int (*fn)()));
|
||||
_PROTOTYPE(static int xxchar, (struct ioarg *ap ));
|
||||
_PROTOTYPE(void tempname, (char *tname ));
|
||||
|
||||
int
|
||||
getc(ec)
|
||||
register int ec;
|
||||
{
|
||||
register int c;
|
||||
|
||||
if(e.linep > elinep) {
|
||||
while((c=readc()) != '\n' && c)
|
||||
;
|
||||
err("input line too long");
|
||||
gflg++;
|
||||
return(c);
|
||||
}
|
||||
c = readc();
|
||||
if (ec != '\'' && e.iop->task != XGRAVE) {
|
||||
if(c == '\\') {
|
||||
c = readc();
|
||||
if (c == '\n' && ec != '\"')
|
||||
return(getc(ec));
|
||||
c |= QUOTE;
|
||||
}
|
||||
}
|
||||
return(c);
|
||||
}
|
||||
|
||||
void
|
||||
unget(c)
|
||||
int c;
|
||||
{
|
||||
if (e.iop >= e.iobase)
|
||||
e.iop->peekc = c;
|
||||
}
|
||||
|
||||
int
|
||||
eofc()
|
||||
|
||||
{
|
||||
return e.iop < e.iobase || (e.iop->peekc == 0 && e.iop->prev == 0);
|
||||
}
|
||||
|
||||
int
|
||||
readc()
|
||||
{
|
||||
register c;
|
||||
|
||||
for (; e.iop >= e.iobase; e.iop--)
|
||||
if ((c = e.iop->peekc) != '\0') {
|
||||
e.iop->peekc = 0;
|
||||
return(c);
|
||||
}
|
||||
else {
|
||||
if (e.iop->prev != 0) {
|
||||
if ((c = (*e.iop->iofn)(e.iop->argp, e.iop)) != '\0') {
|
||||
if (c == -1) {
|
||||
e.iop++;
|
||||
continue;
|
||||
}
|
||||
if (e.iop == iostack)
|
||||
ioecho(c);
|
||||
return(e.iop->prev = c);
|
||||
}
|
||||
else if (e.iop->task == XIO && e.iop->prev != '\n') {
|
||||
e.iop->prev = 0;
|
||||
if (e.iop == iostack)
|
||||
ioecho('\n');
|
||||
return '\n';
|
||||
}
|
||||
}
|
||||
if (e.iop->task == XIO) {
|
||||
if (multiline)
|
||||
return e.iop->prev = 0;
|
||||
if (talking && e.iop == iostack+1)
|
||||
prs(prompt->value);
|
||||
}
|
||||
}
|
||||
if (e.iop >= iostack)
|
||||
return(0);
|
||||
leave();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void
|
||||
ioecho(c)
|
||||
char c;
|
||||
{
|
||||
if (flag['v'])
|
||||
write(2, &c, sizeof c);
|
||||
}
|
||||
|
||||
void
|
||||
pushio(argp, fn)
|
||||
struct ioarg *argp;
|
||||
int (*fn)();
|
||||
{
|
||||
if (++e.iop >= &iostack[NPUSH]) {
|
||||
e.iop--;
|
||||
err("Shell input nested too deeply");
|
||||
gflg++;
|
||||
return;
|
||||
}
|
||||
e.iop->iofn = fn;
|
||||
|
||||
if (argp->afid != AFID_NOBUF)
|
||||
e.iop->argp = argp;
|
||||
else {
|
||||
e.iop->argp = ioargstack + (e.iop - iostack);
|
||||
*e.iop->argp = *argp;
|
||||
e.iop->argp->afbuf = e.iop == &iostack[0] ? &mainbuf : &sharedbuf;
|
||||
if (isatty(e.iop->argp->afile) == 0 &&
|
||||
(e.iop == &iostack[0] ||
|
||||
lseek(e.iop->argp->afile, 0L, 1) != -1)) {
|
||||
if (++bufid == AFID_NOBUF)
|
||||
bufid = AFID_ID;
|
||||
e.iop->argp->afid = bufid;
|
||||
}
|
||||
}
|
||||
|
||||
e.iop->prev = ~'\n';
|
||||
e.iop->peekc = 0;
|
||||
e.iop->xchar = 0;
|
||||
e.iop->nlcount = 0;
|
||||
if (fn == filechar || fn == linechar)
|
||||
e.iop->task = XIO;
|
||||
else if (fn == gravechar || fn == qgravechar)
|
||||
e.iop->task = XGRAVE;
|
||||
else
|
||||
e.iop->task = XOTHER;
|
||||
}
|
||||
|
||||
struct io *
|
||||
setbase(ip)
|
||||
struct io *ip;
|
||||
{
|
||||
register struct io *xp;
|
||||
|
||||
xp = e.iobase;
|
||||
e.iobase = ip;
|
||||
return(xp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Input generating functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Produce the characters of a string, then a newline, then EOF.
|
||||
*/
|
||||
int
|
||||
nlchar(ap)
|
||||
register struct ioarg *ap;
|
||||
{
|
||||
register int c;
|
||||
|
||||
if (ap->aword == NULL)
|
||||
return(0);
|
||||
if ((c = *ap->aword++) == 0) {
|
||||
ap->aword = NULL;
|
||||
return('\n');
|
||||
}
|
||||
return(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a list of words, produce the characters
|
||||
* in them, with a space after each word.
|
||||
*/
|
||||
int
|
||||
wdchar(ap)
|
||||
register struct ioarg *ap;
|
||||
{
|
||||
register char c;
|
||||
register char **wl;
|
||||
|
||||
if ((wl = ap->awordlist) == NULL)
|
||||
return(0);
|
||||
if (*wl != NULL) {
|
||||
if ((c = *(*wl)++) != 0)
|
||||
return(c & 0177);
|
||||
ap->awordlist++;
|
||||
return(' ');
|
||||
}
|
||||
ap->awordlist = NULL;
|
||||
return('\n');
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the characters of a list of words,
|
||||
* producing a space between them.
|
||||
*/
|
||||
int
|
||||
dolchar(ap)
|
||||
register struct ioarg *ap;
|
||||
{
|
||||
register char *wp;
|
||||
|
||||
if ((wp = *ap->awordlist++) != NULL) {
|
||||
PUSHIO(aword, wp, *ap->awordlist == NULL? strchar: xxchar);
|
||||
return(-1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int
|
||||
xxchar(ap)
|
||||
register struct ioarg *ap;
|
||||
{
|
||||
register int c;
|
||||
|
||||
if (ap->aword == NULL)
|
||||
return(0);
|
||||
if ((c = *ap->aword++) == '\0') {
|
||||
ap->aword = NULL;
|
||||
return(' ');
|
||||
}
|
||||
return(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Produce the characters from a single word (string).
|
||||
*/
|
||||
int
|
||||
strchar(ap)
|
||||
register struct ioarg *ap;
|
||||
{
|
||||
register int c;
|
||||
|
||||
if (ap->aword == NULL || (c = *ap->aword++) == 0)
|
||||
return(0);
|
||||
return(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Produce quoted characters from a single word (string).
|
||||
*/
|
||||
int
|
||||
qstrchar(ap)
|
||||
register struct ioarg *ap;
|
||||
{
|
||||
register int c;
|
||||
|
||||
if (ap->aword == NULL || (c = *ap->aword++) == 0)
|
||||
return(0);
|
||||
return(c|QUOTE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the characters from a file.
|
||||
*/
|
||||
int
|
||||
filechar(ap)
|
||||
register struct ioarg *ap;
|
||||
{
|
||||
register int i;
|
||||
char c;
|
||||
struct iobuf *bp = ap->afbuf;
|
||||
|
||||
if (ap->afid != AFID_NOBUF) {
|
||||
if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) {
|
||||
if (i)
|
||||
lseek(ap->afile, ap->afpos, 0);
|
||||
do {
|
||||
i = read(ap->afile, bp->buf, sizeof(bp->buf));
|
||||
} while (i < 0 && errno == EINTR);
|
||||
if (i <= 0) {
|
||||
closef(ap->afile);
|
||||
return 0;
|
||||
}
|
||||
bp->id = ap->afid;
|
||||
bp->ebufp = (bp->bufp = bp->buf) + i;
|
||||
}
|
||||
ap->afpos++;
|
||||
return *bp->bufp++ & 0177;
|
||||
}
|
||||
|
||||
do {
|
||||
i = read(ap->afile, &c, sizeof(c));
|
||||
} while (i < 0 && errno == EINTR);
|
||||
return(i == sizeof(c)? c&0177: (closef(ap->afile), 0));
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the characters from a here temp file.
|
||||
*/
|
||||
int
|
||||
herechar(ap)
|
||||
register struct ioarg *ap;
|
||||
{
|
||||
char c;
|
||||
|
||||
|
||||
if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) {
|
||||
close(ap->afile);
|
||||
c = 0;
|
||||
}
|
||||
return (c);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the characters produced by a process (`...`).
|
||||
* Quote them if required, and remove any trailing newline characters.
|
||||
*/
|
||||
int
|
||||
gravechar(ap, iop)
|
||||
struct ioarg *ap;
|
||||
struct io *iop;
|
||||
{
|
||||
register int c;
|
||||
|
||||
if ((c = qgravechar(ap, iop)&~QUOTE) == '\n')
|
||||
c = ' ';
|
||||
return(c);
|
||||
}
|
||||
|
||||
int
|
||||
qgravechar(ap, iop)
|
||||
register struct ioarg *ap;
|
||||
struct io *iop;
|
||||
{
|
||||
register int c;
|
||||
|
||||
if (iop->xchar) {
|
||||
if (iop->nlcount) {
|
||||
iop->nlcount--;
|
||||
return('\n'|QUOTE);
|
||||
}
|
||||
c = iop->xchar;
|
||||
iop->xchar = 0;
|
||||
} else if ((c = filechar(ap)) == '\n') {
|
||||
iop->nlcount = 1;
|
||||
while ((c = filechar(ap)) == '\n')
|
||||
iop->nlcount++;
|
||||
iop->xchar = c;
|
||||
if (c == 0)
|
||||
return(c);
|
||||
iop->nlcount--;
|
||||
c = '\n';
|
||||
}
|
||||
return(c!=0? c|QUOTE: 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a single command (usually the first line) from a file.
|
||||
*/
|
||||
int
|
||||
linechar(ap)
|
||||
register struct ioarg *ap;
|
||||
{
|
||||
register int c;
|
||||
|
||||
if ((c = filechar(ap)) == '\n') {
|
||||
if (!multiline) {
|
||||
closef(ap->afile);
|
||||
ap->afile = -1; /* illegal value */
|
||||
}
|
||||
}
|
||||
return(c);
|
||||
}
|
||||
|
||||
void
|
||||
prs(s)
|
||||
register char *s;
|
||||
{
|
||||
if (*s)
|
||||
write(2, s, strlen(s));
|
||||
}
|
||||
|
||||
void
|
||||
putc(c)
|
||||
char c;
|
||||
{
|
||||
write(2, &c, sizeof c);
|
||||
}
|
||||
|
||||
void
|
||||
prn(u)
|
||||
unsigned u;
|
||||
{
|
||||
prs(itoa(u, 0));
|
||||
}
|
||||
|
||||
void
|
||||
closef(i)
|
||||
register int i;
|
||||
{
|
||||
if (i > 2)
|
||||
close(i);
|
||||
}
|
||||
|
||||
void
|
||||
closeall()
|
||||
{
|
||||
register u;
|
||||
|
||||
for (u=NUFILE; u<NOFILE;)
|
||||
close(u++);
|
||||
}
|
||||
|
||||
/*
|
||||
* remap fd into Shell's fd space
|
||||
*/
|
||||
int
|
||||
remap(fd)
|
||||
register int fd;
|
||||
{
|
||||
register int i;
|
||||
int map[NOFILE];
|
||||
|
||||
if (fd < e.iofd) {
|
||||
for (i=0; i<NOFILE; i++)
|
||||
map[i] = 0;
|
||||
do {
|
||||
map[fd] = 1;
|
||||
fd = dup(fd);
|
||||
} while (fd >= 0 && fd < e.iofd);
|
||||
for (i=0; i<NOFILE; i++)
|
||||
if (map[i])
|
||||
close(i);
|
||||
if (fd < 0)
|
||||
err("too many files open in shell");
|
||||
}
|
||||
return(fd);
|
||||
}
|
||||
|
||||
int
|
||||
openpipe(pv)
|
||||
register int *pv;
|
||||
{
|
||||
register int i;
|
||||
|
||||
if ((i = pipe(pv)) < 0)
|
||||
err("can't create pipe - try again");
|
||||
return(i);
|
||||
}
|
||||
|
||||
void
|
||||
closepipe(pv)
|
||||
register int *pv;
|
||||
{
|
||||
if (pv != NULL) {
|
||||
close(*pv++);
|
||||
close(*pv);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------- here.c -------- */
|
||||
/* #include "sh.h" */
|
||||
|
||||
/*
|
||||
* here documents
|
||||
*/
|
||||
|
||||
struct here {
|
||||
char *h_tag;
|
||||
int h_dosub;
|
||||
struct ioword *h_iop;
|
||||
struct here *h_next;
|
||||
};
|
||||
|
||||
static struct here *inhere; /* list of hear docs while parsing */
|
||||
static struct here *acthere; /* list of active here documents */
|
||||
|
||||
void
|
||||
markhere(s, iop)
|
||||
register char *s;
|
||||
struct ioword *iop;
|
||||
{
|
||||
register struct here *h, *lh;
|
||||
|
||||
h = (struct here *) space(sizeof(struct here));
|
||||
if (h == 0)
|
||||
return;
|
||||
h->h_tag = evalstr(s, DOSUB);
|
||||
if (h->h_tag == 0)
|
||||
return;
|
||||
h->h_iop = iop;
|
||||
iop->io_name = 0;
|
||||
h->h_next = NULL;
|
||||
if (inhere == 0)
|
||||
inhere = h;
|
||||
else
|
||||
for (lh = inhere; lh!=NULL; lh = lh->h_next)
|
||||
if (lh->h_next == 0) {
|
||||
lh->h_next = h;
|
||||
break;
|
||||
}
|
||||
iop->io_flag |= IOHERE|IOXHERE;
|
||||
for (s = h->h_tag; *s; s++)
|
||||
if (*s & QUOTE) {
|
||||
iop->io_flag &= ~ IOXHERE;
|
||||
*s &= ~ QUOTE;
|
||||
}
|
||||
h->h_dosub = iop->io_flag & IOXHERE;
|
||||
}
|
||||
|
||||
void
|
||||
gethere()
|
||||
{
|
||||
register struct here *h, *hp;
|
||||
|
||||
/* Scan here files first leaving inhere list in place */
|
||||
for (hp = h = inhere; h != NULL; hp = h, h = h->h_next)
|
||||
readhere(&h->h_iop->io_name, h->h_tag, h->h_dosub? 0: '\'');
|
||||
|
||||
/* Make inhere list active - keep list intact for scraphere */
|
||||
if (hp != NULL) {
|
||||
hp->h_next = acthere;
|
||||
acthere = inhere;
|
||||
inhere = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
readhere(name, s, ec)
|
||||
char **name;
|
||||
register char *s;
|
||||
int ec;
|
||||
{
|
||||
int tf;
|
||||
char tname[30];
|
||||
register c;
|
||||
jmp_buf ev;
|
||||
char line [LINELIM+1];
|
||||
char *next;
|
||||
|
||||
tempname(tname);
|
||||
*name = strsave(tname, areanum);
|
||||
tf = creat(tname, 0600);
|
||||
if (tf < 0)
|
||||
return;
|
||||
if (newenv(setjmp(errpt = ev)) != 0)
|
||||
unlink(tname);
|
||||
else {
|
||||
pushio(e.iop->argp, e.iop->iofn);
|
||||
e.iobase = e.iop;
|
||||
for (;;) {
|
||||
if (talking && e.iop <= iostack)
|
||||
prs(cprompt->value);
|
||||
next = line;
|
||||
while ((c = getc(ec)) != '\n' && c) {
|
||||
if (ec == '\'')
|
||||
c &= ~ QUOTE;
|
||||
if (next >= &line[LINELIM]) {
|
||||
c = 0;
|
||||
break;
|
||||
}
|
||||
*next++ = c;
|
||||
}
|
||||
*next = 0;
|
||||
if (strcmp(s, line) == 0 || c == 0)
|
||||
break;
|
||||
*next++ = '\n';
|
||||
write (tf, line, (int)(next-line));
|
||||
}
|
||||
if (c == 0) {
|
||||
prs("here document `"); prs(s); err("' unclosed");
|
||||
}
|
||||
quitenv();
|
||||
}
|
||||
close(tf);
|
||||
}
|
||||
|
||||
/*
|
||||
* open here temp file.
|
||||
* if unquoted here, expand here temp file into second temp file.
|
||||
*/
|
||||
int
|
||||
herein(hname, xdoll)
|
||||
char *hname;
|
||||
int xdoll;
|
||||
{
|
||||
register hf, tf;
|
||||
|
||||
if (hname == 0)
|
||||
return(-1);
|
||||
hf = open(hname, 0);
|
||||
if (hf < 0)
|
||||
return (-1);
|
||||
if (xdoll) {
|
||||
char c;
|
||||
char tname[30];
|
||||
jmp_buf ev;
|
||||
|
||||
tempname(tname);
|
||||
if ((tf = creat(tname, 0600)) < 0)
|
||||
return (-1);
|
||||
if (newenv(setjmp(errpt = ev)) == 0) {
|
||||
PUSHIO(afile, hf, herechar);
|
||||
setbase(e.iop);
|
||||
while ((c = subgetc(0, 0)) != 0) {
|
||||
c &= ~ QUOTE;
|
||||
write(tf, &c, sizeof c);
|
||||
}
|
||||
quitenv();
|
||||
} else
|
||||
unlink(tname);
|
||||
close(tf);
|
||||
tf = open(tname, 0);
|
||||
unlink(tname);
|
||||
return (tf);
|
||||
} else
|
||||
return (hf);
|
||||
}
|
||||
|
||||
void
|
||||
scraphere()
|
||||
{
|
||||
register struct here *h;
|
||||
|
||||
for (h = inhere; h != NULL; h = h->h_next) {
|
||||
if (h->h_iop && h->h_iop->io_name)
|
||||
unlink(h->h_iop->io_name);
|
||||
}
|
||||
inhere = NULL;
|
||||
}
|
||||
|
||||
/* unlink here temp files before a freearea(area) */
|
||||
void
|
||||
freehere(area)
|
||||
int area;
|
||||
{
|
||||
register struct here *h, *hl;
|
||||
|
||||
hl = NULL;
|
||||
for (h = acthere; h != NULL; h = h->h_next)
|
||||
if (getarea((char *) h) >= area) {
|
||||
if (h->h_iop->io_name != NULL)
|
||||
unlink(h->h_iop->io_name);
|
||||
if (hl == NULL)
|
||||
acthere = h->h_next;
|
||||
else
|
||||
hl->h_next = h->h_next;
|
||||
} else
|
||||
hl = h;
|
||||
}
|
||||
|
||||
void
|
||||
tempname(tname)
|
||||
char *tname;
|
||||
{
|
||||
static int inc;
|
||||
register char *cp, *lp;
|
||||
|
||||
for (cp = tname, lp = "/tmp/shtm"; (*cp = *lp++) != '\0'; cp++)
|
||||
;
|
||||
lp = putn(getpid()*1000 + inc++);
|
||||
for (; (*cp = *lp++) != '\0'; cp++)
|
||||
;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
#define Extern
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#define _NSIG NSIG
|
||||
#include <errno.h>
|
||||
#include <setjmp.h>
|
||||
#include "sh.h"
|
||||
|
@ -1,9 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= ns
|
||||
SRCS= ns.c
|
||||
|
||||
CFLAGS+= -DBRIDGING
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,43 +0,0 @@
|
||||
Warsaw, 1998.07.20
|
||||
|
||||
Small replacement for netstat
|
||||
-----------------------------
|
||||
|
||||
This program implements some basic functionality subset of normal netstat -
|
||||
it can display the routing table and protocol statistics.
|
||||
|
||||
Large part of the code dealing with retrieving the routing table via sysctl(3)
|
||||
was taken from code examples written by Richard Stevens to accompany his
|
||||
excellent book.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
ns [-rsi] [-p proto] [-w wait]
|
||||
|
||||
where
|
||||
|
||||
-r print routing table (default)
|
||||
-s print protocol statistics
|
||||
-i print interface statistics
|
||||
-p proto display only statistics related to this
|
||||
protocol, where 'proto' is one of:
|
||||
- ip
|
||||
- tcp
|
||||
- udp
|
||||
- icmp
|
||||
- bdg - bridging stats, if 'ns' was compiled with
|
||||
bridging support (flag BRIDGING in Makefile)
|
||||
-w wait continuous display, repeat every 'wait' seconds.
|
||||
|
||||
Bugs
|
||||
----
|
||||
|
||||
* 'ns' doesn't resolve IP addresses to names
|
||||
* well, real netstat provides _much_ more information... but this one needs
|
||||
to be small, right? :-)
|
||||
|
||||
Andrzej Bialecki
|
||||
<abial@freebsd.org>
|
||||
|
||||
$FreeBSD$
|
@ -1,831 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Andrzej Bialecki
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Small replacement for netstat. Uses only sysctl(3) to get the info.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/route.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netinet/icmp_var.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/tcp_timer.h>
|
||||
#include <netinet/tcp_var.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/udp_var.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <osreldate.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char *progname;
|
||||
int iflag = 0;
|
||||
int lflag = 0; /* print cpu load info */
|
||||
int rflag = 0;
|
||||
int sflag = 0;
|
||||
int pflag = 0;
|
||||
int wflag = 0; /* repeat every wait seconds */
|
||||
int delta = 0 ;
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
void print_load_stats(void);
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "\n%s [-nrsil] [-p proto] [-w wait]\n", progname);
|
||||
fprintf(stderr, " proto: {ip|tcp|udp|icmp}\n\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The following parts related to retrieving the routing table and
|
||||
* interface information, were borrowed from R. Stevens' code examples
|
||||
* accompanying his excellent book. Thanks!
|
||||
*/
|
||||
char *
|
||||
sock_ntop(const struct sockaddr *sa, size_t salen)
|
||||
{
|
||||
char portstr[7];
|
||||
static char str[128]; /* Unix domain is largest */
|
||||
|
||||
switch (sa->sa_family) {
|
||||
case 255: {
|
||||
int i = 0;
|
||||
u_long mask;
|
||||
u_int index = 1 << 31;
|
||||
u_short new_mask = 0;
|
||||
|
||||
mask = ntohl(((struct sockaddr_in *)sa)->sin_addr.s_addr);
|
||||
|
||||
while (mask & index) {
|
||||
new_mask++;
|
||||
index >>= 1;
|
||||
}
|
||||
sprintf(str, "/%hu", new_mask);
|
||||
return (str);
|
||||
}
|
||||
case AF_UNSPEC:
|
||||
case AF_INET: {
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
|
||||
|
||||
if (inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str))
|
||||
== NULL)
|
||||
return (NULL);
|
||||
if (ntohs(sin->sin_port) != 0) {
|
||||
snprintf(portstr, sizeof(portstr), ".%d",
|
||||
ntohs(sin->sin_port));
|
||||
strcat(str, portstr);
|
||||
}
|
||||
if (strcmp(str, "0.0.0.0") == 0)
|
||||
sprintf(str, "default");
|
||||
return (str);
|
||||
}
|
||||
|
||||
case AF_UNIX: {
|
||||
struct sockaddr_un *unp = (struct sockaddr_un *)sa;
|
||||
|
||||
/*
|
||||
* OK to have no pathname bound to the socket:
|
||||
* happens on every connect() unless client calls
|
||||
* bind() first.
|
||||
*/
|
||||
if (unp->sun_path[0] == 0)
|
||||
strcpy(str, "(no pathname bound)");
|
||||
else
|
||||
snprintf(str, sizeof(str), "%s", unp->sun_path);
|
||||
return (str);
|
||||
}
|
||||
|
||||
case AF_LINK: {
|
||||
struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
|
||||
|
||||
if (sdl->sdl_nlen > 0) {
|
||||
bcopy(&sdl->sdl_data[0], str, sdl->sdl_nlen);
|
||||
str[sdl->sdl_nlen] = '\0';
|
||||
} else
|
||||
snprintf(str, sizeof(str), "link#%d", sdl->sdl_index);
|
||||
return (str);
|
||||
}
|
||||
|
||||
default:
|
||||
snprintf(str, sizeof(str),
|
||||
"sock_ntop: unknown AF_xxx: %d, len %d", sa->sa_family,
|
||||
salen);
|
||||
return (str);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
Sock_ntop(const struct sockaddr *sa, size_t salen)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
if ((ptr = sock_ntop(sa, salen)) == NULL)
|
||||
err(1, "sock_ntop error"); /* inet_ntop() sets errno */
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
|
||||
#define ROUNDUP(a,size) (((a) & ((size)-1))?(1+((a)|((size)-1))):(a))
|
||||
|
||||
#define NEXT_SA(ap) \
|
||||
ap=(struct sockaddr *) \
|
||||
((caddr_t)ap+(ap->sa_len?ROUNDUP(ap->sa_len,sizeof(u_long)):\
|
||||
sizeof(u_long)))
|
||||
|
||||
void
|
||||
get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < RTAX_MAX; i++) {
|
||||
if (addrs & (1 << i)) {
|
||||
rti_info[i] = sa;
|
||||
NEXT_SA(sa);
|
||||
} else
|
||||
rti_info[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
get_flags(char *buf, int flags)
|
||||
{
|
||||
if (flags & 0x1)
|
||||
strcat(buf, "U");
|
||||
if (flags & 0x2)
|
||||
strcat(buf, "G");
|
||||
if (flags & 0x4)
|
||||
strcat(buf, "H");
|
||||
if (flags & 0x8)
|
||||
strcat(buf, "r");
|
||||
if (flags & 0x10)
|
||||
strcat(buf, "d");
|
||||
#ifdef NEVER
|
||||
if (flags & 0x20)
|
||||
strcat(buf, "mod,");
|
||||
#endif /*NEVER*/
|
||||
if (flags & 0x100)
|
||||
strcat(buf, "C");
|
||||
if (flags & 0x400)
|
||||
strcat(buf, "L");
|
||||
if (flags & 0x800)
|
||||
strcat(buf, "S");
|
||||
if (flags & 0x10000)
|
||||
strcat(buf, "c");
|
||||
if (flags & 0x20000)
|
||||
strcat(buf, "W");
|
||||
#ifdef NEVER
|
||||
if (flags & 0x200000)
|
||||
strcat(buf, ",LOC");
|
||||
#endif /*NEVER*/
|
||||
if (flags & 0x400000)
|
||||
strcat(buf, "b");
|
||||
#ifdef NEVER
|
||||
if (flags & 0x800000)
|
||||
strcat(buf, ",MCA");
|
||||
#endif /*NEVER*/
|
||||
}
|
||||
|
||||
void
|
||||
print_routing(char *proto)
|
||||
{
|
||||
int mib[6];
|
||||
int i = 0;
|
||||
int rt_len;
|
||||
int if_len;
|
||||
int if_num;
|
||||
char *rt_buf;
|
||||
char *if_buf;
|
||||
char *next;
|
||||
char *lim;
|
||||
struct rt_msghdr *rtm;
|
||||
struct if_msghdr *ifm;
|
||||
struct if_msghdr **ifm_table;
|
||||
struct ifa_msghdr *ifam;
|
||||
struct sockaddr *sa;
|
||||
struct sockaddr *sa1;
|
||||
struct sockaddr *rti_info[RTAX_MAX];
|
||||
struct sockaddr **if_table;
|
||||
struct rt_metrics rm;
|
||||
char fbuf[50];
|
||||
|
||||
/* keep a copy of statistics here for future use */
|
||||
static unsigned *base_stats = NULL ;
|
||||
static unsigned base_len = 0 ;
|
||||
|
||||
/* Get the routing table */
|
||||
mib[0] = CTL_NET;
|
||||
mib[1] = PF_ROUTE;
|
||||
mib[2] = 0;
|
||||
mib[3] = 0;
|
||||
mib[4] = NET_RT_DUMP;
|
||||
mib[5] = 0;
|
||||
|
||||
/*Estimate the size of table */
|
||||
if (sysctl(mib, 6, NULL, &rt_len, NULL, 0) == -1) {
|
||||
perror("sysctl size");
|
||||
exit(-1);
|
||||
}
|
||||
if ((rt_buf = (char *)malloc(rt_len)) == NULL) {
|
||||
perror("malloc");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Now get it. */
|
||||
if (sysctl(mib, 6, rt_buf, &rt_len, NULL, 0) == -1) {
|
||||
perror("sysctl get");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Get the interfaces table */
|
||||
mib[0] = CTL_NET;
|
||||
mib[1] = PF_ROUTE;
|
||||
mib[2] = 0;
|
||||
mib[3] = 0;
|
||||
mib[4] = NET_RT_IFLIST;
|
||||
mib[5] = 0;
|
||||
|
||||
/* Estimate the size of table */
|
||||
if (sysctl(mib, 6, NULL, &if_len, NULL, 0) == -1) {
|
||||
perror("sysctl size");
|
||||
exit(-1);
|
||||
}
|
||||
if ((if_buf = (char *)malloc(if_len)) == NULL) {
|
||||
perror("malloc");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Now get it. */
|
||||
if (sysctl(mib, 6, if_buf, &if_len, NULL, 0) == -1) {
|
||||
perror("sysctl get");
|
||||
exit(-1);
|
||||
}
|
||||
lim = if_buf + if_len;
|
||||
i = 0;
|
||||
for (next = if_buf, i = 0; next < lim; next += ifm->ifm_msglen) {
|
||||
ifm = (struct if_msghdr *)next;
|
||||
i++;
|
||||
}
|
||||
if_num = i;
|
||||
if_table = (struct sockaddr **)calloc(i, sizeof(struct sockaddr));
|
||||
ifm_table = (struct if_msghdr **)calloc(i, sizeof(struct if_msghdr));
|
||||
if (iflag) {
|
||||
printf("\nInterface table:\n");
|
||||
printf("----------------\n");
|
||||
printf("Name Mtu Network Address "
|
||||
"Ipkts Ierrs Opkts Oerrs Coll\n");
|
||||
}
|
||||
/* scan the list and store base values */
|
||||
i = 0 ;
|
||||
for (next = if_buf; next < lim; next += ifm->ifm_msglen) {
|
||||
ifm = (struct if_msghdr *)next;
|
||||
i++ ;
|
||||
}
|
||||
if (base_stats == NULL || i != base_len) {
|
||||
base_stats = calloc(i*5, sizeof(unsigned));
|
||||
base_len = i ;
|
||||
}
|
||||
i = 0;
|
||||
for (next = if_buf; next < lim; next += ifm->ifm_msglen) {
|
||||
ifm = (struct if_msghdr *)next;
|
||||
if_table[i] = (struct sockaddr *)(ifm + 1);
|
||||
ifm_table[i] = ifm;
|
||||
|
||||
sa = if_table[i];
|
||||
if (iflag && sa->sa_family == AF_LINK) {
|
||||
struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
|
||||
unsigned *bp = &base_stats[i*5];
|
||||
|
||||
printf("%-4s %-5d <Link> ",
|
||||
sock_ntop(if_table[i], if_table[i]->sa_len),
|
||||
ifm->ifm_data.ifi_mtu);
|
||||
if (sdl->sdl_alen == 6) {
|
||||
unsigned char *p =
|
||||
sdl->sdl_data + sdl->sdl_nlen;
|
||||
printf("%02x:%02x:%02x:%02x:%02x:%02x ",
|
||||
p[0], p[1], p[2], p[3], p[4], p[5]);
|
||||
} else
|
||||
printf(" ");
|
||||
printf("%9d%6d%9d%6d%6d\n",
|
||||
ifm->ifm_data.ifi_ipackets - bp[0],
|
||||
ifm->ifm_data.ifi_ierrors - bp[1],
|
||||
ifm->ifm_data.ifi_opackets - bp[2],
|
||||
ifm->ifm_data.ifi_oerrors - bp[3],
|
||||
ifm->ifm_data.ifi_collisions -bp[4]);
|
||||
if (delta > 0) {
|
||||
bp[0] = ifm->ifm_data.ifi_ipackets ;
|
||||
bp[1] = ifm->ifm_data.ifi_ierrors ;
|
||||
bp[2] = ifm->ifm_data.ifi_opackets ;
|
||||
bp[3] = ifm->ifm_data.ifi_oerrors ;
|
||||
bp[4] = ifm->ifm_data.ifi_collisions ;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (!rflag) {
|
||||
free(rt_buf);
|
||||
free(if_buf);
|
||||
free(if_table);
|
||||
free(ifm_table);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Now dump the routing table */
|
||||
printf("\nRouting table:\n");
|
||||
printf("--------------\n");
|
||||
printf
|
||||
("Destination Gateway Flags Netif Use\n");
|
||||
lim = rt_buf + rt_len;
|
||||
for (next = rt_buf; next < lim; next += rtm->rtm_msglen) {
|
||||
rtm = (struct rt_msghdr *)next;
|
||||
sa = (struct sockaddr *)(rtm + 1);
|
||||
get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
|
||||
if ((sa = rti_info[RTAX_DST]) != NULL) {
|
||||
sprintf(fbuf, "%s", sock_ntop(sa, sa->sa_len));
|
||||
if (((sa1 = rti_info[RTAX_NETMASK]) != NULL)
|
||||
&& sa1->sa_family == 255) {
|
||||
strcat(fbuf, sock_ntop(sa1, sa1->sa_len));
|
||||
}
|
||||
printf("%-19s", fbuf);
|
||||
}
|
||||
if ((sa = rti_info[RTAX_GATEWAY]) != NULL) {
|
||||
printf("%-19s", sock_ntop(sa, sa->sa_len));
|
||||
}
|
||||
memset(fbuf, 0, sizeof(fbuf));
|
||||
get_flags(fbuf, rtm->rtm_flags);
|
||||
printf("%-10s", fbuf);
|
||||
for (i = 0; i < if_num; i++) {
|
||||
ifm = ifm_table[i];
|
||||
if ((ifm->ifm_index == rtm->rtm_index) &&
|
||||
(ifm->ifm_data.ifi_type > 0)) {
|
||||
sa = if_table[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ifm->ifm_type == RTM_IFINFO) {
|
||||
get_rtaddrs(ifm->ifm_addrs, sa, rti_info);
|
||||
printf(" %s", Sock_ntop(sa, sa->sa_len));
|
||||
} else if (ifm->ifm_type == RTM_NEWADDR) {
|
||||
ifam =
|
||||
(struct ifa_msghdr *)ifm_table[rtm->rtm_index - 1];
|
||||
sa = (struct sockaddr *)(ifam + 1);
|
||||
get_rtaddrs(ifam->ifam_addrs, sa, rti_info);
|
||||
printf(" %s", Sock_ntop(sa, sa->sa_len));
|
||||
}
|
||||
/* printf(" %u", rtm->rtm_use); */
|
||||
printf("\n");
|
||||
}
|
||||
free(rt_buf);
|
||||
free(if_buf);
|
||||
free(if_table);
|
||||
free(ifm_table);
|
||||
}
|
||||
|
||||
void
|
||||
print_ip_stats(void)
|
||||
{
|
||||
int mib[4];
|
||||
int len;
|
||||
struct ipstat s;
|
||||
|
||||
mib[0] = CTL_NET;
|
||||
mib[1] = PF_INET;
|
||||
mib[2] = IPPROTO_IP;
|
||||
#ifndef IPCTL_STATS
|
||||
printf("sorry, ip stats not available\n");
|
||||
return -1;
|
||||
#else
|
||||
mib[3] = IPCTL_STATS;
|
||||
len = sizeof(struct ipstat);
|
||||
if (sysctl(mib, 4, &s, &len, NULL, 0) < 0) {
|
||||
perror("sysctl");
|
||||
return;
|
||||
}
|
||||
printf("\nIP statistics:\n");
|
||||
printf("--------------\n");
|
||||
printf(" %10lu total packets received\n", s.ips_total);
|
||||
printf("* Packets ok:\n");
|
||||
printf(" %10lu fragments received\n", s.ips_fragments);
|
||||
printf(" %10lu forwarded\n", s.ips_forward);
|
||||
#if __FreeBSD_version > 300001
|
||||
printf(" %10lu fast forwarded\n", s.ips_fastforward);
|
||||
#endif
|
||||
printf(" %10lu forwarded on same net (redirect)\n",
|
||||
s.ips_redirectsent);
|
||||
printf(" %10lu delivered to upper level\n", s.ips_delivered);
|
||||
printf(" %10lu total ip packets generated here\n", s.ips_localout);
|
||||
printf(" %10lu total packets reassembled ok\n", s.ips_reassembled);
|
||||
printf(" %10lu total datagrams successfully fragmented\n",
|
||||
s.ips_fragmented);
|
||||
printf(" %10lu output fragments created\n", s.ips_ofragments);
|
||||
printf(" %10lu total raw IP packets generated\n", s.ips_rawout);
|
||||
printf("\n* Bad packets:\n");
|
||||
printf(" %10lu bad checksum\n", s.ips_badsum);
|
||||
printf(" %10lu too short\n", s.ips_tooshort);
|
||||
printf(" %10lu not enough data (too small)\n", s.ips_toosmall);
|
||||
printf(" %10lu more data than declared in header\n", s.ips_badhlen);
|
||||
printf(" %10lu less data than declared in header\n", s.ips_badlen);
|
||||
printf(" %10lu fragments dropped (dups, no mbuf)\n",
|
||||
s.ips_fragdropped);
|
||||
printf(" %10lu fragments timed out in reassembly\n",
|
||||
s.ips_fragtimeout);
|
||||
printf(" %10lu received for unreachable dest.\n", s.ips_cantforward);
|
||||
printf(" %10lu unknown or unsupported protocol\n", s.ips_noproto);
|
||||
printf(" %10lu lost due to no bufs etc.\n", s.ips_odropped);
|
||||
printf(" %10lu couldn't fragment (DF set, etc.)\n", s.ips_cantfrag);
|
||||
printf(" %10lu error in IP options processing\n", s.ips_badoptions);
|
||||
printf(" %10lu dropped due to no route\n", s.ips_noroute);
|
||||
printf(" %10lu bad IP version\n", s.ips_badvers);
|
||||
printf(" %10lu too long (more than max IP size)\n", s.ips_toolong);
|
||||
#if __FreeBSD_version > 300001
|
||||
printf(" %10lu multicast for unregistered groups\n", s.ips_notmember);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
print_tcp_stats(void)
|
||||
{
|
||||
int mib[4];
|
||||
int len;
|
||||
struct tcpstat s;
|
||||
|
||||
mib[0] = CTL_NET;
|
||||
mib[1] = PF_INET;
|
||||
mib[2] = IPPROTO_TCP;
|
||||
#ifndef TCPCTL_STATS
|
||||
printf("sorry, tcp stats not available\n");
|
||||
return;
|
||||
#else
|
||||
mib[3] = TCPCTL_STATS;
|
||||
len = sizeof(struct tcpstat);
|
||||
if (sysctl(mib, 4, &s, &len, NULL, 0) < 0) {
|
||||
perror("sysctl");
|
||||
return;
|
||||
}
|
||||
printf("\nTCP statistics:\n");
|
||||
printf("---------------\n");
|
||||
printf("* Connections:\n");
|
||||
printf(" %10lu initiated\n", s.tcps_connattempt);
|
||||
printf(" %10lu accepted\n", s.tcps_accepts);
|
||||
printf(" %10lu established\n", s.tcps_connects);
|
||||
printf(" %10lu dropped\n", s.tcps_drops);
|
||||
printf(" %10lu embryonic connections dropped\n", s.tcps_conndrops);
|
||||
printf(" %10lu closed (includes dropped)\n", s.tcps_closed);
|
||||
printf(" %10lu segments where we tried to get RTT\n",
|
||||
s.tcps_segstimed);
|
||||
printf(" %10lu times RTT successfully updated\n", s.tcps_rttupdated);
|
||||
printf(" %10lu delayed ACKs sent\n", s.tcps_delack);
|
||||
printf(" %10lu dropped in rxmt timeout\n", s.tcps_timeoutdrop);
|
||||
printf(" %10lu retrasmit timeouts\n", s.tcps_rexmttimeo);
|
||||
printf(" %10lu persist timeouts\n", s.tcps_persisttimeo);
|
||||
printf(" %10lu keepalive timeouts\n", s.tcps_keeptimeo);
|
||||
printf(" %10lu keepalive probes sent\n", s.tcps_keepprobe);
|
||||
printf(" %10lu dropped in keepalive\n", s.tcps_keepdrops);
|
||||
|
||||
printf("* Packets sent:\n");
|
||||
printf(" %10lu total packets sent\n", s.tcps_sndtotal);
|
||||
printf(" %10lu data packets sent\n", s.tcps_sndpack);
|
||||
printf(" %10lu data bytes sent\n", s.tcps_sndbyte);
|
||||
printf(" %10lu data packets retransmitted\n", s.tcps_sndrexmitpack);
|
||||
printf(" %10lu data bytes retransmitted\n", s.tcps_sndrexmitbyte);
|
||||
printf(" %10lu ACK-only packets sent\n", s.tcps_sndacks);
|
||||
printf(" %10lu window probes sent\n", s.tcps_sndprobe);
|
||||
printf(" %10lu URG-only packets sent\n", s.tcps_sndurg);
|
||||
printf(" %10lu window update-only packets sent\n", s.tcps_sndwinup);
|
||||
printf(" %10lu control (SYN,FIN,RST) packets sent\n", s.tcps_sndctrl);
|
||||
printf("* Packets received:\n");
|
||||
printf(" %10lu total packets received\n", s.tcps_rcvtotal);
|
||||
printf(" %10lu packets in sequence\n", s.tcps_rcvpack);
|
||||
printf(" %10lu bytes in sequence\n", s.tcps_rcvbyte);
|
||||
printf(" %10lu packets with bad checksum\n", s.tcps_rcvbadsum);
|
||||
printf(" %10lu packets with bad offset\n", s.tcps_rcvbadoff);
|
||||
printf(" %10lu packets too short\n", s.tcps_rcvshort);
|
||||
printf(" %10lu duplicate-only packets\n", s.tcps_rcvduppack);
|
||||
printf(" %10lu duplicate-only bytes\n", s.tcps_rcvdupbyte);
|
||||
printf(" %10lu packets with some duplicate data\n",
|
||||
s.tcps_rcvpartduppack);
|
||||
printf(" %10lu duplicate bytes in partially dup. packets\n",
|
||||
s.tcps_rcvpartdupbyte);
|
||||
printf(" %10lu out-of-order packets\n", s.tcps_rcvoopack);
|
||||
printf(" %10lu out-of-order bytes\n", s.tcps_rcvoobyte);
|
||||
printf(" %10lu packets with data after window\n",
|
||||
s.tcps_rcvpackafterwin);
|
||||
printf(" %10lu bytes received after window\n",
|
||||
s.tcps_rcvbyteafterwin);
|
||||
printf(" %10lu packets received after 'close'\n",
|
||||
s.tcps_rcvafterclose);
|
||||
printf(" %10lu window probe packets\n", s.tcps_rcvwinprobe);
|
||||
printf(" %10lu duplicate ACKs\n", s.tcps_rcvdupack);
|
||||
printf(" %10lu ACKs for unsent data\n", s.tcps_rcvacktoomuch);
|
||||
printf(" %10lu ACK packets\n", s.tcps_rcvackpack);
|
||||
printf(" %10lu bytes ACKed by received ACKs\n", s.tcps_rcvackbyte);
|
||||
printf(" %10lu window update packets\n", s.tcps_rcvwinupd);
|
||||
printf(" %10lu segments dropped due to PAWS\n", s.tcps_pawsdrop);
|
||||
printf(" %10lu times header predict ok for ACKs\n", s.tcps_predack);
|
||||
printf(" %10lu times header predict ok for data packets\n",
|
||||
s.tcps_preddat);
|
||||
printf(" %10lu PCB cache misses\n", s.tcps_pcbcachemiss);
|
||||
printf(" %10lu times cached RTT in route updated\n",
|
||||
s.tcps_cachedrtt);
|
||||
printf(" %10lu times cached RTTVAR updated\n", s.tcps_cachedrttvar);
|
||||
printf(" %10lu times ssthresh updated\n", s.tcps_cachedssthresh);
|
||||
printf(" %10lu times RTT initialized from route\n", s.tcps_usedrtt);
|
||||
printf(" %10lu times RTTVAR initialized from route\n",
|
||||
s.tcps_usedrttvar);
|
||||
printf(" %10lu times ssthresh initialized from route\n",
|
||||
s.tcps_usedssthresh);
|
||||
printf(" %10lu timeout in persist state\n", s.tcps_persistdrop);
|
||||
printf(" %10lu bogus SYN, e.g. premature ACK\n", s.tcps_badsyn);
|
||||
printf(" %10lu resends due to MTU discovery\n", s.tcps_mturesent);
|
||||
printf(" %10lu listen queue overflows\n", s.tcps_listendrop);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
print_udp_stats(void)
|
||||
{
|
||||
int mib[4];
|
||||
int len;
|
||||
struct udpstat s;
|
||||
|
||||
mib[0] = CTL_NET;
|
||||
mib[1] = PF_INET;
|
||||
mib[2] = IPPROTO_UDP;
|
||||
mib[3] = UDPCTL_STATS;
|
||||
len = sizeof(struct udpstat);
|
||||
if (sysctl(mib, 4, &s, &len, NULL, 0) < 0) {
|
||||
perror("sysctl");
|
||||
return;
|
||||
}
|
||||
printf("\nUDP statistics:\n");
|
||||
printf("---------------\n");
|
||||
printf("* Packets received:\n");
|
||||
printf(" %10lu total input packets\n", s.udps_ipackets);
|
||||
printf(" %10lu packets shorter than header (dropped)\n",
|
||||
s.udps_hdrops);
|
||||
printf(" %10lu bad checksum\n", s.udps_badsum);
|
||||
printf(" %10lu data length larger than packet\n", s.udps_badlen);
|
||||
printf(" %10lu no socket on specified port\n", s.udps_noport);
|
||||
printf(" %10lu of above, arrived as broadcast\n", s.udps_noportbcast);
|
||||
printf(" %10lu not delivered, input socket full\n", s.udps_fullsock);
|
||||
printf(" %10lu packets missing PCB cache\n", s.udpps_pcbcachemiss);
|
||||
printf(" %10lu packets not for hashed PCBs\n", s.udpps_pcbhashmiss);
|
||||
printf("* Packets sent:\n");
|
||||
printf(" %10lu total output packets\n", s.udps_opackets);
|
||||
#if __FreeBSD_version > 300001
|
||||
printf(" %10lu output packets on fast path\n", s.udps_fastout);
|
||||
#endif
|
||||
}
|
||||
|
||||
char *icmp_names[] = {
|
||||
"echo reply",
|
||||
"#1",
|
||||
"#2",
|
||||
"destination unreachable",
|
||||
"source quench",
|
||||
"routing redirect",
|
||||
"#6",
|
||||
"#7",
|
||||
"echo",
|
||||
"router advertisement",
|
||||
"router solicitation",
|
||||
"time exceeded",
|
||||
"parameter problem",
|
||||
"time stamp",
|
||||
"time stamp reply",
|
||||
"information request",
|
||||
"information request reply",
|
||||
"address mask request",
|
||||
"address mask reply",
|
||||
};
|
||||
|
||||
print_icmp_stats()
|
||||
{
|
||||
int mib[4];
|
||||
int len;
|
||||
int i;
|
||||
struct icmpstat s;
|
||||
|
||||
mib[0] = CTL_NET;
|
||||
mib[1] = PF_INET;
|
||||
mib[2] = IPPROTO_ICMP;
|
||||
mib[3] = ICMPCTL_STATS;
|
||||
len = sizeof(struct icmpstat);
|
||||
if (sysctl(mib, 4, &s, &len, NULL, 0) < 0) {
|
||||
perror("sysctl");
|
||||
return (-1);
|
||||
}
|
||||
printf("\nICMP statistics:\n");
|
||||
printf("----------------\n");
|
||||
printf("* Output histogram:\n");
|
||||
for (i = 0; i < (ICMP_MAXTYPE + 1); i++) {
|
||||
if (s.icps_outhist[i] > 0)
|
||||
printf("\t%10lu %s\n",
|
||||
s.icps_outhist[i], icmp_names[i]);
|
||||
}
|
||||
printf("* Input histogram:\n");
|
||||
for (i = 0; i < (ICMP_MAXTYPE + 1); i++) {
|
||||
if (s.icps_inhist[i] > 0)
|
||||
printf("\t%10lu %s\n",
|
||||
s.icps_inhist[i], icmp_names[i]);
|
||||
}
|
||||
printf("* Other stats:\n");
|
||||
printf(" %10lu calls to icmp_error\n", s.icps_error);
|
||||
printf(" %10lu no error 'cuz old ip too short\n", s.icps_oldshort);
|
||||
printf(" %10lu no error 'cuz old was icmp\n", s.icps_oldicmp);
|
||||
|
||||
printf(" %10lu icmp code out of range\n", s.icps_badcode);
|
||||
printf(" %10lu packets shorter than min length\n", s.icps_tooshort);
|
||||
printf(" %10lu bad checksum\n", s.icps_checksum);
|
||||
printf(" %10lu calculated bound mismatch\n", s.icps_badlen);
|
||||
printf(" %10lu number of responses\n", s.icps_reflect);
|
||||
printf(" %10lu broad/multi-cast echo requests dropped\n",
|
||||
s.icps_bmcastecho);
|
||||
printf(" %10lu broad/multi-cast timestamp requests dropped\n",
|
||||
s.icps_bmcasttstamp);
|
||||
}
|
||||
|
||||
int
|
||||
stats(char *proto)
|
||||
{
|
||||
if (!sflag)
|
||||
return 0;
|
||||
if (pflag) {
|
||||
if (proto == NULL) {
|
||||
fprintf(stderr, "Option '-p' requires parameter.\n");
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
if (strcmp(proto, "ip") == 0)
|
||||
print_ip_stats();
|
||||
if (strcmp(proto, "icmp") == 0)
|
||||
print_icmp_stats();
|
||||
if (strcmp(proto, "udp") == 0)
|
||||
print_udp_stats();
|
||||
if (strcmp(proto, "tcp") == 0)
|
||||
print_tcp_stats();
|
||||
return (0);
|
||||
}
|
||||
print_ip_stats();
|
||||
print_icmp_stats();
|
||||
print_udp_stats();
|
||||
print_tcp_stats();
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char c;
|
||||
char *proto = NULL;
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
while ((c = getopt(argc, argv, "dilnrsp:w:")) != -1) {
|
||||
switch (c) {
|
||||
case 'd': /* print deltas in stats every w seconds */
|
||||
delta++ ;
|
||||
break;
|
||||
case 'w':
|
||||
wflag = atoi(optarg);
|
||||
break;
|
||||
case 'n': /* ignored, just for compatibility with std netstat */
|
||||
break;
|
||||
case 'r':
|
||||
rflag++;
|
||||
break;
|
||||
case 'i':
|
||||
iflag++;
|
||||
break;
|
||||
case 'l':
|
||||
lflag++;
|
||||
break;
|
||||
case 's':
|
||||
sflag++;
|
||||
rflag = 0;
|
||||
break;
|
||||
case 'p':
|
||||
pflag++;
|
||||
sflag++;
|
||||
proto = optarg;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rflag == 0 && sflag == 0 && iflag == 0)
|
||||
rflag = 1;
|
||||
argc -= optind;
|
||||
|
||||
if (argc > 0) {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
if (wflag)
|
||||
printf("\033[H\033[J");
|
||||
again:
|
||||
if (wflag) {
|
||||
struct timeval t;
|
||||
|
||||
gettimeofday(&t, NULL);
|
||||
printf("\033[H%s", ctime(&t.tv_sec));
|
||||
}
|
||||
print_routing(proto);
|
||||
print_load_stats();
|
||||
stats(proto);
|
||||
if (wflag) {
|
||||
sleep(wflag);
|
||||
goto again;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
print_load_stats(void)
|
||||
{
|
||||
static u_int32_t cp_time[5];
|
||||
u_int32_t new_cp_time[5];
|
||||
int l;
|
||||
int shz;
|
||||
static int stathz ;
|
||||
|
||||
if (!lflag || !wflag)
|
||||
return;
|
||||
l = sizeof(new_cp_time) ;
|
||||
bzero(new_cp_time, l);
|
||||
if (sysctlbyname("kern.cp_time", new_cp_time, &l, NULL, 0) < 0) {
|
||||
warn("sysctl: retrieving cp_time length");
|
||||
return;
|
||||
}
|
||||
if (stathz == 0) {
|
||||
struct clockinfo ci;
|
||||
|
||||
bzero (&ci, sizeof(ci));
|
||||
l = sizeof(ci) ;
|
||||
if (sysctlbyname("kern.clockrate", &ci, &l, NULL, 0) < 0) {
|
||||
warn("sysctl: retrieving clockinfo length");
|
||||
return;
|
||||
}
|
||||
stathz = ci.stathz ;
|
||||
bcopy(new_cp_time, cp_time, sizeof(cp_time));
|
||||
}
|
||||
shz = stathz * wflag ;
|
||||
if (shz == 0)
|
||||
shz = 1;
|
||||
#define X(i) ( (double)(new_cp_time[i] - cp_time[i])*100/shz )
|
||||
printf("\nUSER %5.2f%% NICE %5.2f%% SYS %5.2f%% "
|
||||
"INTR %5.2f%% IDLE %5.2f%%\n",
|
||||
X(0), X(1), X(2), X(3), X(4) );
|
||||
bcopy(new_cp_time, cp_time, sizeof(cp_time));
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
PROG= oinit
|
||||
|
||||
SH_PATH?= /bin/sh
|
||||
SH_NAME?= -sh
|
||||
SH_ARG?= /etc/rc
|
||||
|
||||
CFLAGS= -DSH_PATH=\"${SH_PATH}\" -DSH_NAME=\"${SH_NAME}\" \
|
||||
-DSH_ARG=\"${SH_ARG}\"
|
||||
|
||||
|
||||
#CFLAGS+= -DUSE_HISTORY
|
||||
#CFLAGS+= -DOINIT_RC=\"/etc/oinit.rc\"
|
||||
|
||||
#LDADD= -lutil -ledit -ltermcap
|
||||
LIBADD= util
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
|
@ -1,123 +0,0 @@
|
||||
Warsaw, 1998.07.07
|
||||
|
||||
This README shortly describes the features of "oinit" - a very simplistic
|
||||
version of init(8) combined with a shell.
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* oinit is able to run system in multi- and single-user modes,
|
||||
* it can be started on system with DEVFS/SLICE (i.e. empty /dev),
|
||||
* provides minimalistic user interface, called "shell()",
|
||||
* it can run the system startup script (/etc/rc),
|
||||
* it can be compiled with -DOINIT_RC to use its own startup script
|
||||
(*very* primitive, but doesn't require any real shell to run it!),
|
||||
* doesn't require the whole chain of init->getty->login->shell to be run,
|
||||
* it is extremely small, and is ideally suited for situations when
|
||||
there is little memory.
|
||||
|
||||
As an additional bonus you receive some obvious and some hidden bugs... :-))
|
||||
This code is at most alpha quality yet.
|
||||
|
||||
|
||||
How it works
|
||||
------------
|
||||
|
||||
Unlike normal init(8), it forks itself on given number of vty's immediately
|
||||
providing shell() interface. Currently it doesn't require (and is unable to
|
||||
perform) any authentication, but this is easy to add if needed.
|
||||
|
||||
Standard version of FreeBSD kernel looks for /sbin/init first, and then
|
||||
tries to execute it. If it fails, it tries to find:
|
||||
/sbin/oinit
|
||||
/sbin/init.bak
|
||||
/stand/sysinstall
|
||||
|
||||
So it is easy to make use of it even on standard system - just put it in
|
||||
/sbin/oinit and rename /sbin/init to something else, e.g. /sbin/init.bak.
|
||||
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
!!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
Init (or oinit) plays crucial role in the system. If you plan to do any
|
||||
changes to your system's init, make sure you have a boot floppy with working
|
||||
version of statically compiled init(8) on it - you can very easily put your
|
||||
system in unusable state when fiddling with it.
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
Shell() interface
|
||||
-----------------
|
||||
|
||||
It allows you to issue built-in and external commands. Built-in commands
|
||||
are listed below. For each command there is short help available, with
|
||||
example of usage.
|
||||
|
||||
cd change working directory
|
||||
pwd print working directory
|
||||
set set environment variable (no expansion)
|
||||
unset unset environment variable
|
||||
env print all environment variables
|
||||
echo echo arguments on stdout
|
||||
exit exit from shell (oinit will start a new one after some delay)
|
||||
. source-in a file with commands
|
||||
? help
|
||||
|
||||
Any other command is passed to execvp(3) as it is.
|
||||
|
||||
EXCEPTION: if you end the command line with a '&', the command is started
|
||||
as daemon. This is NOT the same as in normal shell, where the '&' puts a
|
||||
process in background. Here the newly started process is totally dissociated
|
||||
from terminal.
|
||||
|
||||
Prompt tells you:
|
||||
* your `pwd`
|
||||
* your PID
|
||||
* and that you are root ('#').
|
||||
|
||||
WARNING: this pseudo-shell doesn't do any expansion whatsoever.
|
||||
|
||||
To do list
|
||||
----------
|
||||
|
||||
- oinit proper:
|
||||
* fix signal handling and transitions,
|
||||
* invent a one-file configuration database (combining as many files
|
||||
from /etc as possible into one) able to properly handle inter-
|
||||
dependencies in running various daemons,
|
||||
* allow for interpreting of such database, and running various
|
||||
programs ourselves (this would eventually allow to make /bin/sh
|
||||
an option, not necessity),
|
||||
* better hooks for incorporating other modules into oinit (see e.g.
|
||||
the telnet() below),
|
||||
* add optional authentication,
|
||||
|
||||
- shell():
|
||||
* more built-ins: perhaps 'kill' and 'ps',
|
||||
* variable expansion,
|
||||
* globbing,
|
||||
* conditionals,
|
||||
* history? (it depends on how much memory it needs).
|
||||
* programmatic hooks for easy customisation of user interface (like
|
||||
hierarchy of commands and contexts),
|
||||
* ...
|
||||
|
||||
- implement as a routine (like shell()) a small remote login daemon telnet(),
|
||||
as a built-in module to oinit. It would implement the simplest options of
|
||||
normal telnet, and would itself handle authentication, passing control to
|
||||
shell() on success. The authentication routine would be the same as for
|
||||
checking console access.
|
||||
|
||||
And allow me for a moment of day-dreaming: I'd like to rewrite oinit one day
|
||||
to be a monolithic one-in-all application, non-forking but multithreaded... It
|
||||
would contain all the modules, such as shell(), telnet(), ifconfig() etc...
|
||||
started as threads, not separate processes.
|
||||
|
||||
Credits
|
||||
-------
|
||||
|
||||
The overall framework was taken from FreeBSD /sbin/init.
|
||||
|
||||
Andrzej Bialecki
|
||||
<abial@freebsd.org>
|
||||
|
||||
$FreeBSD$
|
@ -1,947 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Andrzej Bialecki
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* A primitive version of init(8) with simplistic user interface
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/wait.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
|
||||
#ifdef USE_HISTORY
|
||||
#error "Not yet. But it's quite simple to add - patches are welcome!"
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <libutil.h>
|
||||
#include <paths.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <varargs.h>
|
||||
|
||||
#define BUFSIZE 1024
|
||||
#define MAX_CONS 12
|
||||
|
||||
#define NONE 0
|
||||
#define SINGLE 1
|
||||
#define MULTI 2
|
||||
#define DEATH 3
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
char cwd[BUFSIZE];
|
||||
char vty[]="0123456789abcdef";
|
||||
char *progname;
|
||||
char *motd=NULL;
|
||||
int ncons=MAX_CONS;
|
||||
int Reboot=FALSE;
|
||||
int transition=MULTI;
|
||||
int prevtrans=SINGLE;
|
||||
jmp_buf machine;
|
||||
|
||||
char *trans[]={ "NONE", "SINGLE", "MULTI", "DEATH" };
|
||||
|
||||
extern char **environ;
|
||||
|
||||
/* Struct for holding session state */
|
||||
struct sess {
|
||||
char tty[16]; /* vty device path */
|
||||
pid_t pid; /* pid of process running on it */
|
||||
int (*func)(int argc, char **argv);
|
||||
/* internal function to run on it (after forking) */
|
||||
} ttys[MAX_CONS];
|
||||
|
||||
/* Struct for built-in command */
|
||||
struct command {
|
||||
char *cmd; /* command name */
|
||||
char *descr; /* command description */
|
||||
char *usage; /* usage */
|
||||
char *example; /* example of usage */
|
||||
int (*func)(char *); /* callback function */
|
||||
};
|
||||
|
||||
/* Prototypes */
|
||||
int cd(char *);
|
||||
int pwd(char *);
|
||||
int echo(char *);
|
||||
int xit(char *);
|
||||
int set(char *);
|
||||
int unset(char *);
|
||||
int env(char *);
|
||||
int help(char *);
|
||||
int sourcer(char *);
|
||||
void do_command(int shell, char *cmdline);
|
||||
void transition_handler(int);
|
||||
|
||||
/* Table of built-in functions */
|
||||
struct command bltins[]={
|
||||
{"cd","Change working directory","cd [dir]","cd /etc",cd},
|
||||
{"pwd","Print current directory","pwd","pwd",pwd},
|
||||
{"exit","Exit from shell()","exit","exit",xit},
|
||||
{"set","Set environment variable","set [VAR=value]","set TERM=xterm",set},
|
||||
{"unset","Unset environment variable","unset VAR","unset EDITOR",unset},
|
||||
{"echo","Echo arguments on stdout","echo arg1 arg2 ...","echo Hello World!",echo},
|
||||
{"env","Print all environment variables","env","env",env},
|
||||
{".","Source-in a file with commands",". filename",". /etc/rc",sourcer},
|
||||
{"?","Print this help :-)","? [command]","? set",help},
|
||||
{NULL,NULL,NULL,NULL,NULL}
|
||||
};
|
||||
|
||||
/*
|
||||
* Built-in 'cd <path>' handler
|
||||
*/
|
||||
int
|
||||
cd(char *path)
|
||||
{
|
||||
if(chdir(path)) return(-1);
|
||||
getcwd(cwd,BUFSIZE);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Built-in 'pwd' handler
|
||||
*/
|
||||
int
|
||||
pwd(char *dummy)
|
||||
{
|
||||
|
||||
if(getcwd(cwd,BUFSIZE)==NULL) return(-1);
|
||||
printf("%s\n",cwd);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Built-in 'exit' handler
|
||||
*/
|
||||
int
|
||||
xit(char *dummy)
|
||||
{
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Built-in 'echo' handler
|
||||
*/
|
||||
int
|
||||
echo(char *args)
|
||||
{
|
||||
int i=0,j;
|
||||
int len;
|
||||
char c;
|
||||
int s_quote=0,d_quote=0;
|
||||
int sep=0,no_lf=0;
|
||||
|
||||
if(args==NULL) {
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
len=strlen(args);
|
||||
if(len>=2) {
|
||||
if(args[0]=='-' && args[1]=='n') {
|
||||
no_lf++;
|
||||
i=2;
|
||||
while(i<len && (args[i]==' ' || args[i]=='\t')) i++;
|
||||
}
|
||||
}
|
||||
while(i<len) {
|
||||
c=args[i];
|
||||
switch(c) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
if(s_quote||d_quote) {
|
||||
putchar(c);
|
||||
} else if(!sep) {
|
||||
putchar(' ');
|
||||
sep=1;
|
||||
}
|
||||
break;
|
||||
case '\\':
|
||||
i++;
|
||||
c=args[i];
|
||||
switch(c) {
|
||||
case 'n':
|
||||
putchar('\n');
|
||||
break;
|
||||
case 'b':
|
||||
putchar('\b');
|
||||
break;
|
||||
case 't':
|
||||
putchar('\t');
|
||||
break;
|
||||
case 'r':
|
||||
putchar('\r');
|
||||
break;
|
||||
default:
|
||||
putchar(c);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '"':
|
||||
if(!d_quote) {
|
||||
d_quote=1;
|
||||
for(j=i+1;j<len;j++) {
|
||||
if(args[j]=='\\') {
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
if(args[j]=='"') {
|
||||
d_quote=2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(d_quote!=2) {
|
||||
printf("\necho(): unmatched \"\n");
|
||||
return;
|
||||
}
|
||||
} else d_quote=0;
|
||||
break;
|
||||
case '\'':
|
||||
if(!s_quote) {
|
||||
s_quote=1;
|
||||
for(j=i+1;j<len;j++) {
|
||||
if(args[j]=='\\') {
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
if(args[j]=='\'') {
|
||||
s_quote=2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(s_quote!=2) {
|
||||
printf("\necho(): unmatched '\n");
|
||||
return;
|
||||
}
|
||||
} else s_quote=0;
|
||||
break;
|
||||
case '`':
|
||||
printf("echo(): backquote not implemented yet!\n");
|
||||
break;
|
||||
default:
|
||||
sep=0;
|
||||
putchar(c);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if(!no_lf) putchar('\n');
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
* Built-in 'set VAR=value' handler
|
||||
*/
|
||||
int
|
||||
set(char *var)
|
||||
{
|
||||
int res;
|
||||
|
||||
if(var==NULL) return(env(NULL));
|
||||
res=putenv(var);
|
||||
if(res) printf("set: %s\n",strerror(errno));
|
||||
return(res);
|
||||
}
|
||||
|
||||
/*
|
||||
* Built-in 'env' handler
|
||||
*/
|
||||
int
|
||||
env(char *dummy)
|
||||
{
|
||||
char **e;
|
||||
|
||||
e=environ;
|
||||
while(*e!=NULL) {
|
||||
printf("%s\n",*e++);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Built-in 'unset VAR' handler
|
||||
*/
|
||||
int
|
||||
unset(char *var)
|
||||
{
|
||||
if(var==NULL) {
|
||||
printf("%s: parameter required.\n",progname);
|
||||
return(-1);
|
||||
}
|
||||
return(unsetenv(var));
|
||||
}
|
||||
|
||||
/*
|
||||
* Built-in '?' handler
|
||||
*/
|
||||
int
|
||||
help(char *cmd)
|
||||
{
|
||||
struct command *x;
|
||||
int found=0;
|
||||
|
||||
if(cmd==NULL) {
|
||||
printf("\nBuilt-in commands:\n");
|
||||
printf("-------------------\n");
|
||||
x=bltins;
|
||||
while(x->cmd!=NULL) {
|
||||
printf("%s\t%s\n",x->cmd,x->descr);
|
||||
x++;
|
||||
}
|
||||
printf("\nEnter '? <cmd>' for details.\n\n");
|
||||
return(0);
|
||||
} else {
|
||||
x=bltins;
|
||||
while(x->cmd!=NULL) {
|
||||
if(strcmp(x->cmd,cmd)==0) {
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
if(found) {
|
||||
printf("\n%s\t%s:\n",x->cmd,x->descr);
|
||||
printf("\tUsage:\n\t\t%s\n",x->usage);
|
||||
printf("\te.g:\n\t\t%s\n\n",x->example);
|
||||
return(0);
|
||||
} else {
|
||||
printf("\n%s: no such command.\n\n",cmd);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Signal handler for shell()
|
||||
*/
|
||||
void
|
||||
shell_sig(int sig)
|
||||
{
|
||||
switch(sig) {
|
||||
case SIGINT:
|
||||
case SIGQUIT:
|
||||
case SIGTERM:
|
||||
/* ignore ? */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Built-in '.' handler (read-in and execute commands from file)
|
||||
*/
|
||||
int
|
||||
sourcer(char *fname)
|
||||
{
|
||||
FILE *fd;
|
||||
char buf[512],*tok,*arg,**av;
|
||||
int ac,len,f,res,i;
|
||||
pid_t pid;
|
||||
char *sep=" \t";
|
||||
|
||||
fd=fopen(fname,"r");
|
||||
if(fd==NULL) {
|
||||
printf("Couldn't open file '%s'\n",fname);
|
||||
return(-1);
|
||||
}
|
||||
while(!feof(fd)) {
|
||||
memset(buf,0,512);
|
||||
if(fgets(buf,512,fd)==NULL) continue;
|
||||
if((*buf=='#') || (*buf=='\n')) continue;
|
||||
len=strlen(buf);
|
||||
buf[len-1]='\0';
|
||||
if(strncmp(buf,"ncons",5)==0) {
|
||||
tok=strtok(buf,sep);
|
||||
tok=strtok(NULL,sep);
|
||||
ncons=atoi(tok);
|
||||
if((ncons<1)||(ncons>MAX_CONS)) {
|
||||
syslog(LOG_EMERG,"%s: bad ncons value; defaulting to %d\n",fname,MAX_CONS);
|
||||
ncons=MAX_CONS;
|
||||
}
|
||||
continue;
|
||||
} else if(strncmp(buf,"motd",4)==0) {
|
||||
tok=strtok(buf,sep);
|
||||
motd=strdup(strtok(NULL,sep));
|
||||
continue;
|
||||
} else {
|
||||
do_command(0,buf);
|
||||
}
|
||||
/* Next command, please. */
|
||||
}
|
||||
fclose(fd);
|
||||
syslog(LOG_EMERG,"Done with %s",fname);
|
||||
}
|
||||
|
||||
void
|
||||
do_command(int shell, char *cmdline)
|
||||
{
|
||||
char *tok,*c,*sep=" \t";
|
||||
char **av;
|
||||
struct command *x;
|
||||
int found,len;
|
||||
int ac,i,f,res;
|
||||
int bg=0;
|
||||
pid_t pid;
|
||||
|
||||
len=strlen(cmdline);
|
||||
if(cmdline[len-1]=='&') {
|
||||
bg++;
|
||||
cmdline[len-1]='\0';
|
||||
len--;
|
||||
} else bg=0;
|
||||
tok=strtok(cmdline,sep);
|
||||
x=bltins;
|
||||
found=0;
|
||||
while(x->cmd!=NULL) {
|
||||
if(strcmp(x->cmd,tok)==0) {
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
if(found) {
|
||||
tok=cmdline+strlen(x->cmd)+1;
|
||||
while(*tok && isblank(*tok) && (tok<(cmdline+len))) tok++;
|
||||
if(*tok==NULL) tok=NULL;
|
||||
x->func(tok);
|
||||
return;
|
||||
}
|
||||
ac=0;
|
||||
av=(char **)calloc(((len+1)/2+1),sizeof(char *));
|
||||
av[ac++]=tok;
|
||||
while((av[ac++]=strtok(NULL,sep))!=NULL)
|
||||
continue;
|
||||
switch((pid=fork())) {
|
||||
case 0:
|
||||
if(shell) {
|
||||
signal(SIGINT,SIG_DFL);
|
||||
signal(SIGQUIT,SIG_DFL);
|
||||
signal(SIGTERM,SIG_DFL);
|
||||
signal(SIGHUP,SIG_DFL);
|
||||
} else {
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
f=open(_PATH_CONSOLE,O_RDWR);
|
||||
dup2(f,0);
|
||||
dup2(f,1);
|
||||
dup2(f,2);
|
||||
if(f>2) close(f);
|
||||
}
|
||||
if(bg) {
|
||||
if(daemon(0,0)) {
|
||||
printf("do_command(%s): failed to run bg: %s\n",
|
||||
av[0],strerror(errno));
|
||||
_exit(100);
|
||||
}
|
||||
}
|
||||
execvp(av[0],av);
|
||||
/* Something went wrong... */
|
||||
printf("do_command(%s): %s\n",av[0],strerror(errno));
|
||||
_exit(100);
|
||||
break;
|
||||
case -1:
|
||||
printf("do_command(): %s\n",strerror(errno));
|
||||
break;
|
||||
default:
|
||||
while(waitpid(pid,&res,0)!=pid) continue;
|
||||
if(WEXITSTATUS(res)) {
|
||||
printf("do_command(%s): exit code=%d\n",
|
||||
av[0],WEXITSTATUS(res));
|
||||
}
|
||||
break;
|
||||
}
|
||||
free(av);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the user interface. This routine gets executed on each
|
||||
* virtual console serviced by init.
|
||||
*
|
||||
* It works as normal shell does - for each external command it forks
|
||||
* and execs, for each internal command just executes a function.
|
||||
*/
|
||||
|
||||
int
|
||||
shell(int argc, char **argv)
|
||||
{
|
||||
char buf[BUFSIZE];
|
||||
char *prompt=" # ";
|
||||
int fd;
|
||||
int res;
|
||||
pid_t mypid;
|
||||
|
||||
if(motd!=NULL) {
|
||||
if((fd=open(motd,O_RDONLY))!=-1) {
|
||||
do {
|
||||
res=read(fd,buf,BUFSIZE);
|
||||
res=write(1,buf,res);
|
||||
} while(res>0);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n\n+=========================================================+\n");
|
||||
printf("| Built-in shell() (enter '?' for short help on commands) |\n");
|
||||
printf("+=========================================================+\n\n");
|
||||
getcwd(cwd,BUFSIZE);
|
||||
mypid=getpid();
|
||||
signal(SIGINT,shell_sig);
|
||||
signal(SIGQUIT,shell_sig);
|
||||
signal(SIGTERM,shell_sig);
|
||||
while(!feof(stdin)) {
|
||||
memset(buf,0,BUFSIZE);
|
||||
printf("(%d)%s%s",mypid,cwd,prompt);
|
||||
fflush(stdout);
|
||||
if(fgets(buf,BUFSIZE-1,stdin)==NULL) continue;
|
||||
buf[strlen(buf)-1]='\0';
|
||||
if(strlen(buf)==0) continue;
|
||||
do_command(1,buf);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Stub for executing some external program on a console. This is called
|
||||
* from previously forked copy of our process, so that exec is ok.
|
||||
*/
|
||||
int
|
||||
external_cmd(int argc, char **argv)
|
||||
{
|
||||
execvp(argv[0],argv);
|
||||
}
|
||||
|
||||
/*
|
||||
* Acquire vty and properly attach ourselves to it.
|
||||
* Also, build basic environment for running user interface.
|
||||
*/
|
||||
|
||||
int
|
||||
start_session(int vty, int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
char *t;
|
||||
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
revoke(ttys[vty].tty);
|
||||
fd=open(ttys[vty].tty,O_RDWR);
|
||||
dup2(fd,0);
|
||||
dup2(fd,1);
|
||||
dup2(fd,2);
|
||||
if(fd>2) close(fd);
|
||||
login_tty(fd);
|
||||
setpgid(0,getpid());
|
||||
putenv("TERM=xterm");
|
||||
putenv("HOME=/");
|
||||
putenv("PATH=/stand:/bin:/usr/bin:/sbin:.");
|
||||
signal(SIGHUP,SIG_DFL);
|
||||
signal(SIGINT,SIG_DFL);
|
||||
signal(SIGQUIT,SIG_DFL);
|
||||
signal(SIGTERM,SIG_DFL);
|
||||
chdir("/");
|
||||
t=(char *)(rindex(ttys[vty].tty,'/')+1);
|
||||
printf("\n\n\nStarting session on %s.\n",t);
|
||||
ttys[vty].func(argc,argv);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Execute system startup script /etc/rc
|
||||
*
|
||||
* (Of course if you don't like it - I don't - you can run anything you
|
||||
* want here. Perhaps it would be useful just to read some config DB and
|
||||
* do these things ourselves, avoiding forking lots of shells and scripts.)
|
||||
*/
|
||||
|
||||
/* If OINIT_RC is defined, oinit will use it's own configuration file,
|
||||
* /etc/oinit.rc. It's format is described below. Otherwise, it will use
|
||||
* normal /etc/rc interpreted by Bourne shell.
|
||||
*/
|
||||
#ifndef OINIT_RC
|
||||
#ifndef SH_NAME
|
||||
#define SH_NAME "-sh"
|
||||
#endif
|
||||
#ifndef SH_PATH
|
||||
#define SH_PATH _PATH_BSHELL
|
||||
#endif
|
||||
#ifndef SH_ARG
|
||||
#define SH_ARG "/etc/rc"
|
||||
#endif
|
||||
void
|
||||
runcom()
|
||||
{
|
||||
char *argv[3];
|
||||
pid_t pid;
|
||||
int st;
|
||||
int fd;
|
||||
|
||||
if((pid=fork())==0) {
|
||||
/* child */
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
fd=open(_PATH_CONSOLE,O_RDWR);
|
||||
dup2(fd,0);
|
||||
dup2(fd,1);
|
||||
dup2(fd,2);
|
||||
if(fd>2) close(fd);
|
||||
argv[0]=SH_NAME;
|
||||
argv[1]=SH_ARG;
|
||||
argv[2]=0;
|
||||
execvp(SH_PATH,argv);
|
||||
printf("runcom(): %s\n",strerror(errno));
|
||||
_exit(1);
|
||||
}
|
||||
/* Wait for child to exit */
|
||||
while(pid!=waitpid(pid,(int *)0,0)) continue;
|
||||
return;
|
||||
}
|
||||
#else
|
||||
/* Alternative /etc/rc - default is /etc/oinit.rc. Its format is as follows:
|
||||
* - each empty line or line beginning with a '#' is discarded
|
||||
* - any other line must contain a keyword, or a (nonblocking) command to run.
|
||||
*
|
||||
* Thus far, the following keywords are defined:
|
||||
* ncons <number> number of virtual consoles to open
|
||||
* motd <pathname> full path to motd file
|
||||
*
|
||||
* Examples of commands to run:
|
||||
*
|
||||
* ifconfig lo0 inet 127.0.0.1 netmask 255.0.0.0
|
||||
* ifconfig ed0 inet 148.81.168.10 netmask 255.255.255.0
|
||||
* kbdcontrol -l /usr/share/syscons/my_map.kbd
|
||||
*/
|
||||
void
|
||||
runcom(char *fname)
|
||||
{
|
||||
int fd;
|
||||
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
fd=open(_PATH_CONSOLE,O_RDWR);
|
||||
dup2(fd,0);
|
||||
dup2(fd,1);
|
||||
dup2(fd,2);
|
||||
if(fd>2) close(fd);
|
||||
sourcer(fname);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
run_multi()
|
||||
{
|
||||
int i,j;
|
||||
pid_t pid;
|
||||
int found;
|
||||
|
||||
/* Run /etc/rc if not in single user */
|
||||
#ifndef OINIT_RC
|
||||
if(prevtrans==SINGLE) runcom();
|
||||
#else
|
||||
if(prevtrans==SINGLE) runcom(OINIT_RC);
|
||||
#endif
|
||||
if(transition!=MULTI) return(-1);
|
||||
|
||||
syslog(LOG_EMERG,"*** Starting multi-user mode ***");
|
||||
|
||||
/* Fork shell interface for each console */
|
||||
for(i=0;i<ncons;i++) {
|
||||
if(ttys[i].pid==0) {
|
||||
switch(pid=fork()) {
|
||||
case 0:
|
||||
start_session(i,0,NULL);
|
||||
break;
|
||||
case -1:
|
||||
printf("%s: %s\n",progname,strerror(errno));
|
||||
break;
|
||||
default:
|
||||
ttys[i].pid=pid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Initialize any other services we'll use - most probably this will
|
||||
* be a 'telnet' service (some day...).
|
||||
*/
|
||||
/* */
|
||||
|
||||
/* Emulate multi-user */
|
||||
while(transition==MULTI) {
|
||||
/* XXX Modify this to allow for checking for the input on
|
||||
* XXX listening sockets, and forking a 'telnet' service.
|
||||
*/
|
||||
/* */
|
||||
|
||||
/* Wait for any process to exit */
|
||||
pid=waitpid(-1,(int *)0,0);
|
||||
if(pid==-1) continue;
|
||||
found=0;
|
||||
j=-1;
|
||||
/* search if it's one of our sessions */
|
||||
for(i=0;i<ncons;i++) {
|
||||
if(ttys[i].pid==pid) {
|
||||
found++;
|
||||
j=i;
|
||||
ttys[j].pid=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found) {
|
||||
/* Just collect the process's status */
|
||||
continue;
|
||||
} else {
|
||||
/* restart shell() on a console, if it died */
|
||||
if(transition!=MULTI) return(0);
|
||||
switch(pid=fork()) {
|
||||
case 0:
|
||||
sleep(1);
|
||||
start_session(j,0,NULL);
|
||||
break;
|
||||
case -1:
|
||||
printf("%s: %s\n",progname,strerror(errno));
|
||||
break;
|
||||
default:
|
||||
ttys[j].pid=pid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int clang;
|
||||
|
||||
void
|
||||
kill_timer(int sig)
|
||||
{
|
||||
clang=1;
|
||||
}
|
||||
|
||||
kill_ttys()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Start a shell on ttyv0 (i.e. the console).
|
||||
*/
|
||||
|
||||
int
|
||||
run_single()
|
||||
{
|
||||
int i;
|
||||
pid_t pid,wpid;
|
||||
static int sigs[2]={SIGTERM,SIGKILL};
|
||||
|
||||
syslog(LOG_EMERG,"*** Starting single-user mode ***");
|
||||
/* Kill all existing sessions */
|
||||
syslog(LOG_EMERG,"Killing all existing sessions...");
|
||||
for(i=0;i<MAX_CONS;i++) {
|
||||
kill(ttys[i].pid,SIGHUP);
|
||||
ttys[i].pid=0;
|
||||
}
|
||||
for(i=0;i<2;i++) {
|
||||
if(kill(-1,sigs[i])==-1 && errno==ESRCH) break;
|
||||
clang=0;
|
||||
alarm(10);
|
||||
do {
|
||||
pid=waitpid(-1,(int *)0,WUNTRACED);
|
||||
if(errno==EINTR) continue;
|
||||
else break;
|
||||
} while (clang==0);
|
||||
}
|
||||
if(errno!=ECHILD) {
|
||||
syslog(LOG_EMERG,"Some processes would not die; ps -axl advised");
|
||||
}
|
||||
/* Single-user */
|
||||
switch(pid=fork()) {
|
||||
case 0:
|
||||
start_session(0,0,NULL);
|
||||
break;
|
||||
case -1:
|
||||
printf("%s: %s\n",progname,strerror(errno));
|
||||
printf("The system is seriously hosed. I'm dying...\n");
|
||||
transition=DEATH;
|
||||
return(-1);
|
||||
break;
|
||||
default:
|
||||
do {
|
||||
wpid=waitpid(pid,(int *)0,WUNTRACED);
|
||||
} while(wpid!=pid && transition==SINGLE);
|
||||
if(transition!=DEATH) {
|
||||
prevtrans=transition;
|
||||
transition=MULTI;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Transition handler - installed as signal handler.
|
||||
*/
|
||||
|
||||
void
|
||||
transition_handler(int sig)
|
||||
{
|
||||
|
||||
switch(sig) {
|
||||
case SIGHUP:
|
||||
case SIGTERM:
|
||||
prevtrans=transition;
|
||||
transition=SINGLE;
|
||||
syslog(LOG_EMERG,"*** Going from %s -> %s\n",trans[prevtrans],trans[transition]);
|
||||
if(prevtrans!=transition) longjmp(machine,sig);
|
||||
break;
|
||||
case SIGINT:
|
||||
case SIGQUIT:
|
||||
prevtrans=transition;
|
||||
transition=DEATH;
|
||||
syslog(LOG_EMERG,"*** Going from %s -> %s\n",trans[prevtrans],trans[transition]);
|
||||
if(prevtrans!=transition) longjmp(machine,sig);
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_EMERG,"pid=%d sig=%s (ignored)\n",getpid(),sys_siglist[sig]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Change system state appropriately to the signals
|
||||
*/
|
||||
|
||||
int
|
||||
transition_machine()
|
||||
{
|
||||
int i;
|
||||
|
||||
while(transition!=DEATH) {
|
||||
switch(transition) {
|
||||
case MULTI:
|
||||
run_multi();
|
||||
break;
|
||||
case SINGLE:
|
||||
run_single();
|
||||
break;
|
||||
}
|
||||
}
|
||||
syslog(LOG_EMERG,"Killing all existing sessions...");
|
||||
/* Kill all sessions */
|
||||
kill(-1,SIGKILL);
|
||||
/* Be nice and wait for them */
|
||||
while(waitpid(-1,(int *)0,WNOHANG|WUNTRACED)>0) continue;
|
||||
unmount("/",0);
|
||||
reboot(RB_AUTOBOOT);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int devfs=0,c,i;
|
||||
|
||||
/* These are copied from real init(8) */
|
||||
if(getuid()!=0)
|
||||
errx(1,"%s",strerror(EPERM));
|
||||
openlog("init",LOG_CONS|LOG_ODELAY,LOG_AUTH);
|
||||
if(setsid()<0)
|
||||
warn("initial setsid() failed");
|
||||
if(setlogin("root")<0)
|
||||
warn("setlogin() failed");
|
||||
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
chdir("/");
|
||||
|
||||
progname=rindex(argv[0],'/');
|
||||
if(progname==NULL) {
|
||||
progname=argv[0];
|
||||
} else progname++;
|
||||
|
||||
transition=MULTI;
|
||||
|
||||
/* We must recognize the same options as real init does */
|
||||
while((c=getopt(argc,argv,"dsf"))!=-1) {
|
||||
switch(c) {
|
||||
case 'd':
|
||||
devfs=1;
|
||||
break;
|
||||
case 's':
|
||||
transition=SINGLE;
|
||||
break;
|
||||
case 'f':
|
||||
break;
|
||||
default:
|
||||
printf("%s: unrecognized flag '-%c'\n",progname,c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(devfs)
|
||||
mount("devfs",_PATH_DEV,MNT_NOEXEC|MNT_RDONLY,0);
|
||||
|
||||
/* Fill in the sess structures. */
|
||||
/* XXX Really, should be filled based upon config file. */
|
||||
for(i=0;i<MAX_CONS;i++) {
|
||||
if(i==0) {
|
||||
sprintf(ttys[i].tty,_PATH_CONSOLE);
|
||||
} else {
|
||||
sprintf(ttys[i].tty,"%sv%c",_PATH_TTY,vty[i]);
|
||||
}
|
||||
ttys[i].pid=0;
|
||||
ttys[i].func=shell;
|
||||
}
|
||||
|
||||
getcwd(cwd,BUFSIZE);
|
||||
|
||||
signal(SIGINT,transition_handler);
|
||||
signal(SIGQUIT,transition_handler);
|
||||
signal(SIGTERM,transition_handler);
|
||||
signal(SIGHUP,transition_handler);
|
||||
signal(SIGALRM,kill_timer);
|
||||
|
||||
setjmp(machine);
|
||||
transition_machine(transition);
|
||||
/* NOTREACHED */
|
||||
exit(100);
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
# From: @(#)Makefile 8.3 (Berkeley) 4/2/94
|
||||
# $FreeBSD$
|
||||
|
||||
# Only NO_PAM is used by PicoBSD and supported here
|
||||
|
||||
|
||||
PROG= passwd
|
||||
SRCS= local_passwd.c passwd.c pw_copy.c pw_util.c
|
||||
|
||||
GENSRCS=yp.h yp_clnt.c yppasswd.h yppasswd_clnt.c \
|
||||
yppasswd_private.h yppasswd_private_clnt.c yppasswd_private_xdr.c
|
||||
CFLAGS+=-Wall
|
||||
|
||||
LIBADD= crypt util
|
||||
.PATH: ${.CURDIR}/../../../../usr.bin/chpass \
|
||||
# ${.CURDIR}/../../../../usr.sbin/vipw \
|
||||
# ${.CURDIR}/../../../../usr.bin/passwd
|
||||
|
||||
CFLAGS+= -DLOGIN_CAP -DCRYPT -I. -I${.CURDIR} \
|
||||
# -I${.CURDIR}/../../../../usr.bin/passwd \
|
||||
# -I${.CURDIR}/../../../../usr.sbin/vipw \
|
||||
# -I${.CURDIR}/../../../../usr.bin/chpass \
|
||||
# -I${.CURDIR}/../../../../lib/libc/gen \
|
||||
# -Dyp_error=warnx -DLOGGING
|
||||
|
||||
CLEANFILES= ${GENSRCS}
|
||||
|
||||
RPCGEN= RPCGEN_CPP=${CPP:Q} rpcgen -C
|
||||
RPCSRC= ${DESTDIR}/usr/include/rpcsvc/yp.x
|
||||
RPCSRC_PW= ${DESTDIR}/usr/include/rpcsvc/yppasswd.x
|
||||
RPCSRC_PRIV= ${.CURDIR}/../../usr.sbin/rpc.yppasswdd/yppasswd_private.x
|
||||
|
||||
yp.h: ${RPCSRC}
|
||||
${RPCGEN} -h -o ${.TARGET} ${RPCSRC}
|
||||
|
||||
yp_clnt.c: ${RPCSRC} yp.h
|
||||
${RPCGEN} -l -o ${.TARGET} ${RPCSRC}
|
||||
|
||||
yppasswd.h: ${RPCSRC_PW}
|
||||
${RPCGEN} -h -o ${.TARGET} ${RPCSRC_PW}
|
||||
|
||||
yppasswd_clnt.c: ${RPCSRC_PW}
|
||||
${RPCGEN} -l -o ${.TARGET} ${RPCSRC_PW}
|
||||
|
||||
yppasswd_private.h: ${RPCSRC_PRIV}
|
||||
${RPCGEN} -h -o ${.TARGET} ${RPCSRC_PRIV}
|
||||
|
||||
yppasswd_private_xdr.c: ${RPCSRC_PRIV}
|
||||
${RPCGEN} -c -o ${.TARGET} ${RPCSRC_PRIV}
|
||||
|
||||
yppasswd_private_clnt.c: ${RPCSRC_PRIV}
|
||||
${RPCGEN} -l -o ${.TARGET} ${RPCSRC_PRIV}
|
||||
|
||||
BINOWN= root
|
||||
BINMODE=4555
|
||||
LINKS=${BINDIR}/passwd ${BINDIR}/yppasswd
|
||||
MLINKS=passwd.1 yppasswd.1
|
||||
|
||||
beforeinstall:
|
||||
.for i in passwd yppasswd
|
||||
[ ! -e ${DESTDIR}${BINDIR}/$i ] || \
|
||||
chflags noschg ${DESTDIR}${BINDIR}/$i || true
|
||||
.endfor
|
||||
|
||||
afterinstall:
|
||||
-chflags schg ${DESTDIR}${BINDIR}/passwd
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,40 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
*
|
||||
* Copyright (c) 1994
|
||||
* 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.
|
||||
*
|
||||
* From: @(#)extern.h 8.1 (Berkeley) 4/2/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
int krb_passwd(char *, char *, char *, char *);
|
||||
int local_passwd(char *);
|
@ -1,239 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
*
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char sccsid[] = "@(#)local_passwd.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <pw_util.h>
|
||||
#ifdef YP
|
||||
#include <pw_yp.h>
|
||||
#endif
|
||||
|
||||
#ifdef LOGGING
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
|
||||
#ifdef LOGIN_CAP
|
||||
#ifdef AUTH_NONE /* multiple defs :-( */
|
||||
#undef AUTH_NONE
|
||||
#endif
|
||||
#include <login_cap.h>
|
||||
#endif
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
static uid_t uid;
|
||||
int randinit;
|
||||
|
||||
extern void
|
||||
pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw);
|
||||
|
||||
char *tempname;
|
||||
|
||||
static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */
|
||||
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
void
|
||||
to64(s, v, n)
|
||||
char *s;
|
||||
long v;
|
||||
int n;
|
||||
{
|
||||
while (--n >= 0) {
|
||||
*s++ = itoa64[v&0x3f];
|
||||
v >>= 6;
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
getnewpasswd(pw, nis)
|
||||
struct passwd *pw;
|
||||
int nis;
|
||||
{
|
||||
int tries, min_length = 6;
|
||||
int force_mix_case = 1;
|
||||
char *p, *t;
|
||||
#ifdef LOGIN_CAP
|
||||
login_cap_t * lc;
|
||||
#endif
|
||||
char buf[_PASSWORD_LEN+1], salt[32];
|
||||
struct timeval tv;
|
||||
|
||||
if (!nis)
|
||||
(void)printf("Changing local password for %s.\n", pw->pw_name);
|
||||
|
||||
if (uid && pw->pw_passwd[0] &&
|
||||
strcmp(crypt(getpass("Old password:"), pw->pw_passwd),
|
||||
pw->pw_passwd)) {
|
||||
errno = EACCES;
|
||||
pw_error(NULL, 1, 1);
|
||||
}
|
||||
|
||||
#ifdef LOGIN_CAP
|
||||
/*
|
||||
* Determine minimum password length, next password change date,
|
||||
* and whether or not to force mixed case passwords.
|
||||
* Note that even for NIS passwords, login_cap is still used.
|
||||
*/
|
||||
if ((lc = login_getpwclass(pw)) != NULL) {
|
||||
time_t period;
|
||||
|
||||
/* minpasswordlen capablity */
|
||||
min_length = (int)login_getcapnum(lc, "minpasswordlen",
|
||||
min_length, min_length);
|
||||
/* passwordtime capability */
|
||||
period = login_getcaptime(lc, "passwordtime", 0, 0);
|
||||
if (period > (time_t)0) {
|
||||
pw->pw_change = time(NULL) + period;
|
||||
}
|
||||
/* mixpasswordcase capability */
|
||||
force_mix_case = login_getcapbool(lc, "mixpasswordcase", 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (buf[0] = '\0', tries = 0;;) {
|
||||
p = getpass("New password:");
|
||||
if (!*p) {
|
||||
(void)printf("Password unchanged.\n");
|
||||
pw_error(NULL, 0, 0);
|
||||
}
|
||||
if (strlen(p) < min_length && (uid != 0 || ++tries < 2)) {
|
||||
(void)printf("Please enter a password at least %d characters in length.\n", min_length);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (force_mix_case) {
|
||||
for (t = p; *t && islower(*t); ++t);
|
||||
if (!*t && (uid != 0 || ++tries < 2)) {
|
||||
(void)printf("Please don't use an all-lower case password.\nUnusual capitalization, control characters or digits are suggested.\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
(void)strcpy(buf, p);
|
||||
if (!strcmp(buf, getpass("Retype new password:")))
|
||||
break;
|
||||
(void)printf("Mismatch; try again, EOF to quit.\n");
|
||||
}
|
||||
/* grab a random printable character that isn't a colon */
|
||||
if (!randinit) {
|
||||
randinit = 1;
|
||||
srandomdev();
|
||||
}
|
||||
#ifdef NEWSALT
|
||||
salt[0] = _PASSWORD_EFMT1;
|
||||
to64(&salt[1], (long)(29 * 25), 4);
|
||||
to64(&salt[5], random(), 4);
|
||||
salt[9] = '\0';
|
||||
#else
|
||||
/* Make a good size salt for algorithms that can use it. */
|
||||
gettimeofday(&tv,0);
|
||||
#ifdef LOGIN_CAP
|
||||
if (login_setcryptfmt(lc, "md5", NULL) == NULL)
|
||||
pw_error("cannot set password cipher", 1, 1);
|
||||
login_close(lc);
|
||||
#else
|
||||
(void)crypt_set_format("md5");
|
||||
#endif
|
||||
/* Salt suitable for anything */
|
||||
to64(&salt[0], random(), 3);
|
||||
to64(&salt[3], tv.tv_usec, 3);
|
||||
to64(&salt[6], tv.tv_sec, 2);
|
||||
to64(&salt[8], random(), 5);
|
||||
to64(&salt[13], random(), 5);
|
||||
to64(&salt[17], random(), 5);
|
||||
to64(&salt[22], random(), 5);
|
||||
salt[27] = '\0';
|
||||
#endif
|
||||
return (crypt(buf, salt));
|
||||
}
|
||||
|
||||
int
|
||||
local_passwd(uname)
|
||||
char *uname;
|
||||
{
|
||||
struct passwd *pw;
|
||||
int pfd, tfd;
|
||||
|
||||
if (!(pw = getpwnam(uname)))
|
||||
errx(1, "unknown user %s", uname);
|
||||
|
||||
#ifdef YP
|
||||
/* Use the right password information. */
|
||||
pw = (struct passwd *)&local_password;
|
||||
#endif
|
||||
uid = getuid();
|
||||
if (uid && uid != pw->pw_uid)
|
||||
errx(1, "%s", strerror(EACCES));
|
||||
|
||||
pw_init();
|
||||
|
||||
/*
|
||||
* Get the new password. Reset passwd change time to zero by
|
||||
* default. If the user has a valid login class (or the default
|
||||
* fallback exists), then the next password change date is set
|
||||
* by getnewpasswd() according to the "passwordtime" capability
|
||||
* if one has been specified.
|
||||
*/
|
||||
pw->pw_change = 0;
|
||||
pw->pw_passwd = getnewpasswd(pw, 0);
|
||||
|
||||
pfd = pw_lock();
|
||||
tfd = pw_tmp();
|
||||
pw_copy(pfd, tfd, pw, NULL);
|
||||
|
||||
if (!pw_mkdb(uname))
|
||||
pw_error((char *)NULL, 0, 1);
|
||||
#ifdef LOGGING
|
||||
syslog(LOG_DEBUG, "user %s changed their local password\n", uname);
|
||||
#endif
|
||||
return (0);
|
||||
}
|
@ -1,195 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
*
|
||||
* Copyright (c) 1988, 1993, 1994
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1988, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)passwd.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <libutil.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef YP
|
||||
#include <pwd.h>
|
||||
#include <pw_yp.h>
|
||||
#include <rpcsvc/yp.h>
|
||||
int __use_yp = 0;
|
||||
int yp_errno = YP_TRUE;
|
||||
extern int yp_passwd( char * );
|
||||
#endif
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
static void usage(void);
|
||||
|
||||
int use_local_passwd = 0;
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int ch;
|
||||
char *uname;
|
||||
|
||||
#ifdef YP
|
||||
#define OPTIONS "d:h:lysfo"
|
||||
#else
|
||||
#define OPTIONS "l"
|
||||
#endif
|
||||
|
||||
#ifdef YP
|
||||
int res = 0;
|
||||
|
||||
if (strstr(argv[0], "yppasswd")) __use_yp = 1;
|
||||
#endif
|
||||
|
||||
while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
|
||||
switch (ch) {
|
||||
case 'l': /* change local password file */
|
||||
use_local_passwd = 1;
|
||||
break;
|
||||
#ifdef YP
|
||||
case 'y': /* Change NIS password */
|
||||
__use_yp = 1;
|
||||
break;
|
||||
case 'd': /* Specify NIS domain. */
|
||||
#ifdef PARANOID
|
||||
if (!getuid()) {
|
||||
#endif
|
||||
yp_domain = optarg;
|
||||
if (yp_server == NULL)
|
||||
yp_server = "localhost";
|
||||
#ifdef PARANOID
|
||||
} else {
|
||||
warnx("only the super-user may use the -d flag");
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case 'h': /* Specify NIS server. */
|
||||
#ifdef PARANOID
|
||||
if (!getuid()) {
|
||||
#endif
|
||||
yp_server = optarg;
|
||||
#ifdef PARANOID
|
||||
} else {
|
||||
warnx("only the super-user may use the -h flag");
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case 'o':
|
||||
force_old++;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
case '?':
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if ((uname = getlogin()) == NULL)
|
||||
err(1, "getlogin");
|
||||
|
||||
switch(argc) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
uname = argv[0];
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
#ifdef YP
|
||||
/*
|
||||
* If NIS is turned on in the password database, use it, else punt.
|
||||
*/
|
||||
res = use_yp(uname, 0, 0);
|
||||
if (res == USER_YP_ONLY) {
|
||||
if (!use_local_passwd) {
|
||||
exit(yp_passwd(uname));
|
||||
} else {
|
||||
/*
|
||||
* Reject -l flag if NIS is turned on and the user
|
||||
* doesn't exist in the local password database.
|
||||
*/
|
||||
errx(1, "unknown local user: %s", uname);
|
||||
}
|
||||
} else if (res == USER_LOCAL_ONLY) {
|
||||
/*
|
||||
* Reject -y flag if user only exists locally.
|
||||
*/
|
||||
if (__use_yp)
|
||||
errx(1, "unknown NIS user: %s", uname);
|
||||
} else if (res == USER_YP_AND_LOCAL) {
|
||||
if (!use_local_passwd && (yp_in_pw_file || __use_yp))
|
||||
exit(yp_passwd(uname));
|
||||
}
|
||||
#endif
|
||||
|
||||
exit(local_passwd(uname));
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
|
||||
#ifdef YP
|
||||
(void)fprintf(stderr,
|
||||
"usage: passwd [-l] [-y] [-o] [-d domain [-h host]] [user]\n");
|
||||
#else
|
||||
(void)fprintf(stderr, "usage: passwd [-l] user\n");
|
||||
#endif
|
||||
exit(1);
|
||||
}
|
@ -1,306 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
*
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char sccsid[] = "@(#)pw_copy.c 8.4 (Berkeley) 4/2/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* This module is used to copy the master password file, replacing a single
|
||||
* record, by chpass(1) and passwd(1).
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if 0
|
||||
#include <pw_scan.h>
|
||||
#endif
|
||||
extern int pw_big_ids_warning;
|
||||
extern int pw_scan(char *, struct passwd *);
|
||||
|
||||
#include <pw_util.h>
|
||||
|
||||
extern char *tempname;
|
||||
|
||||
/* for use in pw_copy(). Compare a pw entry to a pw struct. */
|
||||
static int
|
||||
pw_equal(char *buf, struct passwd *pw)
|
||||
{
|
||||
struct passwd buf_pw;
|
||||
int len;
|
||||
|
||||
len = strlen (buf);
|
||||
if (buf[len-1] == '\n')
|
||||
buf[len-1] = '\0';
|
||||
return (strcmp(pw->pw_name, buf_pw.pw_name) == 0
|
||||
&& pw->pw_uid == buf_pw.pw_uid
|
||||
&& pw->pw_gid == buf_pw.pw_gid
|
||||
&& strcmp(pw->pw_class, buf_pw.pw_class) == 0
|
||||
&& (long)pw->pw_change == (long)buf_pw.pw_change
|
||||
&& (long)pw->pw_expire == (long)buf_pw.pw_expire
|
||||
&& strcmp(pw->pw_gecos, buf_pw.pw_gecos) == 0
|
||||
&& strcmp(pw->pw_dir, buf_pw.pw_dir) == 0
|
||||
&& strcmp(pw->pw_shell, buf_pw.pw_shell) == 0);
|
||||
}
|
||||
|
||||
void
|
||||
pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
|
||||
{
|
||||
FILE *from, *to;
|
||||
int done;
|
||||
char *p, buf[8192];
|
||||
char uidstr[20];
|
||||
char gidstr[20];
|
||||
char chgstr[20];
|
||||
char expstr[20];
|
||||
|
||||
snprintf(uidstr, sizeof(uidstr), "%lu", (unsigned long)pw->pw_uid);
|
||||
snprintf(gidstr, sizeof(gidstr), "%lu", (unsigned long)pw->pw_gid);
|
||||
snprintf(chgstr, sizeof(chgstr), "%ld", (long)pw->pw_change);
|
||||
snprintf(expstr, sizeof(expstr), "%ld", (long)pw->pw_expire);
|
||||
|
||||
if (!(from = fdopen(ffd, "r")))
|
||||
pw_error(_PATH_MASTERPASSWD, 1, 1);
|
||||
if (!(to = fdopen(tfd, "w")))
|
||||
pw_error(tempname, 1, 1);
|
||||
|
||||
for (done = 0; fgets(buf, sizeof(buf), from);) {
|
||||
if (!strchr(buf, '\n')) {
|
||||
warnx("%s: line too long", _PATH_MASTERPASSWD);
|
||||
pw_error(NULL, 0, 1);
|
||||
}
|
||||
if (done) {
|
||||
(void)fprintf(to, "%s", buf);
|
||||
if (ferror(to))
|
||||
goto err;
|
||||
continue;
|
||||
}
|
||||
for (p = buf; *p != '\n'; p++)
|
||||
if (*p != ' ' && *p != '\t')
|
||||
break;
|
||||
if (*p == '#' || *p == '\n') {
|
||||
(void)fprintf(to, "%s", buf);
|
||||
if (ferror(to))
|
||||
goto err;
|
||||
continue;
|
||||
}
|
||||
if (!(p = strchr(buf, ':'))) {
|
||||
warnx("%s: corrupted entry", _PATH_MASTERPASSWD);
|
||||
pw_error(NULL, 0, 1);
|
||||
}
|
||||
*p = '\0';
|
||||
if (strcmp(buf, pw->pw_name)) {
|
||||
*p = ':';
|
||||
(void)fprintf(to, "%s", buf);
|
||||
if (ferror(to))
|
||||
goto err;
|
||||
continue;
|
||||
}
|
||||
*p = ':';
|
||||
if (old_pw && !pw_equal(buf, old_pw)) {
|
||||
warnx("%s: entry for %s has changed",
|
||||
_PATH_MASTERPASSWD, pw->pw_name);
|
||||
pw_error(NULL, 0, 1);
|
||||
}
|
||||
(void)fprintf(to, "%s:%s:%s:%s:%s:%s:%s:%s:%s:%s\n",
|
||||
pw->pw_name, pw->pw_passwd,
|
||||
pw->pw_fields & _PWF_UID ? uidstr : "",
|
||||
pw->pw_fields & _PWF_GID ? gidstr : "",
|
||||
pw->pw_class,
|
||||
pw->pw_fields & _PWF_CHANGE ? chgstr : "",
|
||||
pw->pw_fields & _PWF_EXPIRE ? expstr : "",
|
||||
pw->pw_gecos, pw->pw_dir, pw->pw_shell);
|
||||
done = 1;
|
||||
if (ferror(to))
|
||||
goto err;
|
||||
}
|
||||
if (!done) {
|
||||
#ifdef YP
|
||||
/* Ultra paranoid: shouldn't happen. */
|
||||
if (getuid()) {
|
||||
warnx("%s: not found in %s -- permission denied",
|
||||
pw->pw_name, _PATH_MASTERPASSWD);
|
||||
pw_error(NULL, 0, 1);
|
||||
} else
|
||||
#endif /* YP */
|
||||
(void)fprintf(to, "%s:%s:%s:%s:%s:%s:%s:%s:%s:%s\n",
|
||||
pw->pw_name, pw->pw_passwd,
|
||||
pw->pw_fields & _PWF_UID ? uidstr : "",
|
||||
pw->pw_fields & _PWF_GID ? gidstr : "",
|
||||
pw->pw_class,
|
||||
pw->pw_fields & _PWF_CHANGE ? chgstr : "",
|
||||
pw->pw_fields & _PWF_EXPIRE ? expstr : "",
|
||||
pw->pw_gecos, pw->pw_dir, pw->pw_shell);
|
||||
}
|
||||
|
||||
if (ferror(to))
|
||||
err: pw_error(NULL, 1, 1);
|
||||
(void)fclose(to);
|
||||
}
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
/*
|
||||
* Some software assumes that IDs are short. We should emit warnings
|
||||
* for id's which can not be stored in a short, but we are more liberal
|
||||
* by default, warning for IDs greater than USHRT_MAX.
|
||||
*
|
||||
* If pw_big_ids_warning is anything other than -1 on entry to pw_scan()
|
||||
* it will be set based on the existence of PW_SCAN_BIG_IDS in the
|
||||
* environment.
|
||||
*/
|
||||
int pw_big_ids_warning = -1;
|
||||
|
||||
int
|
||||
pw_scan(bp, pw)
|
||||
char *bp;
|
||||
struct passwd *pw;
|
||||
{
|
||||
uid_t id;
|
||||
int root;
|
||||
char *p, *sh;
|
||||
|
||||
if (pw_big_ids_warning == -1)
|
||||
pw_big_ids_warning = getenv("PW_SCAN_BIG_IDS") == NULL ? 1 : 0;
|
||||
|
||||
pw->pw_fields = 0;
|
||||
if (!(pw->pw_name = strsep(&bp, ":"))) /* login */
|
||||
goto fmt;
|
||||
root = !strcmp(pw->pw_name, "root");
|
||||
if(pw->pw_name[0] && (pw->pw_name[0] != '+' || pw->pw_name[1] == '\0'))
|
||||
pw->pw_fields |= _PWF_NAME;
|
||||
|
||||
if (!(pw->pw_passwd = strsep(&bp, ":"))) /* passwd */
|
||||
goto fmt;
|
||||
if(pw->pw_passwd[0]) pw->pw_fields |= _PWF_PASSWD;
|
||||
|
||||
if (!(p = strsep(&bp, ":"))) /* uid */
|
||||
goto fmt;
|
||||
if (p[0])
|
||||
pw->pw_fields |= _PWF_UID;
|
||||
else {
|
||||
if (pw->pw_name[0] != '+' && pw->pw_name[0] != '-') {
|
||||
warnx("no uid for user %s", pw->pw_name);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
id = strtoul(p, (char **)NULL, 10);
|
||||
if (errno == ERANGE) {
|
||||
warnx("%s > max uid value (%lu)", p, ULONG_MAX);
|
||||
return (0);
|
||||
}
|
||||
if (root && id) {
|
||||
warnx("root uid should be 0");
|
||||
return (0);
|
||||
}
|
||||
if (pw_big_ids_warning && id > USHRT_MAX) {
|
||||
warnx("%s > recommended max uid value (%u)", p, USHRT_MAX);
|
||||
/*return (0);*/ /* THIS SHOULD NOT BE FATAL! */
|
||||
}
|
||||
pw->pw_uid = id;
|
||||
|
||||
if (!(p = strsep(&bp, ":"))) /* gid */
|
||||
goto fmt;
|
||||
if(p[0]) pw->pw_fields |= _PWF_GID;
|
||||
id = strtoul(p, (char **)NULL, 10);
|
||||
if (errno == ERANGE) {
|
||||
warnx("%s > max gid value (%u)", p, ULONG_MAX);
|
||||
return (0);
|
||||
}
|
||||
if (pw_big_ids_warning && id > USHRT_MAX) {
|
||||
warnx("%s > recommended max gid value (%u)", p, USHRT_MAX);
|
||||
/* return (0); This should not be fatal! */
|
||||
}
|
||||
pw->pw_gid = id;
|
||||
|
||||
pw->pw_class = strsep(&bp, ":"); /* class */
|
||||
if(pw->pw_class[0]) pw->pw_fields |= _PWF_CLASS;
|
||||
|
||||
if (!(p = strsep(&bp, ":"))) /* change */
|
||||
goto fmt;
|
||||
if(p[0]) pw->pw_fields |= _PWF_CHANGE;
|
||||
pw->pw_change = atol(p);
|
||||
|
||||
if (!(p = strsep(&bp, ":"))) /* expire */
|
||||
goto fmt;
|
||||
if(p[0]) pw->pw_fields |= _PWF_EXPIRE;
|
||||
pw->pw_expire = atol(p);
|
||||
|
||||
if (!(pw->pw_gecos = strsep(&bp, ":"))) /* gecos */
|
||||
goto fmt;
|
||||
if(pw->pw_gecos[0]) pw->pw_fields |= _PWF_GECOS;
|
||||
|
||||
if (!(pw->pw_dir = strsep(&bp, ":"))) /* directory */
|
||||
goto fmt;
|
||||
if(pw->pw_dir[0]) pw->pw_fields |= _PWF_DIR;
|
||||
|
||||
if (!(pw->pw_shell = strsep(&bp, ":"))) /* shell */
|
||||
goto fmt;
|
||||
|
||||
p = pw->pw_shell;
|
||||
if (root && *p) /* empty == /bin/sh */
|
||||
for (setusershell();;) {
|
||||
if (!(sh = getusershell())) {
|
||||
warnx("warning, unknown root shell");
|
||||
break;
|
||||
}
|
||||
if (!strcmp(p, sh))
|
||||
break;
|
||||
}
|
||||
if(p[0]) pw->pw_fields |= _PWF_SHELL;
|
||||
|
||||
if ((p = strsep(&bp, ":"))) { /* too many */
|
||||
fmt: warnx("corrupted entry");
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
@ -1,260 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
*
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char sccsid[] = "@(#)pw_util.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* This file is used by all the "password" programs; vipw(8), chpass(1),
|
||||
* and passwd(1).
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pw_util.h"
|
||||
|
||||
extern char *tempname;
|
||||
static pid_t editpid = -1;
|
||||
static int lockfd;
|
||||
static char _default_editor[] = _PATH_VI;
|
||||
static char _default_mppath[] = _PATH_PWD;
|
||||
static char _default_masterpasswd[] = _PATH_MASTERPASSWD;
|
||||
char *mppath = _default_mppath;
|
||||
char *masterpasswd = _default_masterpasswd;
|
||||
|
||||
void pw_cont(int);
|
||||
|
||||
void
|
||||
pw_cont(int sig)
|
||||
{
|
||||
|
||||
if (editpid != -1)
|
||||
kill(editpid, sig);
|
||||
}
|
||||
|
||||
void
|
||||
pw_init(void)
|
||||
{
|
||||
struct rlimit rlim;
|
||||
|
||||
/* Unlimited resource limits. */
|
||||
rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
|
||||
(void)setrlimit(RLIMIT_CPU, &rlim);
|
||||
(void)setrlimit(RLIMIT_FSIZE, &rlim);
|
||||
(void)setrlimit(RLIMIT_STACK, &rlim);
|
||||
(void)setrlimit(RLIMIT_DATA, &rlim);
|
||||
(void)setrlimit(RLIMIT_RSS, &rlim);
|
||||
|
||||
/* Don't drop core (not really necessary, but GP's). */
|
||||
rlim.rlim_cur = rlim.rlim_max = 0;
|
||||
(void)setrlimit(RLIMIT_CORE, &rlim);
|
||||
|
||||
/* Turn off signals. */
|
||||
(void)signal(SIGALRM, SIG_IGN);
|
||||
(void)signal(SIGHUP, SIG_IGN);
|
||||
(void)signal(SIGINT, SIG_IGN);
|
||||
(void)signal(SIGPIPE, SIG_IGN);
|
||||
(void)signal(SIGQUIT, SIG_IGN);
|
||||
(void)signal(SIGTERM, SIG_IGN);
|
||||
(void)signal(SIGCONT, pw_cont);
|
||||
|
||||
/* Create with exact permissions. */
|
||||
(void)umask(0);
|
||||
}
|
||||
|
||||
int
|
||||
pw_lock(void)
|
||||
{
|
||||
/*
|
||||
* If the master password file doesn't exist, the system is hosed.
|
||||
* Might as well try to build one. Set the close-on-exec bit so
|
||||
* that users can't get at the encrypted passwords while editing.
|
||||
* Open should allow flock'ing the file; see 4.4BSD. XXX
|
||||
*/
|
||||
for (;;) {
|
||||
struct stat st;
|
||||
|
||||
lockfd = open(masterpasswd, O_RDONLY, 0);
|
||||
if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1)
|
||||
err(1, "%s", masterpasswd);
|
||||
if (flock(lockfd, LOCK_EX|LOCK_NB))
|
||||
errx(1, "the password db file is busy");
|
||||
|
||||
/*
|
||||
* If the password file was replaced while we were trying to
|
||||
* get the lock, our hardlink count will be 0 and we have to
|
||||
* close and retry.
|
||||
*/
|
||||
if (fstat(lockfd, &st) < 0)
|
||||
errx(1, "fstat() failed");
|
||||
if (st.st_nlink != 0)
|
||||
break;
|
||||
close(lockfd);
|
||||
lockfd = -1;
|
||||
}
|
||||
return (lockfd);
|
||||
}
|
||||
|
||||
int
|
||||
pw_tmp(void)
|
||||
{
|
||||
static char path[MAXPATHLEN];
|
||||
int fd;
|
||||
char *p;
|
||||
|
||||
strncpy(path, masterpasswd, MAXPATHLEN - 1);
|
||||
path[MAXPATHLEN] = '\0';
|
||||
|
||||
if ((p = strrchr(path, '/')))
|
||||
++p;
|
||||
else
|
||||
p = path;
|
||||
strcpy(p, "pw.XXXXXX");
|
||||
if ((fd = mkstemp(path)) == -1)
|
||||
err(1, "%s", path);
|
||||
tempname = path;
|
||||
return (fd);
|
||||
}
|
||||
|
||||
int
|
||||
pw_mkdb(const char *username)
|
||||
{
|
||||
int pstat;
|
||||
pid_t pid;
|
||||
|
||||
(void)fflush(stderr);
|
||||
if (!(pid = fork())) {
|
||||
if(!username) {
|
||||
warnx("rebuilding the database...");
|
||||
execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", "-d", mppath,
|
||||
tempname, (char *)NULL);
|
||||
} else {
|
||||
warnx("updating the database...");
|
||||
execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", "-d", mppath,
|
||||
"-u", username, tempname, (char *)NULL);
|
||||
}
|
||||
pw_error(_PATH_PWD_MKDB, 1, 1);
|
||||
}
|
||||
pid = waitpid(pid, &pstat, 0);
|
||||
if (pid == -1 || !WIFEXITED(pstat) || WEXITSTATUS(pstat) != 0)
|
||||
return (0);
|
||||
warnx("done");
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
pw_edit(int notsetuid)
|
||||
{
|
||||
int pstat;
|
||||
char *p, *editor;
|
||||
|
||||
if (!(editor = getenv("EDITOR")))
|
||||
editor = _default_editor;
|
||||
if ((p = strrchr(editor, '/')))
|
||||
++p;
|
||||
else
|
||||
p = editor;
|
||||
|
||||
if (!(editpid = fork())) {
|
||||
if (notsetuid) {
|
||||
(void)setgid(getgid());
|
||||
(void)setuid(getuid());
|
||||
}
|
||||
errno = 0;
|
||||
execlp(editor, p, tempname, (char *)NULL);
|
||||
_exit(errno);
|
||||
}
|
||||
for (;;) {
|
||||
editpid = waitpid(editpid, (int *)&pstat, WUNTRACED);
|
||||
errno = WEXITSTATUS(pstat);
|
||||
if (editpid == -1)
|
||||
pw_error(editor, 1, 1);
|
||||
else if (WIFSTOPPED(pstat))
|
||||
raise(WSTOPSIG(pstat));
|
||||
else if (WIFEXITED(pstat) && errno == 0)
|
||||
break;
|
||||
else
|
||||
pw_error(editor, 1, 1);
|
||||
}
|
||||
editpid = -1;
|
||||
}
|
||||
|
||||
void
|
||||
pw_prompt(void)
|
||||
{
|
||||
int c, first;
|
||||
|
||||
(void)printf("re-edit the password file? [y]: ");
|
||||
(void)fflush(stdout);
|
||||
first = c = getchar();
|
||||
while (c != '\n' && c != EOF)
|
||||
c = getchar();
|
||||
if (first == 'n')
|
||||
pw_error(NULL, 0, 0);
|
||||
}
|
||||
|
||||
void
|
||||
pw_error(const char *name, int error, int eval)
|
||||
{
|
||||
if (error) {
|
||||
if (name != NULL)
|
||||
warn("%s", name);
|
||||
else
|
||||
warn(NULL);
|
||||
}
|
||||
warnx("password information unchanged");
|
||||
(void)unlink(tempname);
|
||||
exit(eval);
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
*
|
||||
* Copyright (c) 1994
|
||||
* 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.
|
||||
*
|
||||
* @(#)pw_util.h 8.2 (Berkeley) 4/1/94
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
void pw_edit(int);
|
||||
void pw_error(const char *, int, int);
|
||||
void pw_init(void);
|
||||
int pw_lock(void);
|
||||
int pw_mkdb(const char *);
|
||||
void pw_prompt(void);
|
||||
int pw_tmp(void);
|
@ -1,9 +0,0 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
PROG=sps
|
||||
SRCS= sps.c
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
This is a small 'ps' replacement, which uses information available via
|
||||
sysctl(3) interface (contrary to the 'aps', which requires you to mount
|
||||
procfs(5) to be able to get exactly the same info, so I think that 'sps'
|
||||
is superior solution).
|
||||
|
||||
When I have some time, I'll add usual switches and other functions that normal
|
||||
'ps' has...
|
||||
|
||||
<abial@freebsd.org>
|
||||
|
||||
$FreeBSD$
|
@ -1,122 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Andrzej Bialecki
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Small replacement for ps(1) - uses only sysctl(3) to retrieve info
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/user.h>
|
||||
|
||||
char p_stat[] = "?iRSTZWM";
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int mib[4], i, num, len, j, plen;
|
||||
char buf[MAXPATHLEN], vty[5], pst[5], wmesg[10];
|
||||
struct kinfo_proc *ki;
|
||||
char *t;
|
||||
int ma, mi;
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC;
|
||||
mib[2] = KERN_PROC_ALL;
|
||||
if (sysctl(mib, 3, NULL, &len, NULL, 0) != 0) {
|
||||
perror("sysctl sizing");
|
||||
exit(1);
|
||||
}
|
||||
t = (char *)malloc(len);
|
||||
if (sysctl(mib, 3, t, &len, NULL, 0) != 0) {
|
||||
perror("sysctl info");
|
||||
exit(1);
|
||||
}
|
||||
mib[2] = KERN_PROC_ARGS;
|
||||
num = len / KINFO_PROC_SIZE;
|
||||
i = 0;
|
||||
printf("USERNAME PID PPID PRI NICE TTY STAT WCHAN COMMAND\n");
|
||||
while(i < num) {
|
||||
ki = (struct kinfo_proc *)(t + (num - i - 1) * KINFO_PROC_SIZE);
|
||||
mib[3] = ki->ki_pid;
|
||||
plen = MAXPATHLEN;
|
||||
if (sysctl(mib, 4, buf, &plen, NULL, 0) != 0) {
|
||||
perror("sysctl cmd info");
|
||||
exit(1);
|
||||
}
|
||||
if (plen == 0) {
|
||||
sprintf(buf, "(%s)", ki->ki_comm);
|
||||
} else {
|
||||
for (j = 0; j < plen - 1; j++) {
|
||||
if (buf[j] == '\0') buf[j] = ' ';
|
||||
}
|
||||
}
|
||||
if (strcmp(ki->ki_wmesg, "") == 0) {
|
||||
sprintf(wmesg, "-");
|
||||
} else {
|
||||
strcpy(wmesg, ki->ki_wmesg);
|
||||
}
|
||||
ma = major(ki->ki_tdev);
|
||||
mi = minor(ki->ki_tdev);
|
||||
switch(ma) {
|
||||
case 255:
|
||||
strcpy(vty, "??");
|
||||
break;
|
||||
case 12:
|
||||
if(mi != 255) {
|
||||
sprintf(vty, "v%d", mi);
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case 0:
|
||||
strcpy(vty, "con");
|
||||
break;
|
||||
case 5:
|
||||
sprintf(vty, "p%d", mi);
|
||||
break;
|
||||
}
|
||||
sprintf(pst, "%c", p_stat[ki->ki_stat]);
|
||||
printf("%8s %5u %5u %3d %4d %3s %-4s %-7s %s\n",
|
||||
ki->ki_login,
|
||||
ki->ki_pid,
|
||||
ki->ki_ppid,
|
||||
ki->ki_pri.pri_level, /* XXX check this */
|
||||
ki->ki_nice,
|
||||
vty,
|
||||
pst,
|
||||
wmesg,
|
||||
buf);
|
||||
i++;
|
||||
}
|
||||
free((void *)t);
|
||||
exit(0);
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG=view
|
||||
SRCS=view.c
|
||||
CFLAGS+=-I/usr/local/include
|
||||
LDADD+=-L/usr/local/lib -lpng -lvgl -lz -lm
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,86 +0,0 @@
|
||||
Warsaw, 1998.08.18
|
||||
|
||||
VIEW - small PNG viewer
|
||||
-----------------------
|
||||
|
||||
This program is intended to serve as a simple console viewer for PNG
|
||||
graphics. It also features some scripting abilities, which allow you to
|
||||
build simple presentation.
|
||||
|
||||
In fact, using even this initial version I was able to build a nice
|
||||
presentation of PicoBSD abilities which I used in real-life situation (you
|
||||
can see for yourself one of the presentation's screens, fbsd.png).
|
||||
|
||||
The audience was impressed :-), especially when I asked them politely what
|
||||
are requirements and cost to make that kind of presentation using M$
|
||||
products...
|
||||
|
||||
Simple Viewing
|
||||
--------------
|
||||
|
||||
Usage is as follows:
|
||||
|
||||
view [-g nnn.nnn] [-r x] filename.png
|
||||
|
||||
where
|
||||
-g nnn.nnn screen gamma (you can adjust how bright is the
|
||||
picture)
|
||||
-r x resolution:
|
||||
0 - 640x480x16
|
||||
1 - 640x200x256
|
||||
2 - 320x240x256
|
||||
|
||||
Under right mouse button you can find a simple menu, which tells you also
|
||||
the hotkeys. You can shift, rotate and zoom the picture.
|
||||
|
||||
Presentation
|
||||
------------
|
||||
|
||||
Usage is as above, but the file you give as argument is a (unix) text file
|
||||
of the following format:
|
||||
|
||||
1 VIEW SCRIPT
|
||||
2 5
|
||||
3 welcome.png
|
||||
4 /home/clipart/logo.png
|
||||
5 /home/present/title.png
|
||||
6 /home/present/outline.png
|
||||
7 /home/present/end.png
|
||||
|
||||
(of course without the line numbering or the leading space!). The line number
|
||||
1 is magic, and must be present in order to recognize the file properly.
|
||||
|
||||
The second line tells how many pictures consist the presentation. The
|
||||
following lines tell the file names containing the images themselves.
|
||||
|
||||
See the example in file picobsd.vu.
|
||||
|
||||
Command line arguments (gamma and resolution) are as above. You can also use
|
||||
the pop-up menu to adjust image parameters, as well as go forward or
|
||||
backward in the presentation.
|
||||
|
||||
Bugs, caveats, missing features
|
||||
-------------------------------
|
||||
|
||||
* there are some bugs in libvgl which require strange workarounds, and even
|
||||
then it doesn't work quite right. See the source for the 'XXX' comments...
|
||||
|
||||
* I didn't have time to add gamma adjustment to the pop-up menu. It's
|
||||
simple, though, and I leave it as an exercise for the reader :-))
|
||||
|
||||
* it would be great if someone would add GIF and jpeg support.
|
||||
|
||||
* the error checking is probably weak. A bad PNG file or script file will
|
||||
probably cause a coredump.
|
||||
|
||||
* pop-up menu facilities need more abstraction to be usable in other cases.
|
||||
|
||||
Anyway, as it is even now it's quite usable.
|
||||
|
||||
Have fun!
|
||||
|
||||
Andrzej Bialecki
|
||||
|
||||
<abial@freebsd.org>
|
||||
|
||||
$FreeBSD$
|
Binary file not shown.
Before Width: | Height: | Size: 7.2 KiB |
@ -1,9 +0,0 @@
|
||||
VIEW SCRIPT
|
||||
7
|
||||
/png/logo.png
|
||||
/png/1.png
|
||||
/png/2.png
|
||||
/png/p1.png
|
||||
/png/p2.png
|
||||
/png/p3.png
|
||||
/png/p4.png
|
@ -1,619 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Andrzej Bialecki
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Small PNG viewer with scripting abilities
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/fbio.h>
|
||||
#include <sys/consio.h>
|
||||
#include <sys/mouse.h>
|
||||
#include <vgl.h>
|
||||
#include <png.h>
|
||||
|
||||
#define NUMBER 8
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
/* Prototypes */
|
||||
int kbd_action(int x, int y, char hotkey);
|
||||
|
||||
struct action {
|
||||
int zoom;
|
||||
int rotate;
|
||||
int Xshift,Yshift;
|
||||
};
|
||||
|
||||
struct menu_item {
|
||||
char *descr;
|
||||
char hotkey;
|
||||
int (*func)(int x, int y, char hotkey);
|
||||
};
|
||||
|
||||
struct menu_item std_menu[]= {
|
||||
{"q Quit",'q',kbd_action},
|
||||
{"n Next",'n',kbd_action},
|
||||
{"p Previous",'p',kbd_action},
|
||||
{"Z Zoom in",'Z',kbd_action},
|
||||
{"z Zoom out",'z',kbd_action},
|
||||
{"r Rotate",'r',kbd_action},
|
||||
{"R Refresh",'R',kbd_action},
|
||||
{"l Left",'l',kbd_action},
|
||||
{"h Right",'h',kbd_action},
|
||||
{"j Up",'j',kbd_action},
|
||||
{"k Down",'k',kbd_action},
|
||||
{NULL,0,NULL}
|
||||
};
|
||||
|
||||
char *progname;
|
||||
VGLBitmap pic,bkg;
|
||||
struct action a;
|
||||
byte pal_red[256];
|
||||
byte pal_green[256];
|
||||
byte pal_blue[256];
|
||||
byte pal_colors;
|
||||
double screen_gamma;
|
||||
int max_screen_colors=15;
|
||||
int quit,changed;
|
||||
char **pres;
|
||||
int nimg=0;
|
||||
int auto_chg=0;
|
||||
int cur_img=0;
|
||||
char act;
|
||||
FILE *log;
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr,"\nVGL graphics viewer, 1.0 (c) Andrzej Bialecki.\n");
|
||||
fprintf(stderr,"\nUsage:\n");
|
||||
fprintf(stderr,"\t%s [-r n] [-g n.n] filename\n",progname);
|
||||
fprintf(stderr,"\nwhere:\n");
|
||||
fprintf(stderr,"\t-r n\tchoose resolution:\n");
|
||||
fprintf(stderr,"\t\t0 - 640x480x16 (default)\n");
|
||||
fprintf(stderr,"\t\t1 - 640x200x256\n");
|
||||
fprintf(stderr,"\t\t2 - 320x240x256\n");
|
||||
fprintf(stderr,"\t-g n.n\tset screen gamma (1.3 by default)\n");
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
|
||||
int
|
||||
pop_up(char *title,int x, int y)
|
||||
{
|
||||
VGLBitmap sav,clr;
|
||||
int x1,y1,width,height,i,j;
|
||||
int last_pos,cur_pos,max_item;
|
||||
char buttons;
|
||||
char *t;
|
||||
|
||||
sav.Type=VGLDisplay->Type;
|
||||
clr.Type=VGLDisplay->Type;
|
||||
width=0;
|
||||
height=0;
|
||||
max_item=0;
|
||||
i=0;
|
||||
while(std_menu[i].descr!=NULL) {
|
||||
height++;
|
||||
max_item++;
|
||||
if(strlen(std_menu[i].descr)>width) width=strlen(std_menu[i].descr);
|
||||
i++;
|
||||
}
|
||||
width=width*8+2;
|
||||
height=height*9+4+8;
|
||||
sav.Xsize=width;
|
||||
sav.Ysize=height;
|
||||
clr.Xsize=width;
|
||||
clr.Ysize=height;
|
||||
sav.Bitmap=(byte *)calloc(width*height,1);
|
||||
clr.Bitmap=(byte *)calloc(width*height,1);
|
||||
if(x>(VGLDisplay->Xsize-width)) x1=VGLDisplay->Xsize-width;
|
||||
else x1=x;
|
||||
if(y>(VGLDisplay->Ysize-height)) y1=VGLDisplay->Ysize-height;
|
||||
else y1=y;
|
||||
VGLMouseMode(VGL_MOUSEHIDE);
|
||||
VGLBitmapCopy(VGLDisplay,x1,y1,&sav,0,0,width,height);
|
||||
VGLFilledBox(VGLDisplay,x1,y1,x1+width-1,y1+height-1,pal_colors-1);
|
||||
VGLBitmapString(VGLDisplay,x1+1,y1+1,title,0,pal_colors-1,0,0);
|
||||
VGLLine(VGLDisplay,x1,y1+9,x1+width,y1+9,0);
|
||||
i=0;
|
||||
while(std_menu[i].descr!=NULL) {
|
||||
VGLBitmapString(VGLDisplay,x1+1,y1+11+i*9,std_menu[i].descr,0,pal_colors-1,0,0);
|
||||
i++;
|
||||
}
|
||||
last_pos=-1;
|
||||
VGLMouseMode(VGL_MOUSESHOW);
|
||||
do {
|
||||
pause();
|
||||
VGLMouseStatus(&x,&y,&buttons);
|
||||
cur_pos=(y-y1-11)/9;
|
||||
if((cur_pos<0)||(cur_pos>max_item-1)) {
|
||||
if(last_pos==-1) last_pos=0;
|
||||
VGLBitmapString(VGLDisplay,x1+1,y1+11+last_pos*9,std_menu[last_pos].descr,0,pal_colors-1,0,0);
|
||||
last_pos=-1;
|
||||
} else if(last_pos!=cur_pos) {
|
||||
if(last_pos==-1) last_pos=0;
|
||||
VGLBitmapString(VGLDisplay,x1+1,y1+11+last_pos*9,std_menu[last_pos].descr,0,pal_colors-1,0,0);
|
||||
VGLBitmapString(VGLDisplay,x1+1,y1+11+cur_pos*9,std_menu[cur_pos].descr,pal_colors/2+1,pal_colors-1,0,0);
|
||||
last_pos=cur_pos;
|
||||
}
|
||||
} while (buttons & MOUSE_BUTTON3DOWN);
|
||||
VGLMouseMode(VGL_MOUSEHIDE);
|
||||
/* XXX Screws up totally when r==3. Libvgl bug! */
|
||||
VGLBitmapCopy(&clr,0,0,VGLDisplay,x1,y1,width,height);
|
||||
VGLBitmapCopy(&sav,0,0,VGLDisplay,x1,y1,width,height);
|
||||
VGLMouseMode(VGL_MOUSESHOW);
|
||||
free(sav.Bitmap);
|
||||
free(clr.Bitmap);
|
||||
changed++;
|
||||
if((cur_pos>=0) && (cur_pos<max_item)) {
|
||||
std_menu[cur_pos].func(x,y,std_menu[cur_pos].hotkey);
|
||||
}
|
||||
changed++;
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
display( VGLBitmap *pic,
|
||||
byte *red,
|
||||
byte *green,
|
||||
byte *blue,
|
||||
struct action *e)
|
||||
{
|
||||
VGLBitmap target;
|
||||
int x,y,i=0,j=0;
|
||||
|
||||
VGLMouseMode(VGL_MOUSEHIDE);
|
||||
VGLRestorePalette();
|
||||
/* XXX Broken in r!=2. Libvgl bug. */
|
||||
//VGLClear(VGLDisplay,0);
|
||||
VGLBitmapCopy(&bkg,0,0,VGLDisplay,0,0,bkg.Xsize,bkg.Ysize);
|
||||
|
||||
if(e!=NULL) {
|
||||
if(e->zoom!=1 || e->rotate) {
|
||||
target.Bitmap=(byte *)calloc(pic->Xsize*pic->Ysize*e->zoom*e->zoom,1);
|
||||
if(e->rotate) {
|
||||
target.Xsize=pic->Ysize*e->zoom;
|
||||
target.Ysize=pic->Xsize*e->zoom;
|
||||
} else {
|
||||
target.Xsize=pic->Xsize*e->zoom;
|
||||
target.Ysize=pic->Ysize*e->zoom;
|
||||
}
|
||||
target.Type=pic->Type;
|
||||
for(x=0;x<pic->Xsize;x++) {
|
||||
for(y=0;y<pic->Ysize;y++) {
|
||||
for(i=0;i<e->zoom;i++) {
|
||||
for(j=0;j<e->zoom;j++) {
|
||||
if(e->rotate) {
|
||||
VGLSetXY(&target,target.Xsize-(e->zoom*y+i),e->zoom*x+j,VGLGetXY(pic,x,y));
|
||||
} else {
|
||||
VGLSetXY(&target,e->zoom*x+i,e->zoom*y+j,VGLGetXY(pic,x,y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
target.Bitmap=(byte *)calloc(pic->Xsize*pic->Ysize,sizeof(byte));
|
||||
target.Xsize=pic->Xsize;
|
||||
target.Ysize=pic->Ysize;
|
||||
target.Type=pic->Type;
|
||||
VGLBitmapCopy(pic,0,0,&target,0,0,pic->Xsize,pic->Ysize);
|
||||
}
|
||||
} else {
|
||||
target.Bitmap=(byte *)calloc(pic->Xsize*pic->Ysize,sizeof(byte));
|
||||
target.Xsize=pic->Xsize;
|
||||
target.Ysize=pic->Ysize;
|
||||
target.Type=pic->Type;
|
||||
VGLBitmapCopy(pic,0,0,&target,0,0,pic->Xsize,pic->Ysize);
|
||||
}
|
||||
VGLSetPalette(red, green, blue);
|
||||
if(e!=NULL) {
|
||||
VGLBitmapCopy(&target,0,0,VGLDisplay,e->Xshift,e->Yshift,target.Xsize,target.Ysize);
|
||||
} else {
|
||||
VGLBitmapCopy(&target,0,0,VGLDisplay,0,0,target.Xsize,target.Ysize);
|
||||
}
|
||||
VGLMouseMode(VGL_MOUSESHOW);
|
||||
free(target.Bitmap);
|
||||
}
|
||||
|
||||
int
|
||||
png_load(char *filename)
|
||||
{
|
||||
int i,j,k;
|
||||
FILE *fd;
|
||||
u_char header[NUMBER];
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr,end_info;
|
||||
png_uint_32 width,height;
|
||||
int bit_depth,color_type,interlace_type;
|
||||
int compression_type,filter_type;
|
||||
int channels,rowbytes;
|
||||
double gamma;
|
||||
png_colorp palette;
|
||||
int num_palette;
|
||||
png_bytep *row_pointers;
|
||||
char c;
|
||||
int res=0;
|
||||
|
||||
fd=fopen(filename,"rb");
|
||||
|
||||
if(fd==NULL) {
|
||||
VGLEnd();
|
||||
perror("fopen");
|
||||
exit(1);
|
||||
}
|
||||
fread(header,1,NUMBER,fd);
|
||||
if(!png_check_sig(header,NUMBER)) {
|
||||
fprintf(stderr,"Not a PNG file.\n");
|
||||
return(-1);
|
||||
}
|
||||
png_ptr=png_create_read_struct(PNG_LIBPNG_VER_STRING,(void *)NULL,
|
||||
NULL,NULL);
|
||||
info_ptr=png_create_info_struct(png_ptr);
|
||||
end_info=png_create_info_struct(png_ptr);
|
||||
if(!png_ptr || !info_ptr || !end_info) {
|
||||
VGLEnd();
|
||||
fprintf(stderr,"failed to allocate needed structs!\n");
|
||||
png_destroy_read_struct(&png_ptr,&info_ptr,&end_info);
|
||||
return(-1);
|
||||
}
|
||||
png_set_sig_bytes(png_ptr,NUMBER);
|
||||
png_init_io(png_ptr,fd);
|
||||
png_read_info(png_ptr,info_ptr);
|
||||
png_get_IHDR(png_ptr,info_ptr,&width,&height,&bit_depth,
|
||||
&color_type,&interlace_type,&compression_type,&filter_type);
|
||||
png_get_PLTE(png_ptr,info_ptr,&palette,&num_palette);
|
||||
channels=png_get_channels(png_ptr,info_ptr);
|
||||
rowbytes=png_get_rowbytes(png_ptr,info_ptr);
|
||||
if(bit_depth==16)
|
||||
png_set_strip_16(png_ptr);
|
||||
if(color_type & PNG_COLOR_MASK_ALPHA)
|
||||
png_set_strip_alpha(png_ptr);
|
||||
if(png_get_gAMA(png_ptr,info_ptr,&gamma))
|
||||
png_set_gamma(png_ptr,screen_gamma,gamma);
|
||||
else
|
||||
png_set_gamma(png_ptr,screen_gamma,0.45);
|
||||
if(res==0) {
|
||||
/* Dither */
|
||||
if(color_type & PNG_COLOR_MASK_COLOR) {
|
||||
if(png_get_valid(png_ptr,info_ptr,PNG_INFO_PLTE)) {
|
||||
png_uint_16p histogram;
|
||||
png_get_hIST(png_ptr,info_ptr,&histogram);
|
||||
png_set_dither(png_ptr,palette,num_palette,max_screen_colors,histogram,0);
|
||||
} else {
|
||||
png_color std_color_cube[16]={
|
||||
{0x00,0x00,0x00},
|
||||
{0x02,0x02,0x02},
|
||||
{0x04,0x04,0x04},
|
||||
{0x06,0x06,0x06},
|
||||
{0x08,0x08,0x08},
|
||||
{0x0a,0x0a,0x0a},
|
||||
{0x0c,0x0c,0x0c},
|
||||
{0x0e,0x0e,0x0e},
|
||||
{0x10,0x10,0x10},
|
||||
{0x12,0x12,0x12},
|
||||
{0x14,0x14,0x14},
|
||||
{0x16,0x16,0x16},
|
||||
{0x18,0x18,0x18},
|
||||
{0x1a,0x1a,0x1a},
|
||||
{0x1d,0x1d,0x1d},
|
||||
{0xff,0xff,0xff},
|
||||
};
|
||||
png_set_dither(png_ptr,std_color_cube,max_screen_colors,max_screen_colors,NULL,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
png_set_packing(png_ptr);
|
||||
if(png_get_valid(png_ptr,info_ptr,PNG_INFO_sBIT)) {
|
||||
png_color_8p sig_bit;
|
||||
|
||||
png_get_sBIT(png_ptr,info_ptr,&sig_bit);
|
||||
png_set_shift(png_ptr,sig_bit);
|
||||
}
|
||||
png_read_update_info(png_ptr,info_ptr);
|
||||
png_get_IHDR(png_ptr,info_ptr,&width,&height,&bit_depth,
|
||||
&color_type,&interlace_type,&compression_type,&filter_type);
|
||||
png_get_PLTE(png_ptr,info_ptr,&palette,&num_palette);
|
||||
channels=png_get_channels(png_ptr,info_ptr);
|
||||
rowbytes=png_get_rowbytes(png_ptr,info_ptr);
|
||||
row_pointers=malloc(height*sizeof(png_bytep));
|
||||
for(i=0;i<height;i++) {
|
||||
row_pointers[i]=malloc(rowbytes);
|
||||
}
|
||||
png_read_image(png_ptr,row_pointers);
|
||||
png_read_end(png_ptr,end_info);
|
||||
png_destroy_read_struct(&png_ptr,&info_ptr,&end_info);
|
||||
fclose(fd);
|
||||
/* Set palette */
|
||||
if(res) k=2;
|
||||
else k=2;
|
||||
for(i=0;i<256;i++) {
|
||||
pal_red[i]=255;
|
||||
pal_green[i]=255;
|
||||
pal_blue[i]=255;
|
||||
}
|
||||
for(i=0;i<num_palette;i++) {
|
||||
pal_red[i]=(palette+i)->red>>k;
|
||||
pal_green[i]=(palette+i)->green>>k;
|
||||
pal_blue[i]=(palette+i)->blue>>k;
|
||||
}
|
||||
pal_colors=num_palette;
|
||||
if(pic.Bitmap!=NULL) free(pic.Bitmap);
|
||||
pic.Bitmap=(byte *)calloc(rowbytes*height,sizeof(byte));
|
||||
pic.Type=MEMBUF;
|
||||
pic.Xsize=rowbytes;
|
||||
pic.Ysize=height;
|
||||
for(i=0;i<rowbytes;i++) {
|
||||
for(j=0;j<height;j++) {
|
||||
VGLSetXY(&pic,
|
||||
i,j,row_pointers[j][i]);
|
||||
}
|
||||
}
|
||||
a.zoom=1;
|
||||
a.Xshift=(VGLDisplay->Xsize-pic.Xsize)/2;
|
||||
a.Yshift=(VGLDisplay->Ysize-pic.Ysize)/2;
|
||||
a.rotate=0;
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
kbd_handler(int sig)
|
||||
{
|
||||
u_char buf[10];
|
||||
int res;
|
||||
|
||||
res=read(0,&buf,10);
|
||||
changed++;
|
||||
act=buf[res-1];
|
||||
}
|
||||
|
||||
int
|
||||
kbd_action(int x, int y, char key)
|
||||
{
|
||||
changed=0;
|
||||
if(key!='n') auto_chg=0;
|
||||
switch(key) {
|
||||
case 'q':
|
||||
quit=1;
|
||||
break;
|
||||
case 'Z':
|
||||
a.zoom++;
|
||||
changed++;
|
||||
break;
|
||||
case 'z':
|
||||
a.zoom--;
|
||||
if(a.zoom<1) a.zoom=1;
|
||||
changed++;
|
||||
break;
|
||||
case 'l':
|
||||
a.Xshift+=VGLDisplay->Xsize/5;
|
||||
changed++;
|
||||
break;
|
||||
case 'h':
|
||||
a.Xshift-=VGLDisplay->Xsize/5;
|
||||
changed++;
|
||||
break;
|
||||
case 'k':
|
||||
a.Yshift+=VGLDisplay->Ysize/5;
|
||||
changed++;
|
||||
break;
|
||||
case 'j':
|
||||
a.Yshift-=VGLDisplay->Ysize/5;
|
||||
changed++;
|
||||
break;
|
||||
case 'R':
|
||||
changed++;
|
||||
break;
|
||||
case 'r':
|
||||
if(a.rotate) a.rotate=0;
|
||||
else a.rotate=1;
|
||||
changed++;
|
||||
break;
|
||||
case '\n':
|
||||
case 'n':
|
||||
if(nimg>0) {
|
||||
if(cur_img<nimg-1) {
|
||||
cur_img++;
|
||||
} else {
|
||||
cur_img=0;
|
||||
}
|
||||
png_load(pres[cur_img]);
|
||||
changed++;
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
if(nimg>0) {
|
||||
if(cur_img>0) {
|
||||
cur_img--;
|
||||
} else {
|
||||
cur_img=nimg-1;
|
||||
}
|
||||
png_load(pres[cur_img]);
|
||||
changed++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
act=0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i,j,k;
|
||||
char c;
|
||||
int res=0;
|
||||
int x,y;
|
||||
char buttons;
|
||||
struct termios t_new,t_old;
|
||||
FILE *fsc;
|
||||
|
||||
char buf[100];
|
||||
|
||||
progname=argv[0];
|
||||
screen_gamma=1.5;
|
||||
#ifdef DEBUG
|
||||
log=fopen("/png/view.log","w");
|
||||
#endif
|
||||
while((c=getopt(argc,argv,"r:g:"))!=-1) {
|
||||
switch(c) {
|
||||
case 'r':
|
||||
res=atoi(optarg);
|
||||
if(res>0) max_screen_colors=256;
|
||||
break;
|
||||
case 'g':
|
||||
screen_gamma=atof(optarg);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
switch(res) {
|
||||
case 0:
|
||||
VGLInit(SW_CG640x480);
|
||||
break;
|
||||
case 1:
|
||||
VGLInit(SW_VGA_CG320);
|
||||
break;
|
||||
case 2:
|
||||
VGLInit(SW_VGA_MODEX);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"No such resolution!\n");
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(log,"VGL initialised\n");
|
||||
#endif
|
||||
VGLSavePalette();
|
||||
if(argc>optind) {
|
||||
res=png_load(argv[optind]);
|
||||
} else {
|
||||
VGLEnd();
|
||||
usage();
|
||||
exit(0);
|
||||
}
|
||||
if(res) {
|
||||
/* Hmm... Script? */
|
||||
fsc=fopen(argv[optind],"r");
|
||||
#ifdef DEBUG
|
||||
fprintf(log,"Trying script %s\n",argv[optind]);
|
||||
#endif
|
||||
fgets(buf,99,fsc);
|
||||
buf[strlen(buf)-1]='\0';
|
||||
if(strncmp("VIEW SCRIPT",buf,11)!=NULL) {
|
||||
VGLEnd();
|
||||
usage();
|
||||
}
|
||||
if(strlen(buf)>12) {
|
||||
auto_chg=atoi(buf+12);
|
||||
}
|
||||
fgets(buf,99,fsc);
|
||||
buf[strlen(buf)-1]='\0';
|
||||
nimg=atoi(buf);
|
||||
if(nimg==0) {
|
||||
VGLEnd();
|
||||
usage();
|
||||
}
|
||||
pres=(char **)calloc(nimg,sizeof(char *));
|
||||
for(i=0;i<nimg;i++) {
|
||||
fgets(buf,99,fsc);
|
||||
buf[strlen(buf)-1]='\0';
|
||||
pres[i]=strdup(buf);
|
||||
}
|
||||
fclose(fsc);
|
||||
cur_img=0;
|
||||
#ifdef DEBUG
|
||||
fprintf(log,"Script with %d entries\n",nimg);
|
||||
#endif
|
||||
png_load(pres[cur_img]);
|
||||
}
|
||||
VGLMouseInit(VGL_MOUSEHIDE);
|
||||
/* Prepare the keyboard */
|
||||
tcgetattr(0,&t_old);
|
||||
memcpy(&t_new,&t_old,sizeof(struct termios));
|
||||
cfmakeraw(&t_new);
|
||||
tcsetattr(0,TCSAFLUSH,&t_new);
|
||||
fcntl(0,F_SETFL,O_ASYNC);
|
||||
/* XXX VGLClear doesn't work.. :-(( Prepare a blank background */
|
||||
bkg.Bitmap=(byte *)calloc(VGLDisplay->Xsize*VGLDisplay->Ysize,1);
|
||||
bkg.Xsize=VGLDisplay->Xsize;
|
||||
bkg.Ysize=VGLDisplay->Ysize;
|
||||
bkg.Type=VGLDisplay->Type;
|
||||
signal(SIGIO,kbd_handler);
|
||||
a.zoom=1;
|
||||
a.Xshift=(VGLDisplay->Xsize-pic.Xsize)/2;
|
||||
a.Yshift=(VGLDisplay->Ysize-pic.Ysize)/2;
|
||||
a.rotate=0;
|
||||
quit=0;
|
||||
changed=0;
|
||||
display(&pic,pal_red,pal_green,pal_blue,&a);
|
||||
while(!quit) {
|
||||
if(act) {
|
||||
#ifdef DEBUG
|
||||
fprintf(log,"kbd_action(%c)\n",act);
|
||||
#endif
|
||||
kbd_action(x,y,act);
|
||||
}
|
||||
if(quit) break;
|
||||
if(changed) {
|
||||
#ifdef DEBUG
|
||||
fprintf(log,"changed, redisplaying\n");
|
||||
#endif
|
||||
display(&pic,pal_red,pal_green,pal_blue,&a);
|
||||
changed=0;
|
||||
}
|
||||
if(auto_chg) {
|
||||
sleep(auto_chg);
|
||||
kbd_action(x,y,'n');
|
||||
} else {
|
||||
pause();
|
||||
}
|
||||
VGLMouseStatus(&x,&y,&buttons);
|
||||
if(buttons & MOUSE_BUTTON3DOWN) {
|
||||
#ifdef DEBUG
|
||||
fprintf(log,"pop_up called\n");
|
||||
#endif
|
||||
pop_up("View",x,y);
|
||||
}
|
||||
}
|
||||
VGLEnd();
|
||||
#ifdef DEBUG
|
||||
fclose(log);
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
PROG=vm
|
||||
#CFLAGS+=
|
||||
SRCS= vm.c
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
1998.02.12
|
||||
|
||||
This is a small replacement for vmstat(8) program. It allows you to measure
|
||||
current memory utilisation. The same info is available via sysctl(8) program,
|
||||
but unfortunately this particular variable doesn't have its handler, and
|
||||
consequently it is not displayed in stock version of sysctl(8).
|
||||
|
||||
<abial@freebsd.org>
|
||||
|
||||
$FreeBSD$
|
@ -1,112 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Andrzej Bialecki
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/vmmeter.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
#define pgtok(a) ((a) * (u_int) pagesize >> 10)
|
||||
|
||||
int
|
||||
vm_i()
|
||||
{
|
||||
#define CNT 49
|
||||
int cnt[CNT];
|
||||
char names[CNT*16];
|
||||
char *a, *namep[CNT*16];
|
||||
int i,len;
|
||||
long long inttotal=0;
|
||||
long uptime=1;
|
||||
|
||||
len=sizeof(cnt);
|
||||
i = sysctlbyname("hw.intrcnt", &cnt, &len, NULL, 0);
|
||||
if (i != 0)
|
||||
return i ;
|
||||
len=sizeof(names);
|
||||
i = sysctlbyname("hw.intrnames", &names, &len, NULL, 0);
|
||||
if (i != 0)
|
||||
return i ;
|
||||
|
||||
for( i=0, a = names ; i < CNT && a < names+sizeof(names) ; ) {
|
||||
namep[i++] = a++;
|
||||
while (a < names+sizeof(names) && *a)
|
||||
a++ ;
|
||||
a++ ; /* skip \0 */
|
||||
}
|
||||
printf("interrupt total rate\n");
|
||||
inttotal = 0;
|
||||
for (i=0; i< CNT ; i++)
|
||||
if (cnt[i] >0) {
|
||||
printf("%-12s %20lu %10lu\n", namep[i], cnt[i], cnt[i]/uptime);
|
||||
inttotal += cnt[i];
|
||||
}
|
||||
printf("Total %20llu %10llu\n", inttotal,
|
||||
inttotal / (u_int64_t) uptime);
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int mib[2],i=0,len;
|
||||
int pagesize, pagesize_len;
|
||||
struct vmtotal v;
|
||||
|
||||
if (argc > 1 && !strcmp(argv[1], "-i")) {
|
||||
if (vm_i())
|
||||
fprintf(stderr, "vm -i stats not available via sysctl\n");
|
||||
return 0 ;
|
||||
}
|
||||
pagesize_len = sizeof(int);
|
||||
sysctlbyname("vm.stats.vm.v_page_size",&pagesize,&pagesize_len,NULL,0);
|
||||
|
||||
len=sizeof(struct vmtotal);
|
||||
mib[0]=CTL_VM;
|
||||
mib[1]=VM_METER;
|
||||
for(;;) {
|
||||
sysctl(mib,2,&v,&len,NULL,0);
|
||||
if(i==0) {
|
||||
printf(" procs kB virt mem real mem shared vm shared real free\n");
|
||||
printf(" r w l s tot act tot act tot act tot act\n");
|
||||
}
|
||||
printf("%2hd%2hd%2hd%2hd",v.t_rq-1,v.t_dw+v.t_pw,v.t_sl,v.t_sw);
|
||||
printf("%7d %7d %7d%7d",
|
||||
pgtok(v.t_vm),pgtok(v.t_avm),
|
||||
pgtok(v.t_rm),pgtok(v.t_arm));
|
||||
printf("%7d%7d%7d%7d%7d\n",
|
||||
pgtok(v.t_vmshr),pgtok(v.t_avmshr),
|
||||
pgtok(v.t_rmshr),pgtok(v.t_armshr),
|
||||
pgtok(v.t_free));
|
||||
sleep(5);
|
||||
i++;
|
||||
if(i>22) i=0;
|
||||
}
|
||||
exit(0);
|
||||
|
||||
}
|
@ -9,7 +9,6 @@ MAN= \
|
||||
diskless.8 \
|
||||
intro.8 \
|
||||
nanobsd.8 \
|
||||
picobsd.8 \
|
||||
rc.8 \
|
||||
rc.sendmail.8 \
|
||||
rc.subr.8 \
|
||||
|
@ -339,8 +339,7 @@ customize_cmd cust_etc_size
|
||||
.Sh SEE ALSO
|
||||
.Xr make.conf 5 ,
|
||||
.Xr boot 8 ,
|
||||
.Xr boot0cfg 8 ,
|
||||
.Xr picobsd 8
|
||||
.Xr boot0cfg 8
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
|
@ -1,666 +0,0 @@
|
||||
.\" -*- nroff-fill -*-
|
||||
.\" $FreeBSD$
|
||||
.Dd October 20, 2019
|
||||
.Dt PICOBSD 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm picobsd
|
||||
.Nd building small FreeBSD disk images
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Ar options
|
||||
.Op Ar config-name Op Ar site-name
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
is deprecated and will be removed in
|
||||
.Fx 13.0 .
|
||||
.Pp
|
||||
The
|
||||
.Nm
|
||||
utility is a script which produces a minimal implementation of
|
||||
.Fx
|
||||
(historically called
|
||||
.Nm PicoBSD )
|
||||
which typically fits on a small media such as a floppy disk,
|
||||
or can be downloaded as a
|
||||
single image file from some media such as CDROM, flash memory, or through
|
||||
etherboot.
|
||||
.Pp
|
||||
The
|
||||
.Nm
|
||||
utility was originally created to build simple standalone systems
|
||||
such as firewalls or bridges, but because of the ability to
|
||||
cross-build images with different source trees than the one
|
||||
in the server, it can be extremely useful to developers to
|
||||
test their code without having to reinstall the system.
|
||||
.Pp
|
||||
The boot media (historically a floppy disk, but also small
|
||||
CDROM or USB keys) contains a boot loader and a
|
||||
compressed kernel which includes a memory file system.
|
||||
Depending on the media, it might also contain a number of
|
||||
additional files, which can be updated at run time, and are
|
||||
used to override/update those in the memory file system.
|
||||
.Pp
|
||||
The system loads the kernel in the normal way, uncompresses
|
||||
the memory file system and mounts it as root.
|
||||
It then updates the memory
|
||||
file system with files from the boot media (if present),
|
||||
and executes a specialized version of
|
||||
.Pa /etc/rc .
|
||||
The boot media (floppy, etc.) is
|
||||
required for loading only, and typically used read-only.
|
||||
After the boot phase, the system runs entirely from RAM.
|
||||
.Pp
|
||||
The following options are available (but also check the
|
||||
.Nm
|
||||
script for more details).
|
||||
The most important options for common operations are
|
||||
.Fl src ,
|
||||
.Fl init ,
|
||||
.Fl n and
|
||||
.Fl v .
|
||||
.Bl -tag -width indent
|
||||
.\"
|
||||
.It Fl -all_in_mfs
|
||||
Put the entire contents of the file system in the
|
||||
memory file system image which is contained in the
|
||||
kernel.
|
||||
This is the default behaviour, and is
|
||||
extremely useful as the kernel itself can be loaded,
|
||||
using
|
||||
etherboot
|
||||
or
|
||||
.Xr pxeboot 8 ,
|
||||
.\"
|
||||
.It Fl c , Fl clean
|
||||
Clean the product of previous builds.
|
||||
.\"
|
||||
.It Fl -cfg Ar file
|
||||
Specify a file that contains additional config commands.
|
||||
.\"
|
||||
.It Fl -floppy_size Ar size
|
||||
Set the size of the disk image.
|
||||
Typical values for a floppy disk are 1440 or 2880,
|
||||
but other values can be used for other media (flash memories,
|
||||
CDROM, network booted kernels).
|
||||
Note that this option is overridden by the content of the
|
||||
config files (config in the image tree, or the one
|
||||
specified with
|
||||
.Fl Fl cfg )
|
||||
.\"
|
||||
.It Fl -init
|
||||
When used together with the
|
||||
.Fl -src
|
||||
option, this initializes the
|
||||
.Ao Ar SRC_PATH Ac Ns Pa /../usr
|
||||
subtree as necessary to subsequently build
|
||||
.Nm
|
||||
images.
|
||||
.\"
|
||||
.It Fl -iso
|
||||
Generate an ISO image,
|
||||
.Pa picobsd.iso ,
|
||||
in addition to the disk image
|
||||
.Pa picobsd.bin .
|
||||
.\"
|
||||
.It Fl -modules
|
||||
Also build kernel modules.
|
||||
These are not stored on the
|
||||
.Nm
|
||||
image but are left available in the build directory.
|
||||
.\"
|
||||
.It Fl n
|
||||
Make the script non-interactive, skipping the initial menu
|
||||
and proceeding with the build process without requiring user input.
|
||||
.\"
|
||||
.It Fl -no_all_in_mfs
|
||||
Leaves files contained in the
|
||||
.Pa floppy.tree
|
||||
on the
|
||||
.Nm
|
||||
image, so they can be loaded separately
|
||||
from the kernel (and updated individually to
|
||||
customize the image).
|
||||
.\"
|
||||
.It Fl -no_loader
|
||||
Omit /boot/loader, just rely on boot2 to load the kernel.
|
||||
This saves some space but may have problems with kernels > 4MB.
|
||||
.\"
|
||||
.It Fl -objdir Ar directory
|
||||
Specify a directory with the result of a previous buildworld.
|
||||
This saves the need for an
|
||||
.Fl Fl init
|
||||
call before creating an image.
|
||||
.\"
|
||||
.It Fl -src Ar SRC_PATH
|
||||
Use the source tree at
|
||||
.Ar SRC_PATH
|
||||
instead the one at
|
||||
.Pa /usr/src .
|
||||
This can be useful for cross-building
|
||||
.Nm
|
||||
images.
|
||||
When using this option, you must also create and initialize the subtree at
|
||||
.Ao Ar SRC_PATH Ac Ns Pa /../usr
|
||||
with the correct header files, libraries, and tools (such as the
|
||||
.Xr config 8
|
||||
program) that are necessary for the cross-build (see the
|
||||
.Fl -init
|
||||
option).
|
||||
The source files are unmodified by the
|
||||
.Nm
|
||||
script.
|
||||
However the source tree is not completely read-only,
|
||||
because
|
||||
.Xr config 8
|
||||
expects the kernel configuration file to be in one of
|
||||
its subdirectories, and also the process of initializing the
|
||||
.Pa usr
|
||||
subtree touches some parts of the source tree (this is a bug
|
||||
in the release build scripts which might go away with time).
|
||||
.\"
|
||||
.It Fl v
|
||||
Make the script verbose, showing
|
||||
commands to be executed and waiting for user
|
||||
input before executing each of them.
|
||||
Useful for debugging.
|
||||
as a fully functional system.
|
||||
.El
|
||||
.Sh ENVIRONMENT
|
||||
As a result of extreme size limitations, the
|
||||
.Nm
|
||||
environment differs from the normal
|
||||
.Fx
|
||||
in a number of ways:
|
||||
.Bl -bullet
|
||||
.It
|
||||
There are no dynamic libraries, and there is no directory
|
||||
.Pa /usr/lib .
|
||||
As a result, only static executables may be executed.
|
||||
.It
|
||||
In order to reduce the size of the executables, all executables on a specific
|
||||
floppy are joined together as a single executable built with
|
||||
.Xr crunchgen 1 .
|
||||
.It
|
||||
Some programs are supplied in minimalistic versions, specifically
|
||||
.Nm ns ,
|
||||
a cut-down version of
|
||||
.Xr netstat 1 ,
|
||||
and
|
||||
.Nm vm ,
|
||||
a cut-down version of
|
||||
.Xr vmstat 8 .
|
||||
.El
|
||||
.Sh BUILDING PicoBSD
|
||||
The
|
||||
.Nm
|
||||
sources reside in the hierarchy
|
||||
.Pa /usr/src/release/picobsd .
|
||||
In the following discussion, all relative path names are relative to this
|
||||
directory.
|
||||
.Pp
|
||||
The supported build script is
|
||||
.Pa /usr/src/release/picobsd/build/picobsd
|
||||
which can be run from anywhere, and relies on the
|
||||
.Xr sysutils/makefs
|
||||
port to build a filesystem without requiring
|
||||
.Xr mdconfig
|
||||
or root privileges to mount a filesystem.
|
||||
When run in interactive mode (the default without the
|
||||
.Fl n
|
||||
option), the script will let you configure the various parameters
|
||||
used to build the PicoBSD image.
|
||||
An image is configured
|
||||
using the files and directories described below.
|
||||
The base system contains a template, called
|
||||
.Pa bridge
|
||||
for historical reasons,
|
||||
that can be used as a base for building various kinds
|
||||
of network appliances.
|
||||
.Pp
|
||||
You can define your own PicoBSD configuration, by creating a directory
|
||||
with a name of your choice (e.g.\&
|
||||
.Pa FOO )
|
||||
which contains
|
||||
some of the following files and directories.
|
||||
For more
|
||||
information on how to construct these files, look at one
|
||||
of the standard
|
||||
.Nm
|
||||
configurations as a reference.
|
||||
.Bl -tag -width indent
|
||||
.It Pa PICOBSD
|
||||
The kernel configuration file (required).
|
||||
This is a mostly standard
|
||||
kernel configuration file, possibly stripped down by removing
|
||||
unnecessary drivers and options to reduce the kernel's size.
|
||||
.Pp
|
||||
To be recognised as a
|
||||
.Nm
|
||||
kernel config file, the file must also contain the line
|
||||
beginning with
|
||||
.Dq Li #PicoBSD
|
||||
below, and a matching
|
||||
.Dv MD_ROOT_SIZE
|
||||
option:
|
||||
.Bd -literal -offset indent
|
||||
#marker def_sz init MFS_inodes floppy_inodes
|
||||
#PicoBSD 4200 init 8192 32768
|
||||
options MD_ROOT_SIZE=4200 # same as def_sz
|
||||
.Ed
|
||||
.Pp
|
||||
This informs the script of the size of the memory file system and
|
||||
provides a few other details on how to build the image.
|
||||
.It Pa crunch.conf
|
||||
.Xr crunchgen 1
|
||||
configuration (required).
|
||||
It contains the list of directories containing program sources,
|
||||
the list of binaries to be built, and the list of libraries that
|
||||
these programs use.
|
||||
See the
|
||||
.Xr crunchgen 1
|
||||
manpage for the exact details on the syntax of this file.
|
||||
.Pp
|
||||
The following issues are particularly important when dealing
|
||||
with
|
||||
.Nm
|
||||
configurations:
|
||||
.Bl -bullet
|
||||
.It
|
||||
We can pass build options to those makefiles which understand
|
||||
that, in order to reduce the size of the programs.
|
||||
This is achieved with a line of the form
|
||||
.Pp
|
||||
.Dl "buildopts -DNO_PAM ..."
|
||||
.It
|
||||
When providing the list of directories where source files are, it
|
||||
is convenient to list the following entry first:
|
||||
.Pp
|
||||
.Dl "srcdirs /usr/src/release/picobsd/tinyware"
|
||||
.Pp
|
||||
so that
|
||||
.Nm Ns -specific
|
||||
versions of the programs will be found there.
|
||||
.It
|
||||
The string
|
||||
.Dq Li @__CWD__@
|
||||
is replaced with the full pathname of the directory where the
|
||||
.Nm
|
||||
configuration resides (i.e., the one where we find
|
||||
.Pa PICOBSD , crunch.conf ,
|
||||
and so on).
|
||||
This can be useful to refer source code that resides within a
|
||||
configuration, e.g.\&
|
||||
.Pp
|
||||
.Dl "srcdirs @__CWD__@/src"
|
||||
.El
|
||||
.It Pa config
|
||||
Shell variables, sourced by the
|
||||
.Nm
|
||||
script (optional).
|
||||
The most important variables here are:
|
||||
.Bl -tag -width ".Va MY_DEVS"
|
||||
.It Va MY_DEVS
|
||||
(Not used in
|
||||
.Fx 5.0
|
||||
where we have
|
||||
.Xr devfs 5 ) .
|
||||
Should be set to the list of devices to be created in the
|
||||
.Pa /dev
|
||||
directory of the image (it is really the argument passed to
|
||||
.Xr MAKEDEV 8 ,
|
||||
so refer to that manpage for the names).
|
||||
.It Va fd_size
|
||||
Size (in kilobytes) of the
|
||||
.Nm
|
||||
image.
|
||||
By default,
|
||||
.Va fd_size
|
||||
is set to 1440
|
||||
which produces an image suitable for a standard floppy.
|
||||
.Pp
|
||||
If you plan to store the image on a CDROM (e.g.\& using
|
||||
the
|
||||
.Dq "El Torito"
|
||||
floppy emulation), you can set
|
||||
.Va fd_size
|
||||
equal to 2880.
|
||||
If you are planning to dump the image onto a hard disk
|
||||
(either in a partition or on the whole disk), you
|
||||
are not restricted to one of the standard floppy sizes.
|
||||
Using a large image size per se does not waste RAM at runtime,
|
||||
because only the files that are actually loaded from the image
|
||||
contribute to the memory usage.
|
||||
.It Va import_files
|
||||
Contains a list of files to be imported in the floppy tree.
|
||||
Absolute names refer to the standard file system, relative
|
||||
names refer to the root of the source tree being used
|
||||
(i.e.\&
|
||||
.Va SRC_PATH/.. ) .
|
||||
You can normally use this option if you want to import
|
||||
files such as shared libraries, or databases, without
|
||||
having to replicate them first in your configuration
|
||||
under the
|
||||
.Pa floppy.tree/
|
||||
directory.
|
||||
.El
|
||||
.It Pa floppy.tree.exclude
|
||||
List of files from the standard floppy tree which
|
||||
we do not want to be copied (optional).
|
||||
.It Pa floppy.tree/
|
||||
Local additions to the standard floppy tree (optional).
|
||||
The content of this subtree will be copied as-is into the
|
||||
floppy image.
|
||||
.It Pa floppy.tree. Ns Aq Ar site-name
|
||||
Same as above, but site-specific (optional).
|
||||
.El
|
||||
.Pp
|
||||
More information on the build process can be found in the
|
||||
comments in the
|
||||
.Nm
|
||||
script.
|
||||
.Sh USING ALTERNATE SOURCE TREES
|
||||
The build script can be instructed to use an alternate source tree
|
||||
using the
|
||||
.Fl -src Ar SRC_PATH
|
||||
option.
|
||||
The tree that you specify must contain full sources for the kernel
|
||||
and for all programs that you want to include in your image.
|
||||
As an example, to cross-build the
|
||||
.Pa bridge
|
||||
floppy
|
||||
using RELENG_4 sources, you can do the following:
|
||||
.Bd -literal -offset indent
|
||||
cd <some_empty_directory>
|
||||
mkdir FOO
|
||||
(cd FOO; cvs -d<my_repository> co -rRELENG_4 src)
|
||||
picobsd --src FOO/src --init # this is needed only once
|
||||
picobsd --src FOO/src -n -v bridge
|
||||
.Ed
|
||||
.Pp
|
||||
If the build is successful, the directory
|
||||
.Pa build_dir-bridge/
|
||||
will contain a
|
||||
.Pa kernel
|
||||
that can be downloaded with etherboot, a floppy image called
|
||||
.Pa picobsd.bin ,
|
||||
plus the products of the compilation in other directories.
|
||||
If you want to modify the source tree in
|
||||
.Pa FOO/src ,
|
||||
a new image can be produced by simply running
|
||||
.Pp
|
||||
.Dl "picobsd --src FOO/src -n -v bridge"
|
||||
.Pp
|
||||
whereas if the change affects include files or libraries
|
||||
you first need to update them, e.g.\& by re-running
|
||||
.Pp
|
||||
.Dl "picobsd --src FOO/src --init # this is needed only once"
|
||||
.Pp
|
||||
as you would normally do for any change of this kind.
|
||||
.Sh INSTALLING PicoBSD
|
||||
.Ss Floppy Install
|
||||
Historically,
|
||||
.Nm
|
||||
is run from a floppy disk, where it can be installed with a simple
|
||||
.Pp
|
||||
.Dl "dd if=picobsd.bin of=/dev/rfd0"
|
||||
.Pp
|
||||
and the floppy is ready to boot.
|
||||
.Ss Hard Disk Install
|
||||
The same process can be used to store the image on a hard disk
|
||||
(entire volume or one of the slices):
|
||||
.Bd -literal -offset indent
|
||||
dd if=picobsd.bin of=/dev/ada2
|
||||
dd if=picobsd.bin of=/dev/ada2s3
|
||||
dd if=picobsd.bin of=/dev/ada2 oseek=NN
|
||||
.Ed
|
||||
.Pp
|
||||
The first form will install the image on the entire disk, and it
|
||||
should work in the same way as for a floppy.
|
||||
.Pp
|
||||
The second form will install the image
|
||||
on slice number 3 (which should be large enough to store the
|
||||
contents of the image).
|
||||
However, the process will only have success if the
|
||||
partition does not contain a valid disklabel, otherwise the kernel will
|
||||
likely prevent overwriting the label.
|
||||
In this case you can use the
|
||||
third form, replacing
|
||||
.Ar NN
|
||||
with the actual start of the partition
|
||||
(which you can determine using
|
||||
.Xr gpart 8 ) .
|
||||
Note that after saving the image to the slice, it will not yet be
|
||||
recognised.
|
||||
You have to use the
|
||||
.Xr disklabel 8
|
||||
command to properly initialize the label (do not ask why!).
|
||||
One way to do this is
|
||||
.Bd -literal -offset indent
|
||||
disklabel -w ada0s2 auto
|
||||
disklabel -e ada0s2
|
||||
.Ed
|
||||
.Pp
|
||||
and from the editor enter a line corresponding to the actual partition, e.g.\&
|
||||
if the image has 2.88MB (5760 sectors) you need to enter the following
|
||||
line for the partition:
|
||||
.Pp
|
||||
.Dl "a: 5760 0 4.2BSD 512 4096"
|
||||
.Pp
|
||||
At this point the partition is bootable.
|
||||
Note that the image size can be smaller than the slice size
|
||||
(indicated as partition
|
||||
.Dq Li c: ) .
|
||||
.Ss CDROM Install
|
||||
.Nm
|
||||
can produce an ISO image named picobsd.iso,
|
||||
which does not use
|
||||
.Dq "El Torito"
|
||||
emulation, so it has no size restrictions.
|
||||
Installing means just burning a media with the file.
|
||||
.Ss Booting From The Network
|
||||
Yet another way to use
|
||||
.Nm
|
||||
is to boot the image off the network.
|
||||
For this purpose you should use the uncompressed kernel which is
|
||||
available as a byproduct of the compilation.
|
||||
Refer to the documentation
|
||||
for network booting for more details, the
|
||||
.Nm
|
||||
kernel is bootable as a standard
|
||||
.Fx
|
||||
kernel.
|
||||
.Sh BOOTING PicoBSD
|
||||
To boot
|
||||
.Nm ,
|
||||
insert the floppy and reset the machine.
|
||||
The boot procedure is similar to the
|
||||
standard
|
||||
.Fx
|
||||
boot.
|
||||
Booting from a floppy is normally rather slow (in the order of 1-2
|
||||
minutes), things are much faster if you store your image on
|
||||
a hard disk, Compact Flash, or CDROM.
|
||||
.Pp
|
||||
You can also use etherboot to load the preloaded, uncompressed kernel image
|
||||
which is a byproduct of the
|
||||
.Nm
|
||||
build.
|
||||
In this case
|
||||
the load time is a matter of a few seconds, even on a 10Mbit/s
|
||||
ethernet.
|
||||
.Pp
|
||||
After booting,
|
||||
.Nm
|
||||
loads the root file system from the memory file system, starts
|
||||
.Pa /sbin/init ,
|
||||
and passes control to a first startup script,
|
||||
.Pa /etc/rc .
|
||||
The latter populates the
|
||||
.Pa /etc
|
||||
and
|
||||
.Pa /root
|
||||
directories with the default files, then tries to identify the boot
|
||||
device (floppy, hard disk partition) and possibly override the contents
|
||||
of the root file system with files read from the boot device.
|
||||
This allows you to store local configuration on the same media.
|
||||
After this phase the boot device is no longer used, unless the
|
||||
user specifically does it.
|
||||
.Pp
|
||||
After this, control is transferred to a second script,
|
||||
.Pa /etc/rc1
|
||||
(which can be overridden from the boot device).
|
||||
This script tries to associate a hostname to the system by using
|
||||
the MAC address of the first ethernet interface as a key, and
|
||||
.Pa /etc/hosts
|
||||
as a lookup table.
|
||||
Then control is passed to the main user configuration script,
|
||||
.Pa /etc/rc.conf ,
|
||||
which is supposed to override the value of a number of configuration
|
||||
variables which have been pre-set in
|
||||
.Pa /etc/rc.conf.defaults .
|
||||
You can use the
|
||||
.Va hostname
|
||||
variable to create different configurations from the same file.
|
||||
After taking control back,
|
||||
.Pa /etc/rc1
|
||||
completes the initializations, and as part of this
|
||||
it configures network interfaces and optionally calls the
|
||||
firewall configuration script,
|
||||
.Pa /etc/rc.firewall ,
|
||||
where the user can store his own firewall configuration.
|
||||
.Pp
|
||||
Note that by default
|
||||
.Nm
|
||||
runs entirely from main memory, and has no swap space, unless you
|
||||
explicitly request it.
|
||||
The boot device is also not used anymore after
|
||||
.Pa /etc/rc1
|
||||
takes control, again, unless you explicitly request it.
|
||||
.Sh CONFIGURING a PicoBSD system
|
||||
The operation of a
|
||||
.Nm
|
||||
system can be configured through a few files which are read at boot
|
||||
time, very much like a standard
|
||||
.Fx
|
||||
system.
|
||||
There are, however, some minor differences to reduce the
|
||||
number of files to store and/or customize, thus saving space.
|
||||
Among the files to configure we have the following:
|
||||
.Bl -tag -width indent
|
||||
.It Pa /etc/hosts
|
||||
Traditionally, this file contains the IP-to-hostname mappings.
|
||||
In addition to this, the
|
||||
.Nm
|
||||
version of this file also contains
|
||||
a mapping between Ethernet (MAC) addresses and hostnames, as follows:
|
||||
.Bd -literal -offset indent
|
||||
#ethertable start of the ethernet->hostname mapping
|
||||
# mac_address hostname
|
||||
# 00:12:34:56:78:9a pinco
|
||||
# 12:34:56:* pallino
|
||||
# * this-matches-all
|
||||
.Ed
|
||||
.Pp
|
||||
where the line containing
|
||||
.Dq Li #ethertable
|
||||
marks the start of the table.
|
||||
.Pp
|
||||
If the MAC address is not found, the script will prompt you to
|
||||
enter a hostname and IP address for the system, and this
|
||||
information will be stored in the
|
||||
.Pa /etc/hosts
|
||||
file (in memory) so you can simply store them on disk later.
|
||||
.Pp
|
||||
Note that you can use wildcards in the address part, so a line
|
||||
like the last one in the example will match any MAC address and
|
||||
avoid the request.
|
||||
.It Pa /etc/rc.conf
|
||||
This file contains a number of variables which control the
|
||||
operation of the system, such as interface configuration,
|
||||
router setup, network service startup, etc.
|
||||
For the exact list and meaning of these variables see
|
||||
.Pa /etc/rc.conf.defaults .
|
||||
.Pp
|
||||
It is worth mentioning that some of the variables let you
|
||||
overwrite the contents of some files in
|
||||
.Pa /etc .
|
||||
This option is available at the moment for
|
||||
.Pa /etc/host.conf
|
||||
and
|
||||
.Pa /etc/resolv.conf ,
|
||||
whose contents are generally very short and suitable for this
|
||||
type of updating.
|
||||
In case you use these variables, remember to use newlines
|
||||
as appropriate, e.g.\&
|
||||
.Bd -literal -offset indent
|
||||
host_conf="# this goes into /etc/host.conf
|
||||
hosts
|
||||
bind"
|
||||
.Ed
|
||||
.Pp
|
||||
Although not mandatory, in this file you should only set the
|
||||
variables indicated in
|
||||
.Pa /etc/rc.conf.defaults ,
|
||||
and avoid starting services which depend on having the network running.
|
||||
This can be done at a later time: if you set
|
||||
.Va firewall_enable Ns = Ns Qq Li YES ,
|
||||
the
|
||||
.Pa /etc/rc.firewall
|
||||
script will be run after configuring the network interfaces,
|
||||
so you can set up your firewall and safely start network services or enable
|
||||
things such as routing and bridging.
|
||||
.It Pa /etc/rc.firewall
|
||||
This script can be used to configure the
|
||||
.Xr ipfw 4
|
||||
firewall.
|
||||
On entry, the
|
||||
.Va fwcmd
|
||||
variable is set to the pathname of the firewall command,
|
||||
.Va firewall_type
|
||||
contains the value set in
|
||||
.Pa /etc/rc.conf ,
|
||||
and
|
||||
.Va hostname
|
||||
contains the name assigned to the host.
|
||||
.El
|
||||
.Pp
|
||||
There is a small script called
|
||||
.Nm update
|
||||
which can be used to edit and/or save to disk a copy of the files
|
||||
you have modified after booting.
|
||||
The script takes one or more absolute pathnames, runs the
|
||||
editor on the files passed as arguments, and then saves a
|
||||
compressed copy of the files on the disk (mounting and
|
||||
unmounting the latter around the operation).
|
||||
.Pp
|
||||
If invoked without arguments,
|
||||
.Nm update
|
||||
edits and saves
|
||||
.Pa rc.conf , rc.firewall ,
|
||||
and
|
||||
.Pa master.passwd .
|
||||
.Pp
|
||||
If one of the arguments is
|
||||
.Pa /etc
|
||||
(the directory name alone),
|
||||
then the command saves to disk (without editing)
|
||||
all the files in the directory for which a copy
|
||||
already exists on disk (e.g.\& as a result of a previous update).
|
||||
.Sh SEE ALSO
|
||||
.Xr crunchgen 1 ,
|
||||
.Xr mdconfig 8 ,
|
||||
.Xr nanobsd 8 ,
|
||||
.Xr swapon 8
|
||||
.Sh AUTHORS
|
||||
.An -nosplit
|
||||
.An Andrzej Bialecki Aq Mt abial@FreeBSD.org ,
|
||||
with subsequent work on the scripts by
|
||||
.An Luigi Rizzo Aq Mt luigi@iet.unipi.it
|
||||
and others.
|
||||
Man page and
|
||||
.Pa Makefiles
|
||||
created by
|
||||
.An Greg Lehey Aq Mt grog@lemis.com .
|
||||
.Sh BUGS
|
||||
Documentation is still incomplete.
|
Loading…
Reference in New Issue
Block a user