Compare commits

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

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

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

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

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

    --w
    vodz
2002-09-30 20:39:56 +00:00
Eric Andersen a6f6e06107 Fix dependancy so we rebuild busybox.o, usage.o and busybox.o
whenever the config changes.
 -Erik
2002-09-30 20:39:12 +00:00
Eric Andersen ad082987d0 Use %m, not strerror, and strerror(err) was broken anyways and should have been
strerror(errno).  Problem noted by Alexey V. Neyman <alex.neyman@auriga.ru>
2002-09-30 20:20:20 +00:00
Eric Andersen d9d47c3078 Patch from Konstantin Isakov <ikm@pisem.net>:
In most cases, dirname returns the same argument it was given, so this code
    works nice, but there's one special case: when the name contains no
    dirname, it returns "." (stored statically in the body of itself), and we
    get a segfault in attempt to free() it.
This patch fixes this problem.
2002-09-30 20:14:57 +00:00
Eric Andersen aa1d6ccbfb Don't even try to run ash on uClinux. It won't work.
-Erik
2002-09-30 20:12:32 +00:00
Eric Andersen 6a9799020b Set the close-on-exec flag, just to be saf 2002-09-30 20:08:53 +00:00
Eric Andersen e4d2a43951 Doh. We divide microseconds by 60? 2002-09-30 19:37:48 +00:00
Glenn L McGrath 5c99581880 Save status so we know if to delete compressed file 2002-09-30 05:30:29 +00:00
Glenn L McGrath 924f93e848 make_directory() will fail instantly so we dont need to test for failure here 2002-09-28 08:32:14 +00:00
Glenn L McGrath 891ee641cb Fail straight away rather than recursively printing error messages :) 2002-09-28 08:30:47 +00:00
Glenn L McGrath 8132e933e6 Fix for using '-' as the filename when reading from stdin 2002-09-28 02:06:39 +00:00
Eric Andersen 92052e3945 Bug fix from Nitin Gupta <gupta@equator.com> 2002-09-27 23:34:53 +00:00
Glenn L McGrath 2e41d0cb77 Fix compress support and prevent a segfault 2002-09-27 06:46:02 +00:00
Glenn L McGrath a47a3eada6 Fix simple define problem 2002-09-26 16:01:21 +00:00
Eric Andersen 6f2ebcaa01 Avoid calling exit() from within fork/vfork'ed processes.
-Erik
2002-09-26 13:59:40 +00:00
Eric Andersen a920871c3a Ignoring SIGCHLD causes a race leading to the occasional hang of init
when init will wait() on itself in waitfor() when the child exits before
init is scheduled to run.  Letting init hang is very seriously bad.
 -Erik
2002-09-25 15:08:40 +00:00
Glenn L McGrath 5a66b640f9 Reverse some minor changes that got caught up in my big unarchive patch 2002-09-25 06:08:19 +00:00
Glenn L McGrath 69eab26401 Remove files made obsolete by new unarchiving code 2002-09-25 03:04:03 +00:00
Glenn L McGrath 7ca04f328e New common unarchive code. 2002-09-25 02:47:48 +00:00
Eric Andersen ecfa290cfd Fixup largefile settings
-Erik
2002-09-22 12:09:44 +00:00
Glenn L McGrath b3f7261ffe Fix error messages conditions, and make them the same as GNU mkdir. 2002-09-22 02:12:30 +00:00
Eric Andersen 3a1d8377ab don't leak FILEs 2002-09-20 07:33:18 +00:00
Eric Andersen 19feada06f update the noise a tiny bit 2002-09-18 20:52:26 +00:00
Eric Andersen 7695b7b5f4 Update webpage 2002-09-18 20:48:20 +00:00
145 changed files with 9886 additions and 5923 deletions

No files matched your search

