Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db1df5ebeb | ||
|
|
fda2b7ff47 | ||
|
|
12f834ccfc | ||
|
|
18921bd00d | ||
|
|
5ad22c933c | ||
|
|
09da627a23 | ||
|
|
080ddc1c19 | ||
|
|
5e02c67331 | ||
|
|
fe5b1a9f3c | ||
|
|
72e1212ad8 | ||
|
|
f02c26f1ef | ||
|
|
f6f7bfb8e0 | ||
|
|
44608e9693 | ||
|
|
1887b0478f | ||
|
|
5956028f6f | ||
|
|
9ffd5776eb | ||
|
|
0d53ebdc52 | ||
|
|
4298e87fa5 | ||
|
|
61b7904afd | ||
|
|
c5c1a8a112 | ||
|
|
05fa661123 | ||
|
|
25bca9566d | ||
|
|
98f824aa22 | ||
|
|
934805aec1 | ||
|
|
2a2ab1479c | ||
|
|
431a18497d | ||
|
|
31f9747a23 | ||
|
|
d69e31fb93 | ||
|
|
1977a60de4 | ||
|
|
61fb48930f | ||
|
|
9060a73159 | ||
|
|
e8a90fb2bc | ||
|
|
71ae64bdc6 | ||
|
|
fdfe298a96 | ||
|
|
d274b53c1d | ||
|
|
1bb1e83454 | ||
|
|
adb058b0de | ||
|
|
a39342b131 | ||
|
|
528649463f | ||
|
|
2983330512 | ||
|
|
e0f5500bb5 | ||
|
|
506177df7f | ||
|
|
08a72209c9 | ||
|
|
02e6ba91e8 | ||
|
|
a6f6e06107 | ||
|
|
ad082987d0 | ||
|
|
d9d47c3078 | ||
|
|
aa1d6ccbfb | ||
|
|
6a9799020b | ||
|
|
e4d2a43951 | ||
|
|
5c99581880 | ||
|
|
924f93e848 | ||
|
|
891ee641cb | ||
|
|
8132e933e6 | ||
|
|
92052e3945 | ||
|
|
2e41d0cb77 | ||
|
|
a47a3eada6 | ||
|
|
6f2ebcaa01 | ||
|
|
a920871c3a | ||
|
|
5a66b640f9 | ||
|
|
69eab26401 | ||
|
|
7ca04f328e | ||
|
|
ecfa290cfd | ||
|
|
b3f7261ffe | ||
|
|
3a1d8377ab | ||
|
|
19feada06f | ||
|
|
7695b7b5f4 | ||
|
|
d499330e9e | ||
|
|
06c35da6af | ||
|
|
420b208a45 | ||
|
|
793c3b4a7d | ||
|
|
dc180d1442 | ||
|
|
6c32a8add4 | ||
|
|
60943c5d5c | ||
|
|
39ad2833c0 | ||
|
|
871d93c462 | ||
|
|
927c3bdc18 | ||
|
|
a9a220b92a | ||
|
|
bf8bf105fb | ||
|
|
34fd00af5f | ||
|
|
7365c58783 | ||
|
|
bdff6a4c59 | ||
|
|
d4ee98940b | ||
|
|
02b8dfc524 | ||
|
|
403a73a351 | ||
|
|
18b76e6f80 | ||
|
|
8fede28c74 | ||
|
|
a9cc8961ed | ||
|
|
e18cb71e0c | ||
|
|
c38678d14b | ||
|
|
166fa4684f | ||
|
|
061c900176 | ||
|
|
ebdc8b48a5 | ||
|
|
ec0c48cb29 | ||
|
|
6714862bdd | ||
|
|
7a32aaacd0 | ||
|
|
b3c4e9add5 | ||
|
|
186685d46f | ||
|
|
4d0884a1ea | ||
|
|
7829b8d067 | ||
|
|
2a1eb31f18 | ||
|
|
2bec97c076 | ||
|
|
1130976f8e | ||
|
|
c3b7f7d6e7 | ||
|
|
193697db4e | ||
|
|
210aa14916 | ||
|
|
abac53b33c | ||
|
|
1ee52e8b14 | ||
|
|
933d10d308 | ||
|
|
fbef225c4b | ||
|
|
192ff35d9c | ||
|
|
0be933b505 | ||
|
|
50812fff21 | ||
|
|
de9e803149 | ||
|
|
e599b6d96e | ||
|
|
7dd2cec2fd | ||
|
|
84878fe20e | ||
|
|
0df910af49 | ||
|
|
5d3cb7cc1f | ||
|
|
8042f65398 | ||
|
|
acfc0d872e | ||
|
|
03195fc16f | ||
|
|
a199b17253 | ||
|
|
14dad7028b | ||
|
|
1ed9dd9d06 | ||
|
|
4534af2763 | ||
|
|
0775a07d87 | ||
|
|
4cc2e5e944 | ||
|
|
9fef17dec3 | ||
|
|
7c58e9be69 | ||
|
|
baf55a85fc | ||
|
|
e3906fcd94 | ||
|
|
99b12543cf | ||
|
|
242e3b6bde | ||
|
|
60a22addea | ||
|
|
a0ee881ba4 | ||
|
|
4176972db5 | ||
|
|
d827e8b665 | ||
|
|
b37367aa77 | ||
|
|
f853db54f9 | ||
|
|
75762705a3 | ||
|
|
419eed7501 | ||
|
|
5f8f32a41c | ||
|
|
8fc5d6d2da | ||
|
|
6fdacc74f0 | ||
|
|
a95e99e6f3 | ||
|
|
d9768d7cb9 | ||
|
|
1ff58b6570 | ||
|
|
8eb0dc1d10 | ||
|
|
3d184586a7 | ||
|
|
938e982c4d | ||
|
|
1d23f3a492 | ||
|
|
6069441bd2 | ||
|
|
91a0aac110 | ||
|
|
2ab6ff95e0 | ||
|
|
65d415d847 | ||
|
|
00f5ecb141 | ||
|
|
7940147e25 | ||
|
|
edcac5572f | ||
|
|
f8277ca992 | ||
|
|
74b007f7cc | ||
|
|
c59716ff4c | ||
|
|
6859d761d3 | ||
|
|
0d833ca7fd | ||
|
|
49c024addd | ||
|
|
e85dbfdd80 | ||
|
|
a71389bfe8 | ||
|
|
7373e485d3 | ||
|
|
87715170cc | ||
|
|
b230159958 | ||
|
|
df03932b7e | ||
|
|
70112da81a | ||
|
|
e707806894 | ||
|
|
3bc2b206b0 | ||
|
|
aead70b4d1 | ||
|
|
d0dd3d31e2 | ||
|
|
2a4a8d8ffb | ||
|
|
31a2e20bd3 | ||
|
|
41369af3f2 | ||
|
|
80cd3cfdbc | ||
|
|
f2f26e7fdd | ||
|
|
967c3d4406 | ||
|
|
1cd0445495 | ||
|
|
fc78b79575 | ||
|
|
efd4983eb1 | ||
|
|
d378c3149c | ||
|
|
88947dd05e | ||
|
|
2c0d0f0051 | ||
|
|
e4f9f3a960 | ||
|
|
0fe3e62e2c | ||
|
|
d2fd0d5869 | ||
|
|
acc257e994 | ||
|
|
e8fcf4bd69 | ||
|
|
2276d83639 | ||
|
|
cafc103230 | ||
|
|
1785ddcae2 | ||
|
|
8e139871fe | ||
|
|
0826b6b0b3 | ||
|
|
887ca79f04 | ||
|
|
360e254954 | ||
|
|
0b31586c71 | ||
|
|
51b8bd68bb | ||
|
|
599e3ce163 | ||
|
|
935daf2d0d | ||
|
|
7f90ed4460 | ||
|
|
796446718d | ||
|
|
8c4025e708 | ||
|
|
5222d31a15 | ||
|
|
549df2ebc3 | ||
|
|
7234c3a0b6 | ||
|
|
009ae1f17d | ||
|
|
abc9568690 | ||
|
|
b493dec91e | ||
|
|
69d4178708 | ||
|
|
9031481ac3 | ||
|
|
ed11993900 | ||
|
|
8c26fbe537 | ||
|
|
5b0f9e417e | ||
|
|
27f64e1f4e | ||
|
|
0fbff134f4 | ||
|
|
b0c39a8a8d | ||
|
|
3ece93ba0f | ||
|
|
8b1aa4d749 | ||
|
|
61f83059c1 | ||
|
|
9f92d5f2a2 | ||
|
|
2d34215456 | ||
|
|
b0fd2b06a3 | ||
|
|
a7d0b41c08 | ||
|
|
47abc49c4a | ||
|
|
3ad88ccf2d | ||
|
|
9ef2ea27d4 | ||
|
|
360060252a | ||
|
|
0c789a4255 | ||
|
|
fe1ef2bc62 | ||
|
|
6fb4e4877a | ||
|
|
0d2d1eb599 | ||
|
|
8610f91ebf | ||
|
|
27d3766e0d | ||
|
|
ad79c0b629 | ||
|
|
77d22c4abd | ||
|
|
1a92376f00 | ||
|
|
e90e741b1e | ||
|
|
fc059090b6 | ||
|
|
ff7661d9de | ||
|
|
1fca558799 | ||
|
|
ea1a63a201 | ||
|
|
c9aca4561d | ||
|
|
bc28f7a1e1 | ||
|
|
c06391be0d | ||
|
|
3b79370a7d | ||
|
|
b99cb64b80 | ||
|
|
a94a06a38e | ||
|
|
1d4ef2a9e9 | ||
|
|
53146cc9ec | ||
|
|
8302c43265 | ||
|
|
cffd5022c5 | ||
|
|
d11edf9809 | ||
|
|
236abbfd71 | ||
|
|
94a6a956f0 | ||
|
|
c6def44cfc | ||
|
|
13c26fc1a5 | ||
|
|
c30c5e89cf | ||
|
|
d8636cad4d | ||
|
|
f6495eb767 | ||
|
|
7ac868460a | ||
|
|
081df62b92 | ||
|
|
52e8d060a9 | ||
|
|
d77601178d | ||
|
|
64f70cc755 | ||
|
|
8187bb4394 | ||
|
|
820098fd61 | ||
|
|
aa385d4015 | ||
|
|
f63a20ad7b | ||
|
|
864b79791a | ||
|
|
26920c6c94 | ||
|
|
c088c582bf | ||
|
|
95bf6da637 | ||
|
|
a4a65e7f99 | ||
|
|
051e4c15db | ||
|
|
d598d41110 | ||
|
|
1372780662 | ||
|
|
3a01f8cae2 | ||
|
|
ef38b39262 | ||
|
|
aba75460e4 | ||
|
|
1323c940fd | ||
|
|
00a6a75035 | ||
|
|
1c31501b1b | ||
|
|
416340642d | ||
|
|
8db361b3e5 | ||
|
|
ed8e036360 | ||
|
|
86c76a9c2a | ||
|
|
0e28e1fa05 | ||
|
|
60e56f5292 | ||
|
|
54c14d7850 | ||
|
|
ae1036185e | ||
|
|
5f6873621d | ||
|
|
272a95524f | ||
|
|
a0782684fd | ||
|
|
744ec1d549 | ||
|
|
9fe5f98de4 | ||
|
|
c8459a5a8f | ||
|
|
19732c6226 | ||
|
|
4e116823f4 | ||
|
|
fb24eb4f47 | ||
|
|
defd998c42 | ||
|
|
1f30a41abe | ||
|
|
5d8d4a674b | ||
|
|
65a0730c9f | ||
|
|
3e6908b586 | ||
|
|
db7d5fca5f | ||
|
|
4c9b68f0e0 | ||
|
|
a66a43e8ef | ||
|
|
d75ac02a4f | ||
|
|
114de55668 | ||
|
|
1d1d2f9b18 | ||
|
|
497a88506e | ||
|
|
85208e2ab9 | ||
|
|
b1591d1f8b | ||
|
|
a3603e845e | ||
|
|
265d229427 | ||
|
|
fcffa2cc1a | ||
|
|
50e4d660ac | ||
|
|
45673d2cc0 | ||
|
|
5c69cd84ff | ||
|
|
75ce8d7c88 | ||
|
|
130bec5ad8 | ||
|
|
ae28b04ff2 | ||
|
|
c57e42b8f0 | ||
|
|
8a8308f129 | ||
|
|
66388f89a5 | ||
|
|
50aec98e1c | ||
|
|
6feaeace86 | ||
|
|
cf32ac543c | ||
|
|
35d60421b4 | ||
|
|
9cdb0601eb | ||
|
|
fa15f702d2 | ||
|
|
ef8b112d77 | ||
|
|
b88868276c | ||
|
|
83788da250 | ||
|
|
27eff033d2 | ||
|
|
c7a3fb96d0 | ||
|
|
b0cc0a6ca8 | ||
|
|
889a301a0c | ||
|
|
900c24dc4e | ||
|
|
5a40651046 | ||
|
|
89de1e7930 | ||
|
|
b5474c48b1 | ||
|
|
b159146fa6 | ||
|
|
3ad0bd9563 | ||
|
|
3ec5c692ec | ||
|
|
aee53f4604 | ||
|
|
b3de66869b | ||
|
|
0efab3319d | ||
|
|
3b1cbd7bec | ||
|
|
38ddbed4c1 | ||
|
|
08ed1a73f1 | ||
|
|
806c74fe19 | ||
|
|
f64c1cd26d | ||
|
|
a1bbde71bf | ||
|
|
3bd31ebc9a | ||
|
|
372f91f07c | ||
|
|
bc12fb79fd | ||
|
|
1b17b01584 | ||
|
|
0298be88ae | ||
|
|
684d745bf3 | ||
|
|
02a4ed9264 | ||
|
|
49da8a83ad | ||
|
|
a99b194336 | ||
|
|
eed9451cf6 | ||
|
|
fa144713b8 | ||
|
|
6b140ea5a9 | ||
|
|
7c71822809 | ||
|
|
b5b757eb8d | ||
|
|
6be2319873 | ||
|
|
ad6faf6497 | ||
|
|
4271d438e2 | ||
|
|
d4574f1b61 | ||
|
|
c00e4ff8e5 | ||
|
|
3b7767abe6 | ||
|
|
796245b554 | ||
|
|
8fd6e1fb0f | ||
|
|
d7f7bd0445 | ||
|
|
02a415606c | ||
|
|
8833a51781 | ||
|
|
9bd49d6a22 | ||
|
|
592a3e63ee | ||
|
|
273af73317 | ||
|
|
eb83478528 | ||
|
|
369da77d5e | ||
|
|
20d739adf7 | ||
|
|
53a2299230 | ||
|
|
467a18b1d9 | ||
|
|
a3181dd833 | ||
|
|
ba552523fa | ||
|
|
d35c5df08c | ||
|
|
b75b6e2c35 | ||
|
|
038cbc7442 | ||
|
|
c94e89d81f | ||
|
|
db2b9f37d4 | ||
|
|
8ec99dfa05 | ||
|
|
d402f971a5 | ||
|
|
eeba178d3a | ||
|
|
7d957c6573 | ||
|
|
665b4e69ed | ||
|
|
7875f5b72a | ||
|
|
55ed17747f | ||
|
|
4fa2bb5e95 | ||
|
|
9eaf059d28 | ||
|
|
5ed78adca5 | ||
|
|
d299563257 | ||
|
|
9758e7d58d | ||
|
|
f3fbe20c35 | ||
|
|
01d2ea908b | ||
|
|
39fcb5a750 | ||
|
|
0733e840bd | ||
|
|
d21735de2d | ||
|
|
87ac7028e0 | ||
|
|
438803311b | ||
|
|
9a218bf979 | ||
|
|
1a6986699f | ||
|
|
eec2bbb9bf | ||
|
|
2aef3a6bb9 | ||
|
|
95877b6756 | ||
|
|
79a466f128 | ||
|
|
6d13964714 | ||
|
|
e7dd383f67 | ||
|
|
b9c0b99e51 | ||
|
|
70624846fd | ||
|
|
1fcc66e685 | ||
|
|
ceef50b280 | ||
|
|
f1f2bd0b0a | ||
|
|
9910cd2869 | ||
|
|
1f0c43668a | ||
|
|
31c73af656 | ||
|
|
2b1effdbbc | ||
|
|
c5b5cab37d | ||
|
|
38c15becf6 | ||
|
|
5a841adf5d | ||
|
|
fb74a45088 | ||
|
|
f3f9062ecf | ||
|
|
730f826f25 | ||
|
|
ace02dc9cd | ||
|
|
46ea0e4696 | ||
|
|
6925d50176 | ||
|
|
de2a342289 | ||
|
|
e62dc86bc7 | ||
|
|
04ae328851 | ||
|
|
14b7c5d12b | ||
|
|
741f40b58e | ||
|
|
72812d3143 | ||
|
|
a2e6908165 | ||
|
|
90c2abd212 | ||
|
|
dec43433e5 | ||
|
|
2423b12dae | ||
|
|
05b5addcaa | ||
|
|
07a37aebf5 | ||
|
|
dba11452cb | ||
|
|
1a781a499f | ||
|
|
603557b466 | ||
|
|
089db51fbe | ||
|
|
3eeab3b23f | ||
|
|
6834ee941a | ||
|
|
54805af092 | ||
|
|
c98c06233e | ||
|
|
b24d65659f | ||
|
|
06656f363d | ||
|
|
db930948a9 | ||
|
|
463304edfd | ||
|
|
356b6dbf86 | ||
|
|
0ee0a8d539 | ||
|
|
b6ecbdc07d | ||
|
|
ebd8065f38 | ||
|
|
2dd2d7a37d | ||
|
|
b9df470c4d | ||
|
|
249f39a265 | ||
|
|
ef03dbcd4d | ||
|
|
aad44fb37a | ||
|
|
3280f9a3fc | ||
|
|
6509f92a3b | ||
|
|
1dbbd2fe34 | ||
|
|
ed8a9be287 | ||
|
|
c3657428d3 | ||
|
|
38288bbf4c | ||
|
|
8a35c9a557 | ||
|
|
9e6c9f7311 | ||
|
|
74afa9aed1 | ||
|
|
c29ab97094 | ||
|
|
1477ad8e83 | ||
|
|
02d090d3d2 | ||
|
|
2480e3a30a | ||
|
|
1dbd6ff80f | ||
|
|
585f657e2d | ||
|
|
0c390a76fe | ||
|
|
fd3f1be57f | ||
|
|
355a61b56f | ||
|
|
66c22051f9 | ||
|
|
dbdc0d5da9 | ||
|
|
4d7f9c3d99 |
No files matched your search
@@ -45,7 +45,7 @@ Karl M. Hegbloom <karlheg@debian.org>
|
||||
Daniel Jacobowitz <dan@debian.org>
|
||||
mktemp.c
|
||||
|
||||
Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
Matt Kraai <kraai@alumni.cmu.edu>
|
||||
documentation, bugfixes, test suite
|
||||
|
||||
John Lombardo <john@deltanet.com>
|
||||
@@ -55,7 +55,8 @@ Glenn McGrath <bug1@optushome.com.au>
|
||||
ar, dpkg, dpkg-deb
|
||||
|
||||
Vladimir Oleynik <dzo@simtreas.ru>
|
||||
cmdedit; ports: ash, stty, traceroute; locale, various fixes
|
||||
cmdedit; ports: ash, crond, stty, traceroute, telnetd, top;
|
||||
locale, various fixes
|
||||
and irreconcilable critic of everything not perfect.
|
||||
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
|
||||
@@ -7,7 +7,10 @@
|
||||
New Applets:
|
||||
* Erik Andersen -- Merged several applets from tinylogin,
|
||||
namely adduser, addgroup, deluser, delgroup, getty.
|
||||
|
||||
* Robert Griebl <sandman@handhelds.org>
|
||||
-- reimplemented tinylogin applets: su, login
|
||||
-- added hwclock
|
||||
-- added uncompress
|
||||
|
||||
Other Changes:
|
||||
|
||||
@@ -15,7 +18,7 @@
|
||||
-- a whole bunch of ash size optimizations
|
||||
-- Fix for ash leading redirections (i.e. '2>/dev/null ls rubbish')
|
||||
* Rodney Brown <RDBrown@mira.net>
|
||||
-- Optimized gzip.c, shrinking it be ~1.5k
|
||||
-- Optimized gzip.c, shrinking it by ~1.5k
|
||||
* Matt Kraai
|
||||
-- Fix sed s/[/]// handling (closes: #1208).
|
||||
-- Fix `-/bin/sh' invocation (closes: #1209).
|
||||
@@ -32,7 +35,35 @@
|
||||
applets, fix print nslookup server name if compile without
|
||||
uClibc, fix route crashe 'route add', fix warnings compile
|
||||
networking and pwd_grp applets
|
||||
* Tim Riker <Tim@Rikers.org>
|
||||
-- fix and shrink uuencode
|
||||
-- allow tty* in inittab if exist, serial console is not the issue
|
||||
* Robert Griebl <sandman@handhelds.org>
|
||||
-- added suid/sgid handling with 3 modes to busybox:
|
||||
1) completly disabled
|
||||
2) tinylogin like
|
||||
3) runtime configureable via /etc/busybox.conf
|
||||
|
||||
-- modprobe: complete rewrite, supports modules.dep, parses
|
||||
modules.conf for alias and options and can be called
|
||||
from the kernel.
|
||||
-- tar: support for -z when creating archives
|
||||
-- wget: support for -Y|--proxy=on/off and --passive-ftp
|
||||
-- vi: support for ":x"
|
||||
-- date: support for -I (ISO format)
|
||||
-- find: support for -xdev
|
||||
-- mount: support for -t in list mode, parsing of /etc/filesystems
|
||||
-- ash: support for --login (bash like)
|
||||
-- route: support for -e
|
||||
-- netstat: support for -e and -r
|
||||
-- head/tail: support for old style -[0-9] options
|
||||
-- sed: support for ! and \CregexpC
|
||||
-- pidof: support for -s
|
||||
-- nslookup: support for user specified name server
|
||||
|
||||
-- logger: fixed logging of '<' characters
|
||||
-- ash: fixed crash when run in a rxvt window
|
||||
|
||||
-Erik Andersen, --not yet released--
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
|
||||
# Copyright (C) 1999-2002 Erik Andersen <andersee@debian.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,171 +17,13 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
PROG := busybox
|
||||
VERSION := 0.61.pre
|
||||
BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
|
||||
TOPDIR := ${shell /bin/pwd}
|
||||
HOSTCC := gcc
|
||||
HOSTCFLAGS:= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
|
||||
|
||||
|
||||
# What OS are you compiling busybox for? This allows you to include
|
||||
# OS specific things, syscall overrides, etc.
|
||||
TARGET_OS := linux
|
||||
|
||||
# With a modern GNU make(1) (highly recommended, that's what all the
|
||||
# developers use), all of the following configuration values can be
|
||||
# overridden at the command line. For example:
|
||||
# make CROSS=powerpc-linux- CONFIG_SRC_DIR=$HOME/busybox PREFIX=/mnt/app
|
||||
|
||||
# If you want to add some simple compiler switches (like -march=i686),
|
||||
# especially from the command line, use this instead of CFLAGS directly.
|
||||
# For optimization overrides, it's better still to set OPTIMIZATION.
|
||||
CFLAGS_EXTRA =
|
||||
|
||||
# If you want a static binary, turn this on.
|
||||
DOSTATIC = false
|
||||
|
||||
# Set the following to `true' to make a debuggable build.
|
||||
# Leave this set to `false' for production use.
|
||||
DODEBUG = false
|
||||
|
||||
# This enables compiling with dmalloc ( http://dmalloc.com/ )
|
||||
# which is an excellent public domain mem leak and malloc problem
|
||||
# detector. To enable dmalloc, before running busybox you will
|
||||
# want to first set up your environment.
|
||||
# eg: `export DMALLOC_OPTIONS=debug=0x14f47d83,inter=100,log=logfile`
|
||||
# Do not enable this for production builds...
|
||||
DODMALLOC = false
|
||||
|
||||
# Electric-fence is another very useful malloc debugging library.
|
||||
# Do not enable this for production builds...
|
||||
DOEFENCE = false
|
||||
|
||||
# If you want large file summit support, turn this on.
|
||||
# This has no effect if you don't have a kernel with lfs
|
||||
# support, and a system with libc-2.1.3 or later.
|
||||
# Some of the programs that can benefit from lfs support
|
||||
# are dd, gzip, mount, tar, and mkfs_minix.
|
||||
# LFS allows you to use the above programs for files
|
||||
# larger than 2GB!
|
||||
DOLFS = false
|
||||
|
||||
# If you have a "pristine" source directory, point CONFIG_SRC_DIR to it.
|
||||
# Experimental and incomplete; tell the mailing list
|
||||
# <busybox@opensource.lineo.com> if you do or don't like it so far.
|
||||
CONFIG_SRC_DIR =
|
||||
|
||||
# If you are running a cross compiler, you may want to set CROSS
|
||||
# to something more interesting, like "arm-linux-".
|
||||
CROSS =
|
||||
CC = $(CROSS)gcc
|
||||
AR = $(CROSS)ar
|
||||
AS = $(CROSS)as
|
||||
LD = $(CROSS)ld
|
||||
NM = $(CROSS)nm
|
||||
STRIP = $(CROSS)strip
|
||||
CPP = $(CC) -E
|
||||
MAKEFILES = $(TOPDIR)/.config
|
||||
export VERSION BUILDTIME TOPDIR HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
|
||||
|
||||
|
||||
# To compile vs uClibc, just use the compiler wrapper built by uClibc...
|
||||
# Everything should compile and work as expected these days...
|
||||
#CC = /usr/i386-linux-uclibc/usr/bin/i386-uclibc-gcc
|
||||
|
||||
# To compile vs some other alternative libc, you may need to use/adjust
|
||||
# the following lines to meet your needs...
|
||||
#
|
||||
# If you are using Red Hat 6.x with the compatible RPMs (for developing under
|
||||
# Red Hat 5.x and glibc 2.0) uncomment the following. Be sure to read about
|
||||
# using the compatible RPMs (compat-*) at http://www.redhat.com !
|
||||
#LIBCDIR=/usr/i386-glibc20-linux
|
||||
#
|
||||
# The following is used for libc5 (if you install altgcc and libc5-altdev
|
||||
# on a Debian system).
|
||||
#LIBCDIR=/usr/i486-linuxlibc1
|
||||
#
|
||||
# For other libraries, you are on your own...
|
||||
#LDFLAGS+=-nostdlib
|
||||
#LIBRARIES = $(LIBCDIR)/lib/libc.a -lgcc
|
||||
#CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR)
|
||||
#GCCINCDIR = $(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
|
||||
|
||||
# use '-Os' optimization if available, else use -O2
|
||||
OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null \
|
||||
>/dev/null 2>&1; then echo "-Os"; else echo "-O2" ; fi}
|
||||
GCC_STACK_BOUNDRY := ${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc /dev/null \
|
||||
>/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; else echo "" ; fi}
|
||||
OPTIMIZATIONS=$(OPTIMIZATION) -fomit-frame-pointer $(GCC_STACK_BOUNDRY)
|
||||
WARNINGS=-Wall -Wstrict-prototypes -Wshadow
|
||||
CFLAGS = -I$(TOPDIR)/include
|
||||
ARFLAGS = -r
|
||||
|
||||
#
|
||||
#--------------------------------------------------------
|
||||
# If you're going to do a lot of builds with a non-vanilla configuration,
|
||||
# it makes sense to adjust parameters above, so you can type "make"
|
||||
# by itself, instead of following it by the same half-dozen overrides
|
||||
# every time. The stuff below, on the other hand, is probably less
|
||||
# prone to casual user adjustment.
|
||||
#
|
||||
|
||||
ifeq ($(strip $(DOLFS)),true)
|
||||
# For large file summit support
|
||||
CFLAGS+=-D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64
|
||||
endif
|
||||
ifeq ($(strip $(DODMALLOC)),true)
|
||||
# For testing mem leaks with dmalloc
|
||||
CFLAGS+=-DDMALLOC
|
||||
LIBRARIES = -ldmalloc
|
||||
# Force debug=true, since this is useless when not debugging...
|
||||
DODEBUG = true
|
||||
else
|
||||
ifeq ($(strip $(DOEFENCE)),true)
|
||||
LIBRARIES = -lefence
|
||||
# Force debug=true, since this is useless when not debugging...
|
||||
DODEBUG = true
|
||||
endif
|
||||
endif
|
||||
ifeq ($(strip $(DODEBUG)),true)
|
||||
CFLAGS += $(WARNINGS) -g -D_GNU_SOURCE
|
||||
LDFLAGS += -Wl,-warn-common
|
||||
STRIPCMD =
|
||||
else
|
||||
CFLAGS += $(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE
|
||||
LDFLAGS += -s -Wl,-warn-common
|
||||
STRIPCMD = $(STRIP) --remove-section=.note --remove-section=.comment $(PROG)
|
||||
endif
|
||||
ifeq ($(strip $(DOSTATIC)),true)
|
||||
LDFLAGS += --static
|
||||
endif
|
||||
|
||||
ifndef $(PREFIX)
|
||||
PREFIX = `pwd`/_install
|
||||
endif
|
||||
|
||||
# Additional complications due to support for pristine source dir.
|
||||
# Include files in the build directory should take precedence over
|
||||
# the copy in CONFIG_SRC_DIR, both during the compilation phase and the
|
||||
# shell script that finds the list of object files.
|
||||
# Work in progress by <ldoolitt@recycle.lbl.gov>.
|
||||
#
|
||||
ifneq ($(strip $(CONFIG_SRC_DIR)),)
|
||||
VPATH = $(CONFIG_SRC_DIR)
|
||||
endif
|
||||
|
||||
OBJECTS = $(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
|
||||
CFLAGS += $(CROSS_CFLAGS)
|
||||
ifdef CONFIG_INIT_SCRIPT
|
||||
CFLAGS += -DINIT_SCRIPT='"$(CONFIG_INIT_SCRIPT)"'
|
||||
endif
|
||||
|
||||
# Put user-supplied flags at the end, where they
|
||||
# have a chance of winning.
|
||||
CFLAGS += $(CFLAGS_EXTRA)
|
||||
|
||||
.EXPORT_ALL_VARIABLES:
|
||||
TOPDIR:= $(shell /bin/pwd)/
|
||||
include $(TOPDIR).config
|
||||
include $(TOPDIR)Rules.mak
|
||||
SUBDIRS:=applets archival archival/libunarchive console-tools \
|
||||
editors fileutils findutils init miscutils modutils networking \
|
||||
networking/udhcp procps loginutils shell shellutils sysklogd \
|
||||
textutils util-linux libbb libpwdgrp
|
||||
|
||||
all: do-it-all
|
||||
|
||||
@@ -192,7 +34,8 @@ ifeq (.config,$(wildcard .config))
|
||||
include .config
|
||||
ifeq (.depend,$(wildcard .depend))
|
||||
include .depend
|
||||
do-it-all: busybox busybox.links doc
|
||||
do-it-all: busybox busybox.links #doc
|
||||
include $(patsubst %,%/Makefile.in, $(SUBDIRS))
|
||||
else
|
||||
CONFIGURATION = depend
|
||||
do-it-all: depend
|
||||
@@ -203,18 +46,9 @@ do-it-all: menuconfig
|
||||
endif
|
||||
|
||||
|
||||
SUBDIRS =applets archival archival/libunarchive console-tools editors \
|
||||
fileutils findutils init miscutils modutils networking procps \
|
||||
pwd_grp shell shellutils sysklogd textutils util-linux libbb
|
||||
|
||||
bbsubdirs: $(patsubst %, _dir_%, $(SUBDIRS))
|
||||
|
||||
$(patsubst %, _dir_%, $(SUBDIRS)) : dummy include/config/MARKER
|
||||
$(MAKE) CFLAGS="$(CFLAGS)" -C $(patsubst _dir_%, %, $@)
|
||||
|
||||
busybox: config.h dep-files bbsubdirs
|
||||
$(CC) $(LDFLAGS) -o $@ applets/busybox.o $(shell find $(SUBDIRS) -name \*.a) $(LIBCONFIG_LIB) $(LIBRARIES)
|
||||
$(STRIPCMD)
|
||||
busybox: depend $(libraries-y)
|
||||
$(CC) $(LDFLAGS) -o $@ $(libraries-y) $(LIBRARIES)
|
||||
$(STRIPCMD) $@
|
||||
|
||||
busybox.links: applets/busybox.mkll
|
||||
- $(SHELL) $^ >$@
|
||||
@@ -222,6 +56,9 @@ busybox.links: applets/busybox.mkll
|
||||
install: applets/install.sh busybox busybox.links
|
||||
$(SHELL) $< $(PREFIX)
|
||||
|
||||
uninstall: busybox busybox.links
|
||||
for i in `cat busybox.links` ; do rm -f $$PREFIX$$i; done
|
||||
|
||||
install-hardlinks: applets/install.sh busybox busybox.links
|
||||
$(SHELL) $< $(PREFIX) --hardlinks
|
||||
|
||||
@@ -249,15 +86,15 @@ docs/BusyBox.1: docs/busybox.pod
|
||||
- pod2man --center=BusyBox --release="version $(VERSION)" \
|
||||
$< > $@
|
||||
|
||||
docs/BusyBox.html: docs/busybox.lineo.com/BusyBox.html
|
||||
docs/BusyBox.html: docs/busybox.net/BusyBox.html
|
||||
- mkdir -p docs
|
||||
-@ rm -f docs/BusyBox.html
|
||||
-@ ln -s busybox.lineo.com/BusyBox.html docs/BusyBox.html
|
||||
-@ ln -s busybox.net/BusyBox.html docs/BusyBox.html
|
||||
|
||||
docs/busybox.lineo.com/BusyBox.html: docs/busybox.pod
|
||||
-@ mkdir -p docs/busybox.lineo.com
|
||||
docs/busybox.net/BusyBox.html: docs/busybox.pod
|
||||
-@ mkdir -p docs/busybox.net
|
||||
- pod2html --noindex $< > \
|
||||
docs/busybox.lineo.com/BusyBox.html
|
||||
docs/busybox.net/BusyBox.html
|
||||
-@ rm -f pod2htm*
|
||||
|
||||
|
||||
@@ -285,55 +122,60 @@ docs/busybox.pdf: docs/busybox.ps
|
||||
|
||||
docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
|
||||
- mkdir -p docs
|
||||
(cd docs/busybox.lineo.com; sgmltools -b html ../busybox.sgml)
|
||||
(cd docs/busybox.net; sgmltools -b html ../busybox.sgml)
|
||||
|
||||
|
||||
|
||||
# The nifty new buildsystem stuff
|
||||
scripts/mkdep: scripts/mkdep.c
|
||||
$(TOPDIR)scripts/mkdep: scripts/mkdep.c
|
||||
$(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
|
||||
|
||||
scripts/split-include: scripts/split-include.c
|
||||
$(TOPDIR)scripts/split-include: scripts/split-include.c
|
||||
$(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c
|
||||
|
||||
dep-files: scripts/mkdep
|
||||
@if [ ! -f .depend ] ; then \
|
||||
rm -f .depend .hdepend; \
|
||||
mkdir -p $(TOPDIR)/include/config; \
|
||||
scripts/mkdep -I $(TOPDIR)/include -- \
|
||||
`find $(TOPDIR) -name \*.c -print` >> .depend; \
|
||||
scripts/mkdep -I $(TOPDIR)/include -- \
|
||||
`find $(TOPDIR) -name \*.h -print` >> .hdepend; \
|
||||
$(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS)) _FASTDEP_ALL_SUB_DIRS="$(SUBDIRS)" ; \
|
||||
fi;
|
||||
|
||||
|
||||
depend dep: config.h dep-files
|
||||
$(TOPDIR).depend: $(TOPDIR)scripts/mkdep
|
||||
rm -f .depend .hdepend;
|
||||
mkdir -p $(TOPDIR)include/config;
|
||||
$(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c
|
||||
scripts/mkdep -I $(TOPDIR)include -- \
|
||||
`find $(TOPDIR) -name \*.c -print` >> .depend;
|
||||
scripts/mkdep -I $(TOPDIR)include -- \
|
||||
`find $(TOPDIR) -name \*.h -print` >> .hdepend;
|
||||
$(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS)) _FASTDEP_ALL_SUB_DIRS="$(SUBDIRS)" ;
|
||||
@ echo -e "\n\nNow run 'make' to build BusyBox\n\n"
|
||||
|
||||
CONFIG_SHELL := ${shell if [ -x "$$BASH" ]; then echo $$BASH; \
|
||||
depend dep: $(TOPDIR)include/config.h $(TOPDIR).depend
|
||||
|
||||
BB_SHELL := ${shell if [ -x "$$BASH" ]; then echo $$BASH; \
|
||||
else if [ -x /bin/bash ]; then echo /bin/bash; \
|
||||
else echo sh; fi ; fi}
|
||||
|
||||
include/config/MARKER: scripts/split-include include/config.h
|
||||
include/config/MARKER: depend $(TOPDIR)scripts/split-include
|
||||
scripts/split-include include/config.h include/config
|
||||
@ touch include/config/MARKER
|
||||
|
||||
config.h:
|
||||
@if [ ! -f include/config.h ] ; then \
|
||||
$(TOPDIR)include/config.h:
|
||||
@if [ ! -f $(TOPDIR)include/config.h ] ; then \
|
||||
make oldconfig; \
|
||||
fi;
|
||||
|
||||
menuconfig:
|
||||
mkdir -p $(TOPDIR)/include/config
|
||||
$(TOPDIR).config:
|
||||
@if [ ! -f $(TOPDIR).config ] ; then \
|
||||
cp $(TOPDIR)sysdeps/$(TARGET_OS)/defconfig $(TOPDIR).config; \
|
||||
fi;
|
||||
|
||||
menuconfig: $(TOPDIR).config
|
||||
mkdir -p $(TOPDIR)include/config
|
||||
$(MAKE) -C scripts/lxdialog all
|
||||
$(CONFIG_SHELL) scripts/Menuconfig sysdeps/$(TARGET_OS)/config.in
|
||||
$(BB_SHELL) scripts/Menuconfig sysdeps/$(TARGET_OS)/config.in
|
||||
|
||||
config:
|
||||
mkdir -p $(TOPDIR)/include/config
|
||||
$(CONFIG_SHELL) scripts/Configure sysdeps/$(TARGET_OS)/config.in
|
||||
config: $(TOPDIR).config
|
||||
mkdir -p $(TOPDIR)include/config
|
||||
$(BB_SHELL) scripts/Configure sysdeps/$(TARGET_OS)/config.in
|
||||
|
||||
oldconfig:
|
||||
mkdir -p $(TOPDIR)/include/config
|
||||
$(CONFIG_SHELL) scripts/Configure -d sysdeps/$(TARGET_OS)/config.in
|
||||
oldconfig: $(TOPDIR).config
|
||||
mkdir -p $(TOPDIR)include/config
|
||||
$(BB_SHELL) scripts/Configure -d sysdeps/$(TARGET_OS)/config.in
|
||||
|
||||
|
||||
ifdef CONFIGURATION
|
||||
@@ -355,7 +197,10 @@ dummy:
|
||||
|
||||
endif
|
||||
|
||||
include Rules.mak
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
|
||||
# Testing...
|
||||
test tests:
|
||||
@@ -369,16 +214,17 @@ clean:
|
||||
- $(MAKE) -C tests clean
|
||||
- $(MAKE) -C scripts/lxdialog clean
|
||||
- rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
|
||||
docs/busybox.lineo.com/BusyBox.html
|
||||
docs/busybox.net/BusyBox.html
|
||||
- rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
|
||||
docs/busybox.pdf docs/busybox.lineo.com/busybox.html \
|
||||
docs/busybox.pdf docs/busybox.pod docs/busybox.net/busybox.html \
|
||||
docs/busybox _install pod2htm* *.gdb *.elf *~ core
|
||||
- rm -f busybox.links libbb/loop.h .config.old .hdepend
|
||||
- rm -f busybox busybox.links libbb/loop.h .config.old .hdepend
|
||||
- rm -f scripts/split-include scripts/mkdep .*config.log
|
||||
- rm -rf include/config include/config.h
|
||||
- find -name .\*.flags -o -name .depend -exec rm -f {} \;
|
||||
- find -name \*.o -exec rm -f {} \;
|
||||
- find -name \*.a -exec rm -f {} \;
|
||||
- find . -name .\*.flags -exec rm -f {} \;
|
||||
- find . -name .depend -exec rm -f {} \;
|
||||
- find . -name \*.o -exec rm -f {} \;
|
||||
- find . -name \*.a -exec rm -f {} \;
|
||||
|
||||
distclean: clean
|
||||
- rm -f busybox
|
||||
@@ -403,9 +249,11 @@ dist release: distclean doc
|
||||
|
||||
|
||||
|
||||
.PHONY: tags check
|
||||
.PHONY: tags check depend
|
||||
|
||||
tags:
|
||||
ctags -R .
|
||||
|
||||
check: busybox
|
||||
cd testsuite && ./runtest
|
||||
|
||||
@@ -35,7 +35,7 @@ Supported architectures:
|
||||
Busybox in general will build on any architecture supported by gcc. It has
|
||||
a few specialized features added for __sparc__ and __alpha__. insmod
|
||||
functionality is currently limited to x86, ARM, SH3/4, powerpc, m68k,
|
||||
and MIPS.
|
||||
MIPS, and v850e.
|
||||
|
||||
Supported libcs:
|
||||
|
||||
@@ -83,7 +83,7 @@ top of ash.c as well, so check those out if you want to tweak things.
|
||||
Getting help:
|
||||
|
||||
When you find you need help, you can check out the BusyBox mailing list
|
||||
archives at http://oss.lineo.com/lists/busybox/ or even join
|
||||
archives at http://busybox.net/lists/busybox/ or even join
|
||||
the mailing list if you are interested.
|
||||
|
||||
----------------
|
||||
@@ -91,12 +91,12 @@ the mailing list if you are interested.
|
||||
Bugs:
|
||||
|
||||
If you find bugs, please submit a bug report. Full instructions on how to
|
||||
report a bug are found at http://bugs.lineo.com/Reporting.html.
|
||||
report a bug are found at http://bugs.busybox.net/Reporting.html.
|
||||
|
||||
For the impatient: To submit a bug, simply send an email describing the problem
|
||||
to submit@bugs.lineo.com. Bug reports should look something like this:
|
||||
to submit@bugs.busybox.net. Bug reports should look something like this:
|
||||
|
||||
To: submit@bugs.lineo.com
|
||||
To: submit@bugs.busybox.net
|
||||
From: diligent@testing.linux.org
|
||||
Subject: /bin/true doesn't work
|
||||
|
||||
@@ -123,21 +123,22 @@ understanding.
|
||||
|
||||
FTP:
|
||||
|
||||
Source for the latest released version can always be downloaded from
|
||||
ftp://ftp.lineo.com/pub/busybox.
|
||||
Source for the latest released version, as well as daily snapshots, can always
|
||||
be downloaded from
|
||||
http://busybox.net/downloads/
|
||||
|
||||
----------------
|
||||
|
||||
CVS:
|
||||
|
||||
BusyBox now has its own publicly browsable CVS tree at:
|
||||
http://oss.lineo.com/cgi-bin/cvsweb/busybox/
|
||||
http://busybox.net/cgi-bin/cvsweb/busybox/
|
||||
|
||||
Anonymous CVS access is available. For instructions, check out:
|
||||
http://oss.lineo.com/cvs_anon.html
|
||||
http://busybox.net/cvs_anon.html
|
||||
|
||||
For those that are actively contributing there is even CVS write access:
|
||||
http://oss.lineo.com/cvs_write.html
|
||||
http://busybox.net/cvs_write.html
|
||||
|
||||
----------------
|
||||
|
||||
|
||||
@@ -1,195 +1,238 @@
|
||||
# Rules.make for busybox
|
||||
#
|
||||
# This file contains rules which are shared between multiple Makefiles.
|
||||
# Copyright (C) 2002 Erik Andersen <andersee@debian.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
#
|
||||
# False targets.
|
||||
#
|
||||
.PHONY: dummy
|
||||
|
||||
#
|
||||
# Special variables which should not be exported
|
||||
#
|
||||
unexport EXTRA_AFLAGS
|
||||
unexport EXTRA_CFLAGS
|
||||
unexport EXTRA_LDFLAGS
|
||||
unexport EXTRA_ARFLAGS
|
||||
unexport SUBDIRS
|
||||
unexport SUB_DIRS
|
||||
unexport ALL_SUB_DIRS
|
||||
unexport O_TARGET
|
||||
|
||||
unexport obj-y
|
||||
unexport obj-n
|
||||
unexport obj-
|
||||
unexport export-objs
|
||||
unexport subdir-y
|
||||
unexport subdir-n
|
||||
unexport subdir-
|
||||
|
||||
#
|
||||
# Get things started.
|
||||
#
|
||||
first_rule: sub_dirs
|
||||
$(MAKE) all_targets
|
||||
|
||||
SUB_DIRS := $(subdir-y)
|
||||
ALL_SUB_DIRS := $(sort $(subdir-y) $(subdir-n) $(subdir-))
|
||||
PROG := busybox
|
||||
VERSION := 0.61.pre
|
||||
BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
|
||||
HOSTCC := gcc
|
||||
HOSTCFLAGS:= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
|
||||
|
||||
|
||||
#
|
||||
# Common rules
|
||||
#
|
||||
# What OS are you compiling busybox for? This allows you to include
|
||||
# OS specific things, syscall overrides, etc.
|
||||
TARGET_OS:=linux
|
||||
|
||||
%.s: %.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -S $< -o $@
|
||||
# With a modern GNU make(1) (highly recommended, that's what all the
|
||||
# developers use), all of the following configuration values can be
|
||||
# overridden at the command line. For example:
|
||||
# make CROSS=powerpc-linux- BB_SRC_DIR=$HOME/busybox PREFIX=/mnt/app
|
||||
|
||||
%.i: %.c
|
||||
$(CPP) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) $< > $@
|
||||
# If you want to add some simple compiler switches (like -march=i686),
|
||||
# especially from the command line, use this instead of CFLAGS directly.
|
||||
# For optimization overrides, it's better still to set OPTIMIZATION.
|
||||
CFLAGS_EXTRA:=#-Werror
|
||||
|
||||
# If you want a static binary, turn this on.
|
||||
DOSTATIC:=false
|
||||
|
||||
# Set the following to `true' to make a debuggable build.
|
||||
# Leave this set to `false' for production use.
|
||||
DODEBUG:=false
|
||||
|
||||
# This enables compiling with dmalloc ( http://dmalloc.com/ )
|
||||
# which is an excellent public domain mem leak and malloc problem
|
||||
# detector. To enable dmalloc, before running busybox you will
|
||||
# want to first set up your environment.
|
||||
# eg: `export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile`
|
||||
# The debug= value is generated using the following command
|
||||
# dmalloc -p log-stats -p log-non-free -p log-bad-space -p log-elapsed-time \
|
||||
# -p check-fence -p check-heap -p check-lists -p check-blank \
|
||||
# -p check-funcs -p realloc-copy -p allow-free-null
|
||||
# Do not enable this for production builds...
|
||||
DODMALLOC:=false
|
||||
|
||||
# Electric-fence is another very useful malloc debugging library.
|
||||
# Do not enable this for production builds...
|
||||
DOEFENCE:=false
|
||||
|
||||
# If you want large file summit support, turn this on.
|
||||
# This has no effect if you don't have a kernel with lfs
|
||||
# support, and a system with libc-2.1.3 or later.
|
||||
# Some of the programs that can benefit from lfs support
|
||||
# are dd, gzip, mount, tar, and mkfs_minix.
|
||||
# LFS allows you to use the above programs for files
|
||||
# larger than 2GB!
|
||||
DOLFS:=false
|
||||
|
||||
# If you have a "pristine" source directory, point BB_SRC_DIR to it.
|
||||
# Experimental and incomplete; tell the mailing list
|
||||
# <busybox@busybox.net> if you do or don't like it so far.
|
||||
BB_SRC_DIR:=
|
||||
|
||||
# If you are running a cross compiler, you may want to set CROSS
|
||||
# to something more interesting, like "arm-linux-".
|
||||
CROSS:=
|
||||
CC := $(CROSS)gcc
|
||||
AR := $(CROSS)ar
|
||||
AS := $(CROSS)as
|
||||
LD := $(CROSS)ld
|
||||
NM := $(CROSS)nm
|
||||
STRIP := $(CROSS)strip
|
||||
CPP := $(CC) -E
|
||||
MAKEFILES := $(TOPDIR).config
|
||||
export VERSION BUILDTIME TOPDIR HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
|
||||
|
||||
|
||||
# To compile vs uClibc, just use the compiler wrapper built by uClibc...
|
||||
# Everything should compile and work as expected these days...
|
||||
#CC:=/usr/i386-linux-uclibc/bin/i386-uclibc-gcc
|
||||
|
||||
# To compile vs some other alternative libc, you may need to use/adjust
|
||||
# the following lines to meet your needs...
|
||||
#
|
||||
# If you are using Red Hat 6.x with the compatible RPMs (for developing under
|
||||
# Red Hat 5.x and glibc 2.0) uncomment the following. Be sure to read about
|
||||
# using the compatible RPMs (compat-*) at http://www.redhat.com !
|
||||
#LIBCDIR:=/usr/i386-glibc20-linux
|
||||
#
|
||||
# The following is used for libc5 (if you install altgcc and libc5-altdev
|
||||
# on a Debian system).
|
||||
#LIBCDIR:=/usr/i486-linuxlibc1
|
||||
#
|
||||
# For other libraries, you are on your own...
|
||||
#LDFLAGS+=-nostdlib
|
||||
#LIBRARIES:=$(LIBCDIR)/lib/libc.a -lgcc
|
||||
#CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR)
|
||||
#GCCINCDIR:=$(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
|
||||
|
||||
WARNINGS:=-Wall -Wstrict-prototypes -Wshadow
|
||||
CFLAGS:=-I$(TOPDIR)include
|
||||
ARFLAGS:=-r
|
||||
|
||||
TARGET_ARCH:=${shell $(CC) -dumpmachine | sed -e s'/-.*//' \
|
||||
-e 's/i.86/i386/' \
|
||||
-e 's/sparc.*/sparc/' \
|
||||
-e 's/arm.*/arm/g' \
|
||||
-e 's/m68k.*/m68k/' \
|
||||
-e 's/ppc/powerpc/g' \
|
||||
-e 's/v850.*/v850/g' \
|
||||
-e 's/sh[234]/sh/' \
|
||||
-e 's/mips.*/mips/' \
|
||||
}
|
||||
|
||||
#--------------------------------------------------------
|
||||
# Arch specific compiler optimization stuff should go here.
|
||||
# Unless you want to override the defaults, do not set anything
|
||||
# for OPTIMIZATION...
|
||||
|
||||
# use '-Os' optimization if available, else use -O2
|
||||
OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null \
|
||||
>/dev/null 2>&1; then echo "-Os"; else echo "-O2" ; fi}
|
||||
|
||||
# Some nice architecture specific optimizations
|
||||
ifeq ($(strip $(TARGET_ARCH)),arm)
|
||||
OPTIMIZATION+=-fstrict-aliasing
|
||||
endif
|
||||
ifeq ($(strip $(TARGET_ARCH)),i386)
|
||||
OPTIMIZATION+=-march=i386
|
||||
OPTIMIZATION+=${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc \
|
||||
/dev/null >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; fi}
|
||||
OPTIMIZATION+=${shell if $(CC) -falign-functions=1 -falign-jumps=0 -falign-loops=0 \
|
||||
-S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo \
|
||||
"-falign-functions=1 -falign-jumps=0 -falign-loops=0"; else \
|
||||
if $(CC) -malign-functions=0 -malign-jumps=0 -S -o /dev/null -xc \
|
||||
/dev/null >/dev/null 2>&1; then echo "-malign-functions=0 -malign-jumps=0"; fi; fi}
|
||||
endif
|
||||
OPTIMIZATIONS:=$(OPTIMIZATION) -fomit-frame-pointer
|
||||
|
||||
#
|
||||
#--------------------------------------------------------
|
||||
# If you're going to do a lot of builds with a non-vanilla configuration,
|
||||
# it makes sense to adjust parameters above, so you can type "make"
|
||||
# by itself, instead of following it by the same half-dozen overrides
|
||||
# every time. The stuff below, on the other hand, is probably less
|
||||
# prone to casual user adjustment.
|
||||
#
|
||||
|
||||
ifeq ($(strip $(DOLFS)),true)
|
||||
# For large file summit support
|
||||
CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
|
||||
endif
|
||||
ifeq ($(strip $(DODMALLOC)),true)
|
||||
# For testing mem leaks with dmalloc
|
||||
CFLAGS+=-DDMALLOC
|
||||
LIBRARIES:=-ldmalloc
|
||||
# Force debug=true, since this is useless when not debugging...
|
||||
DODEBUG:=true
|
||||
else
|
||||
ifeq ($(strip $(DOEFENCE)),true)
|
||||
LIBRARIES:=-lefence
|
||||
# Force debug=true, since this is useless when not debugging...
|
||||
DODEBUG:=true
|
||||
endif
|
||||
endif
|
||||
ifeq ($(strip $(DODEBUG)),true)
|
||||
CFLAGS +=$(WARNINGS) -g -D_GNU_SOURCE
|
||||
LDFLAGS +=-Wl,-warn-common
|
||||
STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging
|
||||
else
|
||||
CFLAGS += $(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE
|
||||
LDFLAGS += -s -Wl,-warn-common
|
||||
STRIPCMD:=$(STRIP) --remove-section=.note --remove-section=.comment
|
||||
endif
|
||||
ifeq ($(strip $(DOSTATIC)),true)
|
||||
LDFLAGS += --static
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(PREFIX)),)
|
||||
PREFIX:=`pwd`/_install
|
||||
endif
|
||||
|
||||
# Additional complications due to support for pristine source dir.
|
||||
# Include files in the build directory should take precedence over
|
||||
# the copy in BB_SRC_DIR, both during the compilation phase and the
|
||||
# shell script that finds the list of object files.
|
||||
# Work in progress by <ldoolitt@recycle.lbl.gov>.
|
||||
#
|
||||
ifneq ($(strip $(BB_SRC_DIR)),)
|
||||
VPATH:=$(BB_SRC_DIR)
|
||||
endif
|
||||
|
||||
CFLAGS += -DBB_VER='"$(VERSION)"'
|
||||
CFLAGS += -DBB_BT='"$(BUILDTIME)"'
|
||||
OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
|
||||
CFLAGS += $(CROSS_CFLAGS)
|
||||
ifdef BB_INIT_SCRIPT
|
||||
CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
|
||||
endif
|
||||
|
||||
# Put user-supplied flags at the end, where they
|
||||
# have a chance of winning.
|
||||
CFLAGS += $(CFLAGS_EXTRA)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<
|
||||
@ ( \
|
||||
echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@))))' ; \
|
||||
echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
|
||||
echo 'endif' \
|
||||
) > $(dir $@)/.$(notdir $@).flags
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
%.o: %.s
|
||||
$(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<
|
||||
|
||||
# Old makefiles define their own rules for compiling .S files,
|
||||
# but these standard rules are available for any Makefile that
|
||||
# wants to use them. Our plan is to incrementally convert all
|
||||
# the Makefiles to these standard rules. -- rmk, mec
|
||||
ifdef USE_STANDARD_AS_RULE
|
||||
|
||||
%.s: %.S
|
||||
$(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@
|
||||
|
||||
%.o: %.S
|
||||
$(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<
|
||||
|
||||
endif
|
||||
|
||||
%.lst: %.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $<
|
||||
$(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)
|
||||
#
|
||||
#
|
||||
#
|
||||
all_targets: $(O_TARGET) $(L_TARGET)
|
||||
|
||||
#
|
||||
# Rule to compile a set of .o files into one .o file
|
||||
#
|
||||
ifdef O_TARGET
|
||||
$(O_TARGET): $(obj-y)
|
||||
rm -f $@
|
||||
ifneq "$(strip $(obj-y))" ""
|
||||
$(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^)
|
||||
else
|
||||
$(AR) rcs $@
|
||||
endif
|
||||
@ ( \
|
||||
echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y))))' ; \
|
||||
echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
|
||||
echo 'endif' \
|
||||
) > $(dir $@)/.$(notdir $@).flags
|
||||
endif # O_TARGET
|
||||
|
||||
#
|
||||
# Rule to compile a set of .o files into one .a file
|
||||
#
|
||||
ifdef L_TARGET
|
||||
$(L_TARGET): $(obj-y)
|
||||
rm -f $@
|
||||
$(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
|
||||
@ ( \
|
||||
echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ; \
|
||||
echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
|
||||
echo 'endif' \
|
||||
) > $(dir $@)/.$(notdir $@).flags
|
||||
endif
|
||||
|
||||
|
||||
#
|
||||
# This make dependencies quickly
|
||||
#
|
||||
ifdef _FASTDEP_ALL_SUB_DIRS
|
||||
fastdep: dummy
|
||||
$(TOPDIR)/scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS) -- $(wildcard *.[chS]) > .depend
|
||||
$(TOPDIR)scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -- $(wildcard *.[chS]) > .depend
|
||||
ifdef ALL_SUB_DIRS
|
||||
$(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
|
||||
endif
|
||||
|
||||
ifdef _FASTDEP_ALL_SUB_DIRS
|
||||
$(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
|
||||
$(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
|
||||
endif
|
||||
|
||||
|
||||
#
|
||||
# A rule to make subdirectories
|
||||
#
|
||||
subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
|
||||
sub_dirs: dummy $(subdir-list)
|
||||
.PHONY: dummy
|
||||
|
||||
ifdef SUB_DIRS
|
||||
$(subdir-list) : dummy
|
||||
$(MAKE) -C $(patsubst _subdir_%,%,$@)
|
||||
endif
|
||||
|
||||
#
|
||||
# A rule to do nothing
|
||||
#
|
||||
dummy:
|
||||
|
||||
#
|
||||
# This is useful for testing
|
||||
#
|
||||
script:
|
||||
$(SCRIPT)
|
||||
.EXPORT_ALL_VARIABLES:
|
||||
|
||||
#
|
||||
# include dependency files if they exist
|
||||
#
|
||||
ifneq ($(wildcard .depend),)
|
||||
include .depend
|
||||
endif
|
||||
|
||||
ifneq ($(wildcard $(TOPDIR)/.hdepend),)
|
||||
include $(TOPDIR)/.hdepend
|
||||
endif
|
||||
|
||||
#
|
||||
# Find files whose flags have changed and force recompilation.
|
||||
# For safety, this works in the converse direction:
|
||||
# every file is forced, except those whose flags are positively up-to-date.
|
||||
#
|
||||
FILES_FLAGS_UP_TO_DATE :=
|
||||
|
||||
# For use in expunging commas from flags, which mung our checking.
|
||||
comma = ,
|
||||
|
||||
FILES_FLAGS_EXIST := $(wildcard .*.flags)
|
||||
ifneq ($(FILES_FLAGS_EXIST),)
|
||||
include $(FILES_FLAGS_EXIST)
|
||||
endif
|
||||
|
||||
FILES_FLAGS_CHANGED := $(strip \
|
||||
$(filter-out $(FILES_FLAGS_UP_TO_DATE), \
|
||||
$(O_TARGET) $(L_TARGET) $(active-objs) \
|
||||
))
|
||||
|
||||
# A kludge: .S files don't get flag dependencies (yet),
|
||||
# because that will involve changing a lot of Makefiles. Also
|
||||
# suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
|
||||
# This allows handling of assembly files that get translated into
|
||||
# multiple object files (see arch/ia64/lib/idiv.S, for example).
|
||||
FILES_FLAGS_CHANGED := $(strip \
|
||||
$(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
|
||||
$(FILES_FLAGS_CHANGED)))
|
||||
|
||||
ifneq ($(FILES_FLAGS_CHANGED),)
|
||||
$(FILES_FLAGS_CHANGED): dummy
|
||||
endif
|
||||
@@ -3,24 +3,17 @@ is listed here doesn't mean that it is going to be added to busybox,
|
||||
or that doing so is even a good idea. It just means that I _might_ get
|
||||
around to it some time. If you have any good ideas, please let me know.
|
||||
|
||||
* login/sulogin/passwd/getty/etc are part of tinylogin, and so are not
|
||||
needed or wanted in busybox (or else I'd have to link to libcrypt).
|
||||
|
||||
* We _were_ going to split networking apps into a new package called
|
||||
netkit-tiny. Per discussions on the mailing list, this isn't going
|
||||
to happen. False alarm. Sorry about the confusion.
|
||||
|
||||
|
||||
-Erik
|
||||
|
||||
-----------
|
||||
|
||||
Possible apps to include some time:
|
||||
|
||||
* hwclock
|
||||
* group/commonize strings, remove dups (for i18n, l10n)
|
||||
* login/sulogin/passwd/etc are part of tinylogin. These are
|
||||
being merged into busybox as time allows.
|
||||
|
||||
-----------
|
||||
|
||||
@@ -47,12 +40,13 @@ libraries such as uClibc.
|
||||
Compile with debugging on, run 'nm --size-sort ./busybox'
|
||||
and then start with the biggest things and make them smaller...
|
||||
|
||||
-----------------------
|
||||
|
||||
du.c probably ought to have an -x switch like GNU du does...
|
||||
|
||||
-----------------------
|
||||
|
||||
xargs could use a -l option
|
||||
|
||||
------------------------------------------------------------------
|
||||
|
||||
libbb/unzip.c and archival/gzip.c have common constant static arrays and
|
||||
code for initializing the CRC array. Both use CRC-32 and could use
|
||||
common code for CRC calculation. Within archival/gzip.c, the CRC
|
||||
array should be malloc-ed as it is in libbb/unzip.c .
|
||||
+9
-13
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
|
||||
# Copyright (C) 1999-2002 Erik Andersen <andersee@debian.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,18 +17,14 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
TOPDIR :=..
|
||||
L_TARGET := applets.a
|
||||
|
||||
obj-y :=
|
||||
obj-n :=
|
||||
obj- :=
|
||||
|
||||
obj-y += applets.o busybox.o usage.o
|
||||
|
||||
# Hand off to toplevel Rules.mak
|
||||
include $(TOPDIR)/Rules.mak
|
||||
TOPDIR:= ../
|
||||
APPLETS_DIR:=./
|
||||
include $(TOPDIR).config
|
||||
include $(TOPDIR)Rules.mak
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(TOPDIR).depend
|
||||
|
||||
clean:
|
||||
rm -f $(L_TARGET) *.o core
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2002 by Erik Andersen <andersee@debian.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
APPLETS_AR:=applets.a
|
||||
ifndef $(APPLETS_DIR)
|
||||
APPLETS_DIR:=$(TOPDIR)applets/
|
||||
endif
|
||||
|
||||
APPLET_SRC:=applets.c busybox.c usage.c
|
||||
APPLET_OBJ:= $(patsubst %.c,$(APPLETS_DIR)%.o, $(APPLET_SRC))
|
||||
|
||||
|
||||
|
||||
libraries-y+=$(APPLETS_DIR)$(APPLETS_AR)
|
||||
|
||||
$(APPLET_OBJ): $(TOPDIR).config
|
||||
|
||||
$(APPLETS_DIR)$(APPLETS_AR): $(APPLET_OBJ)
|
||||
$(AR) -ro $@ $(APPLET_OBJ)
|
||||
|
||||
+307
-1
@@ -25,6 +25,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -40,6 +41,43 @@ struct BB_applet *applet_using;
|
||||
/* The -1 arises because of the {0,NULL,0,-1} entry above. */
|
||||
const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
|
||||
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID
|
||||
|
||||
static void check_suid ( struct BB_applet *app );
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <ctype.h>
|
||||
#include "pwd_.h"
|
||||
#include "grp_.h"
|
||||
|
||||
static int parse_config_file ( void );
|
||||
|
||||
static int config_ok;
|
||||
|
||||
#define CONFIG_FILE "/etc/busybox.conf"
|
||||
|
||||
/* applets [] is const, so we have to define this "override" structure */
|
||||
struct BB_suid_config {
|
||||
struct BB_applet *m_applet;
|
||||
|
||||
uid_t m_uid;
|
||||
gid_t m_gid;
|
||||
mode_t m_mode;
|
||||
|
||||
struct BB_suid_config *m_next;
|
||||
};
|
||||
|
||||
static struct BB_suid_config *suid_config;
|
||||
|
||||
#endif /* CONFIG_FEATURE_SUID_CONFIG */
|
||||
|
||||
#endif /* CONFIG_FEATURE_SUID */
|
||||
|
||||
|
||||
|
||||
extern void show_usage(void)
|
||||
{
|
||||
const char *format_string;
|
||||
@@ -52,7 +90,7 @@ extern void show_usage(void)
|
||||
}
|
||||
}
|
||||
format_string = "%s\n\nUsage: %s %s\n\n";
|
||||
if(*usage_string == 0)
|
||||
if(*usage_string == '\b')
|
||||
format_string = "%s\n\nNo help available.\n\n";
|
||||
fprintf(stderr, format_string,
|
||||
full_version, applet_using->name, usage_string);
|
||||
@@ -80,6 +118,11 @@ void run_applet_by_name(const char *name, int argc, char **argv)
|
||||
static int recurse_level = 0;
|
||||
extern int been_there_done_that; /* From busybox.c */
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
if ( recurse_level == 0 )
|
||||
config_ok = parse_config_file ( );
|
||||
#endif
|
||||
|
||||
recurse_level++;
|
||||
/* Do a binary search to find the applet entry given the name. */
|
||||
if ((applet_using = find_applet_by_name(name)) != NULL) {
|
||||
@@ -96,6 +139,10 @@ void run_applet_by_name(const char *name, int argc, char **argv)
|
||||
been_there_done_that=1;
|
||||
busybox_main(0, NULL);
|
||||
}
|
||||
#ifdef CONFIG_FEATURE_SUID
|
||||
check_suid ( applet_using );
|
||||
#endif
|
||||
|
||||
exit((*(applet_using->main)) (argc, argv));
|
||||
}
|
||||
/* Just in case they have renamed busybox - Check argv[1] */
|
||||
@@ -106,6 +153,265 @@ void run_applet_by_name(const char *name, int argc, char **argv)
|
||||
}
|
||||
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
|
||||
/* check if u is member of group g */
|
||||
static int ingroup ( uid_t u, gid_t g )
|
||||
{
|
||||
struct group *grp = getgrgid ( g );
|
||||
|
||||
if ( grp ) {
|
||||
char **mem;
|
||||
|
||||
for ( mem = grp-> gr_mem; *mem; mem++ ) {
|
||||
struct passwd *pwd = getpwnam ( *mem );
|
||||
|
||||
if ( pwd && ( pwd-> pw_uid == u ))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void check_suid ( struct BB_applet *applet )
|
||||
{
|
||||
uid_t ruid = getuid ( ); /* real [ug]id */
|
||||
uid_t rgid = getgid ( );
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
if ( config_ok ) {
|
||||
struct BB_suid_config *sct;
|
||||
|
||||
for ( sct = suid_config; sct; sct = sct-> m_next ) {
|
||||
if ( sct-> m_applet == applet )
|
||||
break;
|
||||
}
|
||||
if ( sct ) {
|
||||
mode_t m = sct-> m_mode;
|
||||
|
||||
if ( sct-> m_uid == ruid ) /* same uid */
|
||||
m >>= 6;
|
||||
else if (( sct-> m_gid == rgid ) || ingroup ( ruid, sct-> m_gid )) /* same group / in group */
|
||||
m >>= 3;
|
||||
|
||||
if (!( m & S_IXOTH )) /* is x bit not set ? */
|
||||
error_msg_and_die ( "You have no permission to run this applet!" );
|
||||
|
||||
if (( sct-> m_mode & ( S_ISGID | S_IXGRP )) == ( S_ISGID | S_IXGRP )) { /* *both* have to be set for sgid */
|
||||
if ( setegid ( sct-> m_gid ))
|
||||
error_msg_and_die ( "BusyBox binary has insufficient rights to set proper GID for applet!" );
|
||||
}
|
||||
else
|
||||
setgid ( rgid ); /* no sgid -> drop */
|
||||
|
||||
if ( sct-> m_mode & S_ISUID ) {
|
||||
if ( seteuid ( sct-> m_uid ))
|
||||
error_msg_and_die ( "BusyBox binary has insufficient rights to set proper UID for applet!" );
|
||||
}
|
||||
else
|
||||
setuid ( ruid ); /* no suid -> drop */
|
||||
}
|
||||
else { /* default: drop all priviledges */
|
||||
setgid ( rgid );
|
||||
setuid ( ruid );
|
||||
}
|
||||
return;
|
||||
}
|
||||
else {
|
||||
#ifndef CONFIG_FEATURE_SUID_CONFIG_QUIET
|
||||
static int onetime = 0;
|
||||
|
||||
if ( !onetime ) {
|
||||
onetime = 1;
|
||||
fprintf ( stderr, "Using fallback suid method\n" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( applet-> need_suid == _BB_SUID_ALWAYS ) {
|
||||
if ( geteuid ( ) != 0 )
|
||||
error_msg_and_die ( "This applet requires root priviledges!" );
|
||||
}
|
||||
else if ( applet-> need_suid == _BB_SUID_NEVER ) {
|
||||
setgid ( rgid ); /* drop all priviledges */
|
||||
setuid ( ruid );
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
|
||||
|
||||
#define parse_error(x) { err=x; goto pe_label; }
|
||||
|
||||
|
||||
int parse_config_file ( void )
|
||||
{
|
||||
struct stat st;
|
||||
char *err = 0;
|
||||
FILE *f = 0;
|
||||
int lc = 0;
|
||||
|
||||
suid_config = 0;
|
||||
|
||||
/* is there a config file ? */
|
||||
if ( stat ( CONFIG_FILE, &st ) == 0 ) {
|
||||
/* is it owned by root with no write perm. for group and others ? */
|
||||
if ( S_ISREG( st. st_mode ) && ( st. st_uid == 0 ) && (!( st. st_mode & ( S_IWGRP | S_IWOTH )))) {
|
||||
/* that's ok .. then try to open it */
|
||||
f = fopen ( CONFIG_FILE, "r" );
|
||||
|
||||
if ( f ) {
|
||||
char buffer [256];
|
||||
int section = 0;
|
||||
|
||||
while ( fgets ( buffer, sizeof( buffer ) - 1, f )) {
|
||||
char c = buffer [0];
|
||||
char *p;
|
||||
|
||||
lc++;
|
||||
|
||||
p = strchr ( buffer, '#' );
|
||||
if ( p )
|
||||
*p = 0;
|
||||
p = buffer + xstrlen ( buffer );
|
||||
while (( p > buffer ) && isspace ( *--p ))
|
||||
*p = 0;
|
||||
|
||||
if ( p == buffer )
|
||||
continue;
|
||||
|
||||
if ( c == '[' ) {
|
||||
p = strchr ( buffer, ']' );
|
||||
|
||||
if ( !p || ( p == ( buffer + 1 ))) /* no matching ] or empty [] */
|
||||
parse_error ( "malformed section header" );
|
||||
|
||||
*p = 0;
|
||||
|
||||
if ( strcasecmp ( buffer + 1, "SUID" ) == 0 )
|
||||
section = 1;
|
||||
else
|
||||
section = -1; /* unknown section - just skip */
|
||||
}
|
||||
else if ( section ) {
|
||||
switch ( section ) {
|
||||
case 1: { /* SUID */
|
||||
int l;
|
||||
struct BB_applet *applet;
|
||||
|
||||
p = strchr ( buffer, '=' ); /* <key>[::space::]*=[::space::]*<value> */
|
||||
|
||||
if ( !p || ( p == ( buffer + 1 ))) /* no = or key is empty */
|
||||
parse_error ( "malformed keyword" );
|
||||
|
||||
l = p - buffer;
|
||||
while ( isspace ( buffer [--l] )) { } /* skip whitespace */
|
||||
|
||||
buffer [l+1] = 0;
|
||||
|
||||
if (( applet = find_applet_by_name ( buffer ))) {
|
||||
struct BB_suid_config *sct = xmalloc ( sizeof( struct BB_suid_config ));
|
||||
|
||||
sct-> m_applet = applet;
|
||||
sct-> m_next = suid_config;
|
||||
suid_config = sct;
|
||||
|
||||
while ( isspace ( *++p )) { } /* skip whitespace */
|
||||
|
||||
sct-> m_mode = 0;
|
||||
|
||||
switch ( *p++ ) {
|
||||
case 'S': sct-> m_mode |= S_ISUID; break;
|
||||
case 's': sct-> m_mode |= S_ISUID; /* no break */
|
||||
case 'x': sct-> m_mode |= S_IXUSR; break;
|
||||
case '-': break;
|
||||
default : parse_error ( "invalid user mode" );
|
||||
}
|
||||
|
||||
switch ( *p++ ) {
|
||||
case 's': sct-> m_mode |= S_ISGID; /* no break */
|
||||
case 'x': sct-> m_mode |= S_IXGRP; break;
|
||||
case 'S': break;
|
||||
case '-': break;
|
||||
default : parse_error ( "invalid group mode" );
|
||||
}
|
||||
|
||||
switch ( *p ) {
|
||||
case 't':
|
||||
case 'x': sct-> m_mode |= S_IXOTH; break;
|
||||
case 'T':
|
||||
case '-': break;
|
||||
default : parse_error ( "invalid other mode" );
|
||||
}
|
||||
|
||||
while ( isspace ( *++p )) { } /* skip whitespace */
|
||||
|
||||
if ( isdigit ( *p )) {
|
||||
sct-> m_uid = strtol ( p, &p, 10 );
|
||||
if ( *p++ != '.' )
|
||||
parse_error ( "parsing <uid>.<gid>" );
|
||||
}
|
||||
else {
|
||||
struct passwd *pwd;
|
||||
char *p2 = strchr ( p, '.' );
|
||||
|
||||
if ( !p2 )
|
||||
parse_error ( "parsing <uid>.<gid>" );
|
||||
|
||||
*p2 = 0;
|
||||
pwd = getpwnam ( p );
|
||||
|
||||
if ( !pwd )
|
||||
parse_error ( "invalid user name" );
|
||||
|
||||
sct-> m_uid = pwd-> pw_uid;
|
||||
p = p2 + 1;
|
||||
}
|
||||
if ( isdigit ( *p ))
|
||||
sct-> m_gid = strtol ( p, &p, 10 );
|
||||
else {
|
||||
struct group *grp = getgrnam ( p );
|
||||
|
||||
if ( !grp )
|
||||
parse_error ( "invalid group name" );
|
||||
|
||||
sct-> m_gid = grp-> gr_gid;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: /* unknown - skip */
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
parse_error ( "keyword not within section" );
|
||||
}
|
||||
fclose ( f );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0; /* no config file or not readable (not an error) */
|
||||
|
||||
pe_label:
|
||||
fprintf ( stderr, "Parse error in %s, line %d: %s\n", CONFIG_FILE, lc, err );
|
||||
|
||||
if ( f )
|
||||
fclose ( f );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* END CODE */
|
||||
/*
|
||||
Local Variables:
|
||||
|
||||
+10
-7
@@ -18,12 +18,15 @@ const char *applet_name;
|
||||
* this should be consistent w/ the enum, busybox.h::Location,
|
||||
* or else...
|
||||
*/
|
||||
static char* install_dir[] = {
|
||||
"/",
|
||||
"/bin",
|
||||
"/sbin",
|
||||
"/usr/bin",
|
||||
"/usr/sbin",
|
||||
static const char usr_bin [] ="/usr/bin";
|
||||
static const char usr_sbin[] ="/usr/sbin";
|
||||
|
||||
static const char* const install_dir[] = {
|
||||
&usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
|
||||
&usr_bin [4], /* "/bin" */
|
||||
&usr_sbin[4], /* "/sbin" */
|
||||
usr_bin,
|
||||
usr_sbin
|
||||
};
|
||||
|
||||
/* abstract link() */
|
||||
@@ -35,7 +38,7 @@ typedef int (*__link_f)(const char *, const char *);
|
||||
* malloc'd string w/ full pathname of busybox's location
|
||||
* NULL on failure
|
||||
*/
|
||||
static char *busybox_fullpath()
|
||||
static inline char *busybox_fullpath(void)
|
||||
{
|
||||
return xreadlink("/proc/self/exe");
|
||||
}
|
||||
|
||||
+9
-23
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
|
||||
# Copyright (C) 1999-2002 Erik Andersen <andersee@debian.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,28 +17,14 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
TOPDIR :=..
|
||||
L_TARGET := archival.a
|
||||
|
||||
obj-y :=
|
||||
obj-n :=
|
||||
obj- :=
|
||||
subdir-y := libunarchive
|
||||
|
||||
obj-$(CONFIG_AR) += ar.o
|
||||
obj-$(CONFIG_BUNZIP2) += bunzip2.o
|
||||
obj-$(CONFIG_CPIO) += cpio.o
|
||||
obj-$(CONFIG_DPKG) += dpkg.o
|
||||
obj-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
obj-$(CONFIG_GUNZIP) += gunzip.o
|
||||
obj-$(CONFIG_GZIP) += gzip.o
|
||||
obj-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
obj-$(CONFIG_TAR) += tar.o
|
||||
|
||||
|
||||
# Hand off to toplevel Rules.mak
|
||||
include $(TOPDIR)/Rules.mak
|
||||
TOPDIR:= ../
|
||||
ARCHIVAL_DIR:=./
|
||||
include $(TOPDIR).config
|
||||
include $(TOPDIR)Rules.mak
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(TOPDIR).depend
|
||||
|
||||
clean:
|
||||
rm -f $(L_TARGET) *.o core
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2002 by Erik Andersen <andersee@debian.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
ARCHIVAL_AR:=archival.a
|
||||
ifndef $(ARCHIVAL_DIR)
|
||||
ARCHIVAL_DIR:=$(TOPDIR)archival/
|
||||
endif
|
||||
|
||||
ARCHIVAL-y:=
|
||||
ARCHIVAL-$(CONFIG_AR) += ar.o
|
||||
ARCHIVAL-$(CONFIG_BUNZIP2) += bunzip2.o
|
||||
ARCHIVAL-$(CONFIG_CPIO) += cpio.o
|
||||
ARCHIVAL-$(CONFIG_DPKG) += dpkg.o
|
||||
ARCHIVAL-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
ARCHIVAL-$(CONFIG_GUNZIP) += gunzip.o
|
||||
ARCHIVAL-$(CONFIG_GZIP) += gzip.o
|
||||
ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
ARCHIVAL-$(CONFIG_TAR) += tar.o
|
||||
ARCHIVAL-$(CONFIG_UNZIP) += unzip.o
|
||||
|
||||
libraries-y+=$(ARCHIVAL_DIR)$(ARCHIVAL_AR)
|
||||
|
||||
$(ARCHIVAL_DIR)$(ARCHIVAL_AR): $(patsubst %,$(ARCHIVAL_DIR)%, $(ARCHIVAL-y))
|
||||
$(AR) -ro $@ $(patsubst %,$(ARCHIVAL_DIR)%, $(ARCHIVAL-y))
|
||||
|
||||
+93
-31
@@ -21,41 +21,101 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* There is no signle standard to adhere to so ar may not portable
|
||||
* between different systems
|
||||
* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <fnmatch.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
static void header_verbose_list_ar(const file_header_t *file_header)
|
||||
{
|
||||
const char *mode = mode_string(file_header->mode);
|
||||
char *mtime;
|
||||
|
||||
mtime = ctime(&file_header->mtime);
|
||||
mtime[16] = ' ';
|
||||
memmove(&mtime[17], &mtime[20], 4);
|
||||
mtime[21] = '\0';
|
||||
printf("%s %d/%d%7d %s %s\n", &mode[1], file_header->uid, file_header->gid, (int) file_header->size, &mtime[4], file_header->name);
|
||||
}
|
||||
|
||||
#if defined CONFIG_TAR | defined CONFIG_DPKG_DEB | defined CONFIG_CPIO
|
||||
/* This is simpler than data_extract_all */
|
||||
static void data_extract_regular_file(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header;
|
||||
int dst_fd;
|
||||
|
||||
file_header = archive_handle->file_header;
|
||||
dst_fd = xopen(file_header->name, O_WRONLY | O_CREAT);
|
||||
copy_file_chunk_fd(archive_handle->src_fd, dst_fd, file_header->size);
|
||||
close(dst_fd);
|
||||
|
||||
chmod(file_header->name, file_header->mode);
|
||||
chown(file_header->name, file_header->uid, file_header->gid);
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
|
||||
struct utimbuf t;
|
||||
t.actime = t.modtime = file_header->mtime;
|
||||
utime(file_header->name, &t);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
extern int ar_main(int argc, char **argv)
|
||||
{
|
||||
FILE *src_stream = NULL;
|
||||
char **extract_names = NULL;
|
||||
char ar_magic[8];
|
||||
int extract_function = extract_unconditional;
|
||||
archive_handle_t *archive_handle;
|
||||
int opt;
|
||||
int num_of_entries = 0;
|
||||
extern off_t archive_offset;
|
||||
|
||||
while ((opt = getopt(argc, argv, "ovtpx")) != -1) {
|
||||
#ifndef CONFIG_DPKG_DEB
|
||||
char magic[8];
|
||||
#endif
|
||||
#if defined CONFIG_TAR | defined CONFIG_DPKG_DEB | defined CONFIG_CPIO
|
||||
archive_handle = init_handle();
|
||||
#else
|
||||
archive_handle = xcalloc(1, sizeof(archive_handle_t));
|
||||
archive_handle->filter = filter_accept_all;
|
||||
archive_handle->action_data = data_skip;
|
||||
archive_handle->action_header = header_skip;
|
||||
archive_handle->file_header =xmalloc(sizeof(file_header_t));
|
||||
#endif
|
||||
|
||||
while ((opt = getopt(argc, argv, "covtpxX")) != -1) {
|
||||
switch (opt) {
|
||||
case 'o':
|
||||
extract_function |= extract_preserve_date;
|
||||
case 'p': /* print */
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
break;
|
||||
case 'v':
|
||||
extract_function |= extract_verbose_list;
|
||||
case 't': /* list contents */
|
||||
archive_handle->action_header = header_list;
|
||||
break;
|
||||
case 't':
|
||||
extract_function |= extract_list;
|
||||
case 'X':
|
||||
archive_handle->action_header = header_verbose_list_ar;
|
||||
case 'x': /* extract */
|
||||
#if defined CONFIG_TAR | defined CONFIG_DPKG_DEB | defined CONFIG_CPIO
|
||||
archive_handle->action_data = data_extract_all;
|
||||
#else
|
||||
archive_handle->action_data = data_extract_regular_file;
|
||||
#endif
|
||||
break;
|
||||
case 'p':
|
||||
extract_function |= extract_to_stdout;
|
||||
/* Modifiers */
|
||||
case 'o': /* preserve original dates */
|
||||
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
|
||||
break;
|
||||
case 'x':
|
||||
extract_function |= extract_all_to_fs;
|
||||
case 'v': /* verbose */
|
||||
archive_handle->action_header = header_verbose_list_ar;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
@@ -67,24 +127,26 @@ extern int ar_main(int argc, char **argv)
|
||||
show_usage();
|
||||
}
|
||||
|
||||
src_stream = xfopen(argv[optind++], "r");
|
||||
archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
|
||||
|
||||
/* check ar magic */
|
||||
fread(ar_magic, 1, 8, src_stream);
|
||||
archive_offset = 8;
|
||||
if (strncmp(ar_magic,"!<arch>",7) != 0) {
|
||||
error_msg_and_die("invalid magic");
|
||||
}
|
||||
|
||||
/* Create a list of files to extract */
|
||||
/* TODO: This is the same as in tar, seperate function ? */
|
||||
while (optind < argc) {
|
||||
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
|
||||
extract_names[num_of_entries] = xstrdup(argv[optind]);
|
||||
num_of_entries++;
|
||||
extract_names[num_of_entries] = NULL;
|
||||
archive_handle->filter = filter_accept_list;
|
||||
archive_handle->accept = add_to_list(archive_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
|
||||
unarchive(src_stream, stdout, &get_header_ar, extract_function, "./", extract_names, NULL);
|
||||
#if defined CONFIG_DPKG_DEB
|
||||
unpack_ar_archive(archive_handle);
|
||||
#else
|
||||
xread_all(archive_handle->src_fd, magic, 7);
|
||||
if (strncmp(magic, "!<arch>", 7) != 0) {
|
||||
error_msg_and_die("Invalid ar magic");
|
||||
}
|
||||
archive_handle->offset += 7;
|
||||
|
||||
while (get_header_ar(archive_handle) == EXIT_SUCCESS);
|
||||
#endif
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+150
-655
File diff suppressed because it is too large.
Load diff
+13
-1
@@ -7,10 +7,16 @@ mainmenu_option next_comment
|
||||
comment 'Archival Utilities'
|
||||
|
||||
bool 'ar' CONFIG_AR
|
||||
if [ "$CONFIG_AR" = "y" ] ; then
|
||||
bool ' Enable support for long filenames (not need for debs)' CONFIG_FEATURE_AR_LONG_FILENAMES
|
||||
fi
|
||||
bool 'bunzip2' CONFIG_BUNZIP2
|
||||
bool 'cpio' CONFIG_CPIO
|
||||
bool 'dpkg' CONFIG_DPKG
|
||||
bool 'dpkg_deb' CONFIG_DPKG_DEB
|
||||
if [ "$CONFIG_DPKG_DEB" = "y" ] ; then
|
||||
bool ' -x support only' CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
fi
|
||||
bool 'gunzip' CONFIG_GUNZIP
|
||||
bool 'gzip' CONFIG_GZIP
|
||||
bool 'rpm2cpio' CONFIG_RPM2CPIO
|
||||
@@ -18,6 +24,12 @@ bool 'tar' CONFIG_TAR
|
||||
if [ "$CONFIG_TAR" = "y" ] ; then
|
||||
bool ' Enable archive creation' CONFIG_FEATURE_TAR_CREATE
|
||||
bool ' Enable -X and --exclude options (exclude files)' CONFIG_FEATURE_TAR_EXCLUDE
|
||||
bool ' Enable -z option (currently only for extracting)' CONFIG_FEATURE_TAR_GZIP
|
||||
bool ' Enable -z option' CONFIG_FEATURE_TAR_GZIP
|
||||
bool ' Enable support for old tar header format' CONFIG_FEATURE_TAR_OLD_FORMAT
|
||||
bool ' Enable support for GNU long filenames' CONFIG_FEATURE_GNUTAR_LONG_FILENAME
|
||||
fi
|
||||
if [ "$CONFIG_CPIO" = "y" -o "$CONFIG_TAR" = "y" ] ; then
|
||||
bool ' Enable tape drive support' CONFIG_FEATURE_UNARCHIVE_TAPE
|
||||
fi
|
||||
bool 'unzip' CONFIG_UNZIP
|
||||
endmenu
|
||||
+182
-38
@@ -31,66 +31,210 @@
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
typedef struct hardlinks_s {
|
||||
file_header_t *entry;
|
||||
int inode;
|
||||
struct hardlinks_s *next;
|
||||
} hardlinks_t;
|
||||
|
||||
extern int cpio_main(int argc, char **argv)
|
||||
{
|
||||
FILE *src_stream = stdin;
|
||||
char **extract_names = NULL;
|
||||
int extract_function = 0;
|
||||
int num_of_entries = 0;
|
||||
int opt = 0;
|
||||
mode_t oldmask = 0;
|
||||
archive_handle_t *archive_handle;
|
||||
int opt;
|
||||
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->src_fd = fileno(stdin);
|
||||
archive_handle->action_header = header_list;
|
||||
|
||||
while ((opt = getopt(argc, argv, "idmuvtF:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': // extract
|
||||
extract_function |= extract_all_to_fs;
|
||||
case 'i': /* extract */
|
||||
archive_handle->action_data = data_extract_all;
|
||||
break;
|
||||
case 'd': // create _leading_ directories
|
||||
extract_function |= extract_create_leading_dirs;
|
||||
oldmask = umask(077); /* Make make_directory act like GNU cpio */
|
||||
case 'd': /* create _leading_ directories */
|
||||
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
break;
|
||||
case 'm': // preserve modification time
|
||||
extract_function |= extract_preserve_date;
|
||||
case 'm': /* preserve modification time */
|
||||
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
|
||||
break;
|
||||
case 'v': // verbosly list files
|
||||
extract_function |= extract_verbose_list;
|
||||
case 'v': /* verbosly list files */
|
||||
archive_handle->action_header = header_verbose_list;
|
||||
break;
|
||||
case 'u': // unconditional
|
||||
extract_function |= extract_unconditional;
|
||||
case 'u': /* unconditional */
|
||||
archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
break;
|
||||
case 't': // list files
|
||||
extract_function |= extract_list;
|
||||
case 't': /* list files */
|
||||
archive_handle->action_header = header_list;
|
||||
break;
|
||||
case 'F':
|
||||
src_stream = xfopen(optarg, "r");
|
||||
archive_handle->src_fd = xopen(optarg, O_RDONLY);
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if ((extract_function & extract_all_to_fs) && (extract_function & extract_list)) {
|
||||
extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/
|
||||
}
|
||||
|
||||
if ((extract_function & extract_all_to_fs) && (extract_function & extract_verbose_list)) {
|
||||
/* The meaning of v changes on extract */
|
||||
extract_function ^= extract_verbose_list;
|
||||
extract_function |= extract_list;
|
||||
}
|
||||
|
||||
while (optind < argc) {
|
||||
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
|
||||
extract_names[num_of_entries] = xstrdup(argv[optind]);
|
||||
num_of_entries++;
|
||||
extract_names[num_of_entries] = NULL;
|
||||
archive_handle->filter = filter_accept_list;
|
||||
archive_handle->accept = add_to_list(archive_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
|
||||
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names, NULL);
|
||||
if (oldmask) {
|
||||
umask(oldmask); /* Restore umask if we changed it */
|
||||
while (1) {
|
||||
static hardlinks_t *saved_hardlinks = NULL;
|
||||
static unsigned short pending_hardlinks = 0;
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
char cpio_header[110];
|
||||
int namesize;
|
||||
char dummy[16];
|
||||
int major, minor, nlink, inode;
|
||||
char extract_flag;
|
||||
|
||||
if (pending_hardlinks) { /* Deal with any pending hardlinks */
|
||||
hardlinks_t *tmp;
|
||||
hardlinks_t *oldtmp;
|
||||
|
||||
tmp = saved_hardlinks;
|
||||
oldtmp = NULL;
|
||||
|
||||
while (tmp) {
|
||||
error_msg_and_die("need to fix this\n");
|
||||
if (tmp->entry->link_name) { /* Found a hardlink ready to be extracted */
|
||||
file_header = tmp->entry;
|
||||
if (oldtmp) {
|
||||
oldtmp->next = tmp->next; /* Remove item from linked list */
|
||||
} else {
|
||||
saved_hardlinks = tmp->next;
|
||||
}
|
||||
free(tmp);
|
||||
continue;
|
||||
}
|
||||
oldtmp = tmp;
|
||||
tmp = tmp->next;
|
||||
}
|
||||
pending_hardlinks = 0; /* No more pending hardlinks, read next file entry */
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
/* There can be padding before archive header */
|
||||
archive_handle->offset += data_align(archive_handle->src_fd, archive_handle->offset, 4);
|
||||
|
||||
if (xread_all_eof(archive_handle->src_fd, cpio_header, 110) == 0) {
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
archive_handle->offset += 110;
|
||||
|
||||
if (strncmp(&cpio_header[0], "07070", 5) != 0) {
|
||||
printf("cpio header is %x-%x-%x-%x-%x\n",
|
||||
cpio_header[0],
|
||||
cpio_header[1],
|
||||
cpio_header[2],
|
||||
cpio_header[3],
|
||||
cpio_header[4]);
|
||||
error_msg_and_die("Unsupported cpio format");
|
||||
}
|
||||
|
||||
if ((cpio_header[5] != '1') && (cpio_header[5] != '2')) {
|
||||
error_msg_and_die("Unsupported cpio format, use newc or crc");
|
||||
}
|
||||
|
||||
sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c",
|
||||
dummy, &inode, (unsigned int*)&file_header->mode,
|
||||
(unsigned int*)&file_header->uid, (unsigned int*)&file_header->gid,
|
||||
&nlink, &file_header->mtime, &file_header->size,
|
||||
dummy, &major, &minor, &namesize, dummy);
|
||||
|
||||
file_header->name = (char *) xmalloc(namesize + 1);
|
||||
xread(archive_handle->src_fd, file_header->name, namesize); /* Read in filename */
|
||||
file_header->name[namesize] = '\0';
|
||||
archive_handle->offset += namesize;
|
||||
|
||||
/* Update offset amount and skip padding before file contents */
|
||||
archive_handle->offset += data_align(archive_handle->src_fd, archive_handle->offset, 4);
|
||||
|
||||
if (strcmp(file_header->name, "TRAILER!!!") == 0) {
|
||||
printf("%d blocks\n", (int) (archive_handle->offset % 512 ? (archive_handle->offset / 512) + 1 : archive_handle->offset / 512)); /* Always round up */
|
||||
if (saved_hardlinks) { /* Bummer - we still have unresolved hardlinks */
|
||||
hardlinks_t *tmp = saved_hardlinks;
|
||||
hardlinks_t *oldtmp = NULL;
|
||||
while (tmp) {
|
||||
error_msg("%s not created: cannot resolve hardlink", tmp->entry->name);
|
||||
oldtmp = tmp;
|
||||
tmp = tmp->next;
|
||||
free (oldtmp->entry->name);
|
||||
free (oldtmp->entry);
|
||||
free (oldtmp);
|
||||
}
|
||||
saved_hardlinks = NULL;
|
||||
pending_hardlinks = 0;
|
||||
}
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (S_ISLNK(file_header->mode)) {
|
||||
file_header->link_name = (char *) xmalloc(file_header->size + 1);
|
||||
xread(archive_handle->src_fd, file_header->link_name, file_header->size);
|
||||
file_header->link_name[file_header->size] = '\0';
|
||||
archive_handle->offset += file_header->size;
|
||||
file_header->size = 0; /* Stop possible seeks in future */
|
||||
}
|
||||
if (nlink > 1 && !S_ISDIR(file_header->mode)) {
|
||||
if (file_header->size == 0) { /* Put file on a linked list for later */
|
||||
hardlinks_t *new = xmalloc(sizeof(hardlinks_t));
|
||||
new->next = saved_hardlinks;
|
||||
new->inode = inode;
|
||||
new->entry = file_header;
|
||||
saved_hardlinks = new;
|
||||
continue;
|
||||
} else { /* Found the file with data in */
|
||||
hardlinks_t *tmp = saved_hardlinks;
|
||||
pending_hardlinks = 1;
|
||||
while (tmp) {
|
||||
if (tmp->inode == inode) {
|
||||
tmp->entry->link_name = xstrdup(file_header->name);
|
||||
nlink--;
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
if (nlink > 1) {
|
||||
error_msg("error resolving hardlink: did you create the archive with GNU cpio 2.0-2.2?");
|
||||
}
|
||||
}
|
||||
}
|
||||
file_header->device = (major << 8) | minor;
|
||||
|
||||
extract_flag = FALSE;
|
||||
if (archive_handle->filter(archive_handle->accept, archive_handle->reject, file_header->name) == EXIT_SUCCESS) {
|
||||
struct stat statbuf;
|
||||
|
||||
extract_flag = TRUE;
|
||||
|
||||
/* Check if the file already exists */
|
||||
if (lstat (file_header->name, &statbuf) == 0) {
|
||||
if ((archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) || (statbuf.st_mtime < file_header->mtime)) {
|
||||
/* Remove file if flag set or its older than the file to be extracted */
|
||||
if (unlink(file_header->name) == -1) {
|
||||
perror_msg_and_die("Couldnt remove old file");
|
||||
}
|
||||
} else {
|
||||
if (! archive_handle->flags & ARCHIVE_EXTRACT_QUIET) {
|
||||
error_msg("%s not created: newer or same age file exists", file_header->name);
|
||||
}
|
||||
extract_flag = FALSE;
|
||||
}
|
||||
}
|
||||
archive_handle->action_header(file_header);
|
||||
}
|
||||
|
||||
archive_handle->action_header(file_header);
|
||||
if (extract_flag) {
|
||||
archive_handle->action_data(archive_handle);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
}
|
||||
archive_handle->offset += file_header->size;
|
||||
}
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
+175
-87
@@ -38,6 +38,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -487,19 +488,17 @@ void add_split_dependencies(common_node_t *parent_node, const char *whole_line,
|
||||
|
||||
void free_package(common_node_t *node)
|
||||
{
|
||||
int i;
|
||||
if (node != NULL) {
|
||||
unsigned short i;
|
||||
if (node) {
|
||||
for (i = 0; i < node->num_of_edges; i++) {
|
||||
if (node->edge[i] != NULL) {
|
||||
if (node->edge[i]) {
|
||||
free(node->edge[i]);
|
||||
}
|
||||
}
|
||||
if (node->edge != NULL) {
|
||||
if (node->edge) {
|
||||
free(node->edge);
|
||||
}
|
||||
if (node != NULL) {
|
||||
free(node);
|
||||
}
|
||||
free(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -858,7 +857,7 @@ void write_status_file(deb_file_t **deb_file)
|
||||
}
|
||||
}
|
||||
/* If the package from the status file wasnt handle above, do it now*/
|
||||
if (write_flag == FALSE) {
|
||||
if (! write_flag) {
|
||||
fprintf(new_status_file, "%s\n\n", control_buffer);
|
||||
}
|
||||
|
||||
@@ -905,9 +904,8 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
int state_status;
|
||||
int state_flag;
|
||||
int state_want;
|
||||
unsigned int status_package_num;
|
||||
int i = deb_start;
|
||||
int j, k;
|
||||
int j;
|
||||
|
||||
/* Check for conflicts
|
||||
* TODO: TEST if conflicts with other packages to be installed
|
||||
@@ -948,38 +946,49 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
}
|
||||
|
||||
/* Check conflicts */
|
||||
for (i = 0; i < conflicts_num; i++) {
|
||||
/* Check for conflicts */
|
||||
for (j = 0; j < STATUS_HASH_PRIME; j++) {
|
||||
if (status_hashtable[j] == NULL) {
|
||||
continue;
|
||||
}
|
||||
state_flag = get_status(j, 2);
|
||||
state_status = get_status(j, 3);
|
||||
if ((state_status != search_name_hashtable("installed"))
|
||||
&& (state_flag != search_name_hashtable("want-install"))) {
|
||||
continue;
|
||||
}
|
||||
status_package_num = status_hashtable[j]->package;
|
||||
for (k = 0; k < package_hashtable[status_package_num]->num_of_edges; k++) {
|
||||
const edge_t *package_edge = package_hashtable[status_package_num]->edge[k];
|
||||
if (package_edge->type != EDGE_CONFLICTS) {
|
||||
continue;
|
||||
i = 0;
|
||||
while (deb_file[i] != NULL) {
|
||||
const common_node_t *package_node = package_hashtable[deb_file[i]->package];
|
||||
int status_num = 0;
|
||||
status_num = search_status_hashtable(name_hashtable[package_node->name]);
|
||||
|
||||
if (get_status(status_num, 3) == search_name_hashtable("installed")) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (j = 0; j < package_node->num_of_edges; j++) {
|
||||
const edge_t *package_edge = package_node->edge[j];
|
||||
const unsigned int package_num =
|
||||
search_package_hashtable(package_edge->name,
|
||||
package_edge->version, package_edge->operator);
|
||||
|
||||
if (package_edge->type == EDGE_CONFLICTS) {
|
||||
int result = 0;
|
||||
if (package_hashtable[package_num] != NULL) {
|
||||
status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
|
||||
state_status = get_status(status_num, 3);
|
||||
state_flag = get_status(status_num, 1);
|
||||
|
||||
result = (state_status == search_name_hashtable("installed")) ||
|
||||
(state_flag == search_name_hashtable("want-install"));
|
||||
|
||||
if (result) {
|
||||
result = test_version(package_hashtable[deb_file[i]->package]->version,
|
||||
package_edge->version, package_edge->operator);
|
||||
}
|
||||
}
|
||||
if (package_edge->name != package_hashtable[conflicts[i]]->name) {
|
||||
continue;
|
||||
}
|
||||
/* There is a conflict against the package name
|
||||
* check if version conflict as well */
|
||||
if (test_version(package_hashtable[deb_file[i]->package]->version,
|
||||
package_edge->version, package_edge->operator)) {
|
||||
error_msg_and_die("Package %s conflict with %s",
|
||||
name_hashtable[package_hashtable[deb_file[i]->package]->name],
|
||||
name_hashtable[package_hashtable[status_package_num]->name]);
|
||||
|
||||
if (result) {
|
||||
error_msg_and_die("Package %s conflicts with %s",
|
||||
name_hashtable[package_node->name],
|
||||
name_hashtable[package_edge->name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
/* Check dependendcies */
|
||||
i = 0;
|
||||
@@ -987,36 +996,58 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
const common_node_t *package_node = package_hashtable[deb_file[i]->package];
|
||||
int status_num = 0;
|
||||
|
||||
status_num = search_status_hashtable(name_hashtable[package_node->name]);
|
||||
state_status = get_status(status_num, 3);
|
||||
state_want = get_status(status_num, 1);
|
||||
|
||||
if (state_status == search_name_hashtable("installed")) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (j = 0; j < package_hashtable[deb_file[i]->package]->num_of_edges; j++) {
|
||||
const edge_t *package_edge = package_node->edge[j];
|
||||
const unsigned int package_num = search_package_hashtable(package_edge->name,
|
||||
package_edge->version, package_edge->operator);
|
||||
unsigned int package_num;
|
||||
|
||||
package_num = search_package_hashtable(package_edge->name, package_edge->version, package_edge->operator);
|
||||
|
||||
status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
|
||||
state_status = get_status(status_num, 3);
|
||||
state_want = get_status(status_num, 1);
|
||||
switch (package_edge->type) {
|
||||
case(EDGE_PRE_DEPENDS):
|
||||
case(EDGE_OR_PRE_DEPENDS):
|
||||
case(EDGE_OR_PRE_DEPENDS): {
|
||||
int result=1;
|
||||
/* It must be already installed */
|
||||
/* NOTE: This is untested, nothing apropriate in my status file */
|
||||
if ((package_hashtable[package_num] == NULL) || (state_status != search_name_hashtable("installed"))) {
|
||||
if (package_hashtable[package_num] != NULL) {
|
||||
status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
|
||||
state_status = get_status(status_num, 3);
|
||||
state_want = get_status(status_num, 1);
|
||||
result = (state_status != search_name_hashtable("installed"));
|
||||
}
|
||||
|
||||
if (result) {
|
||||
error_msg_and_die("Package %s pre-depends on %s, but it is not installed",
|
||||
name_hashtable[package_node->name],
|
||||
name_hashtable[package_edge->name]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(EDGE_DEPENDS):
|
||||
case(EDGE_OR_DEPENDS):
|
||||
case(EDGE_OR_DEPENDS): {
|
||||
int result=1;
|
||||
if (package_hashtable[package_num] != NULL) {
|
||||
status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
|
||||
state_status = get_status(status_num, 3);
|
||||
state_want = get_status(status_num, 1);
|
||||
result=(state_status != search_name_hashtable("installed")) && (state_want != search_name_hashtable("want-install"));
|
||||
}
|
||||
/* It must be already installed, or to be installed */
|
||||
if ((package_hashtable[package_num] == NULL) ||
|
||||
((state_status != search_name_hashtable("installed")) &&
|
||||
(state_want != search_name_hashtable("want_install")))) {
|
||||
if (result) {
|
||||
error_msg_and_die("Package %s depends on %s, but it is not installed, or flaged to be installed",
|
||||
name_hashtable[package_node->name],
|
||||
name_hashtable[package_edge->name]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
@@ -1028,25 +1059,20 @@ int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
char **create_list(const char *filename)
|
||||
{
|
||||
FILE *list_stream;
|
||||
char **file_list = xmalloc(sizeof(char *));
|
||||
char **file_list = NULL;
|
||||
char *line = NULL;
|
||||
char *last_char;
|
||||
int length = 0;
|
||||
int count = 0;
|
||||
|
||||
/* dont use [xw]fopen here, handle error ourself */
|
||||
list_stream = fopen(filename, "r");
|
||||
if (list_stream == NULL) {
|
||||
*file_list = NULL;
|
||||
return(file_list);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
while (getline(&line, &length, list_stream) != -1) {
|
||||
/* +2 as we need to include space for the terminating NULL pointer */
|
||||
file_list = xrealloc(file_list, sizeof(char *) * (length + 2));
|
||||
last_char = last_char_is(line, '\n');
|
||||
if (last_char) {
|
||||
*last_char = '\0';
|
||||
}
|
||||
file_list = xrealloc(file_list, sizeof(char *) * (count + 2));
|
||||
chomp(line);
|
||||
file_list[count] = xstrdup(line);
|
||||
count++;
|
||||
}
|
||||
@@ -1119,20 +1145,37 @@ int run_package_script(const char *package_name, const char *script_type)
|
||||
return(result);
|
||||
}
|
||||
|
||||
void all_control_list(char **remove_files, const char *package_name)
|
||||
char **all_control_list(const char *package_name)
|
||||
{
|
||||
const char *all_extensions[11] = {"preinst", "postinst", "prerm", "postrm",
|
||||
const char *extensions[11] = {"preinst", "postinst", "prerm", "postrm",
|
||||
"list", "md5sums", "shlibs", "conffiles", "config", "templates", NULL };
|
||||
int i;
|
||||
unsigned short i = 0;
|
||||
char **remove_files;
|
||||
|
||||
/* Create a list of all /var/lib/dpkg/info/<package> files */
|
||||
for(i = 0; i < 10; i++) {
|
||||
remove_files[i] = xmalloc(strlen(package_name) + strlen(all_extensions[i]) + 21);
|
||||
sprintf(remove_files[i], "/var/lib/dpkg/info/%s.%s", package_name, all_extensions[i]);
|
||||
remove_files = malloc(sizeof(char *) * 11);
|
||||
while (extensions[i]) {
|
||||
remove_files[i] = xmalloc(strlen(package_name) + strlen(extensions[i]) + 21);
|
||||
sprintf(remove_files[i], "/var/lib/dpkg/info/%s.%s", package_name, extensions[i]);
|
||||
i++;
|
||||
}
|
||||
remove_files[10] = NULL;
|
||||
|
||||
return(remove_files);
|
||||
}
|
||||
|
||||
void free_array(char **array)
|
||||
{
|
||||
|
||||
if (array) {
|
||||
unsigned short i = 0;
|
||||
while (array[i]) {
|
||||
free(array[i]);
|
||||
i++;
|
||||
}
|
||||
free(array);
|
||||
}
|
||||
}
|
||||
|
||||
/* This function lists information on the installed packages. It loops through
|
||||
* the status_hashtable to retrieve the info. This results in smaller code than
|
||||
@@ -1202,11 +1245,9 @@ void remove_package(const unsigned int package_num)
|
||||
exclude_files = create_list(conffile_name);
|
||||
|
||||
/* Some directories cant be removed straight away, so do multiple passes */
|
||||
while (remove_file_array(remove_files, exclude_files) == TRUE);
|
||||
|
||||
/* Create a list of all /var/lib/dpkg/info/<package> files */
|
||||
remove_files = xmalloc(11);
|
||||
all_control_list(remove_files, package_name);
|
||||
while (remove_file_array(remove_files, exclude_files));
|
||||
free_array(exclude_files);
|
||||
free_array(remove_files);
|
||||
|
||||
/* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
|
||||
exclude_files = xmalloc(sizeof(char*) * 3);
|
||||
@@ -1215,7 +1256,12 @@ void remove_package(const unsigned int package_num)
|
||||
sprintf(exclude_files[1], "/var/lib/dpkg/info/%s.postrm", package_name);
|
||||
exclude_files[2] = NULL;
|
||||
|
||||
/* Create a list of all /var/lib/dpkg/info/<package> files */
|
||||
remove_files = all_control_list(package_name);
|
||||
|
||||
remove_file_array(remove_files, exclude_files);
|
||||
free_array(remove_files);
|
||||
free_array(exclude_files);
|
||||
|
||||
/* rename <package>.conffile to <package>.list */
|
||||
rename(conffile_name, list_name);
|
||||
@@ -1242,16 +1288,18 @@ void purge_package(const unsigned int package_num)
|
||||
sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name);
|
||||
remove_files = create_list(list_name);
|
||||
|
||||
exclude_files = xmalloc(1);
|
||||
exclude_files = xmalloc(sizeof(char*));
|
||||
exclude_files[0] = NULL;
|
||||
|
||||
/* Some directories cant be removed straight away, so do multiple passes */
|
||||
while (remove_file_array(remove_files, exclude_files) == TRUE);
|
||||
while (remove_file_array(remove_files, exclude_files));
|
||||
free_array(remove_files);
|
||||
|
||||
/* Create a list of all /var/lib/dpkg/info/<package> files */
|
||||
remove_files = xmalloc(11);
|
||||
all_control_list(remove_files, package_name);
|
||||
remove_files = all_control_list(package_name);
|
||||
remove_file_array(remove_files, exclude_files);
|
||||
free_array(remove_files);
|
||||
free(exclude_files);
|
||||
|
||||
/* run postrm script */
|
||||
if (run_package_script(package_name, "postrm") == -1) {
|
||||
@@ -1263,14 +1311,44 @@ void purge_package(const unsigned int package_num)
|
||||
set_status(status_num, "not-installed", 3);
|
||||
}
|
||||
|
||||
static archive_handle_t *deb_extract(const char *filename, const char *ar_name,
|
||||
const char *tar_gz_name, char *prefix, void (*deb_action_data)(struct archive_handle_s *))
|
||||
{
|
||||
archive_handle_t *ar_archive;
|
||||
archive_handle_t *tar_gz_archive;
|
||||
|
||||
/* Setup the tar archive handle */
|
||||
tar_gz_archive = init_handle();
|
||||
tar_gz_archive->filter = filter_accept_reject_list;
|
||||
tar_gz_archive->action_data = deb_action_data;
|
||||
tar_gz_archive->buffer = prefix;
|
||||
if (tar_gz_name) {
|
||||
tar_gz_archive->accept = add_to_list(NULL, tar_gz_name);
|
||||
}
|
||||
|
||||
/* Setup an ar archive handle that refers to the gzip sub archive */
|
||||
ar_archive = init_handle();
|
||||
ar_archive->action_data_subarchive = get_header_tar_gz;
|
||||
ar_archive->sub_archive = tar_gz_archive;
|
||||
ar_archive->filter = filter_accept_reject_list;
|
||||
ar_archive->accept = add_to_list(NULL, ar_name);
|
||||
|
||||
tar_gz_archive->src_fd = ar_archive->src_fd = xopen(filename, O_RDONLY);
|
||||
|
||||
unpack_ar_archive(ar_archive);
|
||||
close(ar_archive->src_fd);
|
||||
|
||||
return(ar_archive->sub_archive);
|
||||
}
|
||||
|
||||
void unpack_package(deb_file_t *deb_file)
|
||||
{
|
||||
const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
|
||||
const unsigned int status_num = search_status_hashtable(package_name);
|
||||
const unsigned int status_package_num = status_hashtable[status_num]->package;
|
||||
|
||||
FILE *out_stream;
|
||||
char *info_prefix;
|
||||
archive_handle_t *archive_handle;
|
||||
FILE *out_stream;
|
||||
|
||||
/* If existing version, remove it first */
|
||||
if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) {
|
||||
@@ -1284,10 +1362,10 @@ void unpack_package(deb_file_t *deb_file)
|
||||
}
|
||||
|
||||
/* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
|
||||
info_prefix = (char *) xmalloc(sizeof(package_name) + 20 + 4 + 1);
|
||||
info_prefix = (char *) xmalloc(strlen(package_name) + 20 + 4 + 2);
|
||||
sprintf(info_prefix, "/var/lib/dpkg/info/%s.", package_name);
|
||||
deb_extract(deb_file->filename, stdout, (extract_quiet | extract_control_tar_gz | extract_all_to_fs | extract_unconditional), info_prefix, NULL);
|
||||
|
||||
deb_extract(deb_file->filename, "control.tar.gz", NULL, info_prefix, data_extract_all_prefix);
|
||||
/* Run the preinst prior to extracting */
|
||||
if (run_package_script(package_name, "preinst") != 0) {
|
||||
/* when preinst returns exit code != 0 then quit installation process */
|
||||
@@ -1295,12 +1373,17 @@ void unpack_package(deb_file_t *deb_file)
|
||||
}
|
||||
|
||||
/* Extract data.tar.gz to the root directory */
|
||||
deb_extract(deb_file->filename, stdout, (extract_quiet | extract_data_tar_gz | extract_all_to_fs | extract_unconditional), "/", NULL);
|
||||
archive_handle = deb_extract(deb_file->filename, "data.tar.gz", NULL, NULL, data_extract_all);
|
||||
|
||||
/* Create the list file */
|
||||
strcat(info_prefix, "list");
|
||||
out_stream = xfopen(info_prefix, "w");
|
||||
deb_extract(deb_file->filename, out_stream, (extract_quiet | extract_data_tar_gz | extract_list), "/", NULL);
|
||||
while (archive_handle->passed) {
|
||||
/* blindly skip over the leading '.' */
|
||||
fputs(archive_handle->passed->data + 1, out_stream);
|
||||
fputc('\n', out_stream);
|
||||
archive_handle->passed = archive_handle->passed->link;
|
||||
}
|
||||
fclose(out_stream);
|
||||
|
||||
/* change status */
|
||||
@@ -1328,7 +1411,7 @@ void configure_package(deb_file_t *deb_file)
|
||||
set_status(status_num, "installed", 3);
|
||||
}
|
||||
|
||||
extern int dpkg_main(int argc, char **argv)
|
||||
int dpkg_main(int argc, char **argv)
|
||||
{
|
||||
deb_file_t **deb_file = NULL;
|
||||
status_node_t *status_node;
|
||||
@@ -1388,12 +1471,15 @@ extern int dpkg_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Read arguments and store relevant info in structs */
|
||||
deb_file = xmalloc(sizeof(deb_file_t));
|
||||
while (optind < argc) {
|
||||
/* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */
|
||||
deb_file = xrealloc(deb_file, sizeof(deb_file_t *) * (deb_count + 2));
|
||||
deb_file[deb_count] = (deb_file_t *) xmalloc(sizeof(deb_file_t));
|
||||
if (dpkg_opt & dpkg_opt_filename) {
|
||||
archive_handle_t *archive_handle;
|
||||
deb_file[deb_count]->filename = xstrdup(argv[optind]);
|
||||
deb_file[deb_count]->control_file = deb_extract(argv[optind], stdout, (extract_control_tar_gz | extract_one_to_buffer), NULL, "./control");
|
||||
archive_handle = deb_extract(argv[optind], "control.tar.gz", "./control", NULL, data_extract_to_buffer);
|
||||
deb_file[deb_count]->control_file = archive_handle->buffer;
|
||||
if (deb_file[deb_count]->control_file == NULL) {
|
||||
error_msg_and_die("Couldnt extract control file");
|
||||
}
|
||||
@@ -1408,7 +1494,6 @@ extern int dpkg_main(int argc, char **argv)
|
||||
if ((dpkg_opt & dpkg_opt_unpack) || (dpkg_opt & dpkg_opt_install)) {
|
||||
status_node = (status_node_t *) xmalloc(sizeof(status_node_t));
|
||||
status_node->package = deb_file[deb_count]->package;
|
||||
|
||||
/* Try and find a currently installed version of this package */
|
||||
status_num = search_status_hashtable(name_hashtable[package_hashtable[deb_file[deb_count]->package]->name]);
|
||||
/* If no previous entry was found initialise a new entry */
|
||||
@@ -1416,10 +1501,10 @@ extern int dpkg_main(int argc, char **argv)
|
||||
(status_hashtable[status_num]->status == 0)) {
|
||||
/* reinstreq isnt changed to "ok" until the package control info
|
||||
* is written to the status file*/
|
||||
status_node->status = search_name_hashtable("install reinstreq not-installed");
|
||||
status_node->status = search_name_hashtable("want-install reinstreq not-installed");
|
||||
status_hashtable[status_num] = status_node;
|
||||
} else {
|
||||
status_hashtable[status_num]->status = search_name_hashtable("install reinstreq installed");
|
||||
status_hashtable[status_num]->status = search_name_hashtable("want-install reinstreq not-installed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1488,6 +1573,7 @@ extern int dpkg_main(int argc, char **argv)
|
||||
free(deb_file[i]->filename);
|
||||
free(deb_file[i]);
|
||||
}
|
||||
|
||||
free(deb_file);
|
||||
|
||||
for (i = 0; i < NAME_HASH_PRIME; i++) {
|
||||
@@ -1497,7 +1583,9 @@ extern int dpkg_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
for (i = 0; i < PACKAGE_HASH_PRIME; i++) {
|
||||
free_package(package_hashtable[i]);
|
||||
if (package_hashtable[i] != NULL) {
|
||||
free_package(package_hashtable[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < STATUS_HASH_PRIME; i++) {
|
||||
|
||||
+60
-79
@@ -13,119 +13,100 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
extern int dpkg_deb_main(int argc, char **argv)
|
||||
{
|
||||
char *prefix = NULL;
|
||||
char *filename = NULL;
|
||||
char *output_buffer = NULL;
|
||||
archive_handle_t *ar_archive;
|
||||
archive_handle_t *tar_gz_archive;
|
||||
int opt = 0;
|
||||
int arg_type = 0;
|
||||
int deb_extract_funct = extract_create_leading_dirs | extract_unconditional;
|
||||
#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
const llist_t *control_tar_gz_llist = add_to_list(NULL, "control.tar.gz");
|
||||
#endif
|
||||
#ifndef CONFIG_AR
|
||||
char magic[7];
|
||||
#endif
|
||||
|
||||
const int arg_type_prefix = 1;
|
||||
const int arg_type_field = 2;
|
||||
const int arg_type_filename = 4;
|
||||
// const int arg_type_un_ar_gz = 8;
|
||||
/* a .deb file is an ar archive that contain three files,
|
||||
* data.tar.gz, control.tar.gz and debian
|
||||
*/
|
||||
|
||||
/* Setup the tar archive handle */
|
||||
tar_gz_archive = init_handle();
|
||||
|
||||
while ((opt = getopt(argc, argv, "ceftXxI")) != -1) {
|
||||
/* Setup an ar archive handle that refers to the gzip sub archive */
|
||||
ar_archive = init_handle();
|
||||
ar_archive->action_data_subarchive = get_header_tar_gz;
|
||||
ar_archive->sub_archive = tar_gz_archive;
|
||||
ar_archive->filter = filter_accept_list;
|
||||
ar_archive->accept = add_to_list(NULL, "data.tar.gz");
|
||||
|
||||
#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
while ((opt = getopt(argc, argv, "cefXx")) != -1) {
|
||||
#else
|
||||
while ((opt = getopt(argc, argv, "x")) != -1) {
|
||||
#endif
|
||||
switch (opt) {
|
||||
#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
case 'c':
|
||||
deb_extract_funct |= extract_data_tar_gz;
|
||||
deb_extract_funct |= extract_verbose_list;
|
||||
tar_gz_archive->action_header = header_verbose_list;
|
||||
break;
|
||||
case 'e':
|
||||
arg_type = arg_type_prefix;
|
||||
deb_extract_funct |= extract_control_tar_gz;
|
||||
deb_extract_funct |= extract_all_to_fs;
|
||||
ar_archive->accept = control_tar_gz_llist;
|
||||
tar_gz_archive->action_data = data_extract_all;
|
||||
break;
|
||||
case 'f':
|
||||
arg_type = arg_type_field;
|
||||
deb_extract_funct |= extract_control_tar_gz;
|
||||
deb_extract_funct |= extract_one_to_buffer;
|
||||
filename = xstrdup("./control");
|
||||
break;
|
||||
case 't': /* --fsys-tarfile, i just made up this short name */
|
||||
/* Integrate the functionality needed with some code from ar.c */
|
||||
error_msg_and_die("Option disabled");
|
||||
// arg_type = arg_type_un_ar_gz;
|
||||
/* Print the entire control file
|
||||
* it should accept a second argument which specifies a
|
||||
* specific field to print */
|
||||
ar_archive->accept = control_tar_gz_llist;
|
||||
tar_gz_archive->accept = add_to_list(NULL, "./control");;
|
||||
tar_gz_archive->filter = filter_accept_list;
|
||||
tar_gz_archive->action_data = data_extract_to_stdout;
|
||||
break;
|
||||
case 'X':
|
||||
arg_type = arg_type_prefix;
|
||||
deb_extract_funct |= extract_data_tar_gz;
|
||||
deb_extract_funct |= extract_all_to_fs;
|
||||
deb_extract_funct |= extract_list;
|
||||
tar_gz_archive->action_header = header_list;
|
||||
#endif
|
||||
case 'x':
|
||||
arg_type = arg_type_prefix;
|
||||
deb_extract_funct |= extract_data_tar_gz;
|
||||
deb_extract_funct |= extract_all_to_fs;
|
||||
break;
|
||||
case 'I':
|
||||
arg_type = arg_type_filename;
|
||||
deb_extract_funct |= extract_control_tar_gz;
|
||||
deb_extract_funct |= extract_one_to_buffer;
|
||||
tar_gz_archive->action_data = data_extract_all;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc) {
|
||||
if (optind + 2 < argc) {
|
||||
show_usage();
|
||||
}
|
||||
|
||||
tar_gz_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
|
||||
|
||||
/* Workout where to extract the files */
|
||||
if (arg_type == arg_type_prefix) {
|
||||
/* argument is a dir name */
|
||||
if ((optind + 1) == argc ) {
|
||||
prefix = xstrdup("./DEBIAN/");
|
||||
} else {
|
||||
prefix = (char *) xmalloc(strlen(argv[optind + 1]) + 2);
|
||||
strcpy(prefix, argv[optind + 1]);
|
||||
/* Make sure the directory has a trailing '/' */
|
||||
if (last_char_is(prefix, '/') == NULL) {
|
||||
strcat(prefix, "/");
|
||||
}
|
||||
}
|
||||
mkdir(prefix, 0777);
|
||||
}
|
||||
/* 2nd argument is a dir name */
|
||||
mkdir(argv[optind], 0777);
|
||||
chdir(argv[optind]);
|
||||
|
||||
if (arg_type == arg_type_filename) {
|
||||
if ((optind + 1) != argc) {
|
||||
filename = xstrdup(argv[optind + 1]);
|
||||
} else {
|
||||
error_msg_and_die("-I currently requires a filename to be specified");
|
||||
}
|
||||
#ifdef CONFIG_AR
|
||||
unpack_ar_archive(ar_archive);
|
||||
#else
|
||||
xread_all(ar_archive->src_fd, magic, 7);
|
||||
if (strncmp(magic, "!<arch>", 7) != 0) {
|
||||
error_msg_and_die("Invalid ar magic");
|
||||
}
|
||||
ar_archive->offset += 7;
|
||||
|
||||
output_buffer = deb_extract(argv[optind], stdout, deb_extract_funct, prefix, filename);
|
||||
while (get_header_ar(ar_archive) == EXIT_SUCCESS);
|
||||
#endif
|
||||
|
||||
if ((arg_type == arg_type_filename) && (output_buffer != NULL)) {
|
||||
puts(output_buffer);
|
||||
}
|
||||
else if (arg_type == arg_type_field) {
|
||||
char *field = NULL;
|
||||
char *name;
|
||||
char *value;
|
||||
int field_start = 0;
|
||||
|
||||
while (1) {
|
||||
field_start += read_package_field(&output_buffer[field_start], &name, &value);
|
||||
if (name == NULL) {
|
||||
break;
|
||||
}
|
||||
if (strcmp(name, argv[optind + 1]) == 0) {
|
||||
puts(value);
|
||||
}
|
||||
free(field);
|
||||
}
|
||||
}
|
||||
/* Cleanup */
|
||||
close (ar_archive->src_fd);
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
+114
-88
@@ -7,9 +7,9 @@
|
||||
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
* based on gzip sources
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* to support files as well as stdin/stdout, and to generally behave itself wrt
|
||||
* command line handling.
|
||||
* Adjusted further by Erik Andersen <andersee@debian.org> to support files as
|
||||
* well as stdin/stdout, and to generally behave itself wrt command line
|
||||
* handling.
|
||||
*
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath <bug1@optushome.com.au>
|
||||
@@ -64,31 +64,29 @@ static char *license_msg[] = {
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
const char gunzip_to_stdout = 1;
|
||||
const char gunzip_force = 2;
|
||||
const char gunzip_test = 4;
|
||||
|
||||
extern int gunzip_main(int argc, char **argv)
|
||||
{
|
||||
FILE *in_file = stdin;
|
||||
FILE *out_file = NULL;
|
||||
struct stat stat_buf;
|
||||
|
||||
char *if_name = NULL;
|
||||
char *of_name = NULL;
|
||||
char *delete_file_name = NULL;
|
||||
|
||||
const int gunzip_to_stdout = 1;
|
||||
const int gunzip_force = 2;
|
||||
const int gunzip_test = 4;
|
||||
|
||||
int flags = 0;
|
||||
int opt = 0;
|
||||
int delete_old_file = FALSE;
|
||||
char status = EXIT_SUCCESS;
|
||||
char flags = 0;
|
||||
int opt;
|
||||
|
||||
/* if called as zcat */
|
||||
if (strcmp(applet_name, "zcat") == 0)
|
||||
if (strcmp(applet_name, "zcat") == 0) {
|
||||
flags |= gunzip_to_stdout;
|
||||
}
|
||||
|
||||
while ((opt = getopt(argc, argv, "ctfhdq")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "ctfhd")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
flags |= gunzip_to_stdout;
|
||||
@@ -99,85 +97,113 @@ extern int gunzip_main(int argc, char **argv)
|
||||
case 't':
|
||||
flags |= gunzip_test;
|
||||
break;
|
||||
case 'd': /* Used to convert gzip to gunzip. */
|
||||
case 'd': /* Used to convert gzip to gunzip. */
|
||||
break;
|
||||
case 'q':
|
||||
error_msg("-q option not supported, ignored");
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
show_usage(); /* exit's inside usage */
|
||||
show_usage(); /* exit's inside usage */
|
||||
}
|
||||
}
|
||||
|
||||
/* Set input filename and number */
|
||||
if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
|
||||
flags |= gunzip_to_stdout;
|
||||
} else {
|
||||
if_name = xstrdup(argv[optind]);
|
||||
/* Open input file */
|
||||
in_file = xfopen(if_name, "r");
|
||||
do {
|
||||
struct stat stat_buf;
|
||||
const char *old_path = argv[optind];
|
||||
const char *delete_path = NULL;
|
||||
char *new_path = NULL;
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
|
||||
/* set the buffer size */
|
||||
setvbuf(in_file, NULL, _IOFBF, 0x8000);
|
||||
optind++;
|
||||
|
||||
/* Get the time stamp on the input file. */
|
||||
if (stat(if_name, &stat_buf) < 0) {
|
||||
error_msg_and_die("Couldn't stat file %s", if_name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(fileno(in_file)) && (flags & gunzip_force) == 0)
|
||||
error_msg_and_die("compressed data not read from terminal. Use -f to force it.");
|
||||
|
||||
/* Set output filename and number */
|
||||
if (flags & gunzip_test) {
|
||||
out_file = xfopen("/dev/null", "w"); /* why does test use filenum 2 ? */
|
||||
} else if (flags & gunzip_to_stdout) {
|
||||
out_file = stdout;
|
||||
} else {
|
||||
char *extension;
|
||||
int length = strlen(if_name);
|
||||
|
||||
delete_old_file = TRUE;
|
||||
extension = strrchr(if_name, '.');
|
||||
if (extension && strcmp(extension, ".gz") == 0) {
|
||||
length -= 3;
|
||||
} else if (extension && strcmp(extension, ".tgz") == 0) {
|
||||
length -= 4;
|
||||
if (old_path == NULL || strcmp(old_path, "-") == 0) {
|
||||
src_fd = fileno(stdin);
|
||||
flags |= gunzip_to_stdout;
|
||||
} else {
|
||||
error_msg_and_die("Invalid extension");
|
||||
src_fd = xopen(old_path, O_RDONLY);
|
||||
|
||||
/* Get the time stamp on the input file. */
|
||||
if (stat(old_path, &stat_buf) < 0) {
|
||||
error_msg_and_die("Couldn't stat file %s", old_path);
|
||||
}
|
||||
}
|
||||
of_name = (char *) xcalloc(sizeof(char), length + 1);
|
||||
strncpy(of_name, if_name, length);
|
||||
|
||||
/* Open output file */
|
||||
out_file = xfopen(of_name, "w");
|
||||
|
||||
/* Set permissions on the file */
|
||||
chmod(of_name, stat_buf.st_mode);
|
||||
}
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if (unzip(in_file, out_file) == 0) {
|
||||
/* Success, remove .gz file */
|
||||
delete_file_name = if_name;
|
||||
} else {
|
||||
/* remove failed attempt */
|
||||
delete_file_name = of_name;
|
||||
}
|
||||
|
||||
fclose(out_file);
|
||||
fclose(in_file);
|
||||
|
||||
if (delete_old_file == TRUE) {
|
||||
if (unlink(delete_file_name) < 0) {
|
||||
error_msg_and_die("Couldnt remove %s", delete_file_name);
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && ((flags & gunzip_force) == 0)) {
|
||||
error_msg_and_die
|
||||
("compressed data not read from terminal. Use -f to force it.");
|
||||
}
|
||||
}
|
||||
|
||||
free(of_name);
|
||||
/* Set output filename and number */
|
||||
if (flags & gunzip_test) {
|
||||
dst_fd = xopen("/dev/null", O_WRONLY); /* why does test use filenum 2 ? */
|
||||
} else if (flags & gunzip_to_stdout) {
|
||||
dst_fd = fileno(stdout);
|
||||
} else {
|
||||
char *extension;
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
new_path = xstrdup(old_path);
|
||||
|
||||
extension = strrchr(new_path, '.');
|
||||
if (extension && (strcmp(extension, ".gz") == 0)) {
|
||||
*extension = '\0';
|
||||
} else if (extension && (strcmp(extension, ".tgz") == 0)) {
|
||||
extension[2] = 'a';
|
||||
extension[3] = 'r';
|
||||
} else {
|
||||
error_msg_and_die("Invalid extension");
|
||||
}
|
||||
|
||||
/* Open output file */
|
||||
dst_fd = xopen(new_path, O_WRONLY | O_CREAT);
|
||||
|
||||
/* Set permissions on the file */
|
||||
chmod(new_path, stat_buf.st_mode);
|
||||
|
||||
/* If unzip succeeds remove the old file */
|
||||
delete_path = old_path;
|
||||
}
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if (xread_char(src_fd) == 0x1f) {
|
||||
unsigned char magic2;
|
||||
|
||||
magic2 = xread_char(src_fd);
|
||||
#ifdef CONFIG_FEATURE_UNCOMPRESS
|
||||
if (magic2 == 0x9d) {
|
||||
return(uncompress(src_fd, dst_fd));
|
||||
} else
|
||||
#endif
|
||||
if (magic2 == 0x8b) {
|
||||
check_header_gzip(src_fd);
|
||||
status = inflate(src_fd, dst_fd);
|
||||
if (status != 0) {
|
||||
error_msg("Error inflating");
|
||||
}
|
||||
check_trailer_gzip(src_fd);
|
||||
} else {
|
||||
error_msg_and_die("Invalid magic\n");
|
||||
}
|
||||
}
|
||||
|
||||
if ((status != EXIT_SUCCESS) && (new_path)) {
|
||||
/* Unzip failed, remove new path instead of old path */
|
||||
delete_path = new_path;
|
||||
}
|
||||
|
||||
if (dst_fd != fileno(stdout)) {
|
||||
close(dst_fd);
|
||||
}
|
||||
if (src_fd != fileno(stdin)) {
|
||||
close(src_fd);
|
||||
}
|
||||
|
||||
/* delete_path will be NULL if in test mode or from stdin */
|
||||
if (delete_path && (unlink(delete_path) == -1)) {
|
||||
error_msg_and_die("Couldn't remove %s", delete_path);
|
||||
}
|
||||
|
||||
free(new_path);
|
||||
|
||||
} while (optind < argc);
|
||||
|
||||
return status;
|
||||
}
|
||||
+300
-316
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
|
||||
# Copyright (C) 1999-2002 Erik Andersen <andersee@debian.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,41 +17,14 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
TOPDIR :=../..
|
||||
L_TARGET := libunarchive.a
|
||||
|
||||
obj-y := unarchive.o seek_sub_file.o
|
||||
obj-n :=
|
||||
obj- :=
|
||||
|
||||
ifeq ($(CONFIG_DPKG),y)
|
||||
obj-y += deb_extract.o get_header_ar.o get_header_tar.o
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DPKG_DEB),y)
|
||||
obj-y += deb_extract.o get_header_ar.o get_header_tar.o
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_AR),y)
|
||||
obj-y += get_header_ar.o
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CPIO),y)
|
||||
obj-y += get_header_cpio.o
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_RPM2CPIO),y)
|
||||
obj-y += get_header_cpio.o
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_TAR),y)
|
||||
obj-y += get_header_tar.o
|
||||
endif
|
||||
|
||||
|
||||
# Hand off to toplevel Rules.mak
|
||||
include $(TOPDIR)/Rules.mak
|
||||
TOPDIR:= ../../
|
||||
LIBUNARCHIVE_DIR:=./
|
||||
include $(TOPDIR).config
|
||||
include $(TOPDIR)Rules.mak
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(TOPDIR).depend
|
||||
|
||||
clean:
|
||||
rm -f $(L_TARGET) *.o core
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2002 by Erik Andersen <andersee@debian.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
LIBUNARCHIVE_AR:=libunarchive.a
|
||||
ifndef $(LIBUNARCHIVE_DIR)
|
||||
LIBUNARCHIVE_DIR:=$(TOPDIR)archival/libunarchive/
|
||||
endif
|
||||
|
||||
LIBUNARCHIVE-y:= \
|
||||
\
|
||||
data_skip.o \
|
||||
data_extract_all.o \
|
||||
data_extract_all_prefix.o \
|
||||
data_extract_to_stdout.o \
|
||||
data_extract_to_buffer.o \
|
||||
\
|
||||
filter_accept_all.o \
|
||||
filter_accept_list.o \
|
||||
filter_accept_reject_list.o \
|
||||
\
|
||||
get_header_ar.o \
|
||||
get_header_tar.o \
|
||||
get_header_tar_gz.o \
|
||||
\
|
||||
header_skip.o \
|
||||
header_list.o \
|
||||
header_verbose_list.o \
|
||||
\
|
||||
add_to_list.o \
|
||||
check_header_gzip.o \
|
||||
check_trailer_gzip.o \
|
||||
copy_file_chunk_fd.o \
|
||||
data_align.o \
|
||||
find_list_entry.o \
|
||||
init_handle.o \
|
||||
seek_sub_file.o \
|
||||
uncompress.o \
|
||||
unpack_ar_archive.o \
|
||||
unzip.o
|
||||
|
||||
LIBUNARCHIVE-$(CONFIG_DPKG) +=
|
||||
LIBUNARCHIVE-$(CONFIG_DPKG_DEB) +=
|
||||
LIBUNARCHIVE-$(CONFIG_AR) +=
|
||||
LIBUNARCHIVE-$(CONFIG_CPIO) +=
|
||||
LIBUNARCHIVE-$(CONFIG_GUNZIP) +=
|
||||
LIBUNARCHIVE-$(CONFIG_RPM2CPIO) +=
|
||||
LIBUNARCHIVE-$(CONFIG_TAR) +=
|
||||
LIBUNARCHIVE-$(CONFIG_UNZIP) +=
|
||||
|
||||
libraries-y+=$(LIBUNARCHIVE_DIR)$(LIBUNARCHIVE_AR)
|
||||
|
||||
$(LIBUNARCHIVE_DIR)$(LIBUNARCHIVE_AR): $(patsubst %,$(LIBUNARCHIVE_DIR)%, $(LIBUNARCHIVE-y))
|
||||
$(AR) -ro $@ $(patsubst %,$(LIBUNARCHIVE_DIR)%, $(LIBUNARCHIVE-y))
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
extern const llist_t *add_to_list(const llist_t *old_head, const char *new_item)
|
||||
{
|
||||
llist_t *new_head;
|
||||
|
||||
new_head = xmalloc(sizeof(llist_t));
|
||||
new_head->data = new_item;
|
||||
new_head->link = old_head;
|
||||
|
||||
return(new_head);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "libbb.h"
|
||||
|
||||
extern void check_header_gzip(int src_fd)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
struct {
|
||||
unsigned char method;
|
||||
unsigned char flags;
|
||||
unsigned int mtime;
|
||||
unsigned char xtra_flags;
|
||||
unsigned char os_flags;
|
||||
} formated;
|
||||
} header;
|
||||
|
||||
xread_all(src_fd, header.raw, 8);
|
||||
|
||||
/* Check the compression method */
|
||||
if (header.formated.method != 8) {
|
||||
error_msg_and_die("Unknown compression method %d",
|
||||
header.formated.method);
|
||||
}
|
||||
|
||||
if (header.formated.flags & 0x04) {
|
||||
/* bit 2 set: extra field present */
|
||||
unsigned char extra_short;
|
||||
|
||||
extra_short = xread_char(src_fd);
|
||||
extra_short += xread_char(src_fd) << 8;
|
||||
while (extra_short > 0) {
|
||||
/* Ignore extra field */
|
||||
xread_char(src_fd);
|
||||
extra_short--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Discard original name if any */
|
||||
if (header.formated.flags & 0x08) {
|
||||
/* bit 3 set: original file name present */
|
||||
char tmp;
|
||||
|
||||
do {
|
||||
read(src_fd, &tmp, 1);
|
||||
} while (tmp != 0);
|
||||
}
|
||||
|
||||
/* Discard file comment if any */
|
||||
if (header.formated.flags & 0x10) {
|
||||
/* bit 4 set: file comment present */
|
||||
char tmp;
|
||||
|
||||
do {
|
||||
read(src_fd, &tmp, 1);
|
||||
} while (tmp != 0);
|
||||
}
|
||||
|
||||
/* Read the header checksum */
|
||||
if (header.formated.flags & 0x02) {
|
||||
char tmp;
|
||||
|
||||
read(src_fd, &tmp, 1);
|
||||
read(src_fd, &tmp, 1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* busybox gunzip trailing header handler
|
||||
* Copyright Glenn McGrath 2002
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "config.h"
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern unsigned int gunzip_crc;
|
||||
extern unsigned int gunzip_bytes_out;
|
||||
extern unsigned char *gunzip_in_buffer;
|
||||
extern unsigned char gunzip_in_buffer_count;
|
||||
|
||||
extern void check_trailer_gzip(int src_fd)
|
||||
{
|
||||
|
||||
unsigned int stored_crc = 0;
|
||||
unsigned char count;
|
||||
|
||||
/* top up the input buffer with the rest of the trailer */
|
||||
xread_all(src_fd, &gunzip_in_buffer[gunzip_in_buffer_count], 8 - gunzip_in_buffer_count);
|
||||
for (count = 0; count != 4; count++) {
|
||||
stored_crc |= (gunzip_in_buffer[count] << (count * 8));
|
||||
}
|
||||
|
||||
/* Validate decompression - crc */
|
||||
if (stored_crc != (gunzip_crc ^ 0xffffffffL)) {
|
||||
error_msg("invalid compressed data--crc error");
|
||||
}
|
||||
|
||||
/* Validate decompression - size */
|
||||
if (gunzip_bytes_out !=
|
||||
(gunzip_in_buffer[4] | (gunzip_in_buffer[5] << 8) |
|
||||
(gunzip_in_buffer[6] << 16) | (gunzip_in_buffer[7] << 24))) {
|
||||
error_msg("invalid compressed data--length error");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include "libbb.h"
|
||||
|
||||
/* Copy CHUNKSIZE bytes (or untill EOF if chunksize == -1)
|
||||
* from SRC_FILE to DST_FILE. */
|
||||
extern int copy_file_chunk_fd(int src_fd, int dst_fd, off_t chunksize)
|
||||
{
|
||||
size_t nread, size;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
while (chunksize != 0) {
|
||||
if (chunksize > BUFSIZ) {
|
||||
size = BUFSIZ;
|
||||
} else {
|
||||
size = chunksize;
|
||||
}
|
||||
nread = xread(src_fd, buffer, size);
|
||||
if (nread == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (write (dst_fd, buffer, nread) != nread) {
|
||||
error_msg_and_die ("Short write");
|
||||
}
|
||||
|
||||
if (chunksize != -1) {
|
||||
chunksize -= nread;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
extern const unsigned short data_align(const int src_fd, const unsigned int offset, const unsigned short align_to)
|
||||
{
|
||||
const unsigned short skip_amount = (align_to - (offset % align_to)) % align_to;
|
||||
seek_sub_file(src_fd, skip_amount);
|
||||
|
||||
return(skip_amount);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <utime.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void data_extract_all(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
int dst_fd;
|
||||
int res;
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
|
||||
char *name = xstrdup(file_header->name);
|
||||
make_directory (dirname(name), 0777, FILEUTILS_RECUR);
|
||||
free(name);
|
||||
}
|
||||
|
||||
/* Create the file */
|
||||
switch(file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
#ifdef CONFIG_CPIO
|
||||
if (file_header->link_name) {
|
||||
/* hard link */
|
||||
res = link(file_header->link_name, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
perror_msg("Couldnt create hard link");
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* Regular file */
|
||||
dst_fd = xopen(file_header->name, O_WRONLY | O_CREAT);
|
||||
copy_file_chunk_fd(archive_handle->src_fd, dst_fd, file_header->size);
|
||||
close(dst_fd);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case S_IFDIR:
|
||||
res = mkdir(file_header->name, file_header->mode);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
perror_msg("extract_archive: %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
/* Symlink */
|
||||
res = symlink(file_header->link_name, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
perror_msg("Cannot create symlink from %s to '%s'", file_header->name, file_header->link_name);
|
||||
}
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFIFO:
|
||||
res = mknod(file_header->name, file_header->mode, file_header->device);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
perror_msg("Cannot create node %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
chmod(file_header->name, file_header->mode);
|
||||
chown(file_header->name, file_header->uid, file_header->gid);
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
|
||||
struct utimbuf t;
|
||||
t.actime = t.modtime = file_header->mtime;
|
||||
utime(file_header->name, &t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <utime.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void data_extract_all_prefix(archive_handle_t *archive_handle)
|
||||
{
|
||||
char *name_ptr = archive_handle->file_header->name;
|
||||
|
||||
name_ptr += strspn(name_ptr, "./");
|
||||
if (name_ptr[0] != '\0') {
|
||||
archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 2 + strlen(name_ptr));
|
||||
sprintf(archive_handle->file_header->name, "%s%s", archive_handle->buffer, name_ptr);
|
||||
data_extract_all(archive_handle);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
extern void data_extract_to_buffer(archive_handle_t *archive_handle)
|
||||
{
|
||||
archive_handle->buffer = xmalloc(archive_handle->file_header->size + 1);
|
||||
|
||||
xread_all(archive_handle->src_fd, archive_handle->buffer, archive_handle->file_header->size);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void data_extract_to_stdout(archive_handle_t *archive_handle)
|
||||
{
|
||||
copy_file_chunk_fd(archive_handle->src_fd, fileno(stdout), archive_handle->file_header->size);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
extern void data_skip(archive_handle_t *archive_handle)
|
||||
{
|
||||
seek_sub_file(archive_handle->src_fd, archive_handle->file_header->size);
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
char *deb_extract(const char *package_filename, FILE *out_stream,
|
||||
const int extract_function, const char *prefix, const char *filename)
|
||||
{
|
||||
FILE *deb_stream;
|
||||
FILE *uncompressed_stream = NULL;
|
||||
file_header_t *ar_header = NULL;
|
||||
char **file_list = NULL;
|
||||
char *output_buffer = NULL;
|
||||
char *ared_file = NULL;
|
||||
char ar_magic[8];
|
||||
int gunzip_pid;
|
||||
|
||||
if (filename != NULL) {
|
||||
file_list = xmalloc(sizeof(char *) * 2);
|
||||
file_list[0] = xstrdup(filename);
|
||||
file_list[1] = NULL;
|
||||
}
|
||||
|
||||
if (extract_function & extract_control_tar_gz) {
|
||||
ared_file = xstrdup("control.tar.gz");
|
||||
}
|
||||
else if (extract_function & extract_data_tar_gz) {
|
||||
ared_file = xstrdup("data.tar.gz");
|
||||
}
|
||||
|
||||
/* open the debian package to be worked on */
|
||||
deb_stream = wfopen(package_filename, "r");
|
||||
if (deb_stream == NULL) {
|
||||
return(NULL);
|
||||
}
|
||||
/* set the buffer size */
|
||||
setvbuf(deb_stream, NULL, _IOFBF, 0x8000);
|
||||
|
||||
/* check ar magic */
|
||||
fread(ar_magic, 1, 8, deb_stream);
|
||||
if (strncmp(ar_magic,"!<arch>",7) != 0) {
|
||||
error_msg_and_die("invalid magic");
|
||||
}
|
||||
archive_offset = 8;
|
||||
|
||||
while ((ar_header = get_header_ar(deb_stream)) != NULL) {
|
||||
if (strcmp(ared_file, ar_header->name) == 0) {
|
||||
/* open a stream of decompressed data */
|
||||
uncompressed_stream = gz_open(deb_stream, &gunzip_pid);
|
||||
archive_offset = 0;
|
||||
output_buffer = unarchive(uncompressed_stream, out_stream, get_header_tar, extract_function, prefix, file_list, NULL);
|
||||
}
|
||||
seek_sub_file(deb_stream, ar_header->size);
|
||||
free(ar_header->name);
|
||||
free(ar_header);
|
||||
}
|
||||
gz_close(gunzip_pid);
|
||||
fclose(deb_stream);
|
||||
fclose(uncompressed_stream);
|
||||
free(ared_file);
|
||||
if (filename != NULL) {
|
||||
free(file_list[0]);
|
||||
free(file_list);
|
||||
}
|
||||
return(output_buffer);
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
#include "config.h"
|
||||
#include "libbb.h"
|
||||
|
||||
#ifdef CONFIG_FEATURE_UNCOMPRESS
|
||||
|
||||
/* 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:
|
||||
* Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas)
|
||||
* Jim McKie (decvax!mcvax!jim)
|
||||
* Steve Davies (decvax!vax135!petsd!peora!srd)
|
||||
* Ken Turkowski (decvax!decwrl!turtlevax!ken)
|
||||
* James A. Woods (decvax!ihnp4!ames!jaw)
|
||||
* Joe Orost (decvax!vax135!petsd!joe)
|
||||
* Dave Mack (csu@alembic.acs.com)
|
||||
* Peter Jannesen, Network Communication Systems
|
||||
* (peter@ncs.nl)
|
||||
*
|
||||
* marc@suse.de : a small security fix for a buffer overflow
|
||||
*
|
||||
* [... History snipped ...]
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define IBUFSIZ 2048 /* Defailt input buffer size */
|
||||
#define OBUFSIZ 2048 /* Default output buffer size */
|
||||
|
||||
/* Defines for third byte of header */
|
||||
#define MAGIC_1 (char_type)'\037'/* First byte of compressed file */
|
||||
#define MAGIC_2 (char_type)'\235'/* Second byte of compressed file */
|
||||
#define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */
|
||||
/* Masks 0x20 and 0x40 are free. */
|
||||
/* I think 0x20 should mean that there is */
|
||||
/* a fourth header byte (for expansion). */
|
||||
#define BLOCK_MODE 0x80 /* Block compresssion if table is full and */
|
||||
/* compression rate is dropping flush tables */
|
||||
|
||||
/* the next two codes should not be changed lightly, as they must not */
|
||||
/* lie within the contiguous general code space. */
|
||||
#define FIRST 257 /* first free entry */
|
||||
#define CLEAR 256 /* table clear output code */
|
||||
|
||||
#define INIT_BITS 9 /* initial number of bits/code */
|
||||
|
||||
|
||||
/*
|
||||
* machine variants which require cc -Dmachine: pdp11, z8000, DOS
|
||||
*/
|
||||
#define FAST
|
||||
|
||||
#define HBITS 17 /* 50% occupancy */
|
||||
#define HSIZE (1<<HBITS)
|
||||
#define HMASK (HSIZE-1)
|
||||
#define HPRIME 9941
|
||||
#define BITS 16
|
||||
#undef MAXSEG_64K
|
||||
|
||||
typedef long int code_int;
|
||||
|
||||
typedef long int count_int;
|
||||
typedef long int cmp_code_int;
|
||||
|
||||
typedef unsigned char char_type;
|
||||
|
||||
#define MAXCODE(n) (1L << (n))
|
||||
|
||||
|
||||
|
||||
int block_mode = BLOCK_MODE;/* Block compress mode -C compatible with 2.0*/
|
||||
int maxbits = BITS; /* user settable max # bits/code */
|
||||
int exit_code = -1; /* Exitcode of compress (-1 no file compressed) */
|
||||
|
||||
char_type inbuf[IBUFSIZ+64]; /* Input buffer */
|
||||
char_type outbuf[OBUFSIZ+2048];/* Output buffer */
|
||||
|
||||
|
||||
count_int htab[HSIZE];
|
||||
unsigned short codetab[HSIZE];
|
||||
|
||||
#define htabof(i) htab[i]
|
||||
#define codetabof(i) codetab[i]
|
||||
#define tab_prefixof(i) codetabof(i)
|
||||
#define tab_suffixof(i) ((char_type *)(htab))[i]
|
||||
#define de_stack ((char_type *)&(htab[HSIZE-1]))
|
||||
#define clear_htab() memset(htab, -1, sizeof(htab))
|
||||
#define clear_tab_prefixof() memset(codetab, 0, 256);
|
||||
|
||||
|
||||
/*
|
||||
* Decompress stdin to stdout. This routine adapts to the codes in the
|
||||
* file building the "string" table on-the-fly; requiring no table to
|
||||
* be stored in the compressed file. The tables used herein are shared
|
||||
* with those of the compress() routine. See the definitions above.
|
||||
*/
|
||||
|
||||
extern int uncompress(int fd_in, int fd_out)
|
||||
{
|
||||
char_type *stackp;
|
||||
code_int code;
|
||||
int finchar;
|
||||
code_int oldcode;
|
||||
code_int incode;
|
||||
int inbits;
|
||||
int posbits;
|
||||
int outpos;
|
||||
int insize;
|
||||
int bitmask;
|
||||
code_int free_ent;
|
||||
code_int maxcode;
|
||||
code_int maxmaxcode;
|
||||
int n_bits;
|
||||
int rsize = 0;
|
||||
|
||||
insize = 0;
|
||||
|
||||
inbuf [0] = xread_char(fd_in);
|
||||
|
||||
maxbits = inbuf[0] & BIT_MASK;
|
||||
block_mode = inbuf[0] & BLOCK_MODE;
|
||||
maxmaxcode = MAXCODE(maxbits);
|
||||
|
||||
if (maxbits > BITS)
|
||||
{
|
||||
fprintf(stderr, "compressed with %d bits, can only handle %d bits\n", maxbits, BITS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//fprintf(stderr, "Bits: %d, block_mode: %d\n", maxbits, block_mode );
|
||||
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS)-1;
|
||||
bitmask = (1<<n_bits)-1;
|
||||
oldcode = -1;
|
||||
finchar = 0;
|
||||
outpos = 0;
|
||||
posbits = 0<<3;
|
||||
|
||||
free_ent = ((block_mode) ? FIRST : 256);
|
||||
|
||||
clear_tab_prefixof(); /* As above, initialize the first
|
||||
256 entries in the table. */
|
||||
|
||||
for (code = 255 ; code >= 0 ; --code)
|
||||
tab_suffixof(code) = (char_type)code;
|
||||
|
||||
do
|
||||
{
|
||||
resetbuf: ;
|
||||
{
|
||||
int i;
|
||||
int e;
|
||||
int o;
|
||||
|
||||
e = insize-(o = (posbits>>3));
|
||||
|
||||
for (i = 0 ; i < e ; ++i)
|
||||
inbuf[i] = inbuf[i+o];
|
||||
|
||||
insize = e;
|
||||
posbits = 0;
|
||||
}
|
||||
|
||||
if (insize < (int) sizeof(inbuf)-IBUFSIZ)
|
||||
{
|
||||
xread_all(fd_in, inbuf+insize, IBUFSIZ);
|
||||
insize += rsize;
|
||||
}
|
||||
|
||||
inbits = ((rsize > 0) ? (insize - insize%n_bits)<<3 :
|
||||
(insize<<3)-(n_bits-1));
|
||||
|
||||
while (inbits > posbits)
|
||||
{
|
||||
if (free_ent > maxcode)
|
||||
{
|
||||
posbits = ((posbits-1) + ((n_bits<<3) -
|
||||
(posbits-1+(n_bits<<3))%(n_bits<<3)));
|
||||
|
||||
++n_bits;
|
||||
if (n_bits == maxbits)
|
||||
maxcode = maxmaxcode;
|
||||
else
|
||||
maxcode = MAXCODE(n_bits)-1;
|
||||
|
||||
bitmask = (1<<n_bits)-1;
|
||||
goto resetbuf;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
char_type *p = &inbuf[posbits>>3];
|
||||
code = ((((long)(p[0]))|((long)(p[1])<<8)|((long)(p[2])<<16))>>(posbits&0x7))&bitmask;
|
||||
}
|
||||
posbits += n_bits;
|
||||
|
||||
|
||||
if (oldcode == -1)
|
||||
{
|
||||
outbuf[outpos++] = (char_type)(finchar = (int)(oldcode = code));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code == CLEAR && block_mode)
|
||||
{
|
||||
clear_tab_prefixof();
|
||||
free_ent = FIRST - 1;
|
||||
posbits = ((posbits-1) + ((n_bits<<3) -
|
||||
(posbits-1+(n_bits<<3))%(n_bits<<3)));
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS)-1;
|
||||
bitmask = (1<<n_bits)-1;
|
||||
goto resetbuf;
|
||||
}
|
||||
|
||||
incode = code;
|
||||
stackp = de_stack;
|
||||
|
||||
if (code >= free_ent) /* Special case for KwKwK string. */
|
||||
{
|
||||
if (code > free_ent)
|
||||
{
|
||||
char_type *p;
|
||||
|
||||
posbits -= n_bits;
|
||||
p = &inbuf[posbits>>3];
|
||||
|
||||
fprintf(stderr, "insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)\n", insize, posbits,
|
||||
p[-1],p[0],p[1],p[2],p[3], (posbits&07));
|
||||
fprintf(stderr, "uncompress: corrupt input\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*--stackp = (char_type)finchar;
|
||||
code = oldcode;
|
||||
}
|
||||
|
||||
while ((cmp_code_int)code >= (cmp_code_int)256)
|
||||
{ /* Generate output characters in reverse order */
|
||||
*--stackp = tab_suffixof(code);
|
||||
code = tab_prefixof(code);
|
||||
}
|
||||
|
||||
*--stackp = (char_type)(finchar = tab_suffixof(code));
|
||||
|
||||
/* And put them out in forward order */
|
||||
|
||||
{
|
||||
int i;
|
||||
|
||||
if (outpos+(i = (de_stack-stackp)) >= OBUFSIZ)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (i > OBUFSIZ-outpos) i = OBUFSIZ-outpos;
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
memcpy(outbuf+outpos, stackp, i);
|
||||
outpos += i;
|
||||
}
|
||||
|
||||
if (outpos >= OBUFSIZ)
|
||||
{
|
||||
write(fd_out, outbuf, outpos);
|
||||
outpos = 0;
|
||||
}
|
||||
stackp+= i;
|
||||
}
|
||||
while ((i = (de_stack-stackp)) > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(outbuf+outpos, stackp, i);
|
||||
outpos += i;
|
||||
}
|
||||
}
|
||||
|
||||
if ((code = free_ent) < maxmaxcode) /* Generate the new entry. */
|
||||
{
|
||||
tab_prefixof(code) = (unsigned short)oldcode;
|
||||
tab_suffixof(code) = (char_type)finchar;
|
||||
free_ent = code+1;
|
||||
}
|
||||
|
||||
oldcode = incode; /* Remember previous code. */
|
||||
}
|
||||
|
||||
}
|
||||
while (rsize > 0);
|
||||
|
||||
if (outpos > 0) {
|
||||
write(fd_out, outbuf, outpos);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,14 @@
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
/*
|
||||
* Accept names that are in the accept list
|
||||
*/
|
||||
extern char filter_accept_all(const llist_t *accept_list, const llist_t *reject_list, const char *key)
|
||||
{
|
||||
if (key) {
|
||||
return(EXIT_SUCCESS);
|
||||
} else {
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
* Accept names that are in the accept list
|
||||
*/
|
||||
extern char filter_accept_list(const llist_t *accept_list, const llist_t *reject_list, const char *key)
|
||||
{
|
||||
if (find_list_entry(accept_list, key)) {
|
||||
return(EXIT_SUCCESS);
|
||||
} else {
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
* Accept names that are in the accept list
|
||||
*/
|
||||
extern char filter_accept_reject_list(const llist_t *accept_list, const llist_t *reject_list, const char *key)
|
||||
{
|
||||
const llist_t *accept_entry = find_list_entry(accept_list, key);
|
||||
const llist_t *reject_entry = find_list_entry(reject_list, key);
|
||||
|
||||
/* Fail if an accept list was specified and the key wasnt in there */
|
||||
if (accept_list && (accept_entry == NULL)) {
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* If the key is in a reject list fail */
|
||||
if (reject_entry) {
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Accepted */
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
extern const llist_t *find_list_entry(const llist_t *list, const char *filename)
|
||||
{
|
||||
while (list) {
|
||||
if (fnmatch(list->data, filename, 0) == 0) {
|
||||
return(list);
|
||||
}
|
||||
list = list->link;
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
@@ -17,12 +17,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
file_header_t *get_header_ar(FILE *src_stream)
|
||||
extern char get_header_ar(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *typed;
|
||||
file_header_t *typed = archive_handle->file_header;
|
||||
union {
|
||||
char raw[60];
|
||||
struct {
|
||||
@@ -35,72 +36,87 @@ file_header_t *get_header_ar(FILE *src_stream)
|
||||
char magic[2];
|
||||
} formated;
|
||||
} ar;
|
||||
#ifdef CONFIG_FEATURE_AR_LONG_FILENAMES
|
||||
static char *ar_long_names;
|
||||
static unsigned int ar_long_name_size;
|
||||
#endif
|
||||
|
||||
if (fread(ar.raw, 1, 60, src_stream) != 60) {
|
||||
return(NULL);
|
||||
/* dont use xread as we want to handle the error ourself */
|
||||
if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
|
||||
/* End Of File */
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Some ar entries have a trailing '\n' after the previous data entry */
|
||||
if (ar.raw[0] == '\n') {
|
||||
/* fix up the header, we started reading 1 byte too early */
|
||||
memmove(ar.raw, &ar.raw[1], 59);
|
||||
ar.raw[59] = xread_char(archive_handle->src_fd);
|
||||
archive_handle->offset++;
|
||||
}
|
||||
archive_offset += 60;
|
||||
archive_handle->offset += 60;
|
||||
|
||||
/* align the headers based on the header magic */
|
||||
if ((ar.formated.magic[0] != '`') || (ar.formated.magic[1] != '\n')) {
|
||||
/* some version of ar, have an extra '\n' after each data entry,
|
||||
* this puts the next header out by 1 */
|
||||
if (ar.formated.magic[1] != '`') {
|
||||
error_msg("Invalid magic");
|
||||
return(NULL);
|
||||
}
|
||||
/* read the next char out of what would be the data section,
|
||||
* if its a '\n' then it is a valid header offset by 1*/
|
||||
archive_offset++;
|
||||
if (fgetc(src_stream) != '\n') {
|
||||
error_msg("Invalid magic");
|
||||
return(NULL);
|
||||
}
|
||||
/* fix up the header, we started reading 1 byte too early */
|
||||
/* raw_header[60] wont be '\n' as it should, but it doesnt matter */
|
||||
memmove(ar.raw, &ar.raw[1], 59);
|
||||
error_msg_and_die("Invalid ar header");
|
||||
}
|
||||
|
||||
typed = (file_header_t *) xcalloc(1, sizeof(file_header_t));
|
||||
|
||||
typed->size = (size_t) atoi(ar.formated.size);
|
||||
typed->mode = strtol(ar.formated.mode, NULL, 8);
|
||||
typed->mtime = atoi(ar.formated.date);
|
||||
typed->uid = atoi(ar.formated.uid);
|
||||
typed->gid = atoi(ar.formated.gid);
|
||||
typed->size = atoi(ar.formated.size);
|
||||
|
||||
/* long filenames have '/' as the first character */
|
||||
if (ar.formated.name[0] == '/') {
|
||||
#ifdef CONFIG_FEATURE_AR_LONG_FILENAMES
|
||||
if (ar.formated.name[1] == '/') {
|
||||
/* If the second char is a '/' then this entries data section
|
||||
* stores long filename for multiple entries, they are stored
|
||||
* in static variable long_names for use in future entries */
|
||||
ar_long_names = (char *) xrealloc(ar_long_names, typed->size);
|
||||
fread(ar_long_names, 1, typed->size, src_stream);
|
||||
archive_offset += typed->size;
|
||||
ar_long_name_size = typed->size;
|
||||
ar_long_names = xmalloc(ar_long_name_size);
|
||||
xread_all(archive_handle->src_fd, ar_long_names, ar_long_name_size);
|
||||
archive_handle->offset += ar_long_name_size;
|
||||
/* This ar entries data section only contained filenames for other records
|
||||
* they are stored in the static ar_long_names for future reference */
|
||||
return (get_header_ar(src_stream)); /* Return next header */
|
||||
return (get_header_ar(archive_handle)); /* Return next header */
|
||||
} else if (ar.formated.name[1] == ' ') {
|
||||
/* This is the index of symbols in the file for compilers */
|
||||
seek_sub_file(src_stream, typed->size);
|
||||
return (get_header_ar(src_stream)); /* Return next header */
|
||||
data_skip(archive_handle);
|
||||
return (get_header_ar(archive_handle)); /* Return next header */
|
||||
} else {
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
(saved in variable long_name) that conatains the real filename */
|
||||
if (!ar_long_names) {
|
||||
error_msg("Cannot resolve long file name");
|
||||
return (NULL);
|
||||
const unsigned int long_offset = atoi(&ar.formated.name[1]);
|
||||
if (long_offset >= ar_long_name_size) {
|
||||
error_msg_and_die("Cant resolve long filename");
|
||||
}
|
||||
typed->name = xstrdup(ar_long_names + atoi(&ar.formated.name[1]));
|
||||
typed->name = xstrdup(ar_long_names + long_offset);
|
||||
}
|
||||
#else
|
||||
error_msg_and_die("long filenames not supported");
|
||||
#endif
|
||||
} else {
|
||||
/* short filenames */
|
||||
typed->name = xcalloc(1, 16);
|
||||
strncpy(typed->name, ar.formated.name, 16);
|
||||
typed->name = xstrndup(ar.formated.name, 16);
|
||||
}
|
||||
typed->name[strcspn(typed->name, " /")]='\0';
|
||||
|
||||
/* convert the rest of the now valid char header to its typed struct */
|
||||
parse_mode(ar.formated.mode, &typed->mode);
|
||||
typed->mtime = atoi(ar.formated.date);
|
||||
typed->uid = atoi(ar.formated.uid);
|
||||
typed->gid = atoi(ar.formated.gid);
|
||||
typed->name[strcspn(typed->name, " /")] = '\0';
|
||||
|
||||
if (archive_handle->filter(archive_handle->accept, archive_handle->reject, typed->name) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(typed);
|
||||
if (archive_handle->sub_archive) {
|
||||
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS);
|
||||
} else {
|
||||
archive_handle->action_data(archive_handle);
|
||||
}
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
}
|
||||
|
||||
archive_handle->offset += typed->size + 1;
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
return(typed);
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
struct hardlinks {
|
||||
file_header_t *entry;
|
||||
int inode;
|
||||
struct hardlinks *next;
|
||||
};
|
||||
|
||||
file_header_t *get_header_cpio(FILE *src_stream)
|
||||
{
|
||||
file_header_t *cpio_entry = NULL;
|
||||
char cpio_header[110];
|
||||
int namesize;
|
||||
char dummy[16];
|
||||
int major, minor, nlink, inode;
|
||||
static struct hardlinks *saved_hardlinks = NULL;
|
||||
static int pending_hardlinks = 0;
|
||||
|
||||
if (pending_hardlinks) { /* Deal with any pending hardlinks */
|
||||
struct hardlinks *tmp = saved_hardlinks, *oldtmp = NULL;
|
||||
while (tmp) {
|
||||
if (tmp->entry->link_name) { /* Found a hardlink ready to be extracted */
|
||||
cpio_entry = tmp->entry;
|
||||
if (oldtmp) oldtmp->next = tmp->next; /* Remove item from linked list */
|
||||
else saved_hardlinks = tmp->next;
|
||||
free(tmp);
|
||||
return (cpio_entry);
|
||||
}
|
||||
oldtmp = tmp;
|
||||
tmp = tmp->next;
|
||||
}
|
||||
pending_hardlinks = 0; /* No more pending hardlinks, read next file entry */
|
||||
}
|
||||
|
||||
/* There can be padding before archive header */
|
||||
seek_sub_file(src_stream, (4 - (archive_offset % 4)) % 4);
|
||||
if (fread(cpio_header, 1, 110, src_stream) == 110) {
|
||||
archive_offset += 110;
|
||||
if (strncmp(cpio_header, "07070", 5) != 0) {
|
||||
error_msg("Unsupported format or invalid magic");
|
||||
return(NULL);
|
||||
}
|
||||
switch (cpio_header[5]) {
|
||||
case '2': /* "crc" header format */
|
||||
/* Doesnt do the crc check yet */
|
||||
case '1': /* "newc" header format */
|
||||
cpio_entry = (file_header_t *) xcalloc(1, sizeof(file_header_t));
|
||||
sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c",
|
||||
dummy, &inode, (unsigned int*)&cpio_entry->mode,
|
||||
(unsigned int*)&cpio_entry->uid, (unsigned int*)&cpio_entry->gid,
|
||||
&nlink, &cpio_entry->mtime, &cpio_entry->size,
|
||||
dummy, &major, &minor, &namesize, dummy);
|
||||
|
||||
cpio_entry->name = (char *) xcalloc(1, namesize);
|
||||
fread(cpio_entry->name, 1, namesize, src_stream); /* Read in filename */
|
||||
archive_offset += namesize;
|
||||
/* Skip padding before file contents */
|
||||
seek_sub_file(src_stream, (4 - (archive_offset % 4)) % 4);
|
||||
if (strcmp(cpio_entry->name, "TRAILER!!!") == 0) {
|
||||
printf("%d blocks\n", (int) (archive_offset % 512 ? (archive_offset / 512) + 1 : archive_offset / 512)); /* Always round up */
|
||||
if (saved_hardlinks) { /* Bummer - we still have unresolved hardlinks */
|
||||
struct hardlinks *tmp = saved_hardlinks, *oldtmp = NULL;
|
||||
while (tmp) {
|
||||
error_msg("%s not created: cannot resolve hardlink", tmp->entry->name);
|
||||
oldtmp = tmp;
|
||||
tmp = tmp->next;
|
||||
free (oldtmp->entry->name);
|
||||
free (oldtmp->entry);
|
||||
free (oldtmp);
|
||||
}
|
||||
saved_hardlinks = NULL;
|
||||
pending_hardlinks = 0;
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (S_ISLNK(cpio_entry->mode)) {
|
||||
cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1);
|
||||
fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream);
|
||||
archive_offset += cpio_entry->size;
|
||||
cpio_entry->size = 0; /* Stop possiable seeks in future */
|
||||
}
|
||||
if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) {
|
||||
if (cpio_entry->size == 0) { /* Put file on a linked list for later */
|
||||
struct hardlinks *new = xmalloc(sizeof(struct hardlinks));
|
||||
new->next = saved_hardlinks;
|
||||
new->inode = inode;
|
||||
new->entry = cpio_entry;
|
||||
saved_hardlinks = new;
|
||||
return(get_header_cpio(src_stream)); /* Recurse to next file */
|
||||
} else { /* Found the file with data in */
|
||||
struct hardlinks *tmp = saved_hardlinks;
|
||||
pending_hardlinks = 1;
|
||||
while (tmp) {
|
||||
if (tmp->inode == inode) {
|
||||
tmp->entry->link_name = xstrdup(cpio_entry->name);
|
||||
nlink--;
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
if (nlink > 1) error_msg("error resolving hardlink: did you create the archive with GNU cpio 2.0-2.2?");
|
||||
}
|
||||
}
|
||||
cpio_entry->device = (major << 8) | minor;
|
||||
break;
|
||||
default:
|
||||
error_msg("Unsupported format");
|
||||
return(NULL);
|
||||
}
|
||||
if (ferror(src_stream) || feof(src_stream)) {
|
||||
perror_msg("Stream error");
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
return(cpio_entry);
|
||||
}
|
||||
@@ -20,52 +20,57 @@
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
file_header_t *get_header_tar(FILE *tar_stream)
|
||||
extern char get_header_tar(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
union {
|
||||
unsigned char raw[512];
|
||||
struct {
|
||||
char name[100]; /* 0-99 */
|
||||
char mode[8]; /* 100-107 */
|
||||
char uid[8]; /* 108-115 */
|
||||
char gid[8]; /* 116-123 */
|
||||
char size[12]; /* 124-135 */
|
||||
char mtime[12]; /* 136-147 */
|
||||
char chksum[8]; /* 148-155 */
|
||||
char typeflag; /* 156-156 */
|
||||
char name[100]; /* 0-99 */
|
||||
char mode[8]; /* 100-107 */
|
||||
char uid[8]; /* 108-115 */
|
||||
char gid[8]; /* 116-123 */
|
||||
char size[12]; /* 124-135 */
|
||||
char mtime[12]; /* 136-147 */
|
||||
char chksum[8]; /* 148-155 */
|
||||
char typeflag; /* 156-156 */
|
||||
char linkname[100]; /* 157-256 */
|
||||
char magic[6]; /* 257-262 */
|
||||
char magic[6]; /* 257-262 */
|
||||
char version[2]; /* 263-264 */
|
||||
char uname[32]; /* 265-296 */
|
||||
char gname[32]; /* 297-328 */
|
||||
char uname[32]; /* 265-296 */
|
||||
char gname[32]; /* 297-328 */
|
||||
char devmajor[8]; /* 329-336 */
|
||||
char devminor[8]; /* 337-344 */
|
||||
char prefix[155]; /* 345-499 */
|
||||
char padding[12]; /* 500-512 */
|
||||
} formated;
|
||||
} tar;
|
||||
file_header_t *tar_entry = NULL;
|
||||
long sum = 0;
|
||||
long i;
|
||||
char *tmp;
|
||||
|
||||
if (archive_offset % 512 != 0) {
|
||||
seek_sub_file(tar_stream, 512 - (archive_offset % 512));
|
||||
/* Align header */
|
||||
archive_handle->offset += data_align(archive_handle->src_fd, archive_handle->offset, 512);
|
||||
|
||||
if (xread_all_eof(archive_handle->src_fd, tar.raw, 512) == 0) {
|
||||
/* End of file */
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
archive_handle->offset += 512;
|
||||
|
||||
/* If there is no filename its an empty header */
|
||||
if (tar.formated.name[0] == 0) {
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (fread(tar.raw, 1, 512, tar_stream) != 512) {
|
||||
/* Unfortunatly its common for tar files to have all sorts of
|
||||
* trailing garbage, fail silently */
|
||||
// error_msg("Couldnt read header");
|
||||
return(NULL);
|
||||
}
|
||||
archive_offset += 512;
|
||||
|
||||
/* Check header has valid magic, unfortunately some tar files
|
||||
* have empty (0'ed) tar entries at the end, which will
|
||||
* cause this to fail, so fail silently for now
|
||||
/* Check header has valid magic, "ustar" is for the proper tar
|
||||
* 0's are for the old tar format
|
||||
*/
|
||||
if (strncmp(tar.formated.magic, "ustar", 5) != 0) {
|
||||
return(NULL);
|
||||
#ifdef CONFIG_FEATURE_TAR_OLD_FORMAT
|
||||
if (strncmp(tar.formated.magic, "\0\0\0\0\0", 5) != 0)
|
||||
#endif
|
||||
error_msg_and_die("Invalid tar magic");
|
||||
}
|
||||
|
||||
/* Do checksum on headers */
|
||||
@@ -78,22 +83,94 @@ file_header_t *get_header_tar(FILE *tar_stream)
|
||||
}
|
||||
if (sum != strtol(tar.formated.chksum, NULL, 8)) {
|
||||
error_msg("Invalid tar header checksum");
|
||||
return(NULL);
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* convert to type'ed variables */
|
||||
tar_entry = xcalloc(1, sizeof(file_header_t));
|
||||
tar_entry->name = xstrdup(tar.formated.name);
|
||||
if (tar.formated.prefix[0] == 0) {
|
||||
file_header->name = strdup(tar.formated.name);
|
||||
} else {
|
||||
file_header->name = concat_path_file(tar.formated.prefix, tar.formated.name);
|
||||
}
|
||||
tmp = last_char_is(archive_handle->file_header->name, '/');
|
||||
if (tmp) {
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
parse_mode(tar.formated.mode, &tar_entry->mode);
|
||||
tar_entry->uid = strtol(tar.formated.uid, NULL, 8);
|
||||
tar_entry->gid = strtol(tar.formated.gid, NULL, 8);
|
||||
tar_entry->size = strtol(tar.formated.size, NULL, 8);
|
||||
tar_entry->mtime = strtol(tar.formated.mtime, NULL, 8);
|
||||
tar_entry->link_name = strlen(tar.formated.linkname) ?
|
||||
file_header->mode = strtol(tar.formated.mode, NULL, 8);
|
||||
file_header->uid = strtol(tar.formated.uid, NULL, 8);
|
||||
file_header->gid = strtol(tar.formated.gid, NULL, 8);
|
||||
file_header->size = strtol(tar.formated.size, NULL, 8);
|
||||
file_header->mtime = strtol(tar.formated.mtime, NULL, 8);
|
||||
file_header->link_name = (tar.formated.linkname[0] != '\0') ?
|
||||
xstrdup(tar.formated.linkname) : NULL;
|
||||
tar_entry->device = (strtol(tar.formated.devmajor, NULL, 8) << 8) +
|
||||
strtol(tar.formated.devminor, NULL, 8);
|
||||
file_header->device = (dev_t) ((strtol(tar.formated.devmajor, NULL, 8) << 8) +
|
||||
strtol(tar.formated.devminor, NULL, 8));
|
||||
|
||||
#if defined CONFIG_FEATURE_TAR_OLD_FORMAT || defined CONFIG_FEATURE_GNUTAR_LONG_FILENAME
|
||||
/* Fix mode, used by the old format */
|
||||
switch (tar.formated.typeflag) {
|
||||
# ifdef CONFIG_FEATURE_TAR_OLD_FORMAT
|
||||
case 0:
|
||||
file_header->mode |= S_IFREG;
|
||||
break;
|
||||
case 1:
|
||||
error_msg("Internal hard link not supported");
|
||||
break;
|
||||
case 2:
|
||||
file_header->mode |= S_IFLNK;
|
||||
break;
|
||||
case 3:
|
||||
file_header->mode |= S_IFCHR;
|
||||
break;
|
||||
case 4:
|
||||
file_header->mode |= S_IFBLK;
|
||||
break;
|
||||
case 5:
|
||||
file_header->mode |= S_IFDIR;
|
||||
break;
|
||||
case 6:
|
||||
file_header->mode |= S_IFIFO;
|
||||
break;
|
||||
# endif
|
||||
# ifdef CONFIG_FEATURE_GNUTAR_LONG_FILENAME
|
||||
case 'L': {
|
||||
char *longname;
|
||||
|
||||
longname = xmalloc(file_header->size + 1);
|
||||
xread_all(archive_handle->src_fd, longname, file_header->size);
|
||||
longname[file_header->size] = '\0';
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
get_header_tar(archive_handle);
|
||||
file_header->name = longname;
|
||||
break;
|
||||
}
|
||||
case 'K': {
|
||||
char *linkname;
|
||||
|
||||
linkname = xmalloc(file_header->size + 1);
|
||||
xread_all(archive_handle->src_fd, linkname, file_header->size);
|
||||
linkname[file_header->size] = '\0';
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
get_header_tar(archive_handle);
|
||||
file_header->name = linkname;
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
if (archive_handle->filter(archive_handle->accept, archive_handle->reject, archive_handle->file_header->name) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(archive_handle->file_header);
|
||||
archive_handle->flags |= ARCHIVE_EXTRACT_QUIET;
|
||||
archive_handle->action_data(archive_handle);
|
||||
archive_handle->passed = add_to_list(archive_handle->passed, archive_handle->file_header->name);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
}
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
return(tar_entry);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
{
|
||||
int fd_pipe[2];
|
||||
int pid;
|
||||
unsigned char magic[2];
|
||||
|
||||
xread_all(archive_handle->src_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
error_msg_and_die("Invalid gzip magic");
|
||||
}
|
||||
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
|
||||
if (pipe(fd_pipe) != 0) {
|
||||
error_msg_and_die("Can't create pipe");
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
error_msg_and_die("Fork failed\n");
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
/* child process */
|
||||
close(fd_pipe[0]); /* We don't wan't to read from the pipe */
|
||||
inflate(archive_handle->src_fd, fd_pipe[1]);
|
||||
check_trailer_gzip(archive_handle->src_fd);
|
||||
close(fd_pipe[1]); /* Send EOF */
|
||||
exit(0);
|
||||
/* notreached */
|
||||
}
|
||||
/* parent process */
|
||||
close(fd_pipe[1]); /* Don't want to write down the pipe */
|
||||
close(archive_handle->src_fd);
|
||||
|
||||
archive_handle->src_fd = fd_pipe[0];
|
||||
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS);
|
||||
|
||||
if (kill(pid, SIGTERM) == -1) {
|
||||
error_msg_and_die("Couldnt kill gunzip process");
|
||||
}
|
||||
|
||||
/* I dont think this is needed */
|
||||
#if 0
|
||||
if (waitpid(pid, NULL, 0) == -1) {
|
||||
error_msg("Couldnt wait ?");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void header_list(const file_header_t *file_header)
|
||||
{
|
||||
puts(file_header->name);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void header_skip(const file_header_t *file_header)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void header_verbose_list(const file_header_t *file_header)
|
||||
{
|
||||
struct tm *mtime = localtime(&file_header->mtime);
|
||||
|
||||
printf("%s %d/%d%10u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
mode_string(file_header->mode),
|
||||
file_header->uid,
|
||||
file_header->gid,
|
||||
(unsigned int) file_header->size,
|
||||
1900 + mtime->tm_year,
|
||||
1 + mtime->tm_mon,
|
||||
mtime->tm_mday,
|
||||
mtime->tm_hour,
|
||||
mtime->tm_min,
|
||||
mtime->tm_sec,
|
||||
file_header->name);
|
||||
|
||||
if (file_header->link_name) {
|
||||
printf(" -> %s", file_header->link_name);
|
||||
}
|
||||
/* putchar isnt used anywhere else i dont think */
|
||||
puts("");
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <string.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
archive_handle_t *init_handle(void)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
|
||||
/* Initialise default values */
|
||||
archive_handle = xmalloc(sizeof(archive_handle_t));
|
||||
memset(archive_handle, 0, sizeof(archive_handle_t));
|
||||
archive_handle->file_header = xmalloc(sizeof(file_header_t));
|
||||
archive_handle->action_header = header_skip;
|
||||
archive_handle->action_data = data_skip;
|
||||
archive_handle->filter = filter_accept_all;
|
||||
|
||||
return(archive_handle);
|
||||
}
|
||||
@@ -14,22 +14,19 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
off_t archive_offset;
|
||||
|
||||
void seek_sub_file(FILE *src_stream, const int count)
|
||||
extern void seek_sub_file(const int src_fd, const unsigned int amount)
|
||||
{
|
||||
/* Try to fseek as faster */
|
||||
archive_offset += count;
|
||||
if (fseek(src_stream, count, SEEK_CUR) != 0 && errno == ESPIPE) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
fgetc(src_stream);
|
||||
if ((lseek(src_fd, amount, SEEK_CUR) == -1) && (errno == ESPIPE)) {
|
||||
unsigned int i;
|
||||
for (i = 0; i < amount; i++) {
|
||||
xread_char(src_fd);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1,241 +0,0 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fnmatch.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <utime.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
/* Extract the data postioned at src_stream to either filesystem, stdout or
|
||||
* buffer depending on the value of 'function' which is defined in libbb.h
|
||||
*
|
||||
* prefix doesnt have to be just a directory, it may prefix the filename as well.
|
||||
*
|
||||
* e.g. '/var/lib/dpkg/info/dpkg.' will extract all files to the base bath
|
||||
* '/var/lib/dpkg/info/' and all files/dirs created in that dir will have
|
||||
* 'dpkg.' as their prefix
|
||||
*
|
||||
* For this reason if prefix does point to a dir then it must end with a
|
||||
* trailing '/' or else the last dir will be assumed to be the file prefix
|
||||
*/
|
||||
char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *file_entry,
|
||||
const int function, const char *prefix)
|
||||
{
|
||||
FILE *dst_stream = NULL;
|
||||
char *full_name = NULL;
|
||||
char *buffer = NULL;
|
||||
struct utimbuf t;
|
||||
|
||||
/* prefix doesnt have to be a proper path it may prepend
|
||||
* the filename as well */
|
||||
if (prefix != NULL) {
|
||||
/* strip leading '/' in filename to extract as prefix may not be dir */
|
||||
/* Cant use concat_path_file here as prefix might not be a directory */
|
||||
char *path = file_entry->name;
|
||||
if (strncmp("./", path, 2) == 0) {
|
||||
path += 2;
|
||||
if (strlen(path) == 0) {
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
full_name = xmalloc(strlen(prefix) + strlen(path) + 1);
|
||||
strcpy(full_name, prefix);
|
||||
strcat(full_name, path);
|
||||
} else {
|
||||
full_name = file_entry->name;
|
||||
}
|
||||
if (function & extract_to_stdout) {
|
||||
if (S_ISREG(file_entry->mode)) {
|
||||
copy_file_chunk(src_stream, out_stream, file_entry->size);
|
||||
archive_offset += file_entry->size;
|
||||
}
|
||||
}
|
||||
else if (function & extract_one_to_buffer) {
|
||||
if (S_ISREG(file_entry->mode)) {
|
||||
buffer = (char *) xmalloc(file_entry->size + 1);
|
||||
fread(buffer, 1, file_entry->size, src_stream);
|
||||
buffer[file_entry->size] = '\0';
|
||||
archive_offset += file_entry->size;
|
||||
return(buffer);
|
||||
}
|
||||
}
|
||||
else if (function & extract_all_to_fs) {
|
||||
struct stat oldfile;
|
||||
int stat_res;
|
||||
stat_res = lstat (full_name, &oldfile);
|
||||
if (stat_res == 0) { /* The file already exists */
|
||||
if ((function & extract_unconditional) || (oldfile.st_mtime < file_entry->mtime)) {
|
||||
if (!S_ISDIR(oldfile.st_mode)) {
|
||||
unlink(full_name); /* Directories might not be empty etc */
|
||||
}
|
||||
} else {
|
||||
if ((function & extract_quiet) != extract_quiet) {
|
||||
error_msg("%s not created: newer or same age file exists", file_entry->name);
|
||||
}
|
||||
seek_sub_file(src_stream, file_entry->size);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */
|
||||
char *buf, *parent;
|
||||
buf = xstrdup(full_name);
|
||||
parent = dirname(buf);
|
||||
if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) {
|
||||
if ((function & extract_quiet) != extract_quiet) {
|
||||
error_msg("couldn't create leading directories");
|
||||
}
|
||||
}
|
||||
free (buf);
|
||||
}
|
||||
switch(file_entry->mode & S_IFMT) {
|
||||
case S_IFREG:
|
||||
if (file_entry->link_name) { /* Found a cpio hard link */
|
||||
if (link(file_entry->link_name, full_name) != 0) {
|
||||
if ((function & extract_quiet) != extract_quiet) {
|
||||
perror_msg("Cannot link from %s to '%s'",
|
||||
file_entry->name, file_entry->link_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((dst_stream = wfopen(full_name, "w")) == NULL) {
|
||||
seek_sub_file(src_stream, file_entry->size);
|
||||
return NULL;
|
||||
}
|
||||
archive_offset += file_entry->size;
|
||||
copy_file_chunk(src_stream, dst_stream, file_entry->size);
|
||||
fclose(dst_stream);
|
||||
}
|
||||
break;
|
||||
case S_IFDIR:
|
||||
if (stat_res != 0) {
|
||||
if (mkdir(full_name, file_entry->mode) < 0) {
|
||||
if ((function & extract_quiet) != extract_quiet) {
|
||||
perror_msg("extract_archive: %s", full_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
if (symlink(file_entry->link_name, full_name) < 0) {
|
||||
if ((function & extract_quiet) != extract_quiet) {
|
||||
perror_msg("Cannot create symlink from %s to '%s'", file_entry->name, file_entry->link_name);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFIFO:
|
||||
if (mknod(full_name, file_entry->mode, file_entry->device) == -1) {
|
||||
if ((function & extract_quiet) != extract_quiet) {
|
||||
perror_msg("Cannot create node %s", file_entry->name);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Changing a symlink's properties normally changes the properties of the
|
||||
* file pointed to, so dont try and change the date or mode, lchown does
|
||||
* does the right thing, but isnt available in older versions of libc */
|
||||
if (S_ISLNK(file_entry->mode)) {
|
||||
#if (__GLIBC__ > 2) && (__GLIBC_MINOR__ > 1)
|
||||
lchown(full_name, file_entry->uid, file_entry->gid);
|
||||
#endif
|
||||
} else {
|
||||
if (function & extract_preserve_date) {
|
||||
t.actime = file_entry->mtime;
|
||||
t.modtime = file_entry->mtime;
|
||||
utime(full_name, &t);
|
||||
}
|
||||
chmod(full_name, file_entry->mode);
|
||||
chown(full_name, file_entry->uid, file_entry->gid);
|
||||
}
|
||||
} else {
|
||||
/* If we arent extracting data we have to skip it,
|
||||
* if data size is 0 then then just do it anyway
|
||||
* (saves testing for it) */
|
||||
seek_sub_file(src_stream, file_entry->size);
|
||||
}
|
||||
|
||||
/* extract_list and extract_verbose_list can be used in conjunction
|
||||
* with one of the above four extraction functions, so do this seperately */
|
||||
if (function & extract_verbose_list) {
|
||||
fprintf(out_stream, "%s %d/%d %8d %s ", mode_string(file_entry->mode),
|
||||
file_entry->uid, file_entry->gid,
|
||||
(int) file_entry->size, time_string(file_entry->mtime));
|
||||
}
|
||||
if ((function & extract_list) || (function & extract_verbose_list)){
|
||||
/* fputs doesnt add a trailing \n, so use fprintf */
|
||||
fprintf(out_stream, "%s\n", full_name);
|
||||
}
|
||||
|
||||
free(full_name);
|
||||
|
||||
return(NULL); /* Maybe we should say if failed */
|
||||
}
|
||||
|
||||
char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *),
|
||||
const int extract_function, const char *prefix, char **include_name, char **exclude_name)
|
||||
{
|
||||
file_header_t *file_entry;
|
||||
int extract_flag = TRUE;
|
||||
int i;
|
||||
char *buffer = NULL;
|
||||
|
||||
archive_offset = 0;
|
||||
while ((file_entry = get_headers(src_stream)) != NULL) {
|
||||
|
||||
if (include_name != NULL) {
|
||||
extract_flag = FALSE;
|
||||
for(i = 0; include_name[i] != 0; i++) {
|
||||
if (fnmatch(include_name[i], file_entry->name, FNM_LEADING_DIR) == 0) {
|
||||
extract_flag = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
extract_flag = TRUE;
|
||||
}
|
||||
|
||||
/* If the file entry is in the exclude list dont extract it */
|
||||
if (exclude_name != NULL) {
|
||||
for(i = 0; exclude_name[i] != 0; i++) {
|
||||
if (fnmatch(exclude_name[i], file_entry->name, FNM_LEADING_DIR) == 0) {
|
||||
extract_flag = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (extract_flag == TRUE) {
|
||||
buffer = extract_archive(src_stream, out_stream, file_entry, extract_function, prefix);
|
||||
} else {
|
||||
/* seek past the data entry */
|
||||
seek_sub_file(src_stream, file_entry->size);
|
||||
}
|
||||
free(file_entry->name);
|
||||
free(file_entry->link_name);
|
||||
free(file_entry);
|
||||
}
|
||||
return(buffer);
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
#include "config.h"
|
||||
#include "libbb.h"
|
||||
|
||||
#ifdef CONFIG_FEATURE_UNCOMPRESS
|
||||
|
||||
/* 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:
|
||||
* Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas)
|
||||
* Jim McKie (decvax!mcvax!jim)
|
||||
* Steve Davies (decvax!vax135!petsd!peora!srd)
|
||||
* Ken Turkowski (decvax!decwrl!turtlevax!ken)
|
||||
* James A. Woods (decvax!ihnp4!ames!jaw)
|
||||
* Joe Orost (decvax!vax135!petsd!joe)
|
||||
* Dave Mack (csu@alembic.acs.com)
|
||||
* Peter Jannesen, Network Communication Systems
|
||||
* (peter@ncs.nl)
|
||||
*
|
||||
* marc@suse.de : a small security fix for a buffer overflow
|
||||
*
|
||||
* [... History snipped ...]
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define IBUFSIZ 2048 /* Defailt input buffer size */
|
||||
#define OBUFSIZ 2048 /* Default output buffer size */
|
||||
|
||||
/* Defines for third byte of header */
|
||||
#define MAGIC_1 (char_type)'\037'/* First byte of compressed file */
|
||||
#define MAGIC_2 (char_type)'\235'/* Second byte of compressed file */
|
||||
#define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */
|
||||
/* Masks 0x20 and 0x40 are free. */
|
||||
/* I think 0x20 should mean that there is */
|
||||
/* a fourth header byte (for expansion). */
|
||||
#define BLOCK_MODE 0x80 /* Block compresssion if table is full and */
|
||||
/* compression rate is dropping flush tables */
|
||||
|
||||
/* the next two codes should not be changed lightly, as they must not */
|
||||
/* lie within the contiguous general code space. */
|
||||
#define FIRST 257 /* first free entry */
|
||||
#define CLEAR 256 /* table clear output code */
|
||||
|
||||
#define INIT_BITS 9 /* initial number of bits/code */
|
||||
|
||||
|
||||
/*
|
||||
* machine variants which require cc -Dmachine: pdp11, z8000, DOS
|
||||
*/
|
||||
#define FAST
|
||||
|
||||
#define HBITS 17 /* 50% occupancy */
|
||||
#define HSIZE (1<<HBITS)
|
||||
#define HMASK (HSIZE-1)
|
||||
#define HPRIME 9941
|
||||
#define BITS 16
|
||||
#undef MAXSEG_64K
|
||||
|
||||
typedef long int code_int;
|
||||
|
||||
typedef long int count_int;
|
||||
typedef long int cmp_code_int;
|
||||
|
||||
typedef unsigned char char_type;
|
||||
|
||||
#define MAXCODE(n) (1L << (n))
|
||||
|
||||
|
||||
|
||||
int block_mode = BLOCK_MODE;/* Block compress mode -C compatible with 2.0*/
|
||||
int maxbits = BITS; /* user settable max # bits/code */
|
||||
int exit_code = -1; /* Exitcode of compress (-1 no file compressed) */
|
||||
|
||||
char_type inbuf[IBUFSIZ+64]; /* Input buffer */
|
||||
char_type outbuf[OBUFSIZ+2048];/* Output buffer */
|
||||
|
||||
|
||||
count_int htab[HSIZE];
|
||||
unsigned short codetab[HSIZE];
|
||||
|
||||
#define htabof(i) htab[i]
|
||||
#define codetabof(i) codetab[i]
|
||||
#define tab_prefixof(i) codetabof(i)
|
||||
#define tab_suffixof(i) ((char_type *)(htab))[i]
|
||||
#define de_stack ((char_type *)&(htab[HSIZE-1]))
|
||||
#define clear_htab() memset(htab, -1, sizeof(htab))
|
||||
#define clear_tab_prefixof() memset(codetab, 0, 256);
|
||||
|
||||
|
||||
/*
|
||||
* Decompress stdin to stdout. This routine adapts to the codes in the
|
||||
* file building the "string" table on-the-fly; requiring no table to
|
||||
* be stored in the compressed file. The tables used herein are shared
|
||||
* with those of the compress() routine. See the definitions above.
|
||||
*/
|
||||
|
||||
extern int uncompress(int fd_in, int fd_out)
|
||||
{
|
||||
char_type *stackp;
|
||||
code_int code;
|
||||
int finchar;
|
||||
code_int oldcode;
|
||||
code_int incode;
|
||||
int inbits;
|
||||
int posbits;
|
||||
int outpos;
|
||||
int insize;
|
||||
int bitmask;
|
||||
code_int free_ent;
|
||||
code_int maxcode;
|
||||
code_int maxmaxcode;
|
||||
int n_bits;
|
||||
int rsize = 0;
|
||||
|
||||
insize = 0;
|
||||
|
||||
inbuf [0] = xread_char(fd_in);
|
||||
|
||||
maxbits = inbuf[0] & BIT_MASK;
|
||||
block_mode = inbuf[0] & BLOCK_MODE;
|
||||
maxmaxcode = MAXCODE(maxbits);
|
||||
|
||||
if (maxbits > BITS)
|
||||
{
|
||||
fprintf(stderr, "compressed with %d bits, can only handle %d bits\n", maxbits, BITS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//fprintf(stderr, "Bits: %d, block_mode: %d\n", maxbits, block_mode );
|
||||
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS)-1;
|
||||
bitmask = (1<<n_bits)-1;
|
||||
oldcode = -1;
|
||||
finchar = 0;
|
||||
outpos = 0;
|
||||
posbits = 0<<3;
|
||||
|
||||
free_ent = ((block_mode) ? FIRST : 256);
|
||||
|
||||
clear_tab_prefixof(); /* As above, initialize the first
|
||||
256 entries in the table. */
|
||||
|
||||
for (code = 255 ; code >= 0 ; --code)
|
||||
tab_suffixof(code) = (char_type)code;
|
||||
|
||||
do
|
||||
{
|
||||
resetbuf: ;
|
||||
{
|
||||
int i;
|
||||
int e;
|
||||
int o;
|
||||
|
||||
e = insize-(o = (posbits>>3));
|
||||
|
||||
for (i = 0 ; i < e ; ++i)
|
||||
inbuf[i] = inbuf[i+o];
|
||||
|
||||
insize = e;
|
||||
posbits = 0;
|
||||
}
|
||||
|
||||
if (insize < (int) sizeof(inbuf)-IBUFSIZ)
|
||||
{
|
||||
xread_all(fd_in, inbuf+insize, IBUFSIZ);
|
||||
insize += rsize;
|
||||
}
|
||||
|
||||
inbits = ((rsize > 0) ? (insize - insize%n_bits)<<3 :
|
||||
(insize<<3)-(n_bits-1));
|
||||
|
||||
while (inbits > posbits)
|
||||
{
|
||||
if (free_ent > maxcode)
|
||||
{
|
||||
posbits = ((posbits-1) + ((n_bits<<3) -
|
||||
(posbits-1+(n_bits<<3))%(n_bits<<3)));
|
||||
|
||||
++n_bits;
|
||||
if (n_bits == maxbits)
|
||||
maxcode = maxmaxcode;
|
||||
else
|
||||
maxcode = MAXCODE(n_bits)-1;
|
||||
|
||||
bitmask = (1<<n_bits)-1;
|
||||
goto resetbuf;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
char_type *p = &inbuf[posbits>>3];
|
||||
code = ((((long)(p[0]))|((long)(p[1])<<8)|((long)(p[2])<<16))>>(posbits&0x7))&bitmask;
|
||||
}
|
||||
posbits += n_bits;
|
||||
|
||||
|
||||
if (oldcode == -1)
|
||||
{
|
||||
outbuf[outpos++] = (char_type)(finchar = (int)(oldcode = code));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code == CLEAR && block_mode)
|
||||
{
|
||||
clear_tab_prefixof();
|
||||
free_ent = FIRST - 1;
|
||||
posbits = ((posbits-1) + ((n_bits<<3) -
|
||||
(posbits-1+(n_bits<<3))%(n_bits<<3)));
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS)-1;
|
||||
bitmask = (1<<n_bits)-1;
|
||||
goto resetbuf;
|
||||
}
|
||||
|
||||
incode = code;
|
||||
stackp = de_stack;
|
||||
|
||||
if (code >= free_ent) /* Special case for KwKwK string. */
|
||||
{
|
||||
if (code > free_ent)
|
||||
{
|
||||
char_type *p;
|
||||
|
||||
posbits -= n_bits;
|
||||
p = &inbuf[posbits>>3];
|
||||
|
||||
fprintf(stderr, "insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)\n", insize, posbits,
|
||||
p[-1],p[0],p[1],p[2],p[3], (posbits&07));
|
||||
fprintf(stderr, "uncompress: corrupt input\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*--stackp = (char_type)finchar;
|
||||
code = oldcode;
|
||||
}
|
||||
|
||||
while ((cmp_code_int)code >= (cmp_code_int)256)
|
||||
{ /* Generate output characters in reverse order */
|
||||
*--stackp = tab_suffixof(code);
|
||||
code = tab_prefixof(code);
|
||||
}
|
||||
|
||||
*--stackp = (char_type)(finchar = tab_suffixof(code));
|
||||
|
||||
/* And put them out in forward order */
|
||||
|
||||
{
|
||||
int i;
|
||||
|
||||
if (outpos+(i = (de_stack-stackp)) >= OBUFSIZ)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (i > OBUFSIZ-outpos) i = OBUFSIZ-outpos;
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
memcpy(outbuf+outpos, stackp, i);
|
||||
outpos += i;
|
||||
}
|
||||
|
||||
if (outpos >= OBUFSIZ)
|
||||
{
|
||||
write(fd_out, outbuf, outpos);
|
||||
outpos = 0;
|
||||
}
|
||||
stackp+= i;
|
||||
}
|
||||
while ((i = (de_stack-stackp)) > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(outbuf+outpos, stackp, i);
|
||||
outpos += i;
|
||||
}
|
||||
}
|
||||
|
||||
if ((code = free_ent) < maxmaxcode) /* Generate the new entry. */
|
||||
{
|
||||
tab_prefixof(code) = (unsigned short)oldcode;
|
||||
tab_suffixof(code) = (char_type)finchar;
|
||||
free_ent = code+1;
|
||||
}
|
||||
|
||||
oldcode = incode; /* Remember previous code. */
|
||||
}
|
||||
|
||||
}
|
||||
while (rsize > 0);
|
||||
|
||||
if (outpos > 0) {
|
||||
write(fd_out, outbuf, outpos);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
extern void unpack_ar_archive(archive_handle_t *ar_archive)
|
||||
{
|
||||
char magic[7];
|
||||
|
||||
xread_all(ar_archive->src_fd, magic, 7);
|
||||
if (strncmp(magic, "!<arch>", 7) != 0) {
|
||||
error_msg_and_die("Invalid ar magic");
|
||||
}
|
||||
ar_archive->offset += 7;
|
||||
|
||||
while (get_header_ar(ar_archive) == EXIT_SUCCESS);
|
||||
}
|
||||
+513
-635
File diff suppressed because it is too large.
Load diff
+40
-23
@@ -18,10 +18,13 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h> /* For ntohl & htonl function */
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define RPM_MAGIC "\355\253\356\333"
|
||||
#define RPM_HEADER_MAGIC "\216\255\350"
|
||||
@@ -45,46 +48,60 @@ struct rpm_header {
|
||||
u_int32_t size; /* Size of store (4 bytes) */
|
||||
};
|
||||
|
||||
void skip_header(FILE *rpmfile)
|
||||
void skip_header(int rpm_fd)
|
||||
{
|
||||
struct rpm_header header;
|
||||
|
||||
fread(&header, sizeof(struct rpm_header), 1, rpmfile);
|
||||
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) error_msg_and_die("Invalid RPM header magic"); /* Invalid magic */
|
||||
if (header.version != 1) error_msg_and_die("Unsupported RPM header version"); /* This program only supports v1 headers */
|
||||
xread_all(rpm_fd, &header, sizeof(struct rpm_header));
|
||||
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) {
|
||||
error_msg_and_die("Invalid RPM header magic"); /* Invalid magic */
|
||||
}
|
||||
if (header.version != 1) {
|
||||
error_msg_and_die("Unsupported RPM header version"); /* This program only supports v1 headers */
|
||||
}
|
||||
header.entries = ntohl(header.entries);
|
||||
header.size = ntohl(header.size);
|
||||
fseek (rpmfile, 16 * header.entries, SEEK_CUR); /* Seek past index entries */
|
||||
fseek (rpmfile, header.size, SEEK_CUR); /* Seek past store */
|
||||
lseek (rpm_fd, 16 * header.entries, SEEK_CUR); /* Seek past index entries */
|
||||
lseek (rpm_fd, header.size, SEEK_CUR); /* Seek past store */
|
||||
}
|
||||
|
||||
/* No getopt required */
|
||||
extern int rpm2cpio_main(int argc, char **argv)
|
||||
{
|
||||
struct rpm_lead lead;
|
||||
int gunzip_pid;
|
||||
FILE *rpmfile, *cpiofile;
|
||||
int rpm_fd;
|
||||
unsigned char magic[2];
|
||||
|
||||
if (argc == 1) {
|
||||
rpmfile = stdin;
|
||||
rpm_fd = fileno(stdin);
|
||||
} else {
|
||||
rpmfile = xfopen(argv[1], "r");
|
||||
/* set the buffer size */
|
||||
setvbuf(rpmfile, NULL, _IOFBF, 0x8000);
|
||||
rpm_fd = xopen(argv[1], O_RDONLY);
|
||||
}
|
||||
|
||||
xread_all(rpm_fd, &lead, sizeof(struct rpm_lead));
|
||||
if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) {
|
||||
error_msg_and_die("Invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
|
||||
}
|
||||
|
||||
fread (&lead, sizeof(struct rpm_lead), 1, rpmfile);
|
||||
if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) error_msg_and_die("Invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
|
||||
/* Skip the signature header */
|
||||
skip_header(rpmfile);
|
||||
fseek(rpmfile, (8 - (ftell(rpmfile) % 8)) % 8, SEEK_CUR); /* Pad to 8 byte boundary */
|
||||
skip_header(rpm_fd);
|
||||
data_align(rpm_fd, lseek(rpm_fd, 0, SEEK_CUR), 8);
|
||||
|
||||
/* Skip the main header */
|
||||
skip_header(rpmfile);
|
||||
skip_header(rpm_fd);
|
||||
|
||||
xread_all(rpm_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
error_msg_and_die("Invalid gzip magic");
|
||||
}
|
||||
|
||||
cpiofile = gz_open(rpmfile, &gunzip_pid);
|
||||
check_header_gzip(rpm_fd);
|
||||
if (inflate(rpm_fd, fileno(stdout)) != 0) {
|
||||
error_msg("Error inflating");
|
||||
}
|
||||
check_trailer_gzip(rpm_fd);
|
||||
|
||||
close(rpm_fd);
|
||||
|
||||
copyfd(fileno(cpiofile), fileno(stdout));
|
||||
gz_close(gunzip_pid);
|
||||
fclose(rpmfile);
|
||||
return 0;
|
||||
}
|
||||
+383
-360
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,244 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini unzip implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2001 by Laurence Anderson
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/* For reference to format see http://www.pkware.com/support/appnote.html */
|
||||
|
||||
/* TODO Endian issues, exclude, should we accept input from stdin ? */
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#define ZIP_FILEHEADER_MAGIC 0x04034b50
|
||||
#define ZIP_CDS_MAGIC 0x02014b50
|
||||
#define ZIP_CDS_END_MAGIC 0x06054b50
|
||||
#define ZIP_DD_MAGIC 0x08074b50
|
||||
|
||||
extern unsigned int gunzip_crc;
|
||||
extern unsigned int gunzip_bytes_out;
|
||||
|
||||
static void header_list_unzip(const file_header_t *file_header)
|
||||
{
|
||||
printf(" inflating: %s\n", file_header->name);
|
||||
}
|
||||
|
||||
static void header_verbose_list_unzip(const file_header_t *file_header)
|
||||
{
|
||||
unsigned int dostime = (unsigned int) file_header->mtime;
|
||||
|
||||
/* can printf arguments cut of the decade component ? */
|
||||
unsigned short year = 1980 + ((dostime & 0xfe000000) >> 25);
|
||||
while (year >= 100) {
|
||||
year -= 100;
|
||||
}
|
||||
|
||||
printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
|
||||
(unsigned int) file_header->size,
|
||||
(dostime & 0x01e00000) >> 21,
|
||||
(dostime & 0x001f0000) >> 16,
|
||||
year,
|
||||
(dostime & 0x0000f800) >> 11,
|
||||
(dostime & 0x000007e0) >> 5,
|
||||
file_header->name);
|
||||
}
|
||||
|
||||
extern int unzip_main(int argc, char **argv)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[26];
|
||||
struct {
|
||||
unsigned short version; /* 0-1 */
|
||||
unsigned short flags; /* 2-3 */
|
||||
unsigned short method; /* 4-5 */
|
||||
unsigned short modtime; /* 6-7 */
|
||||
unsigned short moddate; /* 8-9 */
|
||||
unsigned int crc32 __attribute__ ((packed)); /* 10-13 */
|
||||
unsigned int cmpsize __attribute__ ((packed));; /* 14-17 */
|
||||
unsigned int ucmpsize __attribute__ ((packed));; /* 18-21 */
|
||||
unsigned short filename_len; /* 22-23 */
|
||||
unsigned short extra_len; /* 24-25 */
|
||||
} formated __attribute__ ((packed));
|
||||
} zip_header;
|
||||
|
||||
archive_handle_t *archive_handle;
|
||||
unsigned int total_size = 0;
|
||||
unsigned int total_entries = 0;
|
||||
char *base_dir = NULL;
|
||||
int opt = 0;
|
||||
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->action_data = NULL;
|
||||
archive_handle->action_header = header_list_unzip;
|
||||
|
||||
while ((opt = getopt(argc, argv, "lnopqd:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'l': /* list */
|
||||
archive_handle->action_header = header_verbose_list_unzip;
|
||||
archive_handle->action_data = data_skip;
|
||||
break;
|
||||
case 'n': /* never overwright existing files */
|
||||
break;
|
||||
case 'o':
|
||||
archive_handle->flags = ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
break;
|
||||
case 'p': /* extract files to stdout */
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
break;
|
||||
case 'q': /* Extract files quietly */
|
||||
archive_handle->action_header = header_skip;
|
||||
break;
|
||||
case 'd': /* Extract files to specified base directory*/
|
||||
base_dir = optarg;
|
||||
break;
|
||||
#if 0
|
||||
case 'x': /* Exclude the specified files */
|
||||
archive_handle->filter = filter_accept_reject_list;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == optind) {
|
||||
show_usage();
|
||||
}
|
||||
|
||||
printf("Archive: %s\n", argv[optind]);
|
||||
if (archive_handle->action_header == header_verbose_list_unzip) {
|
||||
printf(" Length Date Time Name\n");
|
||||
printf(" -------- ---- ---- ----\n");
|
||||
}
|
||||
|
||||
if (*argv[optind] == '-') {
|
||||
archive_handle->src_fd = fileno(stdin);
|
||||
} else {
|
||||
archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
|
||||
}
|
||||
|
||||
if ((base_dir) && (chdir(base_dir))) {
|
||||
perror_msg_and_die("Couldnt chdir");
|
||||
}
|
||||
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
archive_handle->accept = add_to_list(archive_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
unsigned int magic;
|
||||
int dst_fd;
|
||||
|
||||
/* TODO Endian issues */
|
||||
xread_all(archive_handle->src_fd, &magic, 4);
|
||||
archive_handle->offset += 4;
|
||||
|
||||
if (magic == ZIP_CDS_MAGIC) {
|
||||
break;
|
||||
}
|
||||
else if (magic != ZIP_FILEHEADER_MAGIC) {
|
||||
error_msg_and_die("Invlaide zip magic");
|
||||
}
|
||||
|
||||
/* Read the file header */
|
||||
xread_all(archive_handle->src_fd, zip_header.raw, 26);
|
||||
archive_handle->offset += 26;
|
||||
archive_handle->file_header->mode = S_IFREG | 0777;
|
||||
|
||||
if (zip_header.formated.method != 8) {
|
||||
error_msg_and_die("Unsupported compression method %d\n", zip_header.formated.method);
|
||||
}
|
||||
|
||||
/* Read filename */
|
||||
archive_handle->file_header->name = xmalloc(zip_header.formated.filename_len + 1);
|
||||
xread_all(archive_handle->src_fd, archive_handle->file_header->name, zip_header.formated.filename_len);
|
||||
archive_handle->offset += zip_header.formated.filename_len;
|
||||
archive_handle->file_header->name[zip_header.formated.filename_len] = '\0';
|
||||
|
||||
/* Skip extra header bits */
|
||||
archive_handle->file_header->size = zip_header.formated.extra_len;
|
||||
data_skip(archive_handle);
|
||||
archive_handle->offset += zip_header.formated.extra_len;
|
||||
|
||||
/* Handle directories */
|
||||
archive_handle->file_header->mode = S_IFREG | 0777;
|
||||
if (last_char_is(archive_handle->file_header->name, '/')) {
|
||||
archive_handle->file_header->mode ^= S_IFREG;
|
||||
archive_handle->file_header->mode |= S_IFDIR;
|
||||
}
|
||||
|
||||
/* Data section */
|
||||
archive_handle->file_header->size = zip_header.formated.cmpsize;
|
||||
if (archive_handle->action_data) {
|
||||
archive_handle->action_data(archive_handle);
|
||||
} else {
|
||||
dst_fd = xopen(archive_handle->file_header->name, O_WRONLY | O_CREAT);
|
||||
inflate(archive_handle->src_fd, dst_fd);
|
||||
close(dst_fd);
|
||||
chmod(archive_handle->file_header->name, archive_handle->file_header->mode);
|
||||
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header.formated.crc32 != (gunzip_crc ^ 0xffffffffL)) {
|
||||
error_msg("Invalid compressed data--crc error");
|
||||
}
|
||||
|
||||
/* Validate decompression - size */
|
||||
if (gunzip_bytes_out != zip_header.formated.ucmpsize) {
|
||||
error_msg("Invalid compressed data--length error");
|
||||
}
|
||||
}
|
||||
|
||||
/* local file descriptor section */
|
||||
archive_handle->offset += zip_header.formated.cmpsize;
|
||||
/* This ISNT unix time */
|
||||
archive_handle->file_header->mtime = zip_header.formated.modtime | (zip_header.formated.moddate << 16);
|
||||
archive_handle->file_header->size = zip_header.formated.ucmpsize;
|
||||
total_size += archive_handle->file_header->size;
|
||||
total_entries++;
|
||||
|
||||
archive_handle->action_header(archive_handle->file_header);
|
||||
|
||||
/* Data descriptor section */
|
||||
if (zip_header.formated.flags & 4) {
|
||||
/* skip over duplicate crc, compressed size and uncompressed size */
|
||||
unsigned short i;
|
||||
for (i = 0; i != 12; i++) {
|
||||
xread_char(archive_handle->src_fd);
|
||||
}
|
||||
archive_handle->offset += 12;
|
||||
}
|
||||
}
|
||||
/* Central directory section */
|
||||
|
||||
if (archive_handle->action_header == header_verbose_list_unzip) {
|
||||
printf(" -------- -------\n");
|
||||
printf("%9d %d files\n", total_size, total_entries);
|
||||
}
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
+9
-22
@@ -1,6 +1,6 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
|
||||
# Copyright (C) 1999-2002 Erik Andersen <andersee@debian.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,27 +17,14 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
TOPDIR :=..
|
||||
L_TARGET := console-tools.a
|
||||
|
||||
obj-y :=
|
||||
obj-n :=
|
||||
obj- :=
|
||||
|
||||
obj-$(CONFIG_CHVT) += chvt.o
|
||||
obj-$(CONFIG_CLEAR) += clear.o
|
||||
obj-$(CONFIG_DEALLOCVT) += deallocvt.o
|
||||
obj-$(CONFIG_DUMPKMAP) += dumpkmap.o
|
||||
obj-$(CONFIG_LOADACM) += loadacm.o
|
||||
obj-$(CONFIG_LOADFONT) += loadfont.o
|
||||
obj-$(CONFIG_LOADKMAP) += loadkmap.o
|
||||
obj-$(CONFIG_RESET) += reset.o
|
||||
obj-$(CONFIG_SETKEYCODES) += setkeycodes.o
|
||||
|
||||
|
||||
# Hand off to toplevel Rules.mak
|
||||
include $(TOPDIR)/Rules.mak
|
||||
TOPDIR:= ../
|
||||
CONSOLETOOLS_DIR:=./
|
||||
include $(TOPDIR).config
|
||||
include $(TOPDIR)Rules.mak
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(TOPDIR).depend
|
||||
|
||||
clean:
|
||||
rm -f $(L_TARGET) *.o core
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2002 Erik Andersen <andersee@debian.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
CONSOLETOOLS_AR:=console-tools.a
|
||||
ifndef $(CONSOLETOOLS_DIR)
|
||||
CONSOLETOOLS_DIR:=$(TOPDIR)console-tools/
|
||||
endif
|
||||
|
||||
CONSOLETOOLS_DIR-y:=
|
||||
CONSOLETOOLS_DIR-$(CONFIG_CHVT) += chvt.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_CLEAR) += clear.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_DEALLOCVT) += deallocvt.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_DUMPKMAP) += dumpkmap.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_LOADACM) += loadacm.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_LOADFONT) += loadfont.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_LOADKMAP) += loadkmap.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_OPENVT) += openvt.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_RESET) += reset.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_SETKEYCODES) += setkeycodes.o
|
||||
|
||||
libraries-y+=$(CONSOLETOOLS_DIR)$(CONSOLETOOLS_AR)
|
||||
|
||||
$(CONSOLETOOLS_DIR)$(CONSOLETOOLS_AR): $(patsubst %,$(CONSOLETOOLS_DIR)%, $(CONSOLETOOLS_DIR-y))
|
||||
$(AR) -ro $@ $(patsubst %,$(CONSOLETOOLS_DIR)%, $(CONSOLETOOLS_DIR-y))
|
||||
|
||||
@@ -24,7 +24,7 @@ int chvt_main(int argc, char **argv)
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-'))
|
||||
show_usage();
|
||||
fd = get_console_fd("/dev/console");
|
||||
fd = get_console_fd();
|
||||
num = atoi(argv[1]);
|
||||
if (ioctl(fd, VT_ACTIVATE, num))
|
||||
perror_msg_and_die("VT_ACTIVATE");
|
||||
|
||||
@@ -12,6 +12,7 @@ bool 'dumpkmap' CONFIG_DUMPKMAP
|
||||
bool 'loadacm' CONFIG_LOADACM
|
||||
bool 'loadfont' CONFIG_LOADFONT
|
||||
bool 'loadkmap' CONFIG_LOADKMAP
|
||||
bool 'openvt' CONFIG_OPENVT
|
||||
bool 'reset' CONFIG_RESET
|
||||
bool 'setkeycodes' CONFIG_SETKEYCODES
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ int deallocvt_main(int argc, char *argv[])
|
||||
if (argc > 2)
|
||||
show_usage();
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
fd = get_console_fd();
|
||||
|
||||
if (argc == 1) {
|
||||
/* deallocate all unused consoles */
|
||||
|
||||
@@ -81,7 +81,7 @@ int dumpkmap_main(int argc, char **argv)
|
||||
ke.kb_table = i;
|
||||
if (ioctl(fd, KDGKBENT, &ke) < 0) {
|
||||
|
||||
error_msg("ioctl returned: %s, %s, %s, %xqq", strerror(errno),(char *)&ke.kb_index,(char *)&ke.kb_table,(int)&ke.kb_value);
|
||||
error_msg("ioctl returned: %m, %s, %s, %xqq", (char *)&ke.kb_index,(char *)&ke.kb_table,(int)&ke.kb_value);
|
||||
}
|
||||
else {
|
||||
write(1,(void*)&ke.kb_value,2);
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* openvt.c - open a vt to run a command.
|
||||
*
|
||||
* busyboxed by Quy Tonthat <quy@signal3.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* getopt not needed */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include "busybox.h"
|
||||
|
||||
#define VTNAME "/dev/tty%d"
|
||||
|
||||
int openvt_main(int argc, char **argv)
|
||||
{
|
||||
int pid;
|
||||
int fd;
|
||||
int vtno;
|
||||
char vtname[sizeof VTNAME + 2];
|
||||
char * cmd = NULL;
|
||||
char * cmd_args = NULL;
|
||||
|
||||
if (argc < 3)
|
||||
show_usage();
|
||||
|
||||
if (!isdigit(argv[1][0]))
|
||||
show_usage();
|
||||
|
||||
vtno = (int) atol(argv[1]);
|
||||
|
||||
/* if (vtno <= 0 || vtno > 63) */
|
||||
if (vtno <= 0 || vtno > 12)
|
||||
error_msg_and_die("Illegal vt number (%d)", vtno);
|
||||
|
||||
sprintf(vtname, VTNAME, vtno);
|
||||
|
||||
cmd = argv[2];
|
||||
cmd_args = xmalloc(80);
|
||||
cmd_args[0] = '\0';
|
||||
|
||||
if((pid = fork()) == 0) {
|
||||
/* leave current vt */
|
||||
|
||||
#ifdef ESIX_5_3_2_D
|
||||
if (setpgrp() < 0) {
|
||||
#else
|
||||
if (setsid() < 0) {
|
||||
#endif
|
||||
|
||||
perror_msg_and_die("Unable to set new session");
|
||||
}
|
||||
close(0); /* so that new vt becomes stdin */
|
||||
|
||||
/* and grab new one */
|
||||
if ((fd = open(vtname, O_RDWR)) == -1)
|
||||
perror_msg_and_die("could not open %s", vtname);
|
||||
|
||||
/* Reassign stdout and sterr */
|
||||
close(1);
|
||||
close(2);
|
||||
dup(fd);
|
||||
dup(fd);
|
||||
|
||||
execvp(cmd, &argv[2]);
|
||||
/*execlp(cmd, cmd_args);*/
|
||||
_exit(1);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -3,7 +3,7 @@
|
||||
* Mini reset implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
* Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
|
||||
* Copyright (C) 1999-2002 by Erik Andersen <andersee@debian.org>
|
||||
* Written by Erik Andersen and Kent Robotti <robotti@metconnect.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
extern int reset_main(int argc, char **argv)
|
||||
{
|
||||
printf("\033c");
|
||||
printf("\033[?25h\033c\033[J");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ setkeycodes_main(int argc, char** argv)
|
||||
show_usage();
|
||||
}
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
fd = get_console_fd();
|
||||
|
||||
while (argc > 2) {
|
||||
a.keycode = atoi(argv[2]);
|
||||
|
||||
+424
@@ -0,0 +1,424 @@
|
||||
/*
|
||||
* Calendar implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2001 by Steven J. Merrifield <steve@labyrinth.net.au>
|
||||
*
|
||||
* See original copyright at the end of this file
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
#ifdef CONFIG_LOCALE_SUPPORT
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#define THURSDAY 4 /* for reformation */
|
||||
#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
|
||||
|
||||
#define FIRST_MISSING_DAY 639787 /* 3 Sep 1752 */
|
||||
#define NUMBER_MISSING_DAYS 11 /* 11 day correction */
|
||||
|
||||
#define MAXDAYS 42 /* max slots in a month array */
|
||||
#define SPACE -1 /* used in day array */
|
||||
|
||||
static int days_in_month[2][13] = {
|
||||
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
|
||||
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
|
||||
};
|
||||
|
||||
int sep1752[MAXDAYS] = {
|
||||
SPACE, SPACE, 1, 2, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 29, 30,
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
}, j_sep1752[MAXDAYS] = {
|
||||
SPACE, SPACE, 245, 246, 258, 259, 260,
|
||||
261, 262, 263, 264, 265, 266, 267,
|
||||
268, 269, 270, 271, 272, 273, 274,
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
}, empty[MAXDAYS] = {
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
|
||||
};
|
||||
|
||||
char *month_names[12];
|
||||
|
||||
char day_headings[] = " ";
|
||||
char j_day_headings[] = " ";
|
||||
|
||||
/* leap year -- account for gregorian reformation in 1752 */
|
||||
#define leap_year(yr) \
|
||||
((yr) <= 1752 ? !((yr) % 4) : \
|
||||
(!((yr) % 4) && ((yr) % 100)) || !((yr) % 400))
|
||||
|
||||
/* number of centuries since 1700, not inclusive */
|
||||
#define centuries_since_1700(yr) \
|
||||
((yr) > 1700 ? (yr) / 100 - 17 : 0)
|
||||
|
||||
/* number of centuries since 1700 whose modulo of 400 is 0 */
|
||||
#define quad_centuries_since_1700(yr) \
|
||||
((yr) > 1600 ? ((yr) - 1600) / 400 : 0)
|
||||
|
||||
/* number of leap years between year 1 and this year, not inclusive */
|
||||
#define leap_years_since_year_1(yr) \
|
||||
((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
|
||||
|
||||
int julian;
|
||||
void ascii_day __P((char *, int));
|
||||
void center __P((char *, int, int));
|
||||
void day_array __P((int, int, int *));
|
||||
int day_in_week __P((int, int, int));
|
||||
int day_in_year __P((int, int, int));
|
||||
void j_yearly __P((int));
|
||||
void monthly __P((int, int));
|
||||
void trim_trailing_spaces __P((char *));
|
||||
void yearly __P((int));
|
||||
|
||||
int cal_main(int argc, char **argv)
|
||||
{
|
||||
struct tm *local_time;
|
||||
static struct tm zero_tm;
|
||||
time_t now;
|
||||
int ch, month, year, yflag, i;
|
||||
char buf[40];
|
||||
|
||||
#ifdef CONFIG_LOCALE_SUPPORT
|
||||
setlocale(LC_TIME, "");
|
||||
#endif
|
||||
|
||||
yflag = 0;
|
||||
while ((ch = getopt(argc, argv, "jy")) != -1)
|
||||
switch(ch) {
|
||||
case 'j':
|
||||
julian = 1;
|
||||
break;
|
||||
case 'y':
|
||||
yflag = 1;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
month = 0;
|
||||
switch(argc) {
|
||||
case 2:
|
||||
if ((month = atoi(*argv++)) < 1 || month > 12)
|
||||
error_msg_and_die("Illegal month value: use 1-12");
|
||||
/* FALLTHROUGH */
|
||||
case 1:
|
||||
if ((year = atoi(*argv)) < 1 || year > 9999)
|
||||
error_msg_and_die("Illegal year value: use 1-9999");
|
||||
break;
|
||||
case 0:
|
||||
time(&now);
|
||||
local_time = localtime(&now);
|
||||
year = local_time->tm_year + 1900;
|
||||
if (!yflag)
|
||||
month = local_time->tm_mon + 1;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
|
||||
for (i = 0; i < 12; i++) {
|
||||
zero_tm.tm_mon = i;
|
||||
strftime(buf, sizeof(buf), "%B", &zero_tm);
|
||||
month_names[i] = xstrdup(buf);
|
||||
}
|
||||
for (i = 0; i < 7; i++) {
|
||||
zero_tm.tm_wday = i;
|
||||
strftime(buf, sizeof(buf), "%a", &zero_tm);
|
||||
strncpy(day_headings + i * 3, buf, 2);
|
||||
strncpy(j_day_headings + i * 4 + 1, buf, 2);
|
||||
}
|
||||
|
||||
if (month)
|
||||
monthly(month, year);
|
||||
else if (julian)
|
||||
j_yearly(year);
|
||||
else
|
||||
yearly(year);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#define DAY_LEN 3 /* 3 spaces per day */
|
||||
#define J_DAY_LEN 4 /* 4 spaces per day */
|
||||
#define WEEK_LEN 20 /* 7 * 3 - one space at the end */
|
||||
#define J_WEEK_LEN 27 /* 7 * 4 - one space at the end */
|
||||
#define HEAD_SEP 2 /* spaces between day headings */
|
||||
#define J_HEAD_SEP 2
|
||||
|
||||
void monthly(int month, int year)
|
||||
{
|
||||
int col, row, len, days[MAXDAYS];
|
||||
char *p, lineout[30];
|
||||
|
||||
day_array(month, year, days);
|
||||
len = sprintf(lineout, "%s %d", month_names[month - 1], year);
|
||||
printf("%*s%s\n%s\n",
|
||||
((julian ? J_WEEK_LEN : WEEK_LEN) - len) / 2, "",
|
||||
lineout, julian ? j_day_headings : day_headings);
|
||||
for (row = 0; row < 6; row++) {
|
||||
for (col = 0, p = lineout; col < 7; col++,
|
||||
p += julian ? J_DAY_LEN : DAY_LEN)
|
||||
ascii_day(p, days[row * 7 + col]);
|
||||
*p = '\0';
|
||||
trim_trailing_spaces(lineout);
|
||||
printf("%s\n", lineout);
|
||||
}
|
||||
}
|
||||
|
||||
void j_yearly(int year)
|
||||
{
|
||||
int col, *dp, i, month, row, which_cal;
|
||||
int days[12][MAXDAYS];
|
||||
char *p, lineout[80];
|
||||
|
||||
sprintf(lineout, "%d", year);
|
||||
center(lineout, J_WEEK_LEN * 2 + J_HEAD_SEP, 0);
|
||||
printf("\n\n");
|
||||
for (i = 0; i < 12; i++)
|
||||
day_array(i + 1, year, days[i]);
|
||||
memset(lineout, ' ', sizeof(lineout) - 1);
|
||||
lineout[sizeof(lineout) - 1] = '\0';
|
||||
for (month = 0; month < 12; month += 2) {
|
||||
center(month_names[month], J_WEEK_LEN, J_HEAD_SEP);
|
||||
center(month_names[month + 1], J_WEEK_LEN, 0);
|
||||
printf("\n%s%*s%s\n", j_day_headings, J_HEAD_SEP, "",
|
||||
j_day_headings);
|
||||
for (row = 0; row < 6; row++) {
|
||||
for (which_cal = 0; which_cal < 2; which_cal++) {
|
||||
p = lineout + which_cal * (J_WEEK_LEN + 2);
|
||||
dp = &days[month + which_cal][row * 7];
|
||||
for (col = 0; col < 7; col++, p += J_DAY_LEN)
|
||||
ascii_day(p, *dp++);
|
||||
}
|
||||
*p = '\0';
|
||||
trim_trailing_spaces(lineout);
|
||||
printf("%s\n", lineout);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void yearly(int year)
|
||||
{
|
||||
int col, *dp, i, month, row, which_cal;
|
||||
int days[12][MAXDAYS];
|
||||
char *p, lineout[80];
|
||||
|
||||
sprintf(lineout, "%d", year);
|
||||
center(lineout, WEEK_LEN * 3 + HEAD_SEP * 2, 0);
|
||||
printf("\n\n");
|
||||
for (i = 0; i < 12; i++)
|
||||
day_array(i + 1, year, days[i]);
|
||||
memset(lineout, ' ', sizeof(lineout) - 1);
|
||||
lineout[sizeof(lineout) - 1] = '\0';
|
||||
for (month = 0; month < 12; month += 3) {
|
||||
center(month_names[month], WEEK_LEN, HEAD_SEP);
|
||||
center(month_names[month + 1], WEEK_LEN, HEAD_SEP);
|
||||
center(month_names[month + 2], WEEK_LEN, 0);
|
||||
printf("\n%s%*s%s%*s%s\n", day_headings, HEAD_SEP,
|
||||
"", day_headings, HEAD_SEP, "", day_headings);
|
||||
for (row = 0; row < 6; row++) {
|
||||
for (which_cal = 0; which_cal < 3; which_cal++) {
|
||||
p = lineout + which_cal * (WEEK_LEN + 2);
|
||||
dp = &days[month + which_cal][row * 7];
|
||||
for (col = 0; col < 7; col++, p += DAY_LEN)
|
||||
ascii_day(p, *dp++);
|
||||
}
|
||||
*p = '\0';
|
||||
trim_trailing_spaces(lineout);
|
||||
printf("%s\n", lineout);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* day_array --
|
||||
* Fill in an array of 42 integers with a calendar. Assume for a moment
|
||||
* that you took the (maximum) 6 rows in a calendar and stretched them
|
||||
* out end to end. You would have 42 numbers or spaces. This routine
|
||||
* builds that array for any month from Jan. 1 through Dec. 9999.
|
||||
*/
|
||||
void day_array(int month, int year, int *days)
|
||||
{
|
||||
int day, dw, dm;
|
||||
|
||||
if ((month == 9) && (year == 1752)) {
|
||||
memmove(days,
|
||||
julian ? j_sep1752 : sep1752, MAXDAYS * sizeof(int));
|
||||
return;
|
||||
}
|
||||
memmove(days, empty, MAXDAYS * sizeof(int));
|
||||
dm = days_in_month[leap_year(year)][month];
|
||||
dw = day_in_week(1, month, year);
|
||||
day = julian ? day_in_year(1, month, year) : 1;
|
||||
while (dm--)
|
||||
days[dw++] = day++;
|
||||
}
|
||||
|
||||
/*
|
||||
* day_in_year --
|
||||
* return the 1 based day number within the year
|
||||
*/
|
||||
int day_in_year(int day, int month, int year)
|
||||
{
|
||||
int i, leap;
|
||||
|
||||
leap = leap_year(year);
|
||||
for (i = 1; i < month; i++)
|
||||
day += days_in_month[leap][i];
|
||||
return (day);
|
||||
}
|
||||
|
||||
/*
|
||||
* day_in_week
|
||||
* return the 0 based day number for any date from 1 Jan. 1 to
|
||||
* 31 Dec. 9999. Assumes the Gregorian reformation eliminates
|
||||
* 3 Sep. 1752 through 13 Sep. 1752. Returns Thursday for all
|
||||
* missing days.
|
||||
*/
|
||||
int day_in_week(int day, int month, int year)
|
||||
{
|
||||
long temp;
|
||||
|
||||
temp = (long)(year - 1) * 365 + leap_years_since_year_1(year - 1)
|
||||
+ day_in_year(day, month, year);
|
||||
if (temp < FIRST_MISSING_DAY)
|
||||
return ((temp - 1 + SATURDAY) % 7);
|
||||
if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS))
|
||||
return (((temp - 1 + SATURDAY) - NUMBER_MISSING_DAYS) % 7);
|
||||
return (THURSDAY);
|
||||
}
|
||||
|
||||
void ascii_day(char *p, int day)
|
||||
{
|
||||
int display, val;
|
||||
static char *aday[] = {
|
||||
"",
|
||||
" 1", " 2", " 3", " 4", " 5", " 6", " 7",
|
||||
" 8", " 9", "10", "11", "12", "13", "14",
|
||||
"15", "16", "17", "18", "19", "20", "21",
|
||||
"22", "23", "24", "25", "26", "27", "28",
|
||||
"29", "30", "31",
|
||||
};
|
||||
|
||||
if (day == SPACE) {
|
||||
memset(p, ' ', julian ? J_DAY_LEN : DAY_LEN);
|
||||
return;
|
||||
}
|
||||
if (julian) {
|
||||
if ((val = day / 100) != 0) {
|
||||
day %= 100;
|
||||
*p++ = val + '0';
|
||||
display = 1;
|
||||
} else {
|
||||
*p++ = ' ';
|
||||
display = 0;
|
||||
}
|
||||
val = day / 10;
|
||||
if (val || display)
|
||||
*p++ = val + '0';
|
||||
else
|
||||
*p++ = ' ';
|
||||
*p++ = day % 10 + '0';
|
||||
} else {
|
||||
*p++ = aday[day][0];
|
||||
*p++ = aday[day][1];
|
||||
}
|
||||
*p = ' ';
|
||||
}
|
||||
|
||||
void trim_trailing_spaces(char *s)
|
||||
{
|
||||
char *p;
|
||||
|
||||
for (p = s; *p; ++p)
|
||||
continue;
|
||||
while (p > s && (--p, isspace(*p)))
|
||||
continue;
|
||||
if (p > s)
|
||||
++p;
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
void center(char *str, int len, int separate)
|
||||
{
|
||||
|
||||
len -= strlen(str);
|
||||
printf("%*s%s%*s", len / 2, "", str, len / 2 + len % 2, "");
|
||||
if (separate)
|
||||
printf("%*s", separate, "");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Kim Letkeman.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ extern int cat_main(int argc, char **argv)
|
||||
while (--argc > 0) {
|
||||
if(!(strcmp(*++argv, "-"))) {
|
||||
print_file(stdin);
|
||||
} else if (print_file_by_name(*argv) == FALSE) {
|
||||
} else if (! print_file_by_name(*argv)) {
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -72,8 +72,8 @@ int chgrp_main(int argc, char **argv)
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
while (++optind < argc) {
|
||||
if (recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
|
||||
fileAction, fileAction, NULL) == FALSE) {
|
||||
if (! recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
|
||||
fileAction, fileAction, NULL)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
+29
-17
@@ -5,6 +5,9 @@
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
* Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
|
||||
*
|
||||
* Reworked by (C) 2002 Vladimir Oleynik <dzo@simtreas.ru>
|
||||
* to correctly parse '-rwxgoa'
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
@@ -31,7 +34,7 @@
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (!parse_mode((char *)junk, &(statbuf->st_mode)))
|
||||
error_msg_and_die("internal error");
|
||||
error_msg_and_die( "unknown mode: %s", (char *)junk);
|
||||
if (chmod(fileName, statbuf->st_mode) == 0)
|
||||
return (TRUE);
|
||||
perror(fileName);
|
||||
@@ -40,35 +43,44 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
|
||||
int chmod_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int opt;
|
||||
int recursiveFlag = FALSE;
|
||||
int modeind = 0; /* Index of the mode argument in `argv'. */
|
||||
char *smode;
|
||||
static const char chmod_modes[] = "Rrwxstugoa,+-=";
|
||||
|
||||
/* do normal option parsing */
|
||||
while ((opt = getopt(argc, argv, "R")) > 0) {
|
||||
switch (opt) {
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
while (1) {
|
||||
int thisind = optind ? optind : 1;
|
||||
|
||||
opt = getopt(argc, argv, chmod_modes);
|
||||
if (opt == EOF)
|
||||
break;
|
||||
default:
|
||||
smode = strchr(chmod_modes, opt);
|
||||
if(smode == NULL)
|
||||
show_usage();
|
||||
if(smode == chmod_modes) { /* 'R' */
|
||||
recursiveFlag = TRUE;
|
||||
} else {
|
||||
if (modeind != 0 && modeind != thisind)
|
||||
show_usage();
|
||||
modeind = thisind;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > optind && argc > 2 && argv[optind]) {
|
||||
/* Parse the specified mode */
|
||||
mode_t mode;
|
||||
if (parse_mode(argv[optind], &mode) == FALSE) {
|
||||
error_msg_and_die( "unknown mode: %s", argv[optind]);
|
||||
}
|
||||
} else {
|
||||
if (modeind == 0)
|
||||
modeind = optind++;
|
||||
|
||||
opt = optind;
|
||||
if (opt >= argc) {
|
||||
error_msg_and_die(too_few_args);
|
||||
}
|
||||
|
||||
smode = argv[modeind];
|
||||
/* Ok, ready to do the deed now */
|
||||
for (i = optind + 1; i < argc; i++) {
|
||||
if (recursive_action (argv[i], recursiveFlag, FALSE, FALSE, fileAction,
|
||||
fileAction, argv[optind]) == FALSE) {
|
||||
for (; opt < argc; opt++) {
|
||||
if (! recursive_action (argv[opt], recursiveFlag, FALSE, FALSE, fileAction,
|
||||
fileAction, smode)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -94,8 +94,8 @@ int chown_main(int argc, char **argv)
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
while (++optind < argc) {
|
||||
if (recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
|
||||
fileAction, fileAction, NULL) == FALSE) {
|
||||
if (! recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
|
||||
fileAction, fileAction, NULL)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
+126
-90
@@ -3,6 +3,8 @@
|
||||
* Mini date implementation for busybox
|
||||
*
|
||||
* by Matthew Grant <grantma@anathoth.gen.nz>
|
||||
*
|
||||
* iso-format handling added by Robert Griebl <griebl@gmx.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -46,19 +48,18 @@ static struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
|
||||
{
|
||||
int nr;
|
||||
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
|
||||
&(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday),
|
||||
&(tm_time->tm_hour),
|
||||
&(tm_time->tm_min), &(tm_time->tm_year));
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d", &(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday), &(tm_time->tm_hour), &(tm_time->tm_min),
|
||||
&(tm_time->tm_year));
|
||||
|
||||
if (nr < 4 || nr > 5) {
|
||||
error_msg_and_die(invalid_date, t_string);
|
||||
error_msg_and_die(invalid_date, t_string);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if (tm_time->tm_year >= 1900)
|
||||
if (tm_time->tm_year >= 1900) {
|
||||
tm_time->tm_year -= 1900;
|
||||
}
|
||||
/* adjust date */
|
||||
tm_time->tm_mon -= 1;
|
||||
|
||||
@@ -75,50 +76,39 @@ static struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
|
||||
if (t=*tm_time,sscanf(t_string, "%d:%d:%d",
|
||||
&t.tm_hour, &t.tm_min, &t.tm_sec) == 3) {
|
||||
/* no adjustments needed */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d:%d",
|
||||
&t.tm_hour, &t.tm_min) == 2) {
|
||||
/* no adjustments needed */
|
||||
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d:%d",
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour,
|
||||
&t.tm_min, &t.tm_sec) == 5) {
|
||||
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d",
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour, &t.tm_min) == 4) {
|
||||
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d:%d",
|
||||
&t.tm_year,
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour,
|
||||
&t.tm_min, &t.tm_sec) == 6) {
|
||||
|
||||
if (t =
|
||||
*tm_time, sscanf(t_string, "%d:%d:%d", &t.tm_hour, &t.tm_min,
|
||||
&t.tm_sec) == 3) {
|
||||
/* no adjustments needed */
|
||||
} else if (t =
|
||||
*tm_time, sscanf(t_string, "%d:%d", &t.tm_hour,
|
||||
&t.tm_min) == 2) {
|
||||
/* no adjustments needed */
|
||||
} else if (t =
|
||||
*tm_time, sscanf(t_string, "%d.%d-%d:%d:%d", &t.tm_mon,
|
||||
&t.tm_mday, &t.tm_hour, &t.tm_min,
|
||||
&t.tm_sec) == 5) {
|
||||
/* Adjust dates from 1-12 to 0-11 */
|
||||
t.tm_mon -= 1;
|
||||
} else if (t =
|
||||
*tm_time, sscanf(t_string, "%d.%d-%d:%d", &t.tm_mon,
|
||||
&t.tm_mday, &t.tm_hour, &t.tm_min) == 4) {
|
||||
/* Adjust dates from 1-12 to 0-11 */
|
||||
t.tm_mon -= 1;
|
||||
} else if (t =
|
||||
*tm_time, sscanf(t_string, "%d.%d.%d-%d:%d:%d", &t.tm_year,
|
||||
&t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min,
|
||||
&t.tm_sec) == 6) {
|
||||
t.tm_year -= 1900; /* Adjust years */
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d",
|
||||
&t.tm_year,
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour, &t.tm_min) == 5) {
|
||||
} else if (t =
|
||||
*tm_time, sscanf(t_string, "%d.%d.%d-%d:%d", &t.tm_year,
|
||||
&t.tm_mon, &t.tm_mday, &t.tm_hour,
|
||||
&t.tm_min) == 5) {
|
||||
t.tm_year -= 1900; /* Adjust years */
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else {
|
||||
error_msg_and_die(invalid_date, t_string);
|
||||
error_msg_and_die(invalid_date, t_string);
|
||||
}
|
||||
*tm_time = t;
|
||||
return (tm_time);
|
||||
@@ -138,45 +128,73 @@ int date_main(int argc, char **argv)
|
||||
time_t tm;
|
||||
struct tm tm_time;
|
||||
|
||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||
int ifmt = 0;
|
||||
|
||||
# define GETOPT_ISOFMT "I::"
|
||||
#else
|
||||
# define GETOPT_ISOFMT
|
||||
#endif
|
||||
|
||||
/* Interpret command line args */
|
||||
while ((c = getopt(argc, argv, "Rs:ud:")) != EOF) {
|
||||
while ((c = getopt(argc, argv, "Rs:ud:" GETOPT_ISOFMT)) != EOF) {
|
||||
switch (c) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if ((date_str != NULL) || ((date_str = optarg) == NULL)) {
|
||||
show_usage();
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
error_msg_and_die(memory_exhausted);
|
||||
break;
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if ((date_str != NULL) || ((date_str = optarg) == NULL))
|
||||
show_usage();
|
||||
break;
|
||||
default:
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if ((date_str != NULL) || ((date_str = optarg) == NULL)) {
|
||||
show_usage();
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
error_msg_and_die(memory_exhausted);
|
||||
break;
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if ((date_str != NULL) || ((date_str = optarg) == NULL))
|
||||
show_usage();
|
||||
break;
|
||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||
case 'I':
|
||||
if (!optarg)
|
||||
ifmt = 1;
|
||||
else {
|
||||
int ifmt_len = xstrlen(optarg);
|
||||
|
||||
if ((ifmt_len <= 4)
|
||||
&& (strncmp(optarg, "date", ifmt_len) == 0)) {
|
||||
ifmt = 1;
|
||||
} else if ((ifmt_len <= 5)
|
||||
&& (strncmp(optarg, "hours", ifmt_len) == 0)) {
|
||||
ifmt = 2;
|
||||
} else if ((ifmt_len <= 7)
|
||||
&& (strncmp(optarg, "minutes", ifmt_len) == 0)) {
|
||||
ifmt = 3;
|
||||
} else if ((ifmt_len <= 7)
|
||||
&& (strncmp(optarg, "seconds", ifmt_len) == 0)) {
|
||||
ifmt = 4;
|
||||
}
|
||||
}
|
||||
if (ifmt) {
|
||||
break; /* else show_usage(); */
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+'))
|
||||
date_fmt = &argv[optind][1]; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
|
||||
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) {
|
||||
date_fmt = &argv[optind][1]; /* Skip over the '+' */
|
||||
} else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = argv[optind];
|
||||
}
|
||||
#if 0
|
||||
else {
|
||||
error_msg("date_str='%s' date_fmt='%s'\n", date_str, date_fmt);
|
||||
show_usage();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
@@ -201,18 +219,16 @@ int date_main(int argc, char **argv)
|
||||
|
||||
/* Correct any day of week and day of year etc. fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0)
|
||||
error_msg_and_die(invalid_date, date_str);
|
||||
if ( utc ) {
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
error_msg_and_die(memory_exhausted);
|
||||
if (tm < 0) {
|
||||
error_msg_and_die(invalid_date, date_str);
|
||||
}
|
||||
if (utc && (putenv("TZ=UTC0") != 0)) {
|
||||
error_msg_and_die(memory_exhausted);
|
||||
}
|
||||
|
||||
/* if setting time, set it */
|
||||
if (set_time) {
|
||||
if (stime(&tm) < 0) {
|
||||
perror_msg("cannot set date");
|
||||
}
|
||||
if (set_time && (stime(&tm) < 0)) {
|
||||
perror_msg("cannot set date");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,12 +236,32 @@ int date_main(int argc, char **argv)
|
||||
|
||||
/* Deal with format string */
|
||||
if (date_fmt == NULL) {
|
||||
date_fmt = (rfc822
|
||||
? (utc
|
||||
? "%a, %_d %b %Y %H:%M:%S GMT"
|
||||
: "%a, %_d %b %Y %H:%M:%S %z")
|
||||
: "%a %b %e %H:%M:%S %Z %Y");
|
||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||
switch (ifmt) {
|
||||
case 4:
|
||||
date_fmt = utc ? "%Y-%m-%dT%H:%M:%SZ" : "%Y-%m-%dT%H:%M:%S%z";
|
||||
break;
|
||||
case 3:
|
||||
date_fmt = utc ? "%Y-%m-%dT%H:%MZ" : "%Y-%m-%dT%H:%M%z";
|
||||
break;
|
||||
case 2:
|
||||
date_fmt = utc ? "%Y-%m-%dT%HZ" : "%Y-%m-%dT%H%z";
|
||||
break;
|
||||
case 1:
|
||||
date_fmt = "%Y-%m-%d";
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
#endif
|
||||
date_fmt =
|
||||
(rfc822
|
||||
? (utc ? "%a, %e %b %Y %H:%M:%S GMT" :
|
||||
"%a, %e %b %Y %H:%M:%S %z") : "%a %b %e %H:%M:%S %Z %Y");
|
||||
|
||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
} else if (*date_fmt == '\0') {
|
||||
/* Imitate what GNU 'date' does with NO format string! */
|
||||
printf("\n");
|
||||
|
||||
+31
-6
@@ -3,7 +3,7 @@
|
||||
* Mini dd implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
* Copyright (C) 2000,2001 Matt Kraai
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@@ -45,7 +46,7 @@ static const struct suffix_mult dd_suffixes[] = {
|
||||
|
||||
int dd_main(int argc, char **argv)
|
||||
{
|
||||
int i, ifd, ofd, oflag, sync_flag = FALSE, trunc = TRUE;
|
||||
int i, ifd, ofd, oflag, sync_flag = FALSE, trunc = TRUE, noerror = FALSE;
|
||||
size_t in_full = 0, in_part = 0, out_full = 0, out_part = 0;
|
||||
size_t bs = 512, count = -1;
|
||||
ssize_t n;
|
||||
@@ -74,6 +75,9 @@ int dd_main(int argc, char **argv)
|
||||
} else if (strncmp("sync", buf, 4) == 0) {
|
||||
sync_flag = TRUE;
|
||||
buf += 4;
|
||||
} else if (strncmp("noerror", buf, 7) == 0) {
|
||||
noerror = TRUE;
|
||||
buf += 7;
|
||||
} else {
|
||||
error_msg_and_die("invalid conversion `%s'", argv[i]+5);
|
||||
}
|
||||
@@ -106,8 +110,13 @@ int dd_main(int argc, char **argv)
|
||||
perror_msg_and_die("%s", outfile);
|
||||
|
||||
if (seek && trunc) {
|
||||
if (ftruncate(ofd, seek * bs) < 0)
|
||||
perror_msg_and_die("%s", outfile);
|
||||
if (ftruncate(ofd, seek * bs) < 0) {
|
||||
struct stat st;
|
||||
|
||||
if (fstat (ofd, &st) < 0 || S_ISREG (st.st_mode) ||
|
||||
S_ISDIR (st.st_mode))
|
||||
perror_msg_and_die("%s", outfile);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ofd = STDOUT_FILENO;
|
||||
@@ -125,9 +134,19 @@ int dd_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
while (in_full + in_part != count) {
|
||||
if (noerror) {
|
||||
/* Pre-zero the buffer when doing the noerror thing */
|
||||
memset(buf, '\0', bs);
|
||||
}
|
||||
n = safe_read(ifd, buf, bs);
|
||||
if (n < 0)
|
||||
perror_msg_and_die("%s", infile);
|
||||
if (n < 0) {
|
||||
if (noerror) {
|
||||
n = bs;
|
||||
perror_msg("%s", infile);
|
||||
} else {
|
||||
perror_msg_and_die("%s", infile);
|
||||
}
|
||||
}
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n == bs)
|
||||
@@ -147,6 +166,12 @@ int dd_main(int argc, char **argv)
|
||||
out_part++;
|
||||
}
|
||||
|
||||
if (close (ifd) < 0)
|
||||
perror_msg_and_die("%s", infile);
|
||||
|
||||
if (close (ofd) < 0)
|
||||
perror_msg_and_die("%s", outfile);
|
||||
|
||||
fprintf(stderr, "%ld+%ld records in\n", (long)in_full, (long)in_part);
|
||||
fprintf(stderr, "%ld+%ld records out\n", (long)out_full, (long)out_part);
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ static int convert(char *fn, int ConvType)
|
||||
if ((in = wfopen(fn, "rw")) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
strcpy(tempFn, fn);
|
||||
safe_strncpy(tempFn, fn, sizeof(tempFn));
|
||||
c = strlen(tempFn);
|
||||
tempFn[c] = '.';
|
||||
while(1) {
|
||||
|
||||
+41
-101
@@ -4,6 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 1999,2000,2001 by Lineo, inc. and John Beppu
|
||||
* Copyright (C) 1999,2000,2001 by John Beppu <beppu@codepoet.org>
|
||||
* Copyright (C) 2002 Edward Betts <edward@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -36,17 +37,18 @@
|
||||
static unsigned long disp_hr = KILOBYTE;
|
||||
#endif
|
||||
|
||||
typedef void (Display) (long, char *);
|
||||
static int du_depth /*= 0*/;
|
||||
static int count_hardlinks /*= 0*/;
|
||||
static int one_file_system /*= 0*/;
|
||||
static dev_t dir_dev;
|
||||
|
||||
static int du_depth = 0;
|
||||
static int count_hardlinks = 0;
|
||||
|
||||
static Display *print;
|
||||
static void (*print) (long, char *);
|
||||
|
||||
static void print_normal(long size, char *filename)
|
||||
{
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
printf("%s\t%s\n", make_human_readable_str(size<<10, 1, disp_hr), filename);
|
||||
printf("%s\t%s\n", make_human_readable_str(size << 10, 1, disp_hr),
|
||||
filename);
|
||||
#else
|
||||
printf("%ld\t%s\n", size, filename);
|
||||
#endif
|
||||
@@ -59,78 +61,6 @@ static void print_summary(long size, char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
#define HASH_SIZE 311 /* Should be prime */
|
||||
#define hash_inode(i) ((i) % HASH_SIZE)
|
||||
|
||||
typedef struct ino_dev_hash_bucket_struct {
|
||||
struct ino_dev_hash_bucket_struct *next;
|
||||
ino_t ino;
|
||||
dev_t dev;
|
||||
char name[1];
|
||||
} ino_dev_hashtable_bucket_t;
|
||||
|
||||
static ino_dev_hashtable_bucket_t *ino_dev_hashtable[HASH_SIZE];
|
||||
|
||||
/*
|
||||
* Return 1 if statbuf->st_ino && statbuf->st_dev are recorded in
|
||||
* `ino_dev_hashtable', else return 0
|
||||
*
|
||||
* If NAME is a non-NULL pointer to a character pointer, and there is
|
||||
* a match, then set *NAME to the value of the name slot in that
|
||||
* bucket.
|
||||
*/
|
||||
static int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name)
|
||||
{
|
||||
ino_dev_hashtable_bucket_t *bucket;
|
||||
|
||||
bucket = ino_dev_hashtable[hash_inode(statbuf->st_ino)];
|
||||
while (bucket != NULL) {
|
||||
if ((bucket->ino == statbuf->st_ino) &&
|
||||
(bucket->dev == statbuf->st_dev))
|
||||
{
|
||||
if (name) *name = bucket->name;
|
||||
return 1;
|
||||
}
|
||||
bucket = bucket->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Add statbuf to statbuf hash table */
|
||||
static void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name)
|
||||
{
|
||||
int i;
|
||||
size_t s;
|
||||
ino_dev_hashtable_bucket_t *bucket;
|
||||
|
||||
i = hash_inode(statbuf->st_ino);
|
||||
s = name ? strlen(name) : 0;
|
||||
bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s);
|
||||
bucket->ino = statbuf->st_ino;
|
||||
bucket->dev = statbuf->st_dev;
|
||||
if (name)
|
||||
strcpy(bucket->name, name);
|
||||
else
|
||||
bucket->name[0] = '\0';
|
||||
bucket->next = ino_dev_hashtable[i];
|
||||
ino_dev_hashtable[i] = bucket;
|
||||
}
|
||||
|
||||
/* Clear statbuf hash table */
|
||||
static void reset_ino_dev_hashtable(void)
|
||||
{
|
||||
int i;
|
||||
ino_dev_hashtable_bucket_t *bucket;
|
||||
|
||||
for (i = 0; i < HASH_SIZE; i++) {
|
||||
while (ino_dev_hashtable[i] != NULL) {
|
||||
bucket = ino_dev_hashtable[i]->next;
|
||||
free(ino_dev_hashtable[i]);
|
||||
ino_dev_hashtable[i] = bucket;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* tiny recursive du */
|
||||
static long du(char *filename)
|
||||
{
|
||||
@@ -141,6 +71,10 @@ static long du(char *filename)
|
||||
perror_msg("%s", filename);
|
||||
return 0;
|
||||
}
|
||||
if (du_depth == 0)
|
||||
dir_dev = statbuf.st_dev;
|
||||
else if (one_file_system && dir_dev != statbuf.st_dev)
|
||||
return 0;
|
||||
|
||||
du_depth++;
|
||||
sum = (statbuf.st_blocks >> 1);
|
||||
@@ -179,15 +113,13 @@ static long du(char *filename)
|
||||
}
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
else if (statbuf.st_nlink > 1 && !count_hardlinks) {
|
||||
} else if (statbuf.st_nlink > 1 && !count_hardlinks) {
|
||||
/* Add files with hard links only once */
|
||||
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
|
||||
sum = 0L;
|
||||
if (du_depth == 1)
|
||||
print(sum, filename);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
add_to_ino_dev_hashtable(&statbuf, NULL);
|
||||
}
|
||||
}
|
||||
@@ -205,26 +137,34 @@ int du_main(int argc, char **argv)
|
||||
print = print_normal;
|
||||
|
||||
/* parse argv[] */
|
||||
while ((c = getopt(argc, argv, "sl"
|
||||
while ((c = getopt(argc, argv, "slx"
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
"hm"
|
||||
"hm"
|
||||
#endif
|
||||
"k")) != EOF) {
|
||||
switch (c) {
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'l':
|
||||
count_hardlinks = 1;
|
||||
break;
|
||||
"k")) != EOF) {
|
||||
switch (c) {
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'l':
|
||||
count_hardlinks = 1;
|
||||
break;
|
||||
case 'x':
|
||||
one_file_system = 1;
|
||||
break;
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
case 'h': disp_hr = 0; break;
|
||||
case 'm': disp_hr = MEGABYTE; break;
|
||||
case 'h':
|
||||
disp_hr = 0;
|
||||
break;
|
||||
case 'm':
|
||||
disp_hr = MEGABYTE;
|
||||
break;
|
||||
#endif
|
||||
case 'k': break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
case 'k':
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
@@ -234,9 +174,9 @@ int du_main(int argc, char **argv)
|
||||
} else {
|
||||
long sum;
|
||||
|
||||
for (i=optind; i < argc; i++) {
|
||||
for (i = optind; i < argc; i++) {
|
||||
sum = du(argv[i]);
|
||||
if(is_directory(argv[i], FALSE, NULL)==FALSE) {
|
||||
if (is_directory(argv[i], FALSE, NULL) == FALSE) {
|
||||
print_normal(sum, argv[i]);
|
||||
}
|
||||
reset_ino_dev_hashtable();
|
||||
@@ -246,7 +186,7 @@ int du_main(int argc, char **argv)
|
||||
return status;
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.51 2001/10/24 04:59:27 andersen Exp $ */
|
||||
/* $Id: du.c,v 1.55 2002/08/23 07:28:45 aaronl Exp $ */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
|
||||
+2
-8
@@ -146,12 +146,8 @@ static int null (VALUE *v)
|
||||
|
||||
static void tostring (VALUE *v)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
if (v->type == integer) {
|
||||
temp = xmalloc (4 * (sizeof (int) / sizeof (char)));
|
||||
sprintf (temp, "%d", v->u.i);
|
||||
v->u.s = temp;
|
||||
bb_asprintf (&(v->u.s), "%d", v->u.i);
|
||||
v->type = string;
|
||||
}
|
||||
}
|
||||
@@ -377,9 +373,7 @@ static VALUE *eval6 (void)
|
||||
else {
|
||||
v = xmalloc (sizeof(VALUE));
|
||||
v->type = string;
|
||||
v->u.s = strncpy ((char *) xmalloc (i2->u.i + 1),
|
||||
l->u.s + i1->u.i - 1, i2->u.i);
|
||||
v->u.s[i2->u.i] = 0;
|
||||
v->u.s = xstrndup(l->u.s + i1->u.i - 1, i2->u.i);
|
||||
}
|
||||
freev (l);
|
||||
freev (i1);
|
||||
|
||||
+7
-1
@@ -25,6 +25,7 @@
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "busybox.h"
|
||||
|
||||
static int head(int len, FILE *fp)
|
||||
@@ -47,12 +48,17 @@ int head_main(int argc, char **argv)
|
||||
FILE *fp;
|
||||
int need_headers, opt, len = 10, status = EXIT_SUCCESS;
|
||||
|
||||
if (( argc >= 2 ) && ( argv [1][0] == '-' ) && isdigit ( argv [1][1] )) {
|
||||
len = atoi ( &argv [1][1] );
|
||||
optind = 2;
|
||||
}
|
||||
|
||||
/* parse argv[] */
|
||||
while ((opt = getopt(argc, argv, "n:")) > 0) {
|
||||
switch (opt) {
|
||||
case 'n':
|
||||
len = atoi(optarg);
|
||||
if (len >= 1)
|
||||
if (len >= 0)
|
||||
break;
|
||||
/* fallthrough */
|
||||
default:
|
||||
|
||||
+3
-4
@@ -68,8 +68,7 @@ extern int id_main(int argc, char **argv)
|
||||
my_getgrgid(group, getegid());
|
||||
}
|
||||
} else {
|
||||
strncpy(user, argv[optind], 8);
|
||||
user[8] = '\0';
|
||||
safe_strncpy(user, argv[optind], sizeof(user));
|
||||
gid = my_getpwnamegid(user);
|
||||
my_getgrgid(group, gid);
|
||||
}
|
||||
@@ -78,12 +77,12 @@ extern int id_main(int argc, char **argv)
|
||||
grnam=my_getgrnam(group);
|
||||
|
||||
if (no_group) {
|
||||
if(name_not_number && user)
|
||||
if(name_not_number)
|
||||
puts(user);
|
||||
else
|
||||
printf("%ld\n", pwnam);
|
||||
} else if (no_user) {
|
||||
if(name_not_number && group)
|
||||
if(name_not_number)
|
||||
puts(group);
|
||||
else
|
||||
printf("%ld\n", grnam);
|
||||
|
||||
+18
-16
@@ -43,45 +43,47 @@ static int fs_link(const char *link_destname, const char *link_srcname,
|
||||
{
|
||||
int status;
|
||||
int src_is_dir;
|
||||
char *src_name;
|
||||
char *src_name = 0;
|
||||
const char *src;
|
||||
|
||||
if (link_destname==NULL)
|
||||
return(FALSE);
|
||||
|
||||
src_name = (char *) xmalloc(strlen(link_srcname)+strlen(link_destname)+1);
|
||||
|
||||
if (link_srcname==NULL)
|
||||
strcpy(src_name, link_destname);
|
||||
src = link_destname;
|
||||
else
|
||||
strcpy(src_name, link_srcname);
|
||||
src = link_srcname;
|
||||
|
||||
if (flag&LN_NODEREFERENCE)
|
||||
src_is_dir = is_directory(src_name, TRUE, NULL);
|
||||
src_is_dir = is_directory(src, TRUE, NULL);
|
||||
else
|
||||
src_is_dir = is_directory(src_name, FALSE, NULL);
|
||||
src_is_dir = is_directory(src, FALSE, NULL);
|
||||
|
||||
if ((src_is_dir==TRUE)&&((flag&LN_NODEREFERENCE)==0)) {
|
||||
char* srcdir_name;
|
||||
|
||||
srcdir_name = xstrdup(link_destname);
|
||||
strcat(src_name, "/");
|
||||
strcat(src_name, get_last_path_component(srcdir_name));
|
||||
src_name = concat_path_file(src, get_last_path_component(srcdir_name));
|
||||
src = src_name;
|
||||
free(srcdir_name);
|
||||
}
|
||||
|
||||
if (flag&LN_FORCE)
|
||||
unlink(src_name);
|
||||
unlink(src);
|
||||
|
||||
if (flag&LN_SYMLINK)
|
||||
status = symlink(link_destname, src_name);
|
||||
status = symlink(link_destname, src);
|
||||
else
|
||||
status = link(link_destname, src_name);
|
||||
status = link(link_destname, src);
|
||||
|
||||
if (status != 0) {
|
||||
perror_msg(src_name);
|
||||
return(FALSE);
|
||||
perror_msg(src);
|
||||
status = FALSE;
|
||||
} else {
|
||||
status = TRUE;
|
||||
}
|
||||
return(TRUE);
|
||||
free(src_name);
|
||||
return status;
|
||||
}
|
||||
|
||||
extern int ln_main(int argc, char **argv)
|
||||
@@ -119,7 +121,7 @@ extern int ln_main(int argc, char **argv)
|
||||
status = EXIT_FAILURE;
|
||||
optind++;
|
||||
}
|
||||
exit(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+1
-2
@@ -32,8 +32,7 @@ extern int logname_main(int argc, char **argv)
|
||||
if (argc > 1)
|
||||
show_usage();
|
||||
|
||||
my_getpwuid(user, geteuid());
|
||||
if (*user) {
|
||||
if (my_getpwuid(user, geteuid())) {
|
||||
puts(user);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
+484
-340
File diff suppressed because it is too large.
Load diff
+5
-5
@@ -434,7 +434,7 @@ static void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ct
|
||||
temp += FI(B,C,D);
|
||||
}
|
||||
temp += cwp[(int)(*pp++)] + *pc++;
|
||||
temp = CYCLIC (temp, ps[i&3]);
|
||||
CYCLIC (temp, ps[i&3]);
|
||||
temp += B;
|
||||
A = D; D = C; C = B; B = temp;
|
||||
}
|
||||
@@ -443,7 +443,7 @@ static void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ct
|
||||
|
||||
for ( i = 0 ; i < 16 ; i++ ) {
|
||||
temp = A + FF(B,C,D) + cwp[(int)(*pp++)] + *pc++;
|
||||
temp = CYCLIC (temp, ps[i&3]);
|
||||
CYCLIC (temp, ps[i&3]);
|
||||
temp += B;
|
||||
A = D; D = C; C = B; B = temp;
|
||||
}
|
||||
@@ -451,21 +451,21 @@ static void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ct
|
||||
ps += 4;
|
||||
for ( i = 0 ; i < 16 ; i++ ) {
|
||||
temp = A + FG(B,C,D) + cwp[(int)(*pp++)] + *pc++;
|
||||
temp = CYCLIC (temp, ps[i&3]);
|
||||
CYCLIC (temp, ps[i&3]);
|
||||
temp += B;
|
||||
A = D; D = C; C = B; B = temp;
|
||||
}
|
||||
ps += 4;
|
||||
for ( i = 0 ; i < 16 ; i++ ) {
|
||||
temp = A + FH(B,C,D) + cwp[(int)(*pp++)] + *pc++;
|
||||
temp = CYCLIC (temp, ps[i&3]);
|
||||
CYCLIC (temp, ps[i&3]);
|
||||
temp += B;
|
||||
A = D; D = C; C = B; B = temp;
|
||||
}
|
||||
ps += 4;
|
||||
for ( i = 0 ; i < 16 ; i++ ) {
|
||||
temp = A + FI(B,C,D) + cwp[(int)(*pp++)] + *pc++;
|
||||
temp = CYCLIC (temp, ps[i&3]);
|
||||
CYCLIC (temp, ps[i&3]);
|
||||
temp += B;
|
||||
A = D; D = C; C = B; B = temp;
|
||||
}
|
||||
|
||||
+4
-5
@@ -35,7 +35,6 @@ extern int mkdir_main (int argc, char **argv)
|
||||
{
|
||||
mode_t mode = -1;
|
||||
int flags = 0;
|
||||
int status = 0;
|
||||
int i, opt;
|
||||
|
||||
while ((opt = getopt (argc, argv, "m:p")) != -1) {
|
||||
@@ -56,9 +55,9 @@ extern int mkdir_main (int argc, char **argv)
|
||||
if (optind == argc)
|
||||
show_usage ();
|
||||
|
||||
for (i = optind; i < argc; i++)
|
||||
if (make_directory (argv[i], mode, flags) < 0)
|
||||
status = 1;
|
||||
for (i = optind; i < argc; i++) {
|
||||
make_directory (argv[i], mode, flags);
|
||||
}
|
||||
|
||||
return status;
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
+5
-4
@@ -3,6 +3,7 @@
|
||||
* Mini mknod implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
* Copyright (C) 1999-2002 by Erik Andersen <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -27,6 +28,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int mknod_main(int argc, char **argv)
|
||||
@@ -34,7 +36,7 @@ int mknod_main(int argc, char **argv)
|
||||
char *thisarg;
|
||||
mode_t mode = 0;
|
||||
mode_t perm = 0666;
|
||||
dev_t dev = 0;
|
||||
dev_t dev = (dev_t) 0;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -71,7 +73,7 @@ int mknod_main(int argc, char **argv)
|
||||
break;
|
||||
case 'p':
|
||||
mode = S_IFIFO;
|
||||
if (argc!=2) {
|
||||
if (argc != 2) {
|
||||
show_usage();
|
||||
}
|
||||
break;
|
||||
@@ -80,7 +82,7 @@ int mknod_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (mode == S_IFCHR || mode == S_IFBLK) {
|
||||
dev = (atoi(argv[2]) << 8) | atoi(argv[3]);
|
||||
dev = (dev_t) ((atoi(argv[2]) << 8) | atoi(argv[3]));
|
||||
}
|
||||
|
||||
mode |= perm;
|
||||
@@ -89,4 +91,3 @@ int mknod_main(int argc, char **argv)
|
||||
perror_msg_and_die("%s", argv[0]);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
+1
-5
@@ -248,11 +248,7 @@ int od_main(int argc, char **argv)
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
/*
|
||||
* Mini pwd implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
/*
|
||||
* Mini sleep implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
+22
-3
@@ -572,14 +572,34 @@ extern int main(int argc, char **argv)
|
||||
|
||||
speed_was_set = 0;
|
||||
require_set_attr = 0;
|
||||
k = optind;
|
||||
while (k < argc) {
|
||||
k = 0;
|
||||
while (++k < argc) {
|
||||
int match_found = 0;
|
||||
int reversed = 0;
|
||||
int i;
|
||||
|
||||
if (argv[k][0] == '-') {
|
||||
char *find_dev_opt;
|
||||
|
||||
++argv[k];
|
||||
|
||||
/* Handle "-a", "-ag", "-aF/dev/foo", "-aF /dev/foo", etc.
|
||||
Find the options that have been parsed. This is really
|
||||
gross, but it's needed because stty SETTINGS look like options to
|
||||
getopt(), so we need to work around things in a really horrible
|
||||
way. If any new options are ever added to stty, the short option
|
||||
MUST NOT be a letter which is the first letter of one of the
|
||||
possible stty settings.
|
||||
*/
|
||||
find_dev_opt = strchr(argv[k], 'F'); /* find -*F* */
|
||||
if(find_dev_opt) {
|
||||
if(find_dev_opt[1]==0) /* -*F /dev/foo */
|
||||
k++; /* skip /dev/foo */
|
||||
continue; /* else -*F/dev/foo - no skip */
|
||||
}
|
||||
if(argv[k][0]=='a' || argv[k][0]=='g')
|
||||
continue;
|
||||
/* Is not options - is reverse params */
|
||||
reversed = 1;
|
||||
}
|
||||
for (i = 0; i < NUM_mode_info; ++i)
|
||||
@@ -661,7 +681,6 @@ extern int main(int argc, char **argv)
|
||||
} else
|
||||
error_msg_and_die("invalid argument `%s'", argv[k]);
|
||||
}
|
||||
k++;
|
||||
}
|
||||
|
||||
if (require_set_attr) {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
/*
|
||||
* Mini sync implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
@@ -68,6 +69,11 @@ int tail_main(int argc, char **argv)
|
||||
char *s, *start, *end, buf[BUFSIZ];
|
||||
int i, opt;
|
||||
|
||||
if (( argc >= 2 ) && ( argv [1][0] == '-' ) && isdigit ( argv [1][1] )) {
|
||||
count = atoi ( &argv [1][1] );
|
||||
optind = 2;
|
||||
}
|
||||
|
||||
while ((opt = getopt(argc, argv, "c:fhn:q:s:v")) > 0) {
|
||||
switch (opt) {
|
||||
case 'f':
|
||||
|
||||
+103
-135
@@ -110,47 +110,49 @@ enum token_types {
|
||||
static const struct t_op {
|
||||
const char *op_text;
|
||||
short op_num, op_type;
|
||||
} ops [] = {
|
||||
{"-r", FILRD, UNOP},
|
||||
{"-w", FILWR, UNOP},
|
||||
{"-x", FILEX, UNOP},
|
||||
{"-e", FILEXIST,UNOP},
|
||||
{"-f", FILREG, UNOP},
|
||||
{"-d", FILDIR, UNOP},
|
||||
{"-c", FILCDEV,UNOP},
|
||||
{"-b", FILBDEV,UNOP},
|
||||
{"-p", FILFIFO,UNOP},
|
||||
{"-u", FILSUID,UNOP},
|
||||
{"-g", FILSGID,UNOP},
|
||||
{"-k", FILSTCK,UNOP},
|
||||
{"-s", FILGZ, UNOP},
|
||||
{"-t", FILTT, UNOP},
|
||||
{"-z", STREZ, UNOP},
|
||||
{"-n", STRNZ, UNOP},
|
||||
{"-h", FILSYM, UNOP}, /* for backwards compat */
|
||||
{"-O", FILUID, UNOP},
|
||||
{"-G", FILGID, UNOP},
|
||||
{"-L", FILSYM, UNOP},
|
||||
{"-S", FILSOCK,UNOP},
|
||||
{"=", STREQ, BINOP},
|
||||
{"!=", STRNE, BINOP},
|
||||
{"<", STRLT, BINOP},
|
||||
{">", STRGT, BINOP},
|
||||
{"-eq", INTEQ, BINOP},
|
||||
{"-ne", INTNE, BINOP},
|
||||
{"-ge", INTGE, BINOP},
|
||||
{"-gt", INTGT, BINOP},
|
||||
{"-le", INTLE, BINOP},
|
||||
{"-lt", INTLT, BINOP},
|
||||
{"-nt", FILNT, BINOP},
|
||||
{"-ot", FILOT, BINOP},
|
||||
{"-ef", FILEQ, BINOP},
|
||||
{"!", UNOT, BUNOP},
|
||||
{"-a", BAND, BBINOP},
|
||||
{"-o", BOR, BBINOP},
|
||||
{"(", LPAREN, PAREN},
|
||||
{")", RPAREN, PAREN},
|
||||
{0, 0, 0}
|
||||
} ops[] = {
|
||||
{
|
||||
"-r", FILRD, UNOP}, {
|
||||
"-w", FILWR, UNOP}, {
|
||||
"-x", FILEX, UNOP}, {
|
||||
"-e", FILEXIST, UNOP}, {
|
||||
"-f", FILREG, UNOP}, {
|
||||
"-d", FILDIR, UNOP}, {
|
||||
"-c", FILCDEV, UNOP}, {
|
||||
"-b", FILBDEV, UNOP}, {
|
||||
"-p", FILFIFO, UNOP}, {
|
||||
"-u", FILSUID, UNOP}, {
|
||||
"-g", FILSGID, UNOP}, {
|
||||
"-k", FILSTCK, UNOP}, {
|
||||
"-s", FILGZ, UNOP}, {
|
||||
"-t", FILTT, UNOP}, {
|
||||
"-z", STREZ, UNOP}, {
|
||||
"-n", STRNZ, UNOP}, {
|
||||
"-h", FILSYM, UNOP}, /* for backwards compat */
|
||||
{
|
||||
"-O", FILUID, UNOP}, {
|
||||
"-G", FILGID, UNOP}, {
|
||||
"-L", FILSYM, UNOP}, {
|
||||
"-S", FILSOCK, UNOP}, {
|
||||
"=", STREQ, BINOP}, {
|
||||
"!=", STRNE, BINOP}, {
|
||||
"<", STRLT, BINOP}, {
|
||||
">", STRGT, BINOP}, {
|
||||
"-eq", INTEQ, BINOP}, {
|
||||
"-ne", INTNE, BINOP}, {
|
||||
"-ge", INTGE, BINOP}, {
|
||||
"-gt", INTGT, BINOP}, {
|
||||
"-le", INTLE, BINOP}, {
|
||||
"-lt", INTLT, BINOP}, {
|
||||
"-nt", FILNT, BINOP}, {
|
||||
"-ot", FILOT, BINOP}, {
|
||||
"-ef", FILEQ, BINOP}, {
|
||||
"!", UNOT, BUNOP}, {
|
||||
"-a", BAND, BBINOP}, {
|
||||
"-o", BOR, BBINOP}, {
|
||||
"(", LPAREN, PAREN}, {
|
||||
")", RPAREN, PAREN}, {
|
||||
0, 0, 0}
|
||||
};
|
||||
|
||||
static char **t_wp;
|
||||
@@ -158,7 +160,7 @@ static struct t_op const *t_wp_op;
|
||||
static gid_t *group_array = NULL;
|
||||
static int ngroups;
|
||||
|
||||
static enum token t_lex(char* s);
|
||||
static enum token t_lex(char *s);
|
||||
static int oexpr(enum token n);
|
||||
static int aexpr(enum token n);
|
||||
static int nexpr(enum token n);
|
||||
@@ -174,10 +176,9 @@ static int test_eaccess(char *path, int mode);
|
||||
static int is_a_group_member(gid_t gid);
|
||||
static void initialize_group_array(void);
|
||||
|
||||
extern int
|
||||
test_main(int argc, char** argv)
|
||||
extern int test_main(int argc, char **argv)
|
||||
{
|
||||
int res;
|
||||
int res;
|
||||
|
||||
if (strcmp(applet_name, "[") == 0) {
|
||||
if (strcmp(argv[--argc], "]"))
|
||||
@@ -187,29 +188,27 @@ test_main(int argc, char** argv)
|
||||
/* Implement special cases from POSIX.2, section 4.62.4 */
|
||||
switch (argc) {
|
||||
case 1:
|
||||
exit( 1);
|
||||
exit(1);
|
||||
case 2:
|
||||
exit (*argv[1] == '\0');
|
||||
exit(*argv[1] == '\0');
|
||||
case 3:
|
||||
if (argv[1][0] == '!' && argv[1][1] == '\0') {
|
||||
exit (!(*argv[2] == '\0'));
|
||||
exit(!(*argv[2] == '\0'));
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (argv[1][0] != '!' || argv[1][1] != '\0') {
|
||||
if (t_lex(argv[2]),
|
||||
t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
if (t_lex(argv[2]), t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
t_wp = &argv[1];
|
||||
exit (binop() == 0);
|
||||
exit(binop() == 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if (argv[1][0] == '!' && argv[1][1] == '\0') {
|
||||
if (t_lex(argv[3]),
|
||||
t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
if (t_lex(argv[3]), t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
t_wp = &argv[2];
|
||||
exit (!(binop() == 0));
|
||||
exit(!(binop() == 0));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -221,36 +220,31 @@ test_main(int argc, char** argv)
|
||||
if (*t_wp != NULL && *++t_wp != NULL)
|
||||
syntax(*t_wp, "unknown operand");
|
||||
|
||||
return( res);
|
||||
return (res);
|
||||
}
|
||||
|
||||
static void
|
||||
syntax(op, msg)
|
||||
const char *op;
|
||||
const char *msg;
|
||||
static void syntax(const char *op, const char *msg)
|
||||
{
|
||||
if (op && *op)
|
||||
if (op && *op) {
|
||||
error_msg_and_die("%s: %s", op, msg);
|
||||
else
|
||||
} else {
|
||||
error_msg_and_die("%s", msg);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
oexpr(n)
|
||||
enum token n;
|
||||
static int oexpr(enum token n)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = aexpr(n);
|
||||
if (t_lex(*++t_wp) == BOR)
|
||||
if (t_lex(*++t_wp) == BOR) {
|
||||
return oexpr(t_lex(*++t_wp)) || res;
|
||||
}
|
||||
t_wp--;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
aexpr(n)
|
||||
enum token n;
|
||||
static int aexpr(enum token n)
|
||||
{
|
||||
int res;
|
||||
|
||||
@@ -261,23 +255,20 @@ aexpr(n)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
nexpr(n)
|
||||
enum token n; /* token */
|
||||
static int nexpr(enum token n)
|
||||
{
|
||||
if (n == UNOT)
|
||||
return !nexpr(t_lex(*++t_wp));
|
||||
return primary(n);
|
||||
}
|
||||
|
||||
static int
|
||||
primary(n)
|
||||
enum token n;
|
||||
static int primary(enum token n)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (n == EOI)
|
||||
if (n == EOI) {
|
||||
syntax(NULL, "argument expected");
|
||||
}
|
||||
if (n == LPAREN) {
|
||||
res = oexpr(t_lex(*++t_wp));
|
||||
if (t_lex(*++t_wp) != RPAREN)
|
||||
@@ -302,13 +293,12 @@ primary(n)
|
||||
|
||||
if (t_lex(t_wp[1]), t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
return binop();
|
||||
}
|
||||
}
|
||||
|
||||
return strlen(*t_wp) > 0;
|
||||
}
|
||||
|
||||
static int
|
||||
binop()
|
||||
static int binop()
|
||||
{
|
||||
const char *opnd1, *opnd2;
|
||||
struct t_op const *op;
|
||||
@@ -317,9 +307,9 @@ binop()
|
||||
(void) t_lex(*++t_wp);
|
||||
op = t_wp_op;
|
||||
|
||||
if ((opnd2 = *++t_wp) == (char *)0)
|
||||
if ((opnd2 = *++t_wp) == (char *) 0)
|
||||
syntax(op->op_text, "argument expected");
|
||||
|
||||
|
||||
switch (op->op_num) {
|
||||
case STREQ:
|
||||
return strcmp(opnd1, opnd2) == 0;
|
||||
@@ -342,20 +332,17 @@ binop()
|
||||
case INTLT:
|
||||
return getn(opnd1) < getn(opnd2);
|
||||
case FILNT:
|
||||
return newerf (opnd1, opnd2);
|
||||
return newerf(opnd1, opnd2);
|
||||
case FILOT:
|
||||
return olderf (opnd1, opnd2);
|
||||
return olderf(opnd1, opnd2);
|
||||
case FILEQ:
|
||||
return equalf (opnd1, opnd2);
|
||||
return equalf(opnd1, opnd2);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
filstat(nm, mode)
|
||||
char *nm;
|
||||
enum token mode;
|
||||
static int filstat(char *nm, enum token mode)
|
||||
{
|
||||
struct stat s;
|
||||
unsigned int i;
|
||||
@@ -370,7 +357,7 @@ filstat(nm, mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (stat(nm, &s) != 0)
|
||||
if (stat(nm, &s) != 0)
|
||||
return 0;
|
||||
|
||||
switch (mode) {
|
||||
@@ -427,21 +414,19 @@ filstat(nm, mode)
|
||||
return 1;
|
||||
}
|
||||
|
||||
filetype:
|
||||
filetype:
|
||||
return ((s.st_mode & S_IFMT) == i);
|
||||
|
||||
filebit:
|
||||
filebit:
|
||||
return ((s.st_mode & i) != 0);
|
||||
}
|
||||
|
||||
static enum token
|
||||
t_lex(s)
|
||||
char *s;
|
||||
static enum token t_lex(char *s)
|
||||
{
|
||||
struct t_op const *op = ops;
|
||||
|
||||
if (s == 0) {
|
||||
t_wp_op = (struct t_op *)0;
|
||||
t_wp_op = (struct t_op *) 0;
|
||||
return EOI;
|
||||
}
|
||||
while (op->op_text) {
|
||||
@@ -451,14 +436,12 @@ t_lex(s)
|
||||
}
|
||||
op++;
|
||||
}
|
||||
t_wp_op = (struct t_op *)0;
|
||||
t_wp_op = (struct t_op *) 0;
|
||||
return OPERAND;
|
||||
}
|
||||
|
||||
/* atoi with error detection */
|
||||
static int
|
||||
getn(s)
|
||||
const char *s;
|
||||
static int getn(const char *s)
|
||||
{
|
||||
char *p;
|
||||
long r;
|
||||
@@ -467,69 +450,57 @@ getn(s)
|
||||
r = strtol(s, &p, 10);
|
||||
|
||||
if (errno != 0)
|
||||
error_msg_and_die("%s: out of range", s);
|
||||
error_msg_and_die("%s: out of range", s);
|
||||
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
|
||||
p++;
|
||||
|
||||
if (*p)
|
||||
error_msg_and_die("%s: bad number", s);
|
||||
error_msg_and_die("%s: bad number", s);
|
||||
|
||||
return (int) r;
|
||||
}
|
||||
|
||||
static int
|
||||
newerf (f1, f2)
|
||||
const char *f1, *f2;
|
||||
static int newerf(const char *f1, const char *f2)
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_mtime > b2.st_mtime);
|
||||
return (stat(f1, &b1) == 0 &&
|
||||
stat(f2, &b2) == 0 && b1.st_mtime > b2.st_mtime);
|
||||
}
|
||||
|
||||
static int
|
||||
olderf (f1, f2)
|
||||
const char *f1, *f2;
|
||||
static int olderf(const char *f1, const char *f2)
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_mtime < b2.st_mtime);
|
||||
return (stat(f1, &b1) == 0 &&
|
||||
stat(f2, &b2) == 0 && b1.st_mtime < b2.st_mtime);
|
||||
}
|
||||
|
||||
static int
|
||||
equalf (f1, f2)
|
||||
const char *f1, *f2;
|
||||
static int equalf(const char *f1, const char *f2)
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_dev == b2.st_dev &&
|
||||
b1.st_ino == b2.st_ino);
|
||||
return (stat(f1, &b1) == 0 &&
|
||||
stat(f2, &b2) == 0 &&
|
||||
b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino);
|
||||
}
|
||||
|
||||
/* Do the same thing access(2) does, but use the effective uid and gid,
|
||||
and don't make the mistake of telling root that any file is
|
||||
executable. */
|
||||
static int
|
||||
test_eaccess (path, mode)
|
||||
char *path;
|
||||
int mode;
|
||||
static int test_eaccess(char *path, int mode)
|
||||
{
|
||||
struct stat st;
|
||||
unsigned int euid = geteuid();
|
||||
|
||||
if (stat (path, &st) < 0)
|
||||
if (stat(path, &st) < 0)
|
||||
return (-1);
|
||||
|
||||
if (euid == 0) {
|
||||
/* Root can read or write any file. */
|
||||
if (mode != X_OK)
|
||||
return (0);
|
||||
return (0);
|
||||
|
||||
/* Root can execute any file that has any one of the execute
|
||||
bits set. */
|
||||
@@ -537,9 +508,9 @@ int mode;
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (st.st_uid == euid) /* owner */
|
||||
if (st.st_uid == euid) /* owner */
|
||||
mode <<= 6;
|
||||
else if (is_a_group_member (st.st_gid))
|
||||
else if (is_a_group_member(st.st_gid))
|
||||
mode <<= 3;
|
||||
|
||||
if (st.st_mode & mode)
|
||||
@@ -548,8 +519,7 @@ int mode;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static void
|
||||
initialize_group_array ()
|
||||
static void initialize_group_array()
|
||||
{
|
||||
ngroups = getgroups(0, NULL);
|
||||
group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
|
||||
@@ -557,9 +527,7 @@ initialize_group_array ()
|
||||
}
|
||||
|
||||
/* Return non-zero if GID is one that we have in our groups list. */
|
||||
static int
|
||||
is_a_group_member (gid)
|
||||
gid_t gid;
|
||||
static int is_a_group_member(gid_t gid)
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -568,7 +536,7 @@ gid_t gid;
|
||||
return (1);
|
||||
|
||||
if (ngroups == 0)
|
||||
initialize_group_array ();
|
||||
initialize_group_array();
|
||||
|
||||
/* Search through the list looking for GID. */
|
||||
for (i = 0; i < ngroups; i++)
|
||||
|
||||
+6
-4
@@ -53,12 +53,14 @@ extern int touch_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
while (argc > 0) {
|
||||
fd = open(*argv, (create == FALSE) ? O_RDWR : O_RDWR | O_CREAT,
|
||||
fd = open(*argv, create ? O_RDWR | O_CREAT : O_RDWR,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
if (fd < 0) {
|
||||
if (create == FALSE && errno == ENOENT)
|
||||
return EXIT_SUCCESS;
|
||||
else {
|
||||
if (! create && errno == ENOENT) {
|
||||
argc--;
|
||||
argv++;
|
||||
continue;
|
||||
} else {
|
||||
perror_msg_and_die("%s", *argv);
|
||||
}
|
||||
}
|
||||
|
||||
+51
-95
@@ -31,126 +31,82 @@
|
||||
|
||||
/* Busyboxed by Erik Andersen */
|
||||
|
||||
/* Further size reductions by Glenn McGrath and Manuel Novoa III. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#if defined (HAVE_SYSINFO) && defined (HAVE_SYS_SYSTEMINFO_H)
|
||||
# include <sys/systeminfo.h>
|
||||
#endif
|
||||
#include <getopt.h>
|
||||
#include "busybox.h"
|
||||
|
||||
static void print_element(unsigned int mask, char *element);
|
||||
|
||||
/* Values that are bitwise or'd into `toprint'. */
|
||||
/* Operating system name. */
|
||||
static const int PRINT_SYSNAME = 1;
|
||||
|
||||
/* Node name on a communications network. */
|
||||
static const int PRINT_NODENAME = 2;
|
||||
|
||||
/* Operating system release. */
|
||||
static const int PRINT_RELEASE = 4;
|
||||
|
||||
/* Operating system version. */
|
||||
static const int PRINT_VERSION = 8;
|
||||
|
||||
/* Machine hardware name. */
|
||||
static const int PRINT_MACHINE = 16;
|
||||
|
||||
/* Host processor type. */
|
||||
static const int PRINT_PROCESSOR = 32;
|
||||
|
||||
/* Mask indicating which elements of the name to print. */
|
||||
static unsigned char toprint;
|
||||
typedef struct {
|
||||
struct utsname name;
|
||||
char processor[8]; /* for "unknown" */
|
||||
} uname_info_t;
|
||||
|
||||
static const char options[] = "snrvmpa";
|
||||
static const char flags[] = "\x01\x02\x04\x08\x10\x20\x3f";
|
||||
static const unsigned short int utsname_offset[] = {
|
||||
offsetof(uname_info_t,name.sysname),
|
||||
offsetof(uname_info_t,name.nodename),
|
||||
offsetof(uname_info_t,name.release),
|
||||
offsetof(uname_info_t,name.version),
|
||||
offsetof(uname_info_t,name.machine),
|
||||
offsetof(uname_info_t,processor)
|
||||
};
|
||||
|
||||
int uname_main(int argc, char **argv)
|
||||
{
|
||||
struct utsname name;
|
||||
char processor[256];
|
||||
uname_info_t uname_info;
|
||||
|
||||
#if defined(__sparc__) && defined(__linux__)
|
||||
char *fake_sparc = getenv("FAKE_SPARC");
|
||||
#endif
|
||||
|
||||
toprint = 0;
|
||||
const unsigned short int *delta;
|
||||
int opt;
|
||||
char toprint = 0;
|
||||
|
||||
/* Parse any options */
|
||||
//fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
toprint |= PRINT_SYSNAME;
|
||||
break;
|
||||
case 'n':
|
||||
toprint |= PRINT_NODENAME;
|
||||
break;
|
||||
case 'r':
|
||||
toprint |= PRINT_RELEASE;
|
||||
break;
|
||||
case 'v':
|
||||
toprint |= PRINT_VERSION;
|
||||
break;
|
||||
case 'm':
|
||||
toprint |= PRINT_MACHINE;
|
||||
break;
|
||||
case 'p':
|
||||
toprint |= PRINT_PROCESSOR;
|
||||
break;
|
||||
case 'a':
|
||||
toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
|
||||
PRINT_PROCESSOR | PRINT_VERSION |
|
||||
PRINT_MACHINE);
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
while ((opt = getopt(argc, argv, options)) != -1) {
|
||||
const char *p = strchr(options,opt);
|
||||
if (p == NULL) {
|
||||
show_usage();
|
||||
}
|
||||
toprint |= flags[(int)(p-options)];
|
||||
}
|
||||
|
||||
if (toprint == 0)
|
||||
toprint = PRINT_SYSNAME;
|
||||
if (toprint == 0) {
|
||||
toprint = flags[0]; /* sysname */
|
||||
}
|
||||
|
||||
if (uname(&name) == -1)
|
||||
perror_msg("cannot get system name");
|
||||
|
||||
#if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
|
||||
if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
|
||||
perror_msg("cannot get processor type");
|
||||
}
|
||||
|
||||
#else
|
||||
strcpy(processor, "unknown");
|
||||
#endif
|
||||
if (uname(&uname_info.name) == -1) {
|
||||
error_msg_and_die("cannot get system name");
|
||||
}
|
||||
|
||||
#if defined(__sparc__) && defined(__linux__)
|
||||
if (fake_sparc != NULL
|
||||
&& (fake_sparc[0] == 'y'
|
||||
|| fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
|
||||
if ((fake_sparc != NULL)
|
||||
&& ((fake_sparc[0] == 'y')
|
||||
|| (fake_sparc[0] == 'Y'))) {
|
||||
strcpy(uname_info.name.machine, "sparc");
|
||||
}
|
||||
#endif
|
||||
|
||||
print_element(PRINT_SYSNAME, name.sysname);
|
||||
print_element(PRINT_NODENAME, name.nodename);
|
||||
print_element(PRINT_RELEASE, name.release);
|
||||
print_element(PRINT_VERSION, name.version);
|
||||
print_element(PRINT_MACHINE, name.machine);
|
||||
print_element(PRINT_PROCESSOR, processor);
|
||||
strcpy(uname_info.processor, "unknown");
|
||||
|
||||
delta=utsname_offset;
|
||||
do {
|
||||
if (toprint & 1) {
|
||||
printf(((char *)(&uname_info)) + *delta);
|
||||
if (toprint > 1) {
|
||||
putchar(' ');
|
||||
}
|
||||
}
|
||||
++delta;
|
||||
} while (toprint >>= 1);
|
||||
putchar('\n');
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* If the name element set in MASK is selected for printing in `toprint',
|
||||
print ELEMENT; then print a space unless it is the last element to
|
||||
be printed, in which case print a newline. */
|
||||
|
||||
static void print_element(unsigned int mask, char *element)
|
||||
{
|
||||
if (toprint & mask) {
|
||||
toprint &= ~mask;
|
||||
printf("%s%c", element, toprint ? ' ' : '\n');
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
/*
|
||||
* Mini usleep implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
#include "pwd.h"
|
||||
#include "grp.h"
|
||||
#include "pwd_.h"
|
||||
#include "grp_.h"
|
||||
|
||||
/*struct passwd *getpwnam();*/
|
||||
|
||||
|
||||
+24
-55
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -28,7 +29,7 @@
|
||||
#include "busybox.h"
|
||||
|
||||
/* Conversion table. for base 64 */
|
||||
static char tbl_base64[64] = {
|
||||
static char tbl_base64[65] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
@@ -36,10 +37,11 @@ static char tbl_base64[64] = {
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', '+', '/'
|
||||
'4', '5', '6', '7', '8', '9', '+', '/',
|
||||
'=' /* termination character */
|
||||
};
|
||||
|
||||
static char tbl_std[64] = {
|
||||
static char tbl_std[65] = {
|
||||
'`', '!', '"', '#', '$', '%', '&', '\'',
|
||||
'(', ')', '*', '+', ',', '-', '.', '/',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
@@ -47,7 +49,8 @@ static char tbl_std[64] = {
|
||||
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
||||
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||
'X', 'Y', 'Z', '[', '\\', ']', '^', '_'
|
||||
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
|
||||
'`' /* termination character */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -71,10 +74,10 @@ static void uuencode (const char *s, const char *store, const int length, const
|
||||
}
|
||||
/* Pad the result if necessary... */
|
||||
if (i == length + 1) {
|
||||
*(p - 1) = '=';
|
||||
*(p - 1) = tbl[64];
|
||||
}
|
||||
else if (i == length + 2) {
|
||||
*(p - 1) = *(p - 2) = '=';
|
||||
*(p - 1) = *(p - 2) = tbl[64];
|
||||
}
|
||||
/* ...and zero-terminate it. */
|
||||
*p = '\0';
|
||||
@@ -82,8 +85,9 @@ static void uuencode (const char *s, const char *store, const int length, const
|
||||
|
||||
int uuencode_main(int argc, char **argv)
|
||||
{
|
||||
const int src_buf_size = 60; // This *MUST* be a multiple of 3
|
||||
const int src_buf_size = 45;// This *MUST* be a multiple of 3
|
||||
const int dst_buf_size = 4 * ((src_buf_size + 2) / 3);
|
||||
int write_size = dst_buf_size;
|
||||
RESERVE_CONFIG_BUFFER(src_buf, src_buf_size + 1);
|
||||
RESERVE_CONFIG_BUFFER(dst_buf, dst_buf_size + 1);
|
||||
struct stat stat_buf;
|
||||
@@ -92,10 +96,6 @@ int uuencode_main(int argc, char **argv)
|
||||
size_t size;
|
||||
mode_t mode;
|
||||
int opt;
|
||||
int column = 0;
|
||||
int write_size = 0;
|
||||
int remaining;
|
||||
int buffer_offset = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, "m")) != -1) {
|
||||
switch (opt) {
|
||||
@@ -126,53 +126,22 @@ int uuencode_main(int argc, char **argv)
|
||||
printf("begin%s %o %s", tbl == tbl_std ? "" : "-base64", mode, argv[argc - 1]);
|
||||
|
||||
while ((size = fread(src_buf, 1, src_buf_size, src_stream)) > 0) {
|
||||
if (size != src_buf_size) {
|
||||
/* write_size is always 60 until the last line */
|
||||
write_size=(4 * ((size + 2) / 3));
|
||||
/* pad with 0s so we can just encode extra bits */
|
||||
memset(&src_buf[size], 0, src_buf_size - size);
|
||||
}
|
||||
/* Encode the buffer we just read in */
|
||||
uuencode(src_buf, dst_buf, size, tbl);
|
||||
|
||||
/* Write the buffer to stdout, wrapping at 60 chars.
|
||||
* This looks overly complex, but it gets tricky as
|
||||
* the line has to continue to wrap correctly if we
|
||||
* have to refill the buffer
|
||||
*
|
||||
* Improvments most welcome
|
||||
*/
|
||||
|
||||
/* Initialise values for the new buffer */
|
||||
remaining = 4 * ((size + 2) / 3);
|
||||
buffer_offset = 0;
|
||||
|
||||
/* Write the buffer to stdout, wrapping at 60 chars
|
||||
* starting from the column the last buffer ran out
|
||||
*/
|
||||
do {
|
||||
if (remaining > (60 - column)) {
|
||||
write_size = 60 - column;
|
||||
}
|
||||
else if (remaining < 60) {
|
||||
write_size = remaining;
|
||||
} else {
|
||||
write_size = 60;
|
||||
}
|
||||
|
||||
/* Setup a new row if required */
|
||||
if (column == 0) {
|
||||
putchar('\n');
|
||||
if (tbl == tbl_std) {
|
||||
putchar('M');
|
||||
}
|
||||
}
|
||||
/* Write to the 60th column */
|
||||
if (fwrite(&dst_buf[buffer_offset], 1, write_size, stdout) != write_size) {
|
||||
perror("Couldnt finish writing");
|
||||
}
|
||||
/* Update variables based on last write */
|
||||
buffer_offset += write_size;
|
||||
remaining -= write_size;
|
||||
column += write_size;
|
||||
if (column % 60 == 0) {
|
||||
column = 0;
|
||||
}
|
||||
} while (remaining > 0);
|
||||
putchar('\n');
|
||||
if (tbl == tbl_std) {
|
||||
putchar(tbl[size]);
|
||||
}
|
||||
if (fwrite(dst_buf, 1, write_size, stdout) != write_size) {
|
||||
perror("Couldnt finish writing");
|
||||
}
|
||||
}
|
||||
printf(tbl == tbl_std ? "\n`\nend\n" : "\n====\n");
|
||||
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini watch implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2001 by Michael Habermann <mhabermann@gmx.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/* getopt not needed */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "busybox.h"
|
||||
|
||||
extern int watch_main(int argc, char **argv)
|
||||
{
|
||||
const char date_argv[2][10] = { "date", "" };
|
||||
const int header_len = 40;
|
||||
char header[header_len + 1];
|
||||
int period = 2;
|
||||
char **cargv;
|
||||
int cargc;
|
||||
pid_t pid;
|
||||
int old_stdout;
|
||||
int i;
|
||||
|
||||
if (argc < 2) {
|
||||
show_usage();
|
||||
} else {
|
||||
cargv = argv + 1;
|
||||
cargc = argc - 1;
|
||||
|
||||
/* don't use getopt, because it permutes the arguments */
|
||||
if (argc >= 3 && !strcmp(argv[1], "-n")) {
|
||||
period = strtol(argv[2], NULL, 10);
|
||||
if (period < 1)
|
||||
show_usage();
|
||||
cargv += 2;
|
||||
cargc -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* create header */
|
||||
snprintf(header, header_len, "Every %ds: ", period);
|
||||
for (i = 0; i < cargc && (strlen(header) + strlen(cargv[i]) < header_len);
|
||||
i++) {
|
||||
strcat(header, cargv[i]);
|
||||
strcat(header, " ");
|
||||
}
|
||||
|
||||
/* fill with blanks */
|
||||
for (i = strlen(header); i < header_len; i++)
|
||||
header[i] = ' ';
|
||||
|
||||
header[header_len - 1] = '\0';
|
||||
|
||||
|
||||
/* thanks to lye, who showed me how to redirect stdin/stdout */
|
||||
old_stdout = dup(1);
|
||||
|
||||
while (1) {
|
||||
printf("\033[H\033[J%s", header);
|
||||
date_main(1, (char **) date_argv);
|
||||
printf("\n");
|
||||
|
||||
pid = vfork(); /* vfork, because of ucLinux */
|
||||
if (pid > 0) {
|
||||
//parent
|
||||
wait(0);
|
||||
sleep(period);
|
||||
} else if (0 == pid) {
|
||||
//child
|
||||
close(1);
|
||||
dup(old_stdout);
|
||||
if (execvp(*cargv, cargv))
|
||||
error_msg_and_die("Couldn't run command\n");
|
||||
} else {
|
||||
error_msg_and_die("Couldn't vfork\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+79
-57
@@ -26,40 +26,59 @@
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
static int total_lines, total_words, total_chars, max_length;
|
||||
static int print_lines, print_words, print_chars, print_length;
|
||||
enum print_e {
|
||||
print_lines = 1,
|
||||
print_words = 2,
|
||||
print_chars = 4,
|
||||
print_length = 8
|
||||
};
|
||||
|
||||
static void print_counts(int lines, int words, int chars, int length,
|
||||
const char *name)
|
||||
static unsigned int total_lines = 0;
|
||||
static unsigned int total_words = 0;
|
||||
static unsigned int total_chars = 0;
|
||||
static unsigned int max_length = 0;
|
||||
static char print_type = 0;
|
||||
|
||||
static void print_counts(const unsigned int lines, const unsigned int words,
|
||||
const unsigned int chars, const unsigned int length, const char *name)
|
||||
{
|
||||
char const *space = "";
|
||||
int output = 0;
|
||||
|
||||
if (print_lines) {
|
||||
if (print_type & print_lines) {
|
||||
printf("%7d", lines);
|
||||
space = " ";
|
||||
output++;
|
||||
}
|
||||
if (print_words) {
|
||||
printf("%s%7d", space, words);
|
||||
space = " ";
|
||||
if (print_type & print_words) {
|
||||
if (output++)
|
||||
putchar(' ');
|
||||
printf("%7d", words);
|
||||
}
|
||||
if (print_chars) {
|
||||
printf("%s%7d", space, chars);
|
||||
space = " ";
|
||||
if (print_type & print_chars) {
|
||||
if (output++)
|
||||
putchar(' ');
|
||||
printf("%7d", chars);
|
||||
}
|
||||
if (print_length)
|
||||
printf("%s%7d", space, length);
|
||||
if (*name)
|
||||
if (print_type & print_length) {
|
||||
if (output++)
|
||||
putchar(' ');
|
||||
printf("%7d", length);
|
||||
}
|
||||
if (*name) {
|
||||
printf(" %s", name);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static void wc_file(FILE * file, const char *name)
|
||||
{
|
||||
int lines, words, chars, length;
|
||||
int in_word = 0, linepos = 0;
|
||||
unsigned int lines = 0;
|
||||
unsigned int words = 0;
|
||||
unsigned int chars = 0;
|
||||
unsigned int length = 0;
|
||||
unsigned int linepos = 0;
|
||||
char in_word = 0;
|
||||
int c;
|
||||
|
||||
lines = words = chars = length = 0;
|
||||
while ((c = getc(file)) != EOF) {
|
||||
chars++;
|
||||
switch (c) {
|
||||
@@ -77,7 +96,7 @@ static void wc_file(FILE * file, const char *name)
|
||||
case ' ':
|
||||
linepos++;
|
||||
case '\v':
|
||||
word_separator:
|
||||
word_separator:
|
||||
if (in_word) {
|
||||
in_word = 0;
|
||||
words++;
|
||||
@@ -89,68 +108,71 @@ static void wc_file(FILE * file, const char *name)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (linepos > length)
|
||||
if (linepos > length) {
|
||||
length = linepos;
|
||||
if (in_word)
|
||||
}
|
||||
if (in_word) {
|
||||
words++;
|
||||
}
|
||||
print_counts(lines, words, chars, length, name);
|
||||
total_lines += lines;
|
||||
total_words += words;
|
||||
total_chars += chars;
|
||||
if (length > max_length)
|
||||
if (length > max_length) {
|
||||
max_length = length;
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
int wc_main(int argc, char **argv)
|
||||
{
|
||||
FILE *file;
|
||||
unsigned int num_files_counted = 0;
|
||||
int opt, status = EXIT_SUCCESS;
|
||||
|
||||
total_lines = total_words = total_chars = max_length = 0;
|
||||
print_lines = print_words = print_chars = print_length = 0;
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "clLw")) > 0) {
|
||||
switch (opt) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
print_chars = 1;
|
||||
print_type |= print_chars;
|
||||
break;
|
||||
case 'l':
|
||||
print_lines = 1;
|
||||
print_type |= print_lines;
|
||||
break;
|
||||
case 'L':
|
||||
print_length = 1;
|
||||
print_type |= print_length;
|
||||
break;
|
||||
case 'w':
|
||||
print_words = 1;
|
||||
print_type |= print_words;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (!print_lines && !print_words && !print_chars && !print_length)
|
||||
print_lines = print_words = print_chars = 1;
|
||||
|
||||
if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
|
||||
wc_file(stdin, "");
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
while (optind < argc) {
|
||||
if ((file = wfopen(argv[optind], "r")) != NULL)
|
||||
wc_file(file, argv[optind]);
|
||||
else
|
||||
status = EXIT_FAILURE;
|
||||
num_files_counted++;
|
||||
optind++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_files_counted > 1)
|
||||
print_counts(total_lines, total_words, total_chars,
|
||||
max_length, "total");
|
||||
if (print_type == 0) {
|
||||
print_type = print_lines | print_words | print_chars;
|
||||
}
|
||||
|
||||
return status;
|
||||
if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
|
||||
wc_file(stdin, "");
|
||||
} else {
|
||||
unsigned short num_files_counted = 0;
|
||||
while (optind < argc) {
|
||||
if (print_type == print_chars) {
|
||||
struct stat statbuf;
|
||||
stat(argv[optind], &statbuf);
|
||||
print_counts(0, 0, statbuf.st_size, 0, argv[optind]);
|
||||
total_chars += statbuf.st_size;
|
||||
} else {
|
||||
FILE *file;
|
||||
file = xfopen(argv[optind], "r");
|
||||
wc_file(file, argv[optind]);
|
||||
fclose(file);
|
||||
}
|
||||
optind++;
|
||||
num_files_counted++;
|
||||
}
|
||||
if (num_files_counted > 1) {
|
||||
print_counts(total_lines, total_words, total_chars, max_length, "total");
|
||||
}
|
||||
}
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*----------------------------------------------------------------------
|
||||
* Mini who is used to display user name, login time,
|
||||
* idle time and host name.
|
||||
*
|
||||
* Author: Da Chen <dchen@ayrnetworks.com>
|
||||
*
|
||||
* This is a free document; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation:
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* Copyright (c) 2002 AYR Networks, Inc.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <utmp.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <busybox.h>
|
||||
|
||||
extern int who_main(int argc, char **argv)
|
||||
{
|
||||
struct utmp *ut;
|
||||
struct stat st;
|
||||
int devlen, len;
|
||||
time_t now, idle;
|
||||
|
||||
if (argc > 1)
|
||||
show_usage();
|
||||
|
||||
setutent();
|
||||
devlen = sizeof("/dev/") - 1;
|
||||
printf("USER TTY IDLE FROM HOST\n");
|
||||
|
||||
while ((ut = getutent()) != NULL) {
|
||||
char name[40];
|
||||
|
||||
if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) {
|
||||
len = strlen(ut->ut_line);
|
||||
if (ut->ut_line[0] == '/') {
|
||||
strncpy(name, ut->ut_line, len);
|
||||
name[len] = '\0';
|
||||
strcpy(ut->ut_line, ut->ut_line + devlen);
|
||||
} else {
|
||||
strcpy(name, "/dev/");
|
||||
strncpy(name+devlen, ut->ut_line, len);
|
||||
name[devlen+len] = '\0';
|
||||
}
|
||||
|
||||
printf("%-10s %-8s ", ut->ut_user, ut->ut_line);
|
||||
|
||||
if (stat(name, &st) == 0) {
|
||||
now = time(NULL);
|
||||
idle = now - st.st_atime;
|
||||
|
||||
if (idle < 60)
|
||||
printf("00:00m ");
|
||||
else if (idle < (60 * 60))
|
||||
printf("00:%02dm ", (int)(idle / 60));
|
||||
else if (idle < (24 * 60 * 60))
|
||||
printf("%02d:%02dm ", (int)(idle / (60 * 60)),
|
||||
(int)(idle % (60 * 60)) / 60);
|
||||
else if (idle < (24 * 60 * 60 * 365))
|
||||
printf("%03ddays ", (int)(idle / (24 * 60 * 60)));
|
||||
else
|
||||
printf("%02dyears ", (int) (idle / (24 * 60 * 60 * 365)));
|
||||
} else
|
||||
printf("%-8s ", "?");
|
||||
|
||||
printf("%-12.12s %s\n", ctime(&(ut->ut_tv.tv_sec)) + 4, ut->ut_host);
|
||||
}
|
||||
}
|
||||
endutent();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -35,8 +35,7 @@ extern int whoami_main(int argc, char **argv)
|
||||
if (argc > 1)
|
||||
show_usage();
|
||||
|
||||
my_getpwuid(user, uid);
|
||||
if (*user) {
|
||||
if (my_getpwuid(user, uid)) {
|
||||
puts(user);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
This package was debianized by Erik Andersen <andersee@debian.org> on
|
||||
Sun, 18 Jun 2000 23:31:02 -0600
|
||||
|
||||
It was downloaded from ftp://ftp.lineo.com/pub/busybox
|
||||
HomePage is at: http://busybox.lineo.com/
|
||||
It was downloaded from ftp://ftp.busybox.net/busybox
|
||||
HomePage is at: http://busybox.net/
|
||||
|
||||
Copyright: GPL
|
||||
Vendored
+6
-6
@@ -42,8 +42,8 @@ install: build
|
||||
#(cd $(bbbd); $(MAKE) "CONFIG_SRC_DIR=../../" "PREFIX=../../$(bb)" install)
|
||||
mkdir -p $(bb)/bin/
|
||||
cp $(bbbd)/busybox $(bb)/bin/busybox
|
||||
mkdir -p $(bb)/usr/share/doc/busybox/busybox.lineo.com
|
||||
cp $(bbbd)/docs/busybox.lineo.com/BusyBox.html $(bb)/usr/share/doc/busybox/busybox.lineo.com/
|
||||
mkdir -p $(bb)/usr/share/doc/busybox/busybox.net
|
||||
cp $(bbbd)/docs/busybox.net/BusyBox.html $(bb)/usr/share/doc/busybox/busybox.net/
|
||||
mkdir -p $(bb)/usr/share/man/man1
|
||||
cp $(bbbd)/docs/BusyBox.1 $(bb)/usr/share/man/man1/busybox.1
|
||||
|
||||
@@ -67,8 +67,8 @@ install-static: build
|
||||
#(cd $(bbsbd); $(MAKE) "CONFIG_SRC_DIR=../../" "PREFIX=../../$(bbs)" install)
|
||||
mkdir -p $(bbs)/bin/
|
||||
cp $(bbsbd)/busybox $(bbs)/bin/busybox
|
||||
mkdir -p $(bbs)/usr/share/doc/busybox-static/busybox.lineo.com
|
||||
cp $(bbsbd)/docs/busybox.lineo.com/BusyBox.html $(bbs)/usr/share/doc/busybox-static/busybox.lineo.com/
|
||||
mkdir -p $(bbs)/usr/share/doc/busybox-static/busybox.net
|
||||
cp $(bbsbd)/docs/busybox.net/BusyBox.html $(bbs)/usr/share/doc/busybox-static/busybox.net/
|
||||
mkdir -p $(bbs)/usr/share/man/man1/
|
||||
cp $(bbsbd)/docs/BusyBox.1 $(bbs)/usr/share/man/man1/busybox.1
|
||||
|
||||
@@ -130,7 +130,7 @@ busybox: install
|
||||
dh_installdirs
|
||||
dh_installdocs -p$@ $(bbbd)/docs/BusyBox.txt \
|
||||
$(bbbd)/docs/BusyBox.html docs/style-guide.txt \
|
||||
docs/busybox.lineo.com AUTHORS README TODO
|
||||
docs/busybox.net AUTHORS README TODO
|
||||
rm -rf `find $(bb) -name CVS`
|
||||
rm -f `find $(bb) -name .cvsignore`
|
||||
dh_installchangelogs -p$@ Changelog
|
||||
@@ -152,7 +152,7 @@ busybox-static: do_static
|
||||
dh_installdirs
|
||||
dh_installdocs -p$@ $(bbsbd)/docs/BusyBox.txt \
|
||||
$(bbsbd)/docs/BusyBox.html docs/style-guide.txt \
|
||||
docs/busybox.lineo.com AUTHORS README TODO
|
||||
docs/busybox.net AUTHORS README TODO
|
||||
rm -rf `find $(bbs) -name CVS`
|
||||
rm -f `find $(bbs) -name .cvsignore`
|
||||
dh_installchangelogs -p$@ Changelog
|
||||
|
||||
Loaded 100 of 377 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user