Compare commits

..
26 Commits
Author SHA1 Message Date
Denys Vlasenko 2b400d9b2b httpd: fix handling of range requests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-18 13:11:54 +02:00
Denys Vlasenko 81e26c4b8e Bump version to 1.27.2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-17 12:58:27 +02:00
Denys Vlasenko 0b16a67959 svc: fix a case where with more than option, getopt() state is not reset
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-05 01:40:12 +02:00
Natanael Copa 4989d05174 unzip: fix regression on big-endian machines
This fixes a regression which was introduced with commit 2a0867a5
("unzip: optional support for bzip2 and lzma") and causes unzip to exit
with error when extracting archives:

  unzip: unsupported method 2048

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 14:54:16 +02:00
Denys Vlasenko 21e5d0f841 config: FEDORA_COMPAT option (so far only tweaks uname)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:22:17 +02:00
Denys Vlasenko cf792a58ab NOFORK fixes
"rm -i FILE" and "yes" can now be interrupted by ^C in hush.
This also now works:

$ usleep 19999999
^C
$ echo $?
130

function                                             old     new   delta
run_pipe                                            1668    1711     +43
pseudo_exec_argv                                     312     321      +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 52/0)               Total: 52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:20:19 +02:00
Denys Vlasenko 0a53eadea5 tls: fix pstm asm constraint problem
function                                             old     new   delta
pstm_sqr_comba                                       551     475     -76

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:18:00 +02:00
Denys Vlasenko 25f07f5898 tls: fix build problem on non-static i386
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:17:54 +02:00
Denys Vlasenko 6bb89e1622 libbb: safe_write should not return EINTR
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:17:50 +02:00
Denys Vlasenko 310bcec4dc shuf: fix random line selection. Closes 9971
"""
For example, given input file:

    foo
    bar
    baz

after shuffling the input file, foo will never end up back on the first line.
This came to light when I ran into a use-case where someone was selecting
a random line from a file using shuf | head -n 1, and the results on busybox
were showing a statistical anomaly (as in, the first line would never ever
be picked) vs the same process running on environments that had gnu coreutils
installed.

On line https://git.busybox.net/busybox/tree/coreutils/shuf.c#n56 it uses
r %= i, which will result in 0 <= r < i, while the algorithm specifies
0 <= r <= i.
"""

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:17:42 +02:00
Denys Vlasenko 8fd69c7bdb Bump version to 1.27.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:22:15 +02:00
Denys Vlasenko 56a361bec1 fix more instances of ": $((a++))" in shell scripts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Kang-Che Sung 6f13dd1d65 make_single_applets: fix ": $((fail++))" expansion error
$((fail++)) is not a required expression in POSIX, and in "dash" it
could produce an error like this:

    ./make_single_applets.sh: 61: arithmetic expression: expecting primary: "fail++"

Replace this with something portable: fail=$((fail+1)) would work.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Johannes Schindelin 3df48bdde9 copyfd: guard use of munmap() with #if (windows builds need this)
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Johannes Schindelin 1f684bcde4 ash: protect WIFSTOPPED use with #if JOBS
This change fixes the build in setups where there are
no headers defining WIFSTOPPED and WSTOPSIG (where JOBS has to be
set to 0).

This partially reverts 4700fb5be (ash: make dowait() a bit more
readable. Logic is unchanged, 2015-10-09).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 2cb72bb8de libbb: hide getnetbyaddr() inside "#if ENABLE_FEATURE_ETC_NETWORKS" block
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 87d8ae94a2 uuencode: allow space instead of "`" as padding char. Closes 10046
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko a3de7190a5 dd: fix status=none. Closes 10066
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko f807b8e96e inetd,mount: do not die if uclibc without RPC is detected
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 2f6dc07d8f beep: disallow FEATURE_BEEP_FREQ = 0 in configuration
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 54916641be main: fix the case where user has "halt" as login shell. Closes 9986
halt::0:0::/:/sbin/halt

function                                             old     new   delta
run_applet_and_exit                                  748     751      +3
run_applet_no_and_exit                               467     459      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Peter Korsgaard 80cb8796f8 dpkg: fix CONFIG_FEATURE_CLEAN_UP handling
dpkg moved to away from dynamically allocating the hashtables in commit
c87339d584 (dpkg: trivial code shrinkage, and redo G trick correctly) almost
ten years ago, but the cleanup code was never adjusted to match.

Glibc loudly complains about this:

