Compare commits

...
280 Commits
Author SHA1 Message Date
Eric Andersen db1df5ebeb last_patch64 from vodz:
The following usage from original user:
    $ ./busybox swapon -a
    Have typo problem:
    swapon: swapon: Operation not permitted

    But regular version:
    swapon: /dev/hda5: Operation not permitted

    Patch attached, reduced 9 bytes and advanced
    exit code also.
2002-10-26 10:27:42 +00:00
Eric Andersen fda2b7ff47 A patch from Jouni Malinen to avoid some buffer overflows in vi,
closing bug #1270
2002-10-26 10:19:19 +00:00
Eric Andersen 12f834ccfc Ivan Popov noticed that handling of PREFIX was bad.
-Erik
2002-10-26 10:17:24 +00:00
Eric Andersen 18921bd00d A bugfix from Danny Lepage:
It seems that under busybox unstable, "tar -c -f - blabla" create
    a tar file named "-" instead of writing to stdout.

    The included patch should fix this.
2002-10-26 10:05:37 +00:00
Eric Andersen 5ad22c933c This patch from Magnus Damm fixed a long standing problem
with freeing memory.
2002-10-25 12:14:02 +00:00
Eric Andersen 09da627a23 Fix warning 2002-10-22 22:15:33 +00:00
Eric Andersen 080ddc1c19 mjn3 noticed that crond and crontab had #include <pwd.h> and #include <grp.h>
but this conflicted with the internal pwd_.h and grp_.h.  Removing these
headers is correct, since the correct pwd/grp headers will be included via
busybox.h
 -Erik
2002-10-22 20:08:51 +00:00
Eric Andersen 5e02c67331 vodz forgot to include the suid field 2002-10-22 20:01:08 +00:00
Eric Andersen fe5b1a9f3c Apply patch from bug #1278 -- fix usage message for the
start_stop_daemon applet.
2002-10-22 19:21:48 +00:00
Eric Andersen 72e1212ad8 vodz writes:
Oops... Last patch 63 have small typo (stable/devel) mixing.
    Attached patch removing lines from TODO also :)
2002-10-22 19:19:13 +00:00
Eric Andersen f02c26f1ef I committed the fflush in the wrong spot. I should go to bed
earlier so I don't screw up such easy stuff.
 -Erik
2002-10-22 19:15:43 +00:00
Eric Andersen f6f7bfb8e0 last_patch63 from vodz: add in crond and crontab applets 2002-10-22 12:24:59 +00:00
Eric Andersen 44608e9693 Patch last_pach62 from vodz. This patch moves all the /proc parsing
code into libbb so it can be shared by ps, top, etc, saving over 1.5k.
2002-10-22 12:21:15 +00:00
Eric Andersen 1887b0478f Apply last_patch51_3 from vodz 2002-10-22 11:58:59 +00:00
Eric Andersen 5956028f6f Be absurdly careful about flushing stdout. 2002-10-22 11:45:20 +00:00
Glenn L McGrath 9ffd5776eb Move unzip.c uncompress.c from libbb to archiveal/libunarchive 2002-10-22 01:07:32 +00:00
Glenn L McGrath 0d53ebdc52 gz_open is used anymore, use inflate directly, see how its done in get_header_tar_gz 2002-10-21 06:29:55 +00:00
Glenn L McGrath 4298e87fa5 Dont try and make the "/" directory 2002-10-19 23:56:41 +00:00
Glenn L McGrath 61b7904afd Update dpkg to use new unarchive code 2002-10-19 10:40:55 +00:00
Glenn L McGrath c5c1a8a112 Fix exclude/include problem 2002-10-19 06:19:22 +00:00
Glenn L McGrath 05fa661123 Find a string in a list 2002-10-19 05:10:51 +00:00
Glenn L McGrath 25bca9566d Remove entries from the accept list as they are matched so we can determine if any files that were specified in the list wernt found. 2002-10-19 02:18:51 +00:00
Glenn L McGrath 98f824aa22 Dont use absolute pathname (dunno why i did that), fix tar filename/stdin problems 2002-10-19 00:46:35 +00:00
Glenn L McGrath 934805aec1 Put bac kthe code that handles cases where a '-' wasnt specified prior to the options. 2002-10-18 23:59:40 +00:00
Eric Andersen 2a2ab1479c Fix an obvious thinko
-Erik
2002-10-18 22:31:02 +00:00
Eric Andersen 431a18497d disambiguate a test 2002-10-18 22:18:10 +00:00
Eric Andersen 31f9747a23 Fix needless formatting differences vs modutils 2002-10-18 22:14:07 +00:00
Eric Andersen d69e31fb93 Fix needless difference vs GNU 2002-10-18 22:13:23 +00:00
Russ Dill 1977a60de4 missed add for udhcp 2002-10-14 21:47:07 +00:00
Russ Dill 61fb48930f added full udhcp integration 2002-10-14 21:41:28 +00:00
Eric Andersen 9060a73159 Doh! I screwed up applying vodz' patch.
-Erik
2002-10-12 04:16:08 +00:00
Eric Andersen e8a90fb2bc After thinking about it, I think this patch from Matt Kraai is probably the
best way to go.  Sysvinit does not provide a controlling tty since it doesn't
even try to open ttys for apps.  We do.  So we should _try_ to provide a
controlling tty if possible, but we needn't freak out if it doesn't work.  This
way we won't need to use openvt or similar, we'll just have init do the Right
Thing(tm).
2002-10-12 04:05:48 +00:00
Eric Andersen 71ae64bdc6 last_patch61 from vodz:
New complex patch for decrease size devel version. Requires previous patch.
    Also removed small problems from dutmp and tar applets.
Also includes vodz' last_patch61_2:
    Last patch correcting comment for #endif and more integrated
    with libbb (very reduce size if used "cat" applet also).
    Requires last_patch61 for modutils/config.in.
2002-10-10 04:20:21 +00:00
Eric Andersen fdfe298a96 last_patch60 from vodz:
login and getty applets writes utmp/wtmp but init do clearing not.
    I think, in current time deny wtmp/utmp writes as undefault features.
2002-10-10 03:55:09 +00:00
Eric Andersen d274b53c1d last_patch59 from vodz to cleanup chmod and correctly parse '-rwxgoa' 2002-10-10 03:47:01 +00:00
Eric Andersen 1bb1e83454 last_patch58_2 from vodz -- add FEATURE_CPU_USAGE_PERCENTAGE option 2002-10-10 03:44:12 +00:00
"Steven J. Hill" adb058b0de Fixed the script. It always put output to 'stdout' and never to
the 'modules.dep' file.
2002-10-08 21:33:51 +00:00
Eric Andersen a39342b131 Remember to delete docs/busybox.pod 2002-10-08 19:31:04 +00:00
Eric Andersen 528649463f Fix missing \n noticed by Robert Schwebel 2002-10-08 09:38:07 +00:00
Glenn L McGrath 2983330512 Fix segfault when testing if reaidng from stdin "-" 2002-10-06 23:25:23 +00:00
Eric Andersen e0f5500bb5 Fix init docs 2002-09-30 20:59:33 +00:00
Eric Andersen 506177df7f Bugfix from Claudio Fleiner <claudio@fleiner.com> 2002-09-30 20:53:38 +00:00
Eric Andersen 08a72209c9 last_patch58 from vodz:
Ok. I generate patch for include to busybox-devel my work with
    top (original author give me maintaining) and telnetd (my
    support and unofficial maintaining) applets.  Docs changes
    also: added awk, netstat, time applets to list ;)