+2 -1
View File
@@ -55,7 +55,8 @@ Glenn McGrath <bug1@optushome.com.au>
ar, dpkg, dpkg-deb
Vladimir Oleynik <dzo@simtreas.ru>
cmdedit; ports: ash, stty, traceroute; locale, various fixes
cmdedit; ports: ash, crond, stty, traceroute, telnetd, top;
locale, various fixes
and irreconcilable critic of everything not perfect.
Bruce Perens <bruce@pixar.com>
+2 -2
View File
@@ -22,7 +22,7 @@ include $(TOPDIR).config
include $(TOPDIR)Rules.mak
SUBDIRS:=applets archival archival/libunarchive console-tools \
editors fileutils findutils init miscutils modutils networking \
procps loginutils shell shellutils sysklogd \
networking/udhcp procps loginutils shell shellutils sysklogd \
textutils util-linux libbb libpwdgrp
all: do-it-all
@@ -216,7 +216,7 @@ clean:
- rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
docs/busybox.net/BusyBox.html
- rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
docs/busybox.pdf docs/busybox.net/busybox.html \
docs/busybox.pdf docs/busybox.pod docs/busybox.net/busybox.html \
docs/busybox _install pod2htm* *.gdb *.elf *~ core
- rm -f busybox busybox.links libbb/loop.h .config.old .hdepend
- rm -f scripts/split-include scripts/mkdep .*config.log
+2 -2
View File
@@ -162,7 +162,7 @@ OPTIMIZATIONS:=$(OPTIMIZATION) -fomit-frame-pointer
ifeq ($(strip $(DOLFS)),true)
# For large file summit support
CFLAGS+=-D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64
CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
endif
ifeq ($(strip $(DODMALLOC)),true)
# For testing mem leaks with dmalloc
@@ -190,7 +190,7 @@ ifeq ($(strip $(DOSTATIC)),true)
LDFLAGS += --static
endif
ifndef $(PREFIX)
ifeq ($(strip $(PREFIX)),)
PREFIX:=`pwd`/_install
endif
-12
View File
@@ -3,11 +3,6 @@ is listed here doesn't mean that it is going to be added to busybox,
or that doing so is even a good idea. It just means that I _might_ get
around to it some time. If you have any good ideas, please let me know.
* login/sulogin/passwd/etc are part of tinylogin. We are in the
process of merging these applications into busybox, since the
new build system allows us to add Libraries (i.e. libcrypt),
when certain applets are enabled.
* We _were_ going to split networking apps into a new package called
netkit-tiny. Per discussions on the mailing list, this isn't going
to happen. False alarm. Sorry about the confusion.
@@ -18,10 +13,7 @@ around to it some time. If you have any good ideas, please let me know.
Possible apps to include some time:
* hwclock
* group/commonize strings, remove dups (for i18n, l10n)
* login/sulogin/passwd/etc are part of tinylogin. These are
being merged into busybox as time allows.
-----------
@@ -48,10 +40,6 @@ libraries such as uClibc.
Compile with debugging on, run 'nm --size-sort ./busybox'
and then start with the biggest things and make them smaller...
-----------------------
du.c probably ought to have an -x switch like GNU du does...
-----------------------
xargs could use a -l option
+4
View File
@@ -25,8 +25,12 @@ endif
APPLET_SRC:=applets.c busybox.c usage.c
APPLET_OBJ:= $(patsubst %.c,$(APPLETS_DIR)%.o, $(APPLET_SRC))
libraries-y+=$(APPLETS_DIR)$(APPLETS_AR)
$(APPLET_OBJ): $(TOPDIR).config
$(APPLETS_DIR)$(APPLETS_AR): $(APPLET_OBJ)
$(AR) -ro $@ $(APPLET_OBJ)
+93 -31
View File
@@ -21,41 +21,101 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* There is no signle standard to adhere to so ar may not portable
* between different systems
* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
*/
#include <sys/types.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <utime.h>
#include <unistd.h>
#include <getopt.h>
#include "unarchive.h"
#include "busybox.h"
static void header_verbose_list_ar(const file_header_t *file_header)
{
const char *mode = mode_string(file_header->mode);
char *mtime;
mtime = ctime(&file_header->mtime);
mtime[16] = ' ';
memmove(&mtime[17], &mtime[20], 4);
mtime[21] = '\0';
printf("%s %d/%d%7d %s %s\n", &mode[1], file_header->uid, file_header->gid, (int) file_header->size, &mtime[4], file_header->name);
}
#if defined CONFIG_TAR | defined CONFIG_DPKG_DEB | defined CONFIG_CPIO
/* This is simpler than data_extract_all */
static void data_extract_regular_file(archive_handle_t *archive_handle)
{
file_header_t *file_header;
int dst_fd;
file_header = archive_handle->file_header;
dst_fd = xopen(file_header->name, O_WRONLY | O_CREAT);
copy_file_chunk_fd(archive_handle->src_fd, dst_fd, file_header->size);
close(dst_fd);
chmod(file_header->name, file_header->mode);
chown(file_header->name, file_header->uid, file_header->gid);
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
struct utimbuf t;
t.actime = t.modtime = file_header->mtime;
utime(file_header->name, &t);
}
return;
}
#endif
extern int ar_main(int argc, char **argv)
{
FILE *src_stream = NULL;
char **extract_names = NULL;
char ar_magic[8];
int extract_function = extract_unconditional;
archive_handle_t *archive_handle;
int opt;
int num_of_entries = 0;
extern off_t archive_offset;
while ((opt = getopt(argc, argv, "ovtpx")) != -1) {
#ifndef CONFIG_DPKG_DEB
char magic[8];
#endif
#if defined CONFIG_TAR | defined CONFIG_DPKG_DEB | defined CONFIG_CPIO
archive_handle = init_handle();
#else
archive_handle = xcalloc(1, sizeof(archive_handle_t));
archive_handle->filter = filter_accept_all;
archive_handle->action_data = data_skip;
archive_handle->action_header = header_skip;
archive_handle->file_header =xmalloc(sizeof(file_header_t));
#endif
while ((opt = getopt(argc, argv, "covtpxX")) != -1) {
switch (opt) {
case 'o':
extract_function |= extract_preserve_date;
case 'p': /* print */
archive_handle->action_data = data_extract_to_stdout;
break;
case 'v':
extract_function |= extract_verbose_list;
case 't': /* list contents */
archive_handle->action_header = header_list;
break;
case 't':
extract_function |= extract_list;
case 'X':
archive_handle->action_header = header_verbose_list_ar;
case 'x': /* extract */
#if defined CONFIG_TAR | defined CONFIG_DPKG_DEB | defined CONFIG_CPIO
archive_handle->action_data = data_extract_all;
#else
archive_handle->action_data = data_extract_regular_file;
#endif
break;
case 'p':
extract_function |= extract_to_stdout;
/* Modifiers */
case 'o': /* preserve original dates */
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
break;
case 'x':
extract_function |= extract_all_to_fs;
case 'v': /* verbose */
archive_handle->action_header = header_verbose_list_ar;
break;
default:
show_usage();
@@ -67,24 +127,26 @@ extern int ar_main(int argc, char **argv)
show_usage();
}
src_stream = xfopen(argv[optind++], "r");
archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
/* check ar magic */
fread(ar_magic, 1, 8, src_stream);
archive_offset = 8;
if (strncmp(ar_magic,"!<arch>",7) != 0) {
error_msg_and_die("invalid magic");
}
/* Create a list of files to extract */
/* TODO: This is the same as in tar, seperate function ? */
while (optind < argc) {
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
extract_names[num_of_entries] = xstrdup(argv[optind]);
num_of_entries++;
extract_names[num_of_entries] = NULL;
archive_handle->filter = filter_accept_list;
archive_handle->accept = add_to_list(archive_handle->accept, argv[optind]);
optind++;
}
unarchive(src_stream, stdout, &get_header_ar, extract_function, "./", extract_names, NULL);
#if defined CONFIG_DPKG_DEB
unpack_ar_archive(archive_handle);
#else
xread_all(archive_handle->src_fd, magic, 7);
if (strncmp(magic, "!<arch>", 7) != 0) {
error_msg_and_die("Invalid ar magic");
}
archive_handle->offset += 7;
while (get_header_ar(archive_handle) == EXIT_SUCCESS);
#endif
return EXIT_SUCCESS;
}
+6
View File
@@ -7,10 +7,16 @@ mainmenu_option next_comment
comment 'Archival Utilities'
bool 'ar' CONFIG_AR
if [ "$CONFIG_AR" = "y" ] ; then
bool ' Enable support for long filenames (not need for debs)' CONFIG_FEATURE_AR_LONG_FILENAMES
fi
bool 'bunzip2' CONFIG_BUNZIP2
bool 'cpio' CONFIG_CPIO
bool 'dpkg' CONFIG_DPKG
bool 'dpkg_deb' CONFIG_DPKG_DEB
if [ "$CONFIG_DPKG_DEB" = "y" ] ; then
bool ' -x support only' CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
fi
bool 'gunzip' CONFIG_GUNZIP
bool 'gzip' CONFIG_GZIP
bool 'rpm2cpio' CONFIG_RPM2CPIO
+182 -38
View File
@@ -31,66 +31,210 @@
#include "unarchive.h"
#include "busybox.h"
typedef struct hardlinks_s {
file_header_t *entry;
int inode;
struct hardlinks_s *next;
} hardlinks_t;
extern int cpio_main(int argc, char **argv)
{
FILE *src_stream = stdin;
char **extract_names = NULL;
int extract_function = 0;
int num_of_entries = 0;
int opt = 0;
mode_t oldmask = 0;
archive_handle_t *archive_handle;
int opt;
/* Initialise */
archive_handle = init_handle();
archive_handle->src_fd = fileno(stdin);
archive_handle->action_header = header_list;
while ((opt = getopt(argc, argv, "idmuvtF:")) != -1) {
switch (opt) {
case 'i': // extract
extract_function |= extract_all_to_fs;
case 'i': /* extract */
archive_handle->action_data = data_extract_all;
break;
case 'd': // create _leading_ directories
extract_function |= extract_create_leading_dirs;
oldmask = umask(077); /* Make make_directory act like GNU cpio */
case 'd': /* create _leading_ directories */
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
break;
case 'm': // preserve modification time
extract_function |= extract_preserve_date;
case 'm': /* preserve modification time */
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
break;
case 'v': // verbosly list files
extract_function |= extract_verbose_list;
case 'v': /* verbosly list files */
archive_handle->action_header = header_verbose_list;
break;
case 'u': // unconditional
extract_function |= extract_unconditional;
case 'u': /* unconditional */
archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
break;
case 't': // list files
extract_function |= extract_list;
case 't': /* list files */
archive_handle->action_header = header_list;
break;
case 'F':
src_stream = xfopen(optarg, "r");
archive_handle->src_fd = xopen(optarg, O_RDONLY);
break;
default:
show_usage();
}
}
if ((extract_function & extract_all_to_fs) && (extract_function & extract_list)) {
extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/
}
if ((extract_function & extract_all_to_fs) && (extract_function & extract_verbose_list)) {
/* The meaning of v changes on extract */
extract_function ^= extract_verbose_list;
extract_function |= extract_list;
}
while (optind < argc) {
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
extract_names[num_of_entries] = xstrdup(argv[optind]);
num_of_entries++;
extract_names[num_of_entries] = NULL;
archive_handle->filter = filter_accept_list;
archive_handle->accept = add_to_list(archive_handle->accept, argv[optind]);
optind++;
}
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names, NULL);
if (oldmask) {
umask(oldmask); /* Restore umask if we changed it */
while (1) {
static hardlinks_t *saved_hardlinks = NULL;
static unsigned short pending_hardlinks = 0;
file_header_t *file_header = archive_handle->file_header;
char cpio_header[110];
int namesize;
char dummy[16];
int major, minor, nlink, inode;
char extract_flag;
if (pending_hardlinks) { /* Deal with any pending hardlinks */
hardlinks_t *tmp;
hardlinks_t *oldtmp;
tmp = saved_hardlinks;
oldtmp = NULL;
while (tmp) {
error_msg_and_die("need to fix this\n");
if (tmp->entry->link_name) { /* Found a hardlink ready to be extracted */
file_header = tmp->entry;
if (oldtmp) {
oldtmp->next = tmp->next; /* Remove item from linked list */
} else {
saved_hardlinks = tmp->next;
}
free(tmp);
continue;
}
oldtmp = tmp;
tmp = tmp->next;
}
pending_hardlinks = 0; /* No more pending hardlinks, read next file entry */
}
return EXIT_SUCCESS;
/* There can be padding before archive header */
archive_handle->offset += data_align(archive_handle->src_fd, archive_handle->offset, 4);
if (xread_all_eof(archive_handle->src_fd, cpio_header, 110) == 0) {
return(EXIT_FAILURE);
}
archive_handle->offset += 110;
if (strncmp(&cpio_header[0], "07070", 5) != 0) {
printf("cpio header is %x-%x-%x-%x-%x\n",
cpio_header[0],
cpio_header[1],
cpio_header[2],
cpio_header[3],
cpio_header[4]);
error_msg_and_die("Unsupported cpio format");
}
if ((cpio_header[5] != '1') && (cpio_header[5] != '2')) {
error_msg_and_die("Unsupported cpio format, use newc or crc");
}
sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c",
dummy, &inode, (unsigned int*)&file_header->mode,
(unsigned int*)&file_header->uid, (unsigned int*)&file_header->gid,
&nlink, &file_header->mtime, &file_header->size,
dummy, &major, &minor, &namesize, dummy);
file_header->name = (char *) xmalloc(namesize + 1);
xread(archive_handle->src_fd, file_header->name, namesize); /* Read in filename */
file_header->name[namesize] = '\0';
archive_handle->offset += namesize;
/* Update offset amount and skip padding before file contents */
archive_handle->offset += data_align(archive_handle->src_fd, archive_handle->offset, 4);
if (strcmp(file_header->name, "TRAILER!!!") == 0) {
printf("%d blocks\n", (int) (archive_handle->offset % 512 ? (archive_handle->offset / 512) + 1 : archive_handle->offset / 512)); /* Always round up */
if (saved_hardlinks) { /* Bummer - we still have unresolved hardlinks */
hardlinks_t *tmp = saved_hardlinks;
hardlinks_t *oldtmp = NULL;
while (tmp) {
error_msg("%s not created: cannot resolve hardlink", tmp->entry->name);
oldtmp = tmp;
tmp = tmp->next;
free (oldtmp->entry->name);
free (oldtmp->entry);
free (oldtmp);
}
saved_hardlinks = NULL;
pending_hardlinks = 0;
}
return(EXIT_FAILURE);
}
if (S_ISLNK(file_header->mode)) {
file_header->link_name = (char *) xmalloc(file_header->size + 1);
xread(archive_handle->src_fd, file_header->link_name, file_header->size);
file_header->link_name[file_header->size] = '\0';
archive_handle->offset += file_header->size;
file_header->size = 0; /* Stop possible seeks in future */
}
if (nlink > 1 && !S_ISDIR(file_header->mode)) {
if (file_header->size == 0) { /* Put file on a linked list for later */
hardlinks_t *new = xmalloc(sizeof(hardlinks_t));
new->next = saved_hardlinks;
new->inode = inode;
new->entry = file_header;
saved_hardlinks = new;
continue;
} else { /* Found the file with data in */
hardlinks_t *tmp = saved_hardlinks;
pending_hardlinks = 1;
while (tmp) {
if (tmp->inode == inode) {
tmp->entry->link_name = xstrdup(file_header->name);
nlink--;
}
tmp = tmp->next;
}
if (nlink > 1) {
error_msg("error resolving hardlink: did you create the archive with GNU cpio 2.0-2.2?");
}
}
}
file_header->device = (major << 8) | minor;
extract_flag = FALSE;
if (archive_handle->filter(archive_handle->accept, archive_handle->reject, file_header->name) == EXIT_SUCCESS) {
struct stat statbuf;
extract_flag = TRUE;
/* Check if the file already exists */
if (lstat (file_header->name, &statbuf) == 0) {
if ((archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) || (statbuf.st_mtime < file_header->mtime)) {
/* Remove file if flag set or its older than the file to be extracted */
if (unlink(file_header->name) == -1) {
perror_msg_and_die("Couldnt remove old file");
}
} else {
if (! archive_handle->flags & ARCHIVE_EXTRACT_QUIET) {
error_msg("%s not created: newer or same age file exists", file_header->name);
}
extract_flag = FALSE;
}
}
archive_handle->action_header(file_header);
}
archive_handle->action_header(file_header);
if (extract_flag) {
archive_handle->action_data(archive_handle);
} else {
data_skip(archive_handle);
}
archive_handle->offset += file_header->size;
}
return(EXIT_SUCCESS);
}
+44 -6
View File
@@ -38,6 +38,7 @@
*
*/
#include <fcntl.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
@@ -1310,14 +1311,44 @@ void purge_package(const unsigned int package_num)
set_status(status_num, "not-installed", 3);
}
static archive_handle_t *deb_extract(const char *filename, const char *ar_name,
const char *tar_gz_name, char *prefix, void (*deb_action_data)(struct archive_handle_s *))
{
archive_handle_t *ar_archive;
archive_handle_t *tar_gz_archive;
/* Setup the tar archive handle */
tar_gz_archive = init_handle();
tar_gz_archive->filter = filter_accept_reject_list;
tar_gz_archive->action_data = deb_action_data;
tar_gz_archive->buffer = prefix;
if (tar_gz_name) {
tar_gz_archive->accept = add_to_list(NULL, tar_gz_name);
}
/* Setup an ar archive handle that refers to the gzip sub archive */
ar_archive = init_handle();
ar_archive->action_data_subarchive = get_header_tar_gz;
ar_archive->sub_archive = tar_gz_archive;
ar_archive->filter = filter_accept_reject_list;
ar_archive->accept = add_to_list(NULL, ar_name);
tar_gz_archive->src_fd = ar_archive->src_fd = xopen(filename, O_RDONLY);
unpack_ar_archive(ar_archive);
close(ar_archive->src_fd);
return(ar_archive->sub_archive);
}
void unpack_package(deb_file_t *deb_file)
{
const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
const unsigned int status_num = search_status_hashtable(package_name);
const unsigned int status_package_num = status_hashtable[status_num]->package;
FILE *out_stream;
char *info_prefix;
archive_handle_t *archive_handle;
FILE *out_stream;
/* If existing version, remove it first */
if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) {
@@ -1333,8 +1364,8 @@ void unpack_package(deb_file_t *deb_file)
/* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
info_prefix = (char *) xmalloc(strlen(package_name) + 20 + 4 + 2);
sprintf(info_prefix, "/var/lib/dpkg/info/%s.", package_name);
deb_extract(deb_file->filename, stdout, (extract_quiet | extract_control_tar_gz | extract_all_to_fs | extract_unconditional), info_prefix, NULL);
deb_extract(deb_file->filename, "control.tar.gz", NULL, info_prefix, data_extract_all_prefix);
/* Run the preinst prior to extracting */
if (run_package_script(package_name, "preinst") != 0) {
/* when preinst returns exit code != 0 then quit installation process */
@@ -1342,12 +1373,17 @@ void unpack_package(deb_file_t *deb_file)
}
/* Extract data.tar.gz to the root directory */
deb_extract(deb_file->filename, stdout, (extract_quiet | extract_data_tar_gz | extract_all_to_fs | extract_unconditional), "/", NULL);
archive_handle = deb_extract(deb_file->filename, "data.tar.gz", NULL, NULL, data_extract_all);
/* Create the list file */
strcat(info_prefix, "list");
out_stream = xfopen(info_prefix, "w");
deb_extract(deb_file->filename, out_stream, (extract_quiet | extract_data_tar_gz | extract_list), "/", NULL);
while (archive_handle->passed) {
/* blindly skip over the leading '.' */
fputs(archive_handle->passed->data + 1, out_stream);
fputc('\n', out_stream);
archive_handle->passed = archive_handle->passed->link;
}
fclose(out_stream);
/* change status */
@@ -1440,8 +1476,10 @@ int dpkg_main(int argc, char **argv)
deb_file = xrealloc(deb_file, sizeof(deb_file_t *) * (deb_count + 2));
deb_file[deb_count] = (deb_file_t *) xmalloc(sizeof(deb_file_t));
if (dpkg_opt & dpkg_opt_filename) {
archive_handle_t *archive_handle;
deb_file[deb_count]->filename = xstrdup(argv[optind]);
deb_file[deb_count]->control_file = deb_extract(argv[optind], stdout, (extract_control_tar_gz | extract_one_to_buffer), NULL, "./control");
archive_handle = deb_extract(argv[optind], "control.tar.gz", "./control", NULL, data_extract_to_buffer);
deb_file[deb_count]->control_file = archive_handle->buffer;
if (deb_file[deb_count]->control_file == NULL) {
error_msg_and_die("Couldnt extract control file");
}
+60 -79
View File
@@ -13,119 +13,100 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include "unarchive.h"
#include "busybox.h"
extern int dpkg_deb_main(int argc, char **argv)
{
char *prefix = NULL;
char *filename = NULL;
char *output_buffer = NULL;
archive_handle_t *ar_archive;
archive_handle_t *tar_gz_archive;
int opt = 0;
int arg_type = 0;
int deb_extract_funct = extract_create_leading_dirs | extract_unconditional;
#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
const llist_t *control_tar_gz_llist = add_to_list(NULL, "control.tar.gz");
#endif
#ifndef CONFIG_AR
char magic[7];
#endif
const int arg_type_prefix = 1;
const int arg_type_field = 2;
const int arg_type_filename = 4;
// const int arg_type_un_ar_gz = 8;
/* a .deb file is an ar archive that contain three files,
* data.tar.gz, control.tar.gz and debian
*/
/* Setup the tar archive handle */
tar_gz_archive = init_handle();
while ((opt = getopt(argc, argv, "ceftXxI")) != -1) {
/* Setup an ar archive handle that refers to the gzip sub archive */
ar_archive = init_handle();
ar_archive->action_data_subarchive = get_header_tar_gz;
ar_archive->sub_archive = tar_gz_archive;
ar_archive->filter = filter_accept_list;
ar_archive->accept = add_to_list(NULL, "data.tar.gz");
#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
while ((opt = getopt(argc, argv, "cefXx")) != -1) {
#else
while ((opt = getopt(argc, argv, "x")) != -1) {
#endif
switch (opt) {
#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
case 'c':
deb_extract_funct |= extract_data_tar_gz;
deb_extract_funct |= extract_verbose_list;
tar_gz_archive->action_header = header_verbose_list;
break;
case 'e':
arg_type = arg_type_prefix;
deb_extract_funct |= extract_control_tar_gz;
deb_extract_funct |= extract_all_to_fs;
ar_archive->accept = control_tar_gz_llist;
tar_gz_archive->action_data = data_extract_all;
break;
case 'f':
arg_type = arg_type_field;
deb_extract_funct |= extract_control_tar_gz;
deb_extract_funct |= extract_one_to_buffer;
filename = xstrdup("./control");
break;
case 't': /* --fsys-tarfile, i just made up this short name */
/* Integrate the functionality needed with some code from ar.c */
error_msg_and_die("Option disabled");
// arg_type = arg_type_un_ar_gz;
/* Print the entire control file
* it should accept a second argument which specifies a
* specific field to print */
ar_archive->accept = control_tar_gz_llist;
tar_gz_archive->accept = add_to_list(NULL, "./control");;
tar_gz_archive->filter = filter_accept_list;
tar_gz_archive->action_data = data_extract_to_stdout;
break;
case 'X':
arg_type = arg_type_prefix;
deb_extract_funct |= extract_data_tar_gz;
deb_extract_funct |= extract_all_to_fs;
deb_extract_funct |= extract_list;
tar_gz_archive->action_header = header_list;
#endif
case 'x':
arg_type = arg_type_prefix;
deb_extract_funct |= extract_data_tar_gz;
deb_extract_funct |= extract_all_to_fs;
break;
case 'I':
arg_type = arg_type_filename;
deb_extract_funct |= extract_control_tar_gz;
deb_extract_funct |= extract_one_to_buffer;
tar_gz_archive->action_data = data_extract_all;
break;
default:
show_usage();
}
}
if (optind == argc) {
if (optind + 2 < argc) {
show_usage();
}
tar_gz_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
/* Workout where to extract the files */
if (arg_type == arg_type_prefix) {
/* argument is a dir name */
if ((optind + 1) == argc ) {
prefix = xstrdup("./DEBIAN/");
} else {
prefix = (char *) xmalloc(strlen(argv[optind + 1]) + 2);
strcpy(prefix, argv[optind + 1]);
/* Make sure the directory has a trailing '/' */
if (last_char_is(prefix, '/') == NULL) {
strcat(prefix, "/");
}
}
mkdir(prefix, 0777);
}
/* 2nd argument is a dir name */
mkdir(argv[optind], 0777);
chdir(argv[optind]);
if (arg_type == arg_type_filename) {
if ((optind + 1) != argc) {
filename = xstrdup(argv[optind + 1]);
} else {
error_msg_and_die("-I currently requires a filename to be specified");
}
#ifdef CONFIG_AR
unpack_ar_archive(ar_archive);
#else
xread_all(ar_archive->src_fd, magic, 7);
if (strncmp(magic, "!<arch>", 7) != 0) {
error_msg_and_die("Invalid ar magic");
}
ar_archive->offset += 7;
output_buffer = deb_extract(argv[optind], stdout, deb_extract_funct, prefix, filename);
while (get_header_ar(ar_archive) == EXIT_SUCCESS);
#endif
if ((arg_type == arg_type_filename) && (output_buffer != NULL)) {
puts(output_buffer);
}
else if (arg_type == arg_type_field) {
char *field = NULL;
char *name;
char *value;
int field_start = 0;
while (1) {
field_start += read_package_field(&output_buffer[field_start], &name, &value);
if (name == NULL) {
break;
}
if (strcmp(name, argv[optind + 1]) == 0) {
puts(value);
}
free(field);
}
}
/* Cleanup */
close (ar_archive->src_fd);
return(EXIT_SUCCESS);
}
+39 -16
View File
@@ -64,7 +64,12 @@ static char *license_msg[] = {
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "busybox.h"
#include "unarchive.h"
const char gunzip_to_stdout = 1;
const char gunzip_force = 2;
@@ -100,23 +105,20 @@ extern int gunzip_main(int argc, char **argv)
}
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;
int src_fd;
int dst_fd;
optind++;
if (old_path == NULL || strcmp(old_path, "-") == 0) {
in_file = stdin;
src_fd = fileno(stdin);
flags |= gunzip_to_stdout;
} else {
in_file = wfopen(old_path, "r");
if (in_file == NULL) {
status = EXIT_FAILURE;
break;
}
src_fd = xopen(old_path, O_RDONLY);
/* Get the time stamp on the input file. */
if (stat(old_path, &stat_buf) < 0) {
@@ -125,16 +127,16 @@ extern int gunzip_main(int argc, char **argv)
}
/* Check that the input is sane. */
if (isatty(fileno(in_file)) && ((flags & gunzip_force) == 0)) {
if (isatty(src_fd) && ((flags & gunzip_force) == 0)) {
error_msg_and_die
("compressed data not read from terminal. Use -f to force it.");
}
/* Set output filename and number */
if (flags & gunzip_test) {
out_file = xfopen("/dev/null", "w"); /* why does test use filenum 2 ? */
dst_fd = xopen("/dev/null", O_WRONLY); /* why does test use filenum 2 ? */
} else if (flags & gunzip_to_stdout) {
out_file = stdout;
dst_fd = fileno(stdout);
} else {
char *extension;
@@ -151,7 +153,7 @@ extern int gunzip_main(int argc, char **argv)
}
/* Open output file */
out_file = xfopen(new_path, "w");
dst_fd = xopen(new_path, O_WRONLY | O_CREAT);
/* Set permissions on the file */
chmod(new_path, stat_buf.st_mode);
@@ -161,16 +163,37 @@ extern int gunzip_main(int argc, char **argv)
}
/* do the decompression, and cleanup */
if ((unzip(in_file, out_file) != 0) && (new_path)) {
if (xread_char(src_fd) == 0x1f) {
unsigned char magic2;
magic2 = xread_char(src_fd);
#ifdef CONFIG_FEATURE_UNCOMPRESS
if (magic2 == 0x9d) {
return(uncompress(src_fd, dst_fd));
} else
#endif
if (magic2 == 0x8b) {
check_header_gzip(src_fd);
status = inflate(src_fd, dst_fd);
if (status != 0) {
error_msg("Error inflating");
}
check_trailer_gzip(src_fd);
} else {
error_msg_and_die("Invalid magic\n");
}
}
if ((status != EXIT_SUCCESS) && (new_path)) {
/* Unzip failed, remove new path instead of old path */
delete_path = new_path;
}
if (out_file != stdout) {
fclose(out_file);
if (dst_fd != fileno(stdout)) {
close(dst_fd);
}
if (in_file != stdin) {
fclose(in_file);
if (src_fd != fileno(stdin)) {
close(src_fd);
}
/* delete_path will be NULL if in test mode or from stdin */
+40 -8
View File
@@ -22,14 +22,46 @@ ifndef $(LIBUNARCHIVE_DIR)
LIBUNARCHIVE_DIR:=$(TOPDIR)archival/libunarchive/
endif
LIBUNARCHIVE-y:=unarchive.o seek_sub_file.o
LIBUNARCHIVE-$(CONFIG_DPKG) += deb_extract.o get_header_ar.o get_header_tar.o
LIBUNARCHIVE-$(CONFIG_DPKG_DEB) += deb_extract.o get_header_ar.o get_header_tar.o
LIBUNARCHIVE-$(CONFIG_AR) += get_header_ar.o
LIBUNARCHIVE-$(CONFIG_CPIO) += get_header_cpio.o
LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += get_header_cpio.o
LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
LIBUNARCHIVE-$(CONFIG_UNZIP) += get_header_zip.o
LIBUNARCHIVE-y:= \
\
data_skip.o \
data_extract_all.o \
data_extract_all_prefix.o \
data_extract_to_stdout.o \
data_extract_to_buffer.o \
\
filter_accept_all.o \
filter_accept_list.o \
filter_accept_reject_list.o \
\
get_header_ar.o \
get_header_tar.o \
get_header_tar_gz.o \
\
header_skip.o \
header_list.o \
header_verbose_list.o \
\
add_to_list.o \
check_header_gzip.o \
check_trailer_gzip.o \
copy_file_chunk_fd.o \
data_align.o \
find_list_entry.o \
init_handle.o \
seek_sub_file.o \
uncompress.o \
unpack_ar_archive.o \
unzip.o
LIBUNARCHIVE-$(CONFIG_DPKG) +=
LIBUNARCHIVE-$(CONFIG_DPKG_DEB) +=
LIBUNARCHIVE-$(CONFIG_AR) +=
LIBUNARCHIVE-$(CONFIG_CPIO) +=
LIBUNARCHIVE-$(CONFIG_GUNZIP) +=
LIBUNARCHIVE-$(CONFIG_RPM2CPIO) +=
LIBUNARCHIVE-$(CONFIG_TAR) +=
LIBUNARCHIVE-$(CONFIG_UNZIP) +=
libraries-y+=$(LIBUNARCHIVE_DIR)$(LIBUNARCHIVE_AR)
+15
View File
@@ -0,0 +1,15 @@
#include <stdlib.h>
#include <string.h>
#include "unarchive.h"
#include "libbb.h"
extern const llist_t *add_to_list(const llist_t *old_head, const char *new_item)
{
llist_t *new_head;
new_head = xmalloc(sizeof(llist_t));
new_head->data = new_item;
new_head->link = old_head;
return(new_head);
}
+68
View File
@@ -0,0 +1,68 @@
#include <stdlib.h>
#include <unistd.h>
#include "libbb.h"
extern void check_header_gzip(int src_fd)
{
union {
unsigned char raw[8];
struct {
unsigned char method;
unsigned char flags;
unsigned int mtime;
unsigned char xtra_flags;
unsigned char os_flags;
} formated;
} header;
xread_all(src_fd, header.raw, 8);
/* Check the compression method */
if (header.formated.method != 8) {
error_msg_and_die("Unknown compression method %d",
header.formated.method);
}
if (header.formated.flags & 0x04) {
/* bit 2 set: extra field present */
unsigned char extra_short;
extra_short = xread_char(src_fd);
extra_short += xread_char(src_fd) << 8;
while (extra_short > 0) {
/* Ignore extra field */
xread_char(src_fd);
extra_short--;
}
}
/* Discard original name if any */
if (header.formated.flags & 0x08) {
/* bit 3 set: original file name present */
char tmp;
do {
read(src_fd, &tmp, 1);
} while (tmp != 0);
}
/* Discard file comment if any */
if (header.formated.flags & 0x10) {
/* bit 4 set: file comment present */
char tmp;
do {
read(src_fd, &tmp, 1);
} while (tmp != 0);
}
/* Read the header checksum */
if (header.formated.flags & 0x02) {
char tmp;
read(src_fd, &tmp, 1);
read(src_fd, &tmp, 1);
}
return;
}
@@ -0,0 +1,62 @@
/* vi: set sw=4 ts=4: */
/*
* busybox gunzip trailing header handler
* Copyright Glenn McGrath 2002
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "config.h"
#include "busybox.h"
#include "unarchive.h"
extern unsigned int gunzip_crc;
extern unsigned int gunzip_bytes_out;
extern unsigned char *gunzip_in_buffer;
extern unsigned char gunzip_in_buffer_count;
extern void check_trailer_gzip(int src_fd)
{
unsigned int stored_crc = 0;
unsigned char count;
/* top up the input buffer with the rest of the trailer */
xread_all(src_fd, &gunzip_in_buffer[gunzip_in_buffer_count], 8 - gunzip_in_buffer_count);
for (count = 0; count != 4; count++) {
stored_crc |= (gunzip_in_buffer[count] << (count * 8));
}
/* Validate decompression - crc */
if (stored_crc != (gunzip_crc ^ 0xffffffffL)) {
error_msg("invalid compressed data--crc error");
}
/* Validate decompression - size */
if (gunzip_bytes_out !=
(gunzip_in_buffer[4] | (gunzip_in_buffer[5] << 8) |
(gunzip_in_buffer[6] << 16) | (gunzip_in_buffer[7] << 24))) {
error_msg("invalid compressed data--length error");
}
}
@@ -0,0 +1,33 @@
#include <unistd.h>
#include <sys/types.h>
#include "libbb.h"
/* Copy CHUNKSIZE bytes (or untill EOF if chunksize == -1)
* from SRC_FILE to DST_FILE. */
extern int copy_file_chunk_fd(int src_fd, int dst_fd, off_t chunksize)
{
size_t nread, size;
char buffer[BUFSIZ];
while (chunksize != 0) {
if (chunksize > BUFSIZ) {
size = BUFSIZ;
} else {
size = chunksize;
}
nread = xread(src_fd, buffer, size);
if (nread == 0) {
return 1;
}
if (write (dst_fd, buffer, nread) != nread) {
error_msg_and_die ("Short write");
}
if (chunksize != -1) {
chunksize -= nread;
}
}
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include "unarchive.h"
#include "libbb.h"
extern const unsigned short data_align(const int src_fd, const unsigned int offset, const unsigned short align_to)
{
const unsigned short skip_amount = (align_to - (offset % align_to)) % align_to;
seek_sub_file(src_fd, skip_amount);
return(skip_amount);
}
+76
View File
@@ -0,0 +1,76 @@
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <utime.h>
#include <unistd.h>
#include <stdlib.h>
#include "libbb.h"
#include "unarchive.h"
extern void data_extract_all(archive_handle_t *archive_handle)
{
file_header_t *file_header = archive_handle->file_header;
int dst_fd;
int res;
if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
char *name = xstrdup(file_header->name);
make_directory (dirname(name), 0777, FILEUTILS_RECUR);
free(name);
}
/* Create the file */
switch(file_header->mode & S_IFMT) {
case S_IFREG: {
#ifdef CONFIG_CPIO
if (file_header->link_name) {
/* hard link */
res = link(file_header->link_name, file_header->name);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
perror_msg("Couldnt create hard link");
}
} else
#endif
{
/* Regular file */
dst_fd = xopen(file_header->name, O_WRONLY | O_CREAT);
copy_file_chunk_fd(archive_handle->src_fd, dst_fd, file_header->size);
close(dst_fd);
}
break;
}
case S_IFDIR:
res = mkdir(file_header->name, file_header->mode);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
perror_msg("extract_archive: %s", file_header->name);
}
break;
case S_IFLNK:
/* Symlink */
res = symlink(file_header->link_name, file_header->name);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
perror_msg("Cannot create symlink from %s to '%s'", file_header->name, file_header->link_name);
}
break;
case S_IFSOCK:
case S_IFBLK:
case S_IFCHR:
case S_IFIFO:
res = mknod(file_header->name, file_header->mode, file_header->device);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
perror_msg("Cannot create node %s", file_header->name);
}
break;
}
chmod(file_header->name, file_header->mode);
chown(file_header->name, file_header->uid, file_header->gid);
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
struct utimbuf t;
t.actime = t.modtime = file_header->mtime;
utime(file_header->name, &t);
}
}
@@ -0,0 +1,23 @@
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <utime.h>
#include <unistd.h>
#include <stdlib.h>
#include "libbb.h"
#include "unarchive.h"
extern void data_extract_all_prefix(archive_handle_t *archive_handle)
{
char *name_ptr = archive_handle->file_header->name;
name_ptr += strspn(name_ptr, "./");
if (name_ptr[0] != '\0') {
archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 2 + strlen(name_ptr));
sprintf(archive_handle->file_header->name, "%s%s", archive_handle->buffer, name_ptr);
data_extract_all(archive_handle);
}
return;
}
@@ -0,0 +1,11 @@
#include <stdlib.h>
#include <stdio.h>
#include "unarchive.h"
#include "libbb.h"
extern void data_extract_to_buffer(archive_handle_t *archive_handle)
{
archive_handle->buffer = xmalloc(archive_handle->file_header->size + 1);
xread_all(archive_handle->src_fd, archive_handle->buffer, archive_handle->file_header->size);
}
@@ -0,0 +1,8 @@
#include <stdlib.h>
#include <stdio.h>
#include "unarchive.h"
extern void data_extract_to_stdout(archive_handle_t *archive_handle)
{
copy_file_chunk_fd(archive_handle->src_fd, fileno(stdout), archive_handle->file_header->size);
}
+27
View File
@@ -0,0 +1,27 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include "unarchive.h"
#include "libbb.h"
extern void data_skip(archive_handle_t *archive_handle)
{
seek_sub_file(archive_handle->src_fd, archive_handle->file_header->size);
}
-84
View File
@@ -1,84 +0,0 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "unarchive.h"
#include "libbb.h"
char *deb_extract(const char *package_filename, FILE *out_stream,
const int extract_function, const char *prefix, const char *filename)
{
FILE *deb_stream;
FILE *uncompressed_stream = NULL;
file_header_t *ar_header = NULL;
char **file_list = NULL;
char *output_buffer = NULL;
char *ared_file = NULL;
char ar_magic[8];
int gunzip_pid;
if (filename != NULL) {
file_list = xmalloc(sizeof(char *) * 2);
file_list[0] = xstrdup(filename);
file_list[1] = NULL;
}
if (extract_function & extract_control_tar_gz) {
ared_file = xstrdup("control.tar.gz");
}
else if (extract_function & extract_data_tar_gz) {
ared_file = xstrdup("data.tar.gz");
}
/* open the debian package to be worked on */
deb_stream = wfopen(package_filename, "r");
if (deb_stream == NULL) {
return(NULL);
}
/* set the buffer size */
setvbuf(deb_stream, NULL, _IOFBF, 0x8000);
/* check ar magic */
fread(ar_magic, 1, 8, deb_stream);
if (strncmp(ar_magic,"!<arch>",7) != 0) {
error_msg_and_die("invalid magic");
}
archive_offset = 8;
while ((ar_header = get_header_ar(deb_stream)) != NULL) {
if (strcmp(ared_file, ar_header->name) == 0) {
/* open a stream of decompressed data */
uncompressed_stream = gz_open(deb_stream, &gunzip_pid);
archive_offset = 0;
output_buffer = unarchive(uncompressed_stream, out_stream, get_header_tar, extract_function, prefix, file_list, NULL);
}
seek_sub_file(deb_stream, ar_header->size);
free(ar_header->name);
free(ar_header);
}
gz_close(gunzip_pid);
fclose(deb_stream);
fclose(uncompressed_stream);
free(ared_file);
if (filename != NULL) {
free(file_list[0]);
free(file_list);
}
return(output_buffer);
}
+10 -16
View File
@@ -28,8 +28,9 @@
* [... History snipped ...]
*
*/
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define IBUFSIZ 2048 /* Defailt input buffer size */
#define OBUFSIZ 2048 /* Default output buffer size */
@@ -95,9 +96,6 @@ unsigned short codetab[HSIZE];
#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
@@ -105,7 +103,7 @@ extern int uncompress ( FILE *, FILE * );
* with those of the compress() routine. See the definitions above.
*/
int uncompress ( FILE * fdin, FILE * fdout )
extern int uncompress(int fd_in, int fd_out)
{
char_type *stackp;
code_int code;
@@ -125,7 +123,7 @@ int uncompress ( FILE * fdin, FILE * fdout )
insize = 0;
inbuf [0] = fgetc(fdin);
inbuf [0] = xread_char(fd_in);
maxbits = inbuf[0] & BIT_MASK;
block_mode = inbuf[0] & BLOCK_MODE;
@@ -173,11 +171,7 @@ resetbuf: ;
if (insize < (int) sizeof(inbuf)-IBUFSIZ)
{
rsize = fread(inbuf+insize, 1,IBUFSIZ,fdin);
if ( !rsize && ferror(fdin))
return -1;
xread_all(fd_in, inbuf+insize, IBUFSIZ);
insize += rsize;
}
@@ -275,8 +269,7 @@ resetbuf: ;
if (outpos >= OBUFSIZ)
{
fwrite(outbuf, 1,outpos,fdout);
write(fd_out, outbuf, outpos);
outpos = 0;
}
stackp+= i;
@@ -303,8 +296,9 @@ resetbuf: ;
}
while (rsize > 0);
if (outpos > 0)
fwrite(outbuf, outpos,1, fdout);
if (outpos > 0) {
write(fd_out, outbuf, outpos);
}
return 0;
}
File diff suppressed because it is too large. Load diff
+14
View File
@@ -0,0 +1,14 @@
#include <fnmatch.h>
#include <stdlib.h>
#include "unarchive.h"
/*
* Accept names that are in the accept list
*/
extern char filter_accept_all(const llist_t *accept_list, const llist_t *reject_list, const char *key)
{
if (key) {
return(EXIT_SUCCESS);
} else {
return(EXIT_FAILURE);
}
}
@@ -0,0 +1,15 @@
#include <fnmatch.h>
#include <stdlib.h>
#include "unarchive.h"
/*
* Accept names that are in the accept list
*/
extern char filter_accept_list(const llist_t *accept_list, const llist_t *reject_list, const char *key)
{
if (find_list_entry(accept_list, key)) {
return(EXIT_SUCCESS);
} else {
return(EXIT_FAILURE);
}
}
@@ -0,0 +1,25 @@
#include <fnmatch.h>
#include <stdlib.h>
#include "unarchive.h"
/*
* Accept names that are in the accept list
*/
extern char filter_accept_reject_list(const llist_t *accept_list, const llist_t *reject_list, const char *key)
{
const llist_t *accept_entry = find_list_entry(accept_list, key);
const llist_t *reject_entry = find_list_entry(reject_list, key);
/* Fail if an accept list was specified and the key wasnt in there */
if (accept_list && (accept_entry == NULL)) {
return(EXIT_FAILURE);
}
/* If the key is in a reject list fail */
if (reject_entry) {
return(EXIT_FAILURE);
}
/* Accepted */
return(EXIT_SUCCESS);
}
+30
View File
@@ -0,0 +1,30 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <fnmatch.h>
#include <stdlib.h>
#include "unarchive.h"
extern const llist_t *find_list_entry(const llist_t *list, const char *filename)
{
while (list) {
if (fnmatch(list->data, filename, 0) == 0) {
return(list);
}
list = list->link;
}
return(NULL);
}
+57 -41
View File
@@ -17,12 +17,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "unarchive.h"
#include "libbb.h"
file_header_t *get_header_ar(FILE *src_stream)
extern char get_header_ar(archive_handle_t *archive_handle)
{
file_header_t *typed;
file_header_t *typed = archive_handle->file_header;
union {
char raw[60];
struct {
@@ -35,72 +36,87 @@ file_header_t *get_header_ar(FILE *src_stream)
char magic[2];
} formated;
} ar;
#ifdef CONFIG_FEATURE_AR_LONG_FILENAMES
static char *ar_long_names;
static unsigned int ar_long_name_size;
#endif
if (fread(ar.raw, 1, 60, src_stream) != 60) {
return(NULL);
/* dont use xread as we want to handle the error ourself */
if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
/* End Of File */
return(EXIT_FAILURE);
}
/* Some ar entries have a trailing '\n' after the previous data entry */
if (ar.raw[0] == '\n') {
/* fix up the header, we started reading 1 byte too early */
memmove(ar.raw, &ar.raw[1], 59);
ar.raw[59] = xread_char(archive_handle->src_fd);
archive_handle->offset++;
}
archive_offset += 60;
archive_handle->offset += 60;
/* align the headers based on the header magic */
if ((ar.formated.magic[0] != '`') || (ar.formated.magic[1] != '\n')) {
/* some version of ar, have an extra '\n' after each data entry,
* this puts the next header out by 1 */
if (ar.formated.magic[1] != '`') {
error_msg("Invalid magic");
return(NULL);
}
/* read the next char out of what would be the data section,
* if its a '\n' then it is a valid header offset by 1*/
archive_offset++;
if (fgetc(src_stream) != '\n') {
error_msg("Invalid magic");
return(NULL);
}
/* fix up the header, we started reading 1 byte too early */
/* raw_header[60] wont be '\n' as it should, but it doesnt matter */
memmove(ar.raw, &ar.raw[1], 59);
error_msg_and_die("Invalid ar header");
}
typed = (file_header_t *) xcalloc(1, sizeof(file_header_t));
typed->size = (size_t) atoi(ar.formated.size);
typed->mode = strtol(ar.formated.mode, NULL, 8);
typed->mtime = atoi(ar.formated.date);
typed->uid = atoi(ar.formated.uid);
typed->gid = atoi(ar.formated.gid);
typed->size = atoi(ar.formated.size);
/* long filenames have '/' as the first character */
if (ar.formated.name[0] == '/') {
#ifdef CONFIG_FEATURE_AR_LONG_FILENAMES
if (ar.formated.name[1] == '/') {
/* If the second char is a '/' then this entries data section
* stores long filename for multiple entries, they are stored
* in static variable long_names for use in future entries */
ar_long_names = (char *) xrealloc(ar_long_names, typed->size);
fread(ar_long_names, 1, typed->size, src_stream);
archive_offset += typed->size;
ar_long_name_size = typed->size;
ar_long_names = xmalloc(ar_long_name_size);
xread_all(archive_handle->src_fd, ar_long_names, ar_long_name_size);
archive_handle->offset += ar_long_name_size;
/* This ar entries data section only contained filenames for other records
* they are stored in the static ar_long_names for future reference */
return (get_header_ar(src_stream)); /* Return next header */
return (get_header_ar(archive_handle)); /* Return next header */
} else if (ar.formated.name[1] == ' ') {
/* This is the index of symbols in the file for compilers */
seek_sub_file(src_stream, typed->size);
return (get_header_ar(src_stream)); /* Return next header */
data_skip(archive_handle);
return (get_header_ar(archive_handle)); /* Return next header */
} else {
/* The number after the '/' indicates the offset in the ar data section
(saved in variable long_name) that conatains the real filename */
if (!ar_long_names) {
error_msg("Cannot resolve long file name");
return (NULL);
const unsigned int long_offset = atoi(&ar.formated.name[1]);
if (long_offset >= ar_long_name_size) {
error_msg_and_die("Cant resolve long filename");
}
typed->name = xstrdup(ar_long_names + atoi(&ar.formated.name[1]));
typed->name = xstrdup(ar_long_names + long_offset);
}
#else
error_msg_and_die("long filenames not supported");
#endif
} else {
/* short filenames */
typed->name = xstrndup(ar.formated.name, 16);
}
typed->name[strcspn(typed->name, " /")]='\0';
/* convert the rest of the now valid char header to its typed struct */
parse_mode(ar.formated.mode, &typed->mode);
typed->mtime = atoi(ar.formated.date);
typed->uid = atoi(ar.formated.uid);
typed->gid = atoi(ar.formated.gid);
typed->name[strcspn(typed->name, " /")] = '\0';
return(typed);
if (archive_handle->filter(archive_handle->accept, archive_handle->reject, typed->name) == EXIT_SUCCESS) {
archive_handle->action_header(typed);
if (archive_handle->sub_archive) {
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS);
} else {
archive_handle->action_data(archive_handle);
}
} else {
data_skip(archive_handle);
}
archive_handle->offset += typed->size + 1;
return(EXIT_SUCCESS);
}
-137
View File
@@ -1,137 +0,0 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "unarchive.h"
#include "libbb.h"
struct hardlinks {
file_header_t *entry;
int inode;
struct hardlinks *next;
};
file_header_t *get_header_cpio(FILE *src_stream)
{
file_header_t *cpio_entry = NULL;
char cpio_header[110];
int namesize;
char dummy[16];
int major, minor, nlink, inode;
static struct hardlinks *saved_hardlinks = NULL;
static int pending_hardlinks = 0;
if (pending_hardlinks) { /* Deal with any pending hardlinks */
struct hardlinks *tmp = saved_hardlinks, *oldtmp = NULL;
while (tmp) {
if (tmp->entry->link_name) { /* Found a hardlink ready to be extracted */
cpio_entry = tmp->entry;
if (oldtmp) oldtmp->next = tmp->next; /* Remove item from linked list */
else saved_hardlinks = tmp->next;
free(tmp);
return (cpio_entry);
}
oldtmp = tmp;
tmp = tmp->next;
}
pending_hardlinks = 0; /* No more pending hardlinks, read next file entry */
}
/* There can be padding before archive header */
seek_sub_file(src_stream, (4 - (archive_offset % 4)) % 4);
if (fread(cpio_header, 1, 110, src_stream) == 110) {
archive_offset += 110;
if (strncmp(cpio_header, "07070", 5) != 0) {
error_msg("Unsupported format or invalid magic");
return(NULL);
}
switch (cpio_header[5]) {
case '2': /* "crc" header format */
/* Doesnt do the crc check yet */
case '1': /* "newc" header format */
cpio_entry = (file_header_t *) xcalloc(1, sizeof(file_header_t));
sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c",
dummy, &inode, (unsigned int*)&cpio_entry->mode,
(unsigned int*)&cpio_entry->uid, (unsigned int*)&cpio_entry->gid,
&nlink, &cpio_entry->mtime, &cpio_entry->size,
dummy, &major, &minor, &namesize, dummy);
cpio_entry->name = (char *) xcalloc(1, namesize);
fread(cpio_entry->name, 1, namesize, src_stream); /* Read in filename */
archive_offset += namesize;
/* Skip padding before file contents */
seek_sub_file(src_stream, (4 - (archive_offset % 4)) % 4);
if (strcmp(cpio_entry->name, "TRAILER!!!") == 0) {
printf("%d blocks\n", (int) (archive_offset % 512 ? (archive_offset / 512) + 1 : archive_offset / 512)); /* Always round up */
if (saved_hardlinks) { /* Bummer - we still have unresolved hardlinks */
struct hardlinks *tmp = saved_hardlinks, *oldtmp = NULL;
while (tmp) {
error_msg("%s not created: cannot resolve hardlink", tmp->entry->name);
oldtmp = tmp;
tmp = tmp->next;
free (oldtmp->entry->name);
free (oldtmp->entry);
free (oldtmp);
}
saved_hardlinks = NULL;
pending_hardlinks = 0;
}
return(NULL);
}
if (S_ISLNK(cpio_entry->mode)) {
cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1);
fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream);
archive_offset += cpio_entry->size;
cpio_entry->size = 0; /* Stop possiable seeks in future */
}
if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) {
if (cpio_entry->size == 0) { /* Put file on a linked list for later */
struct hardlinks *new = xmalloc(sizeof(struct hardlinks));
new->next = saved_hardlinks;
new->inode = inode;
new->entry = cpio_entry;
saved_hardlinks = new;
return(get_header_cpio(src_stream)); /* Recurse to next file */
} else { /* Found the file with data in */
struct hardlinks *tmp = saved_hardlinks;
pending_hardlinks = 1;
while (tmp) {
if (tmp->inode == inode) {
tmp->entry->link_name = xstrdup(cpio_entry->name);
nlink--;
}
tmp = tmp->next;
}
if (nlink > 1) error_msg("error resolving hardlink: did you create the archive with GNU cpio 2.0-2.2?");
}
}
cpio_entry->device = (major << 8) | minor;
break;
default:
error_msg("Unsupported format");
return(NULL);
}
if (ferror(src_stream) || feof(src_stream)) {
perror_msg("Stream error");
return(NULL);
}
}
return(cpio_entry);
}
+64 -53
View File
@@ -20,8 +20,9 @@
#include "unarchive.h"
#include "libbb.h"
file_header_t *get_header_tar(FILE * tar_stream)
extern char get_header_tar(archive_handle_t *archive_handle)
{
file_header_t *file_header = archive_handle->file_header;
union {
unsigned char raw[512];
struct {
@@ -44,20 +45,23 @@ file_header_t *get_header_tar(FILE * tar_stream)
char padding[12]; /* 500-512 */
} formated;
} tar;
file_header_t *tar_entry = NULL;
long sum = 0;
long i;
char *tmp;
if (archive_offset % 512 != 0) {
seek_sub_file(tar_stream, 512 - (archive_offset % 512));
}
/* Align header */
archive_handle->offset += data_align(archive_handle->src_fd, archive_handle->offset, 512);
if (fread(tar.raw, 1, 512, tar_stream) != 512) {
/* Unfortunatly its common for tar files to have all sorts of
* trailing garbage, fail silently */
return (NULL);
if (xread_all_eof(archive_handle->src_fd, tar.raw, 512) == 0) {
/* End of file */
return(EXIT_FAILURE);
}
archive_handle->offset += 512;
/* If there is no filename its an empty header */
if (tar.formated.name[0] == 0) {
return(EXIT_SUCCESS);
}
archive_offset += 512;
/* Check header has valid magic, "ustar" is for the proper tar
* 0's are for the old tar format
@@ -66,100 +70,107 @@ file_header_t *get_header_tar(FILE * tar_stream)
#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);
error_msg_and_die("Invalid tar magic");
}
/* 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(EXIT_FAILURE);
}
/* convert to type'ed variables */
tar_entry = xcalloc(1, sizeof(file_header_t));
if (tar.formated.prefix[0] == 0) {
tar_entry->name = xstrdup(tar.formated.name);
file_header->name = strdup(tar.formated.name);
} else {
tar_entry->name =
concat_path_file(tar.formated.prefix, tar.formated.name);
file_header->name = concat_path_file(tar.formated.prefix, tar.formated.name);
}
tmp = last_char_is(archive_handle->file_header->name, '/');
if (tmp) {
*tmp = '\0';
}
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 =
(dev_t) ((strtol(tar.formated.devmajor, NULL, 8) << 8) +
file_header->mode = strtol(tar.formated.mode, NULL, 8);
file_header->uid = strtol(tar.formated.uid, NULL, 8);
file_header->gid = strtol(tar.formated.gid, NULL, 8);
file_header->size = strtol(tar.formated.size, NULL, 8);
file_header->mtime = strtol(tar.formated.mtime, NULL, 8);
file_header->link_name = (tar.formated.linkname[0] != '\0') ?
xstrdup(tar.formated.linkname) : NULL;
file_header->device = (dev_t) ((strtol(tar.formated.devmajor, NULL, 8) << 8) +
strtol(tar.formated.devminor, NULL, 8));
#if defined CONFIG_FEATURE_TAR_OLD_FORMAT || defined CONFIG_FEATURE_GNUTAR_LONG_FILENAME
/* Fix mode, used by the old format */
switch (tar.formated.typeflag) {
# ifdef CONFIG_FEATURE_TAR_OLD_FORMAT
case 0:
tar_entry->mode |= S_IFREG;
file_header->mode |= S_IFREG;
break;
case 1:
error_msg("internal hard link not handled\n");
error_msg("Internal hard link not supported");
break;
case 2:
tar_entry->mode |= S_IFLNK;
file_header->mode |= S_IFLNK;
break;
case 3:
tar_entry->mode |= S_IFCHR;
file_header->mode |= S_IFCHR;
break;
case 4:
tar_entry->mode |= S_IFBLK;
file_header->mode |= S_IFBLK;
break;
case 5:
tar_entry->mode |= S_IFDIR;
file_header->mode |= S_IFDIR;
break;
case 6:
tar_entry->mode |= S_IFIFO;
file_header->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';
longname = xmalloc(file_header->size + 1);
xread_all(archive_handle->src_fd, longname, file_header->size);
longname[file_header->size] = '\0';
archive_handle->offset += file_header->size;
tar_entry = get_header_tar(tar_stream);
tar_entry->name = longname;
get_header_tar(archive_handle);
file_header->name = longname;
break;
}
case 'K': {
char *longname;
char *linkname;
longname = xmalloc(tar_entry->size + 1);
fread(longname, 1, tar_entry->size, tar_stream);
archive_offset += tar_entry->size;
longname[tar_entry->size] = '\0';
linkname = xmalloc(file_header->size + 1);
xread_all(archive_handle->src_fd, linkname, file_header->size);
linkname[file_header->size] = '\0';
archive_handle->offset += file_header->size;
tar_entry = get_header_tar(tar_stream);
tar_entry->link_name = longname;
get_header_tar(archive_handle);
file_header->name = linkname;
break;
}
# endif
}
#endif
if (archive_handle->filter(archive_handle->accept, archive_handle->reject, archive_handle->file_header->name) == EXIT_SUCCESS) {
archive_handle->action_header(archive_handle->file_header);
archive_handle->flags |= ARCHIVE_EXTRACT_QUIET;
archive_handle->action_data(archive_handle);
archive_handle->passed = add_to_list(archive_handle->passed, archive_handle->file_header->name);
} else {
data_skip(archive_handle);
}
archive_handle->offset += file_header->size;
return (tar_entry);
return(EXIT_SUCCESS);
}
+80
View File
@@ -0,0 +1,80 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <sys/types.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "libbb.h"
#include "unarchive.h"
extern char get_header_tar_gz(archive_handle_t *archive_handle)
{
int fd_pipe[2];
int pid;
unsigned char magic[2];
xread_all(archive_handle->src_fd, &magic, 2);
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
error_msg_and_die("Invalid gzip magic");
}
check_header_gzip(archive_handle->src_fd);
if (pipe(fd_pipe) != 0) {
error_msg_and_die("Can't create pipe");
}
pid = fork();
if (pid == -1) {
error_msg_and_die("Fork failed\n");
}
if (pid == 0) {
/* child process */
close(fd_pipe[0]); /* We don't wan't to read from the pipe */
inflate(archive_handle->src_fd, fd_pipe[1]);
check_trailer_gzip(archive_handle->src_fd);
close(fd_pipe[1]); /* Send EOF */
exit(0);
/* notreached */
}
/* parent process */
close(fd_pipe[1]); /* Don't want to write down the pipe */
close(archive_handle->src_fd);
archive_handle->src_fd = fd_pipe[0];
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS);
if (kill(pid, SIGTERM) == -1) {
error_msg_and_die("Couldnt kill gunzip process");
}
/* I dont think this is needed */
#if 0
if (waitpid(pid, NULL, 0) == -1) {
error_msg("Couldnt wait ?");
}
#endif
/* Can only do one file at a time */
return(EXIT_FAILURE);
}
-171
View File
@@ -1,171 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* get_header_zip for busybox
*
* Copyright (C) 2001 by Laurence Anderson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <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 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)
{
int zip_header[10];
file_header_t *zip_entry = NULL;
int magic, tmpmagic;
/* If dd_ahead is true, we didn't know the last extracted file's length. */
static int dd_ahead = 0;
magic = le_read_int(zip_stream, 4);
checkmagic:
switch (magic) {
case ZIP_FILEHEADER_MAGIC:
zip_entry = xcalloc(1, sizeof(file_header_t));
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? */
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;
}
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
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 ((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;
}
}
error_msg_and_die(fail_msg);
}
return(zip_entry);
}
+7
View File
@@ -0,0 +1,7 @@
#include <stdio.h>
#include "unarchive.h"
extern void header_list(const file_header_t *file_header)
{
puts(file_header->name);
}
+7
View File
@@ -0,0 +1,7 @@
#include <stdio.h>
#include "unarchive.h"
extern void header_skip(const file_header_t *file_header)
{
return;
}
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "libbb.h"
#include "unarchive.h"
extern void header_verbose_list(const file_header_t *file_header)
{
struct tm *mtime = localtime(&file_header->mtime);
printf("%s %d/%d%10u %4u-%02u-%02u %02u:%02u:%02u %s",
mode_string(file_header->mode),
file_header->uid,
file_header->gid,
(unsigned int) file_header->size,
1900 + mtime->tm_year,
1 + mtime->tm_mon,
mtime->tm_mday,
mtime->tm_hour,
mtime->tm_min,
mtime->tm_sec,
file_header->name);
if (file_header->link_name) {
printf(" -> %s", file_header->link_name);
}
/* putchar isnt used anywhere else i dont think */
puts("");
}
+18
View File
@@ -0,0 +1,18 @@
#include <string.h>
#include "libbb.h"
#include "unarchive.h"
archive_handle_t *init_handle(void)
{
archive_handle_t *archive_handle;
/* Initialise default values */
archive_handle = xmalloc(sizeof(archive_handle_t));
memset(archive_handle, 0, sizeof(archive_handle_t));
archive_handle->file_header = xmalloc(sizeof(file_header_t));
archive_handle->action_header = header_skip;
archive_handle->action_data = data_skip;
archive_handle->filter = filter_accept_all;
return(archive_handle);
}
+9 -13
View File
@@ -14,23 +14,19 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <sys/types.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdlib.h>
#include "unarchive.h"
#include "libbb.h"
off_t archive_offset;
void seek_sub_file(FILE *src_stream, const int count)
extern void seek_sub_file(const int src_fd, const unsigned int amount)
{
/* Try to fseek as faster */
archive_offset += count;
if (fseek(src_stream, count, SEEK_CUR) != 0 && errno == ESPIPE) {
int i;
for (i = 0; i < count; i++) {
fgetc(src_stream);
if ((lseek(src_fd, amount, SEEK_CUR) == -1) && (errno == ESPIPE)) {
unsigned int i;
for (i = 0; i < amount; i++) {
xread_char(src_fd);
}
}
return;
}
-263
View File
@@ -1,263 +0,0 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <errno.h>
#include <fnmatch.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <utime.h>
#include <sys/wait.h>
#include <signal.h>
#include "unarchive.h"
#include "busybox.h"
/* Extract the data postioned at src_stream to either filesystem, stdout or
* buffer depending on the value of 'function' which is defined in libbb.h
*
* prefix doesnt have to be just a directory, it may prefix the filename as well.
*
* e.g. '/var/lib/dpkg/info/dpkg.' will extract all files to the base bath
* '/var/lib/dpkg/info/' and all files/dirs created in that dir will have
* 'dpkg.' as their prefix
*
* For this reason if prefix does point to a dir then it must end with a
* trailing '/' or else the last dir will be assumed to be the file prefix
*/
char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *file_entry,
const int function, const char *prefix)
{
FILE *dst_stream = NULL;
char *full_name = NULL;
char *buffer = NULL;
struct utimbuf t;
/* prefix doesnt have to be a proper path it may prepend
* the filename as well */
if (prefix != NULL) {
/* strip leading '/' in filename to extract as prefix may not be dir */
/* Cant use concat_path_file here as prefix might not be a directory */
char *path = file_entry->name;
if (strncmp("./", path, 2) == 0) {
path += 2;
if (strlen(path) == 0) {
return(NULL);
}
}
bb_asprintf(&full_name, "%s%s", prefix, path);
} else {
full_name = file_entry->name;
}
if (function & extract_to_stdout) {
if (S_ISREG(file_entry->mode)) {
copy_file_chunk(src_stream, out_stream, file_entry->size);
archive_offset += file_entry->size;
}
}
else if (function & extract_one_to_buffer) {
if (S_ISREG(file_entry->mode)) {
buffer = (char *) xmalloc(file_entry->size + 1);
fread(buffer, 1, file_entry->size, src_stream);
buffer[file_entry->size] = '\0';
archive_offset += file_entry->size;
return(buffer);
}
}
else if (function & extract_all_to_fs) {
struct stat oldfile;
int stat_res;
stat_res = lstat (full_name, &oldfile);
if (stat_res == 0) { /* The file already exists */
if ((function & extract_unconditional) || (oldfile.st_mtime < file_entry->mtime)) {
if (!S_ISDIR(oldfile.st_mode)) {
unlink(full_name); /* Directories might not be empty etc */
}
} else {
if ((function & extract_quiet) != extract_quiet) {
error_msg("%s not created: newer or same age file exists", file_entry->name);
}
seek_sub_file(src_stream, file_entry->size);
return (NULL);
}
}
if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */
char *buf, *parent;
buf = xstrdup(full_name);
parent = dirname(buf);
if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) {
if ((function & extract_quiet) != extract_quiet) {
error_msg("couldn't create leading directories");
}
}
free (buf);
}
switch(file_entry->mode & S_IFMT) {
case S_IFREG:
if (file_entry->link_name) { /* Found a cpio hard link */
if (link(file_entry->link_name, full_name) != 0) {
if ((function & extract_quiet) != extract_quiet) {
perror_msg("Cannot link from %s to '%s'",
file_entry->name, file_entry->link_name);
}
}
} else {
if ((dst_stream = wfopen(full_name, "w")) == NULL) {
seek_sub_file(src_stream, file_entry->size);
return NULL;
}
archive_offset += file_entry->size;
if (file_entry->extract_func) file_entry->extract_func(src_stream, dst_stream);
else copy_file_chunk(src_stream, dst_stream, file_entry->size);
fclose(dst_stream);
}
break;
case S_IFDIR:
if (stat_res != 0) {
if (mkdir(full_name, file_entry->mode) < 0) {
if ((function & extract_quiet) != extract_quiet) {
perror_msg("extract_archive: %s", full_name);
}
}
}
break;
case S_IFLNK:
if (symlink(file_entry->link_name, full_name) < 0) {
if ((function & extract_quiet) != extract_quiet) {
perror_msg("Cannot create symlink from %s to '%s'", file_entry->name, file_entry->link_name);
}
return NULL;
}
break;
case S_IFSOCK:
case S_IFBLK:
case S_IFCHR:
case S_IFIFO:
if (mknod(full_name, file_entry->mode, file_entry->device) == -1) {
if ((function & extract_quiet) != extract_quiet) {
perror_msg("Cannot create node %s", file_entry->name);
}
return NULL;
}
break;
}
/* Changing a symlink's properties normally changes the properties of the
* file pointed to, so dont try and change the date or mode, lchown does
* does the right thing, but isnt available in older versions of libc */
if (S_ISLNK(file_entry->mode)) {
#if (__GLIBC__ > 2) && (__GLIBC_MINOR__ > 1)
lchown(full_name, file_entry->uid, file_entry->gid);
#endif
} else {
if (function & extract_preserve_date) {
t.actime = file_entry->mtime;
t.modtime = file_entry->mtime;
utime(full_name, &t);
}
chmod(full_name, file_entry->mode);
chown(full_name, file_entry->uid, file_entry->gid);
}
} else {
/* If we arent extracting data we have to skip it,
* if data size is 0 then then just do it anyway
* (saves testing for it) */
seek_sub_file(src_stream, file_entry->size);
}
/* extract_list and extract_verbose_list can be used in conjunction
* with one of the above four extraction functions, so do this seperately */
if (function & extract_verbose_list) {
fprintf(out_stream, "%s %d/%d %8d %s ", mode_string(file_entry->mode),
file_entry->uid, file_entry->gid,
(int) file_entry->size, time_string(file_entry->mtime));
}
if ((function & extract_list) || (function & extract_verbose_list)){
/* fputs doesnt add a trailing \n, so use fprintf */
fprintf(out_stream, "%s\n", full_name);
}
if (prefix != NULL) {
free(full_name);
}
return(NULL); /* Maybe we should say if failed */
}
char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *),
const int extract_function, const char *prefix, char **include_name, char **exclude_name)
{
file_header_t *file_entry;
int extract_flag = TRUE;
int i;
char *buffer = NULL;
#ifdef CONFIG_FEATURE_UNARCHIVE_TAPE
int pid, tape_pipe[2];
if (pipe(tape_pipe) != 0) error_msg_and_die("Can't create pipe\n");
if ((pid = fork()) == -1) error_msg_and_die("Fork failed\n");
if (pid==0) { /* child process */
close(tape_pipe[0]); /* We don't wan't to read from the pipe */
copyfd(fileno(src_stream), tape_pipe[1]);
close(tape_pipe[1]); /* Send EOF */
exit(0);
/* notreached */
}
close(tape_pipe[1]); /* Don't want to write down the pipe */
fclose(src_stream);
src_stream = fdopen(tape_pipe[0], "r");
#endif
archive_offset = 0;
while ((file_entry = get_headers(src_stream)) != NULL) {
if (include_name != NULL) {
extract_flag = FALSE;
for(i = 0; include_name[i] != 0; i++) {
if (fnmatch(include_name[i], file_entry->name, FNM_LEADING_DIR) == 0) {
extract_flag = TRUE;
break;
}
}
} else {
extract_flag = TRUE;
}
/* If the file entry is in the exclude list dont extract it */
if (exclude_name != NULL) {
for(i = 0; exclude_name[i] != 0; i++) {
if (fnmatch(exclude_name[i], file_entry->name, FNM_LEADING_DIR) == 0) {
extract_flag = FALSE;
break;
}
}
}
if (extract_flag) {
buffer = extract_archive(src_stream, out_stream, file_entry, extract_function, prefix);
} else {
/* seek past the data entry */
seek_sub_file(src_stream, file_entry->size);
}
free(file_entry->name);
free(file_entry->link_name);
free(file_entry);
}
#ifdef CONFIG_FEATURE_UNARCHIVE_TAPE
kill(pid, SIGTERM);
waitpid(pid, NULL, 0);
#endif
return(buffer);
}
+10 -16
View File
@@ -28,8 +28,9 @@
* [... History snipped ...]
*
*/
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define IBUFSIZ 2048 /* Defailt input buffer size */
#define OBUFSIZ 2048 /* Default output buffer size */
@@ -95,9 +96,6 @@ unsigned short codetab[HSIZE];
#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
@@ -105,7 +103,7 @@ extern int uncompress ( FILE *, FILE * );
* with those of the compress() routine. See the definitions above.
*/
int uncompress ( FILE * fdin, FILE * fdout )
extern int uncompress(int fd_in, int fd_out)
{
char_type *stackp;
code_int code;
@@ -125,7 +123,7 @@ int uncompress ( FILE * fdin, FILE * fdout )
insize = 0;
inbuf [0] = fgetc(fdin);
inbuf [0] = xread_char(fd_in);
maxbits = inbuf[0] & BIT_MASK;
block_mode = inbuf[0] & BLOCK_MODE;
@@ -173,11 +171,7 @@ resetbuf: ;
if (insize < (int) sizeof(inbuf)-IBUFSIZ)
{
rsize = fread(inbuf+insize, 1,IBUFSIZ,fdin);
if ( !rsize && ferror(fdin))
return -1;
xread_all(fd_in, inbuf+insize, IBUFSIZ);
insize += rsize;
}
@@ -275,8 +269,7 @@ resetbuf: ;
if (outpos >= OBUFSIZ)
{
fwrite(outbuf, 1,outpos,fdout);
write(fd_out, outbuf, outpos);
outpos = 0;
}
stackp+= i;
@@ -303,8 +296,9 @@ resetbuf: ;
}
while (rsize > 0);
if (outpos > 0)
fwrite(outbuf, outpos,1, fdout);
if (outpos > 0) {
write(fd_out, outbuf, outpos);
}
return 0;
}
+34
View File
@@ -0,0 +1,34 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "unarchive.h"
#include "busybox.h"
extern void unpack_ar_archive(archive_handle_t *ar_archive)
{
char magic[7];
xread_all(ar_archive->src_fd, magic, 7);
if (strncmp(magic, "!<arch>", 7) != 0) {
error_msg_and_die("Invalid ar magic");
}
ar_archive->offset += 7;
while (get_header_ar(ar_archive) == EXIT_SUCCESS);
}
File diff suppressed because it is too large. Load diff
+40 -23
View File
@@ -18,10 +18,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "busybox.h"
#include <sys/types.h>
#include <netinet/in.h> /* For ntohl & htonl function */
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include "busybox.h"
#include "unarchive.h"
#define RPM_MAGIC "\355\253\356\333"
#define RPM_HEADER_MAGIC "\216\255\350"
@@ -45,46 +48,60 @@ struct rpm_header {
u_int32_t size; /* Size of store (4 bytes) */
};
void skip_header(FILE *rpmfile)
void skip_header(int rpm_fd)
{
struct rpm_header header;
fread(&header, sizeof(struct rpm_header), 1, rpmfile);
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) error_msg_and_die("Invalid RPM header magic"); /* Invalid magic */
if (header.version != 1) error_msg_and_die("Unsupported RPM header version"); /* This program only supports v1 headers */
xread_all(rpm_fd, &header, sizeof(struct rpm_header));
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) {
error_msg_and_die("Invalid RPM header magic"); /* Invalid magic */
}
if (header.version != 1) {
error_msg_and_die("Unsupported RPM header version"); /* This program only supports v1 headers */
}
header.entries = ntohl(header.entries);
header.size = ntohl(header.size);
fseek (rpmfile, 16 * header.entries, SEEK_CUR); /* Seek past index entries */
fseek (rpmfile, header.size, SEEK_CUR); /* Seek past store */
lseek (rpm_fd, 16 * header.entries, SEEK_CUR); /* Seek past index entries */
lseek (rpm_fd, header.size, SEEK_CUR); /* Seek past store */
}
/* No getopt required */
extern int rpm2cpio_main(int argc, char **argv)
{
struct rpm_lead lead;
int gunzip_pid;
FILE *rpmfile, *cpiofile;
int rpm_fd;
unsigned char magic[2];
if (argc == 1) {
rpmfile = stdin;
rpm_fd = fileno(stdin);
} else {
rpmfile = xfopen(argv[1], "r");
/* set the buffer size */
setvbuf(rpmfile, NULL, _IOFBF, 0x8000);
rpm_fd = xopen(argv[1], O_RDONLY);
}
xread_all(rpm_fd, &lead, sizeof(struct rpm_lead));
if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) {
error_msg_and_die("Invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
}
fread (&lead, sizeof(struct rpm_lead), 1, rpmfile);
if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) error_msg_and_die("Invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
/* Skip the signature header */
skip_header(rpmfile);
fseek(rpmfile, (8 - (ftell(rpmfile) % 8)) % 8, SEEK_CUR); /* Pad to 8 byte boundary */
skip_header(rpm_fd);
data_align(rpm_fd, lseek(rpm_fd, 0, SEEK_CUR), 8);
/* Skip the main header */
skip_header(rpmfile);
skip_header(rpm_fd);
xread_all(rpm_fd, &magic, 2);
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
error_msg_and_die("Invalid gzip magic");
}
cpiofile = gz_open(rpmfile, &gunzip_pid);
check_header_gzip(rpm_fd);
if (inflate(rpm_fd, fileno(stdout)) != 0) {
error_msg("Error inflating");
}
check_trailer_gzip(rpm_fd);
close(rpm_fd);
copyfd(fileno(cpiofile), fileno(stdout));
gz_close(gunzip_pid);
fclose(rpmfile);
return 0;
}
+142 -153
View File
@@ -115,7 +115,7 @@ struct TarBallInfo {
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 */
const llist_t *excludeList; /* List of files to not include */
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
};
@@ -244,12 +244,10 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
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)
strcpy(header.uname, "root");
my_getgrgid(header.gname, statbuf->st_gid);
if (!*header.uname)
if (my_getpwuid(header.uname, statbuf->st_uid) == NULL)
strcpy(header.uname, "root");
if (my_getgrgid(header.gname, statbuf->st_gid) == NULL)
strcpy(header.gname, "root");
if (tbInfo->hlInfo) {
/* This is a hard link */
@@ -304,7 +302,7 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
if ((size =
full_write(tbInfo->tarFd, (char *) &header,
sizeof(struct TarHeader))) < 0) {
error_msg(io_error, real_name, strerror(errno));
error_msg(io_error, real_name);
return (FALSE);
}
/* Pad the header up to the tar block size */
@@ -325,16 +323,15 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
}
# if defined CONFIG_FEATURE_TAR_EXCLUDE
static inline int exclude_file(char **excluded_files, const char *file)
static inline int exclude_file(const llist_t *excluded_files, const char *file)
{
int i;
if (excluded_files == NULL)
if (excluded_files == NULL) {
return 0;
}
for (i = 0; excluded_files[i] != NULL; i++) {
if (excluded_files[i][0] == '/') {
if (fnmatch(excluded_files[i], file,
while (excluded_files) {
if (excluded_files->data[0] == '/') {
if (fnmatch(excluded_files->data, file,
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
return 1;
} else {
@@ -342,11 +339,12 @@ static inline 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->data, p,
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
return 1;
}
}
excluded_files = excluded_files->link;
}
return 0;
@@ -428,7 +426,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
/* 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));
perror_msg("%s: Cannot open", fileName);
return (FALSE);
}
@@ -436,13 +434,13 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
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));
error_msg(io_error, fileName);
return (FALSE);
}
readSize += size;
}
if (size == -1) {
error_msg(io_error, fileName, strerror(errno));
error_msg(io_error, fileName);
return (FALSE);
}
/* Pad the file up to the tar block size */
@@ -455,8 +453,8 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
return (TRUE);
}
static inline int writeTarFile(const char *tarName, int verboseFlag,
char **argv, char **excludeList, int gzip)
static inline int writeTarFile(const char *tarName, const int verboseFlag,
const llist_t *include, const llist_t *exclude, const int gzip)
{
#ifdef CONFIG_FEATURE_TAR_GZIP
int gzipDataPipe[2] = { -1, -1 };
@@ -471,11 +469,12 @@ static inline int writeTarFile(const char *tarName, int verboseFlag,
tbInfo.hlInfoHead = NULL;
/* Make sure there is at least one file to tar up. */
if (*argv == NULL)
if (include == NULL) {
error_msg_and_die("Cowardly refusing to create an empty archive");
}
/* Open the tar file for writing. */
if (tarName == NULL) {
if (tarName == NULL || (tarName[0] == '-' && tarName[1] == '\0')) {
tbInfo.tarFd = fileno(stdout);
tbInfo.verboseFlag = verboseFlag ? 2 : 0;
} else {
@@ -484,7 +483,7 @@ static inline int writeTarFile(const char *tarName, int verboseFlag,
}
if (tbInfo.tarFd < 0) {
perror_msg("Error opening '%s'", tarName);
perror_msg("%s: Cannot open", tarName);
freeHardLinkInfo(&tbInfo.hlInfoHead);
return (FALSE);
}
@@ -492,7 +491,7 @@ static inline int writeTarFile(const char *tarName, int verboseFlag,
/* 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);
#ifdef CONFIG_FEATURE_TAR_GZIP
if (gzip) {
@@ -544,15 +543,16 @@ static inline int writeTarFile(const char *tarName, int verboseFlag,
}
#endif
tbInfo.excludeList = excludeList;
tbInfo.excludeList = exclude;
/* Read the directory/files and iterate over them one at a time */
while (*argv != NULL) {
if (!recursive_action(*argv++, TRUE, FALSE, FALSE,
while (include) {
if (!recursive_action(include->data, TRUE, FALSE, FALSE,
writeFileToTarball, writeFileToTarball,
(void *) &tbInfo)) {
errorFlag = TRUE;
}
include = include->link;
}
/* Write two empty blocks to the end of the archive */
for (size = 0; size < (2 * TAR_BLOCK_SIZE); size++) {
@@ -582,127 +582,111 @@ static inline int writeTarFile(const char *tarName, int verboseFlag,
}
#endif /* tar_create */
void append_file_to_list(const char *new_name, char ***list, int *list_count)
#ifdef CONFIG_FEATURE_TAR_EXCLUDE
static const llist_t *append_file_list_to_list(const char *filename, const llist_t *list)
{
*list = realloc(*list, sizeof(char *) * (*list_count + 2));
(*list)[*list_count] = xstrdup(new_name);
(*list_count)++;
(*list)[*list_count] = NULL;
}
void append_file_list_to_list(char *filename, char ***name_list,
int *num_of_entries)
{
FILE *src_stream;
FILE *src_stream = xfopen(filename, "r");
char *line;
src_stream = xfopen(filename, "r");
while ((line = get_line_from_file(src_stream)) != NULL) {
while((line = get_line_from_file(src_stream)) != NULL) {
chomp(line);
append_file_to_list(line, name_list, num_of_entries);
free(line);
list = add_to_list(list, line);
}
fclose(src_stream);
return (list);
}
#endif
int tar_main(int argc, char **argv)
{
enum untar_funct_e {
/* This is optional */
untar_unzip = 1,
/* Require one and only one of these */
untar_list = 2,
untar_create = 4,
untar_extract = 8
};
FILE *src_stream = NULL;
FILE *uncompressed_stream = NULL;
char **include_list = NULL;
char **exclude_list = NULL;
char *src_filename = NULL;
char *dst_prefix = NULL;
int opt;
unsigned short untar_funct = 0;
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
#ifdef CONFIG_FEATURE_TAR_GZIP
int gunzip_pid;
int gz_fd = 0;
char (*get_header_ptr)(archive_handle_t *) = get_header_tar;
#endif
archive_handle_t *tar_handle;
int opt;
char *base_dir = NULL;
char *tar_filename = "-";
if (argc < 2) {
show_usage();
}
#ifdef CONFIG_FEATURE_TAR_CREATE
unsigned char tar_create = FALSE;
#endif
/* 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;
}
if (argc < 2) {
show_usage();
}
/* Initialise default values */
tar_handle = init_handle();
tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS;
while ((opt = getopt(argc, argv, "ctxT:X:C:f:Opvz")) != -1) {
switch (opt) {
/* One and only one of these is required */
#ifdef CONFIG_FEATURE_TAR_CREATE
case 'c':
untar_funct_required |= untar_create;
tar_create = TRUE;
break;
#endif
case 't':
untar_funct_required |= untar_list;
extract_function |= extract_list | extract_unconditional;
if ((tar_handle->action_header == header_list) ||
(tar_handle->action_header == header_verbose_list)) {
tar_handle->action_header = header_verbose_list;
} else {
tar_handle->action_header = header_list;
}
break;
case 'x':
untar_funct_required |= untar_extract;
extract_function |=
(extract_all_to_fs | extract_unconditional |
extract_create_leading_dirs);
tar_handle->action_data = data_extract_all;
break;
/* 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);
tar_handle->reject =
append_file_list_to_list(optarg, tar_handle->reject);
break;
#endif
case 'T':
/* 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> */
/* Make sure dst_prefix ends in a '/' */
dst_prefix = concat_path_file(optarg, "/");
base_dir = optarg;
break;
case 'f': /* archive filename */
if (strcmp(optarg, "-") == 0) {
src_filename = NULL;
} else {
src_filename = xstrdup(optarg);
}
tar_filename = optarg;
break;
case 'O':
extract_function |= extract_to_stdout;
case 'O': /* To stdout */
tar_handle->action_data = data_extract_to_stdout;
break;
case 'p':
tar_handle->flags |= ARCHIVE_PRESERVE_DATE;
break;
case 'v':
extract_function |= extract_verbose_list;
if ((tar_handle->action_header == header_list) ||
(tar_handle->action_header == header_verbose_list)) {
tar_handle->action_header = header_verbose_list;
} else {
tar_handle->action_header = header_list;
}
break;
#ifdef CONFIG_FEATURE_TAR_GZIP
case 'z':
untar_funct |= untar_unzip;
get_header_ptr = get_header_tar_gz;
break;
#endif
#ifdef CONFIG_FEATURE_TAR_BZIP2
/* Not enabled yet */
case 'j':
archive_handle->archive_action = bunzip2;
break;
#endif
default:
@@ -710,77 +694,82 @@ int tar_main(int argc, char **argv)
}
}
/* Make sure the valid arguments were passed */
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)) {
error_msg_and_die("You may not specify more than one `ctx' option.");
}
untar_funct |= untar_funct_required;
/* Setup an array of filenames to work with */
while (optind < argc) {
append_file_to_list(argv[optind], &include_list, &include_list_count);
/* Check if we are reading from stdin */
if ((argv[optind]) && (*argv[optind] == '-')) {
/* Default is to read from stdin, so just skip to next arg */
optind++;
}
if (extract_function & (extract_list | extract_all_to_fs)) {
if (dst_prefix == NULL) {
dst_prefix = xstrdup("./");
}
/* Setup the source of the tar data */
if (src_filename != NULL) {
src_stream = xfopen(src_filename, "r");
} else {
src_stream = stdin;
}
#ifdef CONFIG_FEATURE_TAR_GZIP
/* Get a binary tree of all the tar file headers */
if (untar_funct & untar_unzip) {
uncompressed_stream = gz_open(src_stream, &gunzip_pid);
} else
#endif /* CONFIG_FEATURE_TAR_GZIP */
uncompressed_stream = src_stream;
/* Setup an array of filenames to work with */
/* TODO: This is the same as in ar, seperate function ? */
while (optind < argc) {
#if 0
char absolute_path[PATH_MAX];
realpath(argv[optind], absolute_path);
tar_handle->accept = add_to_list(tar_handle->accept, absolute_path);
#endif
tar_handle->accept = add_to_list(tar_handle->accept, argv[optind]);
optind++;
/* extract or list archive */
unarchive(uncompressed_stream, stdout, &get_header_tar,
extract_function, dst_prefix, include_list, exclude_list);
fclose(uncompressed_stream);
}
if ((tar_handle->accept) || (tar_handle->reject)) {
tar_handle->filter = filter_accept_reject_list;
}
if ((base_dir) && (chdir(base_dir))) {
perror_msg_and_die("Couldnt chdir");
}
#ifdef CONFIG_FEATURE_TAR_CREATE
/* create an archive */
else if (untar_funct & untar_create) {
if (tar_create == TRUE) {
int verboseFlag = FALSE;
int gzipFlag = FALSE;
#ifdef CONFIG_FEATURE_TAR_GZIP
if (untar_funct & untar_unzip)
# ifdef CONFIG_FEATURE_TAR_GZIP
if (get_header_ptr == get_header_tar_gz) {
gzipFlag = TRUE;
}
# endif /* CONFIG_FEATURE_TAR_GZIP */
#endif /* CONFIG_FEATURE_TAR_GZIP */
if (extract_function & extract_verbose_list)
if (tar_handle->action_header == header_verbose_list) {
verboseFlag = TRUE;
writeTarFile(src_filename, verboseFlag, include_list, exclude_list,
gzipFlag);
}
#endif /* CONFIG_FEATURE_TAR_CREATE */
/* Cleanups */
}
writeTarFile(tar_filename, verboseFlag, tar_handle->accept,
tar_handle->reject, gzipFlag);
} else
#endif /* CONFIG_FEATURE_TAR_CREATE */
{
if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) {
tar_handle->src_fd = fileno(stdin);
} else {
tar_handle->src_fd = xopen(tar_filename, O_RDONLY);
}
#ifdef CONFIG_FEATURE_TAR_GZIP
if (!(untar_funct & untar_create) && (untar_funct & untar_unzip)) {
fclose(src_stream);
close(gz_fd);
gz_close(gunzip_pid);
if (get_header_ptr == get_header_tar_gz) {
get_header_tar_gz(tar_handle);
} else
#endif /* CONFIG_FEATURE_TAR_CREATE */
while (get_header_tar(tar_handle) == EXIT_SUCCESS);
/* Ckeck that every file that should have been extracted was */
while (tar_handle->accept) {
if (find_list_entry(tar_handle->reject, tar_handle->accept->data) == NULL) {
if (find_list_entry(tar_handle->passed, tar_handle->accept->data) == NULL) {
error_msg_and_die("%s: Not found in archive\n", tar_handle->accept->data);
}
}
tar_handle->accept = tar_handle->accept->link;
}
}
#endif /* CONFIG_FEATURE_TAR_GZIP */
#ifdef CONFIG_FEATURE_CLEAN_UP
if (src_filename) {
free(src_filename);
if (tar_handle->src_fd != fileno(stdin)) {
close(tar_handle->src_fd);
}
#endif
return (EXIT_SUCCESS);
#endif /* CONFIG_FEATURE_CLEAN_UP */
return(EXIT_SUCCESS);
}
+191 -41
View File
@@ -20,6 +20,10 @@
*
*/
/* For reference to format see http://www.pkware.com/support/appnote.html */
/* TODO Endian issues, exclude, should we accept input from stdin ? */
#include <fcntl.h>
#include <getopt.h>
#include <stdlib.h>
@@ -28,67 +32,213 @@
#include "unarchive.h"
#include "busybox.h"
#define ZIP_FILEHEADER_MAGIC 0x04034b50
#define ZIP_CDS_MAGIC 0x02014b50
#define ZIP_CDS_END_MAGIC 0x06054b50
#define ZIP_DD_MAGIC 0x08074b50
extern unsigned int gunzip_crc;
extern unsigned int gunzip_bytes_out;
static void header_list_unzip(const file_header_t *file_header)
{
printf(" inflating: %s\n", file_header->name);
}
static void header_verbose_list_unzip(const file_header_t *file_header)
{
unsigned int dostime = (unsigned int) file_header->mtime;
/* can printf arguments cut of the decade component ? */
unsigned short year = 1980 + ((dostime & 0xfe000000) >> 25);
while (year >= 100) {
year -= 100;
}
printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
(unsigned int) file_header->size,
(dostime & 0x01e00000) >> 21,
(dostime & 0x001f0000) >> 16,
year,
(dostime & 0x0000f800) >> 11,
(dostime & 0x000007e0) >> 5,
file_header->name);
}
extern int unzip_main(int argc, char **argv)
{
FILE *src_stream;
int extract_function = extract_all_to_fs | extract_create_leading_dirs;
char **extract_names = NULL;
char **exclude_names = NULL;
int opt = 0;
int num_of_entries = 0;
int exclude = 0;
char *outdir = "./";
FILE *msgout = stdout;
union {
unsigned char raw[26];
struct {
unsigned short version; /* 0-1 */
unsigned short flags; /* 2-3 */
unsigned short method; /* 4-5 */
unsigned short modtime; /* 6-7 */
unsigned short moddate; /* 8-9 */
unsigned int crc32 __attribute__ ((packed)); /* 10-13 */
unsigned int cmpsize __attribute__ ((packed));; /* 14-17 */
unsigned int ucmpsize __attribute__ ((packed));; /* 18-21 */
unsigned short filename_len; /* 22-23 */
unsigned short extra_len; /* 24-25 */
} formated __attribute__ ((packed));
} zip_header;
while ((opt = getopt(argc, argv, "lnopqxd:")) != -1) {
archive_handle_t *archive_handle;
unsigned int total_size = 0;
unsigned int total_entries = 0;
char *base_dir = NULL;
int opt = 0;
/* Initialise */
archive_handle = init_handle();
archive_handle->action_data = NULL;
archive_handle->action_header = header_list_unzip;
while ((opt = getopt(argc, argv, "lnopqd:")) != -1) {
switch (opt) {
case 'l':
extract_function |= extract_verbose_list;
extract_function ^= extract_all_to_fs;
case 'l': /* list */
archive_handle->action_header = header_verbose_list_unzip;
archive_handle->action_data = data_skip;
break;
case 'n':
case 'n': /* never overwright existing files */
break;
case 'o':
extract_function |= extract_unconditional;
archive_handle->flags = ARCHIVE_EXTRACT_UNCONDITIONAL;
break;
case 'p':
extract_function |= extract_to_stdout;
extract_function ^= extract_all_to_fs;
/* FALLTHROUGH */
case 'q':
msgout = xfopen("/dev/null", "w");
case 'p': /* extract files to stdout */
archive_handle->action_data = data_extract_to_stdout;
break;
case 'd':
outdir = xstrdup(optarg);
strcat(outdir, "/");
case 'q': /* Extract files quietly */
archive_handle->action_header = header_skip;
break;
case 'x':
exclude = 1;
case 'd': /* Extract files to specified base directory*/
base_dir = optarg;
break;
#if 0
case 'x': /* Exclude the specified files */
archive_handle->filter = filter_accept_reject_list;
break;
#endif
default:
show_usage();
}
}
if (optind == argc) {
if (argc == optind) {
show_usage();
}
if (*argv[optind] == '-') src_stream = stdin;
else src_stream = xfopen(argv[optind++], "r");
printf("Archive: %s\n", argv[optind]);
if (archive_handle->action_header == header_verbose_list_unzip) {
printf(" Length Date Time Name\n");
printf(" -------- ---- ---- ----\n");
}
if (*argv[optind] == '-') {
archive_handle->src_fd = fileno(stdin);
} else {
archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
}
if ((base_dir) && (chdir(base_dir))) {
perror_msg_and_die("Couldnt chdir");
}
while (optind < argc) {
if (exclude) {
exclude_names = xrealloc(exclude_names, sizeof(char *) * (num_of_entries + 2));
exclude_names[num_of_entries] = xstrdup(argv[optind]);
} else {
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
extract_names[num_of_entries] = xstrdup(argv[optind]);
}
num_of_entries++;
if (exclude) exclude_names[num_of_entries] = NULL;
else extract_names[num_of_entries] = NULL;
archive_handle->filter = filter_accept_list;
archive_handle->accept = add_to_list(archive_handle->accept, argv[optind]);
optind++;
}
unarchive(src_stream, msgout, &get_header_zip, extract_function, outdir, extract_names, exclude_names);
return EXIT_SUCCESS;
while (1) {
unsigned int magic;
int dst_fd;
/* TODO Endian issues */
xread_all(archive_handle->src_fd, &magic, 4);
archive_handle->offset += 4;
if (magic == ZIP_CDS_MAGIC) {
break;
}
else if (magic != ZIP_FILEHEADER_MAGIC) {
error_msg_and_die("Invlaide zip magic");
}
/* Read the file header */
xread_all(archive_handle->src_fd, zip_header.raw, 26);
archive_handle->offset += 26;
archive_handle->file_header->mode = S_IFREG | 0777;
if (zip_header.formated.method != 8) {
error_msg_and_die("Unsupported compression method %d\n", zip_header.formated.method);
}
/* Read filename */
archive_handle->file_header->name = xmalloc(zip_header.formated.filename_len + 1);
xread_all(archive_handle->src_fd, archive_handle->file_header->name, zip_header.formated.filename_len);
archive_handle->offset += zip_header.formated.filename_len;
archive_handle->file_header->name[zip_header.formated.filename_len] = '\0';
/* Skip extra header bits */
archive_handle->file_header->size = zip_header.formated.extra_len;
data_skip(archive_handle);
archive_handle->offset += zip_header.formated.extra_len;
/* Handle directories */
archive_handle->file_header->mode = S_IFREG | 0777;
if (last_char_is(archive_handle->file_header->name, '/')) {
archive_handle->file_header->mode ^= S_IFREG;
archive_handle->file_header->mode |= S_IFDIR;
}
/* Data section */
archive_handle->file_header->size = zip_header.formated.cmpsize;
if (archive_handle->action_data) {
archive_handle->action_data(archive_handle);
} else {
dst_fd = xopen(archive_handle->file_header->name, O_WRONLY | O_CREAT);
inflate(archive_handle->src_fd, dst_fd);
close(dst_fd);
chmod(archive_handle->file_header->name, archive_handle->file_header->mode);
/* Validate decompression - crc */
if (zip_header.formated.crc32 != (gunzip_crc ^ 0xffffffffL)) {
error_msg("Invalid compressed data--crc error");
}
/* Validate decompression - size */
if (gunzip_bytes_out != zip_header.formated.ucmpsize) {
error_msg("Invalid compressed data--length error");
}
}
/* local file descriptor section */
archive_handle->offset += zip_header.formated.cmpsize;
/* This ISNT unix time */
archive_handle->file_header->mtime = zip_header.formated.modtime | (zip_header.formated.moddate << 16);
archive_handle->file_header->size = zip_header.formated.ucmpsize;
total_size += archive_handle->file_header->size;
total_entries++;
archive_handle->action_header(archive_handle->file_header);
/* Data descriptor section */
if (zip_header.formated.flags & 4) {
/* skip over duplicate crc, compressed size and uncompressed size */
unsigned short i;
for (i = 0; i != 12; i++) {
xread_char(archive_handle->src_fd);
}
archive_handle->offset += 12;
}
}
/* Central directory section */
if (archive_handle->action_header == header_verbose_list_unzip) {
printf(" -------- -------\n");
printf("%9d %d files\n", total_size, total_entries);
}
return(EXIT_SUCCESS);
}
+1 -1
View File
@@ -81,7 +81,7 @@ int dumpkmap_main(int argc, char **argv)
ke.kb_table = i;
if (ioctl(fd, KDGKBENT, &ke) < 0) {
error_msg("ioctl returned: %s, %s, %s, %xqq", strerror(errno),(char *)&ke.kb_index,(char *)&ke.kb_table,(int)&ke.kb_value);
error_msg("ioctl returned: %m, %s, %s, %xqq", (char *)&ke.kb_index,(char *)&ke.kb_table,(int)&ke.kb_value);
}
else {
write(1,(void*)&ke.kb_value,2);
+29 -17
View File
@@ -5,6 +5,9 @@
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
* Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
*
* Reworked by (C) 2002 Vladimir Oleynik <dzo@simtreas.ru>
* to correctly parse '-rwxgoa'
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -31,7 +34,7 @@
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{
if (!parse_mode((char *)junk, &(statbuf->st_mode)))
error_msg_and_die("internal error");
error_msg_and_die( "unknown mode: %s", (char *)junk);
if (chmod(fileName, statbuf->st_mode) == 0)
return (TRUE);
perror(fileName);
@@ -40,35 +43,44 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
int chmod_main(int argc, char **argv)
{
int i;
int opt;
int recursiveFlag = FALSE;
int modeind = 0; /* Index of the mode argument in `argv'. */
char *smode;
static const char chmod_modes[] = "Rrwxstugoa,+-=";
/* do normal option parsing */
while ((opt = getopt(argc, argv, "R")) > 0) {
switch (opt) {
case 'R':
recursiveFlag = TRUE;
while (1) {
int thisind = optind ? optind : 1;
opt = getopt(argc, argv, chmod_modes);
if (opt == EOF)
break;
default:
smode = strchr(chmod_modes, opt);
if(smode == NULL)
show_usage();
if(smode == chmod_modes) { /* 'R' */
recursiveFlag = TRUE;
} else {
if (modeind != 0 && modeind != thisind)
show_usage();
modeind = thisind;
}
}
if (argc > optind && argc > 2 && argv[optind]) {
/* Parse the specified mode */
mode_t mode;
if (! parse_mode(argv[optind], &mode)) {
error_msg_and_die( "unknown mode: %s", argv[optind]);
}
} else {
if (modeind == 0)
modeind = optind++;
opt = optind;
if (opt >= argc) {
error_msg_and_die(too_few_args);
}
smode = argv[modeind];
/* Ok, ready to do the deed now */
for (i = optind + 1; i < argc; i++) {
if (! recursive_action (argv[i], recursiveFlag, FALSE, FALSE, fileAction,
fileAction, argv[optind])) {
for (; opt < argc; opt++) {
if (! recursive_action (argv[opt], recursiveFlag, FALSE, FALSE, fileAction,
fileAction, smode)) {
return EXIT_FAILURE;
}
}
+3 -4
View File
@@ -68,8 +68,7 @@ extern int id_main(int argc, char **argv)
my_getgrgid(group, getegid());
}
} else {
strncpy(user, argv[optind], 8);
user[8] = '\0';
safe_strncpy(user, argv[optind], sizeof(user));
gid = my_getpwnamegid(user);
my_getgrgid(group, gid);
}
@@ -78,12 +77,12 @@ extern int id_main(int argc, char **argv)
grnam=my_getgrnam(group);
if (no_group) {
if(name_not_number && user)
if(name_not_number)
puts(user);
else
printf("%ld\n", pwnam);
} else if (no_user) {
if(name_not_number && group)
if(name_not_number)
puts(group);
else
printf("%ld\n", grnam);
+1 -2
View File
@@ -32,8 +32,7 @@ extern int logname_main(int argc, char **argv)
if (argc > 1)
show_usage();
my_getpwuid(user, geteuid());
if (*user) {
if (my_getpwuid(user, geteuid())) {
puts(user);
return EXIT_SUCCESS;
}
+4 -5
View File
@@ -35,7 +35,6 @@ extern int mkdir_main (int argc, char **argv)
{
mode_t mode = -1;
int flags = 0;
int status = 0;
int i, opt;
while ((opt = getopt (argc, argv, "m:p")) != -1) {
@@ -56,9 +55,9 @@ extern int mkdir_main (int argc, char **argv)
if (optind == argc)
show_usage ();
for (i = optind; i < argc; i++)
if (make_directory (argv[i], mode, flags) < 0)
status = 1;
for (i = optind; i < argc; i++) {
make_directory (argv[i], mode, flags);
}
return status;
return(EXIT_SUCCESS);
}
+1 -2
View File
@@ -35,8 +35,7 @@ extern int whoami_main(int argc, char **argv)
if (argc > 1)
show_usage();
my_getpwuid(user, uid);
if (*user) {
if (my_getpwuid(user, uid)) {
puts(user);
return EXIT_SUCCESS;
}
+19
View File
@@ -93,6 +93,25 @@
<td bgcolor="#EEEEE0">
<ul>
<p>
<li><b>18 September 2002 -- BusyBox 0.60.4 released</b>
I am very pleased to announce that the BusyBox 0.60.4
(stable) is now available for download. This is primarily
a bugfix release for the stable series to address all
the problems that have turned up since the last
release. This will be the last release for the 0.60.x series.
I mean it this time -- all further development work will be done
on the development busybox tree, which is quite solid now and
should soon be getting its first real release.
<p>
The <a href="downloads/Changelog.full">changelog</a> has all
the details. As usual you can <a href="downloads">download busybox here</a>.
<p>Have Fun!
<p>
<p>
<li><b>27 April 2002 -- BusyBox 0.60.3 released</b>
+3 -2
View File
@@ -113,7 +113,8 @@ Glenn McGrath <bug1@netconnect.com.au>
Vladimir Oleynik <dzo@simtreas.ru>
cmdedit; ports: ash, stty, traceroute; locale, various fixes
cmdedit; ports: ash, crond, stty, traceroute, telnetd, top;
locale, various fixes
and irreconcilable critic of everything not perfect.
=for html <br>
@@ -166,4 +167,4 @@ Enrique Zanardi <ezanardi@ull.es>
=cut
# $Id: busybox_footer.pod,v 1.5 2001/12/18 14:06:01 andersen Exp $
# $Id: busybox_footer.pod,v 1.7 2002/10/22 12:24:56 andersen Exp $
+14 -14
View File
@@ -55,20 +55,20 @@ terse runtime description of their behavior.
Currently defined functions include:
addgroup, adduser, adjtimex, ar, basename, busybox, cat, chgrp, chmod,
chown, chroot, chvt, clear, cmp, cp, cpio, cut, date, dc, dd, deallocvt,
deluser, df, dirname, dmesg, dos2unix, dpkg, dpkg-deb, du, dumpkmap, dutmp,
echo, expr, false, fbset, fdflush, find, free, freeramdisk, fsck.minix,
getopt, getty, grep, gunzip, gzip, halt, head, hostid, hostname, id,
ifconfig, init, insmod, kill, killall, klogd, length, ln, loadacm,
loadfont, loadkmap, logger, logname, ls, lsmod, makedevs, md5sum, mkdir,
mkfifo, mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc,
nslookup, ping, pivot_root, poweroff, printf, ps, pwd, rdate, readlink,
reboot, renice, reset, rm, rmdir, rmmod, route, rpm2cpio, sed, setkeycodes,
sh, sleep, sort, stty, swapoff, swapon, sync, syslogd, tail, tar, tee,
telnet, test, tftp, touch, tr, true, tty, umount, uname, uniq, unix2dos,
update, uptime, usleep, uudecode, uuencode, watchdog, wc, wget, which,
whoami, xargs, yes, zcat, [
addgroup, adduser, adjtimex, ar, awk, basename, busybox, cat, chgrp,
chmod, chown, chroot, chvt, clear, cmp, cp, cpio, crond, crontab, cut,
date, dc, dd, deallocvt, deluser, df, dirname, dmesg, dos2unix, dpkg,
dpkg-deb, du, dumpkmap, dutmp, echo, expr, false, fbset, fdflush, find,
free, freeramdisk, fsck.minix, getopt, getty, grep, gunzip, gzip, halt,
head, hostid, hostname, id, ifconfig, init, insmod, kill, killall, klogd,
length, ln, loadacm, loadfont, loadkmap, logger, logname, ls, lsmod,
makedevs, md5sum, mkdir, mkfifo, mkfs.minix, mknod, mkswap, mktemp, more,
mount, mt, mv, nc, netstat, nslookup, ping, pivot_root, poweroff, printf,
ps, pwd, rdate, readlink, reboot, renice, reset, rm, rmdir, rmmod, route,
rpm2cpio, sed, setkeycodes, sh, sleep, sort, stty, swapoff, swapon, sync,
syslogd, tail, tar, tee, telnet, telnetd, test, tftp, time, top, touch, tr,
true, tty, umount, uname, uniq, unix2dos, update, uptime, usleep, uudecode,
uuencode, watchdog, wc, wget, which, whoami, xargs, yes, zcat, [
=over 4
+9 -3
View File
@@ -19,7 +19,7 @@
*/
static const char vi_Version[] =
"$Id: vi.c,v 1.23 2002/08/21 13:02:24 aaronl Exp $";
"$Id: vi.c,v 1.24 2002/10/26 10:19:19 andersen Exp $";
/*
* To compile for standalone use:
@@ -2566,8 +2566,14 @@ static Byte get_one_char()
// adding STDIN chars to q
c = readit(); // get the users input
if (last_modifying_cmd != 0) {
// add new char to q
last_modifying_cmd[strlen((char *) last_modifying_cmd)] = c;
int len = strlen((char *) last_modifying_cmd);
if (len + 1 >= BUFSIZ) {
psbs("last_modifying_cmd overrun");
} else {
// add new char to q
last_modifying_cmd[len] = c;
}
}
}
#else /* CONFIG_FEATURE_VI_DOT_CMD */
+28 -18
View File
@@ -3,6 +3,7 @@
# Copyright (c) 2001 David Schleef <ds@schleef.org>
# Copyright (c) 2001 Erik Andersen <andersen@lineo.com>
# Copyright (c) 2001 Stuart Hughes <stuarth@lineo.com>
# Copyright (c) 2002 Steven J. Hill <shill@broadcom.com>
# This program is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
@@ -18,7 +19,7 @@ use File::Find;
my $basedir="";
my $kernel;
my $kernelsyms;
my $stdout=1;
my $stdout=0;
my $verbose=0;
@@ -38,13 +39,13 @@ GetOptions(
if (defined $opt{help}) {
print
"$0 [OPTION]... [basedir]\n",
"\t-h --help\t\tShow this help screen\n",
"\t-b --basedir\t\tModules base directory (defaults to /lib/modules)\n",
"\t-k --kernel\t\tKernel binary for the target\n",
"\t-F --kernelsyms\t\tKernel symbol file\n",
"\t-n --stdout\t\tWrite to stdout instead of modules.dep\n",
"\t-v --verbose\t\tPrint out lots of debugging stuff\n",
" $0 [OPTION]... [basedir]\n",
" -h --help\t\tShow this help screen\n",
" -b --basedir\tModules base directory (defaults to /lib/modules)\n",
" -k --kernel\tKernel binary for the target\n",
" -F --kernelsyms\tKernel symbol file\n",
" -n --stdout\tWrite to stdout instead of <basedir>/modules.dep\n",
" -v --verbose\tPrint out lots of debugging stuff\n",
;
exit 1;
}
@@ -55,6 +56,7 @@ if($basedir !~ m-/lib/modules-) {
# Find the list of .o files living under $basedir
#if ($verbose) { printf "Locating all modules\n"; }
my($ofile) = "";
my($file) = "";
my(@liblist) = ();
find sub {
@@ -127,16 +129,24 @@ foreach $module (keys %$dep) {
}
# resolve the dependancies for each module
foreach $module ( keys %$mod ) {
print "$module:\t";
@sorted = sort bydep keys %{$mod->{$module}};
print join(" \\\n\t",@sorted);
# foreach $m (@sorted ) {
# print "\t$m\n";
# }
print "\n\n";
if ($stdout == 1) {
foreach $module ( keys %$mod ) {
print "$module:\t";
@sorted = sort bydep keys %{$mod->{$module}};
print join(" \\\n\t",@sorted);
print "\n\n";
}
} else {
open(OFILE, ">$basedir/modules.dep");
foreach $module ( keys %$mod ) {
print OFILE "$module:\t";
@sorted = sort bydep keys %{$mod->{$module}};
print OFILE join(" \\\n\t",@sorted);
print OFILE "\n\n";
}
}
sub bydep
{
foreach my $f ( keys %{$mod->{$b}} ) {
@@ -158,7 +168,7 @@ depmod.pl - a cross platform script to generate kernel module dependency
=head1 SYNOPSIS
depmod.pl [OPTION]... [FILE]...
depmod.pl [OPTION]... [basedir]...
Example:
@@ -223,5 +233,5 @@ David Schleef <ds@schleef.org>
=cut
# $Id: depmod.pl,v 1.1 2001/07/30 19:32:03 andersen Exp $
# $Id: depmod.pl,v 1.2 2002/10/08 21:33:51 sjhill Exp $
@@ -1,7 +1,7 @@
#!/bin/sh
# Sample udhcpc renew script
RESOLV_CONF="/etc/resolv.conf"
RESOLV_CONF="/etc/udhcpc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
File renamed without changes.
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
# Sample udhcpc nak script
echo Received a NAK: $message
@@ -1,7 +1,7 @@
#!/bin/sh
# Sample udhcpc bound script
RESOLV_CONF="/etc/resolv.conf"
RESOLV_CONF="/etc/udhcpc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
@@ -27,4 +27,4 @@ for i in $dns
do
echo adding dns $i
echo nameserver $i >> $RESOLV_CONF
done
done
@@ -4,4 +4,4 @@
# common initialization first, especially if more dhcp event notifications
# are added.
exec /usr/share/udhcpc/default.$1
exec /usr/share/udhcpc/sample.$1
+39
View File
@@ -0,0 +1,39 @@
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
RESOLV_CONF="/etc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
case "$1" in
deconfig)
/sbin/ifconfig $interface 0.0.0.0
;;
renew|bound)
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ] ; then
echo "deleting routers"
while route del default gw 0.0.0.0 dev $interface ; do
:
done
for i in $router ; do
route add default gw $i dev $interface
done
fi
echo -n > $RESOLV_CONF
[ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
for i in $dns ; do
echo adding dns $i
echo nameserver $i >> $RESOLV_CONF
done
;;
esac
exit 0
+116
View File
@@ -0,0 +1,116 @@
# Sample udhcpd configuration file (/etc/udhcpd.conf)
# The start and end of the IP lease block
start 192.168.0.20 #default: 192.168.0.20
end 192.168.0.254 #default: 192.168.0.254
# The interface that udhcpd will use
interface eth0 #default: eth0
# The maximim number of leases (includes addressesd reserved
# by OFFER's, DECLINE's, and ARP conficts
#max_leases 254 #default: 254
# If remaining is true (default), udhcpd will store the time
# remaining for each lease in the udhcpd leases file. This is
# for embedded systems that cannot keep time between reboots.
# If you set remaining to no, the absolute time that the lease
# expires at will be stored in the dhcpd.leases file.
#remaining yes #default: yes
# The time period at which udhcpd will write out a dhcpd.leases
# file. If this is 0, udhcpd will never automatically write a
# lease file. (specified in seconds)
#auto_time 7200 #default: 7200 (2 hours)
# The amount of time that an IP will be reserved (leased) for if a
# DHCP decline message is received (seconds).
#decline_time 3600 #default: 3600 (1 hour)
# The amount of time that an IP will be reserved (leased) for if an
# ARP conflct occurs. (seconds
#conflict_time 3600 #default: 3600 (1 hour)
# How long an offered address is reserved (leased) in seconds
#offer_time 60 #default: 60 (1 minute)
# If a lease to be given is below this value, the full lease time is
# instead used (seconds).
#min_lease 60 #defult: 60
# The location of the leases file
#lease_file /var/lib/misc/udhcpd.leases #defualt: /var/lib/misc/udhcpd.leases
# The location of the pid file
#pidfile /var/run/udhcpd.pid #default: /var/run/udhcpd.pid
# Everytime udhcpd writes a leases file, the below script will be called.
# Useful for writing the lease file to flash every few hours.
#notify_file #default: (no script)
#notify_file dumpleases # <--- usefull for debugging
# The following are bootp specific options, setable by udhcpd.
#siaddr 192.168.0.22 #default: 0.0.0.0
#sname zorak #default: (none)
#boot_file /var/nfs_root #default: (none)
# The remainer of options are DHCP options and can be specifed with the
# keyword 'opt' or 'option'. If an option can take multiple items, such
# as the dns option, they can be listed on the same line, or multiple
# lines. The only option with a default is 'lease'.
#Examles
opt dns 192.168.10.2 192.168.10.10
option subnet 255.255.255.0
opt router 192.168.10.2
opt wins 192.168.10.10
option dns 129.219.13.81 # appened to above DNS servers for a total of 3
option domain local
option lease 864000 # 10 days of seconds
# Currently supported options, for more info, see options.c
#subnet
#timezone
#router
#timesvr
#namesvr
#dns
#logsvr
#cookiesvr
#lprsvr
#bootsize
#domain
#swapsvr
#rootpath
#ipttl
#mtu
#broadcast
#wins
#lease
#ntpsrv
#tftp
#bootfile
+16 -1
View File
@@ -107,6 +107,12 @@
#ifdef CONFIG_CPIO
APPLET(cpio, cpio_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CROND
APPLET(crond, crond_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CRONTAB
APPLET(crontab, crontab_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_CUT
APPLET(cut, cut_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
@@ -152,6 +158,9 @@
#ifdef CONFIG_DUMPKMAP
APPLET(dumpkmap, dumpkmap_main, _BB_DIR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DUMPLEASES
APPLET(dumpleases, dumpleases_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_DUTMP
APPLET(dutmp, dutmp_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)
#endif
@@ -464,6 +473,9 @@
#ifdef CONFIG_TELNET
APPLET(telnet, telnet_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TELNETD
APPLET(telnetd, telnetd_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_TEST
APPLET(test, test_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
@@ -492,7 +504,10 @@
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)
APPLET(udhcpc, udhcpc_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_UDHCPD
APPLET(udhcpd, udhcpd_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)
#endif
#ifdef CONFIG_UMOUNT
APPLET(umount, umount_main, _BB_DIR_BIN, _BB_SUID_NEVER)
+30 -9
View File
@@ -83,8 +83,6 @@ char *strtok_r(char *s, const char *delim, char **ptrptr);
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
extern void show_usage(void) __attribute__ ((noreturn));
extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
@@ -129,7 +127,7 @@ extern void write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags);
extern void erase_mtab(const char * name);
extern long atoi_w_units (const char *cp);
extern long* find_pid_by_name( char* pidName);
extern long* find_pid_by_name( const char* pidName);
extern char *find_real_root_device_name(const char* name);
extern char *get_line_from_file(FILE *file);
extern void print_file(FILE *file);
@@ -167,8 +165,8 @@ extern unsigned long parse_number(const char *numstr,
* increases target size and is often not needed embedded systems. */
extern long my_getpwnam(const char *name);
extern long my_getgrnam(const char *name);
extern void my_getpwuid(char *name, long uid);
extern void my_getgrgid(char *group, long gid);
extern char * my_getpwuid(char *name, long uid);
extern char * my_getgrgid(char *group, long gid);
extern long my_getpwnamegid(const char *name);
extern int device_open(char *device, int mode);
@@ -228,10 +226,8 @@ extern long arith (const char *startbuf, int *errcode);
int read_package_field(const char *package_buffer, char **field_name, char **field_value);
char *fgets_str(FILE *file, const char *terminating_string);
extern int inflate(FILE *in, FILE *out);
extern int unzip(FILE *l_in_file, FILE *l_out_file);
extern void gz_close(int gunzip_pid);
extern FILE *gz_open(FILE *compressed_file, int *pid);
extern int uncompress(int fd_in, int fd_out);
extern int inflate(int in, int out);
extern struct hostent *xgethostbyname(const char *name);
extern struct hostent *xgethostbyname2(const char *name, int af);
@@ -335,4 +331,29 @@ 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);
extern int xopen(const char *pathname, int flags);
extern ssize_t xread(int fd, void *buf, size_t count);
extern ssize_t xread_all_eof(int fd, void *buf, size_t count);
extern void xread_all(int fd, void *buf, size_t count);
extern unsigned char xread_char(int fd);
typedef struct {
int pid;
char user[9];
char state[4];
unsigned long rss;
int ppid;
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
unsigned pcpu;
unsigned long stime, utime;
#endif
char *cmd;
/* basename of executable file in call to exec(2),
size from kernel headers */
char short_cmd[16];
} procps_status_t;
extern procps_status_t * procps_scan(int save_user_arg0);
#endif /* __LIBCONFIG_H__ */
+81 -31
View File
@@ -1,21 +1,19 @@
#include <stdio.h> /* for FILE */
#include <unistd.h> /* for off_t */
#ifndef __UNARCHIVE_H__
#define __UNARCHIVE_H__
enum extract_functions_e {
extract_verbose_list = 1,
extract_list = 2,
extract_one_to_buffer = 4,
extract_to_stdout = 8,
extract_all_to_fs = 16,
extract_preserve_date = 32,
extract_data_tar_gz = 64,
extract_control_tar_gz = 128,
extract_unzip_only = 256,
extract_unconditional = 512,
extract_create_leading_dirs = 1024,
extract_quiet = 2048,
extract_exclude_list = 4096
};
#define ARCHIVE_PRESERVE_DATE 1
#define ARCHIVE_CREATE_LEADING_DIRS 2
#define ARCHIVE_EXTRACT_UNCONDITIONAL 4
#define ARCHIVE_EXTRACT_QUIET 8
#include <sys/types.h>
typedef struct gunzip_s {
unsigned short buffer_count;
unsigned char *buffer;
unsigned int crc;
unsigned int count;
} gunzip_t;
typedef struct file_headers_s {
char *name;
@@ -26,23 +24,75 @@ typedef struct file_headers_s {
mode_t mode;
time_t mtime;
dev_t device;
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);
typedef struct llist_s {
const char *data;
const struct llist_s *link;
} llist_t;
void seek_sub_file(FILE * src_stream, const int count);
typedef struct archive_handle_s {
/* define if the header and data compenent should processed */
char (*filter)(const llist_t *, const llist_t *, const char *);
const llist_t *accept;
const llist_t *reject;
const llist_t *passed; /* List of files that have successfully been worked on */
extern off_t archive_offset;
/* Contains the processed header entry */
file_header_t *file_header;
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);
/* process the header component, e.g. tar -t */
void (*action_header)(const file_header_t *);
char *deb_extract(const char *package_filename, FILE * out_stream,
const int extract_function, const char *prefix,
const char *filename);
/* process the data componenet, e.g. extract to filesystem */
void (*action_data)(struct archive_handle_s *);
char (*action_data_subarchive)(struct archive_handle_s *);
/* Contains the handle to a sub archive */
struct archive_handle_s *sub_archive;
/* The raw stream as read from disk or stdin */
int src_fd;
/* Count the number of bytes processed */
off_t offset;
/* Temperary storage */
char *buffer;
/* Misc. stuff */
unsigned char flags;
} archive_handle_t;
extern archive_handle_t *init_handle(void);
extern char filter_accept_all(const llist_t *accept_list, const llist_t *reject_list, const char *key);
extern char filter_accept_list(const llist_t *accept_list, const llist_t *reject_list, const char *key);
extern char filter_accept_reject_list(const llist_t *accept_list, const llist_t *reject_list, const char *key);
extern void unpack_ar_archive(archive_handle_t *ar_archive);
extern void data_skip(archive_handle_t *archive_handle);
extern void data_extract_all(archive_handle_t *archive_handle);
extern void data_extract_all_prefix(archive_handle_t *archive_handle);
extern void data_extract_to_stdout(archive_handle_t *archive_handle);
extern void data_extract_to_buffer(archive_handle_t *archive_handle);
extern void header_skip(const file_header_t *file_header);
extern void header_list(const file_header_t *file_header);
extern void header_verbose_list(const file_header_t *file_header);
extern void check_header_gzip(int src_fd);
extern void check_trailer_gzip(int src_fd);
extern char get_header_ar(archive_handle_t *archive_handle);
extern char get_header_tar(archive_handle_t *archive_handle);
extern char get_header_tar_gz(archive_handle_t *archive_handle);
extern void seek_sub_file(int src_fd, unsigned int amount);
extern const unsigned short data_align(const int src_fd, const unsigned int offset, const unsigned short align_to);
extern const llist_t *add_to_list(const llist_t *old_head, const char *new_item);
extern int copy_file_chunk_fd(int src_fd, int dst_fd, unsigned long long chunksize);
extern const llist_t *find_list_entry(const llist_t *list, const char *filename);
#endif
+52 -4
View File
@@ -186,6 +186,30 @@
"\tu\t\tunconditional overwrite\n" \
"\tF\t\tinput from file"
#define crond_trivial_usage \
"-d[#] -c <crondir> -f -b"
#define crond_full_usage \
"\t-d [#] -l [#] -S -L logfile -f -b -c dir\n" \
"\t-d num\tdebug level\n" \
"\t-l num\tlog level (8 - default)\n" \
"\t-S\tlog to syslod (defualt)\n" \
"\t-L file\tlog to file\n" \
"\t-f\trun in fordeground\n" \
"\t-b\trun in background (default)\n" \
"\t-c dir\tworking dir"
#define crontab_trivial_usage \
"crontab [-c dir] {file|-}|[-u|-l|-e|-d user]"
#define crontab_full_usage \
"\tfile <opts> replace crontab from file\n" \
"\t- <opts> replace crontab from stdin\n" \
"\t-u user specify user\n" \
"\t-l [user] list crontab for user\n" \
"\t-e [user] edit crontab for user\n" \
"\t-d [user] delete crontab for user\n" \
"\t-c dir specify crontab directory"
#define cut_trivial_usage \
"[OPTION]... [FILE]..."
#define cut_full_usage \
@@ -385,6 +409,14 @@
#define dumpkmap_example_usage \
"$ dumpkmap > keymap\n"
#define dumpleases_trivial_usage \
"[-r|-a] [-f LEASEFILE]"
#define dumpleases_full_usage \
"Usage: dumpleases -f <file> -[r|a]\n" \
"\t-f,\t--file=FILENAME\tLeases file to load\n" \
"\t-r,\t--remaining\tInterepret lease times as time remaing\n" \
"\t-a,\t--absolute\tInterepret lease times as expire time\n"
#define dutmp_trivial_usage \
"[FILE]"
#define dutmp_full_usage \
@@ -863,7 +895,7 @@
"\n" \
" Unrecognized actions (like initdefault) will cause init to emit an\n" \
" error message, and then go along with its business. All actions are\n" \
" run in the reverse order from how they appear in /etc/inittab.\n" \
" run in the order they appear in /etc/inittab.\n" \
"\n" \
" <process>: \n" \
"\n" \
@@ -1642,8 +1674,8 @@
"Options:\n" \
"-S\t\t\tstart\n"\
"-K\t\t\tstop\n"\
"-b\t\t\tforce process into background (daemonize)\n"\
"-x <executable>\t\tprogram to start/check if it is running\n"\
"-p <pid-file>\t\tpid file to check\n"\
"-u <username>|<uid>\tstop this user's processes\n"\
"-n <process-name>\tstop processes with this name\n"\
"-s <signal>\t\tsignal to send (default 15)\n"\
@@ -1801,6 +1833,14 @@
"Telnet is used to establish interactive communication with another\n"\
"computer over a network using the TELNET protocol."
#define telnetd_trivial_usage \
"[OPTION]"
#define telnetd_full_usage \
"Telnetd listens for incoming TELNET connections on PORT.\n"\
"Options:\n" \
"\t-p PORT\tlisten for connections on PORT (default 23)\n"\
"\t-l LOGIN\texec LOGIN on connect (default /bin/sh)"
#define test_trivial_usage \
"EXPRESSION\n or [ EXPRESSION ]"
#define test_full_usage \
@@ -1937,12 +1977,14 @@
"/dev/tty2\n"
#define udhcpc_trivial_usage \
"[-fqv] [-c CLIENTID] [-H HOSTNAME] [-i INTERFACE]\n[-p file] [-r IP] [-s script]"
"[-fbnqv] [-c CLIENTID] [-H HOSTNAME] [-i INTERFACE]\n[-p pidfile] [-r IP] [-s script]"
#define udhcpc_full_usage \
"\tUsage: udhcpcd [OPTIONS]\n" \
"\tUsage: udhcpc [OPTIONS]\n" \
"\t-c,\t--clientid=CLIENTID\tClient identifier\n" \
"\t-H,\t--hostname=HOSTNAME\tClient hostname\n" \
"\t-h,\t \tAlias for -h\n" \
"\t-f,\t--foreground\tDo not fork after getting lease\n" \
"\t-b,\t--background\tFork to background if lease cannot be immediately negotiated.\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" \
@@ -1951,6 +1993,12 @@
"\t-s,\t--script=file\tRun file at dhcp events (default: /usr/share/udhcpc/default.script)\n" \
"\t-v,\t--version\tDisplay version"
#define udhcpd_trivial_usage \
"[configfile]\n" \
#define udhcpd_full_usage \
"\tUsage: udhcpd [configfile]\n"
#ifdef CONFIG_FEATURE_MOUNT_FORCE
#define USAGE_MOUNT_FORCE(a) a
#else
+10 -20
View File
@@ -232,6 +232,8 @@ static void message(int device, char *fmt, ...)
log_fd = -2;
fprintf(stderr, "Bummer, can't write to log on %s!\n", log);
device = CONSOLE;
} else {
fcntl(log_fd, F_SETFD, FD_CLOEXEC);
}
}
if ((device & LOG) && (log_fd >= 0)) {
@@ -499,12 +501,11 @@ static pid_t run(struct init_action *a)
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();
* group leader */
setsid();
/* Open the new terminal device */
if ((device_open(a->terminal, O_RDWR | O_NOCTTY)) < 0) {
if ((device_open(a->terminal, O_RDWR)) < 0) {
if (stat(a->terminal, &sb) != 0) {
message(LOG | CONSOLE, "\rdevice '%s' does not exist.\n",
a->terminal);
@@ -514,10 +515,6 @@ static pid_t run(struct init_action *a)
_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
@@ -525,11 +522,6 @@ static pid_t run(struct init_action *a)
dup(0);
dup(0);
/* 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)) {
@@ -635,6 +627,7 @@ static pid_t run(struct init_action *a)
messageND(LOG,
"Waiting for enter to start '%s' (pid %d, terminal %s)\n",
cmdpath, getpid(), a->terminal);
fflush(stdout);
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
getc(stdin);
}
@@ -658,8 +651,7 @@ static pid_t run(struct init_action *a)
execve(cmdpath, cmd, environment);
/* We're still here? Some error happened. */
message(LOG | CONSOLE, "\rBummer, could not run '%s': %s\n", cmdpath,
strerror(errno));
message(LOG | CONSOLE, "\rBummer, could not run '%s': %m\n", cmdpath);
_exit(-1);
}
sigprocmask(SIG_SETMASK, &omask, NULL);
@@ -691,8 +683,7 @@ 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) {
@@ -783,8 +774,8 @@ static void exec_signal(int sig)
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, strerror(errno));
message(CONSOLE | LOG, "\rexec of '%s' failed: %m\n",
a->command);
sync();
sleep(2);
init_reboot(RB_HALT_SYSTEM);
@@ -1063,7 +1054,6 @@ extern int init_main(int argc, char **argv)
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... */
+17 -14
View File
@@ -28,20 +28,23 @@ LIBBB_SRC:= \
copy_file_chunk.c dump.c libc5.c device_open.c error_msg.c \
error_msg_and_die.c fgets_str.c find_mount_point.c find_pid_by_name.c \
find_root_device.c full_read.c full_write.c get_console.c \
get_last_path_component.c get_line_from_file.c gz_open.c human_readable.c \
isdirectory.c kernel_version.c loop.c mode_string.c module_syscalls.c mtab.c \
mtab_file.c my_getgrnam.c my_getgrgid.c my_getpwnam.c my_getpwnamegid.c \
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 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 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
get_last_path_component.c get_line_from_file.c \
human_readable.c isdirectory.c kernel_version.c loop.c \
mode_string.c module_syscalls.c mtab.c mtab_file.c my_getgrnam.c \
my_getgrgid.c my_getpwnam.c my_getpwnamegid.c 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 \
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 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 \
procps.c
LIBBB_OBJS=$(patsubst %.c,$(LIBBB_DIR)%.o, $(LIBBB_SRC))
+10 -44
View File
@@ -22,7 +22,6 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <dirent.h>
#include <stdlib.h>
#include "libbb.h"
@@ -40,7 +39,7 @@
*
* Returns a list of all matching PIDs
*/
extern long* find_pid_by_name( char* pidName)
extern long* find_pid_by_name( const char* pidName)
{
int fd, i, j;
char device[] = "/dev/ps";
@@ -112,61 +111,28 @@ extern long* find_pid_by_name( char* pidName)
/* find_pid_by_name()
*
* Modified by Vladimir Oleynik for use with libbb/procps.c
* This finds the pid of the specified process.
* Currently, it's implemented by rummaging through
* the proc filesystem.
*
* Returns a list of all matching PIDs
*/
extern long* find_pid_by_name( char* pidName)
extern long* find_pid_by_name( const char* pidName)
{
DIR *dir;
struct dirent *next;
long* pidList=NULL;
long* pidList;
int i=0;
procps_status_t * p;
dir = opendir("/proc");
if (!dir)
perror_msg_and_die("Cannot open /proc");
while ((next = readdir(dir)) != NULL) {
FILE *status;
char filename[READ_BUF_SIZE];
char buffer[READ_BUF_SIZE];
char name[READ_BUF_SIZE];
/* Must skip ".." since that is outside /proc */
if (strcmp(next->d_name, "..") == 0)
continue;
/* If it isn't a number, we don't want it */
if (!isdigit(*next->d_name))
continue;
sprintf(filename, "/proc/%s/status", next->d_name);
if (! (status = fopen(filename, "r")) ) {
continue;
}
if (fgets(buffer, READ_BUF_SIZE-1, status) == NULL) {
fclose(status);
continue;
}
fclose(status);
/* Buffer should contain a string like "Name: binary_name" */
sscanf(buffer, "%*s %s", name);
if (strcmp(name, pidName) == 0) {
pidList = xmalloc(sizeof(long));
while ((p = procps_scan(0)) != 0) {
if (strcmp(p->short_cmd, pidName) == 0) {
pidList=xrealloc( pidList, sizeof(long) * (i+2));
pidList[i++]=strtol(next->d_name, NULL, 0);
pidList[i++]=p->pid;
}
}
if (pidList) {
pidList[i]=0;
} else {
pidList=xrealloc( pidList, sizeof(long));
pidList[0]=-1;
}
pidList[i] = i==0 ? -1 : 0;
return pidList;
}
#endif /* CONFIG_FEATURE_USE_DEVPS_PATCH */
-58
View File
@@ -1,58 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) many different people. If you wrote this, please
* acknowledge your work.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "libbb.h"
extern FILE *gz_open(FILE *compressed_file, int *pid)
{
int unzip_pipe[2];
if (pipe(unzip_pipe)!=0) {
error_msg("pipe error");
return(NULL);
}
if ((*pid = fork()) == -1) {
error_msg("fork failed");
return(NULL);
}
if (*pid==0) {
/* child process */
close(unzip_pipe[0]);
unzip(compressed_file, fdopen(unzip_pipe[1], "w"));
fflush(NULL);
fclose(compressed_file);
close(unzip_pipe[1]);
exit(EXIT_SUCCESS);
}
close(unzip_pipe[1]);
if (unzip_pipe[0] == -1) {
error_msg("gzip stream init failed");
}
return(fdopen(unzip_pipe[0], "r"));
}
+4 -4
View File
@@ -41,7 +41,7 @@
int make_directory (char *path, long mode, int flags)
{
int ret;
/* Calling apps probably should use 0777 instead of -1
* then we dont need this condition
*/
@@ -50,7 +50,7 @@ int make_directory (char *path, long mode, int flags)
}
if (flags == FILEUTILS_RECUR) {
char *pp = strrchr(path, '/');
if (pp) {
if ((pp) && (pp != path)) {
*pp = '\0';
make_directory(path, mode, flags);
*pp = '/';
@@ -58,10 +58,10 @@ int make_directory (char *path, long mode, int flags)
}
ret = mkdir(path, mode);
if (ret == -1) {
if (errno == EEXIST) {
if ((flags == FILEUTILS_RECUR) && (errno == EEXIST)) {
ret = 0;
} else {
perror_msg("Cannot create directory %s", path);
perror_msg_and_die("Cannot create directory '%s'", path);
}
}
return(ret);
+1 -1
View File
@@ -45,7 +45,7 @@
const char * const invalid_option = "invalid option -- %c";
#endif
#ifdef L_io_error
const char * const io_error = "%s: input/output error -- %s";
const char * const io_error = "%s: input/output error -- %m";
#endif
#ifdef L_dash_dash_help
const char * const dash_dash_help = "--help";
+7 -5
View File
@@ -27,15 +27,17 @@
/* gets a groupname given a gid */
void my_getgrgid(char *group, long gid)
char * my_getgrgid(char *group, long gid)
{
struct group *mygroup;
mygroup = getgrgid(gid);
if (mygroup==NULL)
sprintf(group, "%-8ld ", (long)gid);
else
strcpy(group, mygroup->gr_name);
if (mygroup==NULL) {
sprintf(group, "%ld", gid);
return NULL;
} else {
return strcpy(group, mygroup->gr_name);
}
}
+7 -5
View File
@@ -28,15 +28,17 @@
/* gets a username given a uid */
void my_getpwuid(char *name, long uid)
char * my_getpwuid(char *name, long uid)
{
struct passwd *myuser;
myuser = getpwuid(uid);
if (myuser==NULL)
sprintf(name, "%-8ld ", (long)uid);
else
strcpy(name, myuser->pw_name);
if (myuser==NULL) {
sprintf(name, "%ld", (long)uid);
return NULL;
} else {
return strcpy(name, myuser->pw_name);
}
}
/* END CODE */
+32 -30
View File
@@ -44,7 +44,7 @@
* 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)
static int palindrome(const char *newval)
{
int i, j;
@@ -79,24 +79,25 @@ static int similiar(const char *old, const char *newval)
* a nice mix of characters.
*/
static int simple(const char *old, const char *newval)
static int simple(const char *newval)
{
int digits = 0;
int uppers = 0;
int lowers = 0;
int others = 0;
int c;
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++;
for (i = 0; (c = *newval++) != 0; i++) {
if (isdigit(c))
digits = c;
else if (isupper(c))
uppers = c;
else if (islower(c))
lowers = c;
else
others++;
others = c;
}
/*
@@ -129,49 +130,50 @@ static char *str_lower(char *string)
return string;
}
static char *password_check(const char *old, const char *newval, const struct passwd *pwdp)
static const char *
password_check(const char *old, const char *newval, const struct passwd *pwdp)
{
char *msg = NULL;
char *oldmono, *newmono, *wrapped;
const char *msg;
char *newmono, *wrapped;
int lenwrap;
if (strcmp(newval, old) == 0)
return "no change";
if (simple(newval))
return "too simple";
msg = NULL;
newmono = str_lower(xstrdup(newval));
oldmono = str_lower(xstrdup(old));
wrapped = (char *) xmalloc(strlen(oldmono) * 2 + 1);
strcpy(wrapped, oldmono);
strcat(wrapped, oldmono);
lenwrap = strlen(old) * 2 + 1;
wrapped = (char *) xmalloc(lenwrap);
str_lower(strcpy(wrapped, old));
if (palindrome(oldmono, newmono))
if (palindrome(newmono))
msg = "a palindrome";
if (!msg && strcmp(oldmono, newmono) == 0)
else if (strcmp(wrapped, newmono) == 0)
msg = "case changes only";
if (!msg && similiar(oldmono, newmono))
else if (similiar(wrapped, newmono))
msg = "too similiar";
if (!msg && simple(old, newval))
msg = "too simple";
if (!msg && strstr(wrapped, newmono))
else if (strstr(strcat(wrapped, wrapped), newmono))
msg = "rotated";
bzero(newmono, strlen(newmono));
bzero(oldmono, strlen(oldmono));
bzero(wrapped, strlen(wrapped));
bzero(wrapped, lenwrap);
free(newmono);
free(oldmono);
free(wrapped);
return msg;
}
static char *obscure_msg(const char *old, const char *newval, const struct passwd *pwdp)
static const char *
obscure_msg(const char *old, const char *newval, const struct passwd *pwdp)
{
int maxlen, oldlen, newlen;
char *new1, *old1, *msg;
char *new1, *old1;
const char *msg;
oldlen = strlen(old);
newlen = strlen(newval);
@@ -233,7 +235,7 @@ static char *obscure_msg(const char *old, const char *newval, const struct passw
extern int obscure(const char *old, const char *newval, const struct passwd *pwdp)
{
char *msg = obscure_msg(old, newval, pwdp);
const char *msg = obscure_msg(old, newval, pwdp);
/* if (msg) { */
if (msg != NULL) {
+137
View File
@@ -0,0 +1,137 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright 1998 by Albert Cahalan; all rights reserved.
* Copyright (C) 2002 by Vladimir Oleynik <dzo@simtreas.ru>
* GNU Library General Public License Version 2, or any later version
*
*/
#include "libbb.h"
#if ! defined CONFIG_FEATURE_USE_DEVPS_PATCH
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <asm/page.h>
extern procps_status_t * procps_scan(int save_user_arg0)
{
static DIR *dir;
struct dirent *entry;
static procps_status_t ret_status;
char *name;
int n;
char status[32];
char buf[1024];
FILE *fp;
procps_status_t curstatus;
int pid;
long tasknice;
struct stat sb;
if (!dir) {
dir = opendir("/proc");
if(!dir)
error_msg_and_die("Can't open /proc");
}
for(;;) {
if((entry = readdir(dir)) == NULL) {
closedir(dir);
dir = 0;
return 0;
}
name = entry->d_name;
if (!(*name >= '0' && *name <= '9'))
continue;
memset(&curstatus, 0, sizeof(procps_status_t));
pid = atoi(name);
curstatus.pid = pid;
sprintf(status, "/proc/%d/stat", pid);
if((fp = fopen(status, "r")) == NULL)
continue;
if(fstat(fileno(fp), &sb))
continue;
my_getpwuid(curstatus.user, sb.st_uid);
name = fgets(buf, sizeof(buf), fp);
fclose(fp);
if(name == NULL)
continue;
name = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */
if(name == 0 || name[1] != ' ')
continue;
*name = 0;
sscanf(buf, "%*s (%15c", curstatus.short_cmd);
n = sscanf(name+2,
"%c %d "
"%*s %*s %*s %*s " /* pgrp, session, tty, tpgid */
"%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
"%lu %lu "
#else
"%*s %*s "
#endif
"%*s %*s %*s " /* cutime, cstime, priority */
"%ld "
"%*s %*s %*s " /* timeout, it_real_value, start_time */
"%*s " /* vsize */
"%ld",
curstatus.state, &curstatus.ppid,
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
&curstatus.utime, &curstatus.stime,
#endif
&tasknice,
&curstatus.rss);
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
if(n != 6)
#else
if(n != 4)
#endif
continue;
if (curstatus.rss == 0 && curstatus.state[0] != 'Z')
curstatus.state[1] = 'W';
else
curstatus.state[1] = ' ';
if (tasknice < 0)
curstatus.state[2] = '<';
else if (tasknice > 0)
curstatus.state[2] = 'N';
else
curstatus.state[2] = ' ';
curstatus.rss <<= (PAGE_SHIFT - 10); /* 2**10 = 1kb */
sprintf(status, "/proc/%d/cmdline", pid);
if(save_user_arg0) {
if((fp = fopen(status, "r")) == NULL)
continue;
if(fgets(buf, sizeof(buf), fp) != NULL) {
name = strchr(buf, '\n');
if(name != NULL)
*name = 0;
if(buf[0])
curstatus.cmd = strdup(buf);
/* if NULL it work true also */
}
fclose(fp);
}
return memcpy(&ret_status, &curstatus, sizeof(procps_status_t));
}
}
#endif /* CONFIG_FEATURE_USE_DEVPS_PATCH. Else this file is empty */
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
-313
View File
@@ -1,313 +0,0 @@
#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
-1069
View File
File diff suppressed because it is too large. Load diff
+56
View File
@@ -19,10 +19,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "libbb.h"
@@ -85,6 +88,59 @@ FILE *xfopen(const char *path, const char *mode)
return fp;
}
extern int xopen(const char *pathname, int flags)
{
int ret;
ret = open(pathname, flags);
if (ret == -1) {
perror_msg_and_die("%s", pathname);
}
return ret;
}
extern ssize_t xread(int fd, void *buf, size_t count)
{
ssize_t size;
size = read(fd, buf, count);
if (size == -1) {
perror_msg_and_die("Read error");
}
return(size);
}
extern void xread_all(int fd, void *buf, size_t count)
{
ssize_t size;
size = xread(fd, buf, count);
if (size != count) {
error_msg_and_die("Short read");
}
return;
}
extern ssize_t xread_all_eof(int fd, void *buf, size_t count)
{
ssize_t size;
size = xread(fd, buf, count);
if ((size != 0) && (size != count)) {
error_msg_and_die("Short read");
}
return(size);
}
extern unsigned char xread_char(int fd)
{
char tmp;
xread_all(fd, &tmp, 1);
return(tmp);
}
/* Stupid gcc always includes its own builtin strlen()... */
#undef strlen
size_t xstrlen(const char *string)
+18 -23
View File
@@ -37,8 +37,6 @@
#define USE_SYSLOG
#endif
extern void updwtmp(const char *filename, const struct utmp *ut);
/* If USE_SYSLOG is undefined all diagnostics go directly to /dev/console. */
#ifdef USE_SYSLOG
#include <syslog.h>
@@ -52,7 +50,10 @@ extern void updwtmp(const char *filename, const struct utmp *ut);
#ifdef LOGIN_PROCESS /* defined in System V utmp.h */
#define SYSV_STYLE /* select System V style getty */
#ifdef CONFIG_FEATURE_U_W_TMP
extern void updwtmp(const char *filename, const struct utmp *ut);
#endif
#endif /* LOGIN_PROCESS */
/*
* Things you may want to modify.
@@ -218,7 +219,6 @@ static struct Speedtab speedtab[] = {
static void parse_args(int argc, char **argv, struct options *op);
static void parse_speeds(struct options *op, char *arg);
static void update_utmp(char *line);
static void open_tty(char *tty, struct termio *tp, int local);
static void termio_init(struct termio *tp, int speed, struct options *op);
static void auto_baud(struct termio *tp);
@@ -234,6 +234,10 @@ static int caps_lock(const char *s);
static int bcode(const char *s);
static void error(const char *fmt, ...) __attribute__ ((noreturn));
#ifdef CONFIG_FEATURE_U_W_TMP
static void update_utmp(char *line);
#endif
/* The following is used for understandable diagnostics. */
/* Fake hostname for ut_host specified on command line. */
@@ -286,8 +290,11 @@ int getty_main(int argc, char **argv)
/* Update the utmp file. */
#ifdef SYSV_STYLE
#ifdef CONFIG_FEATURE_U_W_TMP
update_utmp(options.tty);
#endif
#endif
debug("calling open_tty\n");
@@ -381,34 +388,20 @@ static void parse_args(int argc, char **argv, struct options *op)
switch (c) {
case 'I':
if (!(op->initstring = strdup(optarg)))
error("can't malloc initstring");
error(memory_exhausted);
{
char ch, *p, *q;
int i;
const char *p;
char *q;
/* copy optarg into op->initstring decoding \ddd
octal codes into chars */
q = op->initstring;
p = optarg;
while (*p) {
if (*p == '\\') { /* know \\ means \ */
if (*p == '\\') {
p++;
if (*p == '\\') {
ch = '\\';
p++;
} else { /* handle \000 - \177 */
ch = 0;
for (i = 1; i <= 3; i++) {
if (*p >= '0' && *p <= '7') {
ch <<= 3;
ch += *p - '0';
p++;
} else
break;
}
}
*q++ = ch;
*q++ = process_escape_sequence(&p);
} else {
*q++ = *p++;
}
@@ -492,6 +485,7 @@ static void parse_speeds(struct options *op, char *arg)
}
#ifdef SYSV_STYLE
#ifdef CONFIG_FEATURE_U_W_TMP
/* update_utmp - update our utmp entry */
static void update_utmp(char *line)
@@ -544,7 +538,8 @@ static void update_utmp(char *line)
}
}
#endif
#endif /* CONFIG_FEATURE_U_W_TMP */
#endif /* SYSV_STYLE */
/* open_tty - set up tty as standard { input, output, error } */
static void open_tty(char *tty, struct termio *tp, int local)
+14 -8
View File
@@ -18,22 +18,19 @@
#include "busybox.h"
#ifdef CONFIG_FEATURE_U_W_TMP
// import from utmp.c
static void checkutmp(int picky);
static void setutmp(const char *name, const char *line);
// import from encrypt.c
extern char *pw_encrypt(const char *clear, const char *salt);
/* Stuff global to this file */
struct utmp utent;
#endif
// login defines
#define TIMEOUT 60
#define EMPTY_USERNAME_COUNT 10
#define USERNAME_SIZE 32
/* Stuff global to this file */
struct utmp utent;
static int check_nologin ( int amroot );
@@ -119,7 +116,9 @@ extern int login_main(int argc, char **argv)
if ( !isatty ( 0 ) || !isatty ( 1 ) || !isatty ( 2 ))
return EXIT_FAILURE; /* Must be a terminal */
#ifdef CONFIG_FEATURE_U_W_TMP
checkutmp ( !amroot );
#endif
tmp = ttyname ( 0 );
if ( tmp && ( strncmp ( tmp, "/dev/", 5 ) == 0 ))
@@ -127,12 +126,15 @@ extern int login_main(int argc, char **argv)
else
safe_strncpy ( tty, "UNKNOWN", sizeof( tty ));
#ifdef CONFIG_FEATURE_U_W_TMP
if ( amroot )
memset ( utent.ut_host, 0, sizeof utent.ut_host );
#endif
if ( opt_host ) {
#ifdef CONFIG_FEATURE_U_W_TMP
safe_strncpy ( utent.ut_host, opt_host, sizeof( utent. ut_host ));
#endif
snprintf ( fromhost, sizeof( fromhost ) - 1, " on `%.100s' from `%.200s'", tty, opt_host );
}
else
@@ -212,7 +214,9 @@ auth_ok:
if ( check_nologin ( pw-> pw_uid == 0 ))
return EXIT_FAILURE;
#ifdef CONFIG_FEATURE_U_W_TMP
setutmp ( username, tty );
#endif
if ( *tty != '/' )
snprintf ( full_tty, sizeof( full_tty ) - 1, "/dev/%s", tty);
else
@@ -356,6 +360,7 @@ static void motd ( )
}
#ifdef CONFIG_FEATURE_U_W_TMP
// vv Taken from tinylogin utmp.c vv
#define _WTMP_FILE "/var/log/wtmp"
@@ -437,3 +442,4 @@ static void setutmp(const char *name, const char *line)
endutent();
updwtmp(_WTMP_FILE, &utent);
}
#endif /* CONFIG_FEATURE_U_W_TMP */
+2
View File
@@ -25,6 +25,8 @@ endif
MISCUTILS-y:=
MISCUTILS-$(CONFIG_ADJTIMEX) += adjtimex.o
MISCUTILS-$(CONFIG_CROND) += crond.o
MISCUTILS-$(CONFIG_CRONTAB) += crontab.o
MISCUTILS-$(CONFIG_DC) += dc.o
MISCUTILS-$(CONFIG_DUTMP) += dutmp.o
MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o
+2
View File
@@ -7,6 +7,8 @@ mainmenu_option next_comment
comment 'Miscellaneous Utilities'
bool 'adjtimex' CONFIG_ADJTIMEX
bool 'crond' CONFIG_CROND
bool 'crontab' CONFIG_CRONTAB
bool 'dc' CONFIG_DC
bool 'dutmp' CONFIG_DUTMP
bool 'makedevs' CONFIG_MAKEDEVS
+1144
View File
File diff suppressed because it is too large. Load diff
+391
View File
@@ -0,0 +1,391 @@
/*
* CRONTAB
*
* usually setuid root, -c option only works if getuid() == geteuid()
*
* Copyright 1994 Matthew Dillon (dillon@apollo.west.oic.com)
* May be distributed under the GNU General Public License
*
* Vladimir Oleynik <dzo@simtreas.ru> (C) 2002 to be used in busybox
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <syslog.h>
#include <signal.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/resource.h>
#ifndef CRONTABS
#define CRONTABS "/var/spool/cron/crontabs"
#endif
#ifndef TMPDIR
#define TMPDIR "/var/spool/cron"
#endif
#ifndef CRONUPDATE
#define CRONUPDATE "cron.update"
#endif
#ifndef PATH_VI
#define PATH_VI "/usr/bin/vi" /* location of vi */
#endif
#include "busybox.h"
static const char *CDir = CRONTABS;
static void EditFile(const char *user, const char *file);
static int GetReplaceStream(const char *user, const char *file);
static int ChangeUser(const char *user, short dochdir);
int
crontab_main(int ac, char **av)
{
enum { NONE, EDIT, LIST, REPLACE, DELETE } option = NONE;
const struct passwd *pas;
const char *repFile = NULL;
int repFd = 0;
int i;
char caller[256]; /* user that ran program */
int UserId;
UserId = getuid();
if ((pas = getpwuid(UserId)) == NULL)
perror_msg_and_die("getpwuid");
strncpy(caller, pas->pw_name, sizeof(caller));
i = 1;
if (ac > 1) {
if (av[1][0] == '-' && av[1][1] == 0) {
option = REPLACE;
++i;
} else if (av[1][0] != '-') {
option = REPLACE;
++i;
repFile = av[1];
}
}
for (; i < ac; ++i) {
char *ptr = av[i];
if (*ptr != '-')
break;
ptr += 2;
switch(ptr[-1]) {
case 'l':
if (ptr[-1] == 'l')
option = LIST;
/* fall through */
case 'e':
if (ptr[-1] == 'e')
option = EDIT;
/* fall through */
case 'd':
if (ptr[-1] == 'd')
option = DELETE;
/* fall through */
case 'u':
if (i + 1 < ac && av[i+1][0] != '-') {
++i;
if (getuid() == geteuid()) {
pas = getpwnam(av[i]);
if (pas) {
UserId = pas->pw_uid;
} else {
error_msg_and_die("user %s unknown", av[i]);
}
} else {
error_msg_and_die("only the superuser may specify a user");
}
}
break;
case 'c':
if (getuid() == geteuid()) {
CDir = (*ptr) ? ptr : av[++i];
} else {
error_msg_and_die("-c option: superuser only");
}
break;
default:
i = ac;
break;
}
}
if (i != ac || option == NONE)
show_usage();
/*
* Get password entry
*/
if ((pas = getpwuid(UserId)) == NULL)
perror_msg_and_die("getpwuid");
/*
* If there is a replacement file, obtain a secure descriptor to it.
*/
if (repFile) {
repFd = GetReplaceStream(caller, repFile);
if (repFd < 0)
error_msg_and_die("unable to read replacement file");
}
/*
* Change directory to our crontab directory
*/
if (chdir(CDir) < 0)
perror_msg_and_die("cannot change dir to %s", CDir);
/*
* Handle options as appropriate
*/
switch(option) {
case LIST:
{
FILE *fi;
char buf[1024];
if ((fi = fopen(pas->pw_name, "r"))) {
while (fgets(buf, sizeof(buf), fi) != NULL)
fputs(buf, stdout);
fclose(fi);
} else {
error_msg("no crontab for %s", pas->pw_name);
}
}
break;
case EDIT:
{
FILE *fi;
int fd;
int n;
char tmp[128];
char buf[1024];
snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid());
if ((fd = open(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600)) >= 0) {
chown(tmp, getuid(), getgid());
if ((fi = fopen(pas->pw_name, "r"))) {
while ((n = fread(buf, 1, sizeof(buf), fi)) > 0)
write(fd, buf, n);
}
EditFile(caller, tmp);
remove(tmp);
lseek(fd, 0L, 0);
repFd = fd;
} else {
error_msg_and_die("unable to create %s", tmp);
}
}
option = REPLACE;
/* fall through */
case REPLACE:
{
char buf[1024];
char path[1024];
int fd;
int n;
snprintf(path, sizeof(path), "%s.new", pas->pw_name);
if ((fd = open(path, O_CREAT|O_TRUNC|O_EXCL|O_APPEND|O_WRONLY, 0600)) >= 0) {
while ((n = read(repFd, buf, sizeof(buf))) > 0) {
write(fd, buf, n);
}
close(fd);
rename(path, pas->pw_name);
} else {
error_msg("unable to create %s/%s", CDir, buf);
}
close(repFd);
}
break;
case DELETE:
remove(pas->pw_name);
break;
case NONE:
default:
break;
}
/*
* Bump notification file. Handle window where crond picks file up
* before we can write our entry out.
*/
if (option == REPLACE || option == DELETE) {
FILE *fo;
struct stat st;
while ((fo = fopen(CRONUPDATE, "a"))) {
fprintf(fo, "%s\n", pas->pw_name);
fflush(fo);
if (fstat(fileno(fo), &st) != 0 || st.st_nlink != 0) {
fclose(fo);
break;
}
fclose(fo);
/* loop */
}
if (fo == NULL) {
error_msg("unable to append to %s/%s", CDir, CRONUPDATE);
}
}
return 0;
}
static int
GetReplaceStream(const char *user, const char *file)
{
int filedes[2];
int pid;
int fd;
int n;
char buf[1024];
if (pipe(filedes) < 0) {
perror("pipe");
return(-1);
}
if ((pid = fork()) < 0) {
perror("fork");
return(-1);
}
if (pid > 0) {
/*
* PARENT
*/
close(filedes[1]);
if (read(filedes[0], buf, 1) != 1) {
close(filedes[0]);
filedes[0] = -1;
}
return(filedes[0]);
}
/*
* CHILD
*/
close(filedes[0]);
if (ChangeUser(user, 0) < 0)
exit(0);
fd = open(file, O_RDONLY);
if (fd < 0) {
error_msg("unable to open %s", file);
exit(0);
}
buf[0] = 0;
write(filedes[1], buf, 1);
while ((n = read(fd, buf, sizeof(buf))) > 0) {
write(filedes[1], buf, n);
}
exit(0);
}
static void
EditFile(const char *user, const char *file)
{
int pid;
if ((pid = fork()) == 0) {
/*
* CHILD - change user and run editor
*/
char *ptr;
char visual[1024];
if (ChangeUser(user, 1) < 0)
exit(0);
if ((ptr = getenv("VISUAL")) == NULL || strlen(ptr) > 256)
ptr = PATH_VI;
snprintf(visual, sizeof(visual), "%s %s", ptr, file);
execl("/bin/sh", "/bin/sh", "-c", visual, NULL);
perror("exec");
exit(0);
}
if (pid < 0) {
/*
* PARENT - failure
*/
perror_msg_and_die("fork");
}
wait4(pid, NULL, 0, NULL);
}
static void
log(const char *ctl, ...)
{
va_list va;
char buf[1024];
va_start(va, ctl);
vsnprintf(buf, sizeof(buf), ctl, va);
syslog(LOG_NOTICE, "%s",buf );
va_end(va);
}
static int
ChangeUser(const char *user, short dochdir)
{
struct passwd *pas;
/*
* Obtain password entry and change privilages
*/
if ((pas = getpwnam(user)) == 0) {
log("failed to get uid for %s", user);
return(-1);
}
setenv("USER", pas->pw_name, 1);
setenv("HOME", pas->pw_dir, 1);
setenv("SHELL", "/bin/sh", 1);
/*
* Change running state to the user in question
*/
if (initgroups(user, pas->pw_gid) < 0) {
log("initgroups failed: %s %m", user);
return(-1);
}
if (setregid(pas->pw_gid, pas->pw_gid) < 0) {
log("setregid failed: %s %d", user, pas->pw_gid);
return(-1);
}
if (setreuid(pas->pw_uid, pas->pw_uid) < 0) {
log("setreuid failed: %s %d", user, pas->pw_uid);
return(-1);
}
if (dochdir) {
if (chdir(pas->pw_dir) < 0) {
if (chdir(TMPDIR) < 0) {
log("chdir failed: %s %s", user, pas->pw_dir);
log("chdir failed: %s " TMPDIR, user);
return(-1);
}
}
}
return(pas->pw_uid);
}
+1 -1
View File
@@ -34,7 +34,7 @@ extern int dutmp_main(int argc, char **argv)
} else {
file = open(argv[1], O_RDONLY);
if (file < 0) {
perror_msg_and_die(io_error, argv[1]);
error_msg_and_die(io_error, argv[1]);
}
}
+2 -2
View File
@@ -318,7 +318,7 @@ static void summarize (FILE *fp, const char *fmt, char **command, resource_t *re
fprintf (fp, "%ldm %ld.%02lds", /* -> m:s. */
resp->ru.ru_stime.tv_sec / 60,
resp->ru.ru_stime.tv_sec % 60,
resp->ru.ru_stime.tv_sec / 10000);
resp->ru.ru_stime.tv_usec / 10000);
break;
case 'U': /* User time. */
fprintf (fp, "%ld.%02ld",
@@ -335,7 +335,7 @@ static void summarize (FILE *fp, const char *fmt, char **command, resource_t *re
fprintf (fp, "%ldm %ld.%02lds", /* -> m:s. */
resp->ru.ru_utime.tv_sec / 60,
resp->ru.ru_utime.tv_sec % 60,
resp->ru.ru_utime.tv_sec / 10000);
resp->ru.ru_utime.tv_usec / 10000);
break;
case 'W': /* Times swapped out. */
fprintf (fp, "%ld", resp->ru.ru_nswap);
+4
View File
@@ -29,5 +29,9 @@ if [ "$CONFIG_LSMOD" = "y" ]; then
fi
fi
if [ "$CONFIG_INSMOD" = "y" -o "$CONFIG_LSMOD" = "y" ]; then
bool 'Support tainted module checking with new kernels' CONFIG_FEATURE_CHECK_TAINTED_MODULE
fi
endmenu
+6 -2
View File
@@ -234,7 +234,7 @@
#ifndef MODUTILS_MODULE_H
static const int MODUTILS_MODULE_H = 1;
#ident "$Id: insmod.c,v 1.90 2002/09/16 05:30:24 andersen Exp $"
#ident "$Id: insmod.c,v 1.91 2002/10/10 04:20:21 andersen Exp $"
/* This file contains the structures used by the 2.0 and 2.1 kernels.
We do not use the kernel headers directly because we do not wish
@@ -455,7 +455,7 @@ int delete_module(const char *);
#ifndef MODUTILS_OBJ_H
static const int MODUTILS_OBJ_H = 1;
#ident "$Id: insmod.c,v 1.90 2002/09/16 05:30:24 andersen Exp $"
#ident "$Id: insmod.c,v 1.91 2002/10/10 04:20:21 andersen Exp $"
/* The relocatable object is manipulated using elfin types. */
@@ -3422,6 +3422,7 @@ static void hide_special_symbols(struct obj_file *f)
ELFW(ST_INFO) (STB_LOCAL, ELFW(ST_TYPE) (sym->info));
}
#ifdef CONFIG_FEATURE_CHECK_TAINTED_MODULE
static int obj_gpl_license(struct obj_file *f, const char **license)
{
struct obj_section *sec;
@@ -3533,6 +3534,9 @@ static void check_tainted_module(struct obj_file *f, char *m_name)
if (fd >= 0)
close(fd);
}
#else /* CONFIG_FEATURE_CHECK_TAINTED_MODULE */
#define check_tainted_module(x, y) do { } while(0);
#endif /* CONFIG_FEATURE_CHECK_TAINTED_MODULE */
extern int insmod_main( int argc, char **argv)
{
+19 -27
View File
@@ -40,13 +40,15 @@
#include "busybox.h"
#ifndef CONFIG_FEATURE_CHECK_TAINTED_MODULE
static inline void check_tainted(void) { printf("\n"); }
#else
#define TAINT_FILENAME "/proc/sys/kernel/tainted"
#define TAINT_PROPRIETORY_MODULE (1<<0)
#define TAINT_FORCED_MODULE (1<<1)
#define TAINT_UNSAFE_SMP (1<<2)
void check_tainted(void)
static void check_tainted(void)
{
int tainted;
FILE *f;
@@ -57,15 +59,16 @@ void check_tainted(void)
fclose(f);
}
if (f && tainted) {
printf(" Tainted: %c%c%c",
printf(" Tainted: %c%c%c\n",
tainted & TAINT_PROPRIETORY_MODULE ? 'P' : 'G',
tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
tainted & TAINT_UNSAFE_SMP ? 'S' : ' ');
}
else {
printf(" Not tainted");
printf(" Not tainted\n");
}
}
#endif
#ifdef CONFIG_FEATURE_QUERY_MODULE_INTERFACE
@@ -127,7 +130,6 @@ extern int lsmod_main(int argc, char **argv)
deps = xmalloc(depsize = 256);
printf("Module Size Used by");
check_tainted();
printf("\n");
for (i = 0, mn = module_names; i < nmod; mn += strlen(mn) + 1, i++) {
if (query_module(mn, QM_INFO, &info, sizeof(info), &count)) {
@@ -145,24 +147,24 @@ extern int lsmod_main(int argc, char **argv)
}
perror_msg_and_die("module %s: QM_REFS", mn);
}
printf("%-20s%8lu%4ld ", mn, info.size, info.usecount);
printf("%-20s%8lu%4ld", mn, info.size, info.usecount);
if (info.flags & NEW_MOD_DELETED)
printf("(deleted)");
printf(" (deleted)");
else if (info.flags & NEW_MOD_INITIALIZING)
printf("(initializing)");
printf(" (initializing)");
else if (!(info.flags & NEW_MOD_RUNNING))
printf("(uninitialized)");
printf(" (uninitialized)");
else {
if (info.flags & NEW_MOD_AUTOCLEAN)
printf("(autoclean) ");
printf(" (autoclean) ");
if (!(info.flags & NEW_MOD_USED_ONCE))
printf("(unused)");
printf(" (unused)");
}
if (count) printf("[");
if (count) printf(" [");
for (j = 0, dn = deps; j < count; dn += strlen(dn) + 1, j++) {
printf("%s%s", dn, (j==count-1)? "":" ");
}
if (count) printf("] ");
if (count) printf("]");
printf("\n");
}
@@ -171,26 +173,16 @@ extern int lsmod_main(int argc, char **argv)
return( 0);
}
#else /*CONFIG_FEATURE_OLD_MODULE_INTERFACE*/
#else /* CONFIG_FEATURE_QUERY_MODULE_INTERFACE */
extern int lsmod_main(int argc, char **argv)
{
int fd, i;
char line[128];
printf("Module Size Used by");
check_tainted();
fflush(stdout);
if ((fd = open("/proc/modules", O_RDONLY)) >= 0 ) {
while ((i = read(fd, line, sizeof(line))) > 0) {
write(fileno(stdout), line, i);
}
close(fd);
return 0;
}
perror_msg_and_die("/proc/modules");
if(print_file_by_name("/proc/modules") == FALSE)
return 1;
return 0;
}
#endif /*CONFIG_FEATURE_OLD_MODULE_INTERFACE*/
#endif /* CONFIG_FEATURE_QUERY_MODULE_INTERFACE */
+1 -1
View File
@@ -32,9 +32,9 @@ NETWORKING-$(CONFIG_PING) += ping.o
NETWORKING-$(CONFIG_PING6) += ping6.o
NETWORKING-$(CONFIG_ROUTE) += route.o
NETWORKING-$(CONFIG_TELNET) += telnet.o
NETWORKING-$(CONFIG_TELNETD) += telnetd.o
NETWORKING-$(CONFIG_TFTP) += tftp.o
NETWORKING-$(CONFIG_TRACEROUTE) += traceroute.o
NETWORKING-$(CONFIG_UDHCPC) += udhcpc.o
NETWORKING-$(CONFIG_WGET) += wget.o
libraries-y+=$(NETWORKING_DIR)$(NETWORKING_AR)
+3 -1
View File
@@ -34,6 +34,7 @@ bool 'telnet' CONFIG_TELNET
if [ "$CONFIG_TELNET" = "y" ]; then
bool ' Pass TERM type to remote host' CONFIG_FEATURE_TELNET_TTYPE
fi
bool 'telnetd' CONFIG_TELNETD
bool 'tftp' CONFIG_TFTP
if [ "$CONFIG_TFTP" = "y" ]; then
bool ' Enable "get" command' CONFIG_FEATURE_TFTP_GET
@@ -46,12 +47,13 @@ if [ "$CONFIG_TRACEROUTE" = "y" ]; then
bool ' Enable verbose output' CONFIG_FEATURE_TRACEROUTE_VERBOSE
bool ' Enable SO_DEBUG option' CONFIG_FEATURE_TRACEROUTE_SO_DEBUG
fi
bool 'udhcpc' CONFIG_UDHCPC
bool 'wget' CONFIG_WGET
if [ "$CONFIG_WGET" = "y" ]; then
bool ' Enable a nifty process meter (+2k)' CONFIG_FEATURE_WGET_STATUSBAR
bool ' Enable HTTP authentication' CONFIG_FEATURE_WGET_AUTHENTICATION
fi
source networking/udhcp/config.in
endmenu
+2 -2
View File
@@ -1,6 +1,6 @@
/* vi: set sw=4 ts=4: */
/*
* $Id: hostname.c,v 1.32 2001/10/31 09:59:57 andersen Exp $
* $Id: hostname.c,v 1.33 2002/10/18 22:13:23 andersen Exp $
* Mini hostname implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -106,7 +106,7 @@ int hostname_main(int argc, char **argv)
}
puts(buf);
} else if (type == 'd') {
puts(p ? p + 1 : "");
if (p) puts(p + 1);
} else if (type == 'i') {
while (hp->h_addr_list[0]) {
printf("%s ", inet_ntoa(*(struct in_addr *) (*hp->h_addr_list++)));
+538
View File
@@ -0,0 +1,538 @@
/* $Id: telnetd.c,v 1.1 2002/09/30 20:52:04 andersen Exp $
*
* Simple telnet server
* Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
*
* This file is distributed under the Gnu Public License (GPL),
* please see the file LICENSE for further information.
*
* ---------------------------------------------------------------------------
* (C) Copyright 2000, Axis Communications AB, LUND, SWEDEN
****************************************************************************
*
* The telnetd manpage says it all:
*
* Telnetd operates by allocating a pseudo-terminal device (see pty(4)) for
* a client, then creating a login process which has the slave side of the
* pseudo-terminal as stdin, stdout, and stderr. Telnetd manipulates the
* master side of the pseudo-terminal, implementing the telnet protocol and
* passing characters between the remote client and the login process.
*
* Vladimir Oleynik <dzo@simtreas.ru> 2001
* Set process group corrections, initial busybox port
*/
/*#define DEBUG 1 */
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <stdio.h>
#include <signal.h>
#include <termios.h>
#ifdef DEBUG
#define TELCMDS
#define TELOPTS
#endif
#include <arpa/telnet.h>
#include <ctype.h>
#include <sys/syslog.h>
#include "busybox.h"
#define BUFSIZE 4000
static const char *loginpath = "/bin/sh";
/* shell name and arguments */
static const char *argv_init[] = {NULL, NULL};
/* structure that describes a session */
struct tsession {
struct tsession *next;
int sockfd, ptyfd;
int shell_pid;
/* two circular buffers */
char *buf1, *buf2;
int rdidx1, wridx1, size1;
int rdidx2, wridx2, size2;
};
/*
This is how the buffers are used. The arrows indicate the movement
of data.
+-------+ wridx1++ +------+ rdidx1++ +----------+
| | <-------------- | buf1 | <-------------- | |
| | size1-- +------+ size1++ | |
| pty | | socket |
| | rdidx2++ +------+ wridx2++ | |
| | --------------> | buf2 | --------------> | |
+-------+ size2++ +------+ size2-- +----------+
Each session has got two buffers.
*/
static int maxfd;
static struct tsession *sessions;
/*
Remove all IAC's from the buffer pointed to by bf (recieved IACs are ignored
and must be removed so as to not be interpreted by the terminal). Make an
uninterrupted string of characters fit for the terminal. Do this by packing
all characters meant for the terminal sequentially towards the end of bf.
Return a pointer to the beginning of the characters meant for the terminal.
and make *num_totty the number of characters that should be sent to
the terminal.
Note - If an IAC (3 byte quantity) starts before (bf + len) but extends
past (bf + len) then that IAC will be left unprocessed and *processed will be
less than len.
FIXME - if we mean to send 0xFF to the terminal then it will be escaped,
what is the escape character? We aren't handling that situation here.
*/
static char *
remove_iacs(struct tsession *ts, int *pnum_totty) {
unsigned char *ptr0 = ts->buf1 + ts->wridx1;
unsigned char *ptr = ptr0;
unsigned char *totty = ptr;
unsigned char *end = ptr + MIN(BUFSIZE - ts->wridx1, ts->size1);
int processed;
int num_totty;
while (ptr < end) {
if (*ptr != IAC) {
*totty++ = *ptr++;
}
else {
if ((ptr+2) < end) {
/* the entire IAC is contained in the buffer
we were asked to process. */
#ifdef DEBUG
fprintf(stderr, "Ignoring IAC %s,%s\n",
*ptr, TELCMD(*(ptr+1)), TELOPT(*(ptr+2)));
#endif
ptr += 3;
} else {
/* only the beginning of the IAC is in the
buffer we were asked to process, we can't
process this char. */
break;
}
}
}
processed = ptr - ptr0;
num_totty = totty - ptr0;
/* the difference between processed and num_to tty
is all the iacs we removed from the stream.
Adjust buf1 accordingly. */
ts->wridx1 += processed - num_totty;
ts->size1 -= processed - num_totty;
*pnum_totty = num_totty;
/* move the chars meant for the terminal towards the end of the
buffer. */
return memmove(ptr - num_totty, ptr0, num_totty);
}
static int
getpty(char *line)
{
int p;
#ifdef HAVE_DEVPTS_FS
p = open("/dev/ptmx", 2);
if (p > 0) {
grantpt(p);
unlockpt(p);
strcpy(line, ptsname(p));
return(p);
}
#else
struct stat stb;
int i;
int j;
strcpy(line, "/dev/ptyXX");
for (i = 0; i < 16; i++) {
line[8] = "pqrstuvwxyzabcde"[i];
line[9] = '0';
if (stat(line, &stb) < 0) {
continue;
}
for (j = 0; j < 16; j++) {
line[9] = j < 10 ? j + '0' : j - 10 + 'a';
if ((p = open(line, O_RDWR | O_NOCTTY)) >= 0) {
line[5] = 't';
return p;
}
}
}
#endif /* HAVE_DEVPTS_FS */
return -1;
}
static void
send_iac(struct tsession *ts, unsigned char command, int option)
{
/* We rely on that there is space in the buffer for now. */
char *b = ts->buf2 + ts->rdidx2;
*b++ = IAC;
*b++ = command;
*b++ = option;
ts->rdidx2 += 3;
ts->size2 += 3;
}
static struct tsession *
make_new_session(int sockfd)
{
struct termios termbuf;
int pty, pid;
char tty_name[32];
struct tsession *ts = malloc(sizeof(struct tsession) + BUFSIZE * 2);
ts->buf1 = (char *)(&ts[1]);
ts->buf2 = ts->buf1 + BUFSIZE;
ts->sockfd = sockfd;
ts->rdidx1 = ts->wridx1 = ts->size1 = 0;
ts->rdidx2 = ts->wridx2 = ts->size2 = 0;
/* Got a new connection, set up a tty and spawn a shell. */
pty = getpty(tty_name);
if (pty < 0) {
syslog_msg(LOG_USER, LOG_ERR, "All network ports in use!");
return 0;
}
if (pty > maxfd)
maxfd = pty;
ts->ptyfd = pty;
/* Make the telnet client understand we will echo characters so it
* should not do it locally. We don't tell the client to run linemode,
* because we want to handle line editing and tab completion and other
* stuff that requires char-by-char support.
*/
send_iac(ts, DO, TELOPT_ECHO);
send_iac(ts, DO, TELOPT_LFLOW);
send_iac(ts, WILL, TELOPT_ECHO);
send_iac(ts, WILL, TELOPT_SGA);
if ((pid = fork()) < 0) {
syslog_msg(LOG_USER, LOG_ERR, "Can`t forking");
}
if (pid == 0) {
/* In child, open the child's side of the tty. */
int i;
for(i = 0; i <= maxfd; i++)
close(i);
/* make new process group */
setsid();
if (open(tty_name, O_RDWR /*| O_NOCTTY*/) < 0) {
syslog_msg(LOG_USER, LOG_ERR, "Could not open tty");
exit(1);
}
dup(0);
dup(0);
tcsetpgrp(0, getpid());
/* The pseudo-terminal allocated to the client is configured to operate in
* cooked mode, and with XTABS CRMOD enabled (see tty(4)).
*/
tcgetattr(0, &termbuf);
termbuf.c_lflag |= ECHO; /* if we use readline we dont want this */
termbuf.c_oflag |= ONLCR|XTABS;
termbuf.c_iflag |= ICRNL;
termbuf.c_iflag &= ~IXOFF;
/*termbuf.c_lflag &= ~ICANON;*/
tcsetattr(0, TCSANOW, &termbuf);
/* exec shell, with correct argv and env */
execv(loginpath, (char *const *)argv_init);
/* NOT REACHED */
syslog_msg(LOG_USER, LOG_ERR, "execv error");
exit(1);
}
ts->shell_pid = pid;
return ts;
}
static void
free_session(struct tsession *ts)
{
struct tsession *t = sessions;
/* Unlink this telnet session from the session list. */
if(t == ts)
sessions = ts->next;
else {
while(t->next != ts)
t = t->next;
t->next = ts->next;
}
kill(ts->shell_pid, SIGKILL);
wait4(ts->shell_pid, NULL, 0, NULL);
close(ts->ptyfd);
close(ts->sockfd);
if(ts->ptyfd == maxfd || ts->sockfd == maxfd)
maxfd--;
if(ts->ptyfd == maxfd || ts->sockfd == maxfd)
maxfd--;
free(ts);
}
int
telnetd_main(int argc, char **argv)
{
struct sockaddr_in sa;
int master_fd;
fd_set rdfdset, wrfdset;
int selret;
int on = 1;
int portnbr = 23;
int c;
/* check if user supplied a port number */
for (;;) {
c = getopt( argc, argv, "p:l:");
if (c == EOF) break;
switch (c) {
case 'p':
portnbr = atoi(optarg);
break;
case 'l':
loginpath = strdup (optarg);
break;
default:
show_usage();
}
}
if (access(loginpath, X_OK) < 0) {
error_msg_and_die ("'%s' unavailable.", loginpath);
}
argv_init[0] = loginpath;
sessions = 0;
/* Grab a TCP socket. */
master_fd = socket(AF_INET, SOCK_STREAM, 0);
if (master_fd < 0) {
perror_msg_and_die("socket");
}
(void)setsockopt(master_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
/* Set it to listen to specified port. */
memset((void *)&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_port = htons(portnbr);
if (bind(master_fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
perror_msg_and_die("bind");
}
if (listen(master_fd, 1) < 0) {
perror_msg_and_die("listen");
}
if (daemon(0, 0) < 0)
perror_msg_and_die("daemon");
maxfd = master_fd;
do {
struct tsession *ts;
FD_ZERO(&rdfdset);
FD_ZERO(&wrfdset);
/* select on the master socket, all telnet sockets and their
* ptys if there is room in their respective session buffers.
*/
FD_SET(master_fd, &rdfdset);
ts = sessions;
while (ts) {
/* buf1 is used from socket to pty
* buf2 is used from pty to socket
*/
if (ts->size1 > 0) {
FD_SET(ts->ptyfd, &wrfdset); /* can write to pty */
}
if (ts->size1 < BUFSIZE) {
FD_SET(ts->sockfd, &rdfdset); /* can read from socket */
}
if (ts->size2 > 0) {
FD_SET(ts->sockfd, &wrfdset); /* can write to socket */
}
if (ts->size2 < BUFSIZE) {
FD_SET(ts->ptyfd, &rdfdset); /* can read from pty */
}
ts = ts->next;
}
selret = select(maxfd + 1, &rdfdset, &wrfdset, 0, 0);
if (!selret)
break;
/* First check for and accept new sessions. */
if (FD_ISSET(master_fd, &rdfdset)) {
int fd, salen;
salen = sizeof(sa);
if ((fd = accept(master_fd, (struct sockaddr *)&sa,
&salen)) < 0) {
continue;
} else {
/* Create a new session and link it into
our active list. */
struct tsession *new_ts = make_new_session(fd);
if (new_ts) {
new_ts->next = sessions;
sessions = new_ts;
if (fd > maxfd)
maxfd = fd;
} else {
close(fd);
}
}
}
/* Then check for data tunneling. */
ts = sessions;
while (ts) { /* For all sessions... */
int maxlen, w, r;
struct tsession *next = ts->next; /* in case we free ts. */
if (ts->size1 && FD_ISSET(ts->ptyfd, &wrfdset)) {
int num_totty;
char *ptr;
/* Write to pty from buffer 1. */
ptr = remove_iacs(ts, &num_totty);
w = write(ts->ptyfd, ptr, num_totty);
if (w < 0) {
free_session(ts);
ts = next;
continue;
}
ts->wridx1 += w;
ts->size1 -= w;
if (ts->wridx1 == BUFSIZE)
ts->wridx1 = 0;
}
if (ts->size2 && FD_ISSET(ts->sockfd, &wrfdset)) {
/* Write to socket from buffer 2. */
maxlen = MIN(BUFSIZE - ts->wridx2, ts->size2);
w = write(ts->sockfd, ts->buf2 + ts->wridx2, maxlen);
if (w < 0) {
free_session(ts);
ts = next;
continue;
}
ts->wridx2 += w;
ts->size2 -= w;
if (ts->wridx2 == BUFSIZE)
ts->wridx2 = 0;
}
if (ts->size1 < BUFSIZE && FD_ISSET(ts->sockfd, &rdfdset)) {
/* Read from socket to buffer 1. */
maxlen = MIN(BUFSIZE - ts->rdidx1,
BUFSIZE - ts->size1);
r = read(ts->sockfd, ts->buf1 + ts->rdidx1, maxlen);
if (!r || (r < 0 && errno != EINTR)) {
free_session(ts);
ts = next;
continue;
}
if(!*(ts->buf1 + ts->rdidx1 + r - 1)) {
r--;
if(!r)
continue;
}
ts->rdidx1 += r;
ts->size1 += r;
if (ts->rdidx1 == BUFSIZE)
ts->rdidx1 = 0;
}
if (ts->size2 < BUFSIZE && FD_ISSET(ts->ptyfd, &rdfdset)) {
/* Read from pty to buffer 2. */
maxlen = MIN(BUFSIZE - ts->rdidx2,
BUFSIZE - ts->size2);
r = read(ts->ptyfd, ts->buf2 + ts->rdidx2, maxlen);
if (!r || (r < 0 && errno != EINTR)) {
free_session(ts);
ts = next;
continue;
}
ts->rdidx2 += r;
ts->size2 += r;
if (ts->rdidx2 == BUFSIZE)
ts->rdidx2 = 0;
}
if (ts->size1 == 0) {
ts->rdidx1 = 0;
ts->wridx1 = 0;
}
if (ts->size2 == 0) {
ts->rdidx2 = 0;
ts->wridx2 = 0;
}
ts = next;
}
} while (1);
return 0;
}
+1 -1
View File
@@ -475,7 +475,7 @@ static inline int tftp(const int cmd, const struct hostent *host,
#ifdef CONFIG_FEATURE_CLEAN_UP
close(socketfd);
RELEASE_CONFIG_BUFFER(buf);
free(buf);
#endif
return finished ? EXIT_SUCCESS : EXIT_FAILURE;
+13
View File
@@ -0,0 +1,13 @@
udhcp server/client package
-----------------------
Russ Dill <Russ.Dill@asu.edu>
Matthew Ramsay <matthewr@moreton.com.au>
Chris Trew <christ@moreton.com.au>
Other Credits:
--------------
Moreton Bay (http://www.moretonbay.com/)
Lineo (http://opensource.lineo.com)
+339
View File
@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
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., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
+246
View File
@@ -0,0 +1,246 @@
0.9.8 (pending)
+ udhcp now fits nicely into busybox
(Glenn McGrath <bug1@optushome.com.au> as well as myself)
+ updated client manpage (me)
+ both client and server now use sockets for signal handling,
hopefully, this will be the last needed change in signal
handling, I'm fairly certain all the possible races are now
closed. (me)
+ The server now restarts the auto_time timer when it receives
a SIGUSR1 (write out config file). (me)
+ Improve signal handling (David Poole)
+ Fix to config file parsing (Matt Kraai)
+ Fix load lease logic (me)
+ Fix clear_lease logic (me)
+ -h is now an alias for -H (udhcp bug #1253)
+ Shorter timeout on not receiving offers (me)
+ Improved signal behavior by client (me)
+ Would never assign end address (Keith Smith <keith@ksmith.com>)
+ Was improperly reporting yiaddr as siaddr (ben-udhcp@bdlow.net)
udhcp bug#1256
+ Fixed reading of client id (David Poole <davep@portsmith.com>)
+ change sys_errlist[] to strerror() as it aparently doesn't exist
(andersee <andersee@codepoet.org>)
+ fixed get_raw_packet so it returns -2 on non fatal errors
(Ted Lemon <Ted.Lemon@nominum.com>)
+ Improved (hopefully) NAKing behavior (me)
+ Added -b option (Jouni Malinen)
+ Compute checksums correctly on big endian hosts
(Jouni Malinen <jkmaline@cc.hut.fi>)
0.9.7 (020526)
+ Use add_lease in read_leases, sanitizes leases more, and clears out exprired
ones if there is no more room (me)
+ Moved udhcpd.leases to /var/lib/misc/udhcpd.leases (Debian bug #147747)
+ Change (obsolete) AF_INET in arping.c to PF_PACKET (Debian bug #127049)
+ Added script hook for DHCPNAK (nak), as well as providing the message option
(me)
+ Generate the paramaters request list by seeing what options in options.c are
ored with OPTION_REQ in options.c
+ Fix dhcp renew forgetfullness on client (bug #1230)
+ Fix dhcp release bug on client (bug #1231)
+ Set option request list for DHCP renew (bug #1233)
+ Set BOOTREQUEST/REPLY properly
+ Change client-identifier field to popularly expected behavior (me)
+ Only reopen port on errors (me)
+ Change fork/close/setsid structures to daemon() (me)
+ Allow user to specify udhcpd config file at run time (Steven, me)
+ Write pidfile after changing it (Steven CTR Carr <Steven.CTR.Carr@tc.faa.gov>)
+ Added env var docs to udhcpc man page (Matt)
+ Standardized lowercase udhcp in documentation (me)
+ Accept packets without a UDP checksum (me)
+ Accept packets with extra garbage (me)
+ Better error handling in files.c (me)
+ Combined read_interface function to reduce COMBINED_BINARY size (me)
+ Drop calc_length(), some servers choke on smaller packets (me)
+ Try to clean some fat out (me)
0.9.6 (011001)
+ Added bootp paramaters to server (me)
+ Added bootp paramaters to client (me)
+ Added vendor id to client (me)
+ Better pidfile handling in client and server (me)
+ Added man pages (Matt Kraai <kraai@alumni.carnegiemellon.edu>)
0.9.5 (010914)
+ Fixed $HOME and $PATH env passing (me)
+ Fixed client to only listen for raw packets on correct interface (me)
+ added --quit,-q option to quit after a lease is obtained (me)
+ Fixed 100% CPU utilization by client when interface is down (me)
0.9.4 (010827)
+ Force broadcast to broken clients that request unicast (ie, MSFT 98)
+ Make install rules (Adam J. Richter <adam@yggdrasil.com>)
+ One scripts, instead of many (Adam)
+ Removed script paramater info files (env vars only) (Adam)
+ Controlling of forking behavior in client (Adam)
+ General script.c/dhcpc.c cleanups (Adam)
0.9.3 (010820)
+ Increased debugging verbosity (me)
+ Cut trailing whitespace when reading config file (me)
+ added hostname option to client (me)
+ fixed a strncpy bug in script.c (me)
+ fixed a leaky socket in dhcpc.c (me)
+ fixed a leaky socket in dhcpd.c (me)
0.9.2 (010810)
+ Added raw sockets to client (me)
+ alignment fixes (Mark Huang)
+ compiler warning fixes (Mark Huang)
+ client now sends parameter list (Mark Huang/me)
+ added ipttl option
+ Does now not request broadcast packets
0.9.1 (010806)
+ Added udhcpc client
+ reorganized functions/files
+ listening socket now only binds to one interface
0.9.0 (010720) Major rewrite, current changes, goals:
+ should not segfault on bogus packets.
+ Options can be read from sname and file fields.
+ supports all DHCP messages (release, decline, inform).
+ IP block is now specified by a range of IP's.
+ Leases file now contains lease time (relative, or absolute).
+ Just about any DHCP option is now supported.
+ DNS entries are no longer read from resolv.conf
+ Lease file can be written periodically when the process receives a SIGUSR1
+ arpping should be supported on all arches.
+ support for DHCP relays.
+ DHCP messages can be unicast if the client requests it.
+ many, many, many other things.
0.8.29 (000323)
+ stable(?) release
0.8.28 (000323)
+ removed alarm as it was causing server to go down
+ removed debugging
+ break down dhcpd.c into manageable files
0.8.27 (000221)
+ OFFER also sends gateway/subnet (for picky dhcp clients)
+ multiple DNS now handled from resolv.conf if available
+ multiple WINS (from dhcpd.conf)
0.8.25 (000120)
+ now compiles *and* runs on a generic linux system
tested with a windows 98 client and the sample config
files in the samples directory.
0.8.24 (000117)
+ makeiplist tool has basic functionality in place
+ new sample config files
+ route add -host 255.255.255.255 dev eth0 added for generic linux
0.8.23 (000117)
+ NETtel specific fix for ignoring dhcp requests on 2nd interface
0.8.22 (000113)
+ minor changes to compile under a generic linux system
+ minor config file location changes for a generic linux system
+ makeiplist fixes.. still incomplete.. but etting closer
0.8.21 (000113)
+ now sends the correct server ip instead of hardcoded value
+ minor debugging fixes for critical messages
0.8.20 (000106)
+ cut out dhcp server checking.. this was causing dialout ppp
sessions with idle time set to never time out.
+ also removed the 10 second pause before launching.. as this
was originally to stop it replying to a dhcp client
on a NETtel which was really a bad way to do it in the
first place :-)
0.8.19 (000104)
+ fixes for route add -host on a machine that needs to run both
a DHCP client and server (dual eth box)
0.8.18 (991220)
+ Race conditions fixed by disabling alarm whilst the server is busy
+ Fixed continous clearing of the offered array so that it is only cleared
when it is dirty - (could change the position of when dirty is set)
0.8.17 (991212)
- has problems clearing out the offered array
0.8.16 (991203)
+ Non blocking error is changes to informational as it is not really
an error
0.8.15 (991129)
+ Servs the dns field 3 times (Nettel only) so that windows servers
dont time out whilst nettel is booting
0.8.14 (991126)
+ added owner check for the offered array so clean out time may be
increased
+ added new func to print out chadder/MAC
0.8.13 (991125)
+ added win95 support (w95 changed xid halfway through conversation)
+ had to change the offered array to use hardware addresses instead of xid
+ fixed re offered bug
+ added more debugging
0.8.12 (991111)
+ debugging was real bad.. cleaned up a bit.. needs overhaul
0.8.11 (991110)
+ fixed up offeredAddr array to actually be used now!! offeredAddr is
used to see if another simultaneous connecting client was offered
an address that we are about to offer another client (multiple
client bug)
+ removed re_offered variable as it breaks multiple client support
+ added lease time to ACK -- doesn't work if in OFFER
+ decreased internal array clear delay to 60 seconds
+ minor findAddr bug (returning -1 instead of 0)
+ if clients xid already in offeredAddr offer the same addr and don't add a
new addr to offered (caused by a client issuing multiple DISCOVERs)
0.8.10 (991105)
+ \n bug in arpping
+ minor debugging changes (removed printfs etc)
+ started browseiplist (not finished)
0.8.9 (19991105)
+ fixed options array size bug (options were cut off)
0.8.8 (19991105)
+ ignores requests from dhcpcd on the same machine
0.8.7 (19991104)
+ don't die if we can't bind to search for existing DHCP server
+ slightly more verbose syslogging
0.8.6 (19991103)
+ added makeiplist (not finished -- core dumps)
+ minor debug changes
0.8.5 (19991029)
+ exits if another DHCP server is already on the network
+ added Linux Makefile
0.8.4 (19991026)
+ minor bug fix in findaddr preventing an addr being found
0.8.3 (19991025)
+ fixed up debugging
+ minor hwaddr issues
0.8.2 (19991022)
+ free leases (new arpping code from dhcpcd)
+ fixed bug where crashes if no leases/iplist file
+ syslogging and debugging switch
+ serve DNS from resolv.conf
+ fixed bug where new lease added if same mac offered
+ now checks the ip is free b4 offering
+ now supports wins server
Loaded 100 of 145 files, more files were not shown because too many files have changed in this diff. Show more