Compare commits

...
213 Commits
Author SHA1 Message Date
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
176 changed files with 21914 additions and 10588 deletions

No files matched your search

+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--
+14 -15
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
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
@@ -222,10 +221,10 @@ clean:
- 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
+38 -8
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,
+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:
+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*/
}
+3 -1
View File
@@ -18,7 +18,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
+124 -74
View File
@@ -487,19 +487,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 +903,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 +945,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 +995,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 +1058,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 +1066,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 +1144,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 +1245,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 +1255,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 +1287,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) {
@@ -1284,7 +1331,7 @@ 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);
@@ -1328,7 +1375,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,8 +1435,9 @@ 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) {
deb_file[deb_count]->filename = xstrdup(argv[optind]);
@@ -1408,7 +1456,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 +1463,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 +1535,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 +1545,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++) {
+63 -79
View File
@@ -66,24 +66,22 @@ static char *license_msg[] = {
#include <getopt.h>
#include "busybox.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 +92,95 @@ 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 {
FILE *in_file, *out_file;
struct stat stat_buf;
const char *old_path = argv[optind];
const char *delete_path = NULL;
char *new_path = NULL;
/* Set input filename and number */
if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
optind++;
if (old_path == NULL || strcmp(old_path, "-") == 0) {
in_file = 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);
in_file = wfopen(old_path, "r");
if (in_file == NULL) {
status = EXIT_FAILURE;
break;
}
/* set the buffer size */
setvbuf(in_file, NULL, _IOFBF, 0x8000);
/* 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(fileno(in_file)) && ((flags & gunzip_force) == 0)) {
error_msg_and_die
("compressed data not read from terminal. Use -f to force it.");
}
/* Set output filename and number */
if (flags & gunzip_test) {
out_file = xfopen("/dev/null", "w"); /* why does test use filenum 2 ? */
out_file = xfopen("/dev/null", "w"); /* why does test use filenum 2 ? */
} else if (flags & gunzip_to_stdout) {
out_file = stdout;
} else {
char *extension;
int length = strlen(if_name);
delete_old_file = TRUE;
extension = strrchr(if_name, '.');
if (extension && strcmp(extension, ".gz") == 0) {
length -= 3;
} else if (extension && strcmp(extension, ".tgz") == 0) {
length -= 4;
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");
out_file = xfopen(new_path, "w");
/* 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 ((unzip(in_file, out_file) != 0) && (new_path)) {
/* Unzip failed, remove new path instead of old path */
delete_path = new_path;
}
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 (out_file != stdout) {
fclose(out_file);
}
if (in_file != stdin) {
fclose(in_file);
}
free(of_name);
optind++;
} /* while () */
/* 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);
}
return(EXIT_SUCCESS);
free(new_path);
} while (optind < argc);
return status;
}
+237 -241
View File
File diff suppressed because it is too large. Load diff
+2 -1
View File
@@ -80,4 +80,5 @@ char *deb_extract(const char *package_filename, FILE *out_stream,
free(file_list);
}
return(output_buffer);
}
}
@@ -0,0 +1,313 @@
#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>
#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);
extern int uncompress ( FILE *, FILE * );
/*
* 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.
*/
int uncompress ( FILE * fdin, FILE * fdout )
{
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] = fgetc(fdin);
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)
{
rsize = fread(inbuf+insize, 1,IBUFSIZ,fdin);
if ( !rsize && ferror(fdin))
return -1;
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)
{
fwrite(outbuf, 1,outpos,fdout);
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)
fwrite(outbuf, outpos,1, fdout);
return 0;
}
#endif
File diff suppressed because it is too large. Load diff
+3 -3
View File
@@ -91,8 +91,7 @@ file_header_t *get_header_ar(FILE *src_stream)
}
} 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';
@@ -103,4 +102,5 @@ file_header_t *get_header_ar(FILE *src_stream)
typed->gid = atoi(ar.formated.gid);
return(typed);
}
}
+2 -1
View File
@@ -133,4 +133,5 @@ file_header_t *get_header_cpio(FILE *src_stream)
}
}
return(cpio_entry);
}
}
+98 -32
View File
@@ -20,24 +20,24 @@
#include "unarchive.h"
#include "libbb.h"
file_header_t *get_header_tar(FILE *tar_stream)
file_header_t *get_header_tar(FILE * tar_stream)
{
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 */
@@ -55,45 +55,111 @@ file_header_t *get_header_tar(FILE *tar_stream)
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);
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
return (NULL);
}
/* If there is no filename its an empty header, skip it */
if (tar.formated.name[0] == 0) {
return (NULL);
}
/* Do checksum on headers */
for (i = 0; i < 148 ; i++) {
for (i = 0; i < 148; i++) {
sum += tar.raw[i];
}
sum += ' ' * 8;
for (i = 156; i < 512 ; i++) {
for (i = 156; i < 512; i++) {
sum += tar.raw[i];
}
if (sum != strtol(tar.formated.chksum, NULL, 8)) {
error_msg("Invalid tar header checksum");
return(NULL);
return (NULL);
}
/* 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) {
tar_entry->name = xstrdup(tar.formated.name);
} else {
tar_entry->name =
concat_path_file(tar.formated.prefix, tar.formated.name);
}
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->mode = strtol(tar.formated.mode, NULL, 8);
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) ?
xstrdup(tar.formated.linkname) : NULL;
tar_entry->device = (strtol(tar.formated.devmajor, NULL, 8) << 8) +
strtol(tar.formated.devminor, NULL, 8);
tar_entry->link_name =
strlen(tar.formated.linkname) ? xstrdup(tar.formated.linkname) : NULL;
tar_entry->device =
(dev_t) ((strtol(tar.formated.devmajor, NULL, 8) << 8) +
strtol(tar.formated.devminor, NULL, 8));
return(tar_entry);
}
#if defined CONFIG_FEATURE_TAR_OLD_FORMAT || defined CONFIG_FEATURE_GNUTAR_LONG_FILENAME
switch (tar.formated.typeflag) {
# ifdef CONFIG_FEATURE_TAR_OLD_FORMAT
case 0:
tar_entry->mode |= S_IFREG;
break;
case 1:
error_msg("internal hard link not handled\n");
break;
case 2:
tar_entry->mode |= S_IFLNK;
break;
case 3:
tar_entry->mode |= S_IFCHR;
break;
case 4:
tar_entry->mode |= S_IFBLK;
break;
case 5:
tar_entry->mode |= S_IFDIR;
break;
case 6:
tar_entry->mode |= S_IFIFO;
break;
# endif
# ifdef CONFIG_FEATURE_GNUTAR_LONG_FILENAME
case 'L': {
char *longname;
longname = xmalloc(tar_entry->size + 1);
fread(longname, 1, tar_entry->size, tar_stream);
archive_offset += tar_entry->size;
longname[tar_entry->size] = '\0';
tar_entry = get_header_tar(tar_stream);
tar_entry->name = longname;
break;
}
case 'K': {
char *longname;
longname = xmalloc(tar_entry->size + 1);
fread(longname, 1, tar_entry->size, tar_stream);
archive_offset += tar_entry->size;
longname[tar_entry->size] = '\0';
tar_entry = get_header_tar(tar_stream);
tar_entry->link_name = longname;
break;
}
# endif
}
#endif
return (tar_entry);
}
+108 -47
View File
@@ -19,92 +19,153 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stddef.h>
#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
#define ZIP_FILEHEADER_MAGIC 0x04034b50
#define ZIP_CDS_MAGIC 0x02014b50
#define ZIP_CDS_END_MAGIC 0x06054b50
#define ZIP_DD_MAGIC 0x08074b50
enum {
zh_version,
zh_flags,
zh_method,
zh_modtime,
zh_moddate,
zh_crc32,
zh_cmpsize,
zh_ucmpsize,
zh_filename_len,
zh_extra_len
};
static const char fail_msg[] = "Invalid file or read error";
static int le_read_int(FILE *fp, int n)
{
int r = 0;
int s = 1;
int c;
archive_offset += n;
do {
if ((c = fgetc(fp)) == EOF) {
error_msg_and_die(fail_msg);
}
r += s * c;
s <<= 8;
} while (--n);
return r;
}
static void read_header(FILE *fp, int *zh)
{
static const char s[] = { 2, 2, 2, 2, 2, 4, 4, 4, 2, 2, 0 };
int i = 0;
do {
zh[i] = le_read_int(fp, s[i]);
} while (s[++i]);
}
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;
int zip_header[10];
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
int magic, tmpmagic;
/* If dd_ahead is true, we didn't know the last extracted file's length. */
static int dd_ahead = 0;
fread (&magic, 4, 1, zip_stream);
archive_offset += 4;
magic = le_read_int(zip_stream, 4);
if (feof(zip_stream)) return(NULL);
checkmagic:
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;
read_header(zip_stream, zip_header);
if (zip_header[zh_method] == 8) {
zip_entry->extract_func = &inflate;
} else if (zip_header[zh_method] != 0) {
error_msg_and_die("Unsupported compression method %d\n",
zip_header[zh_method]);
}
zip_entry->name = xmalloc(zip_header[zh_filename_len] + 1);
if (!fread(zip_entry->name, zip_header[zh_filename_len], 1, zip_stream)) {
error_msg_and_die(fail_msg);
}
archive_offset += zip_header[zh_filename_len];
seek_sub_file(zip_stream, zip_header[zh_extra_len]);
zip_entry->size = zip_header[zh_cmpsize];
zip_entry->mode = S_IFREG | 0777;
// Time/Date?
if (*(zip_entry->name + strlen(zip_entry->name) - 1) == '/') { // Files that end in a / are directories
/* Time/Date? */
zip_entry->name[zip_header[zh_filename_len]] = 0;
if (*(zip_entry->name + zip_header[zh_filename_len] - 1) == '/') {
/* Files that end in a / are directories */
/* Remove trailing / so unarchive doesn't get confused */
*(zip_entry->name + zip_header[zh_filename_len] - 1) = '\0';
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!
if (zip_header[zh_flags] & 0x8) {
/* crc32, and sizes are in the data description _after_ the file */
if (zip_header[zh_cmpsize] == 0) {
/* As we don't know how long this file it is difficult to skip!
* but it is compressed, so normally its ok */
dd_ahead = 1;
}
if (zip_header[zh_ucmpsize] != 0) {
/* Humm... we would otherwise skip this twice - not good! */
dd_ahead = 2;
}
}
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;
cmpsize = le_read_int(zip_stream, 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);
while ((tmpmagic = fgetc(zip_stream)) != EOF) {
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;
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);
error_msg_and_die(fail_msg);
}
//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);
}
+2 -1
View File
@@ -32,4 +32,5 @@ void seek_sub_file(FILE *src_stream, const int count)
}
}
return;
}
}
+4 -4
View File
@@ -58,9 +58,7 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f
return(NULL);
}
}
full_name = xmalloc(strlen(prefix) + strlen(path) + 1);
strcpy(full_name, prefix);
strcat(full_name, path);
bb_asprintf(&full_name, "%s%s", prefix, path);
} else {
full_name = file_entry->name;
}
@@ -192,7 +190,9 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f
fprintf(out_stream, "%s\n", full_name);
}
free(full_name);
if (prefix != NULL) {
free(full_name);
}
return(NULL); /* Maybe we should say if failed */
}
+313
View File
@@ -0,0 +1,313 @@
#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>
#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);
extern int uncompress ( FILE *, FILE * );
/*
* 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.
*/
int uncompress ( FILE * fdin, FILE * fdout )
{
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] = fgetc(fdin);
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)
{
rsize = fread(inbuf+insize, 1,IBUFSIZ,fdin);
if ( !rsize && ferror(fdin))
return -1;
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)
{
fwrite(outbuf, 1,outpos,fdout);
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)
fwrite(outbuf, outpos,1, fdout);
return 0;
}
#endif
File diff suppressed because it is too large. Load diff
+290 -245
View File
@@ -47,14 +47,17 @@
#include <fnmatch.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include "unarchive.h"
#include "busybox.h"
#ifdef CONFIG_FEATURE_TAR_CREATE
/* Tar file constants */
# define TAR_MAGIC "ustar" /* ustar and a null */
# define TAR_VERSION " " /* Be compatable with GNU tar format */
# define TAR_MAGIC "ustar" /* ustar and a null */
# define TAR_VERSION " " /* Be compatable with GNU tar format */
# ifndef MAJOR
# define MAJOR(dev) (((dev)>>8)&0xff)
@@ -66,26 +69,25 @@ static const int TAR_MAGIC_LEN = 6;
static const int TAR_VERSION_LEN = 2;
/* POSIX tar Header Block, from POSIX 1003.1-1990 */
enum { NAME_SIZE = 100 }; /* because gcc won't let me use 'static const int' */
struct TarHeader
{ /* byte offset */
char name[NAME_SIZE]; /* 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[NAME_SIZE]; /* 157-256 */
char magic[6]; /* 257-262 */
char version[2]; /* 263-264 */
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 (pad to exactly the TAR_BLOCK_SIZE) */
enum { NAME_SIZE = 100 }; /* because gcc won't let me use 'static const int' */
struct TarHeader { /* byte offset */
char name[NAME_SIZE]; /* 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[NAME_SIZE]; /* 157-256 */
char magic[6]; /* 257-262 */
char version[2]; /* 263-264 */
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 (pad to exactly the TAR_BLOCK_SIZE) */
};
typedef struct TarHeader TarHeader;
@@ -95,58 +97,56 @@ typedef struct TarHeader TarHeader;
** Even these functions use the xxxHardLinkInfo() functions.
*/
typedef struct HardLinkInfo HardLinkInfo;
struct HardLinkInfo
{
HardLinkInfo *next; /* Next entry in list */
dev_t dev; /* Device number */
ino_t ino; /* Inode number */
short linkCount; /* (Hard) Link Count */
char name[1]; /* Start of filename (must be last) */
struct HardLinkInfo {
HardLinkInfo *next; /* Next entry in list */
dev_t dev; /* Device number */
ino_t ino; /* Inode number */
short linkCount; /* (Hard) Link Count */
char name[1]; /* Start of filename (must be last) */
};
/* Some info to be carried along when creating a new tarball */
struct TarBallInfo
{
char* fileName; /* File name of the tarball */
int tarFd; /* Open-for-write file descriptor
for the tarball */
struct stat statBuf; /* Stat info for the tarball, letting
us know the inode and device that the
tarball lives, so we can avoid trying
to include the tarball into itself */
int verboseFlag; /* Whether to print extra stuff or not */
char** excludeList; /* List of files to not include */
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
struct TarBallInfo {
char *fileName; /* File name of the tarball */
int tarFd; /* Open-for-write file descriptor
for the tarball */
struct stat statBuf; /* Stat info for the tarball, letting
us know the inode and device that the
tarball lives, so we can avoid trying
to include the tarball into itself */
int verboseFlag; /* Whether to print extra stuff or not */
char **excludeList; /* List of files to not include */
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
};
typedef struct TarBallInfo TarBallInfo;
/* A nice enum with all the possible tar file content types */
enum TarFileType
{
REGTYPE = '0', /* regular file */
REGTYPE0 = '\0', /* regular file (ancient bug compat)*/
LNKTYPE = '1', /* hard link */
SYMTYPE = '2', /* symbolic link */
CHRTYPE = '3', /* character special */
BLKTYPE = '4', /* block special */
DIRTYPE = '5', /* directory */
FIFOTYPE = '6', /* FIFO special */
CONTTYPE = '7', /* reserved */
GNULONGLINK = 'K', /* GNU long (>100 chars) link name */
GNULONGNAME = 'L', /* GNU long (>100 chars) file name */
enum TarFileType {
REGTYPE = '0', /* regular file */
REGTYPE0 = '\0', /* regular file (ancient bug compat) */
LNKTYPE = '1', /* hard link */
SYMTYPE = '2', /* symbolic link */
CHRTYPE = '3', /* character special */
BLKTYPE = '4', /* block special */
DIRTYPE = '5', /* directory */
FIFOTYPE = '6', /* FIFO special */
CONTTYPE = '7', /* reserved */
GNULONGLINK = 'K', /* GNU long (>100 chars) link name */
GNULONGNAME = 'L', /* GNU long (>100 chars) file name */
};
typedef enum TarFileType TarFileType;
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
static void
addHardLinkInfo (HardLinkInfo **hlInfoHeadPtr, dev_t dev, ino_t ino,
short linkCount, const char *name)
static inline void addHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr, dev_t dev,
ino_t ino, short linkCount,
const char *name)
{
/* Note: hlInfoHeadPtr can never be NULL! */
HardLinkInfo *hlInfo;
hlInfo = (HardLinkInfo *)xmalloc(sizeof(HardLinkInfo)+strlen(name)+1);
hlInfo =
(HardLinkInfo *) xmalloc(sizeof(HardLinkInfo) + strlen(name) + 1);
if (hlInfo) {
hlInfo->next = *hlInfoHeadPtr;
*hlInfoHeadPtr = hlInfo;
@@ -158,8 +158,7 @@ addHardLinkInfo (HardLinkInfo **hlInfoHeadPtr, dev_t dev, ino_t ino,
return;
}
static void
freeHardLinkInfo (HardLinkInfo **hlInfoHeadPtr)
static void freeHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr)
{
HardLinkInfo *hlInfo = NULL;
HardLinkInfo *hlInfoNext = NULL;
@@ -177,21 +176,21 @@ freeHardLinkInfo (HardLinkInfo **hlInfoHeadPtr)
}
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
static HardLinkInfo *
findHardLinkInfo (HardLinkInfo *hlInfo, dev_t dev, ino_t ino)
static inline HardLinkInfo *findHardLinkInfo(HardLinkInfo * hlInfo, dev_t dev,
ino_t ino)
{
while(hlInfo) {
while (hlInfo) {
if ((ino == hlInfo->ino) && (dev == hlInfo->dev))
break;
hlInfo = hlInfo->next;
}
return(hlInfo);
return (hlInfo);
}
/* Put an octal string into the specified buffer.
* The number is zero and space padded and possibly null padded.
* Returns TRUE if successful. */
static int putOctal (char *cp, int len, long value)
* Returns TRUE if successful. */
static int putOctal(char *cp, int len, long value)
{
int tempLength;
char tempBuffer[32];
@@ -199,10 +198,10 @@ static int putOctal (char *cp, int len, long value)
/* Create a string of the specified length with an initial space,
* leading zeroes and the octal number, and a trailing null. */
sprintf (tempString, "%0*lo", len - 1, value);
sprintf(tempString, "%0*lo", len - 1, value);
/* If the string is too large, suppress the leading space. */
tempLength = strlen (tempString) + 1;
tempLength = strlen(tempString) + 1;
if (tempLength > len) {
tempLength--;
tempString++;
@@ -217,71 +216,77 @@ static int putOctal (char *cp, int len, long value)
return FALSE;
/* Copy the string to the field. */
memcpy (cp, tempString, len);
memcpy(cp, tempString, len);
return TRUE;
}
/* Write out a tar header for the specified file/directory/whatever */
static int
writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
const char *real_name, struct stat *statbuf)
static inline int writeTarHeader(struct TarBallInfo *tbInfo,
const char *header_name,
const char *real_name, struct stat *statbuf)
{
long chksum=0;
long chksum = 0;
struct TarHeader header;
const unsigned char *cp = (const unsigned char *) &header;
ssize_t size = sizeof(struct TarHeader);
memset( &header, 0, size);
strncpy(header.name, header_name, sizeof(header.name));
memset(&header, 0, size);
strncpy(header.name, header_name, sizeof(header.name));
putOctal(header.mode, sizeof(header.mode), statbuf->st_mode);
putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
putOctal(header.gid, sizeof(header.gid), statbuf->st_gid);
putOctal(header.size, sizeof(header.size), 0); /* Regular file size is handled later */
putOctal(header.size, sizeof(header.size), 0); /* Regular file size is handled later */
putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime);
strncpy(header.magic, TAR_MAGIC TAR_VERSION,
TAR_MAGIC_LEN + TAR_VERSION_LEN );
strncpy(header.magic, TAR_MAGIC TAR_VERSION,
TAR_MAGIC_LEN + TAR_VERSION_LEN);
/* Enter the user and group names (default to root if it fails) */
my_getpwuid(header.uname, statbuf->st_uid);
if (! *header.uname)
if (!*header.uname)
strcpy(header.uname, "root");
my_getgrgid(header.gname, statbuf->st_gid);
if (! *header.uname)
if (!*header.uname)
strcpy(header.uname, "root");
if (tbInfo->hlInfo) {
/* This is a hard link */
header.typeflag = LNKTYPE;
strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
strncpy(header.linkname, tbInfo->hlInfo->name,
sizeof(header.linkname));
} else if (S_ISLNK(statbuf->st_mode)) {
char *lpath = xreadlink(real_name);
if (!lpath) /* Already printed err msg inside xreadlink() */
return ( FALSE);
header.typeflag = SYMTYPE;
strncpy(header.linkname, lpath, sizeof(header.linkname));
if (!lpath) /* Already printed err msg inside xreadlink() */
return (FALSE);
header.typeflag = SYMTYPE;
strncpy(header.linkname, lpath, sizeof(header.linkname));
free(lpath);
} else if (S_ISDIR(statbuf->st_mode)) {
header.typeflag = DIRTYPE;
strncat(header.name, "/", sizeof(header.name));
header.typeflag = DIRTYPE;
strncat(header.name, "/", sizeof(header.name));
} else if (S_ISCHR(statbuf->st_mode)) {
header.typeflag = CHRTYPE;
putOctal(header.devmajor, sizeof(header.devmajor), MAJOR(statbuf->st_rdev));
putOctal(header.devminor, sizeof(header.devminor), MINOR(statbuf->st_rdev));
header.typeflag = CHRTYPE;
putOctal(header.devmajor, sizeof(header.devmajor),
MAJOR(statbuf->st_rdev));
putOctal(header.devminor, sizeof(header.devminor),
MINOR(statbuf->st_rdev));
} else if (S_ISBLK(statbuf->st_mode)) {
header.typeflag = BLKTYPE;
putOctal(header.devmajor, sizeof(header.devmajor), MAJOR(statbuf->st_rdev));
putOctal(header.devminor, sizeof(header.devminor), MINOR(statbuf->st_rdev));
header.typeflag = BLKTYPE;
putOctal(header.devmajor, sizeof(header.devmajor),
MAJOR(statbuf->st_rdev));
putOctal(header.devminor, sizeof(header.devminor),
MINOR(statbuf->st_rdev));
} else if (S_ISFIFO(statbuf->st_mode)) {
header.typeflag = FIFOTYPE;
header.typeflag = FIFOTYPE;
} else if (S_ISREG(statbuf->st_mode)) {
header.typeflag = REGTYPE;
header.typeflag = REGTYPE;
putOctal(header.size, sizeof(header.size), statbuf->st_size);
} else {
error_msg("%s: Unknown file type", real_name);
return ( FALSE);
return (FALSE);
}
/* Calculate and store the checksum (i.e., the sum of all of the bytes of
@@ -294,29 +299,33 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
while (size-- > 0)
chksum += *cp++;
putOctal(header.chksum, 7, chksum);
/* Now write the header out to disk */
if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) {
error_msg(io_error, real_name, strerror(errno));
return ( FALSE);
if ((size =
full_write(tbInfo->tarFd, (char *) &header,
sizeof(struct TarHeader))) < 0) {
error_msg(io_error, real_name, strerror(errno));
return (FALSE);
}
/* Pad the header up to the tar block size */
for (; size<TAR_BLOCK_SIZE; size++) {
for (; size < TAR_BLOCK_SIZE; size++) {
write(tbInfo->tarFd, "\0", 1);
}
/* Now do the verbose thing (or not) */
if (tbInfo->verboseFlag==TRUE) {
if (tbInfo->verboseFlag) {
FILE *vbFd = stdout;
if (tbInfo->tarFd == fileno(stdout)) // If the archive goes to stdout, verbose to stderr
if (tbInfo->verboseFlag == 2) /* If the archive goes to stdout, verbose to stderr */
vbFd = stderr;
fprintf(vbFd, "%s\n", header.name);
}
return ( TRUE);
return (TRUE);
}
# if defined CONFIG_FEATURE_TAR_EXCLUDE
static int exclude_file(char **excluded_files, const char *file)
static inline int exclude_file(char **excluded_files, const char *file)
{
int i;
@@ -333,7 +342,7 @@ static int exclude_file(char **excluded_files, const char *file)
for (p = file; p[0] != '\0'; p++) {
if ((p == file || p[-1] == '/') && p[0] != '/' &&
fnmatch(excluded_files[i], p,
fnmatch(excluded_files[i], p,
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
return 1;
}
@@ -344,55 +353,57 @@ static int exclude_file(char **excluded_files, const char *file)
}
#endif
static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData)
static int writeFileToTarball(const char *fileName, struct stat *statbuf,
void *userData)
{
struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData;
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
const char *header_name;
/*
** Check to see if we are dealing with a hard link.
** If so -
** Treat the first occurance of a given dev/inode as a file while
** treating any additional occurances as hard links. This is done
** by adding the file information to the HardLinkInfo linked list.
*/
** Check to see if we are dealing with a hard link.
** If so -
** Treat the first occurance of a given dev/inode as a file while
** treating any additional occurances as hard links. This is done
** by adding the file information to the HardLinkInfo linked list.
*/
tbInfo->hlInfo = NULL;
if (statbuf->st_nlink > 1) {
tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf->st_dev,
statbuf->st_ino);
tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf->st_dev,
statbuf->st_ino);
if (tbInfo->hlInfo == NULL)
addHardLinkInfo (&tbInfo->hlInfoHead, statbuf->st_dev,
statbuf->st_ino, statbuf->st_nlink, fileName);
addHardLinkInfo(&tbInfo->hlInfoHead, statbuf->st_dev,
statbuf->st_ino, statbuf->st_nlink, fileName);
}
/* It is against the rules to archive a socket */
if (S_ISSOCK(statbuf->st_mode)) {
error_msg("%s: socket ignored", fileName);
return( TRUE);
return (TRUE);
}
/* It is a bad idea to store the archive we are in the process of creating,
* so check the device and inode to be sure that this particular file isn't
* the new tarball */
if (tbInfo->statBuf.st_dev == statbuf->st_dev &&
tbInfo->statBuf.st_ino == statbuf->st_ino) {
tbInfo->statBuf.st_ino == statbuf->st_ino) {
error_msg("%s: file is the archive; skipping", fileName);
return( TRUE);
return (TRUE);
}
header_name = fileName;
while (header_name[0] == '/') {
static int alreadyWarned=FALSE;
if (alreadyWarned==FALSE) {
static int alreadyWarned = FALSE;
if (alreadyWarned == FALSE) {
error_msg("Removing leading '/' from member names");
alreadyWarned=TRUE;
alreadyWarned = TRUE;
}
header_name++;
}
if (strlen(fileName) >= NAME_SIZE) {
error_msg(name_longer_than_foo, NAME_SIZE);
return ( TRUE);
return (TRUE);
}
if (header_name[0] == '\0')
@@ -402,56 +413,61 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
if (exclude_file(tbInfo->excludeList, header_name)) {
return SKIP;
}
# endif //CONFIG_FEATURE_TAR_EXCLUDE
# endif /* CONFIG_FEATURE_TAR_EXCLUDE */
if (writeTarHeader(tbInfo, header_name, fileName, statbuf)==FALSE) {
return( FALSE);
}
if (writeTarHeader(tbInfo, header_name, fileName, statbuf) == FALSE) {
return (FALSE);
}
/* Now, if the file is a regular file, copy it out to the tarball */
if ((tbInfo->hlInfo == NULL)
&& (S_ISREG(statbuf->st_mode))) {
int inputFileFd;
&& (S_ISREG(statbuf->st_mode))) {
int inputFileFd;
char buffer[BUFSIZ];
ssize_t size=0, readSize=0;
ssize_t size = 0, readSize = 0;
/* open the file we want to archive, and make sure all is well */
if ((inputFileFd = open(fileName, O_RDONLY)) < 0) {
error_msg("%s: Cannot open: %s", fileName, strerror(errno));
return( FALSE);
return (FALSE);
}
/* write the file to the archive */
while ( (size = full_read(inputFileFd, buffer, sizeof(buffer))) > 0 ) {
if (full_write(tbInfo->tarFd, buffer, size) != size ) {
while ((size = full_read(inputFileFd, buffer, sizeof(buffer))) > 0) {
if (full_write(tbInfo->tarFd, buffer, size) != size) {
/* Output file seems to have a problem */
error_msg(io_error, fileName, strerror(errno));
return( FALSE);
error_msg(io_error, fileName, strerror(errno));
return (FALSE);
}
readSize+=size;
readSize += size;
}
if (size == -1) {
error_msg(io_error, fileName, strerror(errno));
return( FALSE);
error_msg(io_error, fileName, strerror(errno));
return (FALSE);
}
/* Pad the file up to the tar block size */
for (; (readSize%TAR_BLOCK_SIZE) != 0; readSize++) {
for (; (readSize % TAR_BLOCK_SIZE) != 0; readSize++) {
write(tbInfo->tarFd, "\0", 1);
}
close( inputFileFd);
close(inputFileFd);
}
return( TRUE);
return (TRUE);
}
static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
char** excludeList)
static inline int writeTarFile(const char *tarName, int verboseFlag,
char **argv, char **excludeList, int gzip)
{
int tarFd=-1;
int errorFlag=FALSE;
#ifdef CONFIG_FEATURE_TAR_GZIP
int gzipDataPipe[2] = { -1, -1 };
int gzipStatusPipe[2] = { -1, -1 };
pid_t gzipPid = 0;
#endif
int errorFlag = FALSE;
ssize_t size;
struct TarBallInfo tbInfo;
tbInfo.verboseFlag = verboseFlag;
tbInfo.hlInfoHead = NULL;
/* Make sure there is at least one file to tar up. */
@@ -459,31 +475,87 @@ static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
error_msg_and_die("Cowardly refusing to create an empty archive");
/* Open the tar file for writing. */
if (tarName == NULL)
if (tarName == NULL) {
tbInfo.tarFd = fileno(stdout);
else
tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (tbInfo.tarFd < 0) {
perror_msg( "Error opening '%s'", tarName);
freeHardLinkInfo(&tbInfo.hlInfoHead);
return ( FALSE);
tbInfo.verboseFlag = verboseFlag ? 2 : 0;
} else {
tbInfo.tarFd = open(tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
tbInfo.verboseFlag = verboseFlag ? 1 : 0;
}
tbInfo.excludeList=excludeList;
if (tbInfo.tarFd < 0) {
perror_msg("Error opening '%s'", tarName);
freeHardLinkInfo(&tbInfo.hlInfoHead);
return (FALSE);
}
/* Store the stat info for the tarball's file, so
* can avoid including the tarball into itself.... */
if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
error_msg_and_die(io_error, tarName, strerror(errno));
error_msg_and_die(io_error, tarName, strerror(errno));
#ifdef CONFIG_FEATURE_TAR_GZIP
if (gzip) {
if (socketpair(AF_UNIX, SOCK_STREAM, 0, gzipDataPipe) < 0
|| pipe(gzipStatusPipe) < 0)
perror_msg_and_die("Failed to create gzip pipe");
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
gzipPid = fork();
if (gzipPid == 0) {
dup2(gzipDataPipe[0], 0);
close(gzipDataPipe[1]);
if (tbInfo.tarFd != 1);
dup2(tbInfo.tarFd, 1);
close(gzipStatusPipe[0]);
fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows sucess */
execl("/bin/gzip", "gzip", "-f", 0);
write(gzipStatusPipe[1], "", 1);
close(gzipStatusPipe[1]);
exit(-1);
} else if (gzipPid > 0) {
close(gzipDataPipe[0]);
close(gzipStatusPipe[1]);
while (1) {
char buf;
int n = read(gzipStatusPipe[0], &buf, 1);
if (n == 1)
error_msg_and_die("Could not exec gzip process"); /* socket was not closed => error */
else if ((n < 0) && (errno == EAGAIN || errno == EINTR))
continue; /* try it again */
break;
}
close(gzipStatusPipe[0]);
tbInfo.tarFd = gzipDataPipe[1];
} else {
perror_msg_and_die("Failed to fork gzip process");
}
}
#endif
tbInfo.excludeList = excludeList;
/* Read the directory/files and iterate over them one at a time */
while (*argv != NULL) {
if (! recursive_action(*argv++, TRUE, FALSE, FALSE,
writeFileToTarball, writeFileToTarball,
(void*) &tbInfo)) {
if (!recursive_action(*argv++, TRUE, FALSE, FALSE,
writeFileToTarball, writeFileToTarball,
(void *) &tbInfo)) {
errorFlag = TRUE;
}
}
/* Write two empty blocks to the end of the archive */
for (size=0; size<(2*TAR_BLOCK_SIZE); size++) {
for (size = 0; size < (2 * TAR_BLOCK_SIZE); size++) {
write(tbInfo.tarFd, "\0", 1);
}
@@ -493,16 +565,22 @@ static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
* so is considered a waste of space */
/* Hang up the tools, close up shop, head home */
close(tarFd);
if (errorFlag) {
close(tbInfo.tarFd);
if (errorFlag)
error_msg("Error exit delayed from previous errors");
freeHardLinkInfo(&tbInfo.hlInfoHead);
return(FALSE);
}
freeHardLinkInfo(&tbInfo.hlInfoHead);
return( TRUE);
#ifdef CONFIG_FEATURE_TAR_GZIP
if (gzip && gzipPid) {
if (waitpid(gzipPid, NULL, 0) == -1)
printf("Couldnt wait ?");
}
#endif
return !errorFlag;
}
#endif //tar_create
#endif /* tar_create */
void append_file_to_list(const char *new_name, char ***list, int *list_count)
{
@@ -512,60 +590,21 @@ void append_file_to_list(const char *new_name, char ***list, int *list_count)
(*list)[*list_count] = NULL;
}
void append_file_list_to_list(char *filename, char ***name_list, int *num_of_entries)
void append_file_list_to_list(char *filename, char ***name_list,
int *num_of_entries)
{
FILE *src_stream;
char *line;
src_stream = xfopen(filename, "r");
while ((line = get_line_from_file(src_stream)) != NULL) {
chomp (line);
chomp(line);
append_file_to_list(line, name_list, num_of_entries);
free(line);
}
fclose(src_stream);
}
#ifdef CONFIG_FEATURE_TAR_EXCLUDE
/*
* Create a list of names that are in the include list AND NOT in the exclude lists
*/
char **list_and_not_list(char **include_list, char **exclude_list)
{
char **new_include_list = NULL;
int new_include_count = 0;
int include_count = 0;
int exclude_count;
if (include_list == NULL) {
return(NULL);
}
while (include_list[include_count] != NULL) {
int found = FALSE;
exclude_count = 0;
while (exclude_list[exclude_count] != NULL) {
if (strcmp(include_list[include_count], exclude_list[exclude_count]) == 0) {
found = TRUE;
break;
}
exclude_count++;
}
if (! found) {
new_include_list = realloc(new_include_list, sizeof(char *) * (include_count + 2));
new_include_list[new_include_count] = include_list[include_count];
new_include_count++;
} else {
free(include_list[include_count]);
}
include_count++;
}
new_include_list[new_include_count] = NULL;
return(new_include_list);
}
#endif
int tar_main(int argc, char **argv)
{
enum untar_funct_e {
@@ -588,6 +627,7 @@ int tar_main(int argc, char **argv)
unsigned short untar_funct_required = 0;
unsigned short extract_function = 0;
int include_list_count = 0;
#ifdef CONFIG_FEATURE_TAR_EXCLUDE
int exclude_list_count = 0;
#endif
@@ -603,6 +643,7 @@ int tar_main(int argc, char **argv)
/* Prepend '-' to the first argument if required */
if (argv[1][0] != '-') {
char *tmp = xmalloc(strlen(argv[1]) + 2);
tmp[0] = '-';
strcpy(tmp + 1, argv[1]);
argv[1] = tmp;
@@ -611,36 +652,40 @@ int tar_main(int argc, char **argv)
while ((opt = getopt(argc, argv, "ctxT:X:C:f:Opvz")) != -1) {
switch (opt) {
/* One and only one of these is required */
/* One and only one of these is required */
case 'c':
untar_funct_required |= untar_create;
break;
case 't':
untar_funct_required |= untar_list;
extract_function |= extract_list |extract_unconditional;
extract_function |= extract_list | extract_unconditional;
break;
case 'x':
untar_funct_required |= untar_extract;
extract_function |= (extract_all_to_fs | extract_unconditional | extract_create_leading_dirs);
extract_function |=
(extract_all_to_fs | extract_unconditional |
extract_create_leading_dirs);
break;
/* These are optional */
/* Exclude or Include files listed in <filename>*/
/* These are optional */
/* Exclude or Include files listed in <filename> */
#ifdef CONFIG_FEATURE_TAR_EXCLUDE
case 'X':
append_file_list_to_list(optarg, &exclude_list, &exclude_list_count);
append_file_list_to_list(optarg, &exclude_list,
&exclude_list_count);
break;
#endif
case 'T':
// by default a list is an include list
append_file_list_to_list(optarg, &include_list, &include_list_count);
/* by default a list is an include list */
append_file_list_to_list(optarg, &include_list,
&include_list_count);
break;
case 'C': // Change to dir <optarg>
case 'C': /* Change to dir <optarg> */
/* Make sure dst_prefix ends in a '/' */
dst_prefix = concat_path_file(optarg, "/");
break;
case 'f': // archive filename
case 'f': /* archive filename */
if (strcmp(optarg, "-") == 0) {
src_filename = NULL;
} else {
@@ -653,10 +698,7 @@ int tar_main(int argc, char **argv)
case 'p':
break;
case 'v':
if (extract_function & extract_list) {
extract_function |= extract_verbose_list;
}
extract_function |= extract_list;
extract_function |= extract_verbose_list;
break;
#ifdef CONFIG_FEATURE_TAR_GZIP
case 'z':
@@ -672,9 +714,9 @@ int tar_main(int argc, char **argv)
if (untar_funct_required == 0) {
error_msg_and_die("You must specify one of the `-ctx' options");
}
if ((untar_funct_required != untar_create) &&
(untar_funct_required != untar_extract) &&
(untar_funct_required != untar_list)) {
if ((untar_funct_required != untar_create) &&
(untar_funct_required != untar_extract) &&
(untar_funct_required != untar_list)) {
error_msg_and_die("You may not specify more than one `ctx' option.");
}
untar_funct |= untar_funct_required;
@@ -700,42 +742,45 @@ int tar_main(int argc, char **argv)
if (untar_funct & untar_unzip) {
uncompressed_stream = gz_open(src_stream, &gunzip_pid);
} else
#endif // CONFIG_FEATURE_TAR_GZIP
#endif /* CONFIG_FEATURE_TAR_GZIP */
uncompressed_stream = src_stream;
/* extract or list archive */
unarchive(uncompressed_stream, stdout, &get_header_tar, extract_function, dst_prefix, include_list, exclude_list);
unarchive(uncompressed_stream, stdout, &get_header_tar,
extract_function, dst_prefix, include_list, exclude_list);
fclose(uncompressed_stream);
}
#ifdef CONFIG_FEATURE_TAR_CREATE
/* create an archive */
else if (untar_funct & untar_create) {
int verboseFlag = FALSE;
int gzipFlag = FALSE;
#ifdef CONFIG_FEATURE_TAR_GZIP
if (untar_funct & untar_unzip) {
error_msg_and_die("Creation of compressed tarfile not internally support by tar, pipe to busybox gunzip");
}
#endif // CONFIG_FEATURE_TAR_GZIP
if (extract_function & extract_verbose_list) {
if (untar_funct & untar_unzip)
gzipFlag = TRUE;
#endif /* CONFIG_FEATURE_TAR_GZIP */
if (extract_function & extract_verbose_list)
verboseFlag = TRUE;
}
writeTarFile(src_filename, verboseFlag, include_list, exclude_list);
writeTarFile(src_filename, verboseFlag, include_list, exclude_list,
gzipFlag);
}
#endif // CONFIG_FEATURE_TAR_CREATE
#endif /* CONFIG_FEATURE_TAR_CREATE */
/* Cleanups */
#ifdef CONFIG_FEATURE_TAR_GZIP
if (untar_funct & untar_unzip) {
if (!(untar_funct & untar_create) && (untar_funct & untar_unzip)) {
fclose(src_stream);
close(gz_fd);
gz_close(gunzip_pid);
}
#endif // CONFIG_FEATURE_TAR_GZIP
#endif /* CONFIG_FEATURE_TAR_GZIP */
#ifdef CONFIG_FEATURE_CLEAN_UP
if (src_filename) {
free(src_filename);
}
#endif
return(EXIT_SUCCESS);
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 */
+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.
*
+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:
+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)
+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 -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;
}
+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;
}
+64 -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,27 @@
<tr>
<td bgcolor="#EEEEE0">
<ul>
<li>
<b>6 March 2002 -- busybox.net now has mirrors!</b>
<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 +125,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 +149,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 +183,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 +401,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>
+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
+881 -879
View File
File diff suppressed because it is too large. Load diff
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
# Sample udhcpc renew script
RESOLV_CONF="/etc/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
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
# Sample udhcpc bound script
RESOLV_CONF="/etc/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/default.$1
+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");
+220 -176
View File
@@ -16,510 +16,554 @@
#if defined(PROTOTYPES)
#define APPLET(a,b,c) extern int b(int argc, char **argv);
#define APPLET_NOUSAGE(a,b,c) extern int b(int argc, char **argv);
#define APPLET_ODDNAME(a,b,c,d) extern int b(int argc, char **argv);
#define APPLET(a,b,c,d) extern int b(int argc, char **argv);
#define APPLET_NOUSAGE(a,b,c,d) extern int b(int argc, char **argv);
#define APPLET_ODDNAME(a,b,c,d,e) extern int b(int argc, char **argv);
extern const char usage_messages[];
#elif defined(MAKE_USAGE)
#ifdef CONFIG_FEATURE_VERBOSE_USAGE
#define APPLET(a,b,c) a##_trivial_usage "\n\n" a##_full_usage "\0"
#define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\n\n" d##_full_usage "\0"
#define APPLET(a,b,c,d) a##_trivial_usage "\n\n" a##_full_usage "\0"
#define APPLET_NOUSAGE(a,b,c,d) "\b\0"
#define APPLET_ODDNAME(a,b,c,d,e) e##_trivial_usage "\n\n" e##_full_usage "\0"
#else
#define APPLET(a,b,c) a##_trivial_usage "\0"
#define APPLET_NOUSAGE(a,b,c) "\0"
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\0"
#define APPLET(a,b,c,d) a##_trivial_usage "\0"
#define APPLET_NOUSAGE(a,b,c,d) "\b\0"
#define APPLET_ODDNAME(a,b,c,d,e) e##_trivial_usage "\0"
#endif
#elif defined(MAKE_LINKS)
# define APPLET(a,b,c) LINK c a
# define APPLET_NOUSAGE(a,b,c) LINK c a
# define APPLET_ODDNAME(a,b,c,d) LINK c a
# define APPLET(a,b,c,d) LINK c a
# define APPLET_NOUSAGE(a,b,c,d) LINK c a
# define APPLET_ODDNAME(a,b,c,d,e) LINK c a
#else
const struct BB_applet applets[] = {
#define APPLET(a,b,c) {#a,b,c},
#define APPLET_NOUSAGE(a,b,c) {a,b,c},
#define APPLET_ODDNAME(a,b,c,d) {a,b,c},
#define APPLET(a,b,c,d) {#a,b,c,d},
#define APPLET_NOUSAGE(a,b,c,d) {a,b,c,d},
#define APPLET_ODDNAME(a,b,c,d,e) {a,b,c,d},
#endif
#ifdef CONFIG_TEST
APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN)
APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_ADDGROUP
APPLET(addgroup, addgroup_main, _BB_DIR_BIN)
APPLET(addgroup, addgroup_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_ADDUSER
APPLET(adduser, adduser_main, _BB_DIR_BIN)
APPLET(adduser, adduser_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_ADJTIMEX
APPLET(adjtimex, adjtimex_main, _BB_DIR_SBIN)
APPLET(adjtimex, adjtimex_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_AR
APPLET(ar, ar_main, _BB_DIR_USR_BIN)
APPLET(ar, ar_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_ASH
APPLET_NOUSAGE("ash", ash_main, _BB_DIR_BIN)
APPLET_NOUSAGE("ash", ash_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_AWK
APPLET(awk, awk_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_BASENAME
APPLET(basename, basename_main, _BB_DIR_USR_BIN)
APPLET(basename, basename_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_BUNZIP2
APPLET(bunzip2, bunzip2_main, _BB_DIR_USR_BIN)
APPLET(bunzip2, bunzip2_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
APPLET_NOUSAGE("busybox", busybox_main, _BB_DIR_BIN)
APPLET_NOUSAGE("busybox", busybox_main, _BB_DIR_BIN, _BB_SUID_MAYBE)
#ifdef CONFIG_BUNZIP2
APPLET(bzcat, bunzip2_main, _BB_DIR_USR_BIN)
APPLET(bzcat, bunzip2_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CAL
APPLET(cal, cal_main, _BB_DIR_USR_BIN)
APPLET(cal, cal_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CAT
APPLET(cat, cat_main, _BB_DIR_BIN)
APPLET(cat, cat_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CHGRP
APPLET(chgrp, chgrp_main, _BB_DIR_BIN)
APPLET(chgrp, chgrp_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CHMOD
APPLET(chmod, chmod_main, _BB_DIR_BIN)
APPLET(chmod, chmod_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CHOWN
APPLET(chown, chown_main, _BB_DIR_BIN)
APPLET(chown, chown_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CHROOT
APPLET(chroot, chroot_main, _BB_DIR_USR_SBIN)
APPLET(chroot, chroot_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CHVT
APPLET(chvt, chvt_main, _BB_DIR_USR_BIN)
APPLET(chvt, chvt_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CLEAR
APPLET(clear, clear_main, _BB_DIR_USR_BIN)
APPLET(clear, clear_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CMP
APPLET(cmp, cmp_main, _BB_DIR_USR_BIN)
APPLET(cmp, cmp_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CP
APPLET(cp, cp_main, _BB_DIR_BIN)
APPLET(cp, cp_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CPIO
APPLET(cpio, cpio_main, _BB_DIR_BIN)
APPLET(cpio, cpio_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CUT
APPLET(cut, cut_main, _BB_DIR_USR_BIN)
APPLET(cut, cut_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DATE
APPLET(date, date_main, _BB_DIR_BIN)
APPLET(date, date_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DC
APPLET(dc, dc_main, _BB_DIR_USR_BIN)
APPLET(dc, dc_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DD
APPLET(dd, dd_main, _BB_DIR_BIN)
APPLET(dd, dd_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DEALLOCVT
APPLET(deallocvt, deallocvt_main, _BB_DIR_USR_BIN)
APPLET(deallocvt, deallocvt_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DELGROUP
APPLET(delgroup, delgroup_main, _BB_DIR_BIN)
APPLET(delgroup, delgroup_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DELUSER
APPLET(deluser, deluser_main, _BB_DIR_BIN)
APPLET(deluser, deluser_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DF
APPLET(df, df_main, _BB_DIR_BIN)
APPLET(df, df_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DIRNAME
APPLET(dirname, dirname_main, _BB_DIR_USR_BIN)
APPLET(dirname, dirname_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DMESG
APPLET(dmesg, dmesg_main, _BB_DIR_BIN)
APPLET(dmesg, dmesg_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DOS2UNIX
APPLET(dos2unix, dos2unix_main, _BB_DIR_USR_BIN)
APPLET(dos2unix, dos2unix_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DPKG
APPLET(dpkg, dpkg_main, _BB_DIR_USR_BIN)
APPLET(dpkg, dpkg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DPKG_DEB
APPLET_ODDNAME("dpkg-deb", dpkg_deb_main, _BB_DIR_USR_BIN, dpkg_deb)
APPLET_ODDNAME("dpkg-deb", dpkg_deb_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER, dpkg_deb)
#endif
#ifdef CONFIG_DU
APPLET(du, du_main, _BB_DIR_USR_BIN)
APPLET(du, du_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DUMPKMAP
APPLET(dumpkmap, dumpkmap_main, _BB_DIR_BIN)
APPLET(dumpkmap, dumpkmap_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DUTMP
APPLET(dutmp, dutmp_main, _BB_DIR_USR_SBIN)
APPLET(dutmp, dutmp_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_ECHO
APPLET(echo, echo_main, _BB_DIR_BIN)
APPLET(echo, echo_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#if defined(CONFIG_FEATURE_GREP_EGREP_ALIAS)
APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN)
APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_ENV
APPLET(env, env_main, _BB_DIR_USR_BIN)
APPLET(env, env_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_EXPR
APPLET(expr, expr_main, _BB_DIR_USR_BIN)
APPLET(expr, expr_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_FALSE
APPLET(false, false_main, _BB_DIR_BIN)
APPLET(false, false_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_FBSET
APPLET(fbset, fbset_main, _BB_DIR_USR_SBIN)
APPLET(fbset, fbset_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_FDFLUSH
APPLET(fdflush, fdflush_main, _BB_DIR_BIN)
APPLET(fdflush, fdflush_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_FIND
APPLET(find, find_main, _BB_DIR_USR_BIN)
APPLET(find, find_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_FREE
APPLET(free, free_main, _BB_DIR_USR_BIN)
APPLET(free, free_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_FREERAMDISK
APPLET(freeramdisk, freeramdisk_main, _BB_DIR_SBIN)
APPLET(freeramdisk, freeramdisk_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_FSCK_MINIX
APPLET_ODDNAME("fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix)
APPLET_ODDNAME("fsck.minix", fsck_minix_main, _BB_DIR_SBIN, _BB_SUID_NEVER, fsck_minix)
#endif
#ifdef CONFIG_GETOPT
APPLET(getopt, getopt_main, _BB_DIR_BIN)
APPLET(getopt, getopt_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_GETTY
APPLET(getty, getty_main, _BB_DIR_SBIN)
APPLET(getty, getty_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_GREP
APPLET(grep, grep_main, _BB_DIR_BIN)
APPLET(grep, grep_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_GUNZIP
APPLET(gunzip, gunzip_main, _BB_DIR_BIN)
APPLET(gunzip, gunzip_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_GZIP
APPLET(gzip, gzip_main, _BB_DIR_BIN)
APPLET(gzip, gzip_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_HALT
APPLET(halt, halt_main, _BB_DIR_SBIN)
APPLET(halt, halt_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_HEAD
APPLET(head, head_main, _BB_DIR_USR_BIN)
APPLET(head, head_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_HEXDUMP
APPLET(hexdump, hexdump_main, _BB_DIR_USR_BIN)
APPLET(hexdump, hexdump_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_HOSTID
APPLET(hostid, hostid_main, _BB_DIR_USR_BIN)
APPLET(hostid, hostid_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_HOSTNAME
APPLET(hostname, hostname_main, _BB_DIR_BIN)
APPLET(hostname, hostname_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_HUSH
APPLET_NOUSAGE("hush", hush_main, _BB_DIR_BIN)
APPLET_NOUSAGE("hush", hush_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_HWCLOCK
APPLET(hwclock, hwclock_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_ID
APPLET(id, id_main, _BB_DIR_USR_BIN)
APPLET(id, id_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_IFCONFIG
APPLET(ifconfig, ifconfig_main, _BB_DIR_SBIN)
APPLET(ifconfig, ifconfig_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_INIT
APPLET(init, init_main, _BB_DIR_SBIN)
APPLET(init, init_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_INSMOD
APPLET(insmod, insmod_main, _BB_DIR_SBIN)
APPLET(insmod, insmod_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_KILL
APPLET(kill, kill_main, _BB_DIR_BIN)
APPLET(kill, kill_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_KILLALL
APPLET(killall, kill_main, _BB_DIR_USR_BIN)
APPLET(killall, kill_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_KLOGD
APPLET(klogd, klogd_main, _BB_DIR_SBIN)
APPLET(klogd, klogd_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LASH
APPLET(lash, lash_main, _BB_DIR_BIN)
APPLET(lash, lash_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LENGTH
APPLET(length, length_main, _BB_DIR_USR_BIN)
APPLET(length, length_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_FEATURE_INITRD
APPLET_NOUSAGE("linuxrc", init_main, _BB_DIR_ROOT)
APPLET_NOUSAGE("linuxrc", init_main, _BB_DIR_ROOT, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LN
APPLET(ln, ln_main, _BB_DIR_BIN)
APPLET(ln, ln_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LOADACM
APPLET(loadacm, loadacm_main, _BB_DIR_USR_BIN)
APPLET(loadacm, loadacm_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LOADFONT
APPLET(loadfont, loadfont_main, _BB_DIR_USR_BIN)
APPLET(loadfont, loadfont_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LOADKMAP
APPLET(loadkmap, loadkmap_main, _BB_DIR_SBIN)
APPLET(loadkmap, loadkmap_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LOGGER
APPLET(logger, logger_main, _BB_DIR_USR_BIN)
APPLET(logger, logger_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LOGIN
APPLET(login, login_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LOGNAME
APPLET(logname, logname_main, _BB_DIR_USR_BIN)
APPLET(logname, logname_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LOGREAD
APPLET(logread, logread_main, _BB_DIR_SBIN)
APPLET(logread, logread_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LOSETUP
APPLET(losetup, losetup_main, _BB_DIR_SBIN)
APPLET(losetup, losetup_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LS
APPLET(ls, ls_main, _BB_DIR_BIN)
APPLET(ls, ls_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_LSMOD
APPLET(lsmod, lsmod_main, _BB_DIR_SBIN)
APPLET(lsmod, lsmod_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MAKEDEVS
APPLET(makedevs, makedevs_main, _BB_DIR_SBIN)
APPLET(makedevs, makedevs_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MD5SUM
APPLET(md5sum, md5sum_main, _BB_DIR_USR_BIN)
APPLET(md5sum, md5sum_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MESG
APPLET(mesg, mesg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MKDIR
APPLET(mkdir, mkdir_main, _BB_DIR_BIN)
APPLET(mkdir, mkdir_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MKFIFO
APPLET(mkfifo, mkfifo_main, _BB_DIR_USR_BIN)
APPLET(mkfifo, mkfifo_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MKFS_MINIX
APPLET_ODDNAME("mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix)
APPLET_ODDNAME("mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, _BB_SUID_NEVER, mkfs_minix)
#endif
#ifdef CONFIG_MKNOD
APPLET(mknod, mknod_main, _BB_DIR_BIN)
APPLET(mknod, mknod_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MKSWAP
APPLET(mkswap, mkswap_main, _BB_DIR_SBIN)
APPLET(mkswap, mkswap_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MKTEMP
APPLET(mktemp, mktemp_main, _BB_DIR_BIN)
APPLET(mktemp, mktemp_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MODPROBE
APPLET(modprobe, modprobe_main, _BB_DIR_SBIN)
APPLET(modprobe, modprobe_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MORE
APPLET(more, more_main, _BB_DIR_BIN)
APPLET(more, more_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MOUNT
APPLET(mount, mount_main, _BB_DIR_BIN)
APPLET(mount, mount_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MSH
APPLET_NOUSAGE("msh", msh_main, _BB_DIR_BIN)
APPLET_NOUSAGE("msh", msh_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MT
APPLET(mt, mt_main, _BB_DIR_BIN)
APPLET(mt, mt_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_MV
APPLET(mv, mv_main, _BB_DIR_BIN)
APPLET(mv, mv_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_NC
APPLET(nc, nc_main, _BB_DIR_USR_BIN)
APPLET(nc, nc_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_NETSTAT
APPLET(netstat, netstat_main, _BB_DIR_BIN)
APPLET(netstat, netstat_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_NSLOOKUP
APPLET(nslookup, nslookup_main, _BB_DIR_USR_BIN)
APPLET(nslookup, nslookup_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_OD
APPLET(od, od_main, _BB_DIR_USR_BIN)
APPLET(od, od_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_OPENVT
APPLET(openvt, openvt_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_PASSWD
APPLET(passwd, passwd_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)
#endif
#ifdef CONFIG_PIDOF
APPLET(pidof, pidof_main, _BB_DIR_BIN)
APPLET(pidof, pidof_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_PING
APPLET(ping, ping_main, _BB_DIR_BIN)
APPLET(ping, ping_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_PING6
APPLET(ping6, ping6_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_PIVOT_ROOT
APPLET(pivot_root, pivot_root_main, _BB_DIR_SBIN)
APPLET(pivot_root, pivot_root_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_POWEROFF
APPLET(poweroff, poweroff_main, _BB_DIR_SBIN)
APPLET(poweroff, poweroff_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_PRINTF
APPLET(printf, printf_main, _BB_DIR_USR_BIN)
APPLET(printf, printf_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_PS
APPLET(ps, ps_main, _BB_DIR_BIN)
APPLET(ps, ps_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_PWD
APPLET(pwd, pwd_main, _BB_DIR_BIN)
APPLET(pwd, pwd_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_RDATE
APPLET(rdate, rdate_main, _BB_DIR_USR_BIN)
APPLET(rdate, rdate_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_READLINK
APPLET(readlink, readlink_main, _BB_DIR_USR_BIN)
APPLET(readlink, readlink_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_REBOOT
APPLET(reboot, reboot_main, _BB_DIR_SBIN)
APPLET(reboot, reboot_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_RENICE
APPLET(renice, renice_main, _BB_DIR_USR_BIN)
APPLET(renice, renice_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_RESET
APPLET(reset, reset_main, _BB_DIR_USR_BIN)
APPLET(reset, reset_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_RM
APPLET(rm, rm_main, _BB_DIR_BIN)
APPLET(rm, rm_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_RMDIR
APPLET(rmdir, rmdir_main, _BB_DIR_BIN)
APPLET(rmdir, rmdir_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_RMMOD
APPLET(rmmod, rmmod_main, _BB_DIR_SBIN)
APPLET(rmmod, rmmod_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_ROUTE
APPLET(route, route_main, _BB_DIR_SBIN)
APPLET(route, route_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_RPM2CPIO
APPLET(rpm2cpio, rpm2cpio_main, _BB_DIR_USR_BIN)
APPLET(rpm2cpio, rpm2cpio_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_RUN_PARTS
APPLET_ODDNAME("run-parts", run_parts_main, _BB_DIR_BIN, run_parts)
APPLET_ODDNAME("run-parts", run_parts_main, _BB_DIR_BIN, _BB_SUID_NEVER, run_parts)
#endif
#ifdef CONFIG_SED
APPLET(sed, sed_main, _BB_DIR_BIN)
APPLET(sed, sed_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_SETKEYCODES
APPLET(setkeycodes, setkeycodes_main, _BB_DIR_USR_BIN)
APPLET(setkeycodes, setkeycodes_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#if defined(CONFIG_FEATURE_SH_IS_ASH) && defined(CONFIG_ASH)
APPLET_NOUSAGE("sh", ash_main, _BB_DIR_BIN)
APPLET_NOUSAGE("sh", ash_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#elif defined(CONFIG_FEATURE_SH_IS_HUSH) && defined(CONFIG_HUSH)
APPLET_NOUSAGE("sh", hush_main, _BB_DIR_BIN)
APPLET_NOUSAGE("sh", hush_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#elif defined(CONFIG_FEATURE_SH_IS_LASH) && defined(CONFIG_LASH)
APPLET_NOUSAGE("sh", lash_main, _BB_DIR_BIN)
APPLET_NOUSAGE("sh", lash_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#elif defined(CONFIG_FEATURE_SH_IS_MSH) && defined(CONFIG_MSH)
APPLET_NOUSAGE("sh", msh_main, _BB_DIR_BIN)
APPLET_NOUSAGE("sh", msh_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_SLEEP
APPLET(sleep, sleep_main, _BB_DIR_BIN)
APPLET(sleep, sleep_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_SORT
APPLET(sort, sort_main, _BB_DIR_USR_BIN)
APPLET(sort, sort_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_START_STOP_DAEMON
APPLET_ODDNAME("start-stop-daemon", start_stop_daemon_main, _BB_DIR_SBIN, start_stop_daemon)
APPLET_ODDNAME("start-stop-daemon", start_stop_daemon_main, _BB_DIR_SBIN, _BB_SUID_NEVER, start_stop_daemon)
#endif
#ifdef CONFIG_STTY
APPLET(stty, stty_main, _BB_DIR_BIN)
APPLET(stty, stty_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_SU
APPLET(su, su_main, _BB_DIR_BIN, _BB_SUID_ALWAYS)
#endif
#ifdef CONFIG_SULOGIN
APPLET(sulogin, sulogin_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_SWAPONOFF
APPLET(swapoff, swap_on_off_main, _BB_DIR_SBIN)
APPLET(swapoff, swap_on_off_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_SWAPONOFF
APPLET(swapon, swap_on_off_main, _BB_DIR_SBIN)
APPLET(swapon, swap_on_off_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_SYNC
APPLET(sync, sync_main, _BB_DIR_BIN)
APPLET(sync, sync_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_SYSLOGD
APPLET(syslogd, syslogd_main, _BB_DIR_SBIN)
APPLET(syslogd, syslogd_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TAIL
APPLET(tail, tail_main, _BB_DIR_USR_BIN)
APPLET(tail, tail_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TAR
APPLET(tar, tar_main, _BB_DIR_BIN)
APPLET(tar, tar_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TEE
APPLET(tee, tee_main, _BB_DIR_USR_BIN)
APPLET(tee, tee_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TELNET
APPLET(telnet, telnet_main, _BB_DIR_USR_BIN)
APPLET(telnet, telnet_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TEST
APPLET(test, test_main, _BB_DIR_USR_BIN)
APPLET(test, test_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TFTP
APPLET(tftp, tftp_main, _BB_DIR_USR_BIN)
APPLET(tftp, tftp_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TIME
APPLET(time, time_main, _BB_DIR_USR_BIN)
APPLET(time, time_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TOP
APPLET(top, top_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TOUCH
APPLET(touch, touch_main, _BB_DIR_BIN)
APPLET(touch, touch_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TR
APPLET(tr, tr_main, _BB_DIR_USR_BIN)
APPLET(tr, tr_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TRACEROUTE
APPLET(traceroute, traceroute_main, _BB_DIR_USR_BIN)
APPLET(traceroute, traceroute_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TRUE
APPLET(true, true_main, _BB_DIR_BIN)
APPLET(true, true_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TTY
APPLET(tty, tty_main, _BB_DIR_USR_BIN)
APPLET(tty, tty_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_UDHCPC
APPLET(udhcpc, udhcpc_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_UMOUNT
APPLET(umount, umount_main, _BB_DIR_BIN)
APPLET(umount, umount_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_UNAME
APPLET(uname, uname_main, _BB_DIR_BIN)
APPLET(uname, uname_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_GUNZIP
# ifdef CONFIG_FEATURE_UNCOMPRESS
APPLET_ODDNAME("uncompress", gunzip_main, _BB_DIR_BIN, _BB_SUID_NEVER, gunzip)
# endif
#endif
#ifdef CONFIG_UNIQ
APPLET(uniq, uniq_main, _BB_DIR_USR_BIN)
APPLET(uniq, uniq_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_UNIX2DOS
APPLET(unix2dos, dos2unix_main, _BB_DIR_USR_BIN)
APPLET(unix2dos, dos2unix_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_UNZIP
APPLET(unzip, unzip_main, _BB_DIR_USR_BIN)
APPLET(unzip, unzip_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_UPDATE
APPLET(update, update_main, _BB_DIR_SBIN)
APPLET(update, update_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_UPTIME
APPLET(uptime, uptime_main, _BB_DIR_USR_BIN)
APPLET(uptime, uptime_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_USLEEP
APPLET(usleep, usleep_main, _BB_DIR_BIN)
APPLET(usleep, usleep_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_UUDECODE
APPLET(uudecode, uudecode_main, _BB_DIR_USR_BIN)
APPLET(uudecode, uudecode_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_UUENCODE
APPLET(uuencode, uuencode_main, _BB_DIR_USR_BIN)
APPLET(uuencode, uuencode_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_VI
APPLET(vi, vi_main, _BB_DIR_BIN)
APPLET(vi, vi_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_VLOCK
APPLET(vlock, vlock_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)
#endif
#ifdef CONFIG_WATCH
APPLET(watch, watch_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_WATCHDOG
APPLET(watchdog, watchdog_main, _BB_DIR_SBIN)
APPLET(watchdog, watchdog_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_WC
APPLET(wc, wc_main, _BB_DIR_USR_BIN)
APPLET(wc, wc_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_WGET
APPLET(wget, wget_main, _BB_DIR_USR_BIN)
APPLET(wget, wget_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_WHICH
APPLET(which, which_main, _BB_DIR_USR_BIN)
APPLET(which, which_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_WHO
APPLET(who, who_main, _BB_DIR_USR_BIN)
APPLET(who, who_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_WHOAMI
APPLET(whoami, whoami_main, _BB_DIR_USR_BIN)
APPLET(whoami, whoami_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_XARGS
APPLET(xargs, xargs_main, _BB_DIR_USR_BIN)
APPLET(xargs, xargs_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_YES
APPLET(yes, yes_main, _BB_DIR_USR_BIN)
APPLET(yes, yes_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_GUNZIP
APPLET(zcat, gunzip_main, _BB_DIR_BIN)
APPLET(zcat, gunzip_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#if !defined(PROTOTYPES) && !defined(MAKE_USAGE)
+18 -11
View File
@@ -39,6 +39,8 @@
#include <features.h>
/* Pull in the utility routines from libbb */
#include "libbb.h"
enum Location {
_BB_DIR_ROOT = 0,
@@ -48,11 +50,19 @@ enum Location {
_BB_DIR_USR_SBIN
};
struct BB_applet {
const char* name;
int (*main)(int argc, char** argv);
enum Location location;
enum SUIDRoot {
_BB_SUID_NEVER = 0,
_BB_SUID_MAYBE,
_BB_SUID_ALWAYS
};
struct BB_applet {
const char *name;
int (*main) (int argc, char **argv);
enum Location location:4;
enum SUIDRoot need_suid:4;
};
/* From busybox.c */
extern const struct BB_applet applets[];
@@ -97,16 +107,13 @@ extern const struct BB_applet applets[];
#define RB_POWER_OFF 0x4321fedc
#endif
/* Pull in the utility routines from libbb */
#include "libbb.h"
/* Try to pull in PATH_MAX */
#include <limits.h>
/* for PATH_MAX on systems that don't have it in limits.h */
#include <sys/param.h>
#ifndef PATH_MAX
#include <sys/param.h>
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
#endif /* _BB_INTERNAL_H_ */
#endif /* _BB_INTERNAL_H_ */
+3 -1
View File
@@ -1,14 +1,16 @@
#ifndef __CONFIG_GRP_H
#define __CONFIG_GRP_H
#if defined USE_SYSTEM_PWD_GRP
#if !defined CONFIG_USE_BB_PWD_GRP
#include <grp.h>
#else
#include <sys/types.h>
#include <features.h>
#include <stdio.h>
/* The group structure */
struct group
{
+4 -1
View File
@@ -4,7 +4,7 @@
*
* Heavily modified by Manuel Novoa III Mar 12, 2001
*
* Version: $Id: inet_common.h,v 1.1 2001/11/10 12:18:42 andersen Exp $
* Version: $Id: inet_common.h,v 1.2 2002/07/03 11:46:38 andersen Exp $
*
*/
@@ -28,3 +28,6 @@ extern int INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirs
*/
extern int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
int numeric, unsigned int netmask);
extern int INET6_resolve(char *name, struct sockaddr_in6 *sin6);
extern int INET6_rresolve(char *name, size_t len, struct sockaddr_in6 *sin6, int numeric);
+42 -4
View File
@@ -37,6 +37,22 @@
#include <features.h>
#include "config.h"
#include "pwd_.h"
#include "grp_.h"
#ifdef CONFIG_FEATURE_SHADOWPASSWDS
#include "shadow_.h"
#endif
#ifdef CONFIG_FEATURE_SHA1_PASSWORDS
# include "sha1.h"
#endif
/* Compatability with ANSI C */
#ifndef inline
# define inline
#endif
#if (__GNU_LIBRARY__ < 5) && (!defined __dietlibc__)
/* libc5 doesn't define socklen_t */
typedef unsigned int socklen_t;
@@ -58,9 +74,6 @@ char *strtok_r(char *s, const char *delim, char **ptrptr);
#define BUF_SIZE 8192
#define EXPAND_ALLOC 1024
static inline int is_decimal(int ch) { return ((ch >= '0') && (ch <= '9')); }
static inline int is_octal(int ch) { return ((ch >= '0') && (ch <= '7')); }
/* Macros for min/max. */
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
@@ -110,7 +123,7 @@ extern int parse_mode( const char* s, mode_t* theMode);
extern int get_kernel_revision(void);
extern int get_console_fd(char* tty_name);
extern int get_console_fd(void);
extern struct mntent *find_mount_point(const char *name, const char *table);
extern void write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags);
@@ -221,7 +234,10 @@ extern void gz_close(int gunzip_pid);
extern FILE *gz_open(FILE *compressed_file, int *pid);
extern struct hostent *xgethostbyname(const char *name);
extern struct hostent *xgethostbyname2(const char *name, int af);
extern int create_icmp_socket(void);
extern int create_icmp6_socket(void);
extern int xconnect(const char *host, const char *port);
char *dirname (char *path);
@@ -258,6 +274,15 @@ extern const char * const too_few_args;
extern const char * const name_longer_than_foo;
extern const char * const unknown;
extern const char * const can_not_create_raw_socket;
extern const char * const nologin_file;
extern const char * const passwd_file;
extern const char * const shadow_file;
extern const char * const gshadow_file;
extern const char * const group_file;
extern const char * const securetty_file;
extern const char * const motd_file;
extern const char * const issue_file;
extern const char * const _path_login;
#ifdef CONFIG_FEATURE_DEVFS
# define CURRENT_VC "/dev/vc/0"
@@ -297,4 +322,17 @@ void reset_ino_dev_hashtable(void);
extern size_t xstrlen(const char *string);
#define strlen(x) xstrlen(x)
void bb_asprintf(char **string_ptr, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
#define FAIL_DELAY 3
extern void change_identity ( const struct passwd *pw );
extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args );
extern int restricted_shell ( const char *shell );
extern void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw );
extern int correct_password ( const struct passwd *pw );
extern char *pw_encrypt(const char *clear, const char *salt);
extern struct spwd *pwd_to_spwd(const struct passwd *pw);
extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
#endif /* __LIBCONFIG_H__ */
+2 -1
View File
@@ -1,8 +1,9 @@
#ifndef __CONFIG_PWD_H
#define __CONFIG_PWD_H
#if defined USE_SYSTEM_PWD_GRP
#if !defined CONFIG_USE_BB_PWD_GRP
#include <pwd.h>
#else
#include <sys/types.h>
+82
View File
@@ -0,0 +1,82 @@
/*
* Copyright 1988 - 1994, Julianne Frances Haugh <jockgrrl@austin.rr.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _H_SHADOW
#define _H_SHADOW
#ifdef USE_SYSTEM_SHADOW
#include <shadow.h>
#else
/*
* This information is not derived from AT&T licensed sources. Posted
* to the USENET 11/88, and updated 11/90 with information from SVR4.
*
* $Id: shadow_.h,v 1.1 2002/06/23 04:24:20 andersen Exp $
*/
typedef long sptime;
/*
* Shadow password security file structure.
*/
struct spwd {
char *sp_namp; /* login name */
char *sp_pwdp; /* encrypted password */
sptime sp_lstchg; /* date of last change */
sptime sp_min; /* minimum number of days between changes */
sptime sp_max; /* maximum number of days between changes */
sptime sp_warn; /* number of days of warning before password
expires */
sptime sp_inact; /* number of days after password expires
until the account becomes unusable. */
sptime sp_expire; /* days since 1/1/70 until account expires */
unsigned long sp_flag; /* reserved for future use */
};
/*
* Shadow password security file functions.
*/
#include <stdio.h> /* for FILE */
extern struct spwd *getspent(void);
extern struct spwd *sgetspent(const char *);
extern struct spwd *fgetspent(FILE *);
extern void setspent(void);
extern void endspent(void);
extern int putspent(const struct spwd *, FILE *);
extern struct spwd *getspnam(const char *name);
extern struct spwd *pwd_to_spwd(const struct passwd *pw);
#endif /* USE_LOCAL_SHADOW */
#endif /* _H_SHADOW */
+15 -12
View File
@@ -1,5 +1,5 @@
#include <stdio.h> // for FILE
#include <unistd.h> // for off_t
#include <stdio.h> /* for FILE */
#include <unistd.h> /* for off_t */
enum extract_functions_e {
extract_verbose_list = 1,
@@ -26,20 +26,23 @@ typedef struct file_headers_s {
mode_t mode;
time_t mtime;
dev_t device;
int (*extract_func)(FILE *, FILE *);
int (*extract_func) (FILE *, FILE *);
} file_header_t;
file_header_t *get_header_ar(FILE *in_file);
file_header_t *get_header_cpio(FILE *src_stream);
file_header_t *get_header_tar(FILE *tar_stream);
file_header_t *get_header_zip(FILE *zip_stream);
file_header_t *get_header_ar(FILE * in_file);
file_header_t *get_header_cpio(FILE * src_stream);
file_header_t *get_header_tar(FILE * tar_stream);
file_header_t *get_header_zip(FILE * zip_stream);
void seek_sub_file(FILE *src_stream, const int count);
void seek_sub_file(FILE * src_stream, const int count);
extern off_t archive_offset;
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);
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);
char *deb_extract(const char *package_filename, FILE *out_stream, const int extract_function,
const char *prefix, const char *filename);
char *deb_extract(const char *package_filename, FILE * out_stream,
const int extract_function, const char *prefix,
const char *filename);
+170 -9
View File
@@ -38,6 +38,14 @@
"\t-x\t\textract\n" \
"\t-v\t\tverbosely list files processed\n"
#define awk_trivial_usage \
"[-v var=val][-F sep] { -f progname | 'programtext' } [FILE ...]"
#define awk_full_usage \
"Options:\n" \
"\t-v var=val\tassign value 'val' to variable 'var'\n" \
"\t-F sep\t\tuse 'sep' as field separator\n" \
"\t-f progname\tread program source from file 'progname'\n"
#define basename_trivial_usage \
"FILE [SUFFIX]"
#define basename_full_usage \
@@ -217,7 +225,7 @@
#define dc_example_usage \
"$ dc 2 2 +\n" \
"4\n" \
"$ dc 8 8 \* 2 2 + /\n" \
"$ dc 8 8 * 2 2 + /\n" \
"16\n" \
"$ dc 0 1 and\n" \
"0\n" \
@@ -570,11 +578,11 @@
"while true ; do\n" \
" case $1 in\n" \
" -a|--a-long) echo \"Option a\" ; shift ;;\n" \
" -b|--b-long) echo \"Option b, argument \`$2'\" ; shift 2 ;;\n" \
" -b|--b-long) echo \"Option b, argument `$2'\" ; shift 2 ;;\n" \
" -c|--c-long)\n" \
" case "$2" in\n" \
" \"\") echo \"Option c, no argument\"; shift 2 ;;\n" \
" *) echo \"Option c, argument \`$2'\" ; shift 2 ;;\n" \
" *) echo \"Option c, argument `$2'\" ; shift 2 ;;\n" \
" esac ;;\n" \
" --) shift ; break ;;\n" \
" *) echo \"Internal error!\" ; exit 1 ;;\n" \
@@ -700,6 +708,17 @@
"$ hostname\n" \
"sage \n"
#define hwclock_trivial_usage \
"[-r|--show] [-s|--hctosys] [-w|--systohc] [-l|--localtime] [-u|--utc]"
#define hwclock_full_usage \
"Query and set the hardware clock (RTC)\n\n" \
"Options:\n" \
"\t-r\tread hardware clock and print result\n" \
"\t-s\tset the system time from the hardware clock\n" \
"\t-w\tset the hardware clock to the current system time\n" \
"\t-u\tthe hardware clock is kept in coordinated universal time\n" \
"\t-l\tthe hardware clock is kept in local time"
#define id_trivial_usage \
"[OPTIONS]... [USERNAME]"
#define id_full_usage \
@@ -733,12 +752,19 @@
#else
#define USAGE_IFCONFIG_OPT_A(a)
#endif
#ifdef CONFIG_FEATURE_IPV6
#define USAGE_IPV6(a) a
#else
#define USAGE_IPV6(a)
#endif
#define ifconfig_trivial_usage \
USAGE_IFCONFIG_OPT_A("[-a]") " <interface> [<address>]"
#define ifconfig_full_usage \
"configure a network interface\n\n" \
"Options:\n" \
USAGE_IPV6("[add <address>[/<prefixlen>]]\n") \
USAGE_IPV6("[del <address>[/<prefixlen>]]\n") \
"\t[[-]broadcast [<address>]] [[-]pointopoint [<address>]]\n" \
"\t[netmask <address>] [dstaddr <address>]\n" \
USAGE_SIOCSKEEPALIVE("\t[outfill <NN>] [keepalive <NN>]\n") \
@@ -978,6 +1004,15 @@
#define logger_example_usage \
"$ logger "hello"\n"
#define login_trivial_usage \
"[OPTION]... [username] [ENV=VAR ...]"
#define login_full_usage \
"Begin a new session on the system\n\n" \
"Options:\n" \
"\t-f\tDo not authenticate (user already authenticated)\n" \
"\t-h\tName of the remote host for this login.\n" \
"\t-p\tPreserve environment."
#define logname_trivial_usage \
""
#define logname_full_usage \
@@ -1114,6 +1149,13 @@
"busybox: OK\n" \
"^D\n"
#define mesg_trivial_usage \
"mesg [y|n]"
#define mesg_full_usage \
"mesg [Y|N], controls write access to your terminal\n" \
"\ty\tAllow write access to your terminal.\n" \
"\tn\tDisallow write access to your terminal.\n"
#define mkdir_trivial_usage \
"[OPTION] DIRECTORY..."
#define mkdir_full_usage \
@@ -1185,7 +1227,7 @@
#define modprobe_trivial_usage \
"[FILE ...]"
#define modprobe_full_usage \
"Used for hight level module loading and unloading."
"Used for high level module loading and unloading."
#define modprobe_example_usage \
"$ modprobe cdrom\n"
@@ -1281,11 +1323,13 @@
"221 foobar closing connection\n"
#define netstat_trivial_usage \
"[-lantuwx]"
"[-laenrtuwx]"
#define netstat_full_usage \
"-l display listening server sockets\n" \
"-a display all sockets (default: connected)\n" \
"-e display other/more information\n" \
"-n don't resolve names\n" \
"-r display routing table\n" \
"-t tcp sockets\n" \
"-u udp sockets\n" \
"-w raw sockets\n" \
@@ -1310,6 +1354,31 @@
"Write an unambiguous representation, octal bytes by default, of FILE\n"\
"to standard output. With no FILE, or when FILE is -, read standard input."
#define openvt_trivial_usage \
"<vtnum> <COMMAND> [ARGS...]"
#define openvt_full_usage \
"Start a command on a new virtual terminal"
#define openvt_example_usage \
"openvt 2 /bin/ash\n"
#ifdef CONFIG_FEATURE_SHA1_PASSWORDS
#define PASSWORD_ALG_TYPES(a) a
#else
#define PASSWORD_ALG_TYPES(a)
#endif
#define passwd_trivial_usage \
"[OPTION] [name]"
#define passwd_full_usage \
"Change a user password. If no name is specified,\n" \
"changes the password for the current user.\n" \
"Options:\n" \
"\t-a\tDefine which algorithm shall be used for the password.\n" \
"\t\t\t(Choices: des, md5" \
PASSWORD_ALG_TYPES(", sha1") \
")\n\t-d\tDelete the password for the specified user account.\n" \
"\t-l\tLocks (disables) the specified user account.\n" \
"\t-u\tUnlocks (re-enables) the specified user account."
#define pidof_trivial_usage \
"process-name [process-name ...]"
#define pidof_full_usage \
@@ -1341,6 +1410,29 @@
"1 packets transmitted, 1 packets received, 0% packet loss\n" \
"round-trip min/avg/max = 20.1/20.1/20.1 ms\n"
#ifndef CONFIG_FEATURE_FANCY_PING6
#define ping6_trivial_usage "host"
#define ping6_full_usage "Send ICMP ECHO_REQUEST packets to network hosts"
#else
#define ping6_trivial_usage \
"[OPTION]... host"
#define ping6_full_usage \
"Send ICMP ECHO_REQUEST packets to network hosts.\n\n" \
"Options:\n" \
"\t-c COUNT\tSend only COUNT pings.\n" \
"\t-s SIZE\t\tSend SIZE data bytes in packets (default=56).\n" \
"\t-q\t\tQuiet mode, only displays output at start\n" \
"\t\t\tand when finished."
#endif
#define ping6_example_usage \
"$ ping6 ip6-localhost\n" \
"PING ip6-localhost (::1): 56 data bytes\n" \
"64 bytes from ::1: icmp6_seq=0 ttl=64 time=20.1 ms\n" \
"\n" \
"--- ip6-localhost ping statistics ---\n" \
"1 packets transmitted, 1 packets received, 0% packet loss\n" \
"round-trip min/avg/max = 20.1/20.1/20.1 ms\n"
#define pivot_root_trivial_usage \
"NEW_ROOT PUT_OLD"
#define pivot_root_full_usage \
@@ -1450,7 +1542,8 @@
#define route_full_usage \
"Edit the kernel's routing tables.\n\n" \
"Options:\n" \
"\t-n\tDont resolve names."
"\t-n\tDont resolve names.\n" \
"\t-e\tDisplay other/more information"
#define rpm2cpio_trivial_usage \
"package.rpm"
@@ -1567,6 +1660,22 @@
"\n\t-g\t\tprint in stty-readable form" \
"\n\t[SETTING]\tsee manpage"
#define su_trivial_usage \
"[OPTION]... [-] [username]"
#define su_full_usage \
"Change user id or become root.\n" \
"Options:\n" \
"\t-p\tPreserve environment"
#define sulogin_trivial_usage \
"[OPTION]... [tty-device]"
#define sulogin_full_usage \
"Single user login\n" \
"Options:\n" \
"\t-f\tDo not authenticate (user already authenticated)\n" \
"\t-h\tName of the remote host for this login.\n" \
"\t-p\tPreserve environment."
#define swapoff_trivial_usage \
"[OPTION] [DEVICE]"
#define swapoff_full_usage \
@@ -1592,6 +1701,12 @@
#else
#define USAGE_REMOTE_LOG(a)
#endif
#ifdef CONFIG_FEATURE_IPC_SYSLOG
#define USAGE_IPC_LOG(a) a
#else
#define USAGE_IPC_LOG(a)
#endif
#define syslogd_trivial_usage \
"[OPTION]..."
#define syslogd_full_usage \
@@ -1603,7 +1718,9 @@
"\t-O FILE\t\tUse an alternate log file (default=/var/log/messages)" \
USAGE_REMOTE_LOG( \
"\n\t-R HOST[:PORT]\tLog to IP or hostname on PORT (default PORT=514/UDP)\n" \
"\t-L\t\tLog locally and via network logging (default is network only)")
"\t-L\t\tLog locally and via network logging (default is network only)") \
USAGE_IPC_LOG( \
"\n\t-C\t\tLog to a circular buffer (read the buffer using logread)")
#define syslogd_example_usage \
"$ syslogd -R masterlog:514\n" \
"$ syslogd -R 192.168.1.1:601\n"
@@ -1743,6 +1860,15 @@
"Options:\n" \
"\t-v\tDisplays verbose resource usage information."
#define top_trivial_usage \
"[-d <seconds>]"
#define top_full_usage \
"top provides an view of processor activity in real time.\n" \
"This utility reads the status for all processes in /proc each <seconds>\n" \
"and shows the status for however many processes will fit on the screen.\n" \
"This utility will not show processes that are started after program startup,\n" \
"but it will show the EXIT status for and PIDs that exit while it is running."
#define touch_trivial_usage \
"[-c] FILE [FILE ...]"
#define touch_full_usage \
@@ -1810,6 +1936,21 @@
"$ tty\n" \
"/dev/tty2\n"
#define udhcpc_trivial_usage \
"[-fqv] [-c CLIENTID] [-H HOSTNAME] [-i INTERFACE]\n[-p file] [-r IP] [-s script]"
#define udhcpc_full_usage \
"\tUsage: udhcpcd [OPTIONS]\n" \
"\t-c,\t--clientid=CLIENTID\tClient identifier\n" \
"\t-H,\t--hostname=HOSTNAME\tClient hostname\n" \
"\t-f,\t--foreground\tDo not fork after getting lease\n" \
"\t-i,\t--interface=INTERFACE\tInterface to use (default: eth0)\n" \
"\t-n,\t--now\tExit with failure if lease cannot be immediately negotiated.\n" \
"\t-p,\t--pidfile=file\tStore process ID of daemon in file\n" \
"\t-q,\t--quit\tQuit after obtaining lease\n" \
"\t-r,\t--request=IP\tIP address to request (default: none)\n" \
"\t-s,\t--script=file\tRun file at dhcp events (default: /usr/share/udhcpc/default.script)\n" \
"\t-v,\t--version\tDisplay version"
#ifdef CONFIG_FEATURE_MOUNT_FORCE
#define USAGE_MOUNT_FORCE(a) a
#else
@@ -1937,6 +2078,25 @@
"Options:\n" \
"\t-R\tRead-only- do not write to the file."
#define vlock_trivial_usage \
"[OPTIONS]"
#define vlock_full_usage \
"Lock a virtual terminal. A password is required to unlock\n" \
"Options:\n" \
"\t-a\tLock all VTs"
#define watch_trivial_usage \
"[-n <seconds>] COMMAND..."
#define watch_full_usage \
"Executes a program periodically.\n" \
"Options:\n" \
"\t-n\tLoop period in seconds - default is 2."
#define watch_example_usage \
"$ watch date\n" \
"Mon Dec 17 10:31:40 GMT 2000\n" \
"Mon Dec 17 10:31:42 GMT 2000\n" \
"Mon Dec 17 10:31:44 GMT 2000"
#define watchdog_trivial_usage \
"DEV"
#define watchdog_full_usage \
@@ -1957,14 +2117,15 @@
" 31 46 1365 /etc/passwd\n"
#define wget_trivial_usage \
"[-c|--continue] [-q|--quiet] [-O|--output-document file]\n\t[--header 'header: value'] [-P DIR] url"
"[-c|--continue] [-q|--quiet] [-O|--output-document file]\n\t[--header 'header: value'] [-Y|--proxy on/off] [-P DIR] url"
#define wget_full_usage \
"wget retrieves files via HTTP or FTP\n\n" \
"Options:\n" \
"\t-c\tcontinue retrieval of aborted transfers\n" \
"\t-q\tquiet mode - do not print\n" \
"\t-P\tSet directory prefix to DIR\n" \
"\t-O\tsave to filename ('-' for stdout)"
"\t-O\tsave to filename ('-' for stdout)\n" \
"\t-Y\tuse proxy ('on' or 'off')"
#define which_trivial_usage \
"[COMMAND ...]"
+1
View File
@@ -25,6 +25,7 @@ endif
INIT-y:=
INIT-$(CONFIG_HALT) += halt.o
INIT-$(CONFIG_INIT) += init.o
INIT-$(CONFIG_MESG) += mesg.o
INIT-$(CONFIG_POWEROFF) += poweroff.o
INIT-$(CONFIG_REBOOT) += reboot.o
INIT-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o
+1
View File
@@ -22,6 +22,7 @@ fi
bool 'start-stop-daemon' CONFIG_START_STOP_DAEMON
bool 'run-parts' CONFIG_RUN_PARTS
bool 'mesg' CONFIG_MESG
endmenu
+209 -198
View File
@@ -51,38 +51,40 @@
#define fork vfork
#endif
#define INIT_BUFFS_SIZE 256
/* From <linux/vt.h> */
struct vt_stat {
unsigned short v_active; /* active vt */
unsigned short v_signal; /* signal to send */
unsigned short v_state; /* vt bitmask */
unsigned short v_active; /* active vt */
unsigned short v_signal; /* signal to send */
unsigned short v_state; /* vt bitmask */
};
static const int VT_GETSTATE = 0x5603; /* get global vt state info */
static const int VT_GETSTATE = 0x5603; /* get global vt state info */
/* From <linux/serial.h> */
struct serial_struct {
int type;
int line;
int port;
int irq;
int flags;
int xmit_fifo_size;
int custom_divisor;
int baud_base;
unsigned short close_delay;
char reserved_char[2];
int hub6;
unsigned short closing_wait; /* time to wait before closing */
unsigned short closing_wait2; /* no longer used... */
int reserved[4];
int type;
int line;
int port;
int irq;
int flags;
int xmit_fifo_size;
int custom_divisor;
int baud_base;
unsigned short close_delay;
char reserved_char[2];
int hub6;
unsigned short closing_wait; /* time to wait before closing */
unsigned short closing_wait2; /* no longer used... */
int reserved[4];
};
#if (__GNU_LIBRARY__ > 5) || defined(__dietlibc__)
#include <sys/reboot.h>
#define init_reboot(magic) reboot(magic)
#if (__GNU_LIBRARY__ > 5) || defined(__dietlibc__)
#include <sys/reboot.h>
#define init_reboot(magic) reboot(magic)
#else
#define init_reboot(magic) reboot(0xfee1dead, 672274793, magic)
#define init_reboot(magic) reboot(0xfee1dead, 672274793, magic)
#endif
#ifndef _PATH_STDPATH
@@ -104,16 +106,16 @@ struct serial_struct {
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#if __GNU_LIBRARY__ > 5
#include <sys/kdaemon.h>
#include <sys/kdaemon.h>
#else
extern int bdflush (int func, long int data);
extern int bdflush(int func, long int data);
#endif
#define SHELL "/bin/sh" /* Default shell */
#define LOGIN_SHELL "-" SHELL /* Default login shell */
#define INITTAB "/etc/inittab" /* inittab file location */
#define SHELL "/bin/sh" /* Default shell */
#define LOGIN_SHELL "-" SHELL /* Default login shell */
#define INITTAB "/etc/inittab" /* inittab file location */
#ifndef INIT_SCRIPT
#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
#endif
#define MAXENV 16 /* Number of env. vars */
@@ -149,24 +151,25 @@ static const struct init_action_type actions[] = {
/* Set up a linked list of init_actions, to be read from inittab */
struct init_action {
pid_t pid;
char command[256];
char terminal[256];
char command[INIT_BUFFS_SIZE];
char terminal[INIT_BUFFS_SIZE];
struct init_action *next;
int action;
};
/* Static variables */
static struct init_action *init_action_list = NULL;
static char *secondConsole = VC_2;
static char *thirdConsole = VC_3;
static char *fourthConsole = VC_4;
static char *log = VC_5;
static int kernelVersion = 0;
static char termType[32] = "TERM=linux";
static char console[32] = _PATH_CONSOLE;
static int kernelVersion = 0;
static char termType[32] = "TERM=linux";
static char console[32] = _PATH_CONSOLE;
#ifndef CONFIG_SYSLOGD
static char *log = VC_5;
#endif
static sig_atomic_t got_cont = 0;
static const int LOG = 0x1;
static const int CONSOLE = 0x2;
#if defined CONFIG_FEATURE_EXTRA_QUIET
static const int MAYBE_CONSOLE = 0x0;
#else
@@ -176,6 +179,7 @@ static const int MAYBE_CONSOLE = 0x0;
static const int RB_HALT_SYSTEM = 0xcdef0123;
static const int RB_ENABLE_CAD = 0x89abcdef;
static const int RB_DISABLE_CAD = 0;
#define RB_POWER_OFF 0x4321fedc
static const int RB_AUTOBOOT = 0x01234567;
#endif
@@ -188,17 +192,20 @@ static int waitfor(struct init_action *a);
static void loop_forever(void)
{
while (1)
sleep (1);
sleep(1);
}
/* Print a message to the specified device.
* Device may be bitwise-or'd from LOG | CONSOLE */
#ifdef DEBUG_INIT
static inline messageND(int device, char *fmt, ...) { }
#else
static inline messageND(int device, char *fmt, ...)
{
}
#else
#define messageND message
#endif
static void message(int device, char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
static void message(int device, char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));
static void message(int device, char *fmt, ...)
{
va_list arguments;
@@ -221,15 +228,9 @@ static void message(int device, char *fmt, ...)
/* Take full control of the log tty, and never close it.
* It's mine, all mine! Muhahahaha! */
if (log_fd < 0) {
if (log == NULL) {
/* don't even try to log, because there is no such console */
log_fd = -2;
/* log to main console instead */
device = CONSOLE;
} else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
if ((log_fd = device_open(log, O_RDWR | O_NDELAY)) < 0) {
log_fd = -2;
fprintf(stderr, "Bummer, can't write to log on %s!\n", log);
log = NULL;
device = CONSOLE;
}
}
@@ -242,9 +243,9 @@ static void message(int device, char *fmt, ...)
if (device & CONSOLE) {
/* Always send console messages to /dev/console so people will see them. */
if (
(fd =
device_open(_PATH_CONSOLE, O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0) {
if ((fd =
device_open(_PATH_CONSOLE,
O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0) {
va_start(arguments, fmt);
vdprintf(fd, fmt, arguments);
va_end(arguments);
@@ -266,21 +267,21 @@ static void set_term(int fd)
tcgetattr(fd, &tty);
/* set control chars */
tty.c_cc[VINTR] = 3; /* C-c */
tty.c_cc[VQUIT] = 28; /* C-\ */
tty.c_cc[VERASE] = 127; /* C-? */
tty.c_cc[VKILL] = 21; /* C-u */
tty.c_cc[VEOF] = 4; /* C-d */
tty.c_cc[VINTR] = 3; /* C-c */
tty.c_cc[VQUIT] = 28; /* C-\ */
tty.c_cc[VERASE] = 127; /* C-? */
tty.c_cc[VKILL] = 21; /* C-u */
tty.c_cc[VEOF] = 4; /* C-d */
tty.c_cc[VSTART] = 17; /* C-q */
tty.c_cc[VSTOP] = 19; /* C-s */
tty.c_cc[VSUSP] = 26; /* C-z */
tty.c_cc[VSTOP] = 19; /* C-s */
tty.c_cc[VSUSP] = 26; /* C-z */
/* use line dicipline 0 */
tty.c_line = 0;
/* Make it be sane */
tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
tty.c_cflag |= CREAD|HUPCL|CLOCAL;
tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD;
tty.c_cflag |= CREAD | HUPCL | CLOCAL;
/* input modes */
@@ -301,7 +302,7 @@ static void set_term(int fd)
static int check_free_memory(void)
{
struct sysinfo info;
unsigned int result, u, s=10;
unsigned int result, u, s = 10;
if (sysinfo(&info) != 0) {
perror_msg("Error checking free memory");
@@ -311,11 +312,16 @@ static int check_free_memory(void)
/* Kernels 2.0.x and 2.2.x return info.mem_unit==0 with values in bytes.
* Kernels 2.4.0 return info.mem_unit in bytes. */
u = info.mem_unit;
if (u==0) u=1;
while ( (u&1) == 0 && s > 0 ) { u>>=1; s--; }
result = (info.totalram>>s) + (info.totalswap>>s);
result = result*u;
if (result < 0) result = INT_MAX;
if (u == 0)
u = 1;
while ((u & 1) == 0 && s > 0) {
u >>= 1;
s--;
}
result = (info.totalram >> s) + (info.totalswap >> s);
result = result * u;
if (result < 0)
result = INT_MAX;
return result;
}
@@ -379,28 +385,22 @@ static void console_init(void)
/* Perhaps we should panic here? */
safe_strncpy(console, "/dev/null", sizeof(console));
} else {
/* check for serial console and disable logging to tty5 &
* running a shell to tty2-4 */
/* check for serial console */
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
log = NULL;
secondConsole = NULL;
thirdConsole = NULL;
fourthConsole = NULL;
/* Force the TERM setting to vt102 for serial console --
* iff TERM is set to linux (the default) */
if (strcmp( termType, "TERM=linux" ) == 0)
* if TERM is set to linux (the default) */
if (strcmp(termType, "TERM=linux") == 0)
safe_strncpy(termType, "TERM=vt102", sizeof(termType));
message(LOG | CONSOLE,
"\rserial console detected. Disabling virtual terminals.\n");
}
close(fd);
}
message(LOG, "console=%s\n", console);
}
static void fixup_argv(int argc, char **argv, char *new_argv0)
{
int len;
/* Fix up argv[0] to be certain we claim to be init */
len = strlen(argv[0]);
memset(argv[0], 0, len);
@@ -437,19 +437,19 @@ static void check_memory(void)
#endif
goodnight:
message(CONSOLE,
"\rSorry, your computer does not have enough memory.\n");
message(CONSOLE, "\rSorry, your computer does not have enough memory.\n");
loop_forever();
}
static pid_t run(struct init_action *a)
{
struct stat sb;
int i, j, fd, junk;
int i, j, junk;
pid_t pid, pgrp, tmp_pid;
char *s, *tmpCmd, *cmd[255], *cmdpath, buf[255];
char *s, *tmpCmd, *cmd[INIT_BUFFS_SIZE], *cmdpath;
char buf[INIT_BUFFS_SIZE + 6]; /* INIT_BUFFS_SIZE+strlen("exec ")+1 */
sigset_t nmask, omask;
char *environment[MAXENV+1] = {
char *environment[MAXENV + 1] = {
termType,
"HOME=/",
"PATH=" _PATH_STDPATH,
@@ -464,8 +464,8 @@ static pid_t run(struct init_action *a)
"\nPlease press Enter to activate this console. ";
/* inherit environment to the child, merging our values -andy */
for (i=0; environ[i]; i++) {
for (j=0; environment[j]; j++) {
for (i = 0; environ[i]; i++) {
for (j = 0; environment[j]; j++) {
s = strchr(environment[j], '=');
if (!strncmp(environ[i], environment[j], s - environment[j]))
break;
@@ -481,30 +481,30 @@ static pid_t run(struct init_action *a)
sigaddset(&nmask, SIGCHLD);
sigprocmask(SIG_BLOCK, &nmask, &omask);
if ((pid = fork()) == 0)
{
if ((pid = fork()) == 0) {
/* Clean up */
ioctl(0, TIOCNOTTY, 0);
close(0);
close(1);
close(2);
sigprocmask(SIG_SETMASK, &omask, NULL);
/* Create a new session and make ourself the process group leader */
setsid();
/* Reset signal handlers that were set by the parent process */
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGCONT, SIG_DFL);
signal(SIGSTOP, SIG_DFL);
signal(SIGTSTP, SIG_DFL);
/* Create a new session and make ourself the process
* group leader for non-interactive jobs */
if ((a->action & (RESPAWN)) == 0)
setsid();
/* Open the new terminal device */
if ((fd = device_open(a->terminal, O_RDWR|O_NOCTTY)) < 0) {
if ((device_open(a->terminal, O_RDWR | O_NOCTTY)) < 0) {
if (stat(a->terminal, &sb) != 0) {
message(LOG | CONSOLE, "\rdevice '%s' does not exist.\n",
a->terminal);
@@ -513,19 +513,26 @@ static pid_t run(struct init_action *a)
message(LOG | CONSOLE, "\rBummer, can't open %s\n", a->terminal);
_exit(1);
}
/* Non-interactive jobs should not get a controling tty */
if ((a->action & (RESPAWN)) == 0)
(void) ioctl(0, TIOCSCTTY, 0);
/* Make sure the terminal will act fairly normal for us */
set_term(0);
/* Setup stdout, stderr for the new process so
* they point to the supplied terminal */
dup(0);
dup(0);
/* If the init Action requires up to wait, then force the
/* For interactive jobs, create a new session
* and become the process group leader */
if ((a->action & (RESPAWN)))
setsid();
/* If the init Action requires us to wait, then force the
* supplied terminal to be the controlling tty. */
if (a->action & (SYSINIT|WAIT|CTRLALTDEL|SHUTDOWN|RESTART|ASKFIRST)) {
/* Take over the controlling tty */
ioctl(fd, TIOCSCTTY, 1);
/* Setup stdin, stdout, stderr for the new process so
* they point to the supplied terminal */
dup(fd);
dup(fd);
if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
/* Now fork off another process to just hang around */
if ((pid = fork()) < 0) {
@@ -542,13 +549,10 @@ static pid_t run(struct init_action *a)
signal(SIGCHLD, SIG_DFL);
/* Wait for child to exit */
while ((tmp_pid = waitpid(pid, &junk, 0)) != pid) {
if (tmp_pid < 0 && errno == ECHILD)
break;
}
while ((tmp_pid = waitpid(pid, &junk, 0)) != pid);
/* See if stealing the controlling tty back is necessary */
pgrp = tcgetpgrp(tmp_pid);
pgrp = tcgetpgrp(0);
if (pgrp != getpid())
_exit(0);
@@ -556,13 +560,13 @@ static pid_t run(struct init_action *a)
if ((pid = fork()) < 0) {
message(LOG | CONSOLE, "\rCan't fork!\n");
_exit(1);
}
}
if (pid == 0) {
setsid();
ioctl(tmp_pid, TIOCSCTTY, 1);
ioctl(0, TIOCSCTTY, 1);
_exit(0);
}
while((tmp_pid = waitpid(pid, &junk, 0)) != pid) {
}
while ((tmp_pid = waitpid(pid, &junk, 0)) != pid) {
if (tmp_pid < 0 && errno == ECHILD)
break;
}
@@ -570,29 +574,22 @@ static pid_t run(struct init_action *a)
}
/* Now fall though to actually execute things */
} else {
dup(fd);
dup(fd);
}
/* See if any special /bin/sh requiring characters are present */
if (strpbrk(a->command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
cmd[0] = SHELL;
cmd[1] = "-c";
strcpy(buf, "exec ");
safe_strncpy(buf + sizeof("exec "), a->command,
sizeof(buf) - sizeof("exec "));
strcat(strcpy(buf, "exec "), a->command);
cmd[2] = buf;
cmd[3] = NULL;
} else {
/* Convert command (char*) into cmd (char**, one word per string) */
safe_strncpy(buf, a->command, sizeof(buf));
strcpy(buf, a->command);
s = buf;
for (tmpCmd = buf, i = 0;
(tmpCmd = strsep(&s, " \t")) != NULL;) {
for (tmpCmd = buf, i = 0; (tmpCmd = strsep(&s, " \t")) != NULL;) {
if (*tmpCmd != '\0') {
cmd[i] = tmpCmd;
tmpCmd++;
i++;
}
}
@@ -617,12 +614,12 @@ static pid_t run(struct init_action *a)
s = get_last_path_component(cmdpath);
/* make a new argv[0] */
if ((cmd[0] = malloc(strlen(s)+2)) == NULL) {
if ((cmd[0] = malloc(strlen(s) + 2)) == NULL) {
message(LOG | CONSOLE, "malloc failed");
cmd[0] = cmdpath;
} else {
cmd[0][0] = '-';
strcpy(cmd[0]+1, s);
strcpy(cmd[0] + 1, s);
}
}
@@ -635,19 +632,21 @@ static pid_t run(struct init_action *a)
* be allowed to start a shell or whatever an init script
* specifies.
*/
messageND(LOG, "Waiting for enter to start '%s' (pid %d, terminal %s)\n",
cmdpath, getpid(), a->terminal);
messageND(LOG,
"Waiting for enter to start '%s' (pid %d, terminal %s)\n",
cmdpath, getpid(), a->terminal);
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
getc(stdin);
}
/* Log the process name and args */
messageND(LOG, "Starting pid %d, console %s: '%s'\n",
getpid(), a->terminal, cmdpath);
getpid(), a->terminal, cmdpath);
#if defined CONFIG_FEATURE_INIT_COREDUMPS
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {
struct rlimit limit;
limit.rlim_cur = RLIM_INFINITY;
limit.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_CORE, &limit);
@@ -669,7 +668,7 @@ static pid_t run(struct init_action *a)
static int waitfor(struct init_action *a)
{
int pid;
int pid;
int status, wpid;
pid = run(a);
@@ -692,13 +691,14 @@ static void run_actions(int action)
for (a = init_action_list; a; a = tmp) {
tmp = a->next;
if (a->action == action) {
if (a->action & (SYSINIT|WAIT|CTRLALTDEL|SHUTDOWN|RESTART)) {
if (a->
action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
waitfor(a);
delete_init_action(a);
} else if (a->action & ONCE) {
run(a);
delete_init_action(a);
} else if (a->action & (RESPAWN|ASKFIRST)) {
} else if (a->action & (RESPAWN | ASKFIRST)) {
/* Only run stuff with pid==0. If they have
* a pid, that means it is still running */
if (a->pid == 0) {
@@ -715,6 +715,11 @@ static void shutdown_system(void)
{
sigset_t block_signals;
/* run everything to be run at "shutdown". This is done _prior_
* to killing everything, in case people wish to use scripts to
* shut things down gracefully... */
run_actions(SHUTDOWN);
/* first disable all our signals */
sigemptyset(&block_signals);
sigaddset(&block_signals, SIGHUP);
@@ -731,24 +736,21 @@ static void shutdown_system(void)
/* Allow Ctrl-Alt-Del to reboot system. */
init_reboot(RB_ENABLE_CAD);
message(CONSOLE|LOG, "\n\rThe system is going down NOW !!\n");
message(CONSOLE | LOG, "\n\rThe system is going down NOW !!\n");
sync();
/* Send signals to every process _except_ pid 1 */
message(CONSOLE|LOG, "\rSending SIGTERM to all processes.\n");
message(CONSOLE | LOG, "\rSending SIGTERM to all processes.\n");
kill(-1, SIGTERM);
sleep(1);
sync();
message(CONSOLE|LOG, "\rSending SIGKILL to all processes.\n");
message(CONSOLE | LOG, "\rSending SIGKILL to all processes.\n");
kill(-1, SIGKILL);
sleep(1);
/* run everything to be run at "shutdown" */
run_actions(SHUTDOWN);
sync();
if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2, 2, 11)) {
/* bdflush, kupdate not needed for kernels >2.2.11 */
bdflush(1, 0);
sync();
@@ -758,15 +760,31 @@ static void shutdown_system(void)
static void exec_signal(int sig)
{
struct init_action *a, *tmp;
sigset_t unblock_signals;
for (a = init_action_list; a; a = tmp) {
tmp = a->next;
if (a->action & RESTART) {
shutdown_system();
message(CONSOLE|LOG, "\rTrying to re-exec %s\n", a->command);
/* unblock all signals, blocked in shutdown_system() */
sigemptyset(&unblock_signals);
sigaddset(&unblock_signals, SIGHUP);
sigaddset(&unblock_signals, SIGCHLD);
sigaddset(&unblock_signals, SIGUSR1);
sigaddset(&unblock_signals, SIGUSR2);
sigaddset(&unblock_signals, SIGINT);
sigaddset(&unblock_signals, SIGTERM);
sigaddset(&unblock_signals, SIGCONT);
sigaddset(&unblock_signals, SIGSTOP);
sigaddset(&unblock_signals, SIGTSTP);
sigprocmask(SIG_UNBLOCK, &unblock_signals, NULL);
message(CONSOLE | LOG, "\rTrying to re-exec %s\n", a->command);
execl(a->command, a->command, NULL);
message(CONSOLE|LOG, "\rexec of '%s' failed: %s\n",
a->command, sys_errlist[errno]);
message(CONSOLE | LOG, "\rexec of '%s' failed: %s\n",
a->command, strerror(errno));
sync();
sleep(2);
init_reboot(RB_HALT_SYSTEM);
@@ -778,22 +796,20 @@ static void exec_signal(int sig)
static void halt_signal(int sig)
{
shutdown_system();
message(CONSOLE|LOG,
message(CONSOLE | LOG,
#if #cpu(s390)
/* Seems the s390 console is Wierd(tm). */
"\rThe system is halted. You may reboot now.\n"
#else
/* secondConsole is NULL for a serial console */
"\rThe system is halted. Press %s or turn off power\n",
(secondConsole == NULL)? "Reset" : "CTRL-ALT-DEL"
"\rThe system is halted. Press Reset or turn off power\n"
#endif
);
);
sync();
/* allow time for last message to reach serial console */
sleep(2);
if (sig == SIGUSR2 && kernelVersion >= KERNEL_VERSION(2,2,0))
if (sig == SIGUSR2 && kernelVersion >= KERNEL_VERSION(2, 2, 0))
init_reboot(RB_POWER_OFF);
else
init_reboot(RB_HALT_SYSTEM);
@@ -804,7 +820,7 @@ static void halt_signal(int sig)
static void reboot_signal(int sig)
{
shutdown_system();
message(CONSOLE|LOG, "\rPlease stand by while rebooting the system.\n");
message(CONSOLE | LOG, "\rPlease stand by while rebooting the system.\n");
sync();
/* allow time for last message to reach serial console */
@@ -826,12 +842,13 @@ static void stop_handler(int sig)
int saved_errno = errno;
got_cont = 0;
while(!got_cont) pause();
while (!got_cont)
pause();
got_cont = 0;
errno = saved_errno;
}
/* The SIGCONT handler */
/* The SIGCONT handler */
static void cont_handler(int sig)
{
got_cont = 1;
@@ -846,12 +863,8 @@ static void new_init_action(int action, char *command, char *cons)
if (*cons == '\0')
cons = console;
/* If BusyBox detects that a serial console is in use, then entries
* not refering to the console or null devices will _not_ be run.
* The exception to this rule is the null device.
*/
if (secondConsole == NULL && strcmp(cons, console)
&& strcmp(cons, "/dev/null"))
/* do not run entries if console device is not available */
if (access(cons, R_OK | W_OK))
return;
if (strcmp(cons, "/dev/null") == 0 && (action & ASKFIRST))
return;
@@ -863,21 +876,21 @@ static void new_init_action(int action, char *command, char *cons)
}
/* Append to the end of the list */
for (a = init_action_list; a && a->next; a = a->next) ;
for (a = init_action_list; a && a->next; a = a->next);
if (a) {
a->next = new_action;
} else {
init_action_list = new_action;
}
safe_strncpy(new_action->command, command, 255);
strcpy(new_action->command, command);
new_action->action = action;
safe_strncpy(new_action->terminal, cons, 255);
strcpy(new_action->terminal, cons);
new_action->pid = 0;
// message(LOG|CONSOLE, "command='%s' action='%d' terminal='%s'\n",
// new_action->command, new_action->action, new_action->terminal);
/* message(LOG|CONSOLE, "command='%s' action='%d' terminal='%s'\n",
new_action->command, new_action->action, new_action->terminal); */
}
static void delete_init_action(struct init_action * action)
static void delete_init_action(struct init_action *action)
{
struct init_action *a, *b = NULL;
@@ -900,12 +913,13 @@ static void delete_init_action(struct init_action * action)
* of "askfirst" shells). If CONFIG_FEATURE_USE_INITTAB
* _is_ defined, but /etc/inittab is missing, this
* results in the same set of default behaviors.
* */
*/
static void parse_inittab(void)
{
#ifdef CONFIG_FEATURE_USE_INITTAB
FILE *file;
char buf[256], lineAsRead[256], tmpConsole[256];
char buf[INIT_BUFFS_SIZE], lineAsRead[INIT_BUFFS_SIZE],
tmpConsole[INIT_BUFFS_SIZE];
char *id, *runlev, *action, *command, *eol;
const struct init_action_type *a = actions;
int foundIt;
@@ -925,17 +939,11 @@ static void parse_inittab(void)
#endif
/* Prepare to restart init when a HUP is received */
new_init_action(RESTART, "/sbin/init", console);
/* Askfirst shell on tty1 */
/* Askfirst shell on tty1-4 */
new_init_action(ASKFIRST, LOGIN_SHELL, console);
/* Askfirst shell on tty2 */
if (secondConsole != NULL)
new_init_action(ASKFIRST, LOGIN_SHELL, secondConsole);
/* Askfirst shell on tty3 */
if (thirdConsole != NULL)
new_init_action(ASKFIRST, LOGIN_SHELL, thirdConsole);
/* Askfirst shell on tty4 */
if (fourthConsole != NULL)
new_init_action(ASKFIRST, LOGIN_SHELL, fourthConsole);
new_init_action(ASKFIRST, LOGIN_SHELL, VC_2);
new_init_action(ASKFIRST, LOGIN_SHELL, VC_3);
new_init_action(ASKFIRST, LOGIN_SHELL, VC_4);
/* sysinit */
new_init_action(SYSINIT, INIT_SCRIPT, console);
@@ -943,7 +951,7 @@ static void parse_inittab(void)
#ifdef CONFIG_FEATURE_USE_INITTAB
}
while (fgets(buf, 255, file) != NULL) {
while (fgets(buf, INIT_BUFFS_SIZE, file) != NULL) {
foundIt = FALSE;
/* Skip leading spaces */
for (id = buf; *id == ' ' || *id == '\t'; id++);
@@ -996,7 +1004,7 @@ static void parse_inittab(void)
if (strcmp(a->name, action) == 0) {
if (*id != '\0') {
strcpy(tmpConsole, "/dev/");
strncat(tmpConsole, id, 200);
strncat(tmpConsole, id, INIT_BUFFS_SIZE - 6);
id = tmpConsole;
}
new_init_action(a->action, command, id);
@@ -1011,8 +1019,9 @@ static void parse_inittab(void)
message(LOG | CONSOLE, "\rBad inittab entry: %s\n", lineAsRead);
}
}
fclose(file);
return;
#endif /* CONFIG_FEATURE_USE_INITTAB */
#endif /* CONFIG_FEATURE_USE_INITTAB */
}
@@ -1026,35 +1035,35 @@ extern int init_main(int argc, char **argv)
if (argc > 1 && !strcmp(argv[1], "-q")) {
/* don't assume init's pid == 1 */
long *pid = find_pid_by_name("init");
if (!pid || *pid<=0) {
if (!pid || *pid <= 0) {
pid = find_pid_by_name("linuxrc");
if (!pid || *pid<=0)
if (!pid || *pid <= 0)
error_msg_and_die("no process killed");
}
kill(*pid, SIGHUP);
exit(0);
}
#ifndef DEBUG_INIT
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
if (getpid() != 1
#ifdef CONFIG_FEATURE_INITRD
&& strstr(applet_name, "linuxrc") == NULL
&& strstr(applet_name, "linuxrc") == NULL
#endif
)
{
show_usage();
) {
show_usage();
}
/* Set up sig handlers -- be sure to
* clear all of these in run() */
signal(SIGHUP, exec_signal);
signal(SIGHUP, exec_signal);
signal(SIGUSR1, halt_signal);
signal(SIGUSR2, halt_signal);
signal(SIGINT, ctrlaltdel_signal);
signal(SIGINT, ctrlaltdel_signal);
signal(SIGTERM, reboot_signal);
signal(SIGCONT, cont_handler);
signal(SIGSTOP, stop_handler);
signal(SIGTSTP, stop_handler);
signal(SIGCHLD, SIG_IGN);
/* Turn off rebooting via CTL-ALT-DEL -- we get a
* SIGINT on CAD so we can shut things down gracefully... */
@@ -1064,23 +1073,27 @@ extern int init_main(int argc, char **argv)
/* Figure out what kernel this is running */
kernelVersion = get_kernel_revision();
/* Figure out where the default console should be */
console_init();
/* Close whatever files are open, and reset the console. */
close(0);
close(1);
close(2);
/* Figure out where the default console should be */
console_init();
if (device_open(console, O_RDWR | O_NOCTTY) == 0) {
set_term(0);
close(0);
}
set_term(0);
chdir("/");
setsid();
/* Make sure PATH is set to something sane */
putenv("PATH="_PATH_STDPATH);
putenv("PATH=" _PATH_STDPATH);
/* Hello world */
message(MAYBE_CONSOLE|LOG, "\rinit started: %s\n", full_version);
message(MAYBE_CONSOLE | LOG, "\rinit started: %s\n", full_version);
/* Make sure there is enough memory to do something useful. */
check_memory();
@@ -1089,12 +1102,9 @@ extern int init_main(int argc, char **argv)
if (argc > 1 && (!strcmp(argv[1], "single") ||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
/* Ask first then start a shell on tty2-4 */
if (secondConsole != NULL)
new_init_action(ASKFIRST, LOGIN_SHELL, secondConsole);
if (thirdConsole != NULL)
new_init_action(ASKFIRST, LOGIN_SHELL, thirdConsole);
if (fourthConsole != NULL)
new_init_action(ASKFIRST, LOGIN_SHELL, fourthConsole);
new_init_action(ASKFIRST, LOGIN_SHELL, VC_2);
new_init_action(ASKFIRST, LOGIN_SHELL, VC_3);
new_init_action(ASKFIRST, LOGIN_SHELL, VC_4);
/* Start a shell on tty1 */
new_init_action(RESPAWN, LOGIN_SHELL, console);
} else {
@@ -1123,7 +1133,8 @@ extern int init_main(int argc, char **argv)
/* If there is nothing else to do, stop */
if (init_action_list == NULL) {
message(LOG | CONSOLE, "\rNo more tasks for init -- sleeping forever.\n");
message(LOG | CONSOLE,
"\rNo more tasks for init -- sleeping forever.\n");
loop_forever();
}
+58
View File
@@ -0,0 +1,58 @@
/*
* mesg implementation for busybox
*
* Copyright (c) 2002 Manuel Novoa III <mjn3@codepoet.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <unistd.h>
#include <stdlib.h>
#include "libbb.h"
#ifdef USE_TTY_GROUP
#define S_IWGRP_OR_S_IWOTH S_IWGRP
#else
#define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH)
#endif
extern int mesg_main(int argc, char *argv[])
{
struct stat sb;
char *tty;
char c;
if ((--argc == 0)
|| ((argc == 1) && (((c = **++argv) == 'y') || (c == 'n')))) {
if ((tty = ttyname(STDERR_FILENO)) == NULL) {
tty = "ttyname";
} else if (stat(tty, &sb) == 0) {
if (argc == 0) {
puts(((sb.st_mode & (S_IWGRP | S_IWOTH)) ==
0) ? "is n" : "is y");
return EXIT_SUCCESS;
}
if (chmod
(tty,
(c ==
'y') ? sb.st_mode | (S_IWGRP_OR_S_IWOTH) : sb.
st_mode & ~(S_IWGRP | S_IWOTH)) == 0) {
return EXIT_SUCCESS;
}
}
perror_msg_and_die("%s", tty);
}
show_usage();
}
+72 -5
View File
@@ -23,21 +23,88 @@
#include "busybox.h"
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#if (__GNU_LIBRARY__ > 5) || defined(__dietlibc__)
#include <sys/reboot.h>
#define init_reboot(magic) reboot(magic)
#else
#define init_reboot(magic) reboot(0xfee1dead, 672274793, magic)
#endif
#ifndef RB_ENABLE_CAD
static const int RB_ENABLE_CAD = 0x89abcdef;
static const int RB_AUTOBOOT = 0x01234567;
#endif
extern int reboot_main(int argc, char **argv)
{
int delay = 0; /* delay in seconds before rebooting */
int rc;
while ((rc = getopt(argc, argv, "d:")) > 0) {
switch (rc) {
case 'd':
delay = atoi(optarg);
break;
default:
show_usage();
break;
}
}
if(delay > 0)
sleep(delay);
#ifdef CONFIG_USER_INIT
/* Don't kill ourself */
signal(SIGTERM,SIG_IGN);
signal(SIGHUP,SIG_IGN);
setpgrp();
/* Allow Ctrl-Alt-Del to reboot system. */
init_reboot(RB_ENABLE_CAD);
message(CONSOLE|LOG, "\n\rThe system is going down NOW !!\n");
sync();
/* Send signals to every process _except_ pid 1 */
message(CONSOLE|LOG, "\rSending SIGTERM to all processes.\n");
kill(-1, SIGTERM);
sleep(1);
sync();
message(CONSOLE|LOG, "\rSending SIGKILL to all processes.\n");
kill(-1, SIGKILL);
sleep(1);
sync();
if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
/* bdflush, kupdate not needed for kernels >2.2.11 */
bdflush(1, 0);
sync();
}
init_reboot(RB_AUTOBOOT);
exit(0); /* Shrug */
#else
#ifdef CONFIG_FEATURE_INITRD
/* don't assume init's pid == 1 */
long *pid = find_pid_by_name("init");
if (!pid || *pid<=0) {
pid = find_pid_by_name("linuxrc");
{
/* don't assume init's pid == 1 */
long *pid = find_pid_by_name("init");
if (!pid || *pid<=0)
pid = find_pid_by_name("linuxrc");
if (!pid || *pid<=0)
error_msg_and_die("no process killed");
fflush(stdout);
return(kill(*pid, SIGTERM));
}
return(kill(*pid, SIGTERM));
#else
return(kill(1, SIGTERM));
#endif
#endif
}
/*
+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;
}
+9 -3
View File
@@ -34,17 +34,23 @@ LIBBB_SRC:= \
my_getpwuid.c parse_mode.c parse_number.c perror_msg.c perror_msg_and_die.c \
print_file.c process_escape_sequence.c read_package_field.c recursive_action.c \
safe_read.c safe_strncpy.c syscalls.c syslog_msg_with_name.c time_string.c \
trim.c unzip.c vdprintf.c verror_msg.c vperror_msg.c wfopen.c xfuncs.c \
trim.c unzip.c uncompress.c vdprintf.c verror_msg.c vperror_msg.c wfopen.c \
xgetcwd.c xreadlink.c xregcomp.c interface.c remove_file.c last_char_is.c \
copyfd.c vherror_msg.c herror_msg.c herror_msg_and_die.c xgethostbyname.c \
dirname.c make_directory.c create_icmp_socket.c u_signal_names.c arith.c \
simplify_path.c inet_common.c inode_hash.c
simplify_path.c inet_common.c inode_hash.c obscure.c pwd2spwd.c xfuncs.c \
correct_password.c change_identity.c setup_environment.c run_shell.c \
pw_encrypt.c restricted_shell.c xgethostbyname2.c create_icmp6_socket.c \
xconnect.c bb_asprintf.c
LIBBB_OBJS=$(patsubst %.c,$(LIBBB_DIR)%.o, $(LIBBB_SRC))
LIBBB_MSRC:=$(LIBBB_DIR)messages.c
LIBBB_MOBJ:=full_version.o name_too_long.o omitting_directory.o not_a_directory.o \
memory_exhausted.o invalid_date.o invalid_option.o io_error.o dash_dash_help.o \
write_error.o too_few_args.o name_longer_than_foo.o unknown.o can_not_create_raw_socket.o
write_error.o too_few_args.o name_longer_than_foo.o unknown.o can_not_create_raw_socket.o \
shadow_file.o passwd_file.o group_file.o gshadow_file.o nologin_file.o securetty_file.o \
motd_file.o
LIBBB_MOBJS=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ))
libraries-y+=$(LIBBB_DIR)$(LIBBB_AR)
+45 -43
View File
@@ -26,14 +26,14 @@
* listed in #defines below. Parens, order of operations, and error handling
* are supported. This code is threadsafe. The exact expression format should
* be that which POSIX specifies for shells. */
/* The code uses a simple two-stack algorithm. See
* http://www.onthenet.com.au/~grahamis/int2008/week02/lect02.html
* for a detailed explaination of the infix-to-postfix algorithm on which
* this is based (this code differs in that it applies operators immediately
* to the stack instead of adding them to a queue to end up with an
* expression). */
/* To use the routine, call it with an expression string and error return
* pointer */
@@ -149,7 +149,7 @@ typedef char operator;
#define TOK_NUM tok_decl(15,0)
#define TOK_RPAREN tok_decl(15,1)
#define TOK_ERROR tok_decl(15,2) /* just a place-holder really */
#define TOK_ERROR tok_decl(15,2) /* just a place-holder really */
#define ARITH_APPLY(op) arith_apply(op, numstack, &numstackptr)
#define NUMPTR (*numstackptr)
@@ -157,7 +157,7 @@ typedef char operator;
/* "applying" a token means performing it on the top elements on the integer
* stack. For a unary operator it will only change the top element, but a
* binary operator will pop two arguments and push a result */
static short arith_apply(operator op, long *numstack, long **numstackptr)
static short arith_apply(operator op, long *numstack, long **numstackptr)
{
long numptr_val;
long *NUMPTR_M1;
@@ -172,49 +172,49 @@ static short arith_apply(operator op, long *numstack, long **numstackptr)
else if (op == TOK_BNOT)
*NUMPTR_M1 = ~(*NUMPTR_M1);
else if (op != TOK_UPLUS) {
/* Binary operators */
/* Binary operators */
if (NUMPTR_M1 == numstack) goto err; /* ... and binary operators need two
arguments */
numptr_val = *--NUMPTR; /* ... and they pop one */
NUMPTR_M1 = NUMPTR - 1;
numptr_val = *--NUMPTR; /* ... and they pop one */
NUMPTR_M1 = NUMPTR - 1;
if (op == TOK_BOR)
*NUMPTR_M1 |= numptr_val;
*NUMPTR_M1 |= numptr_val;
else if (op == TOK_OR)
*NUMPTR_M1 = numptr_val || *NUMPTR_M1;
*NUMPTR_M1 = numptr_val || *NUMPTR_M1;
else if (op == TOK_BAND)
*NUMPTR_M1 &= numptr_val;
*NUMPTR_M1 &= numptr_val;
else if (op == TOK_AND)
*NUMPTR_M1 = *NUMPTR_M1 && numptr_val;
*NUMPTR_M1 = *NUMPTR_M1 && numptr_val;
else if (op == TOK_EQ)
*NUMPTR_M1 = (*NUMPTR_M1 == numptr_val);
*NUMPTR_M1 = (*NUMPTR_M1 == numptr_val);
else if (op == TOK_NE)
*NUMPTR_M1 = (*NUMPTR_M1 != numptr_val);
*NUMPTR_M1 = (*NUMPTR_M1 != numptr_val);
else if (op == TOK_GE)
*NUMPTR_M1 = (*NUMPTR_M1 >= numptr_val);
*NUMPTR_M1 = (*NUMPTR_M1 >= numptr_val);
else if (op == TOK_RSHIFT)
*NUMPTR_M1 >>= numptr_val;
*NUMPTR_M1 >>= numptr_val;
else if (op == TOK_LSHIFT)
*NUMPTR_M1 <<= numptr_val;
*NUMPTR_M1 <<= numptr_val;
else if (op == TOK_GT)
*NUMPTR_M1 = (*NUMPTR_M1 > numptr_val);
*NUMPTR_M1 = (*NUMPTR_M1 > numptr_val);
else if (op == TOK_LT)
*NUMPTR_M1 = (*NUMPTR_M1 < numptr_val);
*NUMPTR_M1 = (*NUMPTR_M1 < numptr_val);
else if (op == TOK_LE)
*NUMPTR_M1 = (*NUMPTR_M1 <= numptr_val);
*NUMPTR_M1 = (*NUMPTR_M1 <= numptr_val);
else if (op == TOK_MUL)
*NUMPTR_M1 *= numptr_val;
*NUMPTR_M1 *= numptr_val;
else if (op == TOK_ADD)
*NUMPTR_M1 += numptr_val;
*NUMPTR_M1 += numptr_val;
else if (op == TOK_SUB)
*NUMPTR_M1 -= numptr_val;
else if(numptr_val==0) /* zero divisor check */
return -2;
*NUMPTR_M1 -= numptr_val;
else if(numptr_val==0) /* zero divisor check */
return -2;
else if (op == TOK_DIV)
*NUMPTR_M1 /= numptr_val;
*NUMPTR_M1 /= numptr_val;
else if (op == TOK_REM)
*NUMPTR_M1 %= numptr_val;
/* WARNING!!! WARNING!!! WARNING!!! */
/* Any new operators should be added BEFORE the zero divisor check! */
*NUMPTR_M1 %= numptr_val;
/* WARNING!!! WARNING!!! WARNING!!! */
/* Any new operators should be added BEFORE the zero divisor check! */
}
return 0;
err: return(-1);
@@ -240,30 +240,32 @@ static const char op_token[] = {
extern long arith (const char *expr, int *errcode)
{
register char arithval; /* Current character under analysis */
operator lasttok, op;
register char arithval; /* Current character under analysis */
operator lasttok, op;
unsigned char prec;
const char *p = endexpression;
size_t datasizes = strlen(expr);
size_t datasizes = strlen(expr) + 2;
/* Stack of integers */
/* The proof that there can be no more than strlen(startbuf)/2+1 integers
* in any given correct or incorrect expression is left as an excersize to
* the reader. */
long *numstack = alloca((datasizes/2)*sizeof(long)),
long *numstack = alloca(((datasizes)/2)*sizeof(long)),
*numstackptr = numstack;
/* Stack of operator tokens */
operator *stack = alloca((datasizes+1) * sizeof(operator)),
operator *stack = alloca((datasizes) * sizeof(operator)),
*stackptr = stack;
*stackptr++ = lasttok = TOK_LPAREN; /* start off with a left paren */
*numstack = 0;
*stackptr++ = lasttok = TOK_LPAREN; /* start off with a left paren */
loop:
loop:
if ((arithval = *expr) == 0) {
if (p == endexpression) { /* Null expression. */
return (*errcode = 0);
*errcode = 0;
return *numstack;
}
/* This is only reached after all tokens have been extracted from the
@@ -271,13 +273,13 @@ extern long arith (const char *expr, int *errcode)
* are to be applied in order. At the end, there should be a final
* result on the integer stack */
if (expr != endexpression + 1) { /* If we haven't done so already, */
if (expr != endexpression + 1) { /* If we haven't done so already, */
expr = endexpression; /* append a closing right paren */
goto loop; /* and let the loop process it. */
goto loop; /* and let the loop process it. */
}
/* At this point, we're done with the expression. */
if (numstackptr != numstack+1) {/* ... but if there isn't, it's bad */
err:
err:
return (*errcode = -1);
/* NOTREACHED */
}
@@ -285,7 +287,7 @@ extern long arith (const char *expr, int *errcode)
} else {
/* Continue processing the expression. */
if (isspace(arithval)) {
goto prologue; /* Skip whitespace */
goto prologue; /* Skip whitespace */
}
if ((unsigned)arithval-'0' <= 9) /* isdigit */ {
*numstackptr++ = strtol(expr, (char **) &expr, 10);
@@ -321,7 +323,7 @@ extern long arith (const char *expr, int *errcode)
if ((lasttok != TOK_NUM)
&& (p >= op_token + NUM_PAIR_SAME + NUM_PAIR_EQUAL
+ sizeof(op_char) - 2)) {
p += 2; /* Unary plus or minus */
p += 2; /* Unary plus or minus */
}
}
}
@@ -349,7 +351,7 @@ extern long arith (const char *expr, int *errcode)
if (stackptr[-1] == TOK_LPAREN) {
--stackptr;
lasttok = TOK_NUM; /* Any operator directly after a */
/* close paren should consider itself binary */
/* close paren should consider itself binary */
goto prologue;
}
} else if (PREC(stackptr[-1]) < prec) {
@@ -366,7 +368,7 @@ extern long arith (const char *expr, int *errcode)
/* Push this operator to the stack and remember it. */
*stackptr++ = lasttok = op;
prologue:
prologue:
++expr;
goto loop;
}
+21
View File
@@ -0,0 +1,21 @@
/*
Copyright (C) 2002 Vladimir Oleynik <dzo@simtreas.ru>
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "libbb.h"
void bb_asprintf(char **string_ptr, const char *format, ...)
{
va_list p;
va_start(p, format);
if(vasprintf(string_ptr, format, p)<0)
error_msg_and_die(memory_exhausted);
va_end(p);
}
+54
View File
@@ -0,0 +1,54 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright 1989 - 1991, Julianne Frances Haugh <jockgrrl@austin.rr.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include <ctype.h>
#include "libbb.h"
/* Become the user and group(s) specified by PW. */
void change_identity ( const struct passwd *pw )
{
if ( initgroups ( pw-> pw_name, pw-> pw_gid ) == -1 )
perror_msg_and_die ( "cannot set groups" );
endgrent ( );
if ( setgid ( pw-> pw_gid ))
perror_msg_and_die ( "cannot set group id" );
if ( setuid ( pw->pw_uid ))
perror_msg_and_die ( "cannot set user id" );
}
+1 -2
View File
@@ -38,8 +38,7 @@ extern char *concat_path_file(const char *path, const char *filename)
lc = last_char_is(path, '/');
while (*filename == '/')
filename++;
outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL));
sprintf(outbuf, "%s%s%s", path, (lc==NULL)? "/" : "", filename);
bb_asprintf(&outbuf, "%s%s%s", path, (lc==NULL)? "/" : "", filename);
return outbuf;
}
+29 -21
View File
@@ -36,7 +36,7 @@ int copy_file(const char *source, const char *dest, int flags)
{
struct stat source_stat;
struct stat dest_stat;
int dest_exists = 1;
int dest_exists = 0;
int status = 0;
if ((!(flags & FILEUTILS_DEREFERENCE) &&
@@ -47,19 +47,19 @@ int copy_file(const char *source, const char *dest, int flags)
return -1;
}
if (stat(dest, &dest_stat) < 0) {
if (lstat(dest, &dest_stat) < 0) {
if (errno != ENOENT) {
perror_msg("unable to stat `%s'", dest);
return -1;
}
dest_exists = 0;
}
if (dest_exists && source_stat.st_rdev == dest_stat.st_rdev &&
} else {
if (source_stat.st_dev == dest_stat.st_dev &&
source_stat.st_ino == dest_stat.st_ino) {
error_msg("`%s' and `%s' are the same file", source, dest);
return -1;
}
dest_exists = 1;
}
if (S_ISDIR(source_stat.st_mode)) {
DIR *dp;
@@ -116,13 +116,8 @@ int copy_file(const char *source, const char *dest, int flags)
free(new_source);
free(new_dest);
}
/* ??? What if an error occurs in readdir? */
if (closedir(dp) < 0) {
perror_msg("unable to close directory `%s'", source);
status = -1;
}
/* closedir have only EBADF error, but "dp" not changes */
closedir(dp);
if (!dest_exists &&
chmod(dest, source_stat.st_mode & ~saved_umask) < 0) {
@@ -145,8 +140,7 @@ int copy_file(const char *source, const char *dest, int flags)
}
#endif
if ((sfp = fopen(source, "r")) == NULL) {
perror_msg("unable to open `%s'", source);
if ((sfp = wfopen(source, "r")) == NULL) {
return -1;
}
@@ -201,8 +195,23 @@ int copy_file(const char *source, const char *dest, int flags)
perror_msg("unable to close `%s'", source);
status = -1;
}
} else if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) ||
S_ISSOCK(source_stat.st_mode)) {
}
else if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) ||
S_ISSOCK(source_stat.st_mode) || S_ISFIFO(source_stat.st_mode) ||
S_ISLNK(source_stat.st_mode)) {
if (dest_exists &&
((flags & FILEUTILS_FORCE) == 0 || unlink(dest) < 0)) {
perror_msg("unable to remove `%s'", dest);
return -1;
}
} else {
error_msg("internal error: unrecognized file type");
return -1;
}
if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) ||
S_ISSOCK(source_stat.st_mode)) {
if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) {
perror_msg("unable to create `%s'", dest);
return -1;
@@ -213,7 +222,9 @@ int copy_file(const char *source, const char *dest, int flags)
return -1;
}
} else if (S_ISLNK(source_stat.st_mode)) {
char *lpath = xreadlink(source);
char *lpath;
lpath = xreadlink(source);
if (symlink(lpath, dest) < 0) {
perror_msg("cannot create symlink `%s'", dest);
return -1;
@@ -231,9 +242,6 @@ int copy_file(const char *source, const char *dest, int flags)
#endif
return 0;
} else {
error_msg("internal error: unrecognized file type");
return -1;
}
#ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS
+78
View File
@@ -0,0 +1,78 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright 1989 - 1991, Julianne Frances Haugh <jockgrrl@austin.rr.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include <ctype.h>
#include <crypt.h>
#include "libbb.h"
/* Ask the user for a password.
Return 1 if the user gives the correct password for entry PW,
0 if not. Return 1 without asking for a password if run by UID 0
or if PW has an empty password. */
int correct_password ( const struct passwd *pw )
{
char *unencrypted, *encrypted, *correct;
#ifdef CONFIG_FEATURE_SHADOWPASSWDS
if (( strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( strcmp ( pw-> pw_passwd, "*" ) == 0 )) {
struct spwd *sp = getspnam ( pw-> pw_name );
if ( !sp )
error_msg_and_die ( "no valid shadow password" );
correct = sp-> sp_pwdp;
}
else
#endif
correct = pw-> pw_passwd;
if ( correct == 0 || correct[0] == '\0' )
return 1;
unencrypted = getpass ( "Password: " );
if ( !unencrypted )
{
fputs ( "getpass: cannot open /dev/tty\n", stderr );
return 0;
}
encrypted = crypt ( unencrypted, correct );
memset ( unencrypted, 0, xstrlen ( unencrypted ));
return ( strcmp ( encrypted, correct ) == 0 ) ? 1 : 0;
}
+39
View File
@@ -0,0 +1,39 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* create raw socket for icmp (IPv6 version) protocol test permision
* and drop root privilegies if running setuid
*
*/
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <errno.h>
#include <unistd.h>
#include "libbb.h"
#if CONFIG_FEATURE_IPV6
int create_icmp6_socket(void)
{
struct protoent *proto;
int sock;
proto = getprotobyname("ipv6-icmp");
/* if getprotobyname failed, just silently force
* proto->p_proto to have the correct value for "ipv6-icmp" */
if ((sock = socket(AF_INET6, SOCK_RAW,
(proto ? proto->p_proto : IPPROTO_ICMPV6))) < 0) {
if (errno == EPERM)
error_msg_and_die("permission denied. (are you root?)");
else
perror_msg_and_die(can_not_create_raw_socket);
}
/* drop root privs if running setuid */
setuid(getuid());
return sock;
}
#endif
+233 -191
View File
@@ -30,21 +30,21 @@
enum _vflag vflag = FIRST;
FS *fshead; /* head of format strings */
extern FS *fshead; /* head of format strings */
extern FS *fshead; /* head of format strings */
extern int blocksize;
static FU *endfu;
static char **_argv;
static off_t savaddress; /* saved address/offset in stream */
static off_t eaddress; /* end address */
static off_t address; /* address/offset in stream */
off_t skip; /* bytes to skip */
static off_t savaddress; /* saved address/offset in stream */
static off_t eaddress; /* end address */
static off_t address; /* address/offset in stream */
off_t skip; /* bytes to skip */
off_t saveaddress;
int exitval; /* final exit value */
int blocksize; /* data block size */
int length = -1; /* max bytes to read */
int exitval; /* final exit value */
int blocksize; /* data block size */
int length = -1; /* max bytes to read */
int size(FS *fs)
int size(FS * fs)
{
register FU *fu;
register int bcnt, cursize;
@@ -69,23 +69,33 @@ int size(FS *fs)
prec = atoi(fmt);
while (isdigit(*++fmt));
}
switch(*fmt) {
switch (*fmt) {
case 'c':
bcnt += 1;
break;
case 'd': case 'i': case 'o': case 'u':
case 'x': case 'X':
case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
bcnt += 4;
break;
case 'e': case 'E': case 'f': case 'g': case 'G':
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
bcnt += 8;
break;
case 's':
bcnt += prec;
break;
case '_':
switch(*++fmt) {
case 'c': case 'p': case 'u':
switch (*++fmt) {
case 'c':
case 'p':
case 'u':
bcnt += 1;
break;
}
@@ -93,10 +103,10 @@ int size(FS *fs)
}
cursize += bcnt * fu->reps;
}
return(cursize);
return (cursize);
}
void rewrite(FS *fs)
void rewrite(FS * fs)
{
enum { NOTOKAY, USEBCNT, USEPREC } sokay;
register PR *pr, **nextpr = NULL;
@@ -112,7 +122,7 @@ void rewrite(FS *fs)
*/
for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) {
/* NOSTRICT */
pr = (PR *)xmalloc(sizeof(PR));
pr = (PR *) xmalloc(sizeof(PR));
if (!fu->nextpr)
fu->nextpr = pr;
else
@@ -143,53 +153,64 @@ void rewrite(FS *fs)
sokay = USEPREC;
prec = atoi(p1);
while (isdigit(*++p1));
}
else
} else
sokay = NOTOKAY;
}
p2 = p1 + 1; /* set end pointer */
p2 = p1 + 1; /* set end pointer */
/*
* figure out the byte count for each conversion;
* rewrite the format as necessary, set up blank-
* padding for end of data.
*/
switch(*p1) {
switch (*p1) {
case 'c':
pr->flags = F_CHAR;
switch(fu->bcnt) {
case 0: case 1:
switch (fu->bcnt) {
case 0:
case 1:
pr->bcnt = 1;
break;
default:
p1[1] = '\0';
error_msg_and_die("bad byte count for conversion character %s.", p1);
error_msg_and_die
("bad byte count for conversion character %s.", p1);
}
break;
case 'd': case 'i':
case 'd':
case 'i':
pr->flags = F_INT;
goto sw1;
case 'l':
++p2;
switch(p1[1]) {
case 'd': case 'i':
switch (p1[1]) {
case 'd':
case 'i':
++p1;
pr->flags = F_INT;
goto sw1;
case 'o': case 'u': case 'x': case 'X':
case 'o':
case 'u':
case 'x':
case 'X':
++p1;
pr->flags = F_UINT;
goto sw1;
default:
p1[2] = '\0';
error_msg_and_die("hexdump: bad conversion character %%%s.\n", p1);
error_msg_and_die
("hexdump: bad conversion character %%%s.\n", p1);
}
/* NOTREACHED */
case 'o': case 'u': case 'x': case 'X':
case 'o':
case 'u':
case 'x':
case 'X':
pr->flags = F_UINT;
sw1: switch(fu->bcnt) {
case 0: case 4:
sw1:switch (fu->bcnt) {
case 0:
case 4:
pr->bcnt = 4;
break;
case 1:
@@ -200,13 +221,19 @@ sw1: switch(fu->bcnt) {
break;
default:
p1[1] = '\0';
error_msg_and_die("bad byte count for conversion character %s.", p1);
error_msg_and_die
("bad byte count for conversion character %s.", p1);
}
break;
case 'e': case 'E': case 'f': case 'g': case 'G':
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
pr->flags = F_DBL;
switch(fu->bcnt) {
case 0: case 8:
switch (fu->bcnt) {
case 0:
case 8:
pr->bcnt = 8;
break;
case 4:
@@ -214,14 +241,16 @@ sw1: switch(fu->bcnt) {
break;
default:
p1[1] = '\0';
error_msg_and_die("bad byte count for conversion character %s.", p1);
error_msg_and_die
("bad byte count for conversion character %s.", p1);
}
break;
case 's':
pr->flags = F_STR;
switch(sokay) {
switch (sokay) {
case NOTOKAY:
error_msg_and_die("%%s requires a precision or a byte count.");
error_msg_and_die
("%%s requires a precision or a byte count.");
case USEBCNT:
pr->bcnt = fu->bcnt;
break;
@@ -232,7 +261,7 @@ sw1: switch(fu->bcnt) {
break;
case '_':
++p2;
switch(p1[1]) {
switch (p1[1]) {
case 'A':
endfu = fu;
fu->flags |= F_IGNORE;
@@ -240,18 +269,21 @@ sw1: switch(fu->bcnt) {
case 'a':
pr->flags = F_ADDRESS;
++p2;
switch(p1[2]) {
case 'd': case 'o': case'x':
switch (p1[2]) {
case 'd':
case 'o':
case 'x':
*p1 = p1[2];
break;
default:
p1[3] = '\0';
error_msg_and_die("hexdump: bad conversion character %%%s.\n", p1);
error_msg_and_die
("hexdump: bad conversion character %%%s.\n", p1);
}
break;
case 'c':
pr->flags = F_C;
/* *p1 = 'c'; set in conv_c */
/* *p1 = 'c'; set in conv_c */
goto sw2;
case 'p':
pr->flags = F_P;
@@ -259,24 +291,29 @@ sw1: switch(fu->bcnt) {
goto sw2;
case 'u':
pr->flags = F_U;
/* *p1 = 'c'; set in conv_u */
sw2: switch(fu->bcnt) {
case 0: case 1:
/* *p1 = 'c'; set in conv_u */
sw2:switch (fu->bcnt) {
case 0:
case 1:
pr->bcnt = 1;
break;
default:
p1[2] = '\0';
error_msg_and_die("bad byte count for conversion character %s.", p1);
error_msg_and_die
("bad byte count for conversion character %s.",
p1);
}
break;
default:
p1[2] = '\0';
error_msg_and_die("hexdump: bad conversion character %%%s.\n", p1);
error_msg_and_die
("hexdump: bad conversion character %%%s.\n", p1);
}
break;
default:
p1[1] = '\0';
error_msg_and_die("hexdump: bad conversion character %%%s.\n", p1);
error_msg_and_die("hexdump: bad conversion character %%%s.\n",
p1);
}
/*
@@ -292,8 +329,9 @@ sw2: switch(fu->bcnt) {
fmtp = p2;
/* only one conversion character if byte count */
if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++) {
error_msg_and_die("hexdump: byte count with multiple conversion characters.\n");
if (!(pr->flags & F_ADDRESS) && fu->bcnt && nconv++) {
error_msg_and_die
("hexdump: byte count with multiple conversion characters.\n");
}
}
/*
@@ -315,7 +353,7 @@ sw2: switch(fu->bcnt) {
*/
for (fu = fs->nextfu;; fu = fu->nextfu) {
if (!fu->nextfu && fs->bcnt < blocksize &&
!(fu->flags&F_SETREP) && fu->bcnt)
!(fu->flags & F_SETREP) && fu->bcnt)
fu->reps += (blocksize - fs->bcnt) / fu->bcnt;
if (fu->reps > 1) {
for (pr = fu->nextpr;; pr = pr->nextpr)
@@ -339,11 +377,10 @@ static void doskip(char *fname, int statok)
if (fstat(fileno(stdin), &sbuf)) {
perror_msg_and_die("hexdump: %s", fname);
}
if ( ( ! (S_ISCHR(sbuf.st_mode) ||
S_ISBLK(sbuf.st_mode) ||
S_ISFIFO(sbuf.st_mode)) ) &&
skip >= sbuf.st_size) {
/* If size valid and skip >= size */
if ((!(S_ISCHR(sbuf.st_mode) ||
S_ISBLK(sbuf.st_mode) ||
S_ISFIFO(sbuf.st_mode))) && skip >= sbuf.st_size) {
/* If size valid and skip >= size */
skip -= sbuf.st_size;
address += sbuf.st_size;
return;
@@ -363,7 +400,7 @@ int next(char **argv)
if (argv) {
_argv = argv;
return(1);
return (1);
}
for (;;) {
if (*_argv) {
@@ -376,7 +413,7 @@ int next(char **argv)
statok = done = 1;
} else {
if (done++)
return(0);
return (0);
statok = 0;
}
if (skip)
@@ -384,13 +421,12 @@ int next(char **argv)
if (*_argv)
++_argv;
if (!skip)
return(1);
return (1);
}
/* NOTREACHED */
}
static u_char *
get(void)
static u_char *get(void)
{
static int ateof = 1;
static u_char *curp, *savp;
@@ -399,8 +435,8 @@ get(void)
u_char *tmpp;
if (!curp) {
curp = (u_char *)xmalloc(blocksize);
savp = (u_char *)xmalloc(blocksize);
curp = (u_char *) xmalloc(blocksize);
savp = (u_char *) xmalloc(blocksize);
} else {
tmpp = curp;
curp = savp;
@@ -413,22 +449,22 @@ get(void)
* and no other files are available, zero-pad the rest of the
* block and set the end flag.
*/
if (!length || (ateof && !next((char **)NULL))) {
if (!length || (ateof && !next((char **) NULL))) {
if (need == blocksize) {
return((u_char *)NULL);
return ((u_char *) NULL);
}
if (vflag != ALL && !bcmp(curp, savp, nread)) {
if (vflag != DUP) {
printf("*\n");
}
return((u_char *)NULL);
return ((u_char *) NULL);
}
bzero((char *)curp + nread, need);
bzero((char *) curp + nread, need);
eaddress = address + nread;
return(curp);
return (curp);
}
n = fread((char *)curp + nread, sizeof(u_char),
length == -1 ? need : MIN(length, need), stdin);
n = fread((char *) curp + nread, sizeof(u_char),
length == -1 ? need : MIN(length, need), stdin);
if (!n) {
if (ferror(stdin)) {
perror_msg("%s", _argv[-1]);
@@ -441,12 +477,11 @@ get(void)
length -= n;
}
if (!(need -= n)) {
if (vflag == ALL || vflag == FIRST ||
bcmp(curp, savp, blocksize)) {
if (vflag == ALL || vflag == FIRST || bcmp(curp, savp, blocksize)) {
if (vflag == DUP || vflag == FIRST) {
vflag = WAIT;
}
return(curp);
return (curp);
}
if (vflag == WAIT) {
printf("*\n");
@@ -461,7 +496,7 @@ get(void)
}
}
static void bpad(PR *pr)
static void bpad(PR * pr)
{
register char *p1, *p2;
@@ -473,18 +508,18 @@ static void bpad(PR *pr)
*pr->cchar = 's';
for (p1 = pr->fmt; *p1 != '%'; ++p1);
for (p2 = ++p1; *p1 && index(" -0+#", *p1); ++p1);
while ((*p2++ = *p1++) != 0) ;
while ((*p2++ = *p1++) != 0);
}
void conv_c(PR *pr, u_char *p)
void conv_c(PR * pr, u_char * p)
{
char buf[10], *str;
switch(*p) {
switch (*p) {
case '\0':
str = "\\0";
goto strpr;
/* case '\a': */
/* case '\a': */
case '\007':
str = "\\a";
goto strpr;
@@ -511,22 +546,22 @@ void conv_c(PR *pr, u_char *p)
}
if (isprint(*p)) {
*pr->cchar = 'c';
(void)printf(pr->fmt, *p);
(void) printf(pr->fmt, *p);
} else {
sprintf(str = buf, "%03o", (int)*p);
strpr:
sprintf(str = buf, "%03o", (int) *p);
strpr:
*pr->cchar = 's';
printf(pr->fmt, str);
}
}
void conv_u(PR *pr, u_char *p)
void conv_u(PR * pr, u_char * p)
{
static char *list[] = {
"nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
"bs", "ht", "lf", "vt", "ff", "cr", "so", "si",
"bs", "ht", "lf", "vt", "ff", "cr", "so", "si",
"dle", "dcl", "dc2", "dc3", "dc4", "nak", "syn", "etb",
"can", "em", "sub", "esc", "fs", "gs", "rs", "us",
"can", "em", "sub", "esc", "fs", "gs", "rs", "us",
};
/* od used nl, not lf */
@@ -541,118 +576,128 @@ void conv_u(PR *pr, u_char *p)
printf(pr->fmt, *p);
} else {
*pr->cchar = 'x';
printf(pr->fmt, (int)*p);
printf(pr->fmt, (int) *p);
}
}
void display(void)
{
// extern FU *endfu;
/* extern FU *endfu; */
register FS *fs;
register FU *fu;
register PR *pr;
register int cnt;
register u_char *bp;
// off_t saveaddress;
/* off_t saveaddress; */
u_char savech = 0, *savebp;
while ((bp = get()) != NULL) {
for (fs = fshead, savebp = bp, saveaddress = address; fs;
fs = fs->nextfs, bp = savebp, address = saveaddress) {
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
for (fs = fshead, savebp = bp, saveaddress = address; fs;
fs = fs->nextfs, bp = savebp, address = saveaddress) {
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
if (fu->flags & F_IGNORE) {
break;
}
for (cnt = fu->reps; cnt; --cnt) {
for (pr = fu->nextpr; pr; address += pr->bcnt,
bp += pr->bcnt, pr = pr->nextpr) {
if (eaddress && address >= eaddress &&
!(pr->flags&(F_TEXT|F_BPAD))) {
for (pr = fu->nextpr; pr; address += pr->bcnt,
bp += pr->bcnt, pr = pr->nextpr) {
if (eaddress && address >= eaddress &&
!(pr->flags & (F_TEXT | F_BPAD))) {
bpad(pr);
}
if (cnt == 1 && pr->nospace) {
if (cnt == 1 && pr->nospace) {
savech = *pr->nospace;
*pr->nospace = '\0';
}
// PRINT;
switch(pr->flags) {
case F_ADDRESS:
printf(pr->fmt, address);
break;
case F_BPAD:
printf(pr->fmt, "");
break;
case F_C:
conv_c(pr, bp);
break;
case F_CHAR:
printf(pr->fmt, *bp);
break;
case F_DBL: {
double dval;
float fval;
switch(pr->bcnt) {
case 4:
bcopy((char *)bp, (char *)&fval, sizeof(fval));
printf(pr->fmt, fval);
break;
case 8:
bcopy((char *)bp, (char *)&dval, sizeof(dval));
printf(pr->fmt, dval);
break;
}
break;
}
case F_INT: {
int ival;
short sval;
switch(pr->bcnt) {
case 1:
printf(pr->fmt, (int)*bp);
break;
case 2:
bcopy((char *)bp, (char *)&sval, sizeof(sval));
printf(pr->fmt, (int)sval);
break;
case 4:
bcopy((char *)bp, (char *)&ival, sizeof(ival));
printf(pr->fmt, ival);
break;
}
break;
}
case F_P:
printf(pr->fmt, isprint(*bp) ? *bp : '.');
break;
case F_STR:
printf(pr->fmt, (char *)bp);
break;
case F_TEXT:
printf(pr->fmt);
break;
case F_U:
conv_u(pr, bp);
break;
case F_UINT: {
u_int ival;
u_short sval;
switch(pr->bcnt) {
case 1:
printf(pr->fmt, (u_int)*bp);
break;
case 2:
bcopy((char *)bp, (char *)&sval, sizeof(sval));
printf(pr->fmt, (u_int)sval);
break;
case 4:
bcopy((char *)bp, (char *)&ival, sizeof(ival));
printf(pr->fmt, ival);
break;
}
break;
}
}
if (cnt == 1 && pr->nospace) {
/* PRINT; */
switch (pr->flags) {
case F_ADDRESS:
printf(pr->fmt, address);
break;
case F_BPAD:
printf(pr->fmt, "");
break;
case F_C:
conv_c(pr, bp);
break;
case F_CHAR:
printf(pr->fmt, *bp);
break;
case F_DBL:{
double dval;
float fval;
switch (pr->bcnt) {
case 4:
bcopy((char *) bp, (char *) &fval,
sizeof(fval));
printf(pr->fmt, fval);
break;
case 8:
bcopy((char *) bp, (char *) &dval,
sizeof(dval));
printf(pr->fmt, dval);
break;
}
break;
}
case F_INT:{
int ival;
short sval;
switch (pr->bcnt) {
case 1:
printf(pr->fmt, (int) *bp);
break;
case 2:
bcopy((char *) bp, (char *) &sval,
sizeof(sval));
printf(pr->fmt, (int) sval);
break;
case 4:
bcopy((char *) bp, (char *) &ival,
sizeof(ival));
printf(pr->fmt, ival);
break;
}
break;
}
case F_P:
printf(pr->fmt, isprint(*bp) ? *bp : '.');
break;
case F_STR:
printf(pr->fmt, (char *) bp);
break;
case F_TEXT:
printf(pr->fmt);
break;
case F_U:
conv_u(pr, bp);
break;
case F_UINT:{
u_int ival;
u_short sval;
switch (pr->bcnt) {
case 1:
printf(pr->fmt, (u_int) * bp);
break;
case 2:
bcopy((char *) bp, (char *) &sval,
sizeof(sval));
printf(pr->fmt, (u_int) sval);
break;
case 4:
bcopy((char *) bp, (char *) &ival,
sizeof(ival));
printf(pr->fmt, ival);
break;
}
break;
}
}
if (cnt == 1 && pr->nospace) {
*pr->nospace = savech;
}
}
@@ -672,12 +717,12 @@ void display(void)
eaddress = address;
}
for (pr = endfu->nextpr; pr; pr = pr->nextpr) {
switch(pr->flags) {
switch (pr->flags) {
case F_ADDRESS:
(void)printf(pr->fmt, eaddress);
(void) printf(pr->fmt, eaddress);
break;
case F_TEXT:
(void)printf(pr->fmt);
(void) printf(pr->fmt);
break;
}
}
@@ -703,7 +748,7 @@ int dump(char **argv)
next(argv);
display();
return(exitval);
return (exitval);
}
void add(char *fmt)
@@ -718,7 +763,7 @@ void add(char *fmt)
/* start new linked list of format units */
/* NOSTRICT */
tfs = (FS *)xmalloc(sizeof(FS));
tfs = (FS *) xmalloc(sizeof(FS));
if (!fshead) {
fshead = tfs;
} else {
@@ -737,7 +782,7 @@ void add(char *fmt)
/* allocate a new format unit and link it in */
/* NOSTRICT */
tfu = (FU *)xmalloc(sizeof(FU));
tfu = (FU *) xmalloc(sizeof(FU));
*nextfu = tfu;
nextfu = &tfu->nextfu;
tfu->reps = 1;
@@ -785,7 +830,7 @@ void add(char *fmt)
}
strncpy(tfu->fmt, savep, p - savep);
tfu->fmt[p - savep] = '\0';
// escape(tfu->fmt);
/* escape(tfu->fmt); */
p1 = tfu->fmt;
@@ -796,9 +841,9 @@ void add(char *fmt)
break;
}
if (*p1 == '\\') {
switch(*++p1) {
switch (*++p1) {
case 'a':
/* *p2 = '\a'; */
/* *p2 = '\a'; */
*p2 = '\007';
break;
case 'b':
@@ -829,6 +874,7 @@ void add(char *fmt)
p++;
}
}
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
@@ -841,11 +887,7 @@ void add(char *fmt)
* 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.
*
+3 -6
View File
@@ -36,7 +36,7 @@ static const int KDGKBTYPE = 0x4B33; /* get keyboard type */
static const int KB_84 = 0x01;
static const int KB_101 = 0x02; /* this is what we always answer */
int is_a_console(int fd)
static int is_a_console(int fd)
{
char arg;
@@ -82,17 +82,14 @@ static int open_a_console(char *fnam)
* if tty_name is non-NULL, try this one instead.
*/
int get_console_fd(char *tty_name)
int get_console_fd(void)
{
int fd;
if (tty_name) {
if (-1 == (fd = open_a_console(tty_name)))
if (-1 == (fd = open_a_console("/dev/console")))
return -1;
else
return fd;
}
fd = open_a_console(CURRENT_TTY);
if (fd >= 0)
return fd;
+69 -2
View File
@@ -4,7 +4,7 @@
*
* Heavily modified by Manuel Novoa III Mar 12, 2001
*
* Version: $Id: inet_common.c,v 1.1 2001/11/10 12:18:42 andersen Exp $
* Version: $Id: inet_common.c,v 1.3 2002/07/03 11:46:36 andersen Exp $
*
*/
@@ -16,6 +16,11 @@
#include <unistd.h>
#include "libbb.h"
#ifdef DEBUG
#include <resolv.h>
#endif
const char bb_INET_default[]="default";
int INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst)
@@ -103,7 +108,7 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
/* Grmpf. -FvK */
if (s_in->sin_family != AF_INET) {
#ifdef DEBUG
fprintf(stderr, _("rresolve: unsupport address family %d !\n"), s_in->sin_family);
fprintf(stderr, "rresolve: unsupport address family %d !\n", s_in->sin_family);
#endif
errno = EAFNOSUPPORT;
return (-1);
@@ -172,3 +177,65 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
return (0);
}
#if CONFIG_FEATURE_IPV6
int INET6_resolve(char *name, struct sockaddr_in6 *sin6)
{
struct addrinfo req, *ai;
int s;
memset (&req, '\0', sizeof req);
req.ai_family = AF_INET6;
if ((s = getaddrinfo(name, NULL, &req, &ai))) {
fprintf(stderr, "getaddrinfo: %s: %d\n", name, s);
return -1;
}
memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6));
freeaddrinfo(ai);
return (0);
}
#ifndef IN6_IS_ADDR_UNSPECIFIED
#define IN6_IS_ADDR_UNSPECIFIED(a) \
(((__u32 *) (a))[0] == 0 && ((__u32 *) (a))[1] == 0 && \
((__u32 *) (a))[2] == 0 && ((__u32 *) (a))[3] == 0)
#endif
int INET6_rresolve(char *name, size_t len, struct sockaddr_in6 *sin6, int numeric)
{
int s;
/* Grmpf. -FvK */
if (sin6->sin6_family != AF_INET6) {
#ifdef DEBUG
fprintf(stderr, _("rresolve: unsupport address family %d !\n"),
sin6->sin6_family);
#endif
errno = EAFNOSUPPORT;
return (-1);
}
if (numeric & 0x7FFF) {
inet_ntop(AF_INET6, &sin6->sin6_addr, name, len);
return (0);
}
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
if (numeric & 0x8000)
strcpy(name, "default");
else
strcpy(name, "*");
return (0);
}
if ((s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6),
name, len , NULL, 0, 0))) {
fputs("getnameinfo failed\n", stderr);
return -1;
}
return (0);
}
#endif /* CONFIG_FEATURE_IPV6 */
+1289 -1211
View File
File diff suppressed because it is too large. Load diff
+19 -1
View File
@@ -9,8 +9,26 @@
#include <unistd.h>
#if __GNU_LIBRARY__ < 5
#if ! defined __dietlibc__ && __GNU_LIBRARY__ < 5
/*
* Some systems already have updwtmp(). Some don't... This is
* the updwtmp() implementation from uClibc, Copyright 2002 by
* Erik Andersen <andersee@debian.org>
*/
extern void updwtmp(const char *wtmp_file, const struct utmp *lutmp)
{
int fd;
fd = open(wtmp_file, O_APPEND | O_WRONLY, 0);
if (fd >= 0) {
if (lockf(fd, F_LOCK, 0)==0) {
write(fd, (const char *) lutmp, sizeof(struct utmp));
lockf(fd, F_ULOCK, 0);
close(fd);
}
}
}
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
+27 -30
View File
@@ -3,6 +3,10 @@
* Mini make_directory implementation for busybox
*
* Copyright (C) 2001 Matt Kraai.
*
* Rewriten in 2002
* Copyright (C) 2002 Glenn McGrath
* Copyright (C) 2002 Vladimir N. Oleynik
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +26,7 @@
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -35,37 +40,29 @@
int make_directory (char *path, long mode, int flags)
{
if (!(flags & FILEUTILS_RECUR)) {
if (mkdir (path, 0777) < 0) {
perror_msg ("Cannot create directory `%s'", path);
return -1;
}
int ret;
if (mode != -1 && chmod (path, mode) < 0) {
perror_msg ("Cannot set permissions of directory `%s'", path);
return -1;
}
} else {
struct stat st;
if (stat (path, &st) < 0 && errno == ENOENT) {
int status;
char *buf, *parent;
mode_t mask;
mask = umask (0);
umask (mask);
buf = xstrdup (path);
parent = dirname (buf);
status = make_directory (parent, (0777 & ~mask) | 0300,
FILEUTILS_RECUR);
free (buf);
if (status < 0 || make_directory (path, mode, 0) < 0)
return -1;
/* Calling apps probably should use 0777 instead of -1
* then we dont need this condition
*/
if (mode == -1) {
mode = 0777;
}
if (flags == FILEUTILS_RECUR) {
char *pp = strrchr(path, '/');
if (pp) {
*pp = '\0';
make_directory(path, mode, flags);
*pp = '/';
}
}
return 0;
ret = mkdir(path, mode);
if (ret == -1) {
if (errno == EEXIST) {
ret = 0;
} else {
perror_msg("Cannot create directory %s", path);
}
}
return(ret);
}
+36
View File
@@ -66,3 +66,39 @@
#ifdef L_can_not_create_raw_socket
const char * const can_not_create_raw_socket = "can`t create raw socket";
#endif
#ifdef L_passwd_file
#define PASSWD_FILE "/etc/passwd"
const char * const passwd_file = PASSWD_FILE;
#endif
#ifdef L_shadow_file
#define SHADOW_FILE "/etc/shadow"
const char * const shadow_file = SHADOW_FILE;
#endif
#ifdef L_group_file
#define GROUP_FILE "/etc/group"
const char * const group_file = GROUP_FILE;
#endif
#ifdef L_gshadow_file
#define GSHADOW_FILE "/etc/gshadow"
const char * const gshadow_file = GSHADOW_FILE;
#endif
#ifdef L_nologin_file
#define NOLOGIN_FILE "/etc/nologin"
const char * const nologin_file = NOLOGIN_FILE;
#endif
#ifdef L_securetty_file
#define SECURETTY_FILE "/etc/securetty"
const char * const securetty_file = SECURETTY_FILE;
#endif
#ifdef L_motd_file
#define MOTD_FILE "/etc/motd"
const char * const motd_file = MOTD_FILE;
#endif
+2 -2
View File
@@ -21,9 +21,9 @@
#include <stdio.h>
#include <string.h>
#include "pwd.h"
#include "grp.h"
#include "libbb.h"
#include "pwd_.h"
#include "grp_.h"
/* gets a groupname given a gid */
+2 -2
View File
@@ -21,9 +21,9 @@
#include <stdio.h>
#include <string.h>
#include "pwd.h"
#include "grp.h"
#include "libbb.h"
#include "pwd_.h"
#include "grp_.h"
/* returns a gid given a group name */
+2 -2
View File
@@ -21,9 +21,9 @@
#include <stdio.h>
#include <string.h>
#include "pwd.h"
#include "grp.h"
#include "libbb.h"
#include "pwd_.h"
#include "grp_.h"
/* returns a uid given a username */
+2 -2
View File
@@ -21,9 +21,9 @@
#include <stdio.h>
#include <string.h>
#include "pwd.h"
#include "grp.h"
#include "libbb.h"
#include "pwd_.h"
#include "grp_.h"
+2 -2
View File
@@ -21,9 +21,9 @@
#include <stdio.h>
#include <string.h>
#include "pwd.h"
#include "grp.h"
#include "libbb.h"
#include "pwd_.h"
#include "grp_.h"
+246
View File
@@ -0,0 +1,246 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright 1989 - 1994, Julianne Frances Haugh <jockgrrl@austin.rr.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* This version of obscure.c contains modifications to support "cracklib"
* by Alec Muffet (alec.muffett@uk.sun.com). You must obtain the Cracklib
* library source code for this function to operate.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "libbb.h"
/*
* can't be a palindrome - like `R A D A R' or `M A D A M'
*/
static int palindrome(const char *old, const char *newval)
{
int i, j;
i = strlen(newval);
for (j = 0; j < i; j++)
if (newval[i - j - 1] != newval[j])
return 0;
return 1;
}
/*
* more than half of the characters are different ones.
*/
static int similiar(const char *old, const char *newval)
{
int i, j;
for (i = j = 0; newval[i] && old[i]; i++)
if (strchr(newval, old[i]))
j++;
if (i >= j * 2)
return 0;
return 1;
}
/*
* a nice mix of characters.
*/
static int simple(const char *old, const char *newval)
{
int digits = 0;
int uppers = 0;
int lowers = 0;
int others = 0;
int size;
int i;
for (i = 0; newval[i]; i++) {
if (isdigit(newval[i]))
digits++;
else if (isupper(newval[i]))
uppers++;
else if (islower(newval[i]))
lowers++;
else
others++;
}
/*
* The scam is this - a password of only one character type
* must be 8 letters long. Two types, 7, and so on.
*/
size = 9;
if (digits)
size--;
if (uppers)
size--;
if (lowers)
size--;
if (others)
size--;
if (size <= i)
return 0;
return 1;
}
static char *str_lower(char *string)
{
char *cp;
for (cp = string; *cp; cp++)
*cp = tolower(*cp);
return string;
}
static char *password_check(const char *old, const char *newval, const struct passwd *pwdp)
{
char *msg = NULL;
char *oldmono, *newmono, *wrapped;
if (strcmp(newval, old) == 0)
return "no change";
newmono = str_lower(xstrdup(newval));
oldmono = str_lower(xstrdup(old));
wrapped = (char *) xmalloc(strlen(oldmono) * 2 + 1);
strcpy(wrapped, oldmono);
strcat(wrapped, oldmono);
if (palindrome(oldmono, newmono))
msg = "a palindrome";
if (!msg && strcmp(oldmono, newmono) == 0)
msg = "case changes only";
if (!msg && similiar(oldmono, newmono))
msg = "too similiar";
if (!msg && simple(old, newval))
msg = "too simple";
if (!msg && strstr(wrapped, newmono))
msg = "rotated";
bzero(newmono, strlen(newmono));
bzero(oldmono, strlen(oldmono));
bzero(wrapped, strlen(wrapped));
free(newmono);
free(oldmono);
free(wrapped);
return msg;
}
static char *obscure_msg(const char *old, const char *newval, const struct passwd *pwdp)
{
int maxlen, oldlen, newlen;
char *new1, *old1, *msg;
oldlen = strlen(old);
newlen = strlen(newval);
#if 0 /* why not check the password when set for the first time? --marekm */
if (old[0] == '\0')
/* return (1); */
return NULL;
#endif
if (newlen < 5)
return "too short";
/*
* Remaining checks are optional.
*/
/* Not for us -- Sean
*if (!getdef_bool("OBSCURE_CHECKS_ENAB"))
* return NULL;
*/
msg = password_check(old, newval, pwdp);
if (msg)
return msg;
/* The traditional crypt() truncates passwords to 8 chars. It is
possible to circumvent the above checks by choosing an easy
8-char password and adding some random characters to it...
Example: "password$%^&*123". So check it again, this time
truncated to the maximum length. Idea from npasswd. --marekm */
maxlen = 8;
if (oldlen <= maxlen && newlen <= maxlen)
return NULL;
new1 = (char *) xstrdup(newval);
old1 = (char *) xstrdup(old);
if (newlen > maxlen)
new1[maxlen] = '\0';
if (oldlen > maxlen)
old1[maxlen] = '\0';
msg = password_check(old1, new1, pwdp);
bzero(new1, newlen);
bzero(old1, oldlen);
free(new1);
free(old1);
return msg;
}
/*
* Obscure - see if password is obscure enough.
*
* The programmer is encouraged to add as much complexity to this
* routine as desired. Included are some of my favorite ways to
* check passwords.
*/
extern int obscure(const char *old, const char *newval, const struct passwd *pwdp)
{
char *msg = obscure_msg(old, newval, pwdp);
/* if (msg) { */
if (msg != NULL) {
printf("Bad password: %s.\n", msg);
/* return 0; */
return 1;
}
/* return 1; */
return 0;
}
+48
View File
@@ -0,0 +1,48 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routine.
*
* Copyright (C) 1999-2002 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <string.h>
#include <crypt.h>
#include "libbb.h"
extern char *pw_encrypt(const char *clear, const char *salt)
{
static char cipher[128];
char *cp;
#ifdef CONFIG_FEATURE_SHA1_PASSWORDS
if (strncmp(salt, "$2$", 3) == 0) {
return sha1_crypt(clear);
}
#endif
cp = (char *) crypt(clear, salt);
/* if crypt (a nonstandard crypt) returns a string too large,
truncate it so we don't overrun buffers and hope there is
enough security in what's left */
if (strlen(cp) > sizeof(cipher)-1) {
cp[sizeof(cipher)-1] = 0;
}
strcpy(cipher, cp);
return cipher;
}
+74
View File
@@ -0,0 +1,74 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright 1989 - 1994, Julianne Frances Haugh <jockgrrl@austin.rr.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <time.h>
#include <sys/types.h>
#include "libbb.h"
#include "shadow_.h"
/*
* pwd_to_spwd - create entries for new spwd structure
*
* pwd_to_spwd() creates a new (struct spwd) containing the
* information in the pointed-to (struct passwd).
*/
#define DAY (24L*3600L)
#define WEEK (7*DAY)
#define SCALE DAY
struct spwd *pwd_to_spwd(const struct passwd *pw)
{
static struct spwd sp;
/*
* Nice, easy parts first. The name and passwd map directly
* from the old password structure to the new one.
*/
sp.sp_namp = pw->pw_name;
sp.sp_pwdp = pw->pw_passwd;
/*
* Defaults used if there is no pw_age information.
*/
sp.sp_min = 0;
sp.sp_max = (10000L * DAY) / SCALE;
sp.sp_lstchg = time((time_t *) 0) / SCALE;
/*
* These fields have no corresponding information in the password
* file. They are set to uninitialized values.
*/
sp.sp_warn = -1;
sp.sp_expire = -1;
sp.sp_inact = -1;
sp.sp_flag = -1;
return &sp;
}
+57
View File
@@ -0,0 +1,57 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright 1989 - 1991, Julianne Frances Haugh <jockgrrl@austin.rr.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include <ctype.h>
#include "libbb.h"
/* Return 1 if SHELL is a restricted shell (one not returned by
getusershell), else 0, meaning it is a standard shell. */
int restricted_shell ( const char *shell )
{
char *line;
setusershell ( );
while (( line = getusershell ( ))) {
if (( *line != '#' ) && ( strcmp ( line, shell ) == 0 ))
break;
}
endusershell ( );
return line ? 0 : 1;
}
+80
View File
@@ -0,0 +1,80 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright 1989 - 1991, Julianne Frances Haugh <jockgrrl@austin.rr.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include <ctype.h>
#include "libbb.h"
/* Run SHELL, or DEFAULT_SHELL if SHELL is empty.
If COMMAND is nonzero, pass it to the shell with the -c option.
If ADDITIONAL_ARGS is nonzero, pass it to the shell as more
arguments. */
void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args )
{
const char **args;
int argno = 1;
int additional_args_cnt = 0;
for ( args = additional_args; args && *args; args++ )
additional_args_cnt++;
if ( additional_args )
args = (const char **) xmalloc (sizeof (char *) * ( 4 + additional_args_cnt ));
else
args = (const char **) xmalloc (sizeof (char *) * 4 );
args [0] = get_last_path_component ( xstrdup ( shell ));
if ( loginshell ) {
char *args0;
bb_asprintf ( &args0, "-%s", args [0] );
args [0] = args0;
}
if ( command ) {
args [argno++] = "-c";
args [argno++] = command;
}
if ( additional_args ) {
for ( ; *additional_args; ++additional_args )
args [argno++] = *additional_args;
}
args [argno] = 0;
execv ( shell, (char **) args );
perror_msg_and_die ( "cannot run %s", shell );
}
+93
View File
@@ -0,0 +1,93 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright 1989 - 1991, Julianne Frances Haugh <jockgrrl@austin.rr.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include <ctype.h>
#include "libbb.h"
#define DEFAULT_LOGIN_PATH "/bin:/usr/bin"
#define DEFAULT_ROOT_LOGIN_PATH "/usr/sbin:/bin:/usr/bin:/sbin"
static void xsetenv ( const char *key, const char *value )
{
if ( setenv ( key, value, 1 ))
error_msg_and_die ( "out of memory" );
}
void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw )
{
if ( loginshell ) {
char *term;
/* Change the current working directory to be the home directory
* of the user. It is a fatal error for this process to be unable
* to change to that directory. There is no "default" home
* directory.
* Some systems default to HOME=/
*/
if ( chdir ( pw-> pw_dir )) {
if ( chdir ( "/" )) {
syslog ( LOG_WARNING, "unable to cd to %s' for user %s'\n", pw-> pw_dir, pw-> pw_name );
error_msg_and_die ( "cannot cd to home directory or /" );
}
fputs ( "warning: cannot change to home directory\n", stderr );
}
/* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH.
Unset all other environment variables. */
term = getenv ("TERM");
clearenv ( );
if ( term )
xsetenv ( "TERM", term );
xsetenv ( "HOME", pw-> pw_dir );
xsetenv ( "SHELL", shell );
xsetenv ( "USER", pw-> pw_name );
xsetenv ( "LOGNAME", pw-> pw_name );
xsetenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ));
}
else if ( changeenv ) {
/* Set HOME, SHELL, and if not becoming a super-user,
USER and LOGNAME. */
xsetenv ( "HOME", pw-> pw_dir );
xsetenv ( "SHELL", shell );
if ( pw-> pw_uid ) {
xsetenv ( "USER", pw-> pw_name );
xsetenv ( "LOGNAME", pw-> pw_name );
}
}
}
Loaded 100 of 176 files, more files were not shown because too many files have changed in this diff. Show more