2002-09-30 20:52:10 +00:00
Eric Andersen 02e6ba91e8 Vodz' last_patch57:
Hi, Erik.

    my_getpw(uid/gid) and applets used it have problem:
    if username for uid not found, applets can`t detect it
    (but code pessent). Also "%8ld " format is bad:
    spaces not required (applets have self format
    or spec format (tar applet) and overflow for "id" applet...)
    This problem also pressent in stable version.
    Patch for unstable in attach.

    --w
    vodz
2002-09-30 20:39:56 +00:00
Eric Andersen a6f6e06107 Fix dependancy so we rebuild busybox.o, usage.o and busybox.o
whenever the config changes.
 -Erik
2002-09-30 20:39:12 +00:00
Eric Andersen ad082987d0 Use %m, not strerror, and strerror(err) was broken anyways and should have been
strerror(errno).  Problem noted by Alexey V. Neyman <alex.neyman@auriga.ru>
2002-09-30 20:20:20 +00:00
Eric Andersen d9d47c3078 Patch from Konstantin Isakov <ikm@pisem.net>:
In most cases, dirname returns the same argument it was given, so this code
    works nice, but there's one special case: when the name contains no
    dirname, it returns "." (stored statically in the body of itself), and we
    get a segfault in attempt to free() it.
This patch fixes this problem.
2002-09-30 20:14:57 +00:00
Eric Andersen aa1d6ccbfb Don't even try to run ash on uClinux. It won't work.
-Erik
2002-09-30 20:12:32 +00:00
Eric Andersen 6a9799020b Set the close-on-exec flag, just to be saf 2002-09-30 20:08:53 +00:00
Eric Andersen e4d2a43951 Doh. We divide microseconds by 60? 2002-09-30 19:37:48 +00:00
Glenn L McGrath 5c99581880 Save status so we know if to delete compressed file 2002-09-30 05:30:29 +00:00
Glenn L McGrath 924f93e848 make_directory() will fail instantly so we dont need to test for failure here 2002-09-28 08:32:14 +00:00
Glenn L McGrath 891ee641cb Fail straight away rather than recursively printing error messages :) 2002-09-28 08:30:47 +00:00
Glenn L McGrath 8132e933e6 Fix for using '-' as the filename when reading from stdin 2002-09-28 02:06:39 +00:00
Eric Andersen 92052e3945 Bug fix from Nitin Gupta <gupta@equator.com> 2002-09-27 23:34:53 +00:00
Glenn L McGrath 2e41d0cb77 Fix compress support and prevent a segfault 2002-09-27 06:46:02 +00:00
Glenn L McGrath a47a3eada6 Fix simple define problem 2002-09-26 16:01:21 +00:00
Eric Andersen 6f2ebcaa01 Avoid calling exit() from within fork/vfork'ed processes.
-Erik
2002-09-26 13:59:40 +00:00
Eric Andersen a920871c3a Ignoring SIGCHLD causes a race leading to the occasional hang of init
when init will wait() on itself in waitfor() when the child exits before
init is scheduled to run.  Letting init hang is very seriously bad.
 -Erik
2002-09-25 15:08:40 +00:00
Glenn L McGrath 5a66b640f9 Reverse some minor changes that got caught up in my big unarchive patch 2002-09-25 06:08:19 +00:00
Glenn L McGrath 69eab26401 Remove files made obsolete by new unarchiving code 2002-09-25 03:04:03 +00:00
Glenn L McGrath 7ca04f328e New common unarchive code. 2002-09-25 02:47:48 +00:00
Eric Andersen ecfa290cfd Fixup largefile settings
-Erik
2002-09-22 12:09:44 +00:00
Glenn L McGrath b3f7261ffe Fix error messages conditions, and make them the same as GNU mkdir. 2002-09-22 02:12:30 +00:00
Eric Andersen 3a1d8377ab don't leak FILEs 2002-09-20 07:33:18 +00:00
Eric Andersen 19feada06f update the noise a tiny bit 2002-09-18 20:52:26 +00:00
Eric Andersen 7695b7b5f4 Update webpage 2002-09-18 20:48:20 +00:00
Manuel Novoa III d499330e9e Commit vodz's patch, plus a tweak to change TracePid to TracerPid. Now
works on i386 (2.4.19) and arm (2.4.6).
2002-09-18 19:27:10 +00:00
Eric Andersen 06c35da6af patch from John Hall <john.hall@optionexist.co.uk> to change the
klogd specific messages to facility LOG_SYSLOG and tidies up some
of the priorities.
2002-09-18 14:23:06 +00:00
Eric Andersen 420b208a45 Add a new top applet
-Erik
2002-09-17 22:14:58 +00:00
Eric Andersen 793c3b4a7d Clear screen too. 2002-09-17 21:21:27 +00:00
Eric Andersen dc180d1442 re-enable the cursor, in case it got disabled
-Erik
2002-09-17 21:17:35 +00:00
Manuel Novoa III 6c32a8add4 Modified so that it "works" for archs other than i386... arm in particular.
Also tried to clean up the logic a little, and ensure that read errors
or invalid archives resulted in error returns.  This could use a lot more
work... Volunteers?
2002-09-17 21:02:16 +00:00
Eric Andersen 60943c5d5c Sane-ify the screen clearing stuff.
-Erik
2002-09-17 20:53:41 +00:00
Eric Andersen 39ad2833c0 hehe. 2002-09-17 20:35:58 +00:00
Eric Andersen 871d93c462 Vodz' last_patch57:
Ok. Patch with reduce size ready.
    Notes: syslogd imposible close logsocket,
    the real programm write logmessages (hmm, cycle loop?)

    (Excuse me - this have small tab-formats rewroting also)

       text    data     bss     dec     hex filename
       2913     332   12388   15633    3d11 syslogd.o
       3109     332    9252   12693    3195 syslogd_old.o
2002-09-17 20:06:29 +00:00
Eric Andersen 927c3bdc18 Support setting depth 2002-09-17 08:44:56 +00:00
Eric Andersen a9a220b92a last_patch56 from vodz to simplify copy_file logic 2002-09-17 08:42:21 +00:00
Eric Andersen bf8bf105fb Patch from "Joe.C" <joe@numa.com.tw> 2002-09-17 08:41:08 +00:00
Eric Andersen 34fd00af5f Patch from David McCullough <davidm@snapgear.com> 2002-09-17 08:40:12 +00:00
Eric Andersen 7365c58783 Use "MiB" not "Mb"
-Erik
2002-09-17 06:36:56 +00:00
Eric Andersen bdff6a4c59 Typo fix from Steven Merrifield 2002-09-17 05:43:26 +00:00
Eric Andersen d4ee98940b last_patch55 from vodz:
I found overflow problem in xargs applet
    (allocated not space for trailing '\0').
    Last patch also reduce 22 bytes size. ;)
2002-09-16 10:44:24 +00:00
Eric Andersen 02b8dfc524 Let people force overwrite links
-Erik
2002-09-16 10:23:38 +00:00
Eric Andersen 403a73a351 Properly honor FILEUTILS_INTERACTIVE and FILEUTILS_FORCE for
file all file types (not just regular files and dirs).  Unlink
destination files when needed.
 -Erik
2002-09-16 09:23:22 +00:00
Glenn L McGrath 18b76e6f80 Watch applet by Michael Habermann 2002-09-16 09:10:04 +00:00
Eric Andersen 8fede28c74 Patch from Matthias Lang <matthias@corelatus.se> to fix gunzip
error handling and prevent gunzip from hanging.
2002-09-16 07:25:41 +00:00
Eric Andersen a9cc8961ed Let people run SHUTDOWN actions prior to killing everything
-Erik
2002-09-16 06:49:06 +00:00
Eric Andersen e18cb71e0c Fix stupid typo noticed by John Mullin <john.mullin@homenetcomm.com> 2002-09-16 06:32:16 +00:00
Eric Andersen c38678d14b Apply vodz' last_patch52 2002-09-16 06:22:25 +00:00
Eric Andersen 166fa4684f Support module tainting
-Erik
2002-09-16 05:30:24 +00:00
Glenn L McGrath 061c900176 mesg applet by Manuel Novoa III 2002-09-16 04:21:46 +00:00
Glenn L McGrath ebdc8b48a5 Put in GPL v2 or later copyright notice 2002-09-16 03:47:48 +00:00
Glenn L McGrath ec0c48cb29 openvt applet by Quy Tonthat 2002-09-16 03:16:06 +00:00
Glenn L McGrath 6714862bdd Use busybox's show_usage function for help 2002-09-15 17:20:45 +00:00
Glenn L McGrath 7a32aaacd0 Awk applet written from scratch by Dmitry Zakharov 2002-09-15 17:03:48 +00:00
Glenn L McGrath b3c4e9add5 Support for GNU style long filename and linknames 2002-09-15 16:54:49 +00:00
Eric Andersen 186685d46f Patch from Thomas Gleixner <tglx@linutronix.de> to do
automatic child reaping to avoid zombies
2002-09-12 15:44:53 +00:00
Manuel Novoa III 4d0884a1ea Apply vodz's last_patch53.gz (bb_asprintf.c) and last_patch54.gz
(arith.c).
2002-09-12 14:52:26 +00:00
Eric Andersen 7829b8d067 Fix for handling of "tftp -l -" from Jean Wolter <jw5@os.inf.tu-dresden.de> 2002-09-10 06:03:31 +00:00
Eric Andersen 2a1eb31f18 Yipe. uid and gid were reversed.
-Erik
2002-09-10 05:23:29 +00:00
Eric Andersen 2bec97c076 Some CML1 grammar fixes
-Erik
2002-09-01 06:45:55 +00:00
Eric Andersen 1130976f8e Eliminate use of obsolete sys_errlist[]
-Erik
2002-08-26 21:36:32 +00:00
Glenn L McGrath c3b7f7d6e7 chmod on the NEW file 2002-08-26 17:17:27 +00:00
Glenn L McGrath 193697db4e Dont return an error if the directory already existed 2002-08-24 20:11:38 +00:00
Glenn L McGrath 210aa14916 Fix warning 2002-08-24 20:00:52 +00:00
Glenn L McGrath abac53b33c Reorganise, make it just one function, remove -v option it didnt work properly anyway, dont setvbuf it doesnt make any difference in performance. 2002-08-24 14:32:17 +00:00
Glenn L McGrath 1ee52e8b14 Run through indent, use braces 2002-08-24 10:30:36 +00:00
Aaron Lehmann 933d10d308 Remove extrangeous backslashes that were probably introduced by
someone joining lines and forgetting to remove the backslash escaping
the newline.
2002-08-23 22:09:50 +00:00
Glenn L McGrath fbef225c4b Rewrite, its smaller 2002-08-23 17:19:26 +00:00
Glenn L McGrath 192ff35d9c Remove empty loops 2002-08-23 14:36:59 +00:00
Glenn L McGrath 0be933b505 Use static instead of extern, braces around if's, run through indent 2002-08-23 14:31:28 +00:00
Glenn L McGrath 50812fff21 Apply vodz last_path_51-2 2002-08-23 13:14:48 +00:00
Glenn L McGrath de9e803149 Apply vodz last_patch51_2 and run through indent 2002-08-23 12:04:23 +00:00
Aaron Lehmann e599b6d96e Don't #ifdef __linux__. this is linux. 2002-08-23 07:56:21 +00:00
Aaron Lehmann 7dd2cec2fd ansify 2002-08-23 07:52:58 +00:00
Aaron Lehmann 84878fe20e remove duplicate definition of G
caught by tinycc
2002-08-23 07:51:01 +00:00
Aaron Lehmann 0df910af49 for some baffling reason tinycc insists that i change this 0 to NULL 2002-08-23 07:45:26 +00:00
Aaron Lehmann 5d3cb7cc1f move some globals to bss 2002-08-23 07:28:45 +00:00
Glenn L McGrath 8042f65398 Run through indent, style 2002-08-23 06:17:46 +00:00
Glenn L McGrath acfc0d872e Run through indent, fix comments 2002-08-23 06:05:11 +00:00
Glenn L McGrath 03195fc16f Run through indent, fix comments 2002-08-23 05:58:38 +00:00
Glenn L McGrath a199b17253 Run through indent, specify cast 2002-08-23 03:37:07 +00:00
Glenn L McGrath 14dad7028b Run through indent 2002-08-23 03:25:22 +00:00
Glenn L McGrath 1ed9dd9d06 Remove duplicate definitions, run through indent 2002-08-22 19:35:36 +00:00
Glenn L McGrath 4534af2763 replace some global const ints with defines 2002-08-22 19:31:35 +00:00
Glenn L McGrath 0775a07d87 Specify cast 2002-08-22 19:22:32 +00:00
Glenn L McGrath 4cc2e5e944 Remove duplicate variable definition 2002-08-22 19:15:26 +00:00
Glenn L McGrath 9fef17dec3 Run through indent, fix comments 2002-08-22 18:41:20 +00:00
Glenn L McGrath 7c58e9be69 Run through indent, fix comment 2002-08-22 18:24:43 +00:00
Glenn L McGrath baf55a85fc Run through indent, fix comments 2002-08-22 18:22:10 +00:00
Glenn L McGrath e3906fcd94 Run through indent, fix BB_ define 2002-08-22 18:13:54 +00:00
Glenn L McGrath 99b12543cf Run through ident, fix comments 2002-08-22 17:47:09 +00:00
Glenn L McGrath 242e3b6bde define inline if needed for ANSI C compatability 2002-08-22 15:59:18 +00:00
Glenn L McGrath 60a22addea Remove unwanted comments, run through indent 2002-08-22 15:54:22 +00:00
Glenn L McGrath a0ee881ba4 Run through indent, use /* */ style comments, change extern to static 2002-08-22 13:44:08 +00:00
Glenn L McGrath 4176972db5 Run through indent, use /* */ style comments 2002-08-22 13:25:12 +00:00
Glenn L McGrath d827e8b665 Run through indent 2002-08-22 13:21:26 +00:00
Glenn L McGrath b37367aa77 Run through indent, use /* */ style comments instead of // 2002-08-22 13:12:40 +00:00
Glenn L McGrath f853db54f9 Remove definition of is_octal and is_decimal, they arent used 2002-08-22 12:55:26 +00:00
Glenn L McGrath 75762705a3 Honour the USTAR prefix field, this enables a 155 byte path length plus the normal 100 byte filename.
The catch is gnu tar cannot create archives that use the prefix field, you need to use s-tar.
2002-08-22 11:50:31 +00:00
Glenn L McGrath 419eed7501 udhcpc sample scripts 2002-08-21 14:24:38 +00:00
Aaron Lehmann 5f8f32a41c Inline functions with only one reference in mkfs_minix. I don't know
why these efforts aren't making the binary smaller.
2002-08-21 13:21:20 +00:00
Aaron Lehmann 8fc5d6d2da Tar inlining, #if 0 out unused function 2002-08-21 13:11:34 +00:00
Aaron Lehmann 6fdacc74f0 vi inlining 2002-08-21 13:02:24 +00:00
Aaron Lehmann a95e99e6f3 Cleanups. These SHOULD make the binary a lot smaller. But they don't.
CURSE GCC
2002-08-21 12:44:54 +00:00
Glenn L McGrath d9768d7cb9 Disable debugging 2002-08-21 11:44:31 +00:00
Aaron Lehmann 1ff58b6570 Clean up udhcpd a bit. Constify. Staticize. Remove these functions and
inline their contents: print_usage, pidfile_delete, and background.
2002-08-21 11:21:19 +00:00
Glenn L McGrath 8eb0dc1d10 New applet, udhcp client 2002-08-21 10:27:58 +00:00
Glenn L McGrath 3d184586a7 Fix dietlibc test condition 2002-08-15 03:29:56 +00:00
Eric Andersen 938e982c4d Try to be a bit more dietlibc friendly 2002-08-13 09:57:44 +00:00
Glenn L McGrath 1d23f3a492 Enable support for the old tar header format, enable via menu's 2002-08-13 05:06:43 +00:00
Aaron Lehmann 6069441bd2 minor fixes for fbset bloat
<mjn3>         printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres,
<mjn3>                    v->xres_virtual, v->yres_virtual, v->bits_per_pixel);
<mjn3>         printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin,
<mjn3>                    v->right_margin, v->upper_margin, v->lower_margin, v->hsync_l
<mjn3> en,
<mjn3>                    v->vsync_len);
<mjn3>         printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false"));
<mjn3>         printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length,
<mjn3>                    v->red.offset, v->green.length, v->green.offset, v->blue.leng
<mjn3> th,
<mjn3>                    v->blue.offset, v->transp.length, v->transp.offset);
<mjn3>         printf("endmode\n\n");
<mjn3> whay have multiple printf calls when one would do?

<mjn3> and this:
<mjn3> static struct cmdoptions_t {
<mjn3>         char *name;
<mjn3>         unsigned char param_count;
<mjn3>         unsigned char code;
<mjn3> } g_cmdoptions[] = {
<mjn3>         {
<mjn3>         "-fb", 1, CMD_FB}, {
<mjn3> (repeated entries)
<mjn3> why isn't this constant?  what about struct packing?

inline the helper functions that are only referenced once.
2002-08-13 04:19:23 +00:00
Robert Griebl 91a0aac110 Added Familiar Linux to the projects list 2002-08-09 22:54:39 +00:00
Robert Griebl 2ab6ff95e0 Patch from Rusell Nelson to document the -C switch for syslogd 2002-08-07 21:24:33 +00:00
Robert Griebl 65d415d847 Added a help text for the -C option to syslogd 2002-08-07 21:10:19 +00:00
Robert Griebl 00f5ecb141 Somehow I applied an old patch for the last commit - this one works now:
- Added \CregexC support to sed (sed testsuite reported no errors, btw)
2002-08-06 23:13:31 +00:00
Robert Griebl 7940147e25 Added the \CregexpC syntax as an alternative for /regexp/ (like GNU sed) 2002-08-06 21:07:17 +00:00
Manuel Novoa III edcac5572f Fix silly typo. addgroup was using /etc/shadow for /etc/gshadow. 2002-08-06 20:39:23 +00:00
Manuel Novoa III f8277ca992 Move #define MAXLINE so this compiles without circ buffers. 2002-08-06 20:12:56 +00:00
Eric Andersen 74b007f7cc Oops. Code things so it actually works this time around...
-Erik
2002-08-05 11:56:25 +00:00
Eric Andersen c59716ff4c Joel Coltoff <joel@wmi.com> noticed that following a recent
change in uClibc that changed opening the /dev/log socket as
SOCK_STREAM to SOCK_DGRAM, busybox syslogd no longer worked
since it needed a matching change.  This fixes it so it
works once again.
2002-08-05 11:14:30 +00:00
Robert Griebl 6859d761d3 - updated a few copyright/left file headers
- documented most of my 0.61 changes in the ChangeLog
2002-08-05 02:57:12 +00:00
Robert Griebl 0d833ca7fd Fixed a bug in xarg: string data was strcat'ed to a malloc'ed buffer - and
malloc does not clear memory by default (somehow this worked on x86, but
not on arm)
2002-08-03 14:49:03 +00:00
Aaron Lehmann 49c024addd Remove ckfree, and replace all references with free. Remove freefunc,
which is also equivilent to free. Remove some if(x)free(x)
redundancies.
2002-08-02 06:39:47 +00:00
Eric Andersen e85dbfdd80 Joseph Chiu <josephc@idealab.com> found an off-by-one bug. oops! 2002-08-01 01:31:17 +00:00
Robert Griebl a71389bfe8 Applied a patch from Philip Blundell <pb@nexus.co.uk>:
Added support for ":x" as an alias for ":wq" to vi
2002-07-31 21:22:21 +00:00
Eric Andersen 7373e485d3 A couple of small bugfixes from Marshall M. Midden <m4@brecis.com> 2002-07-31 04:04:47 +00:00
Eric Andersen 87715170cc Be more portable with 'find' for those that prefer programming
on *BSD, etc.  Formatting fixes, etc.
2002-07-31 03:45:05 +00:00
Robert Griebl b230159958 Fixed a timing bug which occured when bb ash is run in a rxvt on the
HP iPAQ. Sometimes we get a SIGWINCH and want to print the prompt, although
the prompt is not yet initialised (0) .. so just don't print a prompt
as long as the prompt string is 0
2002-07-30 23:13:51 +00:00
Robert Griebl df03932b7e Added the -I (isofmt) options to date, which comes in handy for scripts
(this is a confiureable option)
2002-07-30 23:11:00 +00:00
Robert Griebl 70112da81a Fixed a bug that I had introduced with the new "options" handling. 2002-07-29 20:28:38 +00:00
Eric Andersen e707806894 Kill a silly warning 2002-07-29 08:00:16 +00:00
Eric Andersen 3bc2b206b0 Patch from Tim Riker to allow tty* in inittab if the tty
actually exists -- serial console is not the issue...
2002-07-29 06:39:58 +00:00
Robert Griebl aead70b4d1 modprobe now also uses "options" from /etc/modules.conf 2002-07-26 15:54:20 +00:00
Robert Griebl d0dd3d31e2 Fix for bug #1255 -- support for mount -t <type> 2002-07-25 14:17:19 +00:00
Robert Griebl 2a4a8d8ffb Add support for /etc/filesystem when searching for an "auto" filesystem
This is bug #1246
2002-07-24 01:41:30 +00:00
Robert Griebl 31a2e20bd3 Commited patch from bug #1182
Although ssrat@mailbag.com says this is not GNU behaviour, it really *is*
(man nslookup)
2002-07-24 00:56:56 +00:00
Robert Griebl 41369af3f2 Patch for bug #1183: Added a -xdev option to find (configurable) 2002-07-24 00:34:48 +00:00
Eric Andersen 80cd3cfdbc Fix indentation. Support killall -q, for pcmcia-cs
-Erik
2002-07-23 23:45:11 +00:00
Robert Griebl f2f26e7fdd Added tar -cz support (creating gzipped tar files without a gzip pipe) 2002-07-23 22:05:47 +00:00
Robert Griebl 967c3d4406 Fixed two compiler warnings 2002-07-21 17:33:27 +00:00
Robert Griebl 1cd0445495 Initial checkin of a very primitive hwclock replacement 2002-07-21 16:50:49 +00:00
Robert Griebl fc78b79575 Applied syslogd fix submitted by Bart Visscher:
I am using BB 0.60.2 in a floppy distro, and the syslog (and logger) is
unable to log the "<" char.  This shows up in ppp logfiles.  [...]
#logger "<pcomp>" results in "comp>" arriving at the log.
2002-07-19 20:52:21 +00:00
Robert Griebl efd4983eb1 - Forgot to cvs add bb_asprintf.c (from vodz' patch #50)
- Applied Joel Coltoff's xconnect patch:
On both my host system and with mipsel-linux for my embedded systems
the function getservbyname() gives the port number already in host order.
In fact, this is how it was used by rdate in version 0.60.3. The snapshot
I have of the development tree from July 12, 2002 takes the port number
and stuffs it into htons() before it uses it. This causes bugs in rdate,
telnet and wget. This patch fixes that.
2002-07-19 20:27:11 +00:00
Robert Griebl d378c3149c Applied vodz' patches #49 and #50 (with a small correction in runshell.c)
#49: I found one memory overflow and memory leak in "ln" applet.
Last patch reduced also 54 bytes. ;)

#50: I found bug in loginutils/Makefile.in.
New patch have also new function to libbb and
aplied this to applets and other cosmetic changes.
2002-07-19 00:05:54 +00:00
Robert Griebl 88947dd05e Added a compile time option to suppress the "Using fallback.." message
if no busybox.conf file is existant.
2002-07-18 23:59:17 +00:00
Robert Griebl 2c0d0f0051 Fix for the totally broken adduser applet (parts/ideas from vodz and tito) 2002-07-16 23:50:05 +00:00
Robert Griebl e4f9f3a960 Don't treat a non-existant/-readable config file as an empty config, but
use the compiled in _BB_SUID_* flags (same as for parse errors)
2002-07-16 21:53:59 +00:00
Eric Andersen 0fe3e62e2c Doh! 2002-07-14 15:39:05 +00:00
Eric Andersen d2fd0d5869 Better clarify the CVS tree situation
-Erik
2002-07-13 06:24:58 +00:00
Eric Andersen acc257e994 Try to be more clear about the current two-CVS-trees
situation.
 -Erik
2002-07-13 06:08:39 +00:00
Robert Griebl e8fcf4bd69 Accept the --passive-ftp cmd.line option. We always use passive ftp mode,
so it doesn't hurt (adds compatibility though)
2002-07-12 00:04:46 +00:00
Eric Andersen 2276d83639 Fixup warnings and undefined operations that show up in gcc-3.1
-Erik
2002-07-11 11:11:56 +00:00
Eric Andersen cafc103230 Brad Campbell <brad@seme.com.au> notes that
xconnect.c needs #include <netinet/in.h>
to compile if CONFIG_FEATURE_IPV6 is not defined
2002-07-11 10:40:43 +00:00
Eric Andersen 1785ddcae2 Some minor bits of scrubbing 2002-07-08 01:40:02 +00:00
Eric Andersen 8e139871fe Patch from Stewart Brodie <stewart.brodie@pace.co.uk> to fix ash:
When alias support is not configured, ash believes that command parameters
that look like dd's "if=/dev/zero" are requests to set a temporary
environment variable whilst dd is running, even though it appears after the
command name.  This is caused by the re-use of the checkalias global variable
to indicate when both alias checking and environment variable checking.  The
failure to reset this flag is due to the reset action being performed only
inside the feature check CHECK_ASH_ALIAS.  Hence ash works as expected when
aliases are configured in, and fails when not.

Example script using 'date' with different settings of TZ:

# TZ=Europe/London
# export TZ
# date
Thu May 30 17:18:49 BST 2002
# TZ=America/New_York date
Thu May 30 12:19:10 EDT 2002
# date
Thu May 30 17:19:12 BST 2002
# date TZ=America/New_York
Thu May 30 12:19:30 EDT 2002    <----- wrong, should be BST time (or error!)
# date
Thu May 30 17:19:35 BST 2002

Attached is a patch against revision 1.52 of ash.c which moves the checks so
that checkalias is updated regardless of whether CONFIG_ASH_ALIAS is set.
With this patch applied, the command shown above which should generate an
error does generate an error.

I have tested this patch with the 'dd' command too and that now works
correctly.
2002-07-04 00:19:46 +00:00
Eric Andersen 0826b6b0b3 This is last_patch48 from vodz. More cleanups, kills a bit
of dead code, fixes one blatent bug.
2002-07-03 23:50:16 +00:00
Eric Andersen 887ca79f04 Scrub pwd.h and grp.h handling so we don't have to play any
silly games.
 -Erik
2002-07-03 23:19:26 +00:00
Eric Andersen 360e254954 tito <farmatito@tiscali.it> noticed that delgroup was actually
setting CONFIG_DELUSER.  Oops.
2002-07-03 19:50:23 +00:00
Eric Andersen 0b31586c71 A patch from Bart Visscher <magick@linux-fan.com> to add an
xconnect helper routine which does:
        -address and port resolving
	-tries to connect to all resolved addresses until connected
	-uses getaddrinfo, so works for IPv6 too
This patch also ports rdate, telnet, and wget to use the new
xconnect function.  Thanks Bart!
2002-07-03 11:51:44 +00:00
Eric Andersen 51b8bd68bb This patch from Bart Visscher <magick@linux-fan.com> adds
IPV6 support to busybox.  This patch does the following:
    * Add IPv6 support to libbb
    * Enable IPv6 interface address display
    * Add IPv6 config option
    * Adds ping6, an adaptation of the ping applet for IPv6
    * Adds support routines for ping6:
	- xgethostbyname2
	- create_icmp6_socket
    * Adds ifconfig support for IPv6
    * Add support IPv6 to netstat
    * Add IPv6 support to route
Thanks Bart!
2002-07-03 11:46:38 +00:00
Eric Andersen 599e3ce163 Apply last_patch47 from vodz to fix several problems, such as the ash "job
control turned off" bug, console_setup() was called with a closed file
descriptor, setsid() inconsistancy, and silly string handling bugs.   I have
modified his patch to allow the askfirst init actions to have a controlling
terminal.
2002-07-03 11:08:10 +00:00
Eric Andersen 935daf2d0d hide shadow using stuff when CONFIG_FEATURE_SHADOWPASSWDS
is not set
 -Erik
2002-07-03 09:13:21 +00:00
Eric Andersen 7f90ed4460 Patch from Martin Volf <volf@dragon.cz> to fix where I had
screwed up the usage messages
2002-07-03 05:55:14 +00:00
Eric Andersen 796446718d Fix from vodz so that complex init commands actually work 2002-07-03 05:44:18 +00:00
Eric Andersen 8c4025e708 Patch from Danny Lepage <danny.lepage@cognicase.com> to fix
dutmp for uClibc.
2002-07-03 05:32:02 +00:00
Eric Andersen 5222d31a15 Patch from till busch <buti@gmx.at> -- unblock all signals
in exec_signal() before calling exec()
2002-07-03 05:15:23 +00:00
Eric Andersen 549df2ebc3 Fix text alignment, thanks to Sander Klein <s.klein@quicknet.nl> 2002-07-03 04:54:52 +00:00
Eric Andersen 7234c3a0b6 Cleanup shadow.h stuff so it behaves as intended
-Erik
2002-07-03 04:47:43 +00:00
Eric Andersen 009ae1f17d Little fix to avoid overflow 2002-07-03 04:24:08 +00:00
Eric Andersen abc9568690 Silly spelling fix
-Erik
2002-07-03 02:52:35 +00:00
Eric Andersen b493dec91e David Frascone <dave@frascone.com> noticed two problems. First, modprobe was
trying to call 'insmod -q', which wasn't supported.  Secondly, when modprobe
was fed blank lines from modules.dep, we ended up calling xstrndup(ptr, -1),
which with suitably bad results.  David provided a patch to catch the blank
lines, and I have added insmod -q support.  So modprobe should work again.
 -Erik
2002-07-02 19:14:23 +00:00
Aaron Lehmann 69d4178708 Remove advertising clauses in accordance with
ftp://ftp.cs.berkeley.edu/ucb/4bsd/README.Impt.License.Change
2002-06-23 22:25:24 +00:00
Aaron Lehmann 9031481ac3 inline many functions that are only called once. saves about 300 bytes
on i386. also staticify most functions.
2002-06-23 22:13:22 +00:00
Aaron Lehmann ed11993900 Needs shadow.h; otherwise wont compile without CONFIG_USE_BB_SHADOW 2002-06-23 22:00:41 +00:00
Aaron Lehmann 8c26fbe537 remove cleanUpAndFail, and replace it with exit(). because that's what
it does unless srcMode was set, and srcMode is never set.
2002-06-23 21:56:13 +00:00
Eric Andersen 5b0f9e417e Rework optimization code. Be more compiler aware.
-Erik
2002-06-23 04:50:49 +00:00
Eric Andersen 27f64e1f4e Port over the last of the tinylogin applets
-Erik
2002-06-23 04:24:25 +00:00
Eric Andersen 0fbff134f4 Several login cleanups from vodz 2002-06-22 17:49:29 +00:00
Eric Andersen b0c39a8a8d Apply vodz' last_patch44 -- cleanup several chars to be const, fix
rotten error handling, kill spare \n's, etc
2002-06-22 17:32:58 +00:00
Eric Andersen 3ece93ba0f Kill dead email address
-Erik
2002-06-22 17:23:45 +00:00
Eric Andersen 8b1aa4d749 Apply last_patch46 from vodz, to fix buffer overflows noted by
Gerardo Puga, and to optimize for size a little bit.  Thanks vodz
2002-06-22 17:20:50 +00:00
Eric Andersen 61f83059c1 Apply vodz' cleanup for insmod buffer overflows, which was cleaner
than my first effort.
2002-06-22 17:15:42 +00:00
Aaron Lehmann 9f92d5f2a2 Major revamp. I've been trying to clean up the code. the bzerror stuff
still needs major attention (i.e. removal).

Removed references to uninitialized variables like progName,
smallMode, noisy, etc. Remove functions and code for handling "small"
decompression mode, since it is all unreachable. Remove
total_{in,out}* counters - they are never used. Remove panic()
function and assert_h and their uses because they are all for "should
never happen" circumstances. Replace internal malloc/free wrappers
with xmalloc and free. Remove conditional in if(foo)free(foo);
situations. Remove bogus
	if (sizeof(int) != 4) {
		return BZ_CONFIG_ERROR;
	}
(...etc...) code and code for handling BZ_CONFIG_ERROR. Someone should
go through and change the applet to use well-defined types when
appropriate - it expects sizeof(short)==2 && sizeof(int)==4. Until
this commit these were explicitly checked for, and the applet would
exit if these types were not the right size. (I think this is wrong
even as an interim solution.)

With gcc 3.1 reduces size of binary on i386-linux by about 700 bytes.

Lightly tested.
2002-06-22 06:35:29 +00:00
Eric Andersen 2d34215456 As noted by Yves Lavoie ing. <yves.lavoie.ing@sympatico.ca>, don't
lose the last letter of the module name.
2002-06-18 05:16:25 +00:00
Eric Andersen b0fd2b06a3 Fix a potential macro expansion problem... isspace can be
a macro causing a double decrement...
2002-06-15 14:37:46 +00:00
Eric Andersen a7d0b41c08 Don't use pointless GNU-isms 2002-06-15 14:33:06 +00:00
Robert Griebl 47abc49c4a Patch from Simon Krahnke:
I wrote a patch for busybox for our company's (www.lisa.de)
private use. [...] To sed it adds the '!'-inversion of addresses.
2002-06-11 23:43:27 +00:00
Matt Kraai 3ad88ccf2d * testsuite/sed/sed-recurses-properly: Mark XFAIL. 2002-06-11 13:29:08 +00:00
Matt Kraai 9ef2ea27d4 * libbb/copy_file.c (copy_file): Check st_dev instead of st_rdev. 2002-06-11 13:25:26 +00:00
Eric Andersen 360060252a vodz' last_patch42_2, which is an updated fix for buffer overflows
noted by Gerardo Puga
2002-06-08 12:44:17 +00:00
Robert Griebl 0c789a4255 If config file can not be parsed, use compiled in BB_SUID_... values as a
fallback method
2002-06-06 17:30:16 +00:00
Eric Andersen fe1ef2bc62 Fix buffer overflows noted by Gerardo Puga
-Erik
2002-06-06 14:36:07 +00:00
Eric Andersen 6fb4e4877a Fix buffer overflows noted by Gerardo Puga
-Erik
2002-06-06 14:24:57 +00:00
Eric Andersen 0d2d1eb599 Fix a buffer overflow found by Gerardo Puga <gpuga@gioia.ing.unlp.edu.ar>
-Erik
2002-06-06 13:33:01 +00:00
Eric Andersen 8610f91ebf Lets give this a try... 2002-06-06 13:00:47 +00:00
Eric Andersen 27d3766e0d Email addr fix 2002-06-06 12:59:13 +00:00
Eric Andersen ad79c0b629 Patch from Gyepi SAM <gyepi@praxis-sw.com>:
Fixed up domain removal for local domains. GNU traceroute does not do this. I
don't know why we do.  Fixed incorrect argument for reverse resolution.  Clean
up cruft that appears when CONFIG_FEATURE_TRACEROUTE_VERBOSE is defined
2002-06-06 12:24:51 +00:00
Eric Andersen 77d22c4abd Patch from Gyepi SAM <gyepi@praxis-sw.com>:
When DEBUG is defined
    1. need to include resolv.h (for _resinit())
    2. remove _() call around string. It appears to be a remnant of i18n or some such notion
2002-06-06 12:11:55 +00:00
Eric Andersen 1a92376f00 Patch from vodz to only setenv PATH when PATH changes, which is much
smarter than my quick fix.
2002-06-06 12:07:28 +00:00
Eric Andersen e90e741b1e Per discussion with vodz, Tim's changes do not seem to make sense.
Revert them.
 -Erik
2002-06-06 11:47:00 +00:00
Eric Andersen fc059090b6 last_patch41 from vodz to fix stty -F and similar 2002-06-06 11:35:29 +00:00
Eric Andersen ff7661d9de plug fd leak noticed by Russ Dill
-Erik
2002-06-05 07:11:32 +00:00
Robert Griebl 1fca558799 Bigger patch for (partial) tinylogin integration
- Made a new dir loginutils
- Moved all applets from pwd_grp to loginutils
- Added new applets su.c login.c to loginutils
- Made a new dir libpwdgrp
- Moved everything from pwd_grp/libpwd_grp there
- Added shadow.c to libpwdgrp
- Removed dir pwd_grp
- Added usage strings for login and su to usage.h
- Changed main Makefile to reflect the dir rearrangements
[Parts of this patch may overlap with my other two patches]
2002-06-04 20:45:46 +00:00
Robert Griebl ea1a63a201 Fix for broken handling off BusyBox's own pwd/grp implementations
[Parts of this patch may overlap with my other two patches]
2002-06-04 20:10:23 +00:00
Robert Griebl c9aca4561d Implement two types of suid/sgid support for BusyBox:
1) tinylogin like with compile time selection and a chown root.root
2) Runtime configurable via /etc/busybox.conf (docu is in the works)
[Parts of this patch may overlap with my other two patches]
2002-06-04 20:06:25 +00:00
Robert Griebl bc28f7a1e1 Cleaned up Erik's fgets -> read patch and fixed a buffer overflow 2002-06-04 19:33:58 +00:00
Eric Andersen c06391be0d Avoid stack munching stdio implementations.
-Erik
2002-06-04 13:28:43 +00:00
Robert Griebl 3b79370a7d Fixed a realloc bug found by Martin Volf 2002-06-02 09:36:12 +00:00
Manuel Novoa III b99cb64b80 Include busybox.h before testing CONFIG_LOCALE_SUPPORT. 2002-05-29 19:08:41 +00:00
Glenn L McGrath a94a06a38e Patch from Randolfe Averty to fixup package conflict checks, cleanup some memory leaks and reorganise dependency checking.
Some further memory leaks fixed by me.
2002-05-29 13:45:34 +00:00
Robert Griebl 1d4ef2a9e9 Added support for /etc/modules.conf parsing
for now only the 'alias' entries are evaluated
2002-05-28 21:32:10 +00:00
Robert Griebl 53146cc9ec Added include for isdigit(); simplified -<num> detection 2002-05-27 22:24:53 +00:00
Eric Andersen 8302c43265 Ensure that insmod supports at least one MODULE_INTERFACE
-Erik
2002-05-24 06:59:22 +00:00
Eric Andersen cffd5022c5 Patch from Magnus Damm <damm@opensource.se> to rework things
greatly, and keep the arch specific relocations together,
fixes R_PPC_ADDR32 handling so powerpc can work, and changes the
tlb tables to be linked lists (again so powerpc can work).
2002-05-24 06:50:15 +00:00
Robert Griebl d11edf9809 Made exit code SysV compliant. Also added -s (single pid) flag. 2002-05-22 23:38:12 +00:00
Robert Griebl 236abbfd71 Some cleanups, some size reductions and some buffer overflow checks
Most of it based on ideas from vodz
2002-05-22 23:34:35 +00:00
Robert Griebl 94a6a956f0 Support old-style compress (.Z) files via libbb / unzip( ) calls
(configurable) - When enabled an applet "uncompress" is also made
available (oddname to gunzip)
[the cvs add for this file got lost somehow...]
2002-05-19 19:00:14 +00:00
Tim Riker c6def44cfc ping return 1 if can't ping 2002-05-18 09:16:04 +00:00
Robert Griebl 13c26fc1a5 SUpport old style -[::digit::] options for head and tail
Also make head behave like GNU head (-0/-n 0 is valid)
2002-05-17 22:18:04 +00:00
Robert Griebl c30c5e89cf Reduced code size for new -e flag (suggested by vodz) 2002-05-16 19:14:15 +00:00
Eric Andersen d8636cad4d Doh! Remember to close /etc/inittab 2002-05-15 22:19:09 +00:00
Robert Griebl f6495eb767 Support old-style compress (.Z) files via libbb / unzip( ) calls
(configurable) - When enabled an applet "uncompress" is also made
available (oddname to gunzip)
2002-05-15 22:13:47 +00:00
Robert Griebl 7ac868460a gunzip'ing many files to stdout works now
Fixed a missing initialisation and made a for loop more readable.
2002-05-15 21:57:42 +00:00
Robert Griebl 081df62b92 Don't delete source file when decompressing to stdout
This is the normal GNU gunzip behaviour
2002-05-15 21:45:52 +00:00
Robert Griebl 52e8d060a9 Complete rewrite to support stack loading/unloading with proper
handling of duplicates in the dependencies list.
2002-05-14 23:42:08 +00:00
Robert Griebl d77601178d Added support for -Y|--proxy=on/off to wget 2002-05-14 23:36:45 +00:00
Robert Griebl 64f70cc755 Add --login support. This is the bash way of starting a shell that should
parse the profile files.
2002-05-14 23:22:06 +00:00
Robert Griebl 8187bb4394 This patch adds -e (extended information) to route and -r/-e (show routing
tables/extended information) to netstat.
This makes them behave (more) like their GNU counterparts.
2002-05-14 23:10:58 +00:00
Robert Griebl 820098fd61 This patch adds -e (extended information) to route and -r/-e (show routing
tables/extended information) to netstat.
This makes them behave (more) like their GNU counterparts.
2002-05-14 23:03:23 +00:00
Robert Griebl aa385d4015 Entries with "noauto" options are ignored correctly when mounting all
("mount -a"), but mount fails when these entries are specified explicitly
In these cases the "noauto" option has to be simply ignored.
2002-05-14 22:56:29 +00:00
Eric Andersen f63a20ad7b Tom Oehser noticed that we were lacking the SO_REUSEADDR flag. 2002-05-05 03:40:14 +00:00
Eric Andersen 864b79791a Patch from Robert Griebl <griebl@gmx.de> to support modprobe -r properly,
merged in with the latest and greatest.
2002-05-03 15:48:26 +00:00
Eric Andersen 26920c6c94 Make verbose and show_only work as expected
-Erik
2002-05-03 15:22:42 +00:00
Eric Andersen c088c582bf Patch from Robert Griebl <griebl@gmx.de> to ignore the -s flag 2002-05-03 10:34:35 +00:00
Tim Riker 95bf6da637 fix and shrink uuencode 2002-05-01 05:57:16 +00:00
Matt Kraai a4a65e7f99 * archival/gunzip.c (gunzip_file): New.
(gunzip_main): Handle no arguments correctly.
2002-04-29 15:32:32 +00:00
Eric Andersen 051e4c15db Update website 2002-04-27 12:16:48 +00:00
Eric Andersen d598d41110 Fix silly combinitorial oversight 2002-04-27 09:19:39 +00:00
266 changed files with 28320 additions and 13031 deletions

No files matched your search

+2 -1
View File
@@ -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>
+32 -1
View File
@@ -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:
@@ -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--
+15 -16
View File
@@ -22,8 +22,8 @@ include $(TOPDIR).config
include $(TOPDIR)Rules.mak
SUBDIRS:=applets archival archival/libunarchive console-tools \
editors fileutils findutils init miscutils modutils networking \
procps pwd_grp pwd_grp/libpwd_grp shell shellutils sysklogd \
textutils util-linux libbb
networking/udhcp procps loginutils shell shellutils sysklogd \
textutils util-linux libbb libpwdgrp
all: do-it-all
@@ -47,7 +47,7 @@ endif
busybox: depend $(libraries-y)
$(CC) $(LDFLAGS) $(libraries-y) $(LIBRARIES) -o $@
$(CC) $(LDFLAGS) -o $@ $(libraries-y) $(LIBRARIES)
$(STRIPCMD) $@
busybox.links: applets/busybox.mkll
@@ -160,21 +160,20 @@ $(TOPDIR)include/config.h:
fi;
$(TOPDIR).config:
cp $(TOPDIR)sysdeps/$(TARGET_OS)/defconfig $(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
$(BB_SHELL) scripts/Menuconfig sysdeps/$(TARGET_OS)/config.in
menuconfig:
mkdir -p $(TOPDIR)include/config
$(MAKE) -C scripts/lxdialog all
$(BB_SHELL) scripts/Menuconfig sysdeps/$(TARGET_OS)/config.in
config:
config: $(TOPDIR).config
mkdir -p $(TOPDIR)include/config
$(BB_SHELL) scripts/Configure sysdeps/$(TARGET_OS)/config.in
oldconfig:
oldconfig: $(TOPDIR).config
mkdir -p $(TOPDIR)include/config
$(BB_SHELL) scripts/Configure -d sysdeps/$(TARGET_OS)/config.in
@@ -217,15 +216,15 @@ clean:
- rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
docs/busybox.net/BusyBox.html
- rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
docs/busybox.pdf docs/busybox.net/busybox.html \
docs/busybox.pdf docs/busybox.pod docs/busybox.net/busybox.html \
docs/busybox _install pod2htm* *.gdb *.elf *~ core
- 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 -exec rm -f {} \;
- find -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
+40 -10
View File
@@ -36,7 +36,7 @@ TARGET_OS:=linux
# 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:=
CFLAGS_EXTRA:=#-Werror
# If you want a static binary, turn this on.
DOSTATIC:=false
@@ -91,7 +91,7 @@ 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
#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...
@@ -111,16 +111,46 @@ export VERSION BUILDTIME TOPDIR HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
#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) #-fstrict-aliasing -march=i386 -mcpu=i386 -malign-functions=0 -malign-jumps=0
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,
@@ -132,7 +162,7 @@ ARFLAGS:=-r
ifeq ($(strip $(DOLFS)),true)
# For large file summit support
CFLAGS+=-D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64
CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
endif
ifeq ($(strip $(DODMALLOC)),true)
# For testing mem leaks with dmalloc
@@ -160,7 +190,7 @@ ifeq ($(strip $(DOSTATIC)),true)
LDFLAGS += --static
endif
ifndef $(PREFIX)
ifeq ($(strip $(PREFIX)),)
PREFIX:=`pwd`/_install
endif
-12
View File
@@ -3,11 +3,6 @@ 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/etc are part of tinylogin. We are in the
process of merging these applications into busybox, since the
new build system allows us to add Libraries (i.e. libcrypt),
when certain applets are enabled.
* 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.
@@ -18,10 +13,7 @@ around to it some time. If you have any good ideas, please let me know.
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.
-----------
@@ -48,10 +40,6 @@ 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
+4
View File
@@ -25,8 +25,12 @@ 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
View File
@@ -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:
+93 -31
View File
@@ -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;
}
+64 -591
View File
@@ -71,19 +71,12 @@
#define BZ_MAX_ALPHA_SIZE 258
#define BZ_OK 0
#define BZ_RUN_OK 1
#define BZ_FLUSH_OK 2
#define BZ_FINISH_OK 3
#define BZ_STREAM_END 4
#define BZ_SEQUENCE_ERROR (-1)
#define BZ_PARAM_ERROR (-2)
#define BZ_MEM_ERROR (-3)
#define BZ_DATA_ERROR (-4)
#define BZ_DATA_ERROR_MAGIC (-5)
#define BZ_IO_ERROR (-6)
#define BZ_UNEXPECTED_EOF (-7)
#define BZ_OUTBUFF_FULL (-8)
#define BZ_CONFIG_ERROR (-9)
#define BZ_RUNA 0
#define BZ_RUNB 1
@@ -138,33 +131,23 @@
#define BZ_X_CCRC_4 50
#define BZ_MAX_CODE_LEN 23
#define BZ_VERSION "1.0.1, 23-June-2000"
#define OM_TEST 3
#define SM_F2F 3
typedef struct {
char *next_in;
unsigned int avail_in;
unsigned int total_in_lo32;
unsigned int total_in_hi32;
char *next_out;
unsigned int avail_out;
unsigned int total_out_lo32;
unsigned int total_out_hi32;
void *state;
void *(*bzalloc)(void *,int,int);
void (*bzfree)(void *,void *);
void *opaque;
} bz_stream;
typedef struct {
bz_stream strm;
FILE *handle;
unsigned char initialisedOk;
unsigned char writing;
char buf[BZ_MAX_UNUSED];
int lastErr;
int bufN;
@@ -191,9 +174,7 @@ typedef struct {
/* misc administratium */
int blockSize100k;
unsigned char smallDecompress;
int currBlockNo;
int verbosity;
/* for undoing the Burrows-Wheeler transform */
int origPtr;
@@ -207,10 +188,6 @@ typedef struct {
/* for undoing the Burrows-Wheeler transform (FAST) */
unsigned int *tt;
/* for undoing the Burrows-Wheeler transform (SMALL) */
unsigned short *ll16;
unsigned char *ll4;
/* stored and calculated CRCs */
unsigned int storedBlockCRC;
unsigned int storedCombinedCRC;
@@ -263,10 +240,6 @@ typedef struct {
} DState;
int BZ2_rNums[512];
//int verbosity_level;
unsigned char smallMode;
unsigned char noisy;
char *progName;
char inName[FILE_NAME_LEN];
char outName[FILE_NAME_LEN];
int srcMode;
@@ -347,7 +320,7 @@ const unsigned int BZ2_crc32Table[256] = {
0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
};
void bz_rand_udp_mask(DState *s)
static void bz_rand_udp_mask(DState *s)
{
if (s->rNToGo == 0) {
s->rNToGo = BZ2_rNums[s->rTPos];
@@ -369,43 +342,7 @@ static unsigned char myfeof(FILE *f)
return(FALSE);
}
static void cleanUpAndFail(int ec)
{
int retVal;
if ((srcMode == SM_F2F) && (opMode != OM_TEST) && deleteOutputOnInterrupt) {
if (noisy) {
error_msg("%s: Deleting output file %s, if it exists.\n", progName, outName);
}
if (outputHandleJustInCase != NULL) {
fclose(outputHandleJustInCase);
}
retVal = remove(outName);
if (retVal != 0) {
error_msg("%s: WARNING: deletion of output file (apparently) failed.\n", progName);
}
}
if (noisy && (numFileNames > 0) && (numFilesProcessed < numFileNames)) {
error_msg("%s: WARNING: some files have not been processed:\n"
"\t%d specified on command line, %d not processed yet.\n\n",
progName, numFileNames, numFileNames - numFilesProcessed );
}
exit(ec);
}
void panic(char *s)
{
error_msg("\n%s: PANIC -- internal consistency error:\n"
"\t%s\n"
"\tThis is a BUG. Please report it to me at:\n"
"\tjseward@acm.org\n",
progName, s);
cleanUpAndFail( 3 );
}
void BZ2_hbCreateDecodeTables(int *limit, int *base, int *perm, unsigned char *length, int minLen, int maxLen, int alphaSize )
static void BZ2_hbCreateDecodeTables(int *limit, int *base, int *perm, unsigned char *length, int minLen, int maxLen, int alphaSize )
{
int pp, i, j, vec;
@@ -446,40 +383,6 @@ void BZ2_hbCreateDecodeTables(int *limit, int *base, int *perm, unsigned char *l
}
}
int bz_get_small(DState *s)
{
int cccc;
int nb, na, mid;
nb = 0;
na = 256;
do {
mid = (nb + na) >> 1;
if (s->tPos >= s->cftab[mid]) {
nb = mid;
} else {
na = mid;
}
}
while (na - nb != 1);
cccc = nb;
s->tPos = (((unsigned int)s->ll16[s->tPos]) |
(((((unsigned int)(s->ll4[(s->tPos) >> 1])) >>
(((s->tPos) << 2) & 0x4)) & 0xF) << 16));
return(cccc);
}
void assert_h(int errcode)
{
error_msg_and_die("\n\nbzip2/libbzip2: internal error number %d.\n"
"This is a bug in bzip2/libbzip2, %s.\n"
"Please report it to me at: jseward@acm.org. If this happened\n"
"when you were using some program which uses libbzip2 as a\n"
"component, you should also report this bug to the author(s)\n"
"of that program. Please make an effort to report this bug;\n"
"timely and accurate bug reports eventually lead to higher\n"
"quality software. Thanks. Julian Seward, 21 March 2000.\n\n",
errcode, BZ_VERSION);
}
static int get_bits(DState *s, int *vvv, char nnn)
{
@@ -496,15 +399,11 @@ static int get_bits(DState *s, int *vvv, char nnn)
s->bsLive += 8;
s->strm->next_in++;
s->strm->avail_in--;
s->strm->total_in_lo32++;
if (s->strm->total_in_lo32 == 0) {
s->strm->total_in_hi32++;
}
}
return(TRUE);
}
int bz_get_fast(DState *s)
static int bz_get_fast(DState *s)
{
int cccc;
s->tPos = s->tt[s->tPos];
@@ -514,12 +413,11 @@ int bz_get_fast(DState *s)
}
/*---------------------------------------------------*/
int BZ2_decompress(DState *s)
static inline int BZ2_decompress(DState *s)
{
int uc = 0;
int retVal;
int minLen, maxLen;
bz_stream *strm = s->strm;
/* stuff that needs to be saved/restored */
int i;
@@ -670,21 +568,7 @@ int BZ2_decompress(DState *s)
}
s->blockSize100k -= '0';
if (s->smallDecompress) {
s->ll16 = (strm->bzalloc)(strm->opaque, s->blockSize100k * 100000 * sizeof(unsigned short), 1);
s->ll4 = (strm->bzalloc)(strm->opaque, ((1 + s->blockSize100k * 100000) >> 1) * sizeof(unsigned char), 1);
if (s->ll16 == NULL || s->ll4 == NULL) {
retVal = BZ_MEM_ERROR;
goto save_state_and_return;
}
} else {
s->tt = (strm->bzalloc)(strm->opaque, s->blockSize100k * 100000 * sizeof(int), 1);
if (s->tt == NULL) {
retVal = BZ_MEM_ERROR;
goto save_state_and_return;
}
}
s->tt = xmalloc(s->blockSize100k * 100000 * sizeof(int));
case BZ_X_BLKHDR_1:
s->state = BZ_X_BLKHDR_1;
@@ -757,9 +641,6 @@ int BZ2_decompress(DState *s)
}
s->currBlockNo++;
if (s->verbosity >= 2) {
error_msg("\n [%d: huff+mtf ", s->currBlockNo);
}
s->storedBlockCRC = 0;
case BZ_X_BCRC_1:
@@ -1135,26 +1016,14 @@ int BZ2_decompress(DState *s)
uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ];
s->unzftab[uc] += es;
if (s->smallDecompress) {
while (es > 0) {
if (nblock >= nblockMAX) {
retVal = BZ_DATA_ERROR;
goto save_state_and_return;
}
s->ll16[nblock] = (unsigned short)uc;
nblock++;
es--;
}
} else {
while (es > 0) {
if (nblock >= nblockMAX) {
retVal = BZ_DATA_ERROR;
goto save_state_and_return;
}
s->tt[nblock] = (unsigned int)uc;
nblock++;
es--;
while (es > 0) {
if (nblock >= nblockMAX) {
retVal = BZ_DATA_ERROR;
goto save_state_and_return;
}
s->tt[nblock] = (unsigned int)uc;
nblock++;
es--;
}
continue;
} else {
@@ -1217,11 +1086,7 @@ int BZ2_decompress(DState *s)
/*-- end uc = MTF ( nextSym-1 ) --*/
s->unzftab[s->seqToUnseq[uc]]++;
if (s->smallDecompress) {
s->ll16[nblock] = (unsigned short)(s->seqToUnseq[uc]);
} else {
s->tt[nblock] = (unsigned int)(s->seqToUnseq[uc]);
}
s->tt[nblock] = (unsigned int)(s->seqToUnseq[uc]);
nblock++;
if (! get_mtf_val_init()) {
@@ -1271,9 +1136,6 @@ int BZ2_decompress(DState *s)
s->state_out_ch = 0;
s->calculatedBlockCRC = 0xffffffffL;
s->state = BZ_X_OUTPUT;
if (s->verbosity >= 2) {
error_msg("rt+rld");
}
/*-- Set up cftab to facilitate generation of T^(-1) --*/
s->cftab[0] = 0;
@@ -1284,82 +1146,27 @@ int BZ2_decompress(DState *s)
s->cftab[i] += s->cftab[i-1];
}
if (s->smallDecompress) {
/*-- compute the T^(-1) vector --*/
for (i = 0; i < nblock; i++) {
uc = (unsigned char)(s->tt[i] & 0xff);
s->tt[s->cftab[uc]] |= (i << 8);
s->cftab[uc]++;
}
/*-- Make a copy of cftab, used in generation of T --*/
for (i = 0; i <= 256; i++) {
s->cftabCopy[i] = s->cftab[i];
}
s->tPos = s->tt[s->origPtr] >> 8;
s->nblock_used = 0;
if (s->blockRandomised) {
s->rNToGo = 0;
s->rTPos = 0;
s->k0 = bz_get_fast(s);
/*-- compute the T vector --*/
for (i = 0; i < nblock; i++) {
uc = (unsigned char)(s->ll16[i]);
s->ll16[i] = (unsigned short)(s->cftabCopy[uc] & 0x0000ffff);
if (((i) & 0x1) == 0) {
s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (s->cftabCopy[uc] >> 16);
} else {
s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((s->cftabCopy[uc] >> 16) << 4);
}
s->cftabCopy[uc]++;
}
/*-- Compute T^(-1) by pointer reversal on T --*/
i = s->origPtr;
j = (((unsigned int)s->ll16[i]) |
(((((unsigned int)(s->ll4[(i) >> 1])) >>
(((i) << 2) & 0x4)) & 0xF) << 16));
do {
const int tmp = (((unsigned int)s->ll16[j]) |
(((((unsigned int)(s->ll4[(j) >> 1])) >>
(((j) << 2) & 0x4)) & 0xF) << 16));
s->ll16[j] = (unsigned short)(i & 0x0000ffff);
if (((j) & 0x1) == 0) {
s->ll4[(j) >> 1] = (s->ll4[(j) >> 1] & 0xf0) | (i >> 16);
} else {
s->ll4[(j) >> 1] = (s->ll4[(j) >> 1] & 0x0f) | ((i >> 16) << 4);
}
i = j;
j = tmp;
}
while (i != s->origPtr);
s->tPos = s->origPtr;
s->nblock_used = 0;
if (s->blockRandomised) {
s->rNToGo = 0;
s->rTPos = 0;
s->k0 = bz_get_small(s);
s->nblock_used++;
bz_rand_udp_mask(s);
s->k0 ^= ((s->rNToGo == 1) ? 1 : 0);
} else {
s->k0 = bz_get_small(s);
s->nblock_used++;
}
} else {
/*-- compute the T^(-1) vector --*/
for (i = 0; i < nblock; i++) {
uc = (unsigned char)(s->tt[i] & 0xff);
s->tt[s->cftab[uc]] |= (i << 8);
s->cftab[uc]++;
}
s->tPos = s->tt[s->origPtr] >> 8;
s->nblock_used = 0;
if (s->blockRandomised) {
s->rNToGo = 0;
s->rTPos = 0;
s->k0 = bz_get_fast(s);
s->nblock_used++;
bz_rand_udp_mask(s);
s->k0 ^= ((s->rNToGo == 1) ? 1 : 0);
} else {
s->k0 = bz_get_fast(s);
s->nblock_used++;
}
}
s->nblock_used++;
bz_rand_udp_mask(s);
s->k0 ^= ((s->rNToGo == 1) ? 1 : 0);
} else {
s->k0 = bz_get_fast(s);
s->nblock_used++;
}
retVal = BZ_OK;
goto save_state_and_return;
@@ -1456,13 +1263,8 @@ endhdr_2:
retVal = BZ_STREAM_END;
goto save_state_and_return;
default:
printf("switch val is %d\n", switch_val);
assert_h(4001);
}
assert_h(4002);
save_state_and_return:
s->save_i = i;
s->save_j = j;
@@ -1492,73 +1294,28 @@ save_state_and_return:
return retVal;
}
static void *default_bzalloc(void *opaque, int items, int size)
{
void *v = xmalloc(items *size);
return v;
}
static void default_bzfree(void *opaque, void *addr)
{
if (addr != NULL) {
free(addr);
}
}
//int BZ2_bzDecompressInit(bz_stream* strm, int verbosity_level, int small)
int BZ2_bzDecompressInit(bz_stream* strm, int small)
static inline int BZ2_bzDecompressInit(bz_stream* strm)
{
DState* s;
if (sizeof(int) != 4) {
return BZ_CONFIG_ERROR;
}
if (sizeof(short) != 2) {
return BZ_CONFIG_ERROR;
}
if (sizeof(char) != 1) {
return BZ_CONFIG_ERROR;
}
if (strm == NULL) {
return BZ_PARAM_ERROR;
}
if (small != 0 && small != 1) {
return BZ_PARAM_ERROR;
}
// if (verbosity_level < 0 || verbosity_level > 4) {
// return BZ_PARAM_ERROR;
// }
if (strm->bzalloc == NULL) {
strm->bzalloc = default_bzalloc;
}
if (strm->bzfree == NULL) {
strm->bzfree = default_bzfree;
}
s = (strm->bzalloc)(strm->opaque, sizeof(DState), 1);
if (s == NULL) {
return BZ_MEM_ERROR;
}
s = xmalloc(sizeof(DState));
s->strm = strm;
strm->state = s;
s->state = BZ_X_MAGIC_1;
s->bsLive = 0;
s->bsBuff = 0;
s->calculatedCombinedCRC = 0;
strm->total_in_lo32 = 0;
strm->total_in_hi32 = 0;
strm->total_out_lo32 = 0;
strm->total_out_hi32 = 0;
s->smallDecompress = (unsigned char)small;
s->ll4 = NULL;
s->ll16 = NULL;
s->tt = NULL;
s->currBlockNo = 0;
// s->verbosity = verbosity_level;
return BZ_OK;
}
void bz_seterr(int eee, int *bzerror, bzFile **bzf)
static void bz_seterr(int eee, int *bzerror, bzFile **bzf)
{
if (bzerror != NULL) {
*bzerror = eee;
@@ -1568,20 +1325,11 @@ void bz_seterr(int eee, int *bzerror, bzFile **bzf)
}
}
void BZ2_bzReadClose(int *bzerror, void *b)
static void BZ2_bzReadClose(int *bzerror, void *b)
{
bzFile* bzf = (bzFile*)b;
bz_seterr(BZ_OK, bzerror, &bzf);
if (bzf == NULL) {
bz_seterr(BZ_OK, bzerror, &bzf);
return;
}
if (bzf->writing) {
bz_seterr(BZ_SEQUENCE_ERROR, bzerror, &bzf);
return;
}
if (bzf->initialisedOk) {
bz_stream *strm = &(bzf->strm);
@@ -1593,16 +1341,8 @@ void BZ2_bzReadClose(int *bzerror, void *b)
if ((s == NULL) || (s->strm != strm)) {
return;
}
if (s->tt != NULL) {
(strm->bzfree)(strm->opaque,(s->tt));
}
if (s->ll16 != NULL) {
(strm->bzfree)(strm->opaque,(s->ll16));
}
if (s->ll4 != NULL) {
(strm->bzfree)(strm->opaque,(s->ll4));
}
(strm->bzfree)(strm->opaque,(strm->state));
free(s->tt);
free(strm->state);
strm->state = NULL;
return;
}
@@ -1630,10 +1370,6 @@ static void unRLE_obuf_to_output_FAST(DState *s)
s->state_out_len--;
s->strm->next_out++;
s->strm->avail_out--;
s->strm->total_out_lo32++;
if (s->strm->total_out_lo32 == 0) {
s->strm->total_out_hi32++;
}
}
/* can a new run be started? */
@@ -1702,9 +1438,7 @@ static void unRLE_obuf_to_output_FAST(DState *s)
unsigned int cs_avail_out = s->strm->avail_out;
/* end restore */
unsigned int avail_out_INIT = cs_avail_out;
int s_save_nblockPP = s->save_nblock+1;
unsigned int total_out_lo32_old;
while (1) {
/* try to finish existing run */
@@ -1801,11 +1535,6 @@ s_state_out_len_eq_one:
}
return_notr:
total_out_lo32_old = s->strm->total_out_lo32;
s->strm->total_out_lo32 += (avail_out_INIT - cs_avail_out);
if (s->strm->total_out_lo32 < total_out_lo32_old) {
s->strm->total_out_hi32++;
}
/* save */
s->calculatedBlockCRC = c_calculatedBlockCRC;
@@ -1820,191 +1549,20 @@ return_notr:
/* end save */
}
}
static void unRLE_obuf_to_output_SMALL(DState *s)
{
unsigned char k1;
if (s->blockRandomised) {
while (1) {
/* try to finish existing run */
while (1) {
if (s->strm->avail_out == 0) {
return;
}
if (s->state_out_len == 0) {
break;
}
*((unsigned char *)(s->strm->next_out)) = s->state_out_ch;
s->calculatedBlockCRC = (s->calculatedBlockCRC << 8) ^
BZ2_crc32Table[(s->calculatedBlockCRC >> 24) ^
((unsigned char)s->state_out_ch)];
s->state_out_len--;
s->strm->next_out++;
s->strm->avail_out--;
s->strm->total_out_lo32++;
if (s->strm->total_out_lo32 == 0) {
s->strm->total_out_hi32++;
}
}
/* can a new run be started? */
if (s->nblock_used == s->save_nblock+1) {
return;
}
s->state_out_len = 1;
s->state_out_ch = s->k0;
k1 = bz_get_small(s);
bz_rand_udp_mask(s);
k1 ^= ((s->rNToGo == 1) ? 1 : 0);
s->nblock_used++;
if (s->nblock_used == s->save_nblock+1) {
continue;
}
if (k1 != s->k0) {
s->k0 = k1;
continue;
}
s->state_out_len = 2;
k1 = bz_get_small(s);
bz_rand_udp_mask(s);
k1 ^= ((s->rNToGo == 1) ? 1 : 0);
s->nblock_used++;
if (s->nblock_used == s->save_nblock+1) {
continue;
}
if (k1 != s->k0) {
s->k0 = k1;
continue;
}
s->state_out_len = 3;
k1 = bz_get_small(s);
bz_rand_udp_mask(s);
k1 ^= ((s->rNToGo == 1) ? 1 : 0);
s->nblock_used++;
if (s->nblock_used == s->save_nblock+1) {
continue;
}
if (k1 != s->k0) {
s->k0 = k1;
continue;
}
k1 = bz_get_small(s);
bz_rand_udp_mask(s);
k1 ^= ((s->rNToGo == 1) ? 1 : 0);
s->nblock_used++;
s->state_out_len = ((int)k1) + 4;
s->k0 = bz_get_small(s);
bz_rand_udp_mask(s);
s->k0 ^= ((s->rNToGo == 1) ? 1 : 0);
s->nblock_used++;
}
} else {
while (1) {
/* try to finish existing run */
while (1) {
if (s->strm->avail_out == 0) {
return;
}
if (s->state_out_len == 0) {
break;
}
*((unsigned char *)(s->strm->next_out)) = s->state_out_ch;
s->calculatedBlockCRC = (s->calculatedBlockCRC << 8) ^
BZ2_crc32Table[(s->calculatedBlockCRC >> 24) ^
((unsigned char)s->state_out_ch)];
s->state_out_len--;
s->strm->next_out++;
s->strm->avail_out--;
s->strm->total_out_lo32++;
if (s->strm->total_out_lo32 == 0) {
s->strm->total_out_hi32++;
}
}
/* can a new run be started? */
if (s->nblock_used == s->save_nblock+1) {
return;
}
s->state_out_len = 1;
s->state_out_ch = s->k0;
k1 = bz_get_small(s);
s->nblock_used++;
if (s->nblock_used == s->save_nblock+1) {
continue;
}
if (k1 != s->k0) {
s->k0 = k1;
continue;
}
s->state_out_len = 2;
k1 = bz_get_small(s);
s->nblock_used++;
if (s->nblock_used == s->save_nblock+1) {
continue;
}
if (k1 != s->k0) {
s->k0 = k1;
continue;
}
s->state_out_len = 3;
k1 = bz_get_small(s);
s->nblock_used++;
if (s->nblock_used == s->save_nblock+1) {
continue;
}
if (k1 != s->k0) {
s->k0 = k1;
continue;
}
k1 = bz_get_small(s);
s->nblock_used++;
s->state_out_len = ((int)k1) + 4;
s->k0 = bz_get_small(s);
s->nblock_used++;
}
}
}
static inline
int BZ2_bzDecompress(bz_stream *strm)
{
DState* s;
if (strm == NULL) {
return BZ_PARAM_ERROR;
}
s = strm->state;
if (s == NULL) {
return BZ_PARAM_ERROR;
}
if (s->strm != strm) {
return BZ_PARAM_ERROR;
}
while (1) {
if (s->state == BZ_X_IDLE) {
return BZ_SEQUENCE_ERROR;
}
if (s->state == BZ_X_OUTPUT) {
if (s->smallDecompress) {
unRLE_obuf_to_output_SMALL(s);
} else {
unRLE_obuf_to_output_FAST(s);
}
unRLE_obuf_to_output_FAST(s);
if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) {
s->calculatedBlockCRC = ~(s->calculatedBlockCRC);
if (s->verbosity >= 3) {
error_msg("{0x%x, 0x%x}", s->storedBlockCRC, s->calculatedBlockCRC);
}
if (s->verbosity >= 2) {
error_msg("]");
}
if (s->calculatedBlockCRC != s->storedBlockCRC) {
return BZ_DATA_ERROR;
}
@@ -2018,10 +1576,6 @@ int BZ2_bzDecompress(bz_stream *strm)
if (s->state >= BZ_X_MAGIC_1) {
int r = BZ2_decompress(s);
if (r == BZ_STREAM_END) {
if (s->verbosity >= 3) {
error_msg("\n combined CRCs: stored = 0x%x, computed = 0x%x",
s->storedCombinedCRC, s->calculatedCombinedCRC );
}
if (s->calculatedCombinedCRC != s->storedCombinedCRC) {
return BZ_DATA_ERROR;
}
@@ -2033,28 +1587,16 @@ int BZ2_bzDecompress(bz_stream *strm)
}
}
assert_h(6001);
return(0); /*NOTREACHED*/
}
int BZ2_bzRead(int *bzerror, void *b, void *buf, int len)
static inline int BZ2_bzRead(int *bzerror, void *b, void *buf, int len)
{
int n, ret;
bzFile *bzf = (bzFile*)b;
bz_seterr(BZ_OK, bzerror, &bzf);
if (bzf == NULL || buf == NULL || len < 0) {
bz_seterr(BZ_PARAM_ERROR, bzerror, &bzf);
return 0;
}
if (bzf->writing) {
bz_seterr(BZ_SEQUENCE_ERROR, bzerror, &bzf);
return 0;
}
if (len == 0) {
bz_seterr(BZ_OK, bzerror, &bzf);
return 0;
@@ -2104,75 +1646,29 @@ int BZ2_bzRead(int *bzerror, void *b, void *buf, int len)
return(0); /*not reached*/
}
void BZ2_bzReadGetUnused(int *bzerror, void *b, void **unused, int *nUnused)
static inline void *BZ2_bzReadOpen(int *bzerror, FILE *f, void *unused, int nUnused)
{
bzFile *bzf = (bzFile*)b;
if (bzf == NULL) {
bz_seterr(BZ_PARAM_ERROR, bzerror, &bzf);
return;
}
if (bzf->lastErr != BZ_STREAM_END) {
bz_seterr(BZ_SEQUENCE_ERROR, bzerror, &bzf);
return;
}
if (unused == NULL || nUnused == NULL) {
bz_seterr(BZ_PARAM_ERROR, bzerror, &bzf);
return;
}
bz_seterr(BZ_OK, bzerror, &bzf);
*nUnused = bzf->strm.avail_in;
*unused = bzf->strm.next_in;
}
void *BZ2_bzReadOpen(int *bzerror, FILE *f, int small, void *unused, int nUnused)
{
bzFile *bzf = NULL;
bzFile *bzf = xmalloc(sizeof(bzFile));
int ret;
bz_seterr(BZ_OK, bzerror, &bzf);
if (f == NULL || (small != 0 && small != 1) ||
(unused != NULL && (nUnused < 0 || nUnused > BZ_MAX_UNUSED)) ||
// (verbosity_level < 0 || verbosity_level > 4) ||
(unused == NULL && nUnused != 0)) {
bz_seterr(BZ_PARAM_ERROR, bzerror, &bzf);
return NULL;
}
if (ferror(f)) {
bz_seterr(BZ_IO_ERROR, bzerror, &bzf);
return NULL;
}
bzf = xmalloc(sizeof(bzFile));
if (bzf == NULL) {
bz_seterr(BZ_MEM_ERROR, bzerror, &bzf);
return NULL;
}
bz_seterr(BZ_OK, bzerror, &bzf);
bzf->initialisedOk = FALSE;
bzf->handle = f;
bzf->bufN = 0;
bzf->writing = FALSE;
bzf->strm.bzalloc = NULL;
bzf->strm.bzfree = NULL;
bzf->strm.opaque = NULL;
while (nUnused > 0) {
bzf->buf[bzf->bufN] = *((unsigned char *)(unused)); bzf->bufN++;
unused = ((void *)( 1 + ((unsigned char *)(unused)) ));
nUnused--;
}
ret = BZ2_bzDecompressInit(&(bzf->strm), small);
ret = BZ2_bzDecompressInit(&(bzf->strm));
if (ret != BZ_OK) {
bz_seterr(ret, bzerror, &bzf);
free(bzf);
return NULL;
}
while (nUnused > 0) {
bzf->buf[bzf->bufN] = *((unsigned char *)(unused)); bzf->bufN++;
unused = ((void *)( 1 + ((unsigned char *)(unused)) ));
nUnused--;
}
bzf->strm.avail_in = bzf->bufN;
bzf->strm.next_in = bzf->buf;
@@ -2180,12 +1676,12 @@ void *BZ2_bzReadOpen(int *bzerror, FILE *f, int small, void *unused, int nUnused
return bzf;
}
static unsigned char uncompressStream(FILE *zStream, FILE *stream)
static inline unsigned char uncompressStream(FILE *zStream, FILE *stream)
{
unsigned char unused[BZ_MAX_UNUSED];
unsigned char *unusedTmp;
unsigned char obuf[5000];
void *bzf = NULL;
bzFile *bzf = NULL;
int bzerr_dummy;
int bzerr;
int nread;
@@ -2205,7 +1701,7 @@ static unsigned char uncompressStream(FILE *zStream, FILE *stream)
}
while(1) {
bzf = BZ2_bzReadOpen(&bzerr, zStream, (int)smallMode, unused, nUnused);
bzf = BZ2_bzReadOpen(&bzerr, zStream, unused, nUnused);
if (bzf == NULL || bzerr != BZ_OK) {
goto errhandler;
}
@@ -2226,17 +1722,13 @@ static unsigned char uncompressStream(FILE *zStream, FILE *stream)
if (bzerr != BZ_STREAM_END) {
goto errhandler;
}
BZ2_bzReadGetUnused(&bzerr, bzf, (void **)(&unusedTmp), &nUnused);
if (bzerr != BZ_OK) {
panic("decompress:bzReadGetUnused");
}
nUnused = bzf->strm.avail_in;
unusedTmp = bzf->strm.next_in;
bz_seterr(BZ_OK, &bzerr, &bzf);
for (i = 0; i < nUnused; i++) {
unused[i] = unusedTmp[i];
}
BZ2_bzReadClose(&bzerr, bzf);
if (bzerr != BZ_OK) {
panic("decompress:bzReadGetUnused");
}
if ((nUnused == 0) && myfeof(zStream)) {
break;
}
@@ -2262,38 +1754,25 @@ static unsigned char uncompressStream(FILE *zStream, FILE *stream)
goto errhandler_io;
}
}
// if (verbosity_level >= 2) {
// fprintf(stderr,"\n ");
// }
return TRUE;
errhandler:
BZ2_bzReadClose ( &bzerr_dummy, bzf );
switch (bzerr) {
case BZ_CONFIG_ERROR:
error_msg("bzip2: I'm not configured correctly for this platform!\n"
"\tI require Int32, Int16 and Char to have sizes\n"
"\tof 4, 2 and 1 bytes to run properly, and they don't.\n"
"\tProbably you can fix this by defining them correctly,\n"
"\tand recompiling. Bye!\n" );
exit(3);
case BZ_IO_ERROR:
errhandler_io:
error_msg("\n%s: I/O or other error, bailing out. "
"Possible reason follows.\n", progName);
perror(progName);
cleanUpAndFail(1);
"Possible reason follows.\n", applet_name);
perror(applet_name);
exit(1);
case BZ_DATA_ERROR:
error_msg("\n%s: Data integrity error when decompressing.\n", progName);
cleanUpAndFail(2);
case BZ_MEM_ERROR:
error_msg("\n%s: couldn't allocate enough memory\n", progName);
cleanUpAndFail(1);
error_msg("\n%s: Data integrity error when decompressing.\n", applet_name);
exit(2);
case BZ_UNEXPECTED_EOF:
error_msg("\n%s: Compressed file ends unexpectedly;\n\t"
"perhaps it is corrupted? *Possible* reason follows.\n", progName);
perror(progName);
cleanUpAndFail(2);
"perhaps it is corrupted? *Possible* reason follows.\n", applet_name);
perror(applet_name);
exit(2);
case BZ_DATA_ERROR_MAGIC:
if (zStream != stdin) {
fclose(zStream);
@@ -2304,16 +1783,10 @@ errhandler_io:
if (streamNo == 1) {
return FALSE;
} else {
if (noisy) {
error_msg("\n%s: %s: trailing garbage after EOF ignored\n", progName, inName );
}
return TRUE;
return TRUE;
}
default:
panic ( "decompress:unexpected error" );
}
panic("decompress:end");
return(TRUE); /*notreached*/
}
+9 -1
View File
@@ -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,7 +24,9 @@ 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
+182 -38
View File
@@ -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);
}
+168 -80
View File
@@ -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);
}
}
@@ -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,40 +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];
unsigned int package_num;
package_num = search_package_hashtable(package_edge->name, package_edge->version, package_edge->operator);
if (package_hashtable[package_num] == NULL) {
error_msg_and_die("Dependency checking failed for package %s\nNOTE: This may be due to busybox dpkg's inability to handle the Provides field, you may avoid dependency checking using the \"-F depends\" option ", name_hashtable[package_edge->name]);
}
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++;
@@ -1032,7 +1059,7 @@ 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;
int length = 0;
int count = 0;
@@ -1040,12 +1067,11 @@ char **create_list(const char *filename)
/* 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));
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
@@ -1203,10 +1246,8 @@ void remove_package(const unsigned int package_num)
/* Some directories cant be removed straight away, so do multiple passes */
while (remove_file_array(remove_files, exclude_files));
/* Create a list of all /var/lib/dpkg/info/<package> files */
remove_files = xmalloc(sizeof(char *) * 11);
all_control_list(remove_files, package_name);
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));
free_array(remove_files);
/* Create a list of all /var/lib/dpkg/info/<package> files */
remove_files = xmalloc(sizeof(char *) * 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 + 2);
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
View File
@@ -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);
}
+88 -81
View File
@@ -64,26 +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)
{
int flags = 0;
int opt = 0;
int delete_old_file, file_count;
struct stat stat_buf;
FILE *in_file, *out_file;
char *if_name, *of_name, *delete_file_name;
const int gunzip_to_stdout = 1;
const int gunzip_force = 2;
const int gunzip_test = 4;
const int gunzip_verbose = 8;
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, "ctfhdqv")) != -1) {
while ((opt = getopt(argc, argv, "ctfhd")) != -1) {
switch (opt) {
case 'c':
flags |= gunzip_to_stdout;
@@ -94,109 +97,113 @@ extern int gunzip_main(int argc, char **argv)
case 't':
flags |= gunzip_test;
break;
case 'v':
flags |= gunzip_verbose;
case 'd': /* Used to convert gzip to gunzip. */
break;
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 */
}
}
file_count = argc - optind;
while (file_count==0 || optind < argc) {
in_file = stdin;
out_file = NULL;
if_name = NULL;
of_name = NULL;
delete_file_name = NULL;
delete_old_file = FALSE;
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 input filename and number */
if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
optind++;
if (old_path == NULL || strcmp(old_path, "-") == 0) {
src_fd = fileno(stdin);
flags |= gunzip_to_stdout;
/* Skip to the end */
optind = argc;
} else {
if_name = strdup(argv[optind]);
/* Open input file */
in_file = xfopen(if_name, "r");
if (flags & gunzip_verbose) {
fprintf(stderr, "%s:\t", if_name);
}
/* set the buffer size */
setvbuf(in_file, NULL, _IOFBF, 0x8000);
src_fd = xopen(old_path, O_RDONLY);
/* 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);
if (stat(old_path, &stat_buf) < 0) {
error_msg_and_die("Couldn't stat file %s", old_path);
}
}
/* 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.");
if (isatty(src_fd) && ((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 ? */
dst_fd = xopen("/dev/null", O_WRONLY); /* why does test use filenum 2 ? */
} else if (flags & gunzip_to_stdout) {
out_file = stdout;
dst_fd = fileno(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;
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");
}
of_name = (char *) xcalloc(sizeof(char), length + 1);
strncpy(of_name, if_name, length);
/* Open output file */
out_file = xfopen(of_name, "w");
dst_fd = xopen(new_path, O_WRONLY | O_CREAT);
/* Set permissions on the file */
chmod(of_name, stat_buf.st_mode);
chmod(new_path, stat_buf.st_mode);
/* If unzip succeeds remove the old file */
delete_path = old_path;
}
/* do the decompression, and cleanup */
if (unzip(in_file, out_file) == 0) {
/* Success, remove .gz file */
delete_file_name = if_name;
if (flags & gunzip_verbose) {
fprintf(stderr, "OK\n");
}
} else {
/* remove failed attempt */
delete_file_name = of_name;
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");
}
}
fclose(out_file);
fclose(in_file);
if (delete_old_file == TRUE && !(flags & gunzip_test)) {
if (unlink(delete_file_name) < 0) {
error_msg_and_die("Couldnt remove %s", delete_file_name);
}
if ((status != EXIT_SUCCESS) && (new_path)) {
/* Unzip failed, remove new path instead of old path */
delete_path = new_path;
}
free(of_name);
optind++;
} /* while () */
if (dst_fd != fileno(stdout)) {
close(dst_fd);
}
if (src_fd != fileno(stdin)) {
close(src_fd);
}
return(EXIT_SUCCESS);
/* 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;
}
+237 -241
View File
File diff suppressed because it is too large. Load diff
+40 -8
View File
@@ -22,14 +22,46 @@ ifndef $(LIBUNARCHIVE_DIR)
LIBUNARCHIVE_DIR:=$(TOPDIR)archival/libunarchive/
endif
LIBUNARCHIVE-y:=unarchive.o seek_sub_file.o
LIBUNARCHIVE-$(CONFIG_DPKG) += deb_extract.o get_header_ar.o get_header_tar.o
LIBUNARCHIVE-$(CONFIG_DPKG_DEB) += deb_extract.o get_header_ar.o get_header_tar.o
LIBUNARCHIVE-$(CONFIG_AR) += get_header_ar.o
LIBUNARCHIVE-$(CONFIG_CPIO) += get_header_cpio.o
LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += get_header_cpio.o
LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
LIBUNARCHIVE-$(CONFIG_UNZIP) += get_header_zip.o
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)
+15
View File
@@ -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);
}
+68
View File
@@ -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;
}
+13
View File
@@ -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);
}
+76
View File
@@ -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);
}
+27
View File
@@ -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);
}
-83
View File
@@ -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
+14
View File
@@ -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);
}
+30
View File
@@ -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);
}
+60 -44
View File
@@ -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);
}
-136
View File
@@ -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);
}
+117 -40
View File
@@ -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);
}
+80
View File
@@ -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);
}
-110
View File
@@ -1,110 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* get_header_zip 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
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "unarchive.h"
#include "libbb.h"
#define ZIP_FILEHEADER_MAGIC 0x04034b50
#define ZIP_CDS_MAGIC 0x02014b50
#define ZIP_CDS_END_MAGIC 0x06054b50
#define ZIP_DD_MAGIC 0x8074b50
file_header_t *get_header_zip(FILE *zip_stream)
{
struct {
short version __attribute__ ((packed));
short flags __attribute__ ((packed));
short method __attribute__ ((packed));
short modtime __attribute__ ((packed));
short moddate __attribute__ ((packed));
int crc32 __attribute__ ((packed));
int cmpsize __attribute__ ((packed));
int ucmpsize __attribute__ ((packed));
short filename_len __attribute__ ((packed));
short extra_len __attribute__ ((packed));
} zip_header;
file_header_t *zip_entry = NULL;
int magic;
static int dd_ahead = 0; // If this is true, the we didn't know how long the last extraced file was
fread (&magic, 4, 1, zip_stream);
archive_offset += 4;
if (feof(zip_stream)) return(NULL);
checkmagic:
switch (magic) {
case ZIP_FILEHEADER_MAGIC:
zip_entry = xcalloc(1, sizeof(file_header_t));
fread (&zip_header, sizeof(zip_header), 1, zip_stream);
archive_offset += sizeof(zip_header);
if (!(zip_header.method == 8 || zip_header.method == 0)) { printf("Unsupported compression method %d\n", zip_header.method); return(NULL); }
zip_entry->name = calloc(zip_header.filename_len + 1, sizeof(char));
fread (zip_entry->name, sizeof(char), zip_header.filename_len, zip_stream);
archive_offset += zip_header.filename_len;
seek_sub_file(zip_stream, zip_header.extra_len);
zip_entry->size = zip_header.cmpsize;
if (zip_header.method == 8) zip_entry->extract_func = &inflate;
zip_entry->mode = S_IFREG | 0777;
// Time/Date?
if (*(zip_entry->name + strlen(zip_entry->name) - 1) == '/') { // Files that end in a / are directories
zip_entry->mode ^= S_IFREG;
zip_entry->mode |= S_IFDIR;
*(zip_entry->name + strlen(zip_entry->name) - 1) = '\0'; // Remove trailing / so unarchive doesn't get confused
}
//printf("cmpsize: %d, ucmpsize: %d, method: %d\n", zip_header.cmpsize, zip_header.ucmpsize, zip_header.method);
if (zip_header.flags & 0x8) { // crc32, and sizes are in the data description _after_ the file
if (zip_header.cmpsize == 0) dd_ahead = 1; // As we don't know how long this file it is difficult to skip! but it is compressed, so normally its ok
if (zip_header.ucmpsize != 0) dd_ahead = 2; // Humm... we would otherwise skip this twice - not good!
}
break;
case ZIP_CDS_MAGIC: /* FALLTHRU */
case ZIP_CDS_END_MAGIC:
return(NULL);
break;
case ZIP_DD_MAGIC: {
int cmpsize;
seek_sub_file(zip_stream, 4); // Skip crc32
fread(&cmpsize, 4, 1, zip_stream);
archive_offset += 4;
if (dd_ahead == 1) archive_offset += cmpsize;
seek_sub_file(zip_stream, 4); // Skip uncompressed size
dd_ahead = 0;
return (get_header_zip(zip_stream));
break; }
default:
if (!dd_ahead) error_msg("Invalid magic (%#x): Trying to skip junk", magic);
dd_ahead = 0;
while (!feof(zip_stream)) {
int tmpmagic;
tmpmagic = fgetc(zip_stream);
archive_offset++;
magic = ((magic >> 8) & 0x00ffffff) | ((tmpmagic << 24) & 0xff000000);
if (magic == ZIP_FILEHEADER_MAGIC || magic == ZIP_CDS_MAGIC || magic == ZIP_CDS_END_MAGIC) goto checkmagic;
}
error_msg("End of archive reached: Bad archive");
return(NULL);
}
//if (archive_offset != ftell(zip_stream)) printf("Archive offset out of sync (%d,%d)\n", (int) archive_offset, (int) ftell(zip_stream));
return(zip_entry);
}
+7
View File
@@ -0,0 +1,7 @@
#include <stdio.h>
#include "unarchive.h"
extern void header_list(const file_header_t *file_header)
{
puts(file_header->name);
}
+7
View File
@@ -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("");
}
+18
View File
@@ -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);
}
+10 -13
View File
@@ -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;
}
}
-263
View File
@@ -1,263 +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 <sys/wait.h>
#include <signal.h>
#include "unarchive.h"
#include "busybox.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;
if (file_entry->extract_func) file_entry->extract_func(src_stream, dst_stream);
else 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;
#ifdef CONFIG_FEATURE_UNARCHIVE_TAPE
int pid, tape_pipe[2];
if (pipe(tape_pipe) != 0) error_msg_and_die("Can't create pipe\n");
if ((pid = fork()) == -1) error_msg_and_die("Fork failed\n");
if (pid==0) { /* child process */
close(tape_pipe[0]); /* We don't wan't to read from the pipe */
copyfd(fileno(src_stream), tape_pipe[1]);
close(tape_pipe[1]); /* Send EOF */
exit(0);
/* notreached */
}
close(tape_pipe[1]); /* Don't want to write down the pipe */
fclose(src_stream);
src_stream = fdopen(tape_pipe[0], "r");
#endif
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) {
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);
}
#ifdef CONFIG_FEATURE_UNARCHIVE_TAPE
kill(pid, SIGTERM);
waitpid(pid, NULL, 0);
#endif
return(buffer);
}
+307
View File
@@ -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
+34
View File
@@ -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);
}
File diff suppressed because it is too large. Load diff
+40 -23
View File
@@ -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;
}
+382 -348
View File
File diff suppressed because it is too large. Load diff
+191 -41
View File
@@ -20,6 +20,10 @@
*
*/
/* 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>
@@ -28,67 +32,213 @@
#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)
{
FILE *src_stream;
int extract_function = extract_all_to_fs | extract_create_leading_dirs;
char **extract_names = NULL;
char **exclude_names = NULL;
int opt = 0;
int num_of_entries = 0;
int exclude = 0;
char *outdir = "./";
FILE *msgout = stdout;
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;
while ((opt = getopt(argc, argv, "lnopqxd:")) != -1) {
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':
extract_function |= extract_verbose_list;
extract_function ^= extract_all_to_fs;
case 'l': /* list */
archive_handle->action_header = header_verbose_list_unzip;
archive_handle->action_data = data_skip;
break;
case 'n':
case 'n': /* never overwright existing files */
break;
case 'o':
extract_function |= extract_unconditional;
archive_handle->flags = ARCHIVE_EXTRACT_UNCONDITIONAL;
break;
case 'p':
extract_function |= extract_to_stdout;
extract_function ^= extract_all_to_fs;
/* FALLTHROUGH */
case 'q':
msgout = xfopen("/dev/null", "w");
case 'p': /* extract files to stdout */
archive_handle->action_data = data_extract_to_stdout;
break;
case 'd':
outdir = xstrdup(optarg);
strcat(outdir, "/");
case 'q': /* Extract files quietly */
archive_handle->action_header = header_skip;
break;
case 'x':
exclude = 1;
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 (optind == argc) {
if (argc == optind) {
show_usage();
}
if (*argv[optind] == '-') src_stream = stdin;
else src_stream = xfopen(argv[optind++], "r");
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) {
if (exclude) {
exclude_names = xrealloc(exclude_names, sizeof(char *) * (num_of_entries + 2));
exclude_names[num_of_entries] = xstrdup(argv[optind]);
} else {
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
extract_names[num_of_entries] = xstrdup(argv[optind]);
}
num_of_entries++;
if (exclude) exclude_names[num_of_entries] = NULL;
else 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, msgout, &get_header_zip, extract_function, outdir, extract_names, exclude_names);
return EXIT_SUCCESS;
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);
}
+1
View File
@@ -30,6 +30,7 @@ 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
+1 -1
View File
@@ -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");
+1
View File
@@ -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
+1 -1
View File
@@ -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 */
+1 -1
View File
@@ -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);
+97
View File
@@ -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:
*/
+2 -2
View File
@@ -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;
}
+1 -1
View File
@@ -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]);
+4 -8
View File
@@ -31,12 +31,12 @@
#include <time.h>
#include <unistd.h>
#include "busybox.h"
#ifdef CONFIG_LOCALE_SUPPORT
#include <locale.h>
#endif
#include "busybox.h"
#define THURSDAY 4 /* for reformation */
#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
@@ -372,7 +372,7 @@ void trim_trailing_spaces(char *s)
for (p = s; *p; ++p)
continue;
while (p > s && isspace(*--p))
while (p > s && (--p, isspace(*p)))
continue;
if (p > s)
++p;
@@ -404,11 +404,7 @@ void center(char *str, int len, int separate)
* 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.
*
+29 -17
View File
@@ -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)) {
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])) {
for (; opt < argc; opt++) {
if (! recursive_action (argv[opt], recursiveFlag, FALSE, FALSE, fileAction,
fileAction, smode)) {
return EXIT_FAILURE;
}
}
+126 -90
View File
@@ -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");
+1 -1
View File
@@ -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) {
+35 -33
View File
@@ -37,19 +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 int one_file_system = 0;
static dev_t dir_dev = 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
@@ -114,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);
}
}
@@ -142,27 +139,32 @@ int du_main(int argc, char **argv)
/* parse argv[] */
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;
case 'x':
one_file_system = 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) */
@@ -172,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();
@@ -184,7 +186,7 @@ int du_main(int argc, char **argv)
return status;
}
/* $Id: du.c,v 1.53 2002/04/06 23:16:44 andersen Exp $ */
/* $Id: du.c,v 1.55 2002/08/23 07:28:45 aaronl Exp $ */
/*
Local Variables:
c-file-style: "linux"
+2 -8
View File
@@ -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
View File
@@ -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
View File
@@ -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);
+17 -15
View File
@@ -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)
+1 -2
View File
@@ -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;
}
+447 -363
View File
File diff suppressed because it is too large. Load diff
+5 -5
View File
@@ -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
View File
@@ -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);
}
+4 -4
View File
@@ -28,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)
@@ -35,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++;
@@ -72,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;
@@ -81,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;
@@ -90,4 +91,3 @@ int mknod_main(int argc, char **argv)
perror_msg_and_die("%s", argv[0]);
return EXIT_SUCCESS;
}
+1 -5
View File
@@ -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.
*
+22 -3
View File
@@ -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) {
+6
View File
@@ -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
View File
@@ -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++)
+2 -2
View File
@@ -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
View File
@@ -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");
+102
View File
@@ -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;
}
+1 -2
View File
@@ -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;
}
+2 -1
View File
@@ -16,9 +16,9 @@
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include "pwd.h"
#include "busybox.h"
#include "pwd_.h"
static int start = 0;
static int stop = 0;
@@ -113,6 +113,7 @@ pid_is_exec(int pid, const char *exec)
sprintf(buf, "/proc/%d/cmdline", pid);
fp = fopen(buf, "r");
if (fp && fgets (buf, sizeof (buf), fp) ) {
fclose(fp);
if (strncmp (buf, exec, strlen(exec)) == 0)
return 1;
}
+83 -36
View File
@@ -45,17 +45,15 @@
<tr>
<td bgcolor="#EEEEE0">
BusyBox combines tiny versions of many common UNIX
utilities into a single small executable. It provides
minimalist replacements for most of the utilities you
usually find in fileutils, shellutils, findutils,
textutils, grep, gzip, tar, etc. BusyBox provides a
fairly complete POSIX environment for any small or
embedded system. The utilities in BusyBox generally
have fewer options than their full featured GNU
cousins; however, the options that are included provide
the expected functionality and behave very much like
their GNU counterparts.
BusyBox combines tiny versions of many common UNIX utilities
into a single small executable. It provides minimalist
replacements for most of the utilities you usually find in GNU
fileutils, shellutils, etc. The utilities in BusyBox generally
have fewer options than their full-featured GNU cousins;
however, the options that are included provide the expected
functionality and behave very much like their GNU counterparts.
BusyBox provides a fairly complete POSIX environment for any
small or embedded system.
<p>BusyBox has been written with size-optimization and
limited resources in mind. It is also extremely modular
@@ -94,8 +92,46 @@
<tr>
<td bgcolor="#EEEEE0">
<ul>
<li>
<b>6 March 2002 -- busybox.net now has mirrors!</b>
<p>
<li><b>18 September 2002 -- BusyBox 0.60.4 released</b>
I am very pleased to announce that the BusyBox 0.60.4
(stable) is now available for download. This is primarily
a bugfix release for the stable series to address all
the problems that have turned up since the last
release. This will be the last release for the 0.60.x series.
I mean it this time -- all further development work will be done
on the development busybox tree, which is quite solid now and
should soon be getting its first real release.
<p>
The <a href="downloads/Changelog.full">changelog</a> has all
the details. As usual you can <a href="downloads">download busybox here</a>.
<p>Have Fun!
<p>
<p>
<li><b>27 April 2002 -- BusyBox 0.60.3 released</b>
I am very pleased to announce that the BusyBox 0.60.3 (stable) is
now available for download. This is primarily a bugfix release
for the stable series. A number of problems have turned up since
the last release, and this should address most of those problems.
This should be the last release for the 0.60.x series. The
development busybox tree has been progressing nicely, and will
hopefully be ready to become the next stable release.
<p>
The <a href="downloads/Changelog">changelog</a> has all
the details. As usual you can <a href="downloads">download busybox here</a>.
<p>Have Fun!
<p>
<p>
<li><b>6 March 2002 -- busybox.net now has mirrors!</b>
<p>Busybox.net is now much more available, thanks to
the fine folks at <a href= "http://i-netinnovations.com/">http://i-netinnovations.com/</a>
@@ -108,6 +144,7 @@
accessible for everyone!
<p>
<li><b>Old News</b><br>
For the old news, visit <a href="oldnews.html">the
old news page</a>.</li>
@@ -131,18 +168,22 @@
<ul>
<li><a href=
"http://opensource.se/">opensource.se</a><br>
Embedded open source consulting in Europe.</li>
<li><a href="http://opensource.se/">opensource.se</a><br>
Embedded open source consulting in Europe.
</li>
<li><a href= "http://i-netinnovations.com/">http://i-netinnovations.com/</a><br>
Web hosting (they host busybox.net and uclibc.org).</li>
<li><a href="http://i-netinnovations.com/">http://i-netinnovations.com/</a><br>
Web hosting (currently hosting busybox.net and uclibc.org)
</li>
<li><a href=
"http://www.codepoet-consulting.com">Codepoet
Consulting</a><br>
<li><a href="http://www.lineo.com">Lineo</a><br>
Embedded Linux development and services.
</li>
<li><a href="http://www.codepoet-consulting.com">Codepoet Consulting</a><br>
Custom Linux, embedded Linux, BusyBox, and uClibc
development.</li>
development.
</li>
</ul>
Several individuals have also contributed. If you have
already contributed and would like your name added
@@ -161,21 +202,26 @@
<tr>
<td bgcolor="#EEEEE0">
Source for the latest release can always be
downloaded from <a href="downloads">http://www.busybox.net/downloads</a>.
<p>
BusyBox now has <b>two</b> CVS trees. The "busybox-stable"
tree contains the latest updates to the 0.60.x stable series.
The "busybox" tree contains the latest development version
of busybox.<br>
<ul>
<li>Source for the latest release can always be
downloaded from <a href=
"downloads">http://www.busybox.net/downloads</a>.</li>
<li>A new snapshot of the source is made daily and is
available as a GNU gzipped tarball <a href=
"downloads/snapshots/busybox-snapshot.tar.bz2">right here</a>.</li>
<li>BusyBox now has its own publically browsable <a
href="/cgi-bin/cvsweb/busybox/">CVS tree</a>,
anonymous <a href="cvs_anon.html">CVS access</a>, and
for those that are actively contributing there is
even <a href="cvs_write.html">CVS write
access</a>.</li>
<li><a href= "downloads/snapshots/">Daily Snapshots of the the latest
stable, and the latest development CVS source trees can be found right here</a>.
<br>
</li><li><a href="/cgi-bin/cvsweb/busybox/">Click here to browse the CVS
tree for the development version of BusyBox</a>
</li><li><a href="/cgi-bin/cvsweb/busybox.stable/">Click here to browse
the CVS tree for the stable 0.60.x version of BusyBox</a>.
</li><li>Anonymous <a href="cvs_anon.html">CVS
access</a> is available.
</li><li>For those that are actively contributing there is
even <a href="cvs_write.html">CVS write access</a>.</li>
</ul>
</td>
</tr>
@@ -374,6 +420,7 @@
<li><a href="http://zaurus.sourceforge.net/">Sharp Zaurus
PDA</a></li>
<li><a href="http://familiar.handhelds.org/">Familiar Linux</a> - a linux distribution for handheld computers</li>
</ul>
+1 -1
View File
@@ -142,7 +142,7 @@
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="andersen@codepoet.org">
<input type="hidden" name="item_name" value="Support Busybox/Buy busybox.net">
<input type="hidden" name="item_name" value="Support Busybox">
<input type="hidden" name="image_url" value="https://busybox.net/images/busybox2.jpg">
<input type="hidden" name="no_shipping" value="1">
<input type="image" src="images/donate.png" border="0" name="submit" alt="Make donation using PayPal">
+1 -1
View File
@@ -22,7 +22,7 @@ font-family: monospace; font-size: smaller;" width="80%">
$ ./busybox
BusyBox v0.60.3-pre (2002.02.13-23:05+0000) multi-call binary
BusyBox v0.60.3 (2002.04.27-10:33+0000) multi-call binary
Usage: busybox [function] [arguments]...
or: [function] [arguments]...
+1
View File
@@ -3103,6 +3103,7 @@
-O FILE Use an alternate log file (default=/var/log/messages)
-R HOST[:PORT] Log remotely to IP or hostname on PORT (default PORT=514/UDP)
-L Log locally as well as network logging (default is network only)
-C Log to a circular buffer. Read this buffer using 'logread'
</screen>
</para>
+3 -2
View File
@@ -113,7 +113,8 @@ Glenn McGrath <bug1@netconnect.com.au>
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.
=for html <br>
@@ -166,4 +167,4 @@ Enrique Zanardi <ezanardi@ull.es>
=cut
# $Id: busybox_footer.pod,v 1.5 2001/12/18 14:06:01 andersen Exp $
# $Id: busybox_footer.pod,v 1.7 2002/10/22 12:24:56 andersen Exp $
+14 -14
View File
@@ -55,20 +55,20 @@ terse runtime description of their behavior.
Currently defined functions include:
addgroup, adduser, adjtimex, ar, basename, busybox, cat, chgrp, chmod,
chown, chroot, chvt, clear, cmp, cp, cpio, cut, date, dc, dd, deallocvt,
deluser, df, dirname, dmesg, dos2unix, dpkg, dpkg-deb, du, dumpkmap, dutmp,
echo, expr, false, fbset, fdflush, find, free, freeramdisk, fsck.minix,
getopt, getty, grep, gunzip, gzip, halt, head, hostid, hostname, id,
ifconfig, init, insmod, kill, killall, klogd, length, ln, loadacm,
loadfont, loadkmap, logger, logname, ls, lsmod, makedevs, md5sum, mkdir,
mkfifo, mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc,
nslookup, ping, pivot_root, poweroff, printf, ps, pwd, rdate, readlink,
reboot, renice, reset, rm, rmdir, rmmod, route, rpm2cpio, sed, setkeycodes,
sh, sleep, sort, stty, swapoff, swapon, sync, syslogd, tail, tar, tee,
telnet, test, tftp, touch, tr, true, tty, umount, uname, uniq, unix2dos,
update, uptime, usleep, uudecode, uuencode, watchdog, wc, wget, which,
whoami, xargs, yes, zcat, [
addgroup, adduser, adjtimex, ar, awk, basename, busybox, cat, chgrp,
chmod, chown, chroot, chvt, clear, cmp, cp, cpio, crond, crontab, cut,
date, dc, dd, deallocvt, deluser, df, dirname, dmesg, dos2unix, dpkg,
dpkg-deb, du, dumpkmap, dutmp, echo, expr, false, fbset, fdflush, find,
free, freeramdisk, fsck.minix, getopt, getty, grep, gunzip, gzip, halt,
head, hostid, hostname, id, ifconfig, init, insmod, kill, killall, klogd,
length, ln, loadacm, loadfont, loadkmap, logger, logname, ls, lsmod,
makedevs, md5sum, mkdir, mkfifo, mkfs.minix, mknod, mkswap, mktemp, more,
mount, mt, mv, nc, netstat, nslookup, ping, pivot_root, poweroff, printf,
ps, pwd, rdate, readlink, reboot, renice, reset, rm, rmdir, rmmod, route,
rpm2cpio, sed, setkeycodes, sh, sleep, sort, stty, swapoff, swapon, sync,
syslogd, tail, tar, tee, telnet, telnetd, test, tftp, time, top, touch, tr,
true, tty, umount, uname, uniq, unix2dos, update, uptime, usleep, uudecode,
uuencode, watchdog, wc, wget, which, whoami, xargs, yes, zcat, [
=over 4
+40 -17
View File
@@ -96,6 +96,9 @@ struct sed_cmd {
/* the command */
char cmd; /* p,d,s (add more at your leisure :-) */
/* inversion flag */
int invert; /* the '!' after the address */
};
/* globals */
@@ -175,7 +178,7 @@ static int index_of_next_unescaped_regexp_delim(const struct sed_cmd * const sed
static int get_address(struct sed_cmd *sed_cmd, const char *str, int *linenum, regex_t **regex)
{
char *my_str = xstrdup(str);
int idx = 0;
int idx = 0, idx_start = 1;
char olddelimiter;
olddelimiter = sed_cmd->delimiter;
sed_cmd->delimiter = '/';
@@ -191,13 +194,17 @@ static int get_address(struct sed_cmd *sed_cmd, const char *str, int *linenum, r
*linenum = -1;
idx++;
}
else if (my_str[idx] == '/') {
else if (my_str[idx] == '/' || my_str[idx] == '\\') {
if (my_str[idx] == '\\') {
idx_start++;
sed_cmd-> delimiter = my_str[++idx];
}
idx = index_of_next_unescaped_regexp_delim(sed_cmd, my_str, ++idx);
if (idx == -1)
error_msg_and_die("unterminated match expression");
my_str[idx] = '\0';
*regex = (regex_t *)xmalloc(sizeof(regex_t));
xregcomp(*regex, my_str+1, REG_NEWLINE);
xregcomp(*regex, my_str+idx_start, REG_NEWLINE);
idx++; /* so it points to the next character after the last '/' */
}
else {
@@ -394,17 +401,30 @@ static char *parse_cmd_str(struct sed_cmd * const sed_cmd, const char *const cmd
*/
/* first part (if present) is an address: either a number or a /regex/ */
if (isdigit(cmdstr[idx]) || cmdstr[idx] == '/')
if (isdigit(cmdstr[idx]) || cmdstr[idx] == '/' || ( cmdstr[idx] == '\\' && cmdstr[idx+1] != '\\'))
idx = get_address(sed_cmd, cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match);
/* second part (if present) will begin with a comma */
if (cmdstr[idx] == ',')
idx += get_address(sed_cmd, &cmdstr[++idx], &sed_cmd->end_line, &sed_cmd->end_match);
if (cmdstr[idx] == ',') {
idx++;
idx += get_address(sed_cmd, &cmdstr[idx], &sed_cmd->end_line, &sed_cmd->end_match);
}
/* skip whitespace before the command */
while (isspace(cmdstr[idx]))
idx++;
/* there my be the inversion flag between part2 and part3 */
sed_cmd->invert = 0;
if (cmdstr[idx] == '!') {
sed_cmd->invert = 1;
idx++;
/* skip whitespace before the command */
while (isspace(cmdstr[idx]))
idx++;
}
/* last part (mandatory) will be a command */
if (cmdstr[idx] == '\0')
error_msg_and_die("missing command");
@@ -642,12 +662,12 @@ static void process_file(FILE *file)
/* for every line, go through all the commands */
for (i = 0; i < ncmds; i++) {
struct sed_cmd *sed_cmd = &sed_cmds[i];
int deleted = 0;
/*
* entry point into sedding...
*/
if (
int matched = (
/* no range necessary */
(sed_cmd->beg_line == 0 && sed_cmd->end_line == 0 &&
sed_cmd->beg_match == NULL &&
@@ -658,8 +678,9 @@ static void process_file(FILE *file)
(sed_cmd->beg_match && (regexec(sed_cmd->beg_match, line, 0, NULL, 0) == 0)) ||
/* we are currently within the beginning & ending address range */
still_in_range
) {
int deleted = 0;
);
if (sed_cmd->invert ^ matched) {
/*
* actual sedding
@@ -746,13 +767,15 @@ static void process_file(FILE *file)
/* else if we couldn't open the output file,
* no biggie, just don't print anything */
altered++;
}
}
break;
}
}
/*
* exit point from sedding...
*/
/*
* exit point from sedding...
*/
if (matched) {
if (
/* this is a single-address command or... */
(sed_cmd->end_line == 0 && sed_cmd->end_match == NULL) || (
@@ -774,10 +797,10 @@ static void process_file(FILE *file)
else {
still_in_range = 1;
}
if (deleted)
break;
}
if (deleted)
break;
}
/* we will print the line unless we were told to be quiet or if the
+889 -881
View File
File diff suppressed because it is too large. Load diff
+28 -18
View File
@@ -3,6 +3,7 @@
# Copyright (c) 2001 David Schleef <ds@schleef.org>
# Copyright (c) 2001 Erik Andersen <andersen@lineo.com>
# Copyright (c) 2001 Stuart Hughes <stuarth@lineo.com>
# Copyright (c) 2002 Steven J. Hill <shill@broadcom.com>
# This program is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
@@ -18,7 +19,7 @@ use File::Find;
my $basedir="";
my $kernel;
my $kernelsyms;
my $stdout=1;
my $stdout=0;
my $verbose=0;
@@ -38,13 +39,13 @@ GetOptions(
if (defined $opt{help}) {
print
"$0 [OPTION]... [basedir]\n",
"\t-h --help\t\tShow this help screen\n",
"\t-b --basedir\t\tModules base directory (defaults to /lib/modules)\n",
"\t-k --kernel\t\tKernel binary for the target\n",
"\t-F --kernelsyms\t\tKernel symbol file\n",
"\t-n --stdout\t\tWrite to stdout instead of modules.dep\n",
"\t-v --verbose\t\tPrint out lots of debugging stuff\n",
" $0 [OPTION]... [basedir]\n",
" -h --help\t\tShow this help screen\n",
" -b --basedir\tModules base directory (defaults to /lib/modules)\n",
" -k --kernel\tKernel binary for the target\n",
" -F --kernelsyms\tKernel symbol file\n",
" -n --stdout\tWrite to stdout instead of <basedir>/modules.dep\n",
" -v --verbose\tPrint out lots of debugging stuff\n",
;
exit 1;
}
@@ -55,6 +56,7 @@ if($basedir !~ m-/lib/modules-) {
# Find the list of .o files living under $basedir
#if ($verbose) { printf "Locating all modules\n"; }
my($ofile) = "";
my($file) = "";
my(@liblist) = ();
find sub {
@@ -127,16 +129,24 @@ foreach $module (keys %$dep) {
}
# resolve the dependancies for each module
foreach $module ( keys %$mod ) {
print "$module:\t";
@sorted = sort bydep keys %{$mod->{$module}};
print join(" \\\n\t",@sorted);
# foreach $m (@sorted ) {
# print "\t$m\n";
# }
print "\n\n";
if ($stdout == 1) {
foreach $module ( keys %$mod ) {
print "$module:\t";
@sorted = sort bydep keys %{$mod->{$module}};
print join(" \\\n\t",@sorted);
print "\n\n";
}
} else {
open(OFILE, ">$basedir/modules.dep");
foreach $module ( keys %$mod ) {
print OFILE "$module:\t";
@sorted = sort bydep keys %{$mod->{$module}};
print OFILE join(" \\\n\t",@sorted);
print OFILE "\n\n";
}
}
sub bydep
{
foreach my $f ( keys %{$mod->{$b}} ) {
@@ -158,7 +168,7 @@ depmod.pl - a cross platform script to generate kernel module dependency
=head1 SYNOPSIS
depmod.pl [OPTION]... [FILE]...
depmod.pl [OPTION]... [basedir]...
Example:
@@ -223,5 +233,5 @@ David Schleef <ds@schleef.org>
=cut
# $Id: depmod.pl,v 1.1 2001/07/30 19:32:03 andersen Exp $
# $Id: depmod.pl,v 1.2 2002/10/08 21:33:51 sjhill Exp $
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
# Sample udhcpc renew script
RESOLV_CONF="/etc/udhcpc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ]
then
echo "deleting routers"
while /sbin/route del default gw 0.0.0.0 dev $interface
do :
done
for i in $router
do
/sbin/route add default gw $i dev $interface
done
fi
echo -n > $RESOLV_CONF
[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
for i in $dns
do
echo adding dns $i
echo nameserver $i >> $RESOLV_CONF
done
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
# Sample udhcpc deconfig script
/sbin/ifconfig $interface 0.0.0.0
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
# Sample udhcpc nak script
echo Received a NAK: $message
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
# Sample udhcpc bound script
RESOLV_CONF="/etc/udhcpc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ]
then
echo "deleting routers"
while /sbin/route del default gw 0.0.0.0 dev $interface
do :
done
for i in $router
do
/sbin/route add default gw $i dev $interface
done
fi
echo -n > $RESOLV_CONF
[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
for i in $dns
do
echo adding dns $i
echo nameserver $i >> $RESOLV_CONF
done
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
# Currently, we only dispatch according to command. However, a more
# elaborate system might dispatch by command and interface or do some
# common initialization first, especially if more dhcp event notifications
# are added.
exec /usr/share/udhcpc/sample.$1
+39
View File
@@ -0,0 +1,39 @@
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
RESOLV_CONF="/etc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
case "$1" in
deconfig)
/sbin/ifconfig $interface 0.0.0.0
;;
renew|bound)
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ] ; then
echo "deleting routers"
while route del default gw 0.0.0.0 dev $interface ; do
:
done
for i in $router ; do
route add default gw $i dev $interface
done
fi
echo -n > $RESOLV_CONF
[ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
for i in $dns ; do
echo adding dns $i
echo nameserver $i >> $RESOLV_CONF
done
;;
esac
exit 0
+116
View File
@@ -0,0 +1,116 @@
# Sample udhcpd configuration file (/etc/udhcpd.conf)
# The start and end of the IP lease block
start 192.168.0.20 #default: 192.168.0.20
end 192.168.0.254 #default: 192.168.0.254
# The interface that udhcpd will use
interface eth0 #default: eth0
# The maximim number of leases (includes addressesd reserved
# by OFFER's, DECLINE's, and ARP conficts
#max_leases 254 #default: 254
# If remaining is true (default), udhcpd will store the time
# remaining for each lease in the udhcpd leases file. This is
# for embedded systems that cannot keep time between reboots.
# If you set remaining to no, the absolute time that the lease
# expires at will be stored in the dhcpd.leases file.
#remaining yes #default: yes
# The time period at which udhcpd will write out a dhcpd.leases
# file. If this is 0, udhcpd will never automatically write a
# lease file. (specified in seconds)
#auto_time 7200 #default: 7200 (2 hours)
# The amount of time that an IP will be reserved (leased) for if a
# DHCP decline message is received (seconds).
#decline_time 3600 #default: 3600 (1 hour)
# The amount of time that an IP will be reserved (leased) for if an
# ARP conflct occurs. (seconds
#conflict_time 3600 #default: 3600 (1 hour)
# How long an offered address is reserved (leased) in seconds
#offer_time 60 #default: 60 (1 minute)
# If a lease to be given is below this value, the full lease time is
# instead used (seconds).
#min_lease 60 #defult: 60
# The location of the leases file
#lease_file /var/lib/misc/udhcpd.leases #defualt: /var/lib/misc/udhcpd.leases
# The location of the pid file
#pidfile /var/run/udhcpd.pid #default: /var/run/udhcpd.pid
# Everytime udhcpd writes a leases file, the below script will be called.
# Useful for writing the lease file to flash every few hours.
#notify_file #default: (no script)
#notify_file dumpleases # <--- usefull for debugging
# The following are bootp specific options, setable by udhcpd.
#siaddr 192.168.0.22 #default: 0.0.0.0
#sname zorak #default: (none)
#boot_file /var/nfs_root #default: (none)
# The remainer of options are DHCP options and can be specifed with the
# keyword 'opt' or 'option'. If an option can take multiple items, such
# as the dns option, they can be listed on the same line, or multiple
# lines. The only option with a default is 'lease'.
#Examles
opt dns 192.168.10.2 192.168.10.10
option subnet 255.255.255.0
opt router 192.168.10.2
opt wins 192.168.10.10
option dns 129.219.13.81 # appened to above DNS servers for a total of 3
option domain local
option lease 864000 # 10 days of seconds
# Currently supported options, for more info, see options.c
#subnet
#timezone
#router
#timesvr
#namesvr
#dns
#logsvr
#cookiesvr
#lprsvr
#bootsize
#domain
#swapsvr
#rootpath
#ipttl
#mtu
#broadcast
#wins
#lease
#ntpsrv
#tftp
#bootfile
+1
View File
@@ -11,6 +11,7 @@ if [ "$CONFIG_FIND" = "y" ] ; then
bool ' Enable modified time matching (-mtime) option' CONFIG_FEATURE_FIND_MTIME
bool ' Enable permissions matching (-perm) option' CONFIG_FEATURE_FIND_PERM
bool ' Enable filetype matching (-type) option' CONFIG_FEATURE_FIND_TYPE
bool ' Enable stay in filesystem (-xdev) option' CONFIG_FEATURE_FIND_XDEV
fi
bool 'grep' CONFIG_GREP
if [ "$CONFIG_GREP" = "y" ] ; then
+43
View File
@@ -51,6 +51,12 @@ static char mtime_char;
static int mtime_days;
#endif
#ifdef CONFIG_FEATURE_FIND_XDEV
static dev_t *xdev_dev;
static int xdev_count = 0;
#endif
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{
if (pattern != NULL) {
@@ -88,6 +94,22 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
goto no_match;
}
#endif
#ifdef CONFIG_FEATURE_FIND_XDEV
if (xdev_count) {
int i;
for (i=0; i<xdev_count; i++) {
if (xdev_dev[i] == statbuf-> st_dev)
break;
}
if (i == xdev_count) {
if(S_ISDIR(statbuf->st_mode))
return SKIP;
else
goto no_match;
}
}
#endif
puts(fileName);
no_match:
return (TRUE);
@@ -179,6 +201,27 @@ int find_main(int argc, char **argv)
error_msg_and_die("invalid argument `%s' to `-mtime'", argv[i]);
if ((mtime_char = argv[i][0]) == '-')
mtime_days = -mtime_days;
#endif
#ifdef CONFIG_FEATURE_FIND_XDEV
} else if (strcmp(argv[i], "-xdev") == 0) {
struct stat stbuf;
xdev_count = ( firstopt - 1 ) ? ( firstopt - 1 ) : 1;
xdev_dev = xmalloc ( xdev_count * sizeof( dev_t ));
if ( firstopt == 1 ) {
if ( stat ( ".", &stbuf ) < 0 )
error_msg_and_die("could not stat '.'" );
xdev_dev [0] = stbuf. st_dev;
}
else {
for (i = 1; i < firstopt; i++) {
if ( stat ( argv [i], &stbuf ) < 0 )
error_msg_and_die("could not stat '%s'", argv [i] );
xdev_dev [i-1] = stbuf. st_dev;
}
}
#endif
} else
show_usage();
+21 -21
View File
@@ -28,8 +28,10 @@
int xargs_main(int argc, char **argv)
{
char *cmd_to_be_executed = NULL;
char *file_to_act_on = NULL;
char *cmd_to_be_executed;
char *file_to_act_on;
int i;
int len;
/*
* No options are supported in this version of xargs; no getopt.
@@ -42,44 +44,42 @@ int xargs_main(int argc, char **argv)
* once with no args and xargs will echo the filename. Simple.
*/
argv++;
len = argc; /* arg = count for ' ' + trailing '\0' */
/* Store the command to be executed (taken from the command line) */
if (argc == 1) {
/* default behavior is to echo all the filenames */
cmd_to_be_executed = xstrdup("/bin/echo ");
argv[0] = "/bin/echo";
len++; /* space for trailing '\0' */
} else {
/* concatenate all the arguments passed to xargs together */
int i;
int len = 1; /* for the '\0' */
cmd_to_be_executed = xmalloc(80);
for (i = 1; i < argc; i++) {
len += strlen(argv[i]);
len += 1; /* for the space between the args */
cmd_to_be_executed = xrealloc(cmd_to_be_executed, len);
strcat(cmd_to_be_executed, argv[i]);
strcat(cmd_to_be_executed, " ");
argc--;
}
/* concatenate all the arguments passed to xargs together */
for (i = 0; i < argc; i++)
len += strlen(argv[i]);
cmd_to_be_executed = xmalloc (len);
for (i = len = 0; i < argc; i++) {
len = sprintf(cmd_to_be_executed + len, "%s ", argv[i]);
}
/* Now, read in one line at a time from stdin, and store this
* line to be used later as an argument to the command */
while ((file_to_act_on = get_line_from_file(stdin)) !=NULL) {
FILE *cmd_output = NULL;
char *output_line = NULL;
char *execstr = NULL;
FILE *cmd_output;
char *output_line;
char *execstr;
/* eat the newline off the filename. */
chomp(file_to_act_on);
/* eat blank lines */
if (strlen(file_to_act_on) == 0)
if (file_to_act_on[0] == 0)
continue;
/* assemble the command and execute it */
execstr = xcalloc(strlen(cmd_to_be_executed) +
strlen(file_to_act_on) + 1, sizeof(char));
strcat(execstr, cmd_to_be_executed);
strcat(execstr, file_to_act_on);
bb_asprintf(&execstr, "%s%s", cmd_to_be_executed, file_to_act_on);
cmd_output = popen(execstr, "r");
if (cmd_output == NULL)
perror_msg_and_die("popen");
Loaded 100 of 266 files, more files were not shown because too many files have changed in this diff. Show more