*** Error in `dpkg': free(): invalid pointer: 0x0000007fac3478c0 ***

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Patrick Steinhardt ee67c9a60a setpriv: do not process remaining args
By default, the 'getopt32' call will continue parsing the command line
even after hitting a non-option string. But in setpriv, this should be
avoided, as all parameters following the initial non-option argument are
in fact arguments to the binary that is to be executed by setpriv.
Otherwise, calling e.g. 'busybox setpriv ls -l' would result in an error
due to the unknown parameter "-l".

Fix the issue by passing "+" as the first character in the options
string. This will cause 'getopt32' to stop processing after hitting the
first non-option.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 8965e5089e tls: use capped SNI len everywhere
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko e916d48e5a bzcat: compile bunzip2_main() if BZCAT.
Currently, BZCAT (and BUNZIP2) selects FEATURE_BZIP2_DECOMPRESS,
thus, "#if ENABLE_FEATURE_BZIP2_DECOMPRESS" around bunzip2_main()
is sufficient. But let's robustify it.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 442d522f0b fixes for bugs found by make_single_applets.sh
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
863 changed files with 9130 additions and 16326 deletions

No files matched your search

+381 -377
View File
File diff suppressed because it is too large. Load diff
+5 -6
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 28
SUBLEVEL = 1
PATCHLEVEL = 27
SUBLEVEL = 2
EXTRAVERSION =
NAME = Unnamed
@@ -178,7 +178,7 @@ endif
# SUBARCH is subsequently ignored.
ifneq ($(CROSS_COMPILE),)
SUBARCH := $(shell echo $(CROSS_COMPILE) | cut -d- -f1 | sed 's:^.*/::g')
SUBARCH := $(shell echo $(CROSS_COMPILE) | cut -d- -f1)
else
SUBARCH := $(shell uname -m)
endif
@@ -470,7 +470,6 @@ libs-y := \
coreutils/ \
coreutils/libcoreutils/ \
debianutils/ \
klibc-utils/ \
e2fsprogs/ \
editors/ \
findutils/ \
@@ -509,8 +508,6 @@ ifeq ($(dot-config),1)
# To avoid any implicit rule to kick in, define an empty command
.config .kconfig.d: ;
-include $(srctree)/arch/$(ARCH)/Makefile
# Now we can define CFLAGS etc according to .config
include $(srctree)/Makefile.flags
@@ -534,6 +531,8 @@ endif
# Defaults busybox but it is usually overridden in the arch makefile
all: busybox doc
-include $(srctree)/arch/$(ARCH)/Makefile
# arch Makefile may override CC so keep this after arch Makefile is included
#bbox# NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
CHECKFLAGS += $(NOSTDINC_FLAGS)
+1 -1
View File
@@ -15,7 +15,7 @@ CPPFLAGS += \
-include include/autoconf.h \
-D_GNU_SOURCE -DNDEBUG \
$(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
-D"BB_VER=KBUILD_STR($(BB_VER))"
-D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP
CFLAGS += $(call cc-option,-Wall,)
CFLAGS += $(call cc-option,-Wshadow,)
-437
View File
@@ -1,437 +0,0 @@
Why an applet can't be NOFORK or NOEXEC?
Why can't be NOFORK:
interactive: may wait for user input, ^C has to work
spawner: "tool PROG ARGS" which changes program state and execs - must fork
changes state: e.g. environment, signal handlers
leaks: does not free allocated memory or opened fds
alloc+xfunc: xmalloc, then xfunc - leaks memory if xfunc dies
open+xfunc: opens fd, then calls xfunc - fd is leaked if xfunc dies
talks to network/serial/etc: it's not known how long the delay can be,
it's reasonable to expect it might be many seconds
(even if usually it is not), so ^C has to work
runner: sometimes may run for long(ish) time, and/or works with network:
^C has to work (cat BIGFILE, chmod -R, ftpget, nc)
"runners" can become eligible after shell is taught ^C to interrupt NOFORKs,
need to be inspected that they do not fall into alloc+xfunc, open+xfunc,
leak categories.
Why can't be NOEXEC:
suid: runs under different uid - must fork+exec
if it's important that /proc/PID/cmdline and comm are correct.
("pkill sh" killing itself before it kills real "sh" is no fun)
Why shouldn't be NOFORK/NOEXEC:
rare: not started often enough to bother optimizing (example: poweroff)
daemon: runs indefinitely; these are also always fit "rare" category
longterm: often runs for a long time (many seconds), execing makes
memory footprint smaller
complex: no immediately obvious reason why NOFORK wouldn't work,
but does some non-obvoius operations (example: fuser, lsof, losetup);
detailed audit often turns out that it's a leaker
hardware: performs unusual hardware ops which may take long,
or even hang due to hardware or firmware bugs
Interesting example of "interactive" applet which is nevertheless can be
(and is) NOEXEC is "rm". Yes, "rm -i" is interactive - but it's not that typical
for users to keep it waiting for many minutes, whereas running "rm" in shell
is very typical, and speeding up this common use via NOEXEC is useful.
IOW: rm is "interactive", but not "longterm".
Interesting example of an applet which can be NOFORK but if not,
then should not be NOEXEC, is "usleep". As NOFORK, it amount to simply
nanosleep()ing in the calling program (usually shell). No memory wasted.
But if ran as NOEXEC, it would create a potentially long-term process,
which would be taking more memory because it did not exec
and did not free much of the copied memory of the parent
(COW helps with this only as long as parent doesn't modify its memory).
[ - NOFORK
[[ - NOFORK
acpid - daemon
add-shell - noexec. leaks: open+xfunc
addgroup - noexec. leaks
adduser - noexec. leaks
adjtimex - NOFORK
ar - runner
arch - NOFORK
arp - talks to network: arp -n queries DNS
arping - longterm
ash - interactive, longterm
awk - noexec. runner
base64 - runner
basename - NOFORK
beep - longterm: beep -r 999999999
blkdiscard - noexec. leaks: open+xioctl
blkid - noexec
blockdev - noexec. leaks fd
bootchartd - daemon
brctl - noexec
bunzip2 - runner
bzcat - runner
bzip2 - runner
cal - runner: cal -n9999
cat - runner: cat HUGEFILE
chat - longterm (when used as intended - talking to modem over stdin/out)
chattr - noexec. runner
chgrp - noexec. runner
chmod - noexec. runner
chown - noexec. runner
chpasswd - longterm? (list of "user:password"s from stdin)
chpst - noexec. spawner
chroot - noexec. spawner
chrt - noexec. spawner
chvt - noexec. leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds
cksum - noexec. runner
clear - NOFORK
cmp - runner
comm - runner
conspy - interactive, longterm
cp - noexec. runner
cpio - runner
crond - daemon
crontab - longterm (runs $EDITOR), leaks: open+xasprintf
cryptpw - noexec. changes state: with --password-fd=N, moves N to stdin
cttyhack - noexec. spawner
cut - noexec. runner
date - noexec. nofork candidate(needs to stop messing up env, free xasprintf result, not use xfuncs after xasprintf)
dc - longterm (eats stdin if no params)
dd - noexec. runner
deallocvt - noexec. leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds
delgroup - noexec. leaks
deluser - noexec. leaks
depmod - longterm(ish)
devmem - hardware (access to device memory may hang)
df - noexec. leaks: nested allocs
dhcprelay - daemon
diff - runner
dirname - NOFORK
dmesg - runner
dnsd - daemon
dnsdomainname - noexec. talks to network (may query DNS)
dos2unix - noexec. runner
dpkg - runner
du - runner
dumpkmap - noexec. leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds
dumpleases - noexec. leaks: open+xread
echo - NOFORK
ed - interactive, longterm
egrep - longterm runner ("CMD | egrep ..." may run indefinitely, better to exec to conserve memory)
eject - hardware, leaks: open+ioctl_or_perror_and_die, changes state (moves fds)
env - noexec. spawner, changes state (env)
envdir - noexec. spawner
envuidgid - noexec. spawner
expand - runner
expr - noexec. leaks: nested allocs
factor - longterm (eats stdin if no params)
fakeidentd - daemon
false - NOFORK
fatattr - noexec. leaks: open+xioctl, complex
fbset - hardware, leaks: open+xfunc
fbsplash - runner, longterm
fdflush - hardware, leaks: open+ioctl_or_perror_and_die
fdformat - hardware, longterm
fdisk - interactive, longterm
fgconsole - noexec. leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds
fgrep - longterm runner ("CMD | fgrep ..." may run indefinitely, better to exec to conserve memory)
find - noexec. runner
findfs - suid
flash_eraseall - hardware
flash_lock - hardware
flash_unlock - hardware
flashcp - hardware
flock - spawner, changes state (file locks), let's play safe and not be noexec
fold - noexec. runner
free - NOFORK
freeramdisk - noexec. leaks: open+ioctl_or_perror_and_die
fsck - interactive, longterm
fsck.minix - needs ^C
fsfreeze - noexec. leaks: open+xioctl
fstrim - noexec. leaks: open+xioctl, find_block_device -> readdir+xstrdup
fsync - NOFORK
ftpd - daemon
ftpget - runner
ftpput - runner
fuser - complex
getopt - noexec. leaks: many allocs
getty - interactive, longterm
grep - longterm runner ("CMD | grep ..." may run indefinitely, better to exec to conserve memory)
groups - noexec
gunzip - runner
gzip - runner
halt - rare
hd - noexec. runner
hdparm - hardware
head - noexec. runner
hexdump - noexec. runner
hexedit - interactive, longterm
hostid - NOFORK
hostname - noexec. talks to network (hostname -d may query DNS)
httpd - daemon
hush - interactive, longterm
hwclock - hardware (xioctl(RTC_RD_TIME))
i2cdetect - hardware
i2cdump - hardware
i2cget - hardware
i2cset - hardware
id - noexec
ifconfig - hardware? (mem_start NN io_addr NN irq NN), leaks: xsocket+ioctl_or_perror_and_die
ifenslave - noexec. leaks: xsocket+bb_perror_msg_and_die
ifplugd - daemon
inetd - daemon
init - daemon
inotifyd - daemon
insmod - noexec
install - runner
ionice - noexec. spawner
iostat - longterm: "iostat 1" runs indefinitely
ip - noexec
ipaddr - noexec
ipcalc - noexec. ipcalc -h talks to network
ipcrm - noexec
ipcs - noexec
iplink - noexec
ipneigh - noexec
iproute - noexec
iprule - noexec
iptunnel - noexec
kbd_mode - noexec. leaks: xopen_nonblocking+xioctl
kill - NOFORK
killall - NOFORK
killall5 - NOFORK
klogd - daemon
last - runner (I've got 1300 lines of output when tried it)
less - interactive, longterm
link - NOFORK
linux32 - noexec. spawner
linux64 - noexec. spawner
linuxrc - daemon
ln - noexec
loadfont - noexec. leaks: config_open+bb_error_msg_and_die("map format")
loadkmap - noexec. leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds
logger - runner
login - suid, interactive, longterm
logname - NOFORK
losetup - noexec. complex
lpd - daemon
lpq - runner
lpr - runner
ls - noexec. runner
lsattr - noexec. runner
lsmod - noexec
lsof - complex
lspci - noexec. too rare to bother for nofork
lsscsi - noexec. too rare to bother for nofork
lsusb - noexec. too rare to bother for nofork
lzcat - runner
lzma - runner
lzop - runner
lzopcat - runner
makedevs - noexec
makemime - runner
man - spawner, interactive, longterm
md5sum - noexec. runner
mdev - daemon
mesg - NOFORK
microcom - interactive, longterm
minips - noexec
mkdir - NOFORK
mkdosfs - needs ^C
mke2fs - needs ^C
mkfifo - noexec
mkfs.ext2 - needs ^C
mkfs.minix - needs ^C
mkfs.vfat - needs ^C
mknod - noexec
mkpasswd - noexec. changes state: with --password-fd=N, moves N to stdin
mkswap - needs ^C
mktemp - noexec. leaks: xstrdup+concat_path_file
modinfo - noexec
modprobe - noexec
more - interactive, longterm
mount - suid
mountpoint - noexec. leaks: option -n "print dev name": find_block_device -> readdir+xstrdup
mpstat - longterm: "mpstat 1" runs indefinitely
mt - hardware
mv - noexec candidate, runner
nameif - noexec. openlog(), leaks: config_open2+ioctl_or_perror_and_die
nbd-client - noexec
nc - runner
netstat - longterm with -c (continuous listing)
nice - noexec. spawner
nl - runner
nmeter - longterm
nohup - noexec. spawner
nproc - NOFORK
ntpd - daemon
nuke - noexec
od - runner
openvt - longterm: spawns a child and waits for it
partprobe - noexec. leaks: open+ioctl_or_perror_and_die(BLKRRPART)
passwd - suid
paste - noexec. runner
patch - needs ^C
pgrep - must fork+exec to get correct /proc/PID/cmdline and comm field
pidof - must fork+exec to get correct /proc/PID/cmdline and comm field
ping - suid, longterm
ping6 - suid, longterm
pipe_progress - longterm
pivot_root - NOFORK
pkill - must fork+exec to get correct /proc/PID/cmdline and comm field
pmap - noexec candidate, leaks: open+xstrdup
popmaildir - runner
poweroff - rare
powertop - interactive, longterm
printenv - NOFORK
printf - NOFORK
ps - noexec
pscan - talks to network
pstree - noexec
pwd - NOFORK
pwdx - NOFORK
raidautorun - noexec. very simple. leaks: open+xioctl
rdate - talks to network
rdev - noexec. leaks: find_block_device -> readdir+xstrdup
readlink - NOFORK
readprofile - reads /boot/System.map and /proc/profile, better to free more memory by execing?
realpath - NOFORK
reboot - rare
reformime - runner
remove-shell - noexec. leaks: open+xfunc
renice - noexec. nofork candidate(uses getpwnam, is that ok?)
reset - noexec. spawner (execs "stty")
resize - noexec. changes state (signal handlers)
resume - noexec
rev - runner
rm - noexec. rm -i interactive
rmdir - NOFORK
rmmod - noexec
route - talks to network (may query DNS to convert IPs to names)
rpm - runner
rpm2cpio - runner
rtcwake - longterm: puts system to sleep, optimizing this for speed is pointless
run-init - spawner, rare, changes state (oh yes), execing may be important to free binary's inode
run-parts - longterm
runlevel - noexec. can be nofork if "endutxent()" is called unconditionally, but too rare to bother?
runsv - daemon
runsvdir - daemon
rx - runner
script - longterm: pumps script output from slave pty
scriptreplay - longterm: plays back "script" saved output, sleeping as necessary.
sed - runner
sendmail - runner
seq - noexec. runner
setarch - noexec. spawner
setconsole - noexec
setfattr - noexec
setfont - noexec. leaks a lot of stuff
setkeycodes - noexec
setlogcons - noexec
setpriv - spawner, changes state, let's play safe and not be noexec
setserial - noexec
setsid - spawner, uses fork_or_rexec() [not audited to work in noexec], let's play safe and not be noexec
setuidgid - noexec. spawner
sha1sum - noexec. runner
sha256sum - noexec. runner
sha3sum - noexec. runner
sha512sum - noexec. runner
showkey - interactive, longterm
shred - runner
shuf - noexec. runner
slattach - longterm (may sleep forever), uses bb_common_bufsiz1
sleep - longterm. Could be nofork, if not the problem of "killall sleep" not killing it.
smemcap - runner
softlimit - noexec. spawner
sort - noexec. runner
split - runner
ssl_client - longterm
start-stop-daemon - not noexec: uses bb_common_bufsiz1
stat - noexec. nofork candidate(needs fewer allocs)
strings - runner
stty - noexec. nofork candidate: has no allocs or opens except xmove_fd(xopen("-F DEVICE"),STDIN). tcsetattr(STDIN) is not a problem: it would work the same across processes sharing this fd
su - suid, spawner
sulogin - noexec. spawner
sum - runner
sv - noexec. needs ^C (uses usleep(420000))
svc - noexec. needs ^C (uses usleep(420000))
svlogd - daemon
swapoff - longterm: may cause memory pressure, execing is beneficial
swapon - rare
switch_root - spawner, rare, changes state (oh yes), execing may be important to free binary's inode
sync - NOFORK
sysctl - noexec. leaks: xstrdup+xmalloc_read
syslogd - daemon
tac - noexec. runner
tail - runner
tar - runner
taskset - noexec. spawner
tcpsvd - daemon
tee - runner
telnet - interactive, longterm
telnetd - daemon
test - NOFORK
tftp - runner
tftpd - daemon
time - spawner, longterm, changes state (signals)
timeout - spawner, longterm, changes state (signals)
top - interactive, longterm
touch - NOFORK
tr - runner
traceroute - suid, longterm
traceroute6 - suid, longterm
true - NOFORK
truncate - NOFORK
tty - NOFORK
ttysize - NOFORK
tunctl - noexec
tune2fs - noexec. leaks: open+xfunc
ubiattach - hardware
ubidetach - hardware
ubimkvol - hardware
ubirename - hardware
ubirmvol - hardware
ubirsvol - hardware
ubiupdatevol - hardware
udhcpc - daemon
udhcpd - daemon
udpsvd - daemon
uevent - daemon
umount - noexec. leaks: nested xmalloc
uname - NOFORK
uncompress - runner
unexpand - runner
uniq - runner
unix2dos - noexec. runner
unlink - NOFORK
unlzma - runner
unlzop - runner
unxz - runner
unzip - runner
uptime - noexec. nofork candidate(is getutxent ok?)
users - noexec. nofork candidate(is getutxent ok?)
usleep - NOFORK. But what about "killall usleep"?
uudecode - runner
uuencode - runner
vconfig - noexec. leaks: xsocket+ioctl_or_perror_and_die
vi - interactive, longterm
vlock - suid
volname - hardware (reads CDROM, this can take long-ish if need to spin up)
w - noexec. nofork candidate(is getutxent ok?)
wall - suid
watch - longterm
watchdog - daemon
wc - runner
wget - longterm
which - NOFORK
who - noexec. nofork candidate(is getutxent ok?)
whoami - NOFORK
whois - talks to network
xargs - noexec. spawner
xxd - noexec. runner
xz - runner
xzcat - runner
yes - noexec. runner
zcat - runner
zcip - daemon
+2
View File
@@ -224,6 +224,8 @@ Minor stuff:
---
support start-stop-daemon -d <chdir-path>
---
vdprintf() -> similar sized functionality
---
(TODO list after discussion 11.05.2009)
-11
View File
@@ -1,11 +0,0 @@
# When building a library, even intra-library references,
# such as from find_applet_by_name() to applet_names[],
# don't work with -fpic on sparc, needs -fPIC.
# Don't know why it fails in this case but works when
# a binary is being built.
#
# (if is superfluous, ARCH_FPIC is only used by library build, but it
# demonstrates the point: non-pic binary does not need it)
ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
ARCH_FPIC = -fPIC
endif
-11
View File
@@ -1,11 +0,0 @@
# When building a library, even intra-library references,
# such as from find_applet_by_name() to applet_names[],
# don't work with -fpic on sparc, needs -fPIC.
# Don't know why it fails in this case but works when
# a binary is being built.
#
# (if is superfluous, ARCH_FPIC is only used by library build, but it
# demonstrates the point: non-pic binary does not need it)
ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
ARCH_FPIC = -fPIC
endif
-8
View File
@@ -27,12 +27,4 @@ config FEATURE_SEAMLESS_Z
INSERT
config FEATURE_LZMA_FAST
bool "Optimize lzma for speed"
default n
depends on UNLZMA || LZCAT || LZMA || FEATURE_SEAMLESS_LZMA
help
This option reduces decompression time by about 25% at the cost of
a 1K bigger binary.
endmenu
+19 -22
View File
@@ -16,36 +16,38 @@
* between different systems
* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
*/
//config:config AR
//config: bool "ar (9.5 kb)"
//config: bool "ar"
//config: default n # needs to be improved to be able to replace binutils ar
//config: help
//config: ar is an archival utility program used to create, modify, and
//config: extract contents from archives. In practice, it is used exclusively
//config: for object module archives used by compilers.
//config: ar is an archival utility program used to create, modify, and
//config: extract contents from archives. In practice, it is used exclusively
//config: for object module archives used by compilers.
//config:
//config: Unless you have a specific application which requires ar, you should
//config: probably say N here: most compilers come with their own ar utility.
//config: On an x86 system, the ar applet adds about 1K.
//config:
//config: Unless you have a specific application which requires ar, you should
//config: probably say N here: most compilers come with their own ar utility.
//config:
//config:config FEATURE_AR_LONG_FILENAMES
//config: bool "Support long filenames (not needed for debs)"
//config: default y
//config: depends on AR
//config: help
//config: By default the ar format can only store the first 15 characters
//config: of the filename, this option removes that limitation.
//config: It supports the GNU ar long filename method which moves multiple long
//config: filenames into a the data section of a new ar entry.
//config: By default the ar format can only store the first 15 characters
//config: of the filename, this option removes that limitation.
//config: It supports the GNU ar long filename method which moves multiple long
//config: filenames into a the data section of a new ar entry.
//config:
//config:config FEATURE_AR_CREATE
//config: bool "Support archive creation"
//config: default y
//config: depends on AR
//config: help
//config: This enables archive creation (-c and -r) with busybox ar.
//config: This enables archive creation (-c and -r) with busybox ar.
//applet:IF_AR(APPLET(ar, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_AR) += ar.o
//usage:#define ar_trivial_usage
@@ -240,16 +242,11 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
archive_handle = init_handle();
/* prepend '-' to the first argument if required */
if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0')
argv[1] = xasprintf("-%s", argv[1]);
opt = getopt32(argv, "^"
"voc""ptx"IF_FEATURE_AR_CREATE("r")
"\0"
/* -1: at least one arg is reqd */
/* one of p,t,x[,r] is required */
"-1:p:t:x"IF_FEATURE_AR_CREATE(":r")
);
/* --: prepend '-' to the first argument if required */
/* -1: at least one param is reqd */
/* one of p,t,x[,r] is required */
opt_complementary = "--:-1:p:t:x"IF_FEATURE_AR_CREATE(":r");
opt = getopt32(argv, "voc""ptx"IF_FEATURE_AR_CREATE("r"));
argv += optind;
t = opt / FIRST_CMD;
+58 -42
View File
@@ -4,6 +4,9 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
@@ -18,9 +21,6 @@
/* gzip_main() too: */
//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
#include "libbb.h"
#include "bb_archive.h"
/* Note: must be kept in sync with archival/lzop.c */
enum {
OPT_STDOUT = 1 << 0,
@@ -237,11 +237,11 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
//usage: "\n -f Overwrite"
//config:config UNCOMPRESS
//config: bool "uncompress (7.1 kb)"
//config: bool "uncompress"
//config: default n # ancient
//config: help
//config: uncompress is used to decompress archives created by compress.
//config: Not much used anymore, replaced by gzip/gunzip.
//config: uncompress is used to decompress archives created by compress.
//config: Not much used anymore, replaced by gzip/gunzip.
//applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
@@ -312,20 +312,20 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
//usage: "Decompress to stdout"
//config:config GUNZIP
//config: bool "gunzip (12 kb)"
//config: bool "gunzip"
//config: default y
//config: select FEATURE_GZIP_DECOMPRESS
//config: help
//config: gunzip is used to decompress archives created by gzip.
//config: You can use the '-t' option to test the integrity of
//config: an archive, without decompressing it.
//config: gunzip is used to decompress archives created by gzip.
//config: You can use the `-t' option to test the integrity of
//config: an archive, without decompressing it.
//config:
//config:config ZCAT
//config: bool "zcat (25 kb)"
//config: bool "zcat"
//config: default y
//config: select FEATURE_GZIP_DECOMPRESS
//config: help
//config: Alias to "gunzip -c".
//config: Alias to "gunzip -c".
//config:
//config:config FEATURE_GUNZIP_LONG_OPTIONS
//config: bool "Enable long options"
@@ -389,17 +389,16 @@ int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int gunzip_main(int argc UNUSED_PARAM, char **argv)
{
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
getopt32long(argv, "cfkvqdtn", gunzip_longopts);
#else
getopt32(argv, "cfkvqdtn");
applet_long_options = gunzip_longopts;
#endif
getopt32(argv, "cfkvqdtn");
argv += optind;
/* If called as zcat...
* Normally, "zcat" is just "gunzip -c".
* But if seamless magic is enabled, then we are much more clever.
*/
if (ENABLE_ZCAT && (!ENABLE_GUNZIP || applet_name[1] == 'c'))
if (ENABLE_ZCAT && applet_name[1] == 'c')
option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
@@ -426,25 +425,25 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//usage: "Decompress to stdout"
//config:config BUNZIP2
//config: bool "bunzip2 (8.8 kb)"
//config: bool "bunzip2"
//config: default y
//config: select FEATURE_BZIP2_DECOMPRESS
//config: help
//config: bunzip2 is a compression utility using the Burrows-Wheeler block
//config: sorting text compression algorithm, and Huffman coding. Compression
//config: is generally considerably better than that achieved by more
//config: conventional LZ77/LZ78-based compressors, and approaches the
//config: performance of the PPM family of statistical compressors.
//config: bunzip2 is a compression utility using the Burrows-Wheeler block
//config: sorting text compression algorithm, and Huffman coding. Compression
//config: is generally considerably better than that achieved by more
//config: conventional LZ77/LZ78-based compressors, and approaches the
//config: performance of the PPM family of statistical compressors.
//config:
//config: Unless you have a specific application which requires bunzip2, you
//config: should probably say N here.
//config: Unless you have a specific application which requires bunzip2, you
//config: should probably say N here.
//config:
//config:config BZCAT
//config: bool "bzcat (8.8 kb)"
//config: bool "bzcat"
//config: default y
//config: select FEATURE_BZIP2_DECOMPRESS
//config: help
//config: Alias to "bunzip2 -c".
//config: Alias to "bunzip2 -c".
//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
@@ -455,7 +454,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
{
getopt32(argv, "cfkvqdt");
argv += optind;
if (ENABLE_BZCAT && (!ENABLE_BUNZIP2 || applet_name[2] == 'c')) /* bzcat */
if (ENABLE_BZCAT && applet_name[2] == 'c') /* bzcat */
option_mask32 |= OPT_STDOUT;
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
@@ -494,26 +493,43 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//usage: "Decompress to stdout"
//config:config UNLZMA
//config: bool "unlzma (8.6 kb)"
//config: bool "unlzma"
//config: default y
//config: help
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
//config: compression algorithm, and range coding. Compression
//config: is generally considerably better than that achieved by the bzip2
//config: compressors.
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
//config: compression algorithm, and range coding. Compression
//config: is generally considerably better than that achieved by the bzip2
//config: compressors.
//config:
//config: The BusyBox unlzma applet is limited to decompression only.
//config: On an x86 system, this applet adds about 4K.
//config:
//config:config LZCAT
//config: bool "lzcat (8.5 kb)"
//config: bool "lzcat"
//config: default y
//config: help
//config: Alias to "unlzma -c".
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
//config: compression algorithm, and range coding. Compression
//config: is generally considerably better than that achieved by the bzip2
//config: compressors.
//config:
//config: The BusyBox unlzma applet is limited to decompression only.
//config: On an x86 system, this applet adds about 4K.
//config:
//config:config LZMA
//config: bool "lzma -d"
//config: default y
//config: help
//config: Enable this option if you want commands like "lzma -d" to work.
//config: IOW: you'll get lzma applet, but it will always require -d option.
//config: Enable this option if you want commands like "lzma -d" to work.
//config: IOW: you'll get lzma applet, but it will always require -d option.
//config:
//config:config FEATURE_LZMA_FAST
//config: bool "Optimize for speed"
//config: default n
//config: depends on UNLZMA || LZCAT || LZMA
//config: help
//config: This option reduces decompression time by about 25% at the cost of
//config: a 1K bigger binary.
//applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
@@ -565,23 +581,23 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
//usage: "Decompress to stdout"
//config:config UNXZ
//config: bool "unxz (13 kb)"
//config: bool "unxz"
//config: default y
//config: help
//config: unxz is a unlzma successor.
//config: unxz is a unlzma successor.
//config:
//config:config XZCAT
//config: bool "xzcat (13 kb)"
//config: bool "xzcat"
//config: default y
//config: help
//config: Alias to "unxz -c".
//config: Alias to "unxz -c".
//config:
//config:config XZ
//config: bool "xz -d"
//config: default y
//config: help
//config: Enable this option if you want commands like "xz -d" to work.
//config: IOW: you'll get xz applet, but it will always require -d option.
//config: Enable this option if you want commands like "xz -d" to work.
//config: IOW: you'll get xz applet, but it will always require -d option.
//applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
+15 -17
View File
@@ -6,30 +6,30 @@
* See README and LICENSE files in bz/ directory for more information
* about bzip2 library code.
*/
//config:config BZIP2
//config: bool "bzip2 (18 kb)"
//config: bool "bzip2"
//config: default y
//config: help
//config: bzip2 is a compression utility using the Burrows-Wheeler block
//config: sorting text compression algorithm, and Huffman coding. Compression
//config: is generally considerably better than that achieved by more
//config: conventional LZ77/LZ78-based compressors, and approaches the
//config: performance of the PPM family of statistical compressors.
//config: bzip2 is a compression utility using the Burrows-Wheeler block
//config: sorting text compression algorithm, and Huffman coding. Compression
//config: is generally considerably better than that achieved by more
//config: conventional LZ77/LZ78-based compressors, and approaches the
//config: performance of the PPM family of statistical compressors.
//config:
//config: Unless you have a specific application which requires bzip2, you
//config: should probably say N here.
//config: Unless you have a specific application which requires bzip2, you
//config: should probably say N here.
//config:
//config:config FEATURE_BZIP2_DECOMPRESS
//config: bool "Enable decompression"
//config: default y
//config: depends on BZIP2 || BUNZIP2 || BZCAT
//config: help
//config: Enable -d (--decompress) and -t (--test) options for bzip2.
//config: This will be automatically selected if bunzip2 or bzcat is
//config: enabled.
//config: Enable -d (--decompress) and -t (--test) options for bzip2.
//config: This will be automatically selected if bunzip2 or bzcat is
//config: enabled.
//applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_BZIP2) += bzip2.o
//usage:#define bzip2_trivial_usage
@@ -195,11 +195,9 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
* --best alias for -9
*/
opt = getopt32(argv, "^"
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
"cfkv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs"
"\0" "s2" /* -s means -2 (compatibility) */
);
opt_complementary = "s2"; /* -s means -2 (compatibility) */
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfkv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs");
#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */
if (opt & 0x30) // -d and/or -t
return bunzip2_main(argc, argv);
+19 -19
View File
@@ -10,37 +10,40 @@
* Doesn't check CRC's
* Only supports new ASCII and CRC formats
*/
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
//config:config CPIO
//config: bool "cpio (14 kb)"
//config: bool "cpio"
//config: default y
//config: help
//config: cpio is an archival utility program used to create, modify, and
//config: extract contents from archives.
//config: cpio has 110 bytes of overheads for every stored file.
//config: cpio is an archival utility program used to create, modify, and
//config: extract contents from archives.
//config: cpio has 110 bytes of overheads for every stored file.
//config:
//config: This implementation of cpio can extract cpio archives created in the
//config: "newc" or "crc" format.
//config: This implementation of cpio can extract cpio archives created in the
//config: "newc" or "crc" format.
//config:
//config: Unless you have a specific application which requires cpio, you
//config: should probably say N here.
//config: Unless you have a specific application which requires cpio, you
//config: should probably say N here.
//config:
//config:config FEATURE_CPIO_O
//config: bool "Support archive creation"
//config: default y
//config: depends on CPIO
//config: help
//config: This implementation of cpio can create cpio archives in the "newc"
//config: format only.
//config: This implementation of cpio can create cpio archives in the "newc"
//config: format only.
//config:
//config:config FEATURE_CPIO_P
//config: bool "Support passthrough mode"
//config: default y
//config: depends on FEATURE_CPIO_O
//config: help
//config: Passthrough mode. Rarely used.
//config: Passthrough mode. Rarely used.
//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CPIO) += cpio.o
//usage:#define cpio_trivial_usage
@@ -139,10 +142,6 @@
-u, --unconditional Replace all files unconditionally
*/
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
enum {
OPT_EXTRACT = (1 << 0),
OPT_TEST = (1 << 1),
@@ -361,8 +360,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
char *cpio_owner;
IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
unsigned opt;
#if ENABLE_LONG_OPTS
const char *long_opts =
applet_long_options =
"extract\0" No_argument "i"
"list\0" No_argument "t"
#if ENABLE_FEATURE_CPIO_O
@@ -390,9 +390,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
/* -L makes sense only with -o or -p */
#if !ENABLE_FEATURE_CPIO_O
opt = getopt32long(argv, OPTION_STR, long_opts, &cpio_filename, &cpio_owner);
opt = getopt32(argv, OPTION_STR, &cpio_filename, &cpio_owner);
#else
opt = getopt32long(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), long_opts,
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"),
&cpio_filename, &cpio_owner, &cpio_fmt);
#endif
argv += optind;
+8 -7
View File
@@ -25,19 +25,19 @@
* bugs that need to be fixed
* - (unknown, please let me know when you find any)
*/
//config:config DPKG
//config: bool "dpkg (44 kb)"
//config: bool "dpkg"
//config: default y
//config: select FEATURE_SEAMLESS_GZ
//config: help
//config: dpkg is a medium-level tool to install, build, remove and manage
//config: Debian packages.
//config: dpkg is a medium-level tool to install, build, remove and manage
//config: Debian packages.
//config:
//config: This implementation of dpkg has a number of limitations,
//config: you should use the official dpkg if possible.
//config: This implementation of dpkg has a number of limitations,
//config: you should use the official dpkg if possible.
//applet:IF_DPKG(APPLET(dpkg, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_DPKG) += dpkg.o
//usage:#define dpkg_trivial_usage
@@ -1766,7 +1766,8 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
INIT_G();
opt = getopt32long(argv, "CilPruF:", dpkg_longopts, &str_f);
IF_LONG_OPTS(applet_long_options = dpkg_longopts);
opt = getopt32(argv, "CilPruF:", &str_f);
argv += optind;
//if (opt & OPT_configure) ... // -C
if (opt & OPT_force) { // -F (--force in official dpkg)
+7 -7
View File
@@ -4,17 +4,18 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DPKG_DEB
//config: bool "dpkg_deb"
//config: default y
//config: select FEATURE_SEAMLESS_GZ
//config: help
//config: dpkg-deb unpacks and provides information about Debian archives.
//config: dpkg-deb unpacks and provides information about Debian archives.
//config:
//config: This implementation of dpkg-deb cannot pack archives.
//config: This implementation of dpkg-deb cannot pack archives.
//config:
//config: Unless you have a specific application which requires dpkg-deb,
//config: say N here.
//config: Unless you have a specific application which requires dpkg-deb,
//config: say N here.
//applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb))
@@ -79,9 +80,8 @@ int dpkg_deb_main(int argc UNUSED_PARAM, char **argv)
#endif
/* Must have 1 or 2 args */
opt = getopt32(argv, "^" "cefXx"
"\0" "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"
);
opt_complementary = "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
opt = getopt32(argv, "cefXx");
argv += optind;
//argc -= optind;
+19 -20
View File
@@ -36,12 +36,13 @@ a: 85.1% -- replaced with a.gz
gzip: bogus: No such file or directory
aa: 85.1% -- replaced with aa.gz
*/
//config:config GZIP
//config: bool "gzip (19 kb)"
//config: bool "gzip"
//config: default y
//config: help
//config: gzip is used to compress files.
//config: It's probably the most widely used UNIX compression program.
//config: gzip is used to compress files.
//config: It's probably the most widely used UNIX compression program.
//config:
//config:config FEATURE_GZIP_LONG_OPTIONS
//config: bool "Enable long options"
@@ -54,33 +55,32 @@ aa: 85.1% -- replaced with aa.gz
//config: range 0 2
//config: depends on GZIP
//config: help
//config: Enable big memory options for gzip.
//config: 0: small buffers, small hash-tables
//config: 1: larger buffers, larger hash-tables
//config: 2: larger buffers, largest hash-tables
//config: Larger models may give slightly better compression
//config: Enable big memory options for gzip.
//config: 0: small buffers, small hash-tables
//config: 1: larger buffers, larger hash-tables
//config: 2: larger buffers, largest hash-tables
//config: Larger models may give slightly better compression
//config:
//config:config FEATURE_GZIP_LEVELS
//config: bool "Enable compression levels"
//config: default n
//config: depends on GZIP
//config: help
//config: Enable support for compression levels 4-9. The default level
//config: is 6. If levels 1-3 are specified, 4 is used.
//config: If this option is not selected, -N options are ignored and -9
//config: is used.
//config: Enable support for compression levels 4-9. The default level
//config: is 6. If levels 1-3 are specified, 4 is used.
//config: If this option is not selected, -N options are ignored and -9
//config: is used.
//config:
//config:config FEATURE_GZIP_DECOMPRESS
//config: bool "Enable decompression"
//config: default y
//config: depends on GZIP || GUNZIP || ZCAT
//config: help
//config: Enable -d (--decompress) and -t (--test) options for gzip.
//config: This will be automatically selected if gunzip or zcat is
//config: enabled.
//config: Enable -d (--decompress) and -t (--test) options for gzip.
//config: This will be automatically selected if gunzip or zcat is
//config: enabled.
//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_GZIP) += gzip.o
//usage:#define gzip_trivial_usage
@@ -2216,12 +2216,11 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
+ sizeof(struct globals));
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
opt = getopt32long(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789", gzip_longopts);
#else
opt = getopt32(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789");
applet_long_options = gzip_longopts;
#endif
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789");
#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */
if (opt & 0x30) // -d and/or -t
return gunzip_main(argc, argv);
-2
View File
@@ -11,8 +11,6 @@ COMMON_FILES:= \
data_skip.o \
data_extract_all.o \
data_extract_to_stdout.o \
\
unsafe_symlink_target.o \
\
filter_accept_all.o \
filter_accept_list.o \
+1
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+1
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+24 -32
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
@@ -107,7 +108,9 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
}
else if (existing_sb.st_mtime >= file_header->mtime) {
if (!S_ISDIR(file_header->mode)) {
if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
&& !S_ISDIR(file_header->mode)
) {
bb_error_msg("%s not created: newer or "
"same age file exists", dst_name);
}
@@ -123,11 +126,12 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
/* Handle hard links separately */
if (hard_link) {
res = link(hard_link, dst_name);
if (res != 0) {
if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
/* shared message */
bb_perror_msg("can't create %slink '%s' to '%s'",
"hard", dst_name, hard_link
);
bb_perror_msg("can't create %slink "
"%s to %s", "hard",
dst_name,
hard_link);
}
/* Hardlinks have no separate mode/ownership, skip chown/chmod */
goto ret;
@@ -163,9 +167,10 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
case S_IFDIR:
res = mkdir(dst_name, file_header->mode);
if ((res != 0)
if ((res == -1)
&& (errno != EISDIR) /* btw, Linux doesn't return this */
&& (errno != EEXIST)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("can't make dir %s", dst_name);
}
@@ -173,38 +178,25 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
case S_IFLNK:
/* Symlink */
//TODO: what if file_header->link_target == NULL (say, corrupted tarball?)
/* To avoid a directory traversal attack via symlinks,
* do not restore symlinks with ".." components
* or symlinks starting with "/", unless a magic
* envvar is set.
*
* For example, consider a .tar created via:
* $ tar cvf bug.tar anything.txt
* $ ln -s /tmp symlink
* $ tar --append -f bug.tar symlink
* $ rm symlink
* $ mkdir symlink
* $ tar --append -f bug.tar symlink/evil.py
*
* This will result in an archive that contains:
* $ tar --list -f bug.tar
* anything.txt
* symlink [-> /tmp]
* symlink/evil.py
*
* Untarring bug.tar would otherwise place evil.py in '/tmp'.
*/
create_or_remember_symlink(&archive_handle->symlink_placeholders,
file_header->link_target,
dst_name);
res = symlink(file_header->link_target, dst_name);
if (res != 0
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
/* shared message */
bb_perror_msg("can't create %slink "
"%s to %s", "sym",
dst_name,
file_header->link_target);
}
break;
case S_IFSOCK:
case S_IFBLK:
case S_IFCHR:
case S_IFIFO:
res = mknod(dst_name, file_header->mode, file_header->device);
if (res != 0) {
if ((res == -1)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("can't create node %s", dst_name);
}
break;
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+1
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+22 -29
View File
@@ -1,14 +1,14 @@
/* vi: set sw=4 ts=4: */
/*
* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net).
*
* Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
* which also acknowledges contributions by Mike Burrows, David Wheeler,
* Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
* Robert Sedgewick, and Jon L. Bentley.
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net).
Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
which also acknowledges contributions by Mike Burrows, David Wheeler,
Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
Robert Sedgewick, and Jon L. Bentley.
Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/*
Size and speed optimizations by Manuel Novoa III (mjn3@codepoet.org).
@@ -38,6 +38,7 @@
Manuel
*/
#include "libbb.h"
#include "bb_archive.h"
@@ -156,15 +157,15 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
static int get_next_block(bunzip_data *bd)
{
struct group_data *hufGroup;
int groupCount, *base, *limit, selector,
i, j, symCount, symTotal, nSelectors, byteCount[256];
int dbufCount, dbufSize, groupCount, *base, *limit, selector,
i, j, runPos, symCount, symTotal, nSelectors, byteCount[256];
int runCnt = runCnt; /* for compiler */
uint8_t uc, symToByte[256], mtfSymbol[256], *selectors;
uint32_t *dbuf;
unsigned origPtr, t;
unsigned dbufCount, runPos;
unsigned runCnt = runCnt; /* for compiler */
dbuf = bd->dbuf;
dbufSize = bd->dbufSize;
selectors = bd->selectors;
/* In bbox, we are ok with aborting through setjmp which is set up in start_bunzip */
@@ -187,7 +188,7 @@ static int get_next_block(bunzip_data *bd)
it didn't actually work. */
if (get_bits(bd, 1)) return RETVAL_OBSOLETE_INPUT;
origPtr = get_bits(bd, 24);
if (origPtr > bd->dbufSize) return RETVAL_DATA_ERROR;
if ((int)origPtr > dbufSize) return RETVAL_DATA_ERROR;
/* mapping table: if some byte values are never used (encoding things
like ascii text), the compression code removes the gaps to have fewer
@@ -435,14 +436,7 @@ static int get_next_block(bunzip_data *bd)
symbols, but a run of length 0 doesn't mean anything in this
context). Thus space is saved. */
runCnt += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */
//The 32-bit overflow of runCnt wasn't yet seen, but probably can happen.
//This would be the fix (catches too large count way before it can overflow):
// if (runCnt > bd->dbufSize) {
// dbg("runCnt:%u > dbufSize:%u RETVAL_DATA_ERROR",
// runCnt, bd->dbufSize);
// return RETVAL_DATA_ERROR;
// }
if (runPos < bd->dbufSize) runPos <<= 1;
if (runPos < dbufSize) runPos <<= 1;
goto end_of_huffman_loop;
}
@@ -452,15 +446,14 @@ static int get_next_block(bunzip_data *bd)
literal used is the one at the head of the mtfSymbol array.) */
if (runPos != 0) {
uint8_t tmp_byte;
if (dbufCount + runCnt > bd->dbufSize) {
dbg("dbufCount:%u+runCnt:%u %u > dbufSize:%u RETVAL_DATA_ERROR",
dbufCount, runCnt, dbufCount + runCnt, bd->dbufSize);
if (dbufCount + runCnt > dbufSize) {
dbg("dbufCount:%d+runCnt:%d %d > dbufSize:%d RETVAL_DATA_ERROR",
dbufCount, runCnt, dbufCount + runCnt, dbufSize);
return RETVAL_DATA_ERROR;
}
tmp_byte = symToByte[mtfSymbol[0]];
byteCount[tmp_byte] += runCnt;
while ((int)--runCnt >= 0)
dbuf[dbufCount++] = (uint32_t)tmp_byte;
while (--runCnt >= 0) dbuf[dbufCount++] = (uint32_t)tmp_byte;
runPos = 0;
}
@@ -474,7 +467,7 @@ static int get_next_block(bunzip_data *bd)
first symbol in the mtf array, position 0, would have been handled
as part of a run above. Therefore 1 unused mtf position minus
2 non-literal nextSym values equals -1.) */
if (dbufCount >= bd->dbufSize) return RETVAL_DATA_ERROR;
if (dbufCount >= dbufSize) return RETVAL_DATA_ERROR;
i = nextSym - 1;
uc = mtfSymbol[i];
+1
View File
@@ -32,6 +32,7 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include <setjmp.h>
#include "libbb.h"
#include "bb_archive.h"
+4 -2
View File
@@ -1,10 +1,10 @@
/* vi: set sw=4 ts=4: */
/*
* uncompress for busybox -- (c) 2002 Robert Griebl
/* uncompress for busybox -- (c) 2002 Robert Griebl
*
* based on the original compress42.c source
* (see disclaimer below)
*/
/* (N)compress42.c - File compression ala IEEE Computer, Mar 1992.
*
* Authors:
@@ -21,7 +21,9 @@
* marc@suse.de : a small security fix for a buffer overflow
*
* [... History snipped ...]
*
*/
#include "libbb.h"
#include "bb_archive.h"
+1 -5
View File
@@ -450,12 +450,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
IF_NOT_FEATURE_LZMA_FAST(string:)
do {
uint32_t pos = buffer_pos - rep0;
if ((int32_t)pos < 0) {
if ((int32_t)pos < 0)
pos += header.dict_size;
/* bug 10436 has an example file where this triggers: */
if ((int32_t)pos < 0)
goto bad;
}
previous_byte = buffer[pos];
IF_NOT_FEATURE_LZMA_FAST(one_byte2:)
buffer[buffer_pos++] = previous_byte;
+5 -10
View File
@@ -27,16 +27,11 @@ static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
return ~crc32_block_endian0(~crc, buf, size, global_crc32_table);
}
/* We use arch-optimized unaligned fixed-endian accessors.
* They have been moved to libbb (proved to be useful elsewhere as well),
* just check that we have them defined:
*/
#if !defined(get_unaligned_le32) \
|| !defined(get_unaligned_be32) \
|| !defined(put_unaligned_le32) \
|| !defined(put_unaligned_be32)
# error get_unaligned_le32 accessors are not defined
#endif
/* We use arch-optimized unaligned accessors */
#define get_unaligned_le32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_LE32(v); })
#define get_unaligned_be32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_BE32(v); })
#define put_unaligned_le32(val, buf) move_to_unaligned32(buf, SWAP_LE32(val))
#define put_unaligned_be32(val, buf) move_to_unaligned32(buf, SWAP_BE32(val))
#include "unxz/xz_dec_bcj.c"
#include "unxz/xz_dec_lzma2.c"
+1
View File
@@ -4,6 +4,7 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+1
View File
@@ -4,6 +4,7 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
@@ -1,9 +1,10 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (C) 2002 by Glenn McGrath
* Copyright (C) 2002 by Glenn McGrath
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
@@ -4,6 +4,7 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+1
View File
@@ -4,6 +4,7 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include <fnmatch.h>
#include "libbb.h"
#include "bb_archive.h"
+2 -2
View File
@@ -1,9 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright 2001 Glenn McGrath.
/* Copyright 2001 Glenn McGrath.
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
#include "ar.h"
+2 -2
View File
@@ -1,9 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright 2002 Laurence Anderson
/* Copyright 2002 Laurence Anderson
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+26 -27
View File
@@ -1,6 +1,5 @@
/* vi: set sw=4 ts=4: */
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
/* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*
* FIXME:
* In privileged mode if uname and gname map to a uid and gid then use the
@@ -11,6 +10,7 @@
* Opengroup's ustar interchange format,
* http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html
*/
#include "libbb.h"
#include "bb_archive.h"
@@ -152,7 +152,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
file_header_t *file_header = archive_handle->file_header;
struct tar_header_t tar;
char *cp;
int tar_typeflag; /* can be "char", "int" seems give smaller code */
int i, sum_u, sum;
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
int sum_s;
@@ -254,10 +253,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
* POSIX says that checksum is done on unsigned bytes, but
* Sun and HP-UX gets it wrong... more details in
* GNU tar source. */
sum_u = ' ' * sizeof(tar.chksum);
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
sum_s = sum_u;
sum_s = ' ' * sizeof(tar.chksum);
#endif
sum_u = ' ' * sizeof(tar.chksum);
for (i = 0; i < 148; i++) {
sum_u += ((unsigned char*)&tar)[i];
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
@@ -270,22 +269,27 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
sum_s += ((signed char*)&tar)[i];
#endif
}
/* Most tarfiles have tar.chksum NUL or space terminated, but
* github.com decided to be "special" and have unterminated field:
* 0090: 30343300 30303031 33323731 30000000 |043.000132710...|
* ^^^^^^^^|
* Need to use GET_OCTAL. This overwrites tar.typeflag ---+
* (the '0' char immediately after chksum in example above) with NUL.
*/
tar_typeflag = (uint8_t)tar.typeflag; /* save it */
sum = GET_OCTAL(tar.chksum);
if (sum_u != sum
IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)
) {
/* This field does not need special treatment (getOctal) */
{
char *endp; /* gcc likes temp var for &endp */
sum = strtoul(tar.chksum, &endp, 8);
if ((*endp != '\0' && *endp != ' ')
|| (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
) {
bb_error_msg_and_die("invalid tar header checksum");
}
}
/* don't use xstrtoul, tar.chksum may have leading spaces */
sum = strtoul(tar.chksum, NULL, 8);
if (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) {
bb_error_msg_and_die("invalid tar header checksum");
}
/* GET_OCTAL trashes subsequent field, therefore we call it
/* 0 is reserved for high perf file, treat as normal file */
if (!tar.typeflag) tar.typeflag = '0';
parse_names = (tar.typeflag >= '0' && tar.typeflag <= '7');
/* getOctal trashes subsequent field, therefore we call it
* on fields in reverse order */
if (tar.devmajor[0]) {
char t = tar.prefix[0];
@@ -295,11 +299,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
file_header->device = makedev(major, minor);
tar.prefix[0] = t;
}
/* 0 is reserved for high perf file, treat as normal file */
if (tar_typeflag == '\0') tar_typeflag = '0';
parse_names = (tar_typeflag >= '0' && tar_typeflag <= '7');
file_header->link_target = NULL;
if (!p_linkname && parse_names && tar.linkname[0]) {
file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname));
@@ -333,7 +332,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* Set bits 12-15 of the files mode */
/* (typeflag was not trashed because chksum does not use getOctal) */
switch (tar_typeflag) {
switch (tar.typeflag) {
case '1': /* hardlink */
/* we mark hardlinks as regular files with zero size and a link name */
file_header->mode |= S_IFREG;
@@ -382,7 +381,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
case 'x': { /* pax extended header */
if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
goto skip_ext_hdr;
process_pax_hdr(archive_handle, file_header->size, (tar_typeflag == 'g'));
process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
goto again_after_align;
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
/* See http://www.gnu.org/software/tar/manual/html_node/Extensions.html */
@@ -420,7 +419,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
skip_ext_hdr:
{
off_t sz;
bb_error_msg("warning: skipping header '%c'", tar_typeflag);
bb_error_msg("warning: skipping header '%c'", tar.typeflag);
sz = (file_header->size + 511) & ~(off_t)511;
archive_handle->offset += sz;
sz >>= 9; /* sz /= 512 but w/o contortions for signed div */
@@ -430,7 +429,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
goto again_after_align;
}
default:
bb_error_msg_and_die("unknown typeflag: 0x%x", tar_typeflag);
bb_error_msg_and_die("unknown typeflag: 0x%x", tar.typeflag);
}
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
+1
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+1
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
@@ -5,6 +5,7 @@
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+1
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+1
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+14 -29
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
@@ -224,22 +225,6 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
return xstate;
}
static void fork_transformer_and_free(transformer_state_t *xstate)
{
# if BB_MMU
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
# else
/* NOMMU version of fork_transformer execs
* an external unzipper that wants
* file position at the start of the file.
*/
xlseek(xstate->src_fd, - xstate->signature_skipped, SEEK_CUR);
xstate->signature_skipped = 0;
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
# endif
free(xstate);
}
/* Used by e.g. rpm which gives us a fd without filename,
* thus we can't guess the format from filename's extension.
*/
@@ -247,25 +232,25 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
{
transformer_state_t *xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
if (!xstate->xformer) {
if (!xstate || !xstate->xformer) {
free(xstate);
return 1;
}
fork_transformer_and_free(xstate);
# if BB_MMU
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
# else
/* NOMMU version of fork_transformer execs
* an external unzipper that wants
* file position at the start of the file.
*/
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
xstate->signature_skipped = 0;
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
# endif
free(xstate);
return 0;
}
#if ENABLE_FEATURE_SEAMLESS_LZMA
/* ...and custom version for LZMA */
void FAST_FUNC setup_lzma_on_fd(int fd)
{
transformer_state_t *xstate = xzalloc(sizeof(*xstate));
xstate->src_fd = fd;
xstate->xformer = unpack_lzma_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "unlzma";)
fork_transformer_and_free(xstate);
}
#endif
static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed)
{
+1
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+1
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
+1
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
#include "ar.h"
+1
View File
@@ -2,6 +2,7 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
@@ -1,41 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders,
const char *target,
const char *linkname)
{
if (target[0] == '/' || strstr(target, "..")) {
llist_add_to(symlink_placeholders,
xasprintf("%s%c%s", linkname, '\0', target)
);
return;
}
if (symlink(target, linkname) != 0) {
/* shared message */
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
"sym", linkname, target
);
}
}
void FAST_FUNC create_symlinks_from_list(llist_t *list)
{
while (list) {
char *target;
target = list->data + strlen(list->data) + 1;
if (symlink(target, list->data)) {
/* shared message */
bb_error_msg_and_die("can't create %slink '%s' to '%s'",
"sym",
list->data, target
);
}
list = list->link;
}
}
+11 -11
View File
@@ -24,38 +24,38 @@
"Minimalized" for busybox by Alain Knaff
*/
//config:config LZOP
//config: bool "lzop (13 kb)"
//config: bool "lzop"
//config: default y
//config: help
//config: Lzop compression/decompresion.
//config: Lzop compression/decompresion.
//config:
//config:config UNLZOP
//config: bool "unlzop (13 kb)"
//config: bool "unlzop"
//config: default n # INCOMPAT: upstream lzop does not provide such tool
//config: help
//config: Lzop decompresion.
//config: Lzop decompresion.
//config:
//config:config LZOPCAT
//config: bool "lzopcat (13 kb)"
//config: bool "lzopcat"
//config: default n # INCOMPAT: upstream lzop does not provide such tool
//config: help
//config: Alias to "lzop -dc".
//config: Alias to "unlzop -c".
//config:
//config:config LZOP_COMPR_HIGH
//config: bool "lzop compression levels 7,8,9 (not very useful)"
//config: default n
//config: depends on LZOP || UNLZOP || LZOPCAT
//config: help
//config: High levels (7,8,9) of lzop compression. These levels
//config: are actually slower than gzip at equivalent compression ratios
//config: and take up 3.2K of code.
//config: High levels (7,8,9) of lzop compression. These levels
//config: are actually slower than gzip at equivalent compression ratios
//config: and take up 3.2K of code.
//applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_UNLZOP( APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop))
//applet:IF_LZOPCAT(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat))
//kbuild:lib-$(CONFIG_LZOP) += lzop.o
//kbuild:lib-$(CONFIG_UNLZOP) += lzop.o
//kbuild:lib-$(CONFIG_LZOPCAT) += lzop.o
@@ -1138,7 +1138,7 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
/* -U is "anti -k", invert bit for bbunpack(): */
option_mask32 ^= OPT_KEEP;
/* -k disables -U (if any): */
/* opt_complementary "k-U"? - nope, only handles -Uk, not -kU */
/* opt_complementary = "k-U"; - nope, only handles -Uk, not -kU */
if (option_mask32 & OPT_k)
option_mask32 |= OPT_KEEP;
+129 -283
View File
@@ -6,16 +6,28 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config RPM
//config: bool "rpm (33 kb)"
//config: bool "rpm"
//config: default y
//config: help
//config: Mini RPM applet - queries and extracts RPM packages.
//config: Mini RPM applet - queries and extracts RPM packages.
//applet:IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_RPM) += rpm.o
//usage:#define rpm_trivial_usage
//usage: "-i PACKAGE.rpm; rpm -qp[ildc] PACKAGE.rpm"
//usage:#define rpm_full_usage "\n\n"
//usage: "Manipulate RPM packages\n"
//usage: "\nCommands:"
//usage: "\n -i Install package"
//usage: "\n -qp Query package"
//usage: "\n -qpi Show information"
//usage: "\n -qpl List contents"
//usage: "\n -qpd List documents"
//usage: "\n -qpc List config files"
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
@@ -56,8 +68,6 @@
#define TAG_DIRINDEXES 1116
#define TAG_BASENAMES 1117
#define TAG_DIRNAMES 1118
#define TAG_PAYLOADCOMPRESSOR 1125
#define RPMFILE_CONFIG (1 << 0)
#define RPMFILE_DOC (1 << 1)
@@ -81,145 +91,148 @@ typedef struct {
struct globals {
void *map;
rpm_index *mytags;
rpm_index **mytags;
int tagcount;
unsigned mapsize, pagesize;
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
static int rpm_gettags(const char *filename)
static void extract_cpio(int fd, const char *source_rpm)
{
rpm_index *tags;
int fd;
unsigned pass, idx;
unsigned storepos;
archive_handle_t *archive_handle;
if (!filename) { /* rpm2cpio w/o filename? */
filename = bb_msg_standard_output;
fd = 0;
} else {
fd = xopen(filename, O_RDONLY);
}
if (source_rpm != NULL) {
/* Binary rpm (it was built from some SRPM), install to root */
xchdir("/");
} /* else: SRPM, install to current dir */
/* Initialize */
archive_handle = init_handle();
archive_handle->seek = seek_by_read;
archive_handle->action_data = data_extract_all;
#if 0 /* For testing (rpm -i only lists the files in internal cpio): */
archive_handle->action_header = header_list;
archive_handle->action_data = data_skip;
#endif
archive_handle->ah_flags = ARCHIVE_RESTORE_DATE | ARCHIVE_CREATE_LEADING_DIRS
/* compat: overwrite existing files.
* try "rpm -i foo.src.rpm" few times in a row -
* standard rpm will not complain.
*/
| ARCHIVE_REPLACE_VIA_RENAME;
archive_handle->src_fd = fd;
/*archive_handle->offset = 0; - init_handle() did it */
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1);
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
}
static rpm_index **rpm_gettags(int fd, int *num_tags)
{
/* We should never need more than 200 (shrink via realloc later) */
rpm_index **tags = xzalloc(200 * sizeof(tags[0]));
int pass, tagindex = 0;
xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
storepos = xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
G.tagcount = 0;
tags = NULL;
idx = 0;
/* 1st pass is the signature headers, 2nd is the main stuff */
for (pass = 0; pass < 2; pass++) {
struct rpm_header header;
unsigned cnt;
rpm_index *tmpindex;
int storepos;
xread(fd, &header, sizeof(header));
if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER))
bb_error_msg_and_die("invalid RPM header magic in '%s'", filename);
return NULL; /* Invalid magic, or not version 1 */
header.size = ntohl(header.size);
cnt = ntohl(header.entries);
storepos += sizeof(header) + cnt * 16;
header.entries = ntohl(header.entries);
storepos = xlseek(fd, 0, SEEK_CUR) + header.entries * 16;
G.tagcount += cnt;
tags = xrealloc(tags, sizeof(tags[0]) * G.tagcount);
xread(fd, &tags[idx], sizeof(tags[0]) * cnt);
while (cnt--) {
rpm_index *tag = &tags[idx];
tag->tag = ntohl(tag->tag);
tag->type = ntohl(tag->type);
tag->count = ntohl(tag->count);
tag->offset = storepos + ntohl(tag->offset);
while (header.entries--) {
tmpindex = tags[tagindex++] = xmalloc(sizeof(*tmpindex));
xread(fd, tmpindex, sizeof(*tmpindex));
tmpindex->tag = ntohl(tmpindex->tag);
tmpindex->type = ntohl(tmpindex->type);
tmpindex->count = ntohl(tmpindex->count);
tmpindex->offset = storepos + ntohl(tmpindex->offset);
if (pass == 0)
tag->tag -= 743;
idx++;
tmpindex->tag -= 743;
}
storepos = xlseek(fd, header.size, SEEK_CUR); /* Seek past store */
/* Skip padding to 8 byte boundary after reading signature headers */
if (pass == 0)
while (header.size & 7)
header.size++;
/* Seek past store */
storepos = xlseek(fd, header.size, SEEK_CUR);
xlseek(fd, (-storepos) & 0x7, SEEK_CUR);
}
G.mytags = tags;
/* Map the store */
storepos = (storepos + G.pagesize) & -(int)G.pagesize;
/* remember size for munmap */
G.mapsize = storepos;
/* some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
G.map = mmap(0, storepos, PROT_READ, MAP_PRIVATE, fd, 0);
if (G.map == MAP_FAILED)
bb_perror_msg_and_die("mmap '%s'", filename);
return fd;
/* realloc tags to save space */
tags = xrealloc(tags, tagindex * sizeof(tags[0]));
*num_tags = tagindex;
/* All done, leave the file at the start of the gzipped cpio archive */
return tags;
}
static int bsearch_rpmtag(const void *key, const void *item)
{
int *tag = (int *)key;
rpm_index *tmp = (rpm_index *) item;
return (*tag - tmp->tag);
rpm_index **tmp = (rpm_index **) item;
return (*tag - tmp[0]->tag);
}
static int rpm_getcount(int tag)
{
rpm_index **found;
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
if (!found)
return 0;
return found[0]->count;
}
static char *rpm_getstr(int tag, int itemindex)
{
rpm_index *found;
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(G.mytags[0]), bsearch_rpmtag);
if (!found || itemindex >= found->count)
rpm_index **found;
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
if (!found || itemindex >= found[0]->count)
return NULL;
if (found->type == RPM_STRING_TYPE
|| found->type == RPM_I18NSTRING_TYPE
|| found->type == RPM_STRING_ARRAY_TYPE
if (found[0]->type == RPM_STRING_TYPE
|| found[0]->type == RPM_I18NSTRING_TYPE
|| found[0]->type == RPM_STRING_ARRAY_TYPE
) {
int n;
char *tmpstr = (char *) G.map + found->offset;
char *tmpstr = (char *) G.map + found[0]->offset;
for (n = 0; n < itemindex; n++)
tmpstr = tmpstr + strlen(tmpstr) + 1;
return tmpstr;
}
return NULL;
}
static char *rpm_getstr0(int tag)
{
return rpm_getstr(tag, 0);
}
#if ENABLE_RPM
static int rpm_getint(int tag, int itemindex)
{
rpm_index *found;
rpm_index **found;
char *tmpint;
/* gcc throws warnings here when sizeof(void*)!=sizeof(int) ...
* it's ok to ignore it because tag won't be used as a pointer */
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(G.mytags[0]), bsearch_rpmtag);
if (!found || itemindex >= found->count)
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
if (!found || itemindex >= found[0]->count)
return -1;
tmpint = (char *) G.map + found->offset;
if (found->type == RPM_INT32_TYPE) {
tmpint = (char *) G.map + found[0]->offset;
if (found[0]->type == RPM_INT32_TYPE) {
tmpint += itemindex*4;
return ntohl(*(int32_t*)tmpint);
}
if (found->type == RPM_INT16_TYPE) {
if (found[0]->type == RPM_INT16_TYPE) {
tmpint += itemindex*2;
return ntohs(*(int16_t*)tmpint);
}
if (found->type == RPM_INT8_TYPE) {
if (found[0]->type == RPM_INT8_TYPE) {
tmpint += itemindex;
return *(int8_t*)tmpint;
}
return -1;
}
static int rpm_getcount(int tag)
{
rpm_index *found;
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(G.mytags[0]), bsearch_rpmtag);
if (!found)
return 0;
return found->count;
}
static void fileaction_dobackup(char *filename, int fileref)
{
struct stat oldfile;
@@ -260,103 +273,11 @@ static void loop_through_files(int filetag, void (*fileaction)(char *filename, i
}
}
#if 0 //DEBUG
static void print_all_tags(void)
{
unsigned i = 0;
while (i < G.tagcount) {
rpm_index *tag = &G.mytags[i];
if (tag->type == RPM_STRING_TYPE
|| tag->type == RPM_I18NSTRING_TYPE
|| tag->type == RPM_STRING_ARRAY_TYPE
) {
unsigned n;
char *str = (char *) G.map + tag->offset;
printf("tag[%u] %08x type %08x offset %08x count %d '%s'\n",
i, tag->tag, tag->type, tag->offset, tag->count, str
);
for (n = 1; n < tag->count; n++) {
str += strlen(str) + 1;
printf("\t'%s'\n", str);
}
}
i++;
}
}
#else
#define print_all_tags() ((void)0)
#endif
static void extract_cpio(int fd, const char *source_rpm)
{
archive_handle_t *archive_handle;
if (source_rpm != NULL) {
/* Binary rpm (it was built from some SRPM), install to root */
xchdir("/");
} /* else: SRPM, install to current dir */
/* Initialize */
archive_handle = init_handle();
archive_handle->seek = seek_by_read;
archive_handle->action_data = data_extract_all;
#if 0 /* For testing (rpm -i only lists the files in internal cpio): */
archive_handle->action_header = header_list;
archive_handle->action_data = data_skip;
#endif
archive_handle->ah_flags = ARCHIVE_RESTORE_DATE | ARCHIVE_CREATE_LEADING_DIRS
/* compat: overwrite existing files.
* try "rpm -i foo.src.rpm" few times in a row -
* standard rpm will not complain.
*/
| ARCHIVE_REPLACE_VIA_RENAME;
archive_handle->src_fd = fd;
/*archive_handle->offset = 0; - init_handle() did it */
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1);
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
}
//usage:#define rpm_trivial_usage
//usage: "-i PACKAGE.rpm; rpm -qp[ildc] PACKAGE.rpm"
//usage:#define rpm_full_usage "\n\n"
//usage: "Manipulate RPM packages\n"
//usage: "\nCommands:"
//usage: "\n -i Install package"
//usage: "\n -qp Query package"
//usage: "\n -qpi Show information"
//usage: "\n -qpl List contents"
//usage: "\n -qpd List documents"
//usage: "\n -qpc List config files"
/* RPM version 4.13.0.1:
* Unlike -q, -i seems to imply -p: -i, -ip and -pi work the same.
* OTOH, with -q order is important: "-piq FILE.rpm" works as -qp, not -qpi
* (IOW: shows only package name, not package info).
* "-iq ARG" works as -q: treats ARG as package name, not a file.
*
* "man rpm" on -l option and options implying it:
* -l, --list List files in package.
* -c, --configfiles List only configuration files (implies -l).
* -d, --docfiles List only documentation files (implies -l).
* -L, --licensefiles List only license files (implies -l).
* --dump Dump file information as follows (implies -l):
* path size mtime digest mode owner group isconfig isdoc rdev symlink
* -s, --state Display the states of files in the package (implies -l).
* The state of each file is one of normal, not installed, or replaced.
*
* Looks like we can switch to getopt32 here: in practice, people
* do place -q first if they intend to use it (misinterpreting "-piq" wouldn't matter).
*/
int rpm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int rpm_main(int argc, char **argv)
{
int opt, func = 0;
INIT_G();
G.pagesize = getpagesize();
const unsigned pagesize = getpagesize();
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
switch (opt) {
@@ -368,17 +289,17 @@ int rpm_main(int argc, char **argv)
if (func) bb_show_usage();
func = rpm_query;
break;
case 'p': /* Query a package (IOW: .rpm file, we are not querying RPMDB) */
case 'p': /* Query a package */
func |= rpm_query_package;
break;
case 'l': /* List files in a package */
func |= rpm_query_list;
break;
case 'd': /* List doc files in a package (implies -l) */
case 'd': /* List doc files in a package (implies list) */
func |= rpm_query_list;
func |= rpm_query_list_doc;
break;
case 'c': /* List config files in a package (implies -l) */
case 'c': /* List config files in a package (implies list) */
func |= rpm_query_list;
func |= rpm_query_list_config;
break;
@@ -392,18 +313,24 @@ int rpm_main(int argc, char **argv)
bb_show_usage();
}
for (;;) {
while (*argv) {
int rpm_fd;
unsigned mapsize;
const char *source_rpm;
rpm_fd = rpm_gettags(*argv);
print_all_tags();
rpm_fd = xopen(*argv++, O_RDONLY);
G.mytags = rpm_gettags(rpm_fd, &G.tagcount);
if (!G.mytags)
bb_error_msg_and_die("error reading rpm header");
mapsize = xlseek(rpm_fd, 0, SEEK_CUR);
mapsize = (mapsize + pagesize) & -(int)pagesize;
/* Some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
G.map = mmap(0, mapsize, PROT_READ, MAP_PRIVATE, rpm_fd, 0);
//FIXME: error check?
source_rpm = rpm_getstr0(TAG_SOURCERPM);
source_rpm = rpm_getstr(TAG_SOURCERPM, 0);
if (func & rpm_install) {
/* -i (and not -qi) */
/* Backup any config files */
loop_through_files(TAG_BASENAMES, fileaction_dobackup);
/* Extact the archive */
@@ -411,13 +338,10 @@ int rpm_main(int argc, char **argv)
/* Set the correct file uid/gid's */
loop_through_files(TAG_BASENAMES, fileaction_setowngrp);
}
else
if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
/* -qp */
else if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
if (!(func & (rpm_query_info|rpm_query_list))) {
/* If just a straight query, just give package name */
printf("%s-%s-%s\n", rpm_getstr0(TAG_NAME), rpm_getstr0(TAG_VERSION), rpm_getstr0(TAG_RELEASE));
printf("%s-%s-%s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_RELEASE, 0));
}
if (func & rpm_query_info) {
/* Do the nice printout */
@@ -426,33 +350,30 @@ int rpm_main(int argc, char **argv)
char bdatestring[50];
const char *p;
printf("%-12s: %s\n", "Name" , rpm_getstr0(TAG_NAME));
printf("%-12s: %s\n", "Name" , rpm_getstr(TAG_NAME, 0));
/* TODO compat: add "Epoch" here */
printf("%-12s: %s\n", "Version" , rpm_getstr0(TAG_VERSION));
printf("%-12s: %s\n", "Release" , rpm_getstr0(TAG_RELEASE));
printf("%-12s: %s\n", "Version" , rpm_getstr(TAG_VERSION, 0));
printf("%-12s: %s\n", "Release" , rpm_getstr(TAG_RELEASE, 0));
/* add "Architecture" */
/* printf("%-12s: %s\n", "Install Date", "(not installed)"); - we don't know */
printf("%-12s: %s\n", "Group" , rpm_getstr0(TAG_GROUP));
printf("%-12s: %s\n", "Install Date", "(not installed)");
printf("%-12s: %s\n", "Group" , rpm_getstr(TAG_GROUP, 0));
printf("%-12s: %d\n", "Size" , rpm_getint(TAG_SIZE, 0));
printf("%-12s: %s\n", "License" , rpm_getstr0(TAG_LICENSE));
printf("%-12s: %s\n", "License" , rpm_getstr(TAG_LICENSE, 0));
/* add "Signature" */
printf("%-12s: %s\n", "Source RPM" , source_rpm ? source_rpm : "(none)");
bdate_time = rpm_getint(TAG_BUILDTIME, 0);
bdate_ptm = localtime(&bdate_time);
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm);
printf("%-12s: %s\n", "Build Date" , bdatestring);
printf("%-12s: %s\n", "Build Host" , rpm_getstr0(TAG_BUILDHOST));
p = rpm_getstr0(TAG_PREFIXS);
printf("%-12s: %s\n", "Build Host" , rpm_getstr(TAG_BUILDHOST, 0));
p = rpm_getstr(TAG_PREFIXS, 0);
printf("%-12s: %s\n", "Relocations" , p ? p : "(not relocatable)");
/* add "Packager" */
p = rpm_getstr0(TAG_VENDOR);
if (p) /* rpm 4.13.0.1 does not show "(none)" for Vendor: */
printf("%-12s: %s\n", "Vendor" , p);
p = rpm_getstr0(TAG_URL);
if (p) /* rpm 4.13.0.1 does not show "(none)"/"(null)" for URL: */
printf("%-12s: %s\n", "URL" , p);
printf("%-12s: %s\n", "Summary" , rpm_getstr0(TAG_SUMMARY));
printf("Description :\n%s\n", rpm_getstr0(TAG_DESCRIPTION));
p = rpm_getstr(TAG_VENDOR, 0);
printf("%-12s: %s\n", "Vendor" , p ? p : "(none)");
printf("%-12s: %s\n", "URL" , rpm_getstr(TAG_URL, 0));
printf("%-12s: %s\n", "Summary" , rpm_getstr(TAG_SUMMARY, 0));
printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0));
}
if (func & rpm_query_list) {
int count, it, flags;
@@ -475,85 +396,10 @@ int rpm_main(int argc, char **argv)
rpm_getstr(TAG_BASENAMES, it));
}
}
} else {
/* Unsupported (help text shows what we support) */
bb_show_usage();
}
if (!*++argv)
break;
munmap(G.map, G.mapsize);
munmap(G.map, mapsize);
free(G.mytags);
close(rpm_fd);
}
return 0;
}
#endif /* RPM */
/*
* Mini rpm2cpio implementation for busybox
*
* Copyright (C) 2001 by Laurence Anderson
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config RPM2CPIO
//config: bool "rpm2cpio (20 kb)"
//config: default y
//config: help
//config: Converts a RPM file into a CPIO archive.
//applet:IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_RPM2CPIO) += rpm.o
//usage:#define rpm2cpio_trivial_usage
//usage: "PACKAGE.rpm"
//usage:#define rpm2cpio_full_usage "\n\n"
//usage: "Output a cpio archive of the rpm file"
#if ENABLE_RPM2CPIO
/* No getopt required */
int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
{
const char *str;
int rpm_fd;
INIT_G();
G.pagesize = getpagesize();
rpm_fd = rpm_gettags(argv[1]);
//if (SEAMLESS_COMPRESSION) - we do this at the end instead.
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
// signal(SIGCHLD, check_errors_in_children);
if (ENABLE_FEATURE_SEAMLESS_LZMA
&& (str = rpm_getstr0(TAG_PAYLOADCOMPRESSOR)) != NULL
&& strcmp(str, "lzma") == 0
) {
// lzma compression can't be detected
// set up decompressor without detection
setup_lzma_on_fd(rpm_fd);
} else {
setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
}
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
bb_error_msg_and_die("error unpacking");
if (ENABLE_FEATURE_CLEAN_UP) {
close(rpm_fd);
}
if (SEAMLESS_COMPRESSION) {
check_errors_in_children(0);
return bb_got_signal;
}
return EXIT_SUCCESS;
}
#endif /* RPM2CPIO */
+96
View File
@@ -0,0 +1,96 @@
/* vi: set sw=4 ts=4: */
/*
* Mini rpm2cpio implementation for busybox
*
* Copyright (C) 2001 by Laurence Anderson
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config RPM2CPIO
//config: bool "rpm2cpio"
//config: default y
//config: help
//config: Converts a RPM file into a CPIO archive.
//applet:IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
//usage:#define rpm2cpio_trivial_usage
//usage: "package.rpm"
//usage:#define rpm2cpio_full_usage "\n\n"
//usage: "Output a cpio archive of the rpm file"
#include "libbb.h"
#include "bb_archive.h"
#include "rpm.h"
enum { rpm_fd = STDIN_FILENO };
static unsigned skip_header(void)
{
struct rpm_header header;
unsigned len;
xread(rpm_fd, &header, sizeof(header));
// if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) {
// bb_error_msg_and_die("invalid RPM header magic");
// }
// if (header.version != 1) {
// bb_error_msg_and_die("unsupported RPM header version");
// }
if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) {
bb_error_msg_and_die("invalid RPM header magic or unsupported version");
// ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_MAGICnVER));
}
/* Seek past index entries, and past store */
len = 16 * ntohl(header.entries) + ntohl(header.size);
seek_by_jump(rpm_fd, len);
return sizeof(header) + len;
}
/* No getopt required */
int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
{
struct rpm_lead lead;
unsigned pos;
if (argv[1]) {
xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd);
}
xread(rpm_fd, &lead, sizeof(lead));
/* Just check the magic, the rest is irrelevant */
if (lead.magic != htonl(RPM_LEAD_MAGIC)) {
bb_error_msg_and_die("invalid RPM magic");
}
/* Skip the signature header, align to 8 bytes */
pos = skip_header();
seek_by_jump(rpm_fd, (-(int)pos) & 7);
/* Skip the main header */
skip_header();
//if (SEAMLESS_COMPRESSION)
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
// signal(SIGCHLD, check_errors_in_children);
/* This works, but doesn't report uncompress errors (they happen in child) */
setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
bb_error_msg_and_die("error unpacking");
if (ENABLE_FEATURE_CLEAN_UP) {
close(rpm_fd);
}
if (SEAMLESS_COMPRESSION) {
check_errors_in_children(0);
return bb_got_signal;
}
return EXIT_SUCCESS;
}
+140 -134
View File
@@ -22,13 +22,32 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* TODO: security with -C DESTDIR option can be enhanced.
* Consider tar file created via:
* $ tar cvf bug.tar anything.txt
* $ ln -s /tmp symlink
* $ tar --append -f bug.tar symlink
* $ rm symlink
* $ mkdir symlink
* $ tar --append -f bug.tar symlink/evil.py
*
* This will result in an archive which contains:
* $ tar --list -f bug.tar
* anything.txt
* symlink
* symlink/evil.py
*
* Untarring it puts evil.py in '/tmp' even if the -C DESTDIR is given.
* This doesn't feel right, and IIRC GNU tar doesn't do that.
*/
//config:config TAR
//config: bool "tar (40 kb)"
//config: bool "tar"
//config: default y
//config: help
//config: tar is an archiving program. It's commonly used with gzip to
//config: create compressed archives. It's probably the most widely used
//config: UNIX archive program.
//config: tar is an archiving program. It's commonly used with gzip to
//config: create compressed archives. It's probably the most widely used
//config: UNIX archive program.
//config:
//config:config FEATURE_TAR_LONG_OPTIONS
//config: bool "Enable long options"
@@ -45,35 +64,35 @@
//config: default y
//config: depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ)
//config: help
//config: With this option tar can automatically detect compressed
//config: tarballs. Currently it works only on files (not pipes etc).
//config: With this option tar can automatically detect compressed
//config: tarballs. Currently it works only on files (not pipes etc).
//config:
//config:config FEATURE_TAR_FROM
//config: bool "Enable -X (exclude from) and -T (include from) options"
//config: bool "Enable -X (exclude from) and -T (include from) options)"
//config: default y
//config: depends on TAR
//config: help
//config: If you enable this option you'll be able to specify
//config: a list of files to include or exclude from an archive.
//config: If you enable this option you'll be able to specify
//config: a list of files to include or exclude from an archive.
//config:
//config:config FEATURE_TAR_OLDGNU_COMPATIBILITY
//config: bool "Support old tar header format"
//config: default y
//config: depends on TAR || DPKG
//config: help
//config: This option is required to unpack archives created in
//config: the old GNU format; help to kill this old format by
//config: repacking your ancient archives with the new format.
//config: This option is required to unpack archives created in
//config: the old GNU format; help to kill this old format by
//config: repacking your ancient archives with the new format.
//config:
//config:config FEATURE_TAR_OLDSUN_COMPATIBILITY
//config: bool "Enable untarring of tarballs with checksums produced by buggy Sun tar"
//config: default y
//config: depends on TAR || DPKG
//config: help
//config: This option is required to unpack archives created by some old
//config: version of Sun's tar (it was calculating checksum using signed
//config: arithmetic). It is said to be fixed in newer Sun tar, but "old"
//config: tarballs still exist.
//config: This option is required to unpack archives created by some old
//config: version of Sun's tar (it was calculating checksum using signed
//config: arithmetic). It is said to be fixed in newer Sun tar, but "old"
//config: tarballs still exist.
//config:
//config:config FEATURE_TAR_GNU_EXTENSIONS
//config: bool "Support GNU tar extensions (long filenames)"
@@ -85,18 +104,18 @@
//config: default y
//config: depends on TAR && FEATURE_TAR_LONG_OPTIONS
//config: help
//config: If you enable this option you'll be able to instruct tar to send
//config: the contents of each extracted file to the standard input of an
//config: external program.
//config: If you enable this option you'll be able to instruct tar to send
//config: the contents of each extracted file to the standard input of an
//config: external program.
//config:
//config:config FEATURE_TAR_UNAME_GNAME
//config: bool "Enable use of user and group names"
//config: default y
//config: depends on TAR
//config: help
//config: Enable use of user and group names in tar. This affects contents
//config: listings (-t) and preserving permissions when unpacking (-p).
//config: +200 bytes.
//config: Enable use of user and group names in tar. This affects contents
//config: listings (-t) and preserving permissions when unpacking (-p).
//config: +200 bytes.
//config:
//config:config FEATURE_TAR_NOPRESERVE_TIME
//config: bool "Enable -m (do not preserve time) GNU option"
@@ -108,11 +127,10 @@
//config: default n
//config: depends on TAR && SELINUX
//config: help
//config: With this option busybox supports restoring SELinux labels
//config: when extracting files from tar archives.
//config: With this option busybox supports restoring SELinux labels
//config: when extracting files from tar archives.
//applet:IF_TAR(APPLET(tar, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_TAR) += tar.o
#include <fnmatch.h>
@@ -156,9 +174,7 @@ typedef struct TarBallInfo {
int tarFd; /* Open-for-write file descriptor
* for the tarball */
int verboseFlag; /* Whether to print extra stuff or not */
# if ENABLE_FEATURE_TAR_FROM
const llist_t *excludeList; /* List of files to not include */
# endif
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
//TODO: save only st_dev + st_ino
@@ -280,7 +296,7 @@ static void chksum_and_xwrite(int fd, struct tar_header_t* hp)
xwrite(fd, hp, sizeof(*hp));
}
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
static void writeLongname(int fd, int type, const char *name, int dir)
{
static const struct {
@@ -320,7 +336,7 @@ static void writeLongname(int fd, int type, const char *name, int dir)
memset(&header, 0, size);
xwrite(fd, &header, size);
}
# endif
#endif
/* Write out a tar header for the specified file/directory/whatever */
static int writeTarHeader(struct TarBallInfo *tbInfo,
@@ -349,30 +365,30 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
header.typeflag = LNKTYPE;
strncpy(header.linkname, tbInfo->hlInfo->name,
sizeof(header.linkname));
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
/* Write out long linkname if needed */
if (header.linkname[sizeof(header.linkname)-1])
writeLongname(tbInfo->tarFd, GNULONGLINK,
tbInfo->hlInfo->name, 0);
# endif
#endif
} else if (S_ISLNK(statbuf->st_mode)) {
char *lpath = xmalloc_readlink_or_warn(fileName);
if (!lpath)
return FALSE;
header.typeflag = SYMTYPE;
strncpy(header.linkname, lpath, sizeof(header.linkname));
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
/* Write out long linkname if needed */
if (header.linkname[sizeof(header.linkname)-1])
writeLongname(tbInfo->tarFd, GNULONGLINK, lpath, 0);
# else
#else
/* If it is larger than 100 bytes, bail out */
if (header.linkname[sizeof(header.linkname)-1]) {
free(lpath);
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
return FALSE;
}
# endif
#endif
free(lpath);
} else if (S_ISDIR(statbuf->st_mode)) {
header.typeflag = DIRTYPE;
@@ -402,9 +418,9 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
* It always does unless off_t is wider than 64 bits.
*/
else if (ENABLE_FEATURE_TAR_GNU_EXTENSIONS
# if ULLONG_MAX > 0xffffffffffffffffLL /* 2^64-1 */
#if ULLONG_MAX > 0xffffffffffffffffLL /* 2^64-1 */
&& (filesize <= 0x3fffffffffffffffffffffffLL)
# endif
#endif
) {
/* GNU tar uses "base-256 encoding" for very large numbers.
* Encoding is binary, with highest bit always set as a marker
@@ -431,13 +447,13 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
return FALSE;
}
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
/* Write out long name if needed */
/* (we, like GNU tar, output long linkname *before* long name) */
if (header.name[sizeof(header.name)-1])
writeLongname(tbInfo->tarFd, GNULONGNAME,
header_name, S_ISDIR(statbuf->st_mode));
# endif
#endif
/* Now write the header out to disk */
chksum_and_xwrite(tbInfo->tarFd, &header);
@@ -459,7 +475,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
return TRUE;
}
# if ENABLE_FEATURE_TAR_FROM
#if ENABLE_FEATURE_TAR_FROM
static int exclude_file(const llist_t *excluded_files, const char *file)
{
while (excluded_files) {
@@ -485,9 +501,9 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
return 0;
}
# else
# define exclude_file(excluded_files, file) 0
# endif
#else
# define exclude_file(excluded_files, file) 0
#endif
static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statbuf,
void *userData, int depth UNUSED_PARAM)
@@ -540,12 +556,12 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
if (exclude_file(tbInfo->excludeList, header_name))
return SKIP;
# if !ENABLE_FEATURE_TAR_GNU_EXTENSIONS
#if !ENABLE_FEATURE_TAR_GNU_EXTENSIONS
if (strlen(header_name) >= NAME_SIZE) {
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
return TRUE;
}
# endif
#endif
/* Is this a regular file? */
if (tbInfo->hlInfo == NULL && S_ISREG(statbuf->st_mode)) {
@@ -592,7 +608,7 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
return TRUE;
}
# if SEAMLESS_COMPRESSION
#if SEAMLESS_COMPRESSION
/* Don't inline: vfork scares gcc and pessimizes code */
static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
{
@@ -600,13 +616,13 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
// On Linux, vfork never unpauses parent early, although standard
// allows for that. Do we want to waste bytes checking for it?
# define WAIT_FOR_CHILD 0
# define WAIT_FOR_CHILD 0
volatile int vfork_exec_errno = 0;
struct fd_pair gzipDataPipe;
# if WAIT_FOR_CHILD
# if WAIT_FOR_CHILD
struct fd_pair gzipStatusPipe;
xpiped_pair(gzipStatusPipe);
# endif
# endif
xpiped_pair(gzipDataPipe);
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
@@ -617,12 +633,12 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
/* child */
/* NB: close _first_, then move fds! */
close(gzipDataPipe.wr);
# if WAIT_FOR_CHILD
# if WAIT_FOR_CHILD
close(gzipStatusPipe.rd);
/* gzipStatusPipe.wr will close only on exec -
* parent waits for this close to happen */
fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);
# endif
# endif
xmove_fd(gzipDataPipe.rd, 0);
xmove_fd(tar_fd, 1);
/* exec gzip/bzip2 program/applet */
@@ -634,7 +650,7 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
/* parent */
xmove_fd(gzipDataPipe.wr, tar_fd);
close(gzipDataPipe.rd);
# if WAIT_FOR_CHILD
# if WAIT_FOR_CHILD
close(gzipStatusPipe.wr);
while (1) {
char buf;
@@ -646,52 +662,55 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
continue; /* try it again */
}
close(gzipStatusPipe.rd);
# endif
# endif
if (vfork_exec_errno) {
errno = vfork_exec_errno;
bb_perror_msg_and_die("can't execute '%s'", gzip);
}
}
# endif /* SEAMLESS_COMPRESSION */
#endif /* SEAMLESS_COMPRESSION */
# if !SEAMLESS_COMPRESSION
#if !SEAMLESS_COMPRESSION
/* Do not pass gzip flag to writeTarFile() */
#define writeTarFile(tbInfo, recurseFlags, filelist, gzip) \
writeTarFile(tbInfo, recurseFlags, filelist)
# endif
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
#endif
/* gcc 4.2.1 inlines it, making code bigger */
static NOINLINE int writeTarFile(
struct TarBallInfo *tbInfo,
int recurseFlags,
const llist_t *filelist,
const char *gzip)
static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
int recurseFlags, const llist_t *include,
const llist_t *exclude, const char *gzip)
{
int errorFlag = FALSE;
struct TarBallInfo tbInfo;
/*tbInfo->hlInfoHead = NULL; - already is */
tbInfo.hlInfoHead = NULL;
tbInfo.tarFd = tar_fd;
tbInfo.verboseFlag = verboseFlag;
/* Store the stat info for the tarball's file, so
* can avoid including the tarball into itself.... */
xfstat(tbInfo->tarFd, &tbInfo->tarFileStatBuf, "can't stat tar file");
xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file");
# if SEAMLESS_COMPRESSION
#if SEAMLESS_COMPRESSION
if (gzip)
vfork_compressor(tbInfo->tarFd, gzip);
# endif
vfork_compressor(tbInfo.tarFd, gzip);
#endif
tbInfo.excludeList = exclude;
/* Read the directory/files and iterate over them one at a time */
while (filelist) {
if (!recursive_action(filelist->data, recurseFlags,
writeFileToTarball, writeFileToTarball, tbInfo, 0)
while (include) {
if (!recursive_action(include->data, recurseFlags,
writeFileToTarball, writeFileToTarball, &tbInfo, 0)
) {
errorFlag = TRUE;
}
filelist = filelist->link;
include = include->link;
}
/* Write two empty blocks to the end of the archive */
memset(block_buf, 0, 2*TAR_BLOCK_SIZE);
xwrite(tbInfo->tarFd, block_buf, 2*TAR_BLOCK_SIZE);
xwrite(tbInfo.tarFd, block_buf, 2*TAR_BLOCK_SIZE);
/* To be pedantically correct, we would check if the tarball
* is smaller than 20 tar blocks, and pad it if it was smaller,
@@ -699,16 +718,16 @@ static NOINLINE int writeTarFile(
* so is considered a waste of space */
/* Close so the child process (if any) will exit */
close(tbInfo->tarFd);
close(tbInfo.tarFd);
/* Hang up the tools, close up shop, head home */
if (ENABLE_FEATURE_CLEAN_UP)
freeHardLinkInfo(&tbInfo->hlInfoHead);
freeHardLinkInfo(&tbInfo.hlInfoHead);
if (errorFlag)
bb_error_msg("error exit delayed from previous errors");
# if SEAMLESS_COMPRESSION
#if SEAMLESS_COMPRESSION
if (gzip) {
int status;
if (safe_waitpid(-1, &status, 0) == -1)
@@ -717,25 +736,21 @@ static NOINLINE int writeTarFile(
/* gzip was killed or has exited with nonzero! */
errorFlag = TRUE;
}
# endif
#endif
return errorFlag;
}
#else /* !FEATURE_TAR_CREATE */
# define writeTarFile(...) 0
#endif
#if ENABLE_FEATURE_TAR_FROM
static llist_t *append_file_list_to_list(llist_t *list)
{
FILE *src_stream;
char *line;
llist_t *newlist = NULL;
while (list) {
FILE *src_stream;
char *line;
src_stream = xfopen_stdin(llist_pop(&list));
while ((line = xmalloc_fgetline(src_stream)) != NULL) {
/* kill trailing '/' unless the string is just "/" */
@@ -751,7 +766,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
#endif
//usage:#define tar_trivial_usage
//usage: IF_FEATURE_TAR_CREATE("c|") "x|t [-"
//usage: "-[" IF_FEATURE_TAR_CREATE("c") "xt"
//usage: IF_FEATURE_SEAMLESS_Z("Z")
//usage: IF_FEATURE_SEAMLESS_GZ("z")
//usage: IF_FEATURE_SEAMLESS_XZ("J")
@@ -760,9 +775,8 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: IF_FEATURE_TAR_CREATE("h")
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME("m")
//usage: "vO] "
//usage: "[-f TARFILE] [-C DIR] "
//usage: IF_FEATURE_TAR_FROM("[-T FILE] [-X FILE] "IF_FEATURE_TAR_LONG_OPTIONS("[--exclude PATTERN]... "))
//usage: "[FILE]..."
//usage: IF_FEATURE_TAR_FROM("[-X FILE] [-T FILE] ")
//usage: "[-f TARFILE] [-C DIR] [FILE]..."
//usage:#define tar_full_usage "\n\n"
//usage: IF_FEATURE_TAR_CREATE("Create, extract, ")
//usage: IF_NOT_FEATURE_TAR_CREATE("Extract ")
@@ -773,37 +787,37 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: )
//usage: "\n x Extract"
//usage: "\n t List"
//usage: "\n -f FILE Name of TARFILE ('-' for stdin/out)"
//usage: "\n -C DIR Change to DIR before operation"
//usage: "\n -v Verbose"
//usage: "\n f Name of TARFILE ('-' for stdin/out)"
//usage: "\n C Change to DIR before operation"
//usage: "\n v Verbose"
//usage: IF_FEATURE_SEAMLESS_Z(
//usage: "\n -Z (De)compress using compress"
//usage: "\n Z (De)compress using compress"
//usage: )
//usage: IF_FEATURE_SEAMLESS_GZ(
//usage: "\n -z (De)compress using gzip"
//usage: "\n z (De)compress using gzip"
//usage: )
//usage: IF_FEATURE_SEAMLESS_XZ(
//usage: "\n -J (De)compress using xz"
//usage: "\n J (De)compress using xz"
//usage: )
//usage: IF_FEATURE_SEAMLESS_BZ2(
//usage: "\n -j (De)compress using bzip2"
//usage: "\n j (De)compress using bzip2"
//usage: )
//usage: IF_FEATURE_SEAMLESS_LZMA(
//usage: "\n -a (De)compress using lzma"
//usage: "\n a (De)compress using lzma"
//usage: )
//usage: "\n -O Extract to stdout"
//usage: "\n O Extract to stdout"
//usage: IF_FEATURE_TAR_CREATE(
//usage: "\n -h Follow symlinks"
//usage: "\n h Follow symlinks"
//usage: )
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME(
//usage: "\n -m Don't restore mtime"
//usage: "\n m Don't restore mtime"
//usage: )
//usage: IF_FEATURE_TAR_FROM(
//usage: "\n -T FILE File with names to include"
//usage: "\n -X FILE File with glob patterns to exclude"
//usage: IF_FEATURE_TAR_LONG_OPTIONS(
//usage: "\n --exclude PATTERN Glob pattern to exclude"
//usage: "\n exclude File to exclude"
//usage: )
//usage: "\n X File with names to exclude"
//usage: "\n T File with names to include"
//usage: )
//usage:
//usage:#define tar_example_usage
@@ -927,11 +941,6 @@ static const char tar_longopts[] ALIGN1 =
"exclude\0" Required_argument "\xff"
# endif
;
# define GETOPT32 getopt32long
# define LONGOPTS ,tar_longopts
#else
# define GETOPT32 getopt32
# define LONGOPTS
#endif
int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -957,6 +966,22 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
if (getuid() != 0)
tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM;
/* Prepend '-' to the first argument if required */
opt_complementary = "--:" // first arg is options
"tt:vv:" // count -t,-v
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
"\xff::" // --exclude=PATTERN is a list
#endif
IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
":\xf9+" // --strip-components=NUM
#endif
;
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
applet_long_options = tar_longopts;
#endif
#if ENABLE_DESKTOP
/* Lie to buildroot when it starts asking stupid questions. */
if (argv[1] && strcmp(argv[1], "--version") == 0) {
@@ -967,12 +992,11 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
puts("tar (busybox) " BB_VER);
return 0;
}
#endif
if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
if (argv[1] && argv[1][0] != '-') {
/* Compat:
* 1st argument without dash handles options with parameters
* differently from dashed one: it takes *next argv[i]*
* as parameter even if there are more chars in 1st argument:
* as paramenter even if there are more chars in 1st argument:
* "tar fx TARFILE" - "x" is not taken as f's param
* but is interpreted as -x option
* "tar -xf TARFILE" - dashed equivalent of the above
@@ -992,10 +1016,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
}
*f = 'f';
}
/* Prepend '-' to the first argument */
argv[1] = xasprintf("-%s", argv[1]);
}
opt = GETOPT32(argv, "^"
#endif
opt = getopt32(argv,
"txC:f:Oopvk"
IF_FEATURE_TAR_CREATE( "ch" )
IF_FEATURE_SEAMLESS_BZ2( "j" )
@@ -1006,18 +1029,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
IF_FEATURE_SEAMLESS_Z( "Z" )
IF_FEATURE_TAR_NOPRESERVE_TIME("m")
IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
"\0"
"tt:vv:" // count -t,-v
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
"\xff::" // --exclude=PATTERN is a list
#endif
IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
":\xf9+" // --strip-components=NUM
#endif
LONGOPTS
, &base_dir // -C dir
, &tar_filename // -f filename
IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
@@ -1172,10 +1183,13 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
if (base_dir)
xchdir(base_dir);
//if (SEAMLESS_COMPRESSION)
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
// signal(SIGCHLD, check_errors_in_children);
#if ENABLE_FEATURE_TAR_CREATE
/* Create an archive */
if (opt & OPT_CREATE) {
struct TarBallInfo *tbInfo;
# if SEAMLESS_COMPRESSION
const char *zipMode = NULL;
if (opt & OPT_COMPRESS)
@@ -1188,19 +1202,13 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
zipMode = "lzma";
if (opt & OPT_XZ)
zipMode = "xz";
# endif
tbInfo = xzalloc(sizeof(*tbInfo));
tbInfo->tarFd = tar_handle->src_fd;
tbInfo->verboseFlag = verboseFlag;
# if ENABLE_FEATURE_TAR_FROM
tbInfo->excludeList = tar_handle->reject;
# endif
/* NB: writeTarFile() closes tar_handle->src_fd */
return writeTarFile(tbInfo,
return writeTarFile(tar_handle->src_fd, verboseFlag,
(opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0)
| (opt & OPT_NORECURSION ? 0 : ACTION_RECURSE),
tar_handle->accept,
zipMode);
tar_handle->reject, zipMode);
}
#endif
@@ -1244,8 +1252,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
while (get_header_tar(tar_handle) == EXIT_SUCCESS)
bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */
create_symlinks_from_list(tar_handle->symlink_placeholders);
/* Check that every file that should have been extracted was */
while (tar_handle->accept) {
if (!find_list_entry(tar_handle->reject, tar_handle->accept->data)
-16
View File
@@ -1,16 +0,0 @@
#!/bin/sh
# Makes "symlink attack" tarball (needs GNU tar for --append)
true >anything.txt
tar cvf tar_symlink_attack.tar anything.txt
rm anything.txt
ln -s /tmp symlink
tar --append -f tar_symlink_attack.tar symlink
rm symlink
mkdir symlink
echo BUG >symlink/bb_test_evilfile
tar --append -f tar_symlink_attack.tar symlink/bb_test_evilfile
rm symlink/bb_test_evilfile
rmdir symlink
+58 -166
View File
@@ -17,23 +17,23 @@
* Zip64 + other methods
*/
//config:config UNZIP
//config: bool "unzip (24 kb)"
//config: bool "unzip"
//config: default y
//config: help
//config: unzip will list or extract files from a ZIP archive,
//config: commonly found on DOS/WIN systems. The default behavior
//config: (with no options) is to extract the archive into the
//config: current directory.
//config: unzip will list or extract files from a ZIP archive,
//config: commonly found on DOS/WIN systems. The default behavior
//config: (with no options) is to extract the archive into the
//config: current directory.
//config:
//config:config FEATURE_UNZIP_CDF
//config: bool "Read and use Central Directory data"
//config: default y
//config: depends on UNZIP
//config: help
//config: If you know that you only need to deal with simple
//config: ZIP files without deleted/updated files, SFX archives etc,
//config: you can reduce code size by unselecting this option.
//config: To support less trivial ZIPs, say Y.
//config: If you know that you only need to deal with simple
//config: ZIP files without deleted/updated files, SFX archives etc,
//config: you can reduce code size by unselecting this option.
//config: To support less trivial ZIPs, say Y.
//config:
//config:config FEATURE_UNZIP_BZIP2
//config: bool "Support compression method 12 (bzip2)"
@@ -56,13 +56,12 @@
//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
//usage:#define unzip_trivial_usage
//usage: "[-lnojpq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]"
//usage: "[-lnopq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]"
//usage:#define unzip_full_usage "\n\n"
//usage: "Extract FILEs from ZIP archive\n"
//usage: "\n -l List contents (with -q for short form)"
//usage: "\n -n Never overwrite files (default: ask)"
//usage: "\n -o Overwrite"
//usage: "\n -j Do not restore paths"
//usage: "\n -p Print to stdout"
//usage: "\n -q Quiet"
//usage: "\n -x FILE Exclude FILEs"
@@ -319,12 +318,6 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf)
};
#endif
static void die_if_bad_fnamesize(unsigned sz)
{
if (sz > 0xfff) /* more than 4k?! no funny business please */
bb_error_msg_and_die("bad archive");
}
static void unzip_skip(off_t skip)
{
if (skip != 0)
@@ -342,41 +335,6 @@ static void unzip_create_leading_dirs(const char *fn)
free(name);
}
#if ENABLE_FEATURE_UNZIP_CDF
static void unzip_extract_symlink(llist_t **symlink_placeholders,
zip_header_t *zip,
const char *dst_fn)
{
char *target;
die_if_bad_fnamesize(zip->fmt.ucmpsize);
if (zip->fmt.method == 0) {
/* Method 0 - stored (not compressed) */
target = xzalloc(zip->fmt.ucmpsize + 1);
xread(zip_fd, target, zip->fmt.ucmpsize);
} else {
#if 1
bb_error_msg_and_die("compressed symlink is not supported");
#else
transformer_state_t xstate;
init_transformer_state(&xstate);
xstate.mem_output_size_max = zip->fmt.ucmpsize;
/* ...unpack... */
if (!xstate.mem_output_buf)
WTF();
target = xstate.mem_output_buf;
target = xrealloc(target, xstate.mem_output_size + 1);
target[xstate.mem_output_size] = '\0';
#endif
}
create_or_remember_symlink(symlink_placeholders,
target,
dst_fn);
free(target);
}
#endif
static void unzip_extract(zip_header_t *zip, int dst_fd)
{
transformer_state_t xstate;
@@ -448,32 +406,16 @@ static void my_fgets80(char *buf80)
}
}
static int get_lstat_mode(const char *dst_fn)
{
struct stat stat_buf;
if (lstat(dst_fn, &stat_buf) == -1) {
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
}
/* File does not exist */
return -1;
}
return stat_buf.st_mode;
}
int unzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unzip_main(int argc, char **argv)
{
enum {
OPT_l = (1 << 0),
OPT_x = (1 << 1),
OPT_j = (1 << 2),
};
unsigned opts;
enum { O_PROMPT, O_NEVER, O_ALWAYS };
smallint quiet = 0;
IF_NOT_FEATURE_UNZIP_CDF(const) smallint verbose = 0;
enum { O_PROMPT, O_NEVER, O_ALWAYS };
smallint listing = 0;
smallint overwrite = O_PROMPT;
smallint x_opt_seen;
uint32_t cdf_offset;
unsigned long total_usize;
unsigned long total_size;
@@ -484,11 +426,9 @@ int unzip_main(int argc, char **argv)
llist_t *zaccept = NULL;
llist_t *zreject = NULL;
char *base_dir = NULL;
#if ENABLE_FEATURE_UNZIP_CDF
llist_t *symlink_placeholders = NULL;
#endif
int i;
int i, opt;
char key_buf[80]; /* must match size used by my_fgets80 */
struct stat stat_buf;
/* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP:
*
@@ -531,16 +471,16 @@ int unzip_main(int argc, char **argv)
* 204372 1 file
*/
opts = 0;
x_opt_seen = 0;
/* '-' makes getopt return 1 for non-options */
while ((i = getopt(argc, argv, "-d:lnopqxjv")) != -1) {
switch (i) {
while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) {
switch (opt) {
case 'd': /* Extract to base directory */
base_dir = optarg;
break;
case 'l': /* List */
opts |= OPT_l;
listing = 1;
break;
case 'n': /* Never overwrite existing files */
@@ -560,15 +500,11 @@ int unzip_main(int argc, char **argv)
case 'v': /* Verbose list */
IF_FEATURE_UNZIP_CDF(verbose++;)
opts |= OPT_l;
listing = 1;
break;
case 'x':
opts |= OPT_x;
break;
case 'j':
opts |= OPT_j;
x_opt_seen = 1;
break;
case 1:
@@ -577,7 +513,7 @@ int unzip_main(int argc, char **argv)
/* +5: space for ".zip" and NUL */
src_fn = xmalloc(strlen(optarg) + 5);
strcpy(src_fn, optarg);
} else if (!(opts & OPT_x)) {
} else if (!x_opt_seen) {
/* Include files */
llist_add_to(&zaccept, optarg);
} else {
@@ -645,7 +581,7 @@ int unzip_main(int argc, char **argv)
if (quiet <= 1) { /* not -qq */
if (quiet == 0)
printf("Archive: %s\n", src_fn);
if (opts & OPT_l) {
if (listing) {
puts(verbose ?
" Length Method Size Cmpr Date Time CRC-32 Name\n"
"-------- ------ ------- ---- ---------- ----- -------- ----"
@@ -750,20 +686,6 @@ int unzip_main(int argc, char **argv)
zip.fmt.cmpsize = cdf.fmt.cmpsize;
zip.fmt.ucmpsize = cdf.fmt.ucmpsize;
}
// Seen in some zipfiles: central directory 9 byte extra field contains
// a subfield with ID 0x5455 and 5 data bytes, which is a Unix-style UTC mtime.
// Local header version:
// u16 0x5455 ("UT")
// u16 size (1 + 4 * n)
// u8 flags: bit 0:mtime is present, bit 1:atime is present, bit 2:ctime is present
// u32 mtime
// u32 atime
// u32 ctime
// Central header version:
// u16 0x5455 ("UT")
// u16 size (5 (or 1?))
// u8 flags: bit 0:mtime is present, bit 1:atime is present, bit 2:ctime is present
// u32 mtime (CDF does not store atime/ctime)
# else
/* CDF has the same data as local header, no need to read the latter...
* ...not really. An archive was seen with cdf.extra_len == 6 but
@@ -795,9 +717,9 @@ int unzip_main(int argc, char **argv)
/* Read filename */
free(dst_fn);
die_if_bad_fnamesize(zip.fmt.filename_len);
dst_fn = xzalloc(zip.fmt.filename_len + 1);
xread(zip_fd, dst_fn, zip.fmt.filename_len);
/* Skip extra header bytes */
unzip_skip(zip.fmt.extra_len);
@@ -811,7 +733,7 @@ int unzip_main(int argc, char **argv)
goto skip_cmpsize;
}
if (opts & OPT_l) {
if (listing) {
/* List entry */
char dtbuf[sizeof("mm-dd-yyyy hh:mm")];
sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u",
@@ -868,20 +790,12 @@ int unzip_main(int argc, char **argv)
/* Extracting to STDOUT */
goto do_extract;
}
/* Strip paths (after -l: unzip -lj a.zip lists full names) */
if (opts & OPT_j)
overlapping_strcpy(dst_fn, bb_basename(dst_fn));
/* Did this strip everything ("DIR/" case)? Then skip */
if (!dst_fn[0])
goto skip_cmpsize;
if (last_char_is(dst_fn, '/')) {
int mode;
/* Extract directory */
mode = get_lstat_mode(dst_fn);
if (mode == -1) { /* ENOENT */
if (stat(dst_fn, &stat_buf) == -1) {
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
}
if (!quiet) {
printf(" creating: %s\n", dst_fn);
}
@@ -890,7 +804,7 @@ int unzip_main(int argc, char **argv)
xfunc_die();
}
} else {
if (!S_ISDIR(mode)) {
if (!S_ISDIR(stat_buf.st_mode)) {
bb_error_msg_and_die("'%s' exists but is not a %s",
dst_fn, "directory");
}
@@ -898,33 +812,29 @@ int unzip_main(int argc, char **argv)
goto skip_cmpsize;
}
check_file:
/* Does target file already exist? */
{
int mode = get_lstat_mode(dst_fn);
if (mode == -1) {
/* ENOENT: does not exist */
goto do_open_and_extract;
/* Extract file */
if (stat(dst_fn, &stat_buf) == -1) {
/* File does not exist */
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
}
if (overwrite == O_NEVER) {
goto skip_cmpsize;
}
if (!S_ISREG(mode)) {
fishy:
bb_error_msg_and_die("'%s' exists but is not a %s",
dst_fn, "regular file");
}
if (overwrite == O_ALWAYS) {
goto do_open_and_extract;
}
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
my_fgets80(key_buf);
/* User input could take a long time. Is it still a regular file? */
mode = get_lstat_mode(dst_fn);
if (!S_ISREG(mode))
goto fishy;
goto do_open_and_extract;
}
/* File already exists */
if (overwrite == O_NEVER) {
goto skip_cmpsize;
}
if (!S_ISREG(stat_buf.st_mode)) {
/* File is not regular file */
bb_error_msg_and_die("'%s' exists but is not a %s",
dst_fn, "regular file");
}
/* File is regular file */
if (overwrite == O_ALWAYS)
goto do_open_and_extract;
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
my_fgets80(key_buf);
/* Extract (or skip) it */
switch (key_buf[0]) {
case 'A':
overwrite = O_ALWAYS;
@@ -932,15 +842,9 @@ int unzip_main(int argc, char **argv)
do_open_and_extract:
unzip_create_leading_dirs(dst_fn);
#if ENABLE_FEATURE_UNZIP_CDF
dst_fd = -1;
if (!S_ISLNK(file_mode)) {
dst_fd = xopen3(dst_fn,
O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW,
file_mode);
}
dst_fd = xopen3(dst_fn, O_WRONLY | O_CREAT | O_TRUNC, file_mode);
#else
/* O_NOFOLLOW defends against symlink attacks */
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW);
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
#endif
do_extract:
if (!quiet) {
@@ -948,18 +852,10 @@ int unzip_main(int argc, char **argv)
? " extracting: %s\n"
: */ " inflating: %s\n", dst_fn);
}
#if ENABLE_FEATURE_UNZIP_CDF
if (S_ISLNK(file_mode)) {
if (dst_fd != STDOUT_FILENO) /* not -p? */
unzip_extract_symlink(&symlink_placeholders, &zip, dst_fn);
} else
#endif
{
unzip_extract(&zip, dst_fd);
if (dst_fd != STDOUT_FILENO) {
/* closing STDOUT is potentially bad for future business */
close(dst_fd);
}
unzip_extract(&zip, dst_fd);
if (dst_fd != STDOUT_FILENO) {
/* closing STDOUT is potentially bad for future business */
close(dst_fd);
}
break;
@@ -987,11 +883,7 @@ int unzip_main(int argc, char **argv)
total_entries++;
}
#if ENABLE_FEATURE_UNZIP_CDF
create_symlinks_from_list(symlink_placeholders);
#endif
if ((opts & OPT_l) && quiet <= 1) {
if (listing && quiet <= 1) {
if (!verbose) {
// " Length Date Time Name\n"
// "--------- ---------- ----- ----"
+2
View File
@@ -37,6 +37,7 @@ CONFIG_SELINUX=y
CONFIG_FEATURE_PREFER_APPLETS=y
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
CONFIG_FEATURE_SYSLOG=y
CONFIG_FEATURE_HAVE_RPC=y
#
# Build Options
@@ -890,6 +891,7 @@ CONFIG_HUSH_FUNCTIONS=y
CONFIG_HUSH_LOCAL=y
CONFIG_HUSH_EXPORT_N=y
CONFIG_HUSH_RANDOM_SUPPORT=y
CONFIG_MSH=y
CONFIG_SH_MATH_SUPPORT=y
CONFIG_SH_MATH_SUPPORT_64=y
CONFIG_FEATURE_SH_EXTRA_QUIET=y
+2
View File
@@ -47,6 +47,7 @@ CONFIG_FEATURE_PIDFILE=y
# CONFIG_FEATURE_PREFER_APPLETS is not set
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
# CONFIG_FEATURE_SYSLOG is not set
# CONFIG_FEATURE_HAVE_RPC is not set
#
# Build Options
@@ -897,6 +898,7 @@ CONFIG_FEATURE_SH_IS_NONE=y
# CONFIG_FEATURE_BASH_IS_ASH is not set
# CONFIG_FEATURE_BASH_IS_HUSH is not set
CONFIG_FEATURE_BASH_IS_NONE=y
# CONFIG_MSH is not set
# CONFIG_SH_MATH_SUPPORT is not set
# CONFIG_SH_MATH_SUPPORT_64 is not set
# CONFIG_FEATURE_SH_EXTRA_QUIET is not set
+2
View File
@@ -46,6 +46,7 @@ CONFIG_FEATURE_SUID_CONFIG_QUIET=y
# CONFIG_FEATURE_PREFER_APPLETS is not set
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
CONFIG_FEATURE_SYSLOG=y
CONFIG_FEATURE_HAVE_RPC=y
#
# Build Options
@@ -904,6 +905,7 @@ CONFIG_HUSH_FUNCTIONS=y
CONFIG_HUSH_LOCAL=y
CONFIG_HUSH_EXPORT_N=y
CONFIG_HUSH_RANDOM_SUPPORT=y
CONFIG_MSH=y
CONFIG_SH_MATH_SUPPORT=y
CONFIG_SH_MATH_SUPPORT_64=y
CONFIG_FEATURE_SH_EXTRA_QUIET=y
+2
View File
@@ -49,6 +49,7 @@ CONFIG_LAST_SUPPORTED_WCHAR=0
# CONFIG_FEATURE_PREFER_APPLETS is not set
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
CONFIG_FEATURE_SYSLOG=y
# CONFIG_FEATURE_HAVE_RPC is not set
#
# Build Options
@@ -951,6 +952,7 @@ CONFIG_CTTYHACK=y
# CONFIG_HUSH_RANDOM_SUPPORT is not set
# CONFIG_HUSH_EXPORT_N is not set
# CONFIG_HUSH_MODE_X is not set
# CONFIG_MSH is not set
# CONFIG_FEATURE_SH_IS_ASH is not set
# CONFIG_FEATURE_SH_IS_HUSH is not set
CONFIG_FEATURE_SH_IS_NONE=y
+2
View File
@@ -123,6 +123,7 @@ CONFIG_FEATURE_SUID_CONFIG_QUIET=y
# CONFIG_FEATURE_PREFER_APPLETS is not set
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
CONFIG_FEATURE_SYSLOG=y
# CONFIG_FEATURE_HAVE_RPC is not set
#
# Build Options
@@ -1097,6 +1098,7 @@ CONFIG_CTTYHACK=y
# CONFIG_HUSH_RANDOM_SUPPORT is not set
# CONFIG_HUSH_EXPORT_N is not set
# CONFIG_HUSH_MODE_X is not set
# CONFIG_MSH is not set
CONFIG_FEATURE_SH_IS_ASH=y
# CONFIG_FEATURE_SH_IS_HUSH is not set
# CONFIG_FEATURE_SH_IS_NONE is not set
+2
View File
@@ -49,6 +49,7 @@ CONFIG_LAST_SUPPORTED_WCHAR=0
# CONFIG_FEATURE_PREFER_APPLETS is not set
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
CONFIG_FEATURE_SYSLOG=y
# CONFIG_FEATURE_HAVE_RPC is not set
#
# Build Options
@@ -983,6 +984,7 @@ CONFIG_CTTYHACK=y
# CONFIG_HUSH_RANDOM_SUPPORT is not set
# CONFIG_HUSH_EXPORT_N is not set
# CONFIG_HUSH_MODE_X is not set
# CONFIG_MSH is not set
# CONFIG_FEATURE_SH_IS_ASH is not set
# CONFIG_FEATURE_SH_IS_HUSH is not set
CONFIG_FEATURE_SH_IS_NONE=y
+2
View File
@@ -52,6 +52,7 @@ CONFIG_PID_FILE_PATH=""
# CONFIG_FEATURE_PREFER_APPLETS is not set
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
CONFIG_FEATURE_SYSLOG=y
# CONFIG_FEATURE_HAVE_RPC is not set
#
# Build Options
@@ -1012,6 +1013,7 @@ CONFIG_CTTYHACK=y
# CONFIG_HUSH_RANDOM_SUPPORT is not set
# CONFIG_HUSH_EXPORT_N is not set
# CONFIG_HUSH_MODE_X is not set
# CONFIG_MSH is not set
# CONFIG_FEATURE_SH_IS_ASH is not set
# CONFIG_FEATURE_SH_IS_HUSH is not set
CONFIG_FEATURE_SH_IS_NONE=y
+2
View File
@@ -49,6 +49,7 @@ CONFIG_FEATURE_SUID=y
# CONFIG_FEATURE_PREFER_APPLETS is not set
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
CONFIG_FEATURE_SYSLOG=y
# CONFIG_FEATURE_HAVE_RPC is not set
#
# Build Options
@@ -954,6 +955,7 @@ CONFIG_HUSH_LOCAL=y
CONFIG_HUSH_RANDOM_SUPPORT=y
CONFIG_HUSH_EXPORT_N=y
CONFIG_HUSH_MODE_X=y
# CONFIG_MSH is not set
CONFIG_FEATURE_SH_IS_ASH=y
# CONFIG_FEATURE_SH_IS_HUSH is not set
# CONFIG_FEATURE_SH_IS_NONE is not set
+2
View File
@@ -49,6 +49,7 @@ CONFIG_FEATURE_SUID_CONFIG_QUIET=y
# CONFIG_FEATURE_PREFER_APPLETS is not set
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
CONFIG_FEATURE_SYSLOG=y
# CONFIG_FEATURE_HAVE_RPC is not set
#
# Build Options
@@ -930,6 +931,7 @@ CONFIG_ASH=y
# CONFIG_HUSH_RANDOM_SUPPORT is not set
# CONFIG_HUSH_EXPORT_N is not set
# CONFIG_HUSH_MODE_X is not set
# CONFIG_MSH is not set
CONFIG_FEATURE_SH_IS_ASH=y
# CONFIG_FEATURE_SH_IS_HUSH is not set
# CONFIG_FEATURE_SH_IS_NONE is not set
+4 -4
View File
@@ -7,14 +7,14 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHVT
//config: bool "chvt (2 kb)"
//config: bool "chvt"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program is used to change to another terminal.
//config: Example: chvt 4 (change to terminal /dev/tty4)
//config: This program is used to change to another terminal.
//config: Example: chvt 4 (change to terminal /dev/tty4)
//applet:IF_CHVT(APPLET_NOEXEC(chvt, chvt, BB_DIR_USR_BIN, BB_SUID_DROP, chvt))
//applet:IF_CHVT(APPLET(chvt, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CHVT) += chvt.o
+4 -6
View File
@@ -7,12 +7,12 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CLEAR
//config: bool "clear (tiny)"
//config: bool "clear"
//config: default y
//config: help
//config: This program clears the terminal screen.
//config: This program clears the terminal screen.
//applet:IF_CLEAR(APPLET_NOFORK(clear, clear, BB_DIR_USR_BIN, BB_SUID_DROP, clear))
//applet:IF_CLEAR(APPLET(clear, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CLEAR) += clear.o
@@ -23,11 +23,9 @@
#include "libbb.h"
#define ESC "\033"
int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
/* home; clear to the end of screen */
return full_write1_str(ESC"[H" ESC"[J") != 6;
return full_write1_str("\033[H""\033[J") != 6;
}
+3 -3
View File
@@ -8,13 +8,13 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DEALLOCVT
//config: bool "deallocvt (1.9 kb)"
//config: bool "deallocvt"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program deallocates unused virtual consoles.
//config: This program deallocates unused virtual consoles.
//applet:IF_DEALLOCVT(APPLET_NOEXEC(deallocvt, deallocvt, BB_DIR_USR_BIN, BB_SUID_DROP, deallocvt))
//applet:IF_DEALLOCVT(APPLET(deallocvt, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_DEALLOCVT) += deallocvt.o
+21 -7
View File
@@ -5,17 +5,17 @@
* Copyright (C) Arne Bernin <arne@matrix.loopback.org>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*
*/
//config:config DUMPKMAP
//config: bool "dumpkmap (1.3 kb)"
//config: bool "dumpkmap"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program dumps the kernel's keyboard translation table to
//config: stdout, in binary format. You can then use loadkmap to load it.
//config: This program dumps the kernel's keyboard translation table to
//config: stdout, in binary format. You can then use loadkmap to load it.
//applet:IF_DUMPKMAP(APPLET_NOEXEC(dumpkmap, dumpkmap, BB_DIR_BIN, BB_SUID_DROP, dumpkmap))
/* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */
//applet:IF_DUMPKMAP(APPLET(dumpkmap, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_DUMPKMAP) += dumpkmap.o
@@ -47,6 +47,8 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
{
struct kbentry ke;
int i, j, fd;
#define flags bb_common_bufsiz1
setup_common_bufsiz();
/* When user accidentally runs "dumpkmap FILE"
* instead of "dumpkmap >FILE", we'd dump binary stuff to tty.
@@ -58,8 +60,19 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
fd = get_console_fd_or_die();
#define flags bb_common_bufsiz1
setup_common_bufsiz();
#if 0
write(STDOUT_FILENO, "bkeymap", 7);
/* Here we want to set everything to 0 except for indexes:
* [0-2] [4-6] [8-10] [12]
*/
/*memset(flags, 0x00, MAX_NR_KEYMAPS); - already is */
memset(flags, 0x01, 13);
flags[3] = flags[7] = flags[11] = 0;
/* dump flags */
write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS);
#define flags7 flags
#else
/* Same effect */
/* 0 1 2 3 4 5 6 7 8 9 a b c=12 */
memcpy(flags, "bkeymap\1\1\1\0\1\1\1\0\1\1\1\0\1",
/* Can use sizeof, or sizeof-1. sizeof is even, using that */
@@ -67,6 +80,7 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
);
write(STDOUT_FILENO, flags, 7 + MAX_NR_KEYMAPS);
#define flags7 (flags + 7)
#endif
for (i = 0; i < 13; i++) {
if (flags7[i]) {
+3 -3
View File
@@ -7,13 +7,13 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FGCONSOLE
//config: bool "fgconsole (1.6 kb)"
//config: bool "fgconsole"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program prints active (foreground) console number.
//config: This program prints active (foreground) console number.
//applet:IF_FGCONSOLE(APPLET_NOEXEC(fgconsole, fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP, fgconsole))
//applet:IF_FGCONSOLE(APPLET(fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_FGCONSOLE) += fgconsole.o
+10 -29
View File
@@ -9,25 +9,25 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config KBD_MODE
//config: bool "kbd_mode (4 kb)"
//config: bool "kbd_mode"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program reports and sets keyboard mode.
//config: This program reports and sets keyboard mode.
//applet:IF_KBD_MODE(APPLET_NOEXEC(kbd_mode, kbd_mode, BB_DIR_BIN, BB_SUID_DROP, kbd_mode))
//applet:IF_KBD_MODE(APPLET(kbd_mode, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_KBD_MODE) += kbd_mode.o
//usage:#define kbd_mode_trivial_usage
//usage: "[-a|k|s|u] [-C TTY]"
//usage:#define kbd_mode_full_usage "\n\n"
//usage: "Report or set VT console keyboard mode\n"
//usage: "Report or set the keyboard mode\n"
//usage: "\n -a Default (ASCII)"
//usage: "\n -k Medium-raw (keycode)"
//usage: "\n -k Medium-raw (keyboard)"
//usage: "\n -s Raw (scancode)"
//usage: "\n -u Unicode (utf-8)"
//usage: "\n -C TTY Affect TTY"
//usage: "\n -C TTY Affect TTY instead of /dev/tty"
#include "libbb.h"
#include <linux/kd.h>
@@ -43,20 +43,11 @@ int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
};
int fd;
unsigned opt;
const char *tty_name;
const char *tty_name = CURRENT_TTY;
opt = getopt32(argv, "sakuC:", &tty_name);
if (opt & 0x10) {
opt &= 0xf; /* clear -C bit, see (*) */
fd = xopen_nonblocking(tty_name);
} else {
/* kbd-2.0.3 tries in sequence:
* fd#0, /dev/tty, /dev/tty0.
* get_console_fd_or_die: /dev/console, /dev/tty0, /dev/tty.
* kbd-2.0.3 checks KDGKBTYPE, get_console_fd_or_die checks too.
*/
fd = get_console_fd_or_die();
}
fd = xopen_nonblocking(tty_name);
opt &= 0xf; /* clear -C bit, see (*) */
if (!opt) { /* print current setting */
const char *mode = "unknown";
@@ -71,19 +62,9 @@ int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
mode = "mediumraw (keycode)";
else if (m == K_UNICODE)
mode = "Unicode (UTF-8)";
else if (m == 4 /*K_OFF*/) /* kbd-2.0.3 does not show this mode, says "unknown" */
mode = "off";
printf("The keyboard is in %s mode\n", mode);
} else {
/* here we depend on specific bits assigned to options (*)
* KDSKBMODE constants have these values:
* #define K_RAW 0x00
* #define K_XLATE 0x01
* #define K_MEDIUMRAW 0x02
* #define K_UNICODE 0x03
* #define K_OFF 0x04
* (looks like "-ak" together would cause the same effect as -u)
*/
/* here we depend on specific bits assigned to options (*) */
opt = opt & UNICODE ? 3 : opt >> 1;
/* double cast prevents warnings about widening conversion */
xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt);
+40 -34
View File
@@ -10,33 +10,33 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config LOADFONT
//config: bool "loadfont (5.4 kb)"
//config: bool "loadfont"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads a console font from standard input.
//config: This program loads a console font from standard input.
//config:
//config:config SETFONT
//config: bool "setfont (26 kb)"
//config: bool "setfont"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Allows to load console screen map. Useful for i18n.
//config: Allows to load console screen map. Useful for i18n.
//config:
//config:config FEATURE_SETFONT_TEXTUAL_MAP
//config: bool "Support reading textual screen maps"
//config: default y
//config: depends on SETFONT
//config: help
//config: Support reading textual screen maps.
//config: Support reading textual screen maps.
//config:
//config:config DEFAULT_SETFONT_DIR
//config: string "Default directory for console-tools files"
//config: default ""
//config: depends on SETFONT
//config: help
//config: Directory to use if setfont's params are simple filenames
//config: (not /path/to/file or ./file). Default is "" (no default directory).
//config: Directory to use if setfont's params are simple filenames
//config: (not /path/to/file or ./file). Default is "" (no default directory).
//config:
//config:comment "Common options for loadfont and setfont"
//config: depends on LOADFONT || SETFONT
@@ -51,12 +51,31 @@
//config: default y
//config: depends on LOADFONT || SETFONT
//applet:IF_LOADFONT(APPLET_NOEXEC(loadfont, loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP, loadfont))
//applet:IF_SETFONT(APPLET_NOEXEC(setfont, setfont, BB_DIR_USR_SBIN, BB_SUID_DROP, setfont))
//applet:IF_LOADFONT(APPLET(loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
//applet:IF_SETFONT(APPLET(setfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_LOADFONT) += loadfont.o
//kbuild:lib-$(CONFIG_SETFONT) += loadfont.o
//usage:#define loadfont_trivial_usage
//usage: "< font"
//usage:#define loadfont_full_usage "\n\n"
//usage: "Load a console font from stdin"
/* //usage: "\n -C TTY Affect TTY instead of /dev/tty" */
//usage:
//usage:#define loadfont_example_usage
//usage: "$ loadfont < /etc/i18n/fontname\n"
//usage:
//usage:#define setfont_trivial_usage
//usage: "FONT [-m MAPFILE] [-C TTY]"
//usage:#define setfont_full_usage "\n\n"
//usage: "Load a console font\n"
//usage: "\n -m MAPFILE Load console screen map"
//usage: "\n -C TTY Affect TTY instead of /dev/tty"
//usage:
//usage:#define setfont_example_usage
//usage: "$ setfont -m koi8-r /etc/i18n/fontname\n"
#include "libbb.h"
#include <sys/kd.h>
@@ -333,14 +352,6 @@ static void do_load(int fd, unsigned char *buffer, size_t len)
#if ENABLE_LOADFONT
//usage:#define loadfont_trivial_usage
//usage: "< font"
//usage:#define loadfont_full_usage "\n\n"
//usage: "Load a console font from stdin"
/* //usage: "\n -C TTY Affect TTY instead of /dev/tty" */
//usage:
//usage:#define loadfont_example_usage
//usage: "$ loadfont < /etc/i18n/fontname\n"
int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int loadfont_main(int argc UNUSED_PARAM, char **argv)
{
@@ -348,7 +359,8 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv)
unsigned char *buffer;
// no arguments allowed!
getopt32(argv, "^" "" "\0" "=0");
opt_complementary = "=0";
getopt32(argv, "");
/*
* We used to look at the length of the input file
@@ -368,9 +380,11 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv)
}
#endif
#if ENABLE_SETFONT
/* kbd-1.12:
/*
kbd-1.12:
setfont [-O font+umap.orig] [-o font.orig] [-om cmap.orig]
[-ou umap.orig] [-N] [font.new ...] [-m cmap] [-u umap] [-C console]
[-hNN] [-v] [-V]
@@ -400,17 +414,8 @@ setfont [-O font+umap.orig] [-o font.orig] [-om cmap.orig]
-v Verbose
-V Version
*/
//usage:#define setfont_trivial_usage
//usage: "FONT [-m MAPFILE] [-C TTY]"
//usage:#define setfont_full_usage "\n\n"
//usage: "Load a console font\n"
//usage: "\n -m MAPFILE Load console screen map"
//usage: "\n -C TTY Affect TTY instead of /dev/tty"
//usage:
//usage:#define setfont_example_usage
//usage: "$ setfont -m koi8-r /etc/i18n/fontname\n"
# if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
static int ctoi(char *s)
{
if (s[0] == '\'' && s[1] != '\0' && s[2] == '\'' && s[3] == '\0')
@@ -424,7 +429,7 @@ static int ctoi(char *s)
return -1;
return xstrtoul(s, 0);
}
# endif
#endif
int setfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setfont_main(int argc UNUSED_PARAM, char **argv)
@@ -436,7 +441,8 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
char *mapfilename;
const char *tty_name = CURRENT_TTY;
opts = getopt32(argv, "^" "m:C:" "\0" "=1", &mapfilename, &tty_name);
opt_complementary = "=1";
opts = getopt32(argv, "m:C:", &mapfilename, &tty_name);
argv += optind;
fd = xopen_nonblocking(tty_name);
@@ -474,7 +480,7 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
if (len == 2*E_TABSZ)
mode = PIO_UNISCRNMAP;
}
# if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
// assume textual Unicode console maps:
// 0x00 U+0000 # NULL (NUL)
// 0x01 U+0001 # START OF HEADING (SOH)
@@ -521,7 +527,7 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
}
#undef unicodes
}
# endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
#endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
// do set screen map
xioctl(fd, mode, map);
+4 -4
View File
@@ -7,14 +7,14 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config LOADKMAP
//config: bool "loadkmap (1.5 kb)"
//config: bool "loadkmap"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads a keyboard translation table from
//config: standard input.
//config: This program loads a keyboard translation table from
//config: standard input.
//applet:IF_LOADKMAP(APPLET_NOEXEC(loadkmap, loadkmap, BB_DIR_SBIN, BB_SUID_DROP, loadkmap))
//applet:IF_LOADKMAP(APPLET(loadkmap, BB_DIR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_LOADKMAP) += loadkmap.o
+5 -5
View File
@@ -8,12 +8,12 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config OPENVT
//config: bool "openvt (7 kb)"
//config: bool "openvt"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program is used to start a command on an unused
//config: virtual terminal.
//config: This program is used to start a command on an unused
//config: virtual terminal.
//applet:IF_OPENVT(APPLET(openvt, BB_DIR_USR_BIN, BB_SUID_DROP))
@@ -99,7 +99,7 @@ static int find_free_vtno(void)
/*xfunc_error_retval = 3; - do we need compat? */
if (ioctl(fd, VT_OPENQRY, &vtno) != 0 || vtno <= 0)
bb_perror_msg_and_die("can't find open VT");
// Not really needed, grep for DAEMON_CLOSE_EXTRA_FDS
// Not really needed, grep for DAEMON_ONLY_SANITIZE
// if (fd > 2)
// close(fd);
return vtno;
@@ -155,7 +155,7 @@ int openvt_main(int argc UNUSED_PARAM, char **argv)
/* Grab new VT */
sprintf(vtname, VC_FORMAT, vtno);
/* (Try to) clean up stray open fds above fd 2 */
bb_daemon_helper(DAEMON_CLOSE_EXTRA_FDS);
bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS | DAEMON_ONLY_SANITIZE, NULL);
close(STDIN_FILENO);
/*setsid(); - BAD IDEA: after we exit, child is SIGHUPed... */
xopen(vtname, O_RDWR);
+8 -8
View File
@@ -7,14 +7,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* "Standard" version of this tool is in ncurses package */
//config:config RESET
//config: bool "reset (275 bytes)"
//config: bool "reset"
//config: default y
//config: help
//config: This program is used to reset the terminal screen, if it
//config: gets messed up.
//config: This program is used to reset the terminal screen, if it
//config: gets messed up.
//applet:IF_RESET(APPLET_NOEXEC(reset, reset, BB_DIR_USR_BIN, BB_SUID_DROP, reset))
//applet:IF_RESET(APPLET(reset, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_RESET) += reset.o
@@ -23,8 +25,6 @@
//usage:#define reset_full_usage "\n\n"
//usage: "Reset the screen"
/* "Standard" version of this tool is in ncurses package */
#include "libbb.h"
#define ESC "\033"
@@ -46,11 +46,11 @@ int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
/* See 'man 4 console_codes' for details:
* "ESC c" -- Reset
* "ESC ( B" -- Select G0 Character Set (B = US)
* "ESC [ m" -- Reset all display attributes
* "ESC [ 0 m" -- Reset all display attributes
* "ESC [ J" -- Erase to the end of screen
* "ESC [ ? 25 h" -- Make cursor visible
*/
printf(ESC"c" ESC"(B" ESC"[m" ESC"[J" ESC"[?25h");
printf(ESC"c" ESC"(B" ESC"[0m" ESC"[J" ESC"[?25h");
/* http://bugs.busybox.net/view.php?id=1414:
* people want it to reset echo etc: */
#if ENABLE_STTY
+8 -10
View File
@@ -7,24 +7,23 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config RESIZE
//config: bool "resize (756 bytes)"
//config: bool "resize"
//config: default y
//config: help
//config: This program is used to (re)set the width and height of your current
//config: terminal.
//config: This program is used to (re)set the width and height of your current
//config: terminal.
//config:
//config:config FEATURE_RESIZE_PRINT
//config: bool "Print environment variables"
//config: default y
//config: depends on RESIZE
//config: help
//config: Prints the newly set size (number of columns and rows) of
//config: the terminal.
//config: E.g.:
//config: COLUMNS=80;LINES=44;export COLUMNS LINES;
//config: Prints the newly set size (number of columns and rows) of
//config: the terminal.
//config: E.g.:
//config: COLUMNS=80;LINES=44;export COLUMNS LINES;
//applet:IF_RESIZE(APPLET_NOEXEC(resize, resize, BB_DIR_USR_BIN, BB_SUID_DROP, resize))
/* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */
//applet:IF_RESIZE(APPLET(resize, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_RESIZE) += resize.o
@@ -64,7 +63,6 @@ int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
*/
tcgetattr(STDERR_FILENO, old_termios_p); /* fiddle echo */
//TODO: die if the above fails?
memcpy(&new, old_termios_p, sizeof(new));
new.c_cflag |= (CLOCAL | CREAD);
new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
+19 -23
View File
@@ -1,42 +1,34 @@
/* vi: set sw=4 ts=4: */
/*
* setconsole.c - redirect system console output
* setconsole.c - redirect system console output
*
* Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de>
* Copyright (C) 2008 Bernhard Reutner-Fischer
* Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de>
* Copyright (C) 2008 Bernhard Reutner-Fischer
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETCONSOLE
//config: bool "setconsole (3.7 kb)"
//config: bool "setconsole"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Redirect writes to /dev/console to another device,
//config: like the current tty while logged in via telnet.
//config: This does not redirect kernel log, only writes
//config: from user space.
//config: This program redirects the system console to another device,
//config: like the current tty while logged in via telnet.
//config:
//config:config FEATURE_SETCONSOLE_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on SETCONSOLE && LONG_OPTS
//applet:IF_SETCONSOLE(APPLET_NOEXEC(setconsole, setconsole, BB_DIR_SBIN, BB_SUID_DROP, setconsole))
//applet:IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_SETCONSOLE) += setconsole.o
//usage:#define setconsole_trivial_usage
//usage: "[-r] [DEVICE]"
//usage: "[-r" IF_FEATURE_SETCONSOLE_LONG_OPTIONS("|--reset") "] [DEVICE]"
//usage:#define setconsole_full_usage "\n\n"
//usage: "Make writes to /dev/console appear on DEVICE (default: /dev/tty)."
//usage: "\n""Does not redirect kernel log output or reads from /dev/console."
//usage: "\n"
//usage: "\n"" -r Reset: writes to /dev/console go to kernel log tty(s)"
/* It was a bbox-specific invention, but SUSE does have a similar utility.
* SUSE has no -r option, though.
*/
//usage: "Redirect system console output to DEVICE (default: /dev/tty)\n"
//usage: "\n -r Reset output to /dev/console"
#include "libbb.h"
@@ -44,10 +36,17 @@ int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setconsole_main(int argc UNUSED_PARAM, char **argv)
{
const char *device = CURRENT_TTY;
int reset;
bool reset;
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
static const char setconsole_longopts[] ALIGN1 =
"reset\0" No_argument "r"
;
applet_long_options = setconsole_longopts;
#endif
/* at most one non-option argument */
reset = getopt32(argv, "^" "r" "\0" "?1");
opt_complementary = "?1";
reset = getopt32(argv, "r");
argv += 1 + reset;
if (*argv) {
@@ -57,9 +56,6 @@ int setconsole_main(int argc UNUSED_PARAM, char **argv)
device = DEV_CONSOLE;
}
//TODO: fails if TIOCCONS redir is already active to some tty.
//I think SUSE version first does TIOCCONS on /dev/console fd (iow: resets)
//then TIOCCONS to new tty?
xioctl(xopen(device, O_WRONLY), TIOCCONS, NULL);
return EXIT_SUCCESS;
}
+10 -11
View File
@@ -9,23 +9,24 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETKEYCODES
//config: bool "setkeycodes (1.7 kb)"
//config: bool "setkeycodes"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads entries into the kernel's scancode-to-keycode
//config: map, allowing unusual keyboards to generate usable keycodes.
//config: This program loads entries into the kernel's scancode-to-keycode
//config: map, allowing unusual keyboards to generate usable keycodes.
//applet:IF_SETKEYCODES(APPLET_NOEXEC(setkeycodes, setkeycodes, BB_DIR_USR_BIN, BB_SUID_DROP, setkeycodes))
//applet:IF_SETKEYCODES(APPLET(setkeycodes, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_SETKEYCODES) += setkeycodes.o
//usage:#define setkeycodes_trivial_usage
//usage: "{ SCANCODE KEYCODE }..."
//usage: "SCANCODE KEYCODE..."
//usage:#define setkeycodes_full_usage "\n\n"
//usage: "Modify kernel's scancode-to-keycode map,\n"
//usage: "Set entries into the kernel's scancode-to-keycode map,\n"
//usage: "allowing unusual keyboards to generate usable keycodes.\n\n"
//usage: "SCANCODE is either xx or e0xx (hexadecimal), KEYCODE is decimal."
//usage: "SCANCODE may be either xx or e0xx (hexadecimal),\n"
//usage: "and KEYCODE is given in decimal."
//usage:
//usage:#define setkeycodes_example_usage
//usage: "$ setkeycodes e030 127\n"
@@ -44,6 +45,7 @@ int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setkeycodes_main(int argc, char **argv)
{
int fd;
struct kbkeycode a;
if (!(argc & 1) /* if even */ || argc < 2) {
bb_show_usage();
@@ -52,10 +54,7 @@ int setkeycodes_main(int argc, char **argv)
fd = get_console_fd_or_die();
while (argv[1]) {
struct kbkeycode a;
int sc;
sc = xstrtoul_range(argv[1], 16, 0, 0xe07f);
int sc = xstrtoul_range(argv[1], 16, 0, 0xe07f);
if (sc >= 0xe000) {
sc -= 0xe000;
sc += 0x0080;
+6 -18
View File
@@ -9,32 +9,20 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETLOGCONS
//config: bool "setlogcons (1.8 kb)"
//config: bool "setlogcons"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program redirects the output console of kernel messages.
//config: This program redirects the output console of kernel messages.
//applet:IF_SETLOGCONS(APPLET_NOEXEC(setlogcons, setlogcons, BB_DIR_USR_SBIN, BB_SUID_DROP, setlogcons))
//applet:IF_SETLOGCONS(APPLET(setlogcons, BB_DIR_USR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_SETLOGCONS) += setlogcons.o
//usage:#define setlogcons_trivial_usage
//usage: "[N]"
//usage:#define setlogcons_full_usage "\n\n"
//usage: "Pin kernel output to VT console N. Default:0 (do not pin)"
// Comment from kernel source:
/* ...
* By default, the kernel messages are always printed on the current virtual
* console. However, the user may modify that default with the
* TIOCL_SETKMSGREDIRECT ioctl call.
*
* This function sets the kernel message console to be @new. It returns the old
* virtual console number. The virtual terminal number 0 (both as parameter and
* return value) means no redirection (i.e. always printed on the currently
* active console).
*/
//usage: "Redirect the kernel output to console N. Default:0 (current console)"
#include "libbb.h"
@@ -45,8 +33,8 @@ int setlogcons_main(int argc UNUSED_PARAM, char **argv)
char fn;
char subarg;
} arg = {
11, /* redirect kernel messages (TIOCL_SETKMSGREDIRECT) */
0
11, /* redirect kernel messages */
0 /* to specified console (current as default) */
};
if (argv[1])
+2 -2
View File
@@ -7,11 +7,11 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config SHOWKEY
//config: bool "showkey (4.7 kb)"
//config: bool "showkey"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Shows keys pressed.
//config: Shows keys pressed.
//applet:IF_SHOWKEY(APPLET(showkey, BB_DIR_USR_BIN, BB_SUID_DROP))
+5 -5
View File
@@ -13,9 +13,9 @@ config FEATURE_VERBOSE
bool "Support verbose options (usually -v) for various applets"
default y
help
Enable cp -v, rm -v and similar messages.
Also enables long option (--verbose) if it exists.
Without this option, -v is accepted but ignored.
Enable cp -v, rm -v and similar messages.
Also enables long option (--verbose) if it exists.
Without this option, -v is accepted but ignored.
comment "Common options for cp and mv"
depends on CP || MV
@@ -25,7 +25,7 @@ config FEATURE_PRESERVE_HARDLINKS
default y
depends on CP || MV
help
Allow cp and mv to preserve hard links.
Allow cp and mv to preserve hard links.
comment "Common options for df, du, ls"
depends on DF || DU || LS
@@ -35,6 +35,6 @@ config FEATURE_HUMAN_READABLE
default y
depends on DF || DU || LS
help
Allow df, du, and ls to have human readable output.
Allow df, du, and ls to have human readable output.
endmenu
+10 -8
View File
@@ -6,6 +6,7 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Changes:
@@ -14,12 +15,12 @@
* 3) Save some space by using strcmp(). Calling strncmp() here was silly.
*/
//config:config BASENAME
//config: bool "basename (371 bytes)"
//config: bool "basename"
//config: default y
//config: help
//config: basename is used to strip the directory and suffix from filenames,
//config: leaving just the filename itself. Enable this option if you wish
//config: to enable the 'basename' utility.
//config: basename is used to strip the directory and suffix from filenames,
//config: leaving just the filename itself. Enable this option if you wish
//config: to enable the 'basename' utility.
//applet:IF_BASENAME(APPLET_NOFORK(basename, basename, BB_DIR_USR_BIN, BB_SUID_DROP, basename))
@@ -46,24 +47,25 @@
/* This is a NOFORK applet. Be very careful! */
int basename_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int basename_main(int argc UNUSED_PARAM, char **argv)
int basename_main(int argc, char **argv)
{
size_t m, n;
char *s;
if (argv[1] && strcmp(argv[1], "--") == 0) {
argv++;
argc--;
}
if (!argv[1])
if ((unsigned)(argc-2) >= 2) {
bb_show_usage();
}
/* It should strip slash: /abc/def/ -> def */
s = bb_get_last_path_component_strip(*++argv);
m = strlen(s);
if (*++argv) {
if (argv[1])
bb_show_usage();
n = strlen(*argv);
if ((m > n) && (strcmp(s+m-n, *argv) == 0)) {
m -= n;
+40 -76
View File
@@ -7,25 +7,18 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config CAT
//config: bool "cat (5.6 kb)"
//config: bool "cat"
//config: default y
//config: help
//config: cat is used to concatenate files and print them to the standard
//config: output. Enable this option if you wish to enable the 'cat' utility.
//config:
//config:config FEATURE_CATN
//config: bool "Enable -n and -b options"
//config: default y
//config: depends on CAT
//config: help
//config: -n numbers all output lines while -b numbers nonempty output lines.
//config: cat is used to concatenate files and print them to the standard
//config: output. Enable this option if you wish to enable the 'cat' utility.
//config:
//config:config FEATURE_CATV
//config: bool "cat -v[etA]"
//config: default y
//config: depends on CAT
//config: help
//config: Display nonprinting characters as escape sequences
//config: Display nonprinting characters as escape sequences
//applet:IF_CAT(APPLET(cat, BB_DIR_BIN, BB_SUID_DROP))
@@ -34,19 +27,12 @@
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
//usage:#if ENABLE_FEATURE_CATN || ENABLE_FEATURE_CATV
//usage:#define cat_trivial_usage
//usage: "[-" IF_FEATURE_CATN("nb") IF_FEATURE_CATV("vteA") "] [FILE]..."
//usage:#else
//usage:#define cat_trivial_usage
//usage: "[FILE]..."
//usage:#endif
//usage: "[-nb"IF_FEATURE_CATV("vteA")"] [FILE]..."
//usage:#define cat_full_usage "\n\n"
//usage: "Print FILEs to stdout\n"
//usage: IF_FEATURE_CATN(
//usage: "\n -n Number output lines"
//usage: "\n -b Number nonempty lines"
//usage: )
//usage: IF_FEATURE_CATV(
//usage: "\n -v Show nonprinting characters as ^x or M-x"
//usage: "\n -t ...and tabs as ^I"
@@ -98,35 +84,30 @@
* I agree with the argument. Unfortunately, this ship has sailed (1983...).
* There are dozens of Linux distros and each of them has "cat" which supports -v.
* It's unrealistic for us to "reeducate" them to use our, incompatible way
* to achieve "cat -v" effect. The actual effect would be "users pissed off
* to achieve "cat -v" effect. The actuall effect would be "users pissed off
* by gratuitous incompatibility".
*/
#define CAT_OPT_e (1<<0)
#define CAT_OPT_t (1<<1)
#define CAT_OPT_v (1<<2)
/* -A occupies bit (1<<3) */
#define CAT_OPT_n ((1<<4) * ENABLE_FEATURE_CATN)
#define CAT_OPT_b ((1<<5) * ENABLE_FEATURE_CATN)
#define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1)
#define CATV_OPT_v (1<<2)
static int catv(unsigned opts, char **argv)
{
int retval = EXIT_SUCCESS;
int fd;
#if ENABLE_FEATURE_CATN
unsigned lineno = 0;
unsigned eol_char = (opts & (CAT_OPT_n|CAT_OPT_b)) ? '\n' : 0x100;
unsigned skip_num_on = (opts & CAT_OPT_b) ? '\n' : 0x100;
bool eol_seen = 1;
#endif
BUILD_BUG_ON(CAT_OPT_e != VISIBLE_ENDLINE);
BUILD_BUG_ON(CAT_OPT_t != VISIBLE_SHOW_TABS);
BUILD_BUG_ON(CATV_OPT_e != VISIBLE_ENDLINE);
BUILD_BUG_ON(CATV_OPT_t != VISIBLE_SHOW_TABS);
#if 0 /* These consts match, we can just pass "opts" to visible() */
if (opts & CAT_OPT_e)
if (opts & CATV_OPT_e)
flags |= VISIBLE_ENDLINE;
if (opts & CAT_OPT_t)
if (opts & CATV_OPT_t)
flags |= VISIBLE_SHOW_TABS;
#endif
/* Read from stdin if there's nothing else to do. */
if (!argv[0])
*--argv = (char*)"-";
#define read_buf bb_common_bufsiz1
setup_common_bufsiz();
do {
@@ -146,11 +127,6 @@ static int catv(unsigned opts, char **argv)
for (i = 0; i < res; i++) {
unsigned char c = read_buf[i];
char buf[sizeof("M-^c")];
#if ENABLE_FEATURE_CATN
if (eol_seen && c != skip_num_on)
printf("%6u ", ++lineno);
eol_seen = (c == eol_char);
#endif
visible(c, buf, opts);
fputs(buf, stdout);
}
@@ -161,55 +137,43 @@ static int catv(unsigned opts, char **argv)
fflush_stdout_and_exit(retval);
}
#undef CAT_OPT_n
#undef CAT_OPT_b
#endif
int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cat_main(int argc UNUSED_PARAM, char **argv)
{
#if ENABLE_FEATURE_CATV || ENABLE_FEATURE_CATN
struct number_state ns;
unsigned opts;
opts =
#endif
getopt32(argv, IF_FEATURE_CATV("^")
/* -u is ignored ("unbuffered") */
IF_FEATURE_CATV("etvA")IF_FEATURE_CATN("nb")"u"
IF_FEATURE_CATV("\0" "Aetv" /* -A == -vet */)
);
IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */)
/* -u is ignored ("unbuffered") */
opts = getopt32(argv, IF_FEATURE_CATV("etvA")"nbu");
argv += optind;
/* Read from stdin if there's nothing else to do. */
if (!argv[0])
*--argv = (char*)"-";
#if ENABLE_FEATURE_CATV
if (opts & 7)
return catv(opts, argv);
//BUG: -v,-e,-t,-A ignore -nb
opts >>= 4;
#endif
#if ENABLE_FEATURE_CATN
# define CAT_OPT_n (1<<0)
# define CAT_OPT_b (1<<1)
if (opts & (CAT_OPT_n|CAT_OPT_b)) { /* -n or -b */
struct number_state ns;
#define CAT_OPT_n (1<<0)
#define CAT_OPT_b (1<<1)
#define CAT_OPT_u (1<<2)
if (!(opts & (CAT_OPT_n|CAT_OPT_b))) /* no -n or -b */
return bb_cat(argv);
ns.width = 6;
ns.start = 1;
ns.inc = 1;
ns.sep = "\t";
ns.empty_str = "\n";
ns.all = !(opts & CAT_OPT_b); /* -n without -b */
ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */
do {
print_numbered_lines(&ns, *argv);
} while (*++argv);
fflush_stdout_and_exit(EXIT_SUCCESS);
}
/*opts >>= 2;*/
#endif
return bb_cat(argv);
if (!*argv)
*--argv = (char*)"-";
ns.width = 6;
ns.start = 1;
ns.inc = 1;
ns.sep = "\t";
ns.empty_str = "\n";
ns.all = !(opts & CAT_OPT_b); /* -n without -b */
ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */
do {
print_numbered_lines(&ns, *argv);
} while (*++argv);
fflush_stdout_and_exit(EXIT_SUCCESS);
}
+2 -2
View File
@@ -7,10 +7,10 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHGRP
//config: bool "chgrp (7.2 kb)"
//config: bool "chgrp"
//config: default y
//config: help
//config: chgrp is used to change the group ownership of files.
//config: chgrp is used to change the group ownership of files.
//applet:IF_CHGRP(APPLET_NOEXEC(chgrp, chgrp, BB_DIR_BIN, BB_SUID_DROP, chgrp))
+4 -3
View File
@@ -10,10 +10,10 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHMOD
//config: bool "chmod (5.1 kb)"
//config: bool "chmod"
//config: default y
//config: help
//config: chmod is used to change the access permission of files.
//config: chmod is used to change the access permission of files.
//applet:IF_CHMOD(APPLET_NOEXEC(chmod, chmod, BB_DIR_BIN, BB_SUID_DROP, chmod))
@@ -123,7 +123,8 @@ int chmod_main(int argc UNUSED_PARAM, char **argv)
}
/* Parse options */
getopt32(argv, "^" OPT_STR "\0" "-2");
opt_complementary = "-2";
getopt32(argv, ("-"OPT_STR) + 1); /* Reuse string */
argv += optind;
/* Restore option-like mode if needed */
+7 -7
View File
@@ -7,11 +7,11 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHOWN
//config: bool "chown (7.2 kb)"
//config: bool "chown"
//config: default y
//config: help
//config: chown is used to change the user and/or group ownership
//config: of files.
//config: chown is used to change the user and/or group ownership
//config: of files.
//config:
//config:config FEATURE_CHOWN_LONG_OPTIONS
//config: bool "Enable long options"
@@ -55,7 +55,7 @@
/* This is a NOEXEC applet. Be very careful! */
#define OPT_STR "Rh" IF_DESKTOP("vcfLHP")
#define OPT_STR ("Rh" IF_DESKTOP("vcfLHP"))
#define BIT_RECURSE 1
#define OPT_RECURSE (opt & 1)
#define OPT_NODEREF (opt & 2)
@@ -128,10 +128,10 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
struct param_t param;
#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
opt = getopt32long(argv, "^" OPT_STR "\0" "-2", chown_longopts);
#else
opt = getopt32(argv, "^" OPT_STR "\0" "-2");
applet_long_options = chown_longopts;
#endif
opt_complementary = "-2";
opt = getopt32(argv, OPT_STR);
argv += optind;
/* This matches coreutils behavior (almost - see below) */
+4 -5
View File
@@ -7,13 +7,13 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHROOT
//config: bool "chroot (3.7 kb)"
//config: bool "chroot"
//config: default y
//config: help
//config: chroot is used to change the root directory and run a command.
//config: The default command is '/bin/sh'.
//config: chroot is used to change the root directory and run a command.
//config: The default command is `/bin/sh'.
//applet:IF_CHROOT(APPLET_NOEXEC(chroot, chroot, BB_DIR_USR_SBIN, BB_SUID_DROP, chroot))
//applet:IF_CHROOT(APPLET(chroot, BB_DIR_USR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CHROOT) += chroot.o
@@ -40,7 +40,6 @@ int chroot_main(int argc UNUSED_PARAM, char **argv)
++argv;
if (!*argv)
bb_show_usage();
xchroot(*argv);
++argv;
+2 -3
View File
@@ -7,13 +7,12 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CKSUM
//config: bool "cksum (4.2 kb)"
//config: bool "cksum"
//config: default y
//config: help
//config: cksum is used to calculate the CRC32 checksum of a file.
//config: cksum is used to calculate the CRC32 checksum of a file.
//applet:IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum))
/* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */
//kbuild:lib-$(CONFIG_CKSUM) += cksum.o
+5 -4
View File
@@ -7,11 +7,11 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config COMM
//config: bool "comm (3.9 kb)"
//config: bool "comm"
//config: default y
//config: help
//config: comm is used to compare two files line by line and return
//config: a three-column output.
//config: comm is used to compare two files line by line and return
//config: a three-column output.
//applet:IF_COMM(APPLET(comm, BB_DIR_USR_BIN, BB_SUID_DROP))
@@ -62,7 +62,8 @@ int comm_main(int argc UNUSED_PARAM, char **argv)
int i;
int order;
getopt32(argv, "^" "123" "\0" "=2");
opt_complementary = "=2";
getopt32(argv, "123");
argv += optind;
for (i = 0; i < 2; ++i) {
+16 -34
View File
@@ -12,18 +12,18 @@
* Size reduction.
*/
//config:config CP
//config: bool "cp (9.7 kb)"
//config: bool "cp"
//config: default y
//config: help
//config: cp is used to copy files and directories.
//config: cp is used to copy files and directories.
//config:
//config:config FEATURE_CP_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on CP && LONG_OPTS
//config: help
//config: Enable long options.
//config: Also add support for --parents option.
//config: Enable long options.
//config: Also add support for --parents option.
//applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
@@ -47,7 +47,6 @@
//usage: "\n -f Overwrite"
//usage: "\n -i Prompt before overwrite"
//usage: "\n -l,-s Create (sym)links"
//usage: "\n -T Treat DEST as a normal file"
//usage: "\n -u Copy only newer files"
#include "libbb.h"
@@ -74,17 +73,15 @@ int cp_main(int argc, char **argv)
#endif
};
// Need at least two arguments
// Soft- and hardlinking doesn't mix
// -P and -d are the same (-P is POSIX, -d is GNU)
// -r and -R are the same
// -R (and therefore -r) turns on -d (coreutils does this)
// -a = -pdR
opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR";
#if ENABLE_FEATURE_CP_LONG_OPTIONS
flags = getopt32long(argv, "^"
FILEUTILS_CP_OPTSTR
"\0"
// Need at least two arguments
// Soft- and hardlinking doesn't mix
// -P and -d are the same (-P is POSIX, -d is GNU)
// -r and -R are the same
// -R (and therefore -r) turns on -d (coreutils does this)
// -a = -pdR
"-2:l--s:s--l:Pd:rRd:Rd:apdR",
applet_long_options =
"archive\0" No_argument "a"
"force\0" No_argument "f"
"interactive\0" No_argument "i"
@@ -93,19 +90,13 @@ int cp_main(int argc, char **argv)
"no-dereference\0" No_argument "P"
"recursive\0" No_argument "R"
"symbolic-link\0" No_argument "s"
"no-target-directory\0" No_argument "T"
"verbose\0" No_argument "v"
"update\0" No_argument "u"
"remove-destination\0" No_argument "\xff"
"parents\0" No_argument "\xfe"
);
#else
flags = getopt32(argv, "^"
FILEUTILS_CP_OPTSTR
"\0"
"-2:l--s:s--l:Pd:rRd:Rd:apdR"
);
;
#endif
flags = getopt32(argv, FILEUTILS_CP_OPTSTR);
/* Options of cp from GNU coreutils 6.10:
* -a, --archive
* -f, --force
@@ -127,8 +118,6 @@ int cp_main(int argc, char **argv)
* remove each existing destination file before attempting to open
* --parents
* use full source file name under DIRECTORY
* -T, --no-target-directory
* treat DEST as a normal file
* NOT SUPPORTED IN BBOX:
* --backup[=CONTROL]
* make a backup of each existing destination file
@@ -147,6 +136,8 @@ int cp_main(int argc, char **argv)
* override the usual backup suffix
* -t, --target-directory=DIRECTORY
* copy all SOURCE arguments into DIRECTORY
* -T, --no-target-directory
* treat DEST as a normal file
* -x, --one-file-system
* stay on this file system
* -Z, --context=CONTEXT
@@ -181,12 +172,6 @@ int cp_main(int argc, char **argv)
if (d_flags < 0)
return EXIT_FAILURE;
if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */
if (!(s_flags & 2) && (d_flags & 2))
/* cp -T NOTDIR DIR */
bb_error_msg_and_die("'%s' is a directory", last);
}
#if ENABLE_FEATURE_CP_LONG_OPTIONS
//bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
// flags, FILEUTILS_RMDEST, OPT_parents);
@@ -204,14 +189,11 @@ int cp_main(int argc, char **argv)
if (!((s_flags | d_flags) & 2)
/* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */
|| ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
|| (flags & FILEUTILS_NO_TARGET_DIR)
) {
/* Do a simple copy */
dest = last;
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
}
} else if (flags & FILEUTILS_NO_TARGET_DIR) {
bb_error_msg_and_die("too many arguments");
}
while (1) {
+6 -9
View File
@@ -9,11 +9,11 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CUT
//config: bool "cut (5.3 kb)"
//config: bool "cut"
//config: default y
//config: help
//config: cut is used to print selected parts of lines from
//config: each file to stdout.
//config: cut is used to print selected parts of lines from
//config: each file to stdout.
//applet:IF_CUT(APPLET_NOEXEC(cut, cut, BB_DIR_USR_BIN, BB_SUID_DROP, cut))
@@ -42,7 +42,7 @@
/* option vars */
#define OPT_STR "b:c:f:d:sn"
static const char optstring[] ALIGN1 = "b:c:f:d:sn";
#define CUT_OPT_BYTE_FLGS (1 << 0)
#define CUT_OPT_CHAR_FLGS (1 << 1)
#define CUT_OPT_FIELDS_FLGS (1 << 2)
@@ -201,11 +201,8 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
char *sopt, *ltok;
unsigned opt;
opt = getopt32(argv, "^"
OPT_STR
"\0" "b--bcf:c--bcf:f--bcf",
&sopt, &sopt, &sopt, &ltok
);
opt_complementary = "b--bcf:c--bcf:f--bcf";
opt = getopt32(argv, optstring, &sopt, &sopt, &sopt, &ltok);
// argc -= optind;
argv += optind;
if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
+33 -43
View File
@@ -19,47 +19,46 @@
much as possible, missed out a lot of bounds checking */
//config:config DATE
//config: bool "date (7.1 kb)"
//config: bool "date"
//config: default y
//config: help
//config: date is used to set the system date or display the
//config: current time in the given format.
//config: date is used to set the system date or display the
//config: current time in the given format.
//config:
//config:config FEATURE_DATE_ISOFMT
//config: bool "Enable ISO date format output (-I)"
//config: default y
//config: depends on DATE
//config: help
//config: Enable option (-I) to output an ISO-8601 compliant
//config: date/time string.
//config: Enable option (-I) to output an ISO-8601 compliant
//config: date/time string.
//config:
//config:# defaults to "no": stat's nanosecond field is a bit non-portable
//config:config FEATURE_DATE_NANO
//config: bool "Support %[num]N nanosecond format specifier"
//config: default n # syscall(__NR_clock_gettime)
//config: depends on DATE
//config: default n
//config: depends on DATE # syscall(__NR_clock_gettime)
//config: select PLATFORM_LINUX
//config: help
//config: Support %[num]N format specifier. Adds ~250 bytes of code.
//config: Support %[num]N format specifier. Adds ~250 bytes of code.
//config:
//config:config FEATURE_DATE_COMPAT
//config: bool "Support weird 'date MMDDhhmm[[YY]YY][.ss]' format"
//config: default y
//config: depends on DATE
//config: help
//config: System time can be set by 'date -s DATE' and simply 'date DATE',
//config: but formats of DATE string are different. 'date DATE' accepts
//config: a rather weird MMDDhhmm[[YY]YY][.ss] format with completely
//config: unnatural placement of year between minutes and seconds.
//config: date -s (and other commands like touch -d) use more sensible
//config: formats (for one, ISO format YYYY-MM-DD hh:mm:ss.ssssss).
//config: System time can be set by 'date -s DATE' and simply 'date DATE',
//config: but formats of DATE string are different. 'date DATE' accepts
//config: a rather weird MMDDhhmm[[YY]YY][.ss] format with completely
//config: unnatural placement of year between minutes and seconds.
//config: date -s (and other commands like touch -d) use more sensible
//config: formats (for one, ISO format YYYY-MM-DD hh:mm:ss.ssssss).
//config:
//config: With this option off, 'date DATE' is 'date -s DATE' support
//config: the same format. With it on, 'date DATE' additionally supports
//config: MMDDhhmm[[YY]YY][.ss] format.
//config: With this option off, 'date DATE' is 'date -s DATE' support
//config: the same format. With it on, 'date DATE' additionally supports
//config: MMDDhhmm[[YY]YY][.ss] format.
//applet:IF_DATE(APPLET_NOEXEC(date, date, BB_DIR_BIN, BB_SUID_DROP, date))
/* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */
//applet:IF_DATE(APPLET(date, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_DATE) += date.o
@@ -67,7 +66,7 @@
* date [OPTION]... [+FORMAT]
* date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
* -d, --date=STRING
* display time described by STRING, not 'now'
* display time described by STRING, not `now'
* -f, --file=DATEFILE
* like --date once for each line of DATEFILE
* -r, --reference=FILE
@@ -153,6 +152,12 @@ enum {
OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
};
static void maybe_set_utc(int opt)
{
if (opt & OPT_UTC)
putenv((char*)"TZ=UTC0");
}
#if ENABLE_LONG_OPTS
static const char date_longopts[] ALIGN1 =
"rfc-822\0" No_argument "R"
@@ -165,19 +170,6 @@ static const char date_longopts[] ALIGN1 =
;
#endif
/* We are a NOEXEC applet.
* Obstacles to NOFORK:
* - we change env
* - xasprintf result not freed
* - after xasprintf we use other xfuncs
*/
static void maybe_set_utc(int opt)
{
if (opt & OPT_UTC)
putenv((char*)"TZ=UTC0");
}
int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int date_main(int argc UNUSED_PARAM, char **argv)
{
@@ -192,18 +184,14 @@ int date_main(int argc UNUSED_PARAM, char **argv)
char *filename;
char *isofmt_arg = NULL;
opt = getopt32long(argv, "^"
"Rs:ud:r:"
IF_FEATURE_DATE_ISOFMT("I::D:")
"\0"
"d--s:s--d"
IF_FEATURE_DATE_ISOFMT(":R--I:I--R"),
date_longopts,
opt_complementary = "d--s:s--d"
IF_FEATURE_DATE_ISOFMT(":R--I:I--R");
IF_LONG_OPTS(applet_long_options = date_longopts;)
opt = getopt32(argv, "Rs:ud:r:"
IF_FEATURE_DATE_ISOFMT("I::D:"),
&date_str, &date_str, &filename
IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt)
);
IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt));
argv += optind;
maybe_set_utc(opt);
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_TIMESPEC)) {
@@ -302,6 +290,8 @@ int date_main(int argc UNUSED_PARAM, char **argv)
tm_time.tm_isdst = -1;
ts.tv_sec = validate_tm_time(date_str, &tm_time);
maybe_set_utc(opt);
/* if setting time, set it */
if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) {
bb_perror_msg("can't set date");
+16 -16
View File
@@ -7,49 +7,49 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DD
//config: bool "dd (7.1 kb)"
//config: bool "dd"
//config: default y
//config: help
//config: dd copies a file (from standard input to standard output,
//config: by default) using specific input and output blocksizes,
//config: while optionally performing conversions on it.
//config: dd copies a file (from standard input to standard output,
//config: by default) using specific input and output blocksizes,
//config: while optionally performing conversions on it.
//config:
//config:config FEATURE_DD_SIGNAL_HANDLING
//config: bool "Enable signal handling for status reporting"
//config: default y
//config: depends on DD
//config: help
//config: Sending a SIGUSR1 signal to a running 'dd' process makes it
//config: print to standard error the number of records read and written
//config: so far, then to resume copying.
//config: Sending a SIGUSR1 signal to a running `dd' process makes it
//config: print to standard error the number of records read and written
//config: so far, then to resume copying.
//config:
//config: $ dd if=/dev/zero of=/dev/null &
//config: $ pid=$!; kill -USR1 $pid; sleep 1; kill $pid
//config: 10899206+0 records in
//config: 10899206+0 records out
//config: $ dd if=/dev/zero of=/dev/null &
//config: $ pid=$!; kill -USR1 $pid; sleep 1; kill $pid
//config: 10899206+0 records in
//config: 10899206+0 records out
//config:
//config:config FEATURE_DD_THIRD_STATUS_LINE
//config: bool "Enable the third status line upon signal"
//config: default y
//config: depends on DD && FEATURE_DD_SIGNAL_HANDLING
//config: help
//config: Displays a coreutils-like third status line with transferred bytes,
//config: elapsed time and speed.
//config: Displays a coreutils-like third status line with transferred bytes,
//config: elapsed time and speed.
//config:
//config:config FEATURE_DD_IBS_OBS
//config: bool "Enable ibs, obs and conv options"
//config: default y
//config: depends on DD
//config: help
//config: Enable support for writing a certain number of bytes in and out,
//config: at a time, and performing conversions on the data stream.
//config: Enable support for writing a certain number of bytes in and out,
//config: at a time, and performing conversions on the data stream.
//config:
//config:config FEATURE_DD_STATUS
//config: bool "Enable status display options"
//config: default y
//config: depends on DD
//config: help
//config: Enable support for status=noxfer/none option.
//config: Enable support for status=noxfer/none option.
//applet:IF_DD(APPLET_NOEXEC(dd, dd, BB_DIR_BIN, BB_SUID_DROP, dd))
+17 -20
View File
@@ -18,22 +18,22 @@
* Implement -P and -B; better coreutils compat; cleanup
*/
//config:config DF
//config: bool "df (7.5 kb)"
//config: bool "df"
//config: default y
//config: help
//config: df reports the amount of disk space used and available
//config: on filesystems.
//config: df reports the amount of disk space used and available
//config: on filesystems.
//config:
//config:config FEATURE_DF_FANCY
//config: bool "Enable -a, -i, -B"
//config: default y
//config: depends on DF
//config: help
//config: -a Show all filesystems
//config: -i Inodes
//config: -B <SIZE> Blocksize
//config: -a Show all filesystems
//config: -i Inodes
//config: -B <SIZE> Blocksize
//applet:IF_DF(APPLET_NOEXEC(df, df, BB_DIR_BIN, BB_SUID_DROP, df))
//applet:IF_DF(APPLET(df, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_DF) += df.o
@@ -77,7 +77,7 @@
//usage: "/dev/sda3 17381728 17107080 274648 98% /\n"
#include <mntent.h>
#include <sys/statvfs.h>
#include <sys/vfs.h>
#include "libbb.h"
#include "unicode.h"
@@ -98,7 +98,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
unsigned opt;
FILE *mount_table;
struct mntent *mount_entry;
struct statvfs s;
struct statfs s;
enum {
OPT_KILO = (1 << 0),
@@ -115,18 +115,15 @@ int df_main(int argc UNUSED_PARAM, char **argv)
init_unicode();
opt = getopt32(argv, "^"
"kPT"
#if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY
opt_complementary = "k-mB:m-Bk:B-km";
#elif ENABLE_FEATURE_HUMAN_READABLE
opt_complementary = "k-m:m-k";
#endif
opt = getopt32(argv, "kPT"
IF_FEATURE_DF_FANCY("aiB:")
IF_FEATURE_HUMAN_READABLE("hm")
"\0"
#if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY
"k-mB:m-Bk:B-km"
#elif ENABLE_FEATURE_HUMAN_READABLE
"k-m:m-k"
#endif
IF_FEATURE_DF_FANCY(, &chp)
);
IF_FEATURE_DF_FANCY(, &chp));
if (opt & OPT_MEGA)
df_disp_hr = 1024*1024;
@@ -211,7 +208,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
mount_point = mount_entry->mnt_dir;
fs_type = mount_entry->mnt_type;
if (statvfs(mount_point, &s) != 0) {
if (statfs(mount_point, &s) != 0) {
bb_simple_perror_msg(mount_point);
goto set_error;
}
+3 -3
View File
@@ -7,11 +7,11 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DIRNAME
//config: bool "dirname (289 bytes)"
//config: bool "dirname"
//config: default y
//config: help
//config: dirname is used to strip a non-directory suffix from
//config: a file name.
//config: dirname is used to strip a non-directory suffix from
//config: a file name.
//applet:IF_DIRNAME(APPLET_NOFORK(dirname, dirname, BB_DIR_USR_BIN, BB_SUID_DROP, dirname))
+8 -7
View File
@@ -12,18 +12,18 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DOS2UNIX
//config: bool "dos2unix (5.1 kb)"
//config: bool "dos2unix"
//config: default y
//config: help
//config: dos2unix is used to convert a text file from DOS format to
//config: UNIX format, and vice versa.
//config: dos2unix is used to convert a text file from DOS format to
//config: UNIX format, and vice versa.
//config:
//config:config UNIX2DOS
//config: bool "unix2dos (5.1 kb)"
//config: bool "unix2dos"
//config: default y
//config: help
//config: unix2dos is used to convert a text file from UNIX format to
//config: DOS format, and vice versa.
//config: unix2dos is used to convert a text file from UNIX format to
//config: DOS format, and vice versa.
//applet:IF_DOS2UNIX(APPLET_NOEXEC(dos2unix, dos2unix, BB_DIR_USR_BIN, BB_SUID_DROP, dos2unix))
//applet:IF_UNIX2DOS(APPLET_NOEXEC(unix2dos, dos2unix, BB_DIR_USR_BIN, BB_SUID_DROP, unix2dos))
@@ -120,7 +120,8 @@ int dos2unix_main(int argc UNUSED_PARAM, char **argv)
}
/* -u convert to unix, -d convert to dos */
o = getopt32(argv, "^" "du" "\0" "u--d:d--u"); /* mutually exclusive */
opt_complementary = "u--d:d--u"; /* mutually exclusive */
o = getopt32(argv, "du");
/* Do the conversion requested by an argument else do the default
* conversion depending on our name. */
+7 -13
View File
@@ -22,15 +22,15 @@
//config: bool "du (default blocksize of 512 bytes)"
//config: default y
//config: help
//config: du is used to report the amount of disk space used
//config: for specified files.
//config: du is used to report the amount of disk space used
//config: for specified files.
//config:
//config:config FEATURE_DU_DEFAULT_BLOCKSIZE_1K
//config: bool "Use a default blocksize of 1024 bytes (1K)"
//config: default y
//config: depends on DU
//config: help
//config: Use a blocksize of (1K) instead of the default 512b.
//config: Use a blocksize of (1K) instead of the default 512b.
//applet:IF_DU(APPLET(du, BB_DIR_USR_BIN, BB_SUID_DROP))
@@ -242,11 +242,8 @@ int du_main(int argc UNUSED_PARAM, char **argv)
* ignore -a. This is consistent with -s being equivalent to -d 0.
*/
#if ENABLE_FEATURE_HUMAN_READABLE
opt = getopt32(argv, "^"
"aHkLsxd:+lchm"
"\0" "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s",
&G.max_print_depth
);
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
opt = getopt32(argv, "aHkLsx" "d:+" "lc" "hm", &G.max_print_depth);
argv += optind;
if (opt & OPT_h_for_humans) {
G.disp_unit = 0;
@@ -258,11 +255,8 @@ int du_main(int argc UNUSED_PARAM, char **argv)
G.disp_unit = 1024;
}
#else
opt = getopt32(argv, "^"
"aHkLsxd:+lc"
"\0" "H-L:L-H:s-d:d-s",
&G.max_print_depth
);
opt_complementary = "H-L:L-H:s-d:d-s";
opt = getopt32(argv, "aHkLsx" "d:+" "lc", &G.max_print_depth);
argv += optind;
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if (opt & OPT_k_kbytes) {
+2 -2
View File
@@ -22,7 +22,7 @@
//config: bool "echo (basic SuSv3 version taking no options)"
//config: default y
//config: help
//config: echo is used to print a specified string to stdout.
//config: echo is used to print a specified string to stdout.
//config:
//config:# this entry also appears in shell/Config.in, next to the echo builtin
//config:config FEATURE_FANCY_ECHO
@@ -218,7 +218,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
* 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
* 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
+21 -10
View File
@@ -24,12 +24,17 @@
* - use xfunc_error_retval
*/
//config:config ENV
//config: bool "env (3.8 kb)"
//config: bool "env"
//config: default y
//config: help
//config: env is used to set an environment variable and run
//config: a command; without options it displays the current
//config: environment.
//config: env is used to set an environment variable and run
//config: a command; without options it displays the current
//config: environment.
//config:
//config:config FEATURE_ENV_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on ENV && LONG_OPTS
//applet:IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env))
@@ -48,17 +53,23 @@
#include "libbb.h"
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
static const char env_longopts[] ALIGN1 =
"ignore-environment\0" No_argument "i"
"unset\0" Required_argument "u"
;
#endif
int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int env_main(int argc UNUSED_PARAM, char **argv)
{
unsigned opts;
llist_t *unset_env = NULL;
opts = getopt32long(argv, "+iu:*",
"ignore-environment\0" No_argument "i"
"unset\0" Required_argument "u"
, &unset_env
);
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
applet_long_options = env_longopts;
#endif
opts = getopt32(argv, "+iu:+", &unset_env);
argv += optind;
if (argv[0] && LONE_DASH(argv[0])) {
opts |= 1;
@@ -118,7 +129,7 @@ int env_main(int argc UNUSED_PARAM, char **argv)
* 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
* 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
+48 -18
View File
@@ -21,16 +21,26 @@
* Caveat: this versions of expand and unexpand don't accept tab lists.
*/
//config:config EXPAND
//config: bool "expand (5.8 kb)"
//config: bool "expand"
//config: default y
//config: help
//config: By default, convert all tabs to spaces.
//config: By default, convert all tabs to spaces.
//config:
//config:config FEATURE_EXPAND_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on EXPAND && LONG_OPTS
//config:
//config:config UNEXPAND
//config: bool "unexpand (6 kb)"
//config: bool "unexpand"
//config: default y
//config: help
//config: By default, convert only leading sequences of blanks to tabs.
//config: By default, convert only leading sequences of blanks to tabs.
//config:
//config:config FEATURE_UNEXPAND_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on UNEXPAND && LONG_OPTS
//applet:IF_EXPAND(APPLET(expand, BB_DIR_USR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
@@ -43,16 +53,29 @@
//usage: "[-i] [-t N] [FILE]..."
//usage:#define expand_full_usage "\n\n"
//usage: "Convert tabs to spaces, writing to stdout\n"
//usage: IF_FEATURE_EXPAND_LONG_OPTIONS(
//usage: "\n -i,--initial Don't convert tabs after non blanks"
//usage: "\n -t,--tabs N Tabstops every N chars"
//usage: )
//usage: IF_NOT_FEATURE_EXPAND_LONG_OPTIONS(
//usage: "\n -i Don't convert tabs after non blanks"
//usage: "\n -t Tabstops every N chars"
//usage: )
//usage:#define unexpand_trivial_usage
//usage: "[-fa][-t N] [FILE]..."
//usage:#define unexpand_full_usage "\n\n"
//usage: "Convert spaces to tabs, writing to stdout\n"
//usage: IF_FEATURE_UNEXPAND_LONG_OPTIONS(
//usage: "\n -a,--all Convert all blanks"
//usage: "\n -f,--first-only Convert only leading blanks"
//usage: "\n -t,--tabs N Tabstops every N chars"
//usage: )
//usage: IF_NOT_FEATURE_UNEXPAND_LONG_OPTIONS(
//usage: "\n -a Convert all blanks"
//usage: "\n -f Convert only leading blanks"
//usage: "\n -t N Tabstops every N chars"
//usage: )
#include "libbb.h"
#include "unicode.h"
@@ -165,24 +188,31 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
unsigned opt;
int exit_status = EXIT_SUCCESS;
#if ENABLE_FEATURE_EXPAND_LONG_OPTIONS
static const char expand_longopts[] ALIGN1 =
/* name, has_arg, val */
"initial\0" No_argument "i"
"tabs\0" Required_argument "t"
;
#endif
#if ENABLE_FEATURE_UNEXPAND_LONG_OPTIONS
static const char unexpand_longopts[] ALIGN1 =
/* name, has_arg, val */
"first-only\0" No_argument "i"
"tabs\0" Required_argument "t"
"all\0" No_argument "a"
;
#endif
init_unicode();
if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) {
opt = getopt32long(argv, "it:",
"initial\0" No_argument "i"
"tabs\0" Required_argument "t"
, &opt_t
);
IF_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts);
opt = getopt32(argv, "it:", &opt_t);
} else {
opt = getopt32long(argv, "^"
"ft:a"
"\0"
"ta" /* -t NUM sets -a */,
"first-only\0" No_argument "i"
"tabs\0" Required_argument "t"
"all\0" No_argument "a"
, &opt_t
);
IF_FEATURE_UNEXPAND_LONG_OPTIONS(applet_long_options = unexpand_longopts);
/* -t NUM sets also -a */
opt_complementary = "ta";
opt = getopt32(argv, "ft:a", &opt_t);
/* -f --first-only is the default */
if (!(opt & OPT_ALL)) opt |= OPT_INITIAL;
}
+8 -11
View File
@@ -23,22 +23,22 @@
* provided they all associate ((x op x) op x).
*/
//config:config EXPR
//config: bool "expr (6.1 kb)"
//config: bool "expr"
//config: default y
//config: help
//config: expr is used to calculate numbers and print the result
//config: to standard output.
//config: expr is used to calculate numbers and print the result
//config: to standard output.
//config:
//config:config EXPR_MATH_SUPPORT_64
//config: bool "Extend Posix numbers support to 64 bit"
//config: default y
//config: depends on EXPR
//config: help
//config: Enable 64-bit math support in the expr applet. This will make
//config: the applet slightly larger, but will allow computation with very
//config: large numbers.
//config: Enable 64-bit math support in the expr applet. This will make
//config: the applet slightly larger, but will allow computation with very
//config: large numbers.
//applet:IF_EXPR(APPLET_NOEXEC(expr, expr, BB_DIR_USR_BIN, BB_SUID_DROP, expr))
//applet:IF_EXPR(APPLET(expr, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_EXPR) += expr.o
@@ -118,10 +118,7 @@ struct globals {
char **args;
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
setup_common_bufsiz(); \
/* NB: noexec applet - globals not zeroed */ \
} while (0)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
/* forward declarations */
static VALUE *eval(void);
+2 -2
View File
@@ -4,10 +4,10 @@
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config FACTOR
//config: bool "factor (2.6 kb)"
//config: bool "factor"
//config: default y
//config: help
//config: factor factorizes integers
//config: factor factorizes integers
//applet:IF_FACTOR(APPLET(factor, BB_DIR_USR_BIN, BB_SUID_DROP))
+2 -2
View File
@@ -7,10 +7,10 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FALSE
//config: bool "false (tiny)"
//config: bool "false"
//config: default y
//config: help
//config: false returns an exit code of FALSE (1).
//config: false returns an exit code of FALSE (1).
//applet:IF_FALSE(APPLET_NOFORK(false, false, BB_DIR_BIN, BB_SUID_DROP, false))
Loaded 100 of 863 files, more files were not shown because too many files have changed in this diff. Show more