Compare commits
31
Commits
master
...
1_26_stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4316dff48a | ||
|
|
ee72302ac5 | ||
|
|
50504d3a3b | ||
|
|
f8692dc6a0 | ||
|
|
fa654812e7 | ||
|
|
dac762a702 | ||
|
|
889425812b | ||
|
|
8e38108d03 | ||
|
|
add927e3d1 | ||
|
|
7bcc3c46a7 | ||
|
|
9c806db4b7 | ||
|
|
568cabf98a | ||
|
|
e94d2c5f24 | ||
|
|
a12eb9c64d | ||
|
|
1a6aca3d60 | ||
|
|
fe3f55c540 | ||
|
|
28251dfa64 | ||
|
|
9982d88a61 | ||
|
|
e5dc0d0120 | ||
|
|
890b1feaa0 | ||
|
|
d28cd9900a | ||
|
|
909edacc5e | ||
|
|
ed6fb36124 | ||
|
|
048c043ae6 | ||
|
|
f2200af1a8 | ||
|
|
c2f3655842 | ||
|
|
05069b4682 | ||
|
|
8d0dedf1f6 | ||
|
|
e1065da652 | ||
|
|
2169b25b15 | ||
|
|
18a7bee736 |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 26
|
||||
SUBLEVEL = 0
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
|
||||
@@ -9,8 +9,12 @@
|
||||
|
||||
/* lzop_main() uses bbunpack(), need this: */
|
||||
//kbuild:lib-$(CONFIG_LZOP) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o
|
||||
/* bzip2_main() too: */
|
||||
//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
|
||||
/* gzip_main() too: */
|
||||
//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
|
||||
|
||||
/* Note: must be kept in sync with archival/lzop.c */
|
||||
enum {
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@
|
||||
|
||||
//config:config DPKG
|
||||
//config: bool "dpkg"
|
||||
//config: default n
|
||||
//config: default y
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
//config: dpkg is a medium-level tool to install, build, remove and manage
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
|
||||
//config:config DPKG_DEB
|
||||
//config: bool "dpkg_deb"
|
||||
//config: default n
|
||||
//config: default y
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
//config: dpkg-deb unpacks and provides information about Debian archives.
|
||||
|
||||
+245
-197
@@ -16,7 +16,6 @@
|
||||
* TODO
|
||||
* Zip64 + other methods
|
||||
*/
|
||||
|
||||
//config:config UNZIP
|
||||
//config: bool "unzip"
|
||||
//config: default y
|
||||
@@ -24,8 +23,17 @@
|
||||
//config: unzip will list or extract files from a ZIP archive,
|
||||
//config: commonly found on DOS/WIN systems. The default behavior
|
||||
//config: (with no options) is to extract the archive into the
|
||||
//config: current directory. Use the `-d' option to extract to a
|
||||
//config: directory of your choice.
|
||||
//config: current directory.
|
||||
//config:
|
||||
//config:config FEATURE_UNZIP_CDF
|
||||
//config: bool "Read and use Central Directory data"
|
||||
//config: default y
|
||||
//config: depends on UNZIP
|
||||
//config: help
|
||||
//config: If you know that you only need to deal with simple
|
||||
//config: ZIP files without deleted/updated files, SFX archives etc,
|
||||
//config: you can reduce code size by unselecting this option.
|
||||
//config: To support less trivial ZIPs, say Y.
|
||||
|
||||
//applet:IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
|
||||
@@ -54,8 +62,8 @@
|
||||
enum {
|
||||
#if BB_BIG_ENDIAN
|
||||
ZIP_FILEHEADER_MAGIC = 0x504b0304,
|
||||
ZIP_CDF_MAGIC = 0x504b0102, /* central directory's file header */
|
||||
ZIP_CDE_MAGIC = 0x504b0506, /* "end of central directory" record */
|
||||
ZIP_CDF_MAGIC = 0x504b0102, /* CDF item */
|
||||
ZIP_CDE_MAGIC = 0x504b0506, /* End of CDF */
|
||||
ZIP_DD_MAGIC = 0x504b0708,
|
||||
#else
|
||||
ZIP_FILEHEADER_MAGIC = 0x04034b50,
|
||||
@@ -80,30 +88,20 @@ typedef union {
|
||||
uint32_t ucmpsize PACKED; /* 18-21 */
|
||||
uint16_t filename_len; /* 22-23 */
|
||||
uint16_t extra_len; /* 24-25 */
|
||||
} formatted PACKED;
|
||||
/* filename follows (not NUL terminated) */
|
||||
/* extra field follows */
|
||||
/* data follows */
|
||||
} fmt PACKED;
|
||||
} zip_header_t; /* PACKED - gcc 4.2.1 doesn't like it (spews warning) */
|
||||
|
||||
/* Check the offset of the last element, not the length. This leniency
|
||||
* allows for poor packing, whereby the overall struct may be too long,
|
||||
* even though the elements are all in the right place.
|
||||
*/
|
||||
struct BUG_zip_header_must_be_26_bytes {
|
||||
char BUG_zip_header_must_be_26_bytes[
|
||||
offsetof(zip_header_t, formatted.extra_len) + 2
|
||||
== ZIP_HEADER_LEN ? 1 : -1];
|
||||
};
|
||||
|
||||
#define FIX_ENDIANNESS_ZIP(zip_header) do { \
|
||||
(zip_header).formatted.version = SWAP_LE16((zip_header).formatted.version ); \
|
||||
(zip_header).formatted.method = SWAP_LE16((zip_header).formatted.method ); \
|
||||
(zip_header).formatted.modtime = SWAP_LE16((zip_header).formatted.modtime ); \
|
||||
(zip_header).formatted.moddate = SWAP_LE16((zip_header).formatted.moddate ); \
|
||||
(zip_header).formatted.crc32 = SWAP_LE32((zip_header).formatted.crc32 ); \
|
||||
(zip_header).formatted.cmpsize = SWAP_LE32((zip_header).formatted.cmpsize ); \
|
||||
(zip_header).formatted.ucmpsize = SWAP_LE32((zip_header).formatted.ucmpsize ); \
|
||||
(zip_header).formatted.filename_len = SWAP_LE16((zip_header).formatted.filename_len); \
|
||||
(zip_header).formatted.extra_len = SWAP_LE16((zip_header).formatted.extra_len ); \
|
||||
} while (0)
|
||||
#define FIX_ENDIANNESS_ZIP(zip) \
|
||||
do { if (BB_BIG_ENDIAN) { \
|
||||
(zip).fmt.crc32 = SWAP_LE32((zip).fmt.crc32 ); \
|
||||
(zip).fmt.cmpsize = SWAP_LE32((zip).fmt.cmpsize ); \
|
||||
(zip).fmt.ucmpsize = SWAP_LE32((zip).fmt.ucmpsize ); \
|
||||
(zip).fmt.filename_len = SWAP_LE16((zip).fmt.filename_len); \
|
||||
(zip).fmt.extra_len = SWAP_LE16((zip).fmt.extra_len ); \
|
||||
}} while (0)
|
||||
|
||||
#define CDF_HEADER_LEN 42
|
||||
|
||||
@@ -115,44 +113,44 @@ typedef union {
|
||||
uint16_t version_needed; /* 2-3 */
|
||||
uint16_t cdf_flags; /* 4-5 */
|
||||
uint16_t method; /* 6-7 */
|
||||
uint16_t mtime; /* 8-9 */
|
||||
uint16_t mdate; /* 10-11 */
|
||||
uint16_t modtime; /* 8-9 */
|
||||
uint16_t moddate; /* 10-11 */
|
||||
uint32_t crc32; /* 12-15 */
|
||||
uint32_t cmpsize; /* 16-19 */
|
||||
uint32_t ucmpsize; /* 20-23 */
|
||||
uint16_t file_name_length; /* 24-25 */
|
||||
uint16_t extra_field_length; /* 26-27 */
|
||||
uint16_t filename_len; /* 24-25 */
|
||||
uint16_t extra_len; /* 26-27 */
|
||||
uint16_t file_comment_length; /* 28-29 */
|
||||
uint16_t disk_number_start; /* 30-31 */
|
||||
uint16_t internal_file_attributes; /* 32-33 */
|
||||
uint32_t external_file_attributes PACKED; /* 34-37 */
|
||||
uint16_t internal_attributes; /* 32-33 */
|
||||
uint32_t external_attributes PACKED; /* 34-37 */
|
||||
uint32_t relative_offset_of_local_header PACKED; /* 38-41 */
|
||||
} formatted PACKED;
|
||||
/* filename follows (not NUL terminated) */
|
||||
/* extra field follows */
|
||||
/* file comment follows */
|
||||
} fmt PACKED;
|
||||
} cdf_header_t;
|
||||
|
||||
struct BUG_cdf_header_must_be_42_bytes {
|
||||
char BUG_cdf_header_must_be_42_bytes[
|
||||
offsetof(cdf_header_t, formatted.relative_offset_of_local_header) + 4
|
||||
== CDF_HEADER_LEN ? 1 : -1];
|
||||
};
|
||||
#define FIX_ENDIANNESS_CDF(cdf) \
|
||||
do { if (BB_BIG_ENDIAN) { \
|
||||
(cdf).fmt.version_made_by = SWAP_LE16((cdf).fmt.version_made_by); \
|
||||
(cdf).fmt.version_needed = SWAP_LE16((cdf).fmt.version_needed); \
|
||||
(cdf).fmt.method = SWAP_LE16((cdf).fmt.method ); \
|
||||
(cdf).fmt.modtime = SWAP_LE16((cdf).fmt.modtime ); \
|
||||
(cdf).fmt.moddate = SWAP_LE16((cdf).fmt.moddate ); \
|
||||
(cdf).fmt.crc32 = SWAP_LE32((cdf).fmt.crc32 ); \
|
||||
(cdf).fmt.cmpsize = SWAP_LE32((cdf).fmt.cmpsize ); \
|
||||
(cdf).fmt.ucmpsize = SWAP_LE32((cdf).fmt.ucmpsize ); \
|
||||
(cdf).fmt.filename_len = SWAP_LE16((cdf).fmt.filename_len); \
|
||||
(cdf).fmt.extra_len = SWAP_LE16((cdf).fmt.extra_len ); \
|
||||
(cdf).fmt.file_comment_length = SWAP_LE16((cdf).fmt.file_comment_length); \
|
||||
(cdf).fmt.external_attributes = SWAP_LE32((cdf).fmt.external_attributes); \
|
||||
}} while (0)
|
||||
|
||||
#define FIX_ENDIANNESS_CDF(cdf_header) do { \
|
||||
(cdf_header).formatted.crc32 = SWAP_LE32((cdf_header).formatted.crc32 ); \
|
||||
(cdf_header).formatted.cmpsize = SWAP_LE32((cdf_header).formatted.cmpsize ); \
|
||||
(cdf_header).formatted.ucmpsize = SWAP_LE32((cdf_header).formatted.ucmpsize ); \
|
||||
(cdf_header).formatted.file_name_length = SWAP_LE16((cdf_header).formatted.file_name_length); \
|
||||
(cdf_header).formatted.extra_field_length = SWAP_LE16((cdf_header).formatted.extra_field_length); \
|
||||
(cdf_header).formatted.file_comment_length = SWAP_LE16((cdf_header).formatted.file_comment_length); \
|
||||
IF_DESKTOP( \
|
||||
(cdf_header).formatted.version_made_by = SWAP_LE16((cdf_header).formatted.version_made_by); \
|
||||
(cdf_header).formatted.external_file_attributes = SWAP_LE32((cdf_header).formatted.external_file_attributes); \
|
||||
) \
|
||||
} while (0)
|
||||
|
||||
#define CDE_HEADER_LEN 16
|
||||
#define CDE_LEN 16
|
||||
|
||||
typedef union {
|
||||
uint8_t raw[CDE_HEADER_LEN];
|
||||
uint8_t raw[CDE_LEN];
|
||||
struct {
|
||||
/* uint32_t signature; 50 4b 05 06 */
|
||||
uint16_t this_disk_no;
|
||||
@@ -161,25 +159,43 @@ typedef union {
|
||||
uint16_t cdf_entries_total;
|
||||
uint32_t cdf_size;
|
||||
uint32_t cdf_offset;
|
||||
/* uint16_t file_comment_length; */
|
||||
/* .ZIP file comment (variable size) */
|
||||
} formatted PACKED;
|
||||
} cde_header_t;
|
||||
/* uint16_t archive_comment_length; */
|
||||
/* archive comment follows */
|
||||
} fmt PACKED;
|
||||
} cde_t;
|
||||
|
||||
struct BUG_cde_header_must_be_16_bytes {
|
||||
char BUG_cde_header_must_be_16_bytes[
|
||||
sizeof(cde_header_t) == CDE_HEADER_LEN ? 1 : -1];
|
||||
#define FIX_ENDIANNESS_CDE(cde) \
|
||||
do { if (BB_BIG_ENDIAN) { \
|
||||
(cde).fmt.cdf_offset = SWAP_LE32((cde).fmt.cdf_offset); \
|
||||
}} while (0)
|
||||
|
||||
struct BUG {
|
||||
/* Check the offset of the last element, not the length. This leniency
|
||||
* allows for poor packing, whereby the overall struct may be too long,
|
||||
* even though the elements are all in the right place.
|
||||
*/
|
||||
char BUG_zip_header_must_be_26_bytes[
|
||||
offsetof(zip_header_t, fmt.extra_len) + 2
|
||||
== ZIP_HEADER_LEN ? 1 : -1];
|
||||
char BUG_cdf_header_must_be_42_bytes[
|
||||
offsetof(cdf_header_t, fmt.relative_offset_of_local_header) + 4
|
||||
== CDF_HEADER_LEN ? 1 : -1];
|
||||
char BUG_cde_must_be_16_bytes[
|
||||
sizeof(cde_t) == CDE_LEN ? 1 : -1];
|
||||
};
|
||||
|
||||
#define FIX_ENDIANNESS_CDE(cde_header) do { \
|
||||
(cde_header).formatted.cdf_offset = SWAP_LE32((cde_header).formatted.cdf_offset); \
|
||||
} while (0)
|
||||
|
||||
enum { zip_fd = 3 };
|
||||
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
/* This value means that we failed to find CDF */
|
||||
#define BAD_CDF_OFFSET ((uint32_t)0xffffffff)
|
||||
|
||||
#if !ENABLE_FEATURE_UNZIP_CDF
|
||||
|
||||
# define find_cdf_offset() BAD_CDF_OFFSET
|
||||
|
||||
#else
|
||||
/* Seen in the wild:
|
||||
* Self-extracting PRO2K3XP_32.exe contains 19078464 byte zip archive,
|
||||
* where CDE was nearly 48 kbytes before EOF.
|
||||
@@ -188,30 +204,31 @@ enum { zip_fd = 3 };
|
||||
* To make extraction work, bumped PEEK_FROM_END from 16k to 64k.
|
||||
*/
|
||||
#define PEEK_FROM_END (64*1024)
|
||||
|
||||
/* This value means that we failed to find CDF */
|
||||
#define BAD_CDF_OFFSET ((uint32_t)0xffffffff)
|
||||
|
||||
/* NB: does not preserve file position! */
|
||||
static uint32_t find_cdf_offset(void)
|
||||
{
|
||||
cde_header_t cde_header;
|
||||
cde_t cde;
|
||||
unsigned char *buf;
|
||||
unsigned char *p;
|
||||
off_t end;
|
||||
unsigned char *buf = xzalloc(PEEK_FROM_END);
|
||||
uint32_t found;
|
||||
|
||||
end = xlseek(zip_fd, 0, SEEK_END);
|
||||
end = lseek(zip_fd, 0, SEEK_END);
|
||||
if (end == (off_t) -1)
|
||||
return BAD_CDF_OFFSET;
|
||||
|
||||
end -= PEEK_FROM_END;
|
||||
if (end < 0)
|
||||
end = 0;
|
||||
|
||||
dbg("Looking for cdf_offset starting from 0x%"OFF_FMT"x", end);
|
||||
xlseek(zip_fd, end, SEEK_SET);
|
||||
buf = xzalloc(PEEK_FROM_END);
|
||||
full_read(zip_fd, buf, PEEK_FROM_END);
|
||||
|
||||
found = BAD_CDF_OFFSET;
|
||||
p = buf;
|
||||
while (p <= buf + PEEK_FROM_END - CDE_HEADER_LEN - 4) {
|
||||
while (p <= buf + PEEK_FROM_END - CDE_LEN - 4) {
|
||||
if (*p != 'P') {
|
||||
p++;
|
||||
continue;
|
||||
@@ -223,19 +240,19 @@ static uint32_t find_cdf_offset(void)
|
||||
if (*++p != 6)
|
||||
continue;
|
||||
/* we found CDE! */
|
||||
memcpy(cde_header.raw, p + 1, CDE_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDE(cde_header);
|
||||
memcpy(cde.raw, p + 1, CDE_LEN);
|
||||
FIX_ENDIANNESS_CDE(cde);
|
||||
/*
|
||||
* I've seen .ZIP files with seemingly valid CDEs
|
||||
* where cdf_offset points past EOF - ??
|
||||
* This check ignores such CDEs:
|
||||
*/
|
||||
if (cde_header.formatted.cdf_offset < end + (p - buf)) {
|
||||
found = cde_header.formatted.cdf_offset;
|
||||
if (cde.fmt.cdf_offset < end + (p - buf)) {
|
||||
found = cde.fmt.cdf_offset;
|
||||
dbg("Possible cdf_offset:0x%x at 0x%"OFF_FMT"x",
|
||||
(unsigned)found, end + (p-3 - buf));
|
||||
dbg(" cdf_offset+cdf_size:0x%x",
|
||||
(unsigned)(found + SWAP_LE32(cde_header.formatted.cdf_size)));
|
||||
(unsigned)(found + SWAP_LE32(cde.fmt.cdf_size)));
|
||||
/*
|
||||
* We do not "break" here because only the last CDE is valid.
|
||||
* I've seen a .zip archive which contained a .zip file,
|
||||
@@ -249,33 +266,36 @@ static uint32_t find_cdf_offset(void)
|
||||
return found;
|
||||
};
|
||||
|
||||
static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
|
||||
static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf)
|
||||
{
|
||||
off_t org;
|
||||
uint32_t magic;
|
||||
|
||||
org = xlseek(zip_fd, 0, SEEK_CUR);
|
||||
if (cdf_offset == BAD_CDF_OFFSET)
|
||||
return cdf_offset;
|
||||
|
||||
if (!cdf_offset)
|
||||
cdf_offset = find_cdf_offset();
|
||||
|
||||
if (cdf_offset != BAD_CDF_OFFSET) {
|
||||
dbg("Reading CDF at 0x%x", (unsigned)cdf_offset);
|
||||
xlseek(zip_fd, cdf_offset + 4, SEEK_SET);
|
||||
xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDF(*cdf_ptr);
|
||||
dbg(" file_name_length:%u extra_field_length:%u file_comment_length:%u",
|
||||
(unsigned)cdf_ptr->formatted.file_name_length,
|
||||
(unsigned)cdf_ptr->formatted.extra_field_length,
|
||||
(unsigned)cdf_ptr->formatted.file_comment_length
|
||||
);
|
||||
cdf_offset += 4 + CDF_HEADER_LEN
|
||||
+ cdf_ptr->formatted.file_name_length
|
||||
+ cdf_ptr->formatted.extra_field_length
|
||||
+ cdf_ptr->formatted.file_comment_length;
|
||||
dbg("Reading CDF at 0x%x", (unsigned)cdf_offset);
|
||||
xlseek(zip_fd, cdf_offset, SEEK_SET);
|
||||
xread(zip_fd, &magic, 4);
|
||||
/* Central Directory End? Assume CDF has ended.
|
||||
* (more correct method is to use cde.cdf_entries_total counter)
|
||||
*/
|
||||
if (magic == ZIP_CDE_MAGIC) {
|
||||
dbg("got ZIP_CDE_MAGIC");
|
||||
return 0; /* EOF */
|
||||
}
|
||||
xread(zip_fd, cdf->raw, CDF_HEADER_LEN);
|
||||
|
||||
FIX_ENDIANNESS_CDF(*cdf);
|
||||
dbg(" filename_len:%u extra_len:%u file_comment_length:%u",
|
||||
(unsigned)cdf->fmt.filename_len,
|
||||
(unsigned)cdf->fmt.extra_len,
|
||||
(unsigned)cdf->fmt.file_comment_length
|
||||
);
|
||||
cdf_offset += 4 + CDF_HEADER_LEN
|
||||
+ cdf->fmt.filename_len
|
||||
+ cdf->fmt.extra_len
|
||||
+ cdf->fmt.file_comment_length;
|
||||
|
||||
dbg("Returning file position to 0x%"OFF_FMT"x", org);
|
||||
xlseek(zip_fd, org, SEEK_SET);
|
||||
return cdf_offset;
|
||||
};
|
||||
#endif
|
||||
@@ -297,33 +317,34 @@ static void unzip_create_leading_dirs(const char *fn)
|
||||
free(name);
|
||||
}
|
||||
|
||||
static void unzip_extract(zip_header_t *zip_header, int dst_fd)
|
||||
static void unzip_extract(zip_header_t *zip, int dst_fd)
|
||||
{
|
||||
if (zip_header->formatted.method == 0) {
|
||||
if (zip->fmt.method == 0) {
|
||||
/* Method 0 - stored (not compressed) */
|
||||
off_t size = zip_header->formatted.ucmpsize;
|
||||
off_t size = zip->fmt.ucmpsize;
|
||||
if (size)
|
||||
bb_copyfd_exact_size(zip_fd, dst_fd, size);
|
||||
} else {
|
||||
/* Method 8 - inflate */
|
||||
transformer_state_t xstate;
|
||||
init_transformer_state(&xstate);
|
||||
xstate.bytes_in = zip_header->formatted.cmpsize;
|
||||
xstate.bytes_in = zip->fmt.cmpsize;
|
||||
xstate.src_fd = zip_fd;
|
||||
xstate.dst_fd = dst_fd;
|
||||
if (inflate_unzip(&xstate) < 0)
|
||||
bb_error_msg_and_die("inflate error");
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header->formatted.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
|
||||
if (zip->fmt.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
|
||||
bb_error_msg_and_die("crc error");
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.ucmpsize != xstate.bytes_out) {
|
||||
if (zip->fmt.ucmpsize != xstate.bytes_out) {
|
||||
/* Don't die. Who knows, maybe len calculation
|
||||
* was botched somewhere. After all, crc matched! */
|
||||
bb_error_msg("bad length");
|
||||
}
|
||||
}
|
||||
/* TODO? method 12: bzip2, method 14: LZMA */
|
||||
}
|
||||
|
||||
static void my_fgets80(char *buf80)
|
||||
@@ -339,15 +360,12 @@ int unzip_main(int argc, char **argv)
|
||||
{
|
||||
enum { O_PROMPT, O_NEVER, O_ALWAYS };
|
||||
|
||||
zip_header_t zip_header;
|
||||
smallint quiet = 0;
|
||||
IF_NOT_DESKTOP(const) smallint verbose = 0;
|
||||
IF_NOT_FEATURE_UNZIP_CDF(const) smallint verbose = 0;
|
||||
smallint listing = 0;
|
||||
smallint overwrite = O_PROMPT;
|
||||
smallint x_opt_seen;
|
||||
#if ENABLE_DESKTOP
|
||||
uint32_t cdf_offset;
|
||||
#endif
|
||||
unsigned long total_usize;
|
||||
unsigned long total_size;
|
||||
unsigned total_entries;
|
||||
@@ -430,7 +448,7 @@ int unzip_main(int argc, char **argv)
|
||||
break;
|
||||
|
||||
case 'v': /* Verbose list */
|
||||
IF_DESKTOP(verbose++;)
|
||||
IF_FEATURE_UNZIP_CDF(verbose++;)
|
||||
listing = 1;
|
||||
break;
|
||||
|
||||
@@ -545,91 +563,118 @@ int unzip_main(int argc, char **argv)
|
||||
total_usize = 0;
|
||||
total_size = 0;
|
||||
total_entries = 0;
|
||||
#if ENABLE_DESKTOP
|
||||
cdf_offset = 0;
|
||||
#endif
|
||||
cdf_offset = find_cdf_offset(); /* try to seek to the end, find CDE and CDF start */
|
||||
while (1) {
|
||||
uint32_t magic;
|
||||
zip_header_t zip;
|
||||
mode_t dir_mode = 0777;
|
||||
#if ENABLE_DESKTOP
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
mode_t file_mode = 0666;
|
||||
#endif
|
||||
|
||||
/* Check magic number */
|
||||
xread(zip_fd, &magic, 4);
|
||||
/* Central directory? It's at the end, so exit */
|
||||
if (magic == ZIP_CDF_MAGIC) {
|
||||
dbg("got ZIP_CDF_MAGIC");
|
||||
break;
|
||||
if (!ENABLE_FEATURE_UNZIP_CDF || cdf_offset == BAD_CDF_OFFSET) {
|
||||
/* Normally happens when input is unseekable.
|
||||
*
|
||||
* Valid ZIP file has Central Directory at the end
|
||||
* with central directory file headers (CDFs).
|
||||
* After it, there is a Central Directory End structure.
|
||||
* CDFs identify what files are in the ZIP and where
|
||||
* they are located. This allows ZIP readers to load
|
||||
* the list of files without reading the entire ZIP archive.
|
||||
* ZIP files may be appended to, only files specified in
|
||||
* the CD are valid. Scanning for local file headers is
|
||||
* not a correct algorithm.
|
||||
*
|
||||
* We try to do the above, and resort to "linear" reading
|
||||
* of ZIP file only if seek failed or CDE wasn't found.
|
||||
*/
|
||||
uint32_t magic;
|
||||
|
||||
/* Check magic number */
|
||||
xread(zip_fd, &magic, 4);
|
||||
/* CDF item? Assume there are no more files, exit */
|
||||
if (magic == ZIP_CDF_MAGIC) {
|
||||
dbg("got ZIP_CDF_MAGIC");
|
||||
break;
|
||||
}
|
||||
/* Data descriptor? It was a streaming file, go on */
|
||||
if (magic == ZIP_DD_MAGIC) {
|
||||
dbg("got ZIP_DD_MAGIC");
|
||||
/* skip over duplicate crc32, cmpsize and ucmpsize */
|
||||
unzip_skip(3 * 4);
|
||||
continue;
|
||||
}
|
||||
if (magic != ZIP_FILEHEADER_MAGIC)
|
||||
bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
|
||||
dbg("got ZIP_FILEHEADER_MAGIC");
|
||||
|
||||
xread(zip_fd, zip.raw, ZIP_HEADER_LEN);
|
||||
FIX_ENDIANNESS_ZIP(zip);
|
||||
if ((zip.fmt.method != 0)
|
||||
&& (zip.fmt.method != 8)
|
||||
) {
|
||||
/* TODO? method 12: bzip2, method 14: LZMA */
|
||||
bb_error_msg_and_die("unsupported method %d", zip.fmt.method);
|
||||
}
|
||||
if (zip.fmt.zip_flags & SWAP_LE16(0x0009)) {
|
||||
bb_error_msg_and_die("zip flags 1 and 8 are not supported");
|
||||
}
|
||||
}
|
||||
#if ENABLE_DESKTOP
|
||||
/* Data descriptor? It was a streaming file, go on */
|
||||
if (magic == ZIP_DD_MAGIC) {
|
||||
dbg("got ZIP_DD_MAGIC");
|
||||
/* skip over duplicate crc32, cmpsize and ucmpsize */
|
||||
unzip_skip(3 * 4);
|
||||
continue;
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
else {
|
||||
/* cdf_offset is valid (and we know the file is seekable) */
|
||||
cdf_header_t cdf;
|
||||
cdf_offset = read_next_cdf(cdf_offset, &cdf);
|
||||
if (cdf_offset == 0) /* EOF? */
|
||||
break;
|
||||
# if 1
|
||||
xlseek(zip_fd,
|
||||
SWAP_LE32(cdf.fmt.relative_offset_of_local_header) + 4,
|
||||
SEEK_SET);
|
||||
xread(zip_fd, zip.raw, ZIP_HEADER_LEN);
|
||||
FIX_ENDIANNESS_ZIP(zip);
|
||||
if (zip.fmt.zip_flags & SWAP_LE16(0x0008)) {
|
||||
/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
|
||||
* only from Central Directory.
|
||||
*/
|
||||
zip.fmt.crc32 = cdf.fmt.crc32;
|
||||
zip.fmt.cmpsize = cdf.fmt.cmpsize;
|
||||
zip.fmt.ucmpsize = cdf.fmt.ucmpsize;
|
||||
}
|
||||
# else
|
||||
/* CDF has the same data as local header, no need to read the latter...
|
||||
* ...not really. An archive was seen with cdf.extra_len == 6 but
|
||||
* zip.extra_len == 0.
|
||||
*/
|
||||
memcpy(&zip.fmt.version,
|
||||
&cdf.fmt.version_needed, ZIP_HEADER_LEN);
|
||||
xlseek(zip_fd,
|
||||
SWAP_LE32(cdf.fmt.relative_offset_of_local_header) + 4 + ZIP_HEADER_LEN,
|
||||
SEEK_SET);
|
||||
# endif
|
||||
if ((cdf.fmt.version_made_by >> 8) == 3) {
|
||||
/* This archive is created on Unix */
|
||||
dir_mode = file_mode = (cdf.fmt.external_attributes >> 16);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (magic != ZIP_FILEHEADER_MAGIC)
|
||||
bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
|
||||
dbg("got ZIP_FILEHEADER_MAGIC");
|
||||
|
||||
/* Read the file header */
|
||||
xread(zip_fd, zip_header.raw, ZIP_HEADER_LEN);
|
||||
FIX_ENDIANNESS_ZIP(zip_header);
|
||||
if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
|
||||
bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
|
||||
}
|
||||
#if !ENABLE_DESKTOP
|
||||
if (zip_header.formatted.zip_flags & SWAP_LE16(0x0009)) {
|
||||
bb_error_msg_and_die("zip flags 1 and 8 are not supported");
|
||||
}
|
||||
#else
|
||||
if (zip_header.formatted.zip_flags & SWAP_LE16(0x0001)) {
|
||||
if (zip.fmt.zip_flags & SWAP_LE16(0x0001)) {
|
||||
/* 0x0001 - encrypted */
|
||||
bb_error_msg_and_die("zip flag 1 (encryption) is not supported");
|
||||
}
|
||||
|
||||
if (cdf_offset != BAD_CDF_OFFSET) {
|
||||
cdf_header_t cdf_header;
|
||||
cdf_offset = read_next_cdf(cdf_offset, &cdf_header);
|
||||
/*
|
||||
* Note: cdf_offset can become BAD_CDF_OFFSET after the above call.
|
||||
*/
|
||||
if (zip_header.formatted.zip_flags & SWAP_LE16(0x0008)) {
|
||||
/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
|
||||
* only from Central Directory. See unzip_doc.txt
|
||||
*/
|
||||
zip_header.formatted.crc32 = cdf_header.formatted.crc32;
|
||||
zip_header.formatted.cmpsize = cdf_header.formatted.cmpsize;
|
||||
zip_header.formatted.ucmpsize = cdf_header.formatted.ucmpsize;
|
||||
}
|
||||
if ((cdf_header.formatted.version_made_by >> 8) == 3) {
|
||||
/* This archive is created on Unix */
|
||||
dir_mode = file_mode = (cdf_header.formatted.external_file_attributes >> 16);
|
||||
}
|
||||
}
|
||||
if (cdf_offset == BAD_CDF_OFFSET
|
||||
&& (zip_header.formatted.zip_flags & SWAP_LE16(0x0008))
|
||||
) {
|
||||
/* If it's a streaming zip, we _require_ CDF */
|
||||
bb_error_msg_and_die("can't find file table");
|
||||
}
|
||||
#endif
|
||||
dbg("File cmpsize:0x%x extra_len:0x%x ucmpsize:0x%x",
|
||||
(unsigned)zip_header.formatted.cmpsize,
|
||||
(unsigned)zip_header.formatted.extra_len,
|
||||
(unsigned)zip_header.formatted.ucmpsize
|
||||
(unsigned)zip.fmt.cmpsize,
|
||||
(unsigned)zip.fmt.extra_len,
|
||||
(unsigned)zip.fmt.ucmpsize
|
||||
);
|
||||
|
||||
/* Read filename */
|
||||
free(dst_fn);
|
||||
dst_fn = xzalloc(zip_header.formatted.filename_len + 1);
|
||||
xread(zip_fd, dst_fn, zip_header.formatted.filename_len);
|
||||
dst_fn = xzalloc(zip.fmt.filename_len + 1);
|
||||
xread(zip_fd, dst_fn, zip.fmt.filename_len);
|
||||
|
||||
/* Skip extra header bytes */
|
||||
unzip_skip(zip_header.formatted.extra_len);
|
||||
unzip_skip(zip.fmt.extra_len);
|
||||
|
||||
/* Guard against "/abspath", "/../" and similar attacks */
|
||||
overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn));
|
||||
@@ -644,32 +689,32 @@ int unzip_main(int argc, char **argv)
|
||||
/* List entry */
|
||||
char dtbuf[sizeof("mm-dd-yyyy hh:mm")];
|
||||
sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u",
|
||||
(zip_header.formatted.moddate >> 5) & 0xf, // mm: 0x01e0
|
||||
(zip_header.formatted.moddate) & 0x1f, // dd: 0x001f
|
||||
(zip_header.formatted.moddate >> 9) + 1980, // yy: 0xfe00
|
||||
(zip_header.formatted.modtime >> 11), // hh: 0xf800
|
||||
(zip_header.formatted.modtime >> 5) & 0x3f // mm: 0x07e0
|
||||
// seconds/2 are not shown, encoded in ----------- 0x001f
|
||||
(zip.fmt.moddate >> 5) & 0xf, // mm: 0x01e0
|
||||
(zip.fmt.moddate) & 0x1f, // dd: 0x001f
|
||||
(zip.fmt.moddate >> 9) + 1980, // yy: 0xfe00
|
||||
(zip.fmt.modtime >> 11), // hh: 0xf800
|
||||
(zip.fmt.modtime >> 5) & 0x3f // mm: 0x07e0
|
||||
// seconds/2 not shown, encoded in -- 0x001f
|
||||
);
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
// "--------- ---------- ----- ----"
|
||||
printf( "%9u " "%s " "%s\n",
|
||||
(unsigned)zip_header.formatted.ucmpsize,
|
||||
(unsigned)zip.fmt.ucmpsize,
|
||||
dtbuf,
|
||||
dst_fn);
|
||||
} else {
|
||||
unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize;
|
||||
unsigned long percents = zip.fmt.ucmpsize - zip.fmt.cmpsize;
|
||||
if ((int32_t)percents < 0)
|
||||
percents = 0; /* happens if ucmpsize < cmpsize */
|
||||
percents = percents * 100;
|
||||
if (zip_header.formatted.ucmpsize)
|
||||
percents /= zip_header.formatted.ucmpsize;
|
||||
if (zip.fmt.ucmpsize)
|
||||
percents /= zip.fmt.ucmpsize;
|
||||
// " Length Method Size Cmpr Date Time CRC-32 Name\n"
|
||||
// "-------- ------ ------- ---- ---------- ----- -------- ----"
|
||||
printf( "%8u %s" "%9u%4u%% " "%s " "%08x " "%s\n",
|
||||
(unsigned)zip_header.formatted.ucmpsize,
|
||||
zip_header.formatted.method == 0 ? "Stored" : "Defl:N", /* Defl is method 8 */
|
||||
(unsigned)zip.fmt.ucmpsize,
|
||||
zip.fmt.method == 0 ? "Stored" : "Defl:N", /* Defl is method 8 */
|
||||
/* TODO: show other methods?
|
||||
* 1 - Shrunk
|
||||
* 2 - Reduced with compression factor 1
|
||||
@@ -682,15 +727,16 @@ int unzip_main(int argc, char **argv)
|
||||
* 10 - PKWARE Data Compression Library Imploding
|
||||
* 11 - Reserved by PKWARE
|
||||
* 12 - BZIP2
|
||||
* 14 - LZMA
|
||||
*/
|
||||
(unsigned)zip_header.formatted.cmpsize,
|
||||
(unsigned)zip.fmt.cmpsize,
|
||||
(unsigned)percents,
|
||||
dtbuf,
|
||||
zip_header.formatted.crc32,
|
||||
zip.fmt.crc32,
|
||||
dst_fn);
|
||||
total_size += zip_header.formatted.cmpsize;
|
||||
total_size += zip.fmt.cmpsize;
|
||||
}
|
||||
total_usize += zip_header.formatted.ucmpsize;
|
||||
total_usize += zip.fmt.ucmpsize;
|
||||
i = 'n';
|
||||
} else if (dst_fd == STDOUT_FILENO) {
|
||||
/* Extracting to STDOUT */
|
||||
@@ -751,16 +797,18 @@ int unzip_main(int argc, char **argv)
|
||||
overwrite = O_ALWAYS;
|
||||
case 'y': /* Open file and fall into unzip */
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
#if ENABLE_DESKTOP
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
dst_fd = xopen3(dst_fn, O_WRONLY | O_CREAT | O_TRUNC, file_mode);
|
||||
#else
|
||||
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
#endif
|
||||
case -1: /* Unzip */
|
||||
if (!quiet) {
|
||||
printf(" inflating: %s\n", dst_fn);
|
||||
printf(/* zip.fmt.method == 0
|
||||
? " extracting: %s\n"
|
||||
: */ " inflating: %s\n", dst_fn);
|
||||
}
|
||||
unzip_extract(&zip_header, dst_fd);
|
||||
unzip_extract(&zip, dst_fd);
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
/* closing STDOUT is potentially bad for future business */
|
||||
close(dst_fd);
|
||||
@@ -771,7 +819,7 @@ int unzip_main(int argc, char **argv)
|
||||
overwrite = O_NEVER;
|
||||
case 'n':
|
||||
/* Skip entry data */
|
||||
unzip_skip(zip_header.formatted.cmpsize);
|
||||
unzip_skip(zip.fmt.cmpsize);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
|
||||
+12
-8
@@ -10,12 +10,16 @@ lib-y:=
|
||||
|
||||
INSERT
|
||||
|
||||
lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty
|
||||
lib-$(CONFIG_LESS) += cat.o # less too
|
||||
lib-$(CONFIG_CRONTAB) += cat.o # crontab -l
|
||||
lib-$(CONFIG_ADDUSER) += chown.o # used by adduser
|
||||
lib-$(CONFIG_ADDGROUP) += chown.o # used by adduser
|
||||
lib-$(CONFIG_ASH) += echo.o # used by ash
|
||||
lib-$(CONFIG_HUSH) += echo.o # used by hush
|
||||
lib-$(CONFIG_FTPD) += ls.o # used by ftpd
|
||||
lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty
|
||||
lib-$(CONFIG_LESS) += cat.o # less too
|
||||
lib-$(CONFIG_CRONTAB) += cat.o # crontab -l
|
||||
lib-$(CONFIG_ADDUSER) += chown.o # used by adduser
|
||||
lib-$(CONFIG_ADDGROUP) += chown.o # used by adduser
|
||||
lib-$(CONFIG_ASH) += echo.o # used by ash
|
||||
lib-$(CONFIG_SH_IS_ASH) += echo.o # used by ash
|
||||
lib-$(CONFIG_BASH_IS_ASH) += echo.o # used by ash
|
||||
lib-$(CONFIG_HUSH) += echo.o # used by hush
|
||||
lib-$(CONFIG_SH_IS_HUSH) += echo.o # used by hush
|
||||
lib-$(CONFIG_BASH_IS_HUSH) += echo.o # used by hush
|
||||
lib-$(CONFIG_FTPD) += ls.o # used by ftpd
|
||||
lib-$(CONFIG_ASH_BUILTIN_PRINTF) += printf.o
|
||||
@@ -55,6 +55,8 @@
|
||||
//kbuild:lib-$(CONFIG_TEST2) += test.o test_ptr_hack.o
|
||||
//kbuild:lib-$(CONFIG_ASH_BUILTIN_TEST) += test.o test_ptr_hack.o
|
||||
//kbuild:lib-$(CONFIG_HUSH) += test.o test_ptr_hack.o
|
||||
//kbuild:lib-$(CONFIG_SH_IS_HUSH) += test.o test_ptr_hack.o
|
||||
//kbuild:lib-$(CONFIG_BASH_IS_HUSH) += test.o test_ptr_hack.o
|
||||
|
||||
/* "test --help" is special-cased to ignore --help */
|
||||
//usage:#define test_trivial_usage NOUSAGE_STR
|
||||
|
||||
@@ -4,11 +4,7 @@
|
||||
# enabling it. Run it after applets.h is generated.
|
||||
|
||||
# CONFIG_applet names
|
||||
grep ^IF_ applets.h | grep -v IF_FEATURE_ | sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
|
||||
| grep -v MODPROBE_SMALL \
|
||||
| sed 's/BB_SYSCTL/SYSCTL/' \
|
||||
| sed 's/TEST1/[/' \
|
||||
| sed 's/TEST2/[[/' \
|
||||
grep ^IF_ applets.h | grep -v ^IF_FEATURE_ | sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
|
||||
| sort | uniq \
|
||||
>applets_APP1
|
||||
|
||||
@@ -17,8 +13,11 @@ grep ^IF_ applets.h | sed -e's/ //g' -e's/.*(\([a-z[][^,]*\),.*/\1/' \
|
||||
| grep -v '^bash$' \
|
||||
| grep -v '^sh$' \
|
||||
| tr a-z A-Z \
|
||||
| sed 's/^SYSCTL$/BB_SYSCTL/' \
|
||||
| sed 's/^\[\[$/TEST1/' \
|
||||
| sed 's/^\[$/TEST2/' \
|
||||
| sort | uniq \
|
||||
>applets_APP2
|
||||
|
||||
diff -u applets_APP1 applets_APP2 >applets_APP.diff
|
||||
rm applets_APP1 applets_APP2
|
||||
#rm applets_APP1 applets_APP2
|
||||
+1
-1
@@ -83,7 +83,7 @@
|
||||
//config:
|
||||
//config:config FEATURE_INIT_COREDUMPS
|
||||
//config: bool "Support dumping core for child processes (debugging only)"
|
||||
//config: default y
|
||||
//config: default n # not Y because this is a debug option
|
||||
//config: depends on INIT || LINUXRC
|
||||
//config: help
|
||||
//config: If this option is enabled and the file /.init_enable_core
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ config FEATURE_TAB_COMPLETION
|
||||
|
||||
config FEATURE_USERNAME_COMPLETION
|
||||
bool "Username completion"
|
||||
default n
|
||||
default y
|
||||
depends on FEATURE_TAB_COMPLETION
|
||||
help
|
||||
Enable username completion.
|
||||
|
||||
@@ -176,6 +176,7 @@ lib-$(CONFIG_TRACEROUTE6) += inet_cksum.o
|
||||
lib-$(CONFIG_UDHCPC) += inet_cksum.o
|
||||
lib-$(CONFIG_UDHCPC6) += inet_cksum.o
|
||||
lib-$(CONFIG_UDHCPD) += inet_cksum.o
|
||||
lib-$(CONFIG_DHCPRELAY) += inet_cksum.o
|
||||
|
||||
# We shouldn't build xregcomp.c if we don't need it - this ensures we don't
|
||||
# require regex.h to be in the include dir even if we don't need it thereby
|
||||
|
||||
+16
-16
@@ -329,21 +329,6 @@ static struct suid_config_t {
|
||||
|
||||
static bool suid_cfg_readable;
|
||||
|
||||
/* check if u is member of group g */
|
||||
static int ingroup(uid_t u, gid_t g)
|
||||
{
|
||||
struct group *grp = getgrgid(g);
|
||||
if (grp) {
|
||||
char **mem;
|
||||
for (mem = grp->gr_mem; *mem; mem++) {
|
||||
struct passwd *pwd = getpwnam(*mem);
|
||||
if (pwd && (pwd->pw_uid == u))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* libbb candidate */
|
||||
static char *get_trimmed_slice(char *s, char *e)
|
||||
{
|
||||
@@ -568,7 +553,22 @@ static inline void parse_config_file(void)
|
||||
# endif /* FEATURE_SUID_CONFIG */
|
||||
|
||||
|
||||
# if ENABLE_FEATURE_SUID
|
||||
# if ENABLE_FEATURE_SUID && NUM_APPLETS > 0
|
||||
/* check if u is member of group g */
|
||||
static int ingroup(uid_t u, gid_t g)
|
||||
{
|
||||
struct group *grp = getgrgid(g);
|
||||
if (grp) {
|
||||
char **mem;
|
||||
for (mem = grp->gr_mem; *mem; mem++) {
|
||||
struct passwd *pwd = getpwnam(*mem);
|
||||
if (pwd && (pwd->pw_uid == u))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void check_suid(int applet_no)
|
||||
{
|
||||
gid_t rgid; /* real gid */
|
||||
|
||||
@@ -180,6 +180,7 @@ int FAST_FUNC update_passwd(const char *filename,
|
||||
if (!line) /* EOF/error */
|
||||
break;
|
||||
|
||||
#if ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP
|
||||
if (!name && member) {
|
||||
/* Delete member from all groups */
|
||||
/* line is "GROUP:PASSWD:[member1[,member2]...]" */
|
||||
@@ -209,6 +210,7 @@ int FAST_FUNC update_passwd(const char *filename,
|
||||
fprintf(new_fp, "%s\n", line);
|
||||
goto next;
|
||||
}
|
||||
#endif
|
||||
|
||||
cp = is_prefixed_with(line, name_colon);
|
||||
if (!cp) {
|
||||
|
||||
+3
-1
@@ -69,7 +69,9 @@
|
||||
#if ENABLE_SELINUX
|
||||
# include <selinux/selinux.h> /* for is_selinux_enabled() */
|
||||
# include <selinux/get_context_list.h> /* for get_default_context() */
|
||||
# include <selinux/flask.h> /* for security class definitions */
|
||||
# /* from deprecated <selinux/flask.h>: */
|
||||
# undef SECCLASS_CHR_FILE
|
||||
# define SECCLASS_CHR_FILE 10
|
||||
#endif
|
||||
|
||||
#if ENABLE_PAM
|
||||
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
#!/bin/sh
|
||||
# This script expects that the tree was built with the desired .config:
|
||||
# in particular, it expects that include/applets.h is generated already.
|
||||
#
|
||||
# The script will try to rebuild each enabled applet in isolation.
|
||||
# All other options which chose general bbox config, applet features, etc,
|
||||
# are not modified for the builds.
|
||||
|
||||
makeopts="-j9"
|
||||
|
||||
# The list of all applet config symbols
|
||||
test -f include/applets.h || { echo "No include/applets.h file"; exit 1; }
|
||||
apps="`
|
||||
grep ^IF_ include/applets.h \
|
||||
| grep -v ^IF_FEATURE_ \
|
||||
| sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
|
||||
| sort | uniq
|
||||
`"
|
||||
|
||||
# Take existing config
|
||||
test -f .config || { echo "No .config file"; exit 1; }
|
||||
cfg="`cat .config`"
|
||||
|
||||
# Make a config with all applet symbols off
|
||||
allno="$cfg"
|
||||
for app in $apps; do
|
||||
allno="`echo "$allno" | sed "s/^CONFIG_${app}=y\$/# CONFIG_${app} is not set/"`"
|
||||
done
|
||||
#echo "$allno" >.config_allno
|
||||
|
||||
# Turn on each applet individually and build single-applet executable
|
||||
fail=0
|
||||
for app in $apps; do
|
||||
# Only if it was indeed originally enabled...
|
||||
{ echo "$cfg" | grep -q "^CONFIG_${app}=y\$"; } || continue
|
||||
|
||||
echo "Making ${app}..."
|
||||
mv .config .config.SV
|
||||
echo "CONFIG_${app}=y" >.config
|
||||
echo "$allno" | sed "/^# CONFIG_${app} is not set\$/d" >>.config
|
||||
|
||||
if test x"${app}" != x"SH_IS_ASH" && test x"${app}" != x"SH_IS_HUSH"; then
|
||||
# $allno has all choices for "sh" aliasing set to off.
|
||||
# "sh" aliasing defaults to "ash", not none.
|
||||
# without this fix, "make oldconfig" sets it wrong,
|
||||
# resulting in NUM_APPLETS = 2 (the second applet is "sh")
|
||||
sed '/CONFIG_SH_IS_NONE/d' -i .config
|
||||
echo "CONFIG_SH_IS_NONE=y" >>.config
|
||||
fi
|
||||
|
||||
if ! yes '' | make oldconfig >busybox_make_${app}.log 2>&1; then
|
||||
: $((fail++))
|
||||
echo "Config error for ${app}"
|
||||
mv .config busybox_config_${app}
|
||||
elif ! make $makeopts >>busybox_make_${app}.log 2>&1; then
|
||||
: $((fail++))
|
||||
echo "Build error for ${app}"
|
||||
mv .config busybox_config_${app}
|
||||
elif ! grep -q '^#define NUM_APPLETS 1$' include/NUM_APPLETS.h; then
|
||||
mv busybox busybox_${app}
|
||||
: $((fail++))
|
||||
echo "NUM_APPLETS != 1 for ${app}: `cat include/NUM_APPLETS.h`"
|
||||
mv .config busybox_config_${app}
|
||||
else
|
||||
mv busybox busybox_${app}
|
||||
rm busybox_make_${app}.log
|
||||
fi
|
||||
mv .config.SV .config
|
||||
#exit
|
||||
done
|
||||
touch .config # or else next "make" can be confused
|
||||
echo "Failures: $fail"
|
||||
test $fail = 0 # set exitcode
|
||||
@@ -5,6 +5,37 @@
|
||||
|
||||
menu "Linux Module Utilities"
|
||||
|
||||
config MODPROBE_SMALL
|
||||
bool "Simplified modutils"
|
||||
default y
|
||||
select PLATFORM_LINUX
|
||||
help
|
||||
Simplified modutils.
|
||||
|
||||
With this option modprobe does not require modules.dep file
|
||||
and does not use /etc/modules.conf file.
|
||||
It scans module files in /lib/modules/`uname -r` and
|
||||
determines dependencies and module alias names on the fly.
|
||||
This may make module loading slower, most notably
|
||||
when one needs to load module by alias (this requires
|
||||
scanning through module _bodies_).
|
||||
|
||||
At the first attempt to load a module by alias modprobe
|
||||
will try to generate modules.dep.bb file in order to speed up
|
||||
future loads by alias. Failure to do so (read-only /lib/modules,
|
||||
etc) is not reported, and future modprobes will be slow too.
|
||||
|
||||
NB: modules.dep.bb file format is not compatible
|
||||
with modules.dep file as created/used by standard module tools.
|
||||
|
||||
Additional module parameters can be stored in
|
||||
/etc/modules/$module_name files.
|
||||
|
||||
Apart from modprobe, other utilities are also provided:
|
||||
- insmod is an alias to modprobe
|
||||
- rmmod is an alias to modprobe -r
|
||||
- depmod generates modules.dep.bb
|
||||
|
||||
INSERT
|
||||
|
||||
comment "Options common to multiple modutils"
|
||||
|
||||
+4
-3
@@ -9,17 +9,18 @@
|
||||
*/
|
||||
//config:config DEPMOD
|
||||
//config: bool "depmod"
|
||||
//config: default n
|
||||
//config: depends on !MODPROBE_SMALL
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: depmod generates modules.dep (and potentially modules.alias
|
||||
//config: and modules.symbols) that contain dependency information
|
||||
//config: for modprobe.
|
||||
|
||||
//applet:IF_DEPMOD(APPLET(depmod, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//applet:IF_DEPMOD(IF_NOT_MODPROBE_SMALL(APPLET(depmod, BB_DIR_SBIN, BB_SUID_DROP)))
|
||||
|
||||
//kbuild:ifneq ($(CONFIG_MODPROBE_SMALL),y)
|
||||
//kbuild:lib-$(CONFIG_DEPMOD) += depmod.o modutils.o
|
||||
//kbuild:endif
|
||||
|
||||
#include "libbb.h"
|
||||
#include "modutils.h"
|
||||
|
||||
+4
-3
@@ -8,15 +8,16 @@
|
||||
*/
|
||||
//config:config INSMOD
|
||||
//config: bool "insmod"
|
||||
//config: default n
|
||||
//config: depends on !MODPROBE_SMALL
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: insmod is used to load specified modules in the running kernel.
|
||||
|
||||
//applet:IF_INSMOD(APPLET(insmod, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//applet:IF_INSMOD(IF_NOT_MODPROBE_SMALL(APPLET(insmod, BB_DIR_SBIN, BB_SUID_DROP)))
|
||||
|
||||
//kbuild:ifneq ($(CONFIG_MODPROBE_SMALL),y)
|
||||
//kbuild:lib-$(CONFIG_INSMOD) += insmod.o modutils.o
|
||||
//kbuild:endif
|
||||
|
||||
#include "libbb.h"
|
||||
#include "modutils.h"
|
||||
|
||||
+6
-5
@@ -9,25 +9,26 @@
|
||||
*/
|
||||
//config:config LSMOD
|
||||
//config: bool "lsmod"
|
||||
//config: default n
|
||||
//config: depends on !MODPROBE_SMALL
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: lsmod is used to display a list of loaded modules.
|
||||
//config:
|
||||
//config:config FEATURE_LSMOD_PRETTY_2_6_OUTPUT
|
||||
//config: bool "Pretty output"
|
||||
//config: default n
|
||||
//config: depends on LSMOD
|
||||
//config: default y
|
||||
//config: depends on LSMOD && !MODPROBE_SMALL
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: This option makes output format of lsmod adjusted to
|
||||
//config: the format of module-init-tools for Linux kernel 2.6.
|
||||
//config: Increases size somewhat.
|
||||
|
||||
//applet:IF_LSMOD(APPLET(lsmod, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//applet:IF_LSMOD(IF_NOT_MODPROBE_SMALL(APPLET(lsmod, BB_DIR_SBIN, BB_SUID_DROP)))
|
||||
|
||||
//kbuild:ifneq ($(CONFIG_MODPROBE_SMALL),y)
|
||||
//kbuild:lib-$(CONFIG_LSMOD) += lsmod.o modutils.o
|
||||
//kbuild:endif
|
||||
|
||||
//usage:#if !ENABLE_MODPROBE_SMALL
|
||||
//usage:#define lsmod_trivial_usage
|
||||
|
||||
+17
-45
@@ -7,37 +7,9 @@
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config MODPROBE_SMALL
|
||||
//config: bool "Simplified modutils"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Simplified modutils.
|
||||
//config:
|
||||
//config: With this option modprobe does not require modules.dep file
|
||||
//config: and does not use /etc/modules.conf file.
|
||||
//config: It scans module files in /lib/modules/`uname -r` and
|
||||
//config: determines dependencies and module alias names on the fly.
|
||||
//config: This may make module loading slower, most notably
|
||||
//config: when one needs to load module by alias (this requires
|
||||
//config: scanning through module _bodies_).
|
||||
//config:
|
||||
//config: At the first attempt to load a module by alias modprobe
|
||||
//config: will try to generate modules.dep.bb file in order to speed up
|
||||
//config: future loads by alias. Failure to do so (read-only /lib/modules,
|
||||
//config: etc) is not reported, and future modprobes will be slow too.
|
||||
//config:
|
||||
//config: NB: modules.dep.bb file format is not compatible
|
||||
//config: with modules.dep file as created/used by standard module tools.
|
||||
//config:
|
||||
//config: Additional module parameters can be stored in
|
||||
//config: /etc/modules/$module_name files.
|
||||
//config:
|
||||
//config: Apart from modprobe, other utilities are also provided:
|
||||
//config: - insmod is an alias to modprobe
|
||||
//config: - rmmod is an alias to modprobe -r
|
||||
//config: - depmod generates modules.dep.bb
|
||||
//config:
|
||||
|
||||
/* config MODPROBE_SMALL is defined in Config.src to ensure better "make config" order */
|
||||
|
||||
//config:config FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE
|
||||
//config: bool "Accept module options on modprobe command line"
|
||||
//config: default y
|
||||
@@ -53,11 +25,11 @@
|
||||
//config: help
|
||||
//config: Check if the module is already loaded.
|
||||
|
||||
//applet:IF_MODPROBE_SMALL(APPLET(modprobe, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(depmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, depmod))
|
||||
//applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(insmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, insmod))
|
||||
//applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(lsmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, lsmod))
|
||||
//applet:IF_MODPROBE_SMALL(APPLET_ODDNAME(rmmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, rmmod))
|
||||
//applet:IF_MODPROBE(IF_MODPROBE_SMALL(APPLET(modprobe, BB_DIR_SBIN, BB_SUID_DROP)))
|
||||
//applet:IF_DEPMOD(IF_MODPROBE_SMALL(APPLET_ODDNAME(depmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, depmod)))
|
||||
//applet:IF_INSMOD(IF_MODPROBE_SMALL(APPLET_ODDNAME(insmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, insmod)))
|
||||
//applet:IF_LSMOD(IF_MODPROBE_SMALL(APPLET_ODDNAME(lsmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, lsmod)))
|
||||
//applet:IF_RMMOD(IF_MODPROBE_SMALL(APPLET_ODDNAME(rmmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, rmmod)))
|
||||
|
||||
//kbuild:lib-$(CONFIG_MODPROBE_SMALL) += modprobe-small.o
|
||||
|
||||
@@ -67,8 +39,8 @@
|
||||
#include <fnmatch.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
extern int init_module(void *module, unsigned long len, const char *options);
|
||||
extern int delete_module(const char *module, unsigned flags);
|
||||
#define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts)
|
||||
#define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags)
|
||||
#ifdef __NR_finit_module
|
||||
# define finit_module(fd, uargs, flags) syscall(__NR_finit_module, fd, uargs, flags)
|
||||
#endif
|
||||
@@ -958,7 +930,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(char *options;)
|
||||
|
||||
/* are we lsmod? -> just dump /proc/modules */
|
||||
if ('l' == applet0) {
|
||||
if (ENABLE_LSMOD && 'l' == applet0) {
|
||||
xprint_and_close_file(xfopen_for_read("/proc/modules"));
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -968,14 +940,14 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Prevent ugly corner cases with no modules at all */
|
||||
modinfo = xzalloc(sizeof(modinfo[0]));
|
||||
|
||||
if ('i' != applet0) { /* not insmod */
|
||||
if (!ENABLE_INSMOD || 'i' != applet0) { /* not insmod */
|
||||
/* Goto modules directory */
|
||||
xchdir(CONFIG_DEFAULT_MODULES_DIR);
|
||||
}
|
||||
uname(&uts); /* never fails */
|
||||
|
||||
/* depmod? */
|
||||
if ('d' == applet0) {
|
||||
if (ENABLE_DEPMOD && 'd' == applet0) {
|
||||
/* Supported:
|
||||
* -n: print result to stdout
|
||||
* -a: process all modules (default)
|
||||
@@ -1014,11 +986,11 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
argv += optind;
|
||||
|
||||
/* are we rmmod? -> simulate modprobe -r */
|
||||
if ('r' == applet0) {
|
||||
if (ENABLE_RMMOD && 'r' == applet0) {
|
||||
option_mask32 |= OPT_r;
|
||||
}
|
||||
|
||||
if ('i' != applet0) { /* not insmod */
|
||||
if (!ENABLE_INSMOD || 'i' != applet0) { /* not insmod */
|
||||
/* Goto $VERSION directory */
|
||||
xchdir(uts.release);
|
||||
}
|
||||
@@ -1042,7 +1014,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
argv[1] = NULL;
|
||||
#endif
|
||||
|
||||
if ('i' == applet0) { /* insmod */
|
||||
if (ENABLE_INSMOD && 'i' == applet0) { /* insmod */
|
||||
size_t len;
|
||||
void *map;
|
||||
|
||||
@@ -1062,7 +1034,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
/* Try to load modprobe.dep.bb */
|
||||
if ('r' != applet0) { /* not rmmod */
|
||||
if (!ENABLE_RMMOD || 'r' != applet0) { /* not rmmod */
|
||||
load_dep_bb();
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -9,8 +9,7 @@
|
||||
*/
|
||||
//config:config MODPROBE
|
||||
//config: bool "modprobe"
|
||||
//config: default n
|
||||
//config: depends on !MODPROBE_SMALL
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Handle the loading of modules, and their dependencies on a high
|
||||
@@ -18,8 +17,8 @@
|
||||
//config:
|
||||
//config:config FEATURE_MODPROBE_BLACKLIST
|
||||
//config: bool "Blacklist support"
|
||||
//config: default n
|
||||
//config: depends on MODPROBE
|
||||
//config: default y
|
||||
//config: depends on MODPROBE && !MODPROBE_SMALL
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Say 'y' here to enable support for the 'blacklist' command in
|
||||
@@ -28,9 +27,11 @@
|
||||
//config: hardware autodetection scripts to load modules like evdev, frame
|
||||
//config: buffer drivers etc.
|
||||
|
||||
//applet:IF_MODPROBE(APPLET(modprobe, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//applet:IF_MODPROBE(IF_NOT_MODPROBE_SMALL(APPLET(modprobe, BB_DIR_SBIN, BB_SUID_DROP)))
|
||||
|
||||
//kbuild:ifneq ($(CONFIG_MODPROBE_SMALL),y)
|
||||
//kbuild:lib-$(CONFIG_MODPROBE) += modprobe.o modutils.o
|
||||
//kbuild:endif
|
||||
|
||||
#include "libbb.h"
|
||||
#include "modutils.h"
|
||||
|
||||
+6
-10
@@ -7,17 +7,13 @@
|
||||
*/
|
||||
#include "modutils.h"
|
||||
|
||||
#ifdef __UCLIBC__
|
||||
extern int init_module(void *module, unsigned long len, const char *options);
|
||||
extern int delete_module(const char *module, unsigned int flags);
|
||||
#else
|
||||
# include <sys/syscall.h>
|
||||
# define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts)
|
||||
# if defined(__NR_finit_module)
|
||||
# define finit_module(fd, uargs, flags) syscall(__NR_finit_module, fd, uargs, flags)
|
||||
# endif
|
||||
# define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags)
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts)
|
||||
#if defined(__NR_finit_module)
|
||||
# define finit_module(fd, uargs, flags) syscall(__NR_finit_module, fd, uargs, flags)
|
||||
#endif
|
||||
#define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags)
|
||||
|
||||
static module_entry *helper_get_module(module_db *db, const char *module, int create)
|
||||
{
|
||||
|
||||
+4
-3
@@ -9,15 +9,16 @@
|
||||
*/
|
||||
//config:config RMMOD
|
||||
//config: bool "rmmod"
|
||||
//config: default n
|
||||
//config: depends on !MODPROBE_SMALL
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: rmmod is used to unload specified modules from the kernel.
|
||||
|
||||
//applet:IF_RMMOD(APPLET(rmmod, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//applet:IF_RMMOD(IF_NOT_MODPROBE_SMALL(APPLET(rmmod, BB_DIR_SBIN, BB_SUID_DROP)))
|
||||
|
||||
//kbuild:ifneq ($(CONFIG_MODPROBE_SMALL),y)
|
||||
//kbuild:lib-$(CONFIG_RMMOD) += rmmod.o modutils.o
|
||||
//kbuild:endif
|
||||
|
||||
//usage:#if !ENABLE_MODPROBE_SMALL
|
||||
//usage:#define rmmod_trivial_usage
|
||||
|
||||
@@ -53,7 +53,7 @@ source networking/udhcp/Config.in
|
||||
config IFUPDOWN_UDHCPC_CMD_OPTIONS
|
||||
string "ifup udhcpc command line options"
|
||||
default "-R -n"
|
||||
depends on IFUPDOWN && UDHCPC
|
||||
depends on IFUP || IFDOWN
|
||||
help
|
||||
Command line options to pass to udhcpc from ifup.
|
||||
Intended to alter options not available in /etc/network/interfaces.
|
||||
|
||||
+1
-1
@@ -2337,7 +2337,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
|
||||
if (STRNCASECMP(iobuf, "Range:") == 0) {
|
||||
/* We know only bytes=NNN-[MMM] */
|
||||
char *s = skip_whitespace(iobuf + sizeof("Range:")-1);
|
||||
if (is_prefixed_with(s, "bytes=") == 0) {
|
||||
if (is_prefixed_with(s, "bytes=")) {
|
||||
s += sizeof("bytes=")-1;
|
||||
range_start = BB_STRTOOFF(s, &s, 10);
|
||||
if (s[0] != '-' || range_start < 0) {
|
||||
|
||||
+7
-29
@@ -51,41 +51,19 @@
|
||||
//config: This config option defines location of ifstate.
|
||||
//config:
|
||||
//config:config FEATURE_IFUPDOWN_IP
|
||||
//config: bool "Use ip applet"
|
||||
//config: bool "Use ip tool (else ifconfig/route is used)"
|
||||
//config: default y
|
||||
//config: depends on IFUP || IFDOWN
|
||||
//config: help
|
||||
//config: Use the iproute "ip" command to implement "ifup" and "ifdown", rather
|
||||
//config: than the default of using the older 'ifconfig' and 'route' utilities.
|
||||
//config: than the default of using the older "ifconfig" and "route" utilities.
|
||||
//config:
|
||||
//config:config FEATURE_IFUPDOWN_IP_BUILTIN
|
||||
//config: bool "Use busybox ip applet"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_IFUPDOWN_IP
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: select IP
|
||||
//config: select FEATURE_IP_ADDRESS
|
||||
//config: select FEATURE_IP_LINK
|
||||
//config: select FEATURE_IP_ROUTE
|
||||
//config: help
|
||||
//config: Use the busybox iproute "ip" applet to implement "ifupdown".
|
||||
//config: If Y: you must install either the full-blown iproute2 package
|
||||
//config: or enable "ip" applet in Busybox, or the "ifup" and "ifdown" applets
|
||||
//config: will not work.
|
||||
//config:
|
||||
//config: If left disabled, you must install the full-blown iproute2
|
||||
//config: utility or the "ifup" and "ifdown" applets will not work.
|
||||
//config:
|
||||
//config:config FEATURE_IFUPDOWN_IFCONFIG_BUILTIN
|
||||
//config: bool "Use busybox ifconfig and route applets"
|
||||
//config: default n
|
||||
//config: depends on (IFUP || IFDOWN) && !FEATURE_IFUPDOWN_IP
|
||||
//config: select IFCONFIG
|
||||
//config: select ROUTE
|
||||
//config: help
|
||||
//config: Use the busybox iproute "ifconfig" and "route" applets to
|
||||
//config: implement the "ifup" and "ifdown" utilities.
|
||||
//config:
|
||||
//config: If left disabled, you must install the full-blown ifconfig
|
||||
//config: and route utilities, or the "ifup" and "ifdown" applets will not
|
||||
//config: work.
|
||||
//config: If N: you must install either the full-blown ifconfig and route
|
||||
//config: utilities, or enable these applets in Busybox.
|
||||
//config:
|
||||
//config:config FEATURE_IFUPDOWN_IPV4
|
||||
//config: bool "Support for IPv4"
|
||||
|
||||
+85
-77
@@ -17,24 +17,72 @@
|
||||
//config: utility. You generally don't need "ip" to use busybox with
|
||||
//config: TCP/IP.
|
||||
//config:
|
||||
//config:config IPADDR
|
||||
//config: bool "ipaddr"
|
||||
//config: default y
|
||||
//config: select FEATURE_IP_ADDRESS
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Support short form of ip addr: ipaddr
|
||||
//config:
|
||||
//config:config IPLINK
|
||||
//config: bool "iplink"
|
||||
//config: default y
|
||||
//config: select FEATURE_IP_LINK
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Support short form of ip link: iplink
|
||||
//config:
|
||||
//config:config IPROUTE
|
||||
//config: bool "iproute"
|
||||
//config: default y
|
||||
//config: select FEATURE_IP_ROUTE
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Support short form of ip route: iproute
|
||||
//config:
|
||||
//config:config IPTUNNEL
|
||||
//config: bool "iptunnel"
|
||||
//config: default y
|
||||
//config: select FEATURE_IP_TUNNEL
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Support short form of ip tunnel: iptunnel
|
||||
//config:
|
||||
//config:config IPRULE
|
||||
//config: bool "iprule"
|
||||
//config: default y
|
||||
//config: select FEATURE_IP_RULE
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Support short form of ip rule: iprule
|
||||
//config:
|
||||
//config:config IPNEIGH
|
||||
//config: bool "ipneigh"
|
||||
//config: default y
|
||||
//config: select FEATURE_IP_NEIGH
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Support short form of ip neigh: ipneigh
|
||||
//config:
|
||||
//config:config FEATURE_IP_ADDRESS
|
||||
//config: bool "ip address"
|
||||
//config: default y
|
||||
//config: depends on IP
|
||||
//config: depends on IP || IPADDR
|
||||
//config: help
|
||||
//config: Address manipulation support for the "ip" applet.
|
||||
//config:
|
||||
//config:config FEATURE_IP_LINK
|
||||
//config: bool "ip link"
|
||||
//config: default y
|
||||
//config: depends on IP
|
||||
//config: depends on IP || IPLINK
|
||||
//config: help
|
||||
//config: Configure network devices with "ip".
|
||||
//config:
|
||||
//config:config FEATURE_IP_ROUTE
|
||||
//config: bool "ip route"
|
||||
//config: default y
|
||||
//config: depends on IP
|
||||
//config: depends on IP || IPROUTE
|
||||
//config: help
|
||||
//config: Add support for routing table management to "ip".
|
||||
//config:
|
||||
@@ -48,83 +96,35 @@
|
||||
//config:config FEATURE_IP_TUNNEL
|
||||
//config: bool "ip tunnel"
|
||||
//config: default y
|
||||
//config: depends on IP
|
||||
//config: depends on IP || IPTUNNEL
|
||||
//config: help
|
||||
//config: Add support for tunneling commands to "ip".
|
||||
//config:
|
||||
//config:config FEATURE_IP_RULE
|
||||
//config: bool "ip rule"
|
||||
//config: default y
|
||||
//config: depends on IP
|
||||
//config: depends on IP || IPRULE
|
||||
//config: help
|
||||
//config: Add support for rule commands to "ip".
|
||||
//config:
|
||||
//config:config FEATURE_IP_NEIGH
|
||||
//config: bool "ip neighbor"
|
||||
//config: default y
|
||||
//config: depends on IP
|
||||
//config: depends on IP || IPNEIGH
|
||||
//config: help
|
||||
//config: Add support for neighbor commands to "ip".
|
||||
//config:
|
||||
//config:config FEATURE_IP_SHORT_FORMS
|
||||
//config: bool "Support short forms of ip commands"
|
||||
//config: default y
|
||||
//config: depends on IP
|
||||
//config: help
|
||||
//config: Also support short-form of ip <OBJECT> commands:
|
||||
//config: ip addr -> ipaddr
|
||||
//config: ip link -> iplink
|
||||
//config: ip route -> iproute
|
||||
//config: ip tunnel -> iptunnel
|
||||
//config: ip rule -> iprule
|
||||
//config: ip neigh -> ipneigh
|
||||
//config:
|
||||
//config: Say N unless you desparately need the short form of the ip
|
||||
//config: object commands.
|
||||
//config:
|
||||
//config:config FEATURE_IP_RARE_PROTOCOLS
|
||||
//config: bool "Support displaying rarely used link types"
|
||||
//config: default n
|
||||
//config: depends on IP
|
||||
//config: depends on IP || IPADDR || IPLINK || IPROUTE || IPTUNNEL || IPRULE || IPNEIGH
|
||||
//config: help
|
||||
//config: If you are not going to use links of type "frad", "econet",
|
||||
//config: "bif" etc, you probably don't need to enable this.
|
||||
//config: Ethernet, wireless, infrared, ppp/slip, ip tunnelling
|
||||
//config: link types are supported without this option selected.
|
||||
//config:
|
||||
//config:config IPADDR
|
||||
//config: bool
|
||||
//config: default y
|
||||
//config: depends on FEATURE_IP_SHORT_FORMS && FEATURE_IP_ADDRESS
|
||||
//config:
|
||||
//config:config IPLINK
|
||||
//config: bool
|
||||
//config: default y
|
||||
//config: depends on FEATURE_IP_SHORT_FORMS && FEATURE_IP_LINK
|
||||
//config:
|
||||
//config:config IPROUTE
|
||||
//config: bool
|
||||
//config: default y
|
||||
//config: depends on FEATURE_IP_SHORT_FORMS && FEATURE_IP_ROUTE
|
||||
//config:
|
||||
//config:config IPTUNNEL
|
||||
//config: bool
|
||||
//config: default y
|
||||
//config: depends on FEATURE_IP_SHORT_FORMS && FEATURE_IP_TUNNEL
|
||||
//config:
|
||||
//config:config IPRULE
|
||||
//config: bool
|
||||
//config: default y
|
||||
//config: depends on FEATURE_IP_SHORT_FORMS && FEATURE_IP_RULE
|
||||
//config:
|
||||
//config:config IPNEIGH
|
||||
//config: bool
|
||||
//config: default y
|
||||
//config: depends on FEATURE_IP_SHORT_FORMS && FEATURE_IP_NEIGH
|
||||
|
||||
//applet:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK || ENABLE_FEATURE_IP_TUNNEL || ENABLE_FEATURE_IP_RULE || ENABLE_FEATURE_IP_NEIGH
|
||||
//applet:IF_IP(APPLET(ip, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//applet:#endif
|
||||
//applet:IF_IPADDR(APPLET(ipaddr, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//applet:IF_IPLINK(APPLET(iplink, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
//applet:IF_IPROUTE(APPLET(iproute, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
@@ -133,6 +133,12 @@
|
||||
//applet:IF_IPNEIGH(APPLET(ipneigh, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_IP) += ip.o
|
||||
//kbuild:lib-$(CONFIG_IPADDR) += ip.o
|
||||
//kbuild:lib-$(CONFIG_IPLINK) += ip.o
|
||||
//kbuild:lib-$(CONFIG_IPROUTE) += ip.o
|
||||
//kbuild:lib-$(CONFIG_IPRULE) += ip.o
|
||||
//kbuild:lib-$(CONFIG_IPTUNNEL) += ip.o
|
||||
//kbuild:lib-$(CONFIG_IPNEIGH) += ip.o
|
||||
|
||||
/* would need to make the " | " optional depending on more than one selected: */
|
||||
//usage:#define ip_trivial_usage
|
||||
@@ -218,62 +224,57 @@
|
||||
#include "libiproute/utils.h"
|
||||
#include "libiproute/ip_common.h"
|
||||
|
||||
#if ENABLE_FEATURE_IP_ADDRESS \
|
||||
|| ENABLE_FEATURE_IP_ROUTE \
|
||||
|| ENABLE_FEATURE_IP_LINK \
|
||||
|| ENABLE_FEATURE_IP_TUNNEL \
|
||||
|| ENABLE_FEATURE_IP_RULE \
|
||||
|| ENABLE_FEATURE_IP_NEIGH
|
||||
|
||||
static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM)
|
||||
{
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
typedef int FAST_FUNC (*ip_func_ptr_t)(char**);
|
||||
|
||||
#if ENABLE_IPADDR \
|
||||
|| ENABLE_IPLINK \
|
||||
|| ENABLE_IPROUTE \
|
||||
|| ENABLE_IPRULE \
|
||||
|| ENABLE_IPTUNNEL \
|
||||
|| ENABLE_IPNEIGH
|
||||
static int ip_do(ip_func_ptr_t ip_func, char **argv)
|
||||
{
|
||||
argv = ip_parse_common_args(argv + 1);
|
||||
return ip_func(argv);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_IP_ADDRESS
|
||||
#if ENABLE_IPADDR
|
||||
int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int ipaddr_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
return ip_do(do_ipaddr, argv);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_IP_LINK
|
||||
#if ENABLE_IPLINK
|
||||
int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int iplink_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
return ip_do(do_iplink, argv);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_IP_ROUTE
|
||||
#if ENABLE_IPROUTE
|
||||
int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int iproute_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
return ip_do(do_iproute, argv);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_IP_RULE
|
||||
#if ENABLE_IPRULE
|
||||
int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int iprule_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
return ip_do(do_iprule, argv);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_IP_TUNNEL
|
||||
#if ENABLE_IPTUNNEL
|
||||
int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int iptunnel_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
return ip_do(do_iptunnel, argv);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_IP_NEIGH
|
||||
#if ENABLE_IPNEIGH
|
||||
int ipneigh_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int ipneigh_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -281,11 +282,16 @@ int ipneigh_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_IP
|
||||
static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM)
|
||||
{
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int ip_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
static const char keywords[] ALIGN1 =
|
||||
static const char keywords[] ALIGN1 = ""
|
||||
IF_FEATURE_IP_ADDRESS("address\0")
|
||||
IF_FEATURE_IP_ROUTE("route\0")
|
||||
IF_FEATURE_IP_ROUTE("r\0")
|
||||
@@ -310,10 +316,12 @@ int ip_main(int argc UNUSED_PARAM, char **argv)
|
||||
int key;
|
||||
|
||||
argv = ip_parse_common_args(argv + 1);
|
||||
key = *argv ? index_in_substrings(keywords, *argv++) : -1;
|
||||
if (ARRAY_SIZE(ip_func_ptrs) > 1 && *argv)
|
||||
key = index_in_substrings(keywords, *argv++);
|
||||
else
|
||||
key = -1;
|
||||
ip_func = ip_func_ptrs[key + 1];
|
||||
|
||||
return ip_func(argv);
|
||||
}
|
||||
|
||||
#endif /* any of ENABLE_FEATURE_IP_xxx is 1 */
|
||||
#endif
|
||||
@@ -62,13 +62,16 @@ lib-$(CONFIG_FEATURE_IP_TUNNEL) += \
|
||||
lib-$(CONFIG_FEATURE_IP_RULE) += \
|
||||
ip_parse_common_args.o \
|
||||
iprule.o \
|
||||
libnetlink.o \
|
||||
rt_names.o \
|
||||
rtm_map.o \
|
||||
utils.o
|
||||
|
||||
lib-$(CONFIG_FEATURE_IP_NEIGH) += \
|
||||
ip_parse_common_args.o \
|
||||
ipneigh.o \
|
||||
libnetlink.o \
|
||||
ll_addr.o \
|
||||
ll_map.o \
|
||||
rt_names.o \
|
||||
utils.o
|
||||
+3
-3
@@ -107,10 +107,10 @@
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
/* Wants <limits.h> etc, thus included after libbb.h: */
|
||||
#ifdef __linux__
|
||||
#include <linux/types.h> /* for __be32 etc */
|
||||
#include <linux/netfilter_ipv4.h>
|
||||
/* from linux/netfilter_ipv4.h: */
|
||||
# undef SO_ORIGINAL_DST
|
||||
# define SO_ORIGINAL_DST 80
|
||||
#endif
|
||||
|
||||
// TODO: move into this file:
|
||||
|
||||
@@ -16,7 +16,6 @@ config UDHCPD
|
||||
config DHCPRELAY
|
||||
bool "dhcprelay"
|
||||
default y
|
||||
depends on UDHCPD
|
||||
help
|
||||
dhcprelay listens for dhcp requests on one or more interfaces
|
||||
and forwards these requests to a different interface or dhcp
|
||||
@@ -25,7 +24,6 @@ config DHCPRELAY
|
||||
config DUMPLEASES
|
||||
bool "Lease display utility (dumpleases)"
|
||||
default y
|
||||
depends on UDHCPD
|
||||
help
|
||||
dumpleases displays the leases written out by the udhcpd server.
|
||||
Lease times are stored in the file by time remaining in lease, or
|
||||
|
||||
@@ -15,7 +15,7 @@ lib-$(CONFIG_UDHCPD) += common.o packet.o signalpipe.o socket.o
|
||||
lib-$(CONFIG_UDHCPC) += dhcpc.o
|
||||
lib-$(CONFIG_UDHCPD) += dhcpd.o arpping.o
|
||||
lib-$(CONFIG_DUMPLEASES) += dumpleases.o
|
||||
lib-$(CONFIG_DHCPRELAY) += dhcprelay.o
|
||||
lib-$(CONFIG_DHCPRELAY) += dhcprelay.o common.o socket.o packet.o
|
||||
|
||||
lib-$(CONFIG_FEATURE_UDHCPC_ARPING) += arpping.o
|
||||
lib-$(CONFIG_FEATURE_UDHCP_RFC3397) += domain_codec.o
|
||||
+18
-8
@@ -141,6 +141,8 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define SSL_SUPPORTED (ENABLE_FEATURE_WGET_OPENSSL || ENABLE_FEATURE_WGET_SSL_HELPER)
|
||||
|
||||
struct host_info {
|
||||
char *allocated;
|
||||
const char *path;
|
||||
@@ -151,7 +153,7 @@ struct host_info {
|
||||
};
|
||||
static const char P_FTP[] ALIGN1 = "ftp";
|
||||
static const char P_HTTP[] ALIGN1 = "http";
|
||||
#if ENABLE_FEATURE_WGET_OPENSSL || ENABLE_FEATURE_WGET_SSL_HELPER
|
||||
#if SSL_SUPPORTED
|
||||
static const char P_HTTPS[] ALIGN1 = "https";
|
||||
#endif
|
||||
|
||||
@@ -452,7 +454,7 @@ static void parse_url(const char *src_url, struct host_info *h)
|
||||
if (strcmp(url, P_FTP) == 0) {
|
||||
h->port = bb_lookup_port(P_FTP, "tcp", 21);
|
||||
} else
|
||||
#if ENABLE_FEATURE_WGET_OPENSSL || ENABLE_FEATURE_WGET_SSL_HELPER
|
||||
#if SSL_SUPPORTED
|
||||
if (strcmp(url, P_HTTPS) == 0) {
|
||||
h->port = bb_lookup_port(P_HTTPS, "tcp", 443);
|
||||
h->protocol = P_HTTPS;
|
||||
@@ -1093,12 +1095,20 @@ static void download_one_url(const char *url)
|
||||
}
|
||||
|
||||
fflush(sfp);
|
||||
/* If we use SSL helper, keeping our end of the socket open for writing
|
||||
* makes our end (i.e. the same fd!) readable (EAGAIN instead of EOF)
|
||||
* even after child closes its copy of the fd.
|
||||
* This helps:
|
||||
*/
|
||||
shutdown(fileno(sfp), SHUT_WR);
|
||||
|
||||
/* Tried doing this unconditionally.
|
||||
* Cloudflare and nginx/1.11.5 are shocked to see SHUT_WR on non-HTTPS.
|
||||
*/
|
||||
#if SSL_SUPPORTED
|
||||
if (target.protocol == P_HTTPS) {
|
||||
/* If we use SSL helper, keeping our end of the socket open for writing
|
||||
* makes our end (i.e. the same fd!) readable (EAGAIN instead of EOF)
|
||||
* even after child closes its copy of the fd.
|
||||
* This helps:
|
||||
*/
|
||||
shutdown(fileno(sfp), SHUT_WR);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Retrieve HTTP response line and check for "200" status code.
|
||||
|
||||
@@ -9,3 +9,5 @@ lib-y:=
|
||||
INSERT
|
||||
|
||||
lib-$(CONFIG_ASH) += kill.o # used for built-in kill by ash
|
||||
lib-$(CONFIG_SH_IS_ASH) += kill.o # used for built-in kill by ash
|
||||
lib-$(CONFIG_BASH_IS_ASH) += kill.o # used for built-in kill by ash
|
||||
+3
-1
@@ -68,7 +68,9 @@
|
||||
//usage: )
|
||||
|
||||
#include <selinux/context.h>
|
||||
#include <selinux/flask.h>
|
||||
/* from deprecated <selinux/flask.h>: */
|
||||
#undef SECCLASS_PROCESS
|
||||
#define SECCLASS_PROCESS 2
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
|
||||
+21
-24
@@ -5,34 +5,30 @@
|
||||
|
||||
menu "Shells"
|
||||
|
||||
INSERT
|
||||
|
||||
|
||||
choice
|
||||
prompt "Choose which shell is aliased to 'sh' name"
|
||||
default FEATURE_SH_IS_ASH
|
||||
default SH_IS_ASH
|
||||
help
|
||||
Choose which shell you want to be executed by 'sh' alias.
|
||||
The ash shell is the most bash compatible and full featured one.
|
||||
|
||||
# note: cannot use "select ASH" here, it breaks "make allnoconfig"
|
||||
config FEATURE_SH_IS_ASH
|
||||
depends on ASH
|
||||
bool "ash"
|
||||
config SH_IS_ASH
|
||||
depends on !NOMMU
|
||||
bool "ash"
|
||||
|
||||
config FEATURE_SH_IS_HUSH
|
||||
depends on HUSH
|
||||
config SH_IS_HUSH
|
||||
bool "hush"
|
||||
|
||||
config FEATURE_SH_IS_NONE
|
||||
config SH_IS_NONE
|
||||
bool "none"
|
||||
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "Choose which shell is aliased to 'bash' name"
|
||||
default FEATURE_BASH_IS_NONE
|
||||
default BASH_IS_NONE
|
||||
help
|
||||
Choose which shell you want to be executed by 'bash' alias.
|
||||
The ash shell is the most bash compatible and full featured one.
|
||||
@@ -47,32 +43,33 @@ choice
|
||||
can't be used for running them because it won't recongnize
|
||||
"bash" as a supported applet name.
|
||||
|
||||
config FEATURE_BASH_IS_ASH
|
||||
depends on ASH
|
||||
bool "ash"
|
||||
config BASH_IS_ASH
|
||||
depends on !NOMMU
|
||||
bool "ash"
|
||||
|
||||
config FEATURE_BASH_IS_HUSH
|
||||
depends on HUSH
|
||||
config BASH_IS_HUSH
|
||||
bool "hush"
|
||||
|
||||
config FEATURE_BASH_IS_NONE
|
||||
config BASH_IS_NONE
|
||||
bool "none"
|
||||
|
||||
endchoice
|
||||
|
||||
|
||||
config SH_MATH_SUPPORT
|
||||
INSERT
|
||||
|
||||
|
||||
config FEATURE_SH_MATH
|
||||
bool "POSIX math support"
|
||||
default y
|
||||
depends on ASH || HUSH
|
||||
depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
help
|
||||
Enable math support in the shell via $((...)) syntax.
|
||||
|
||||
config SH_MATH_SUPPORT_64
|
||||
config FEATURE_SH_MATH_64
|
||||
bool "Extend POSIX math support to 64 bit"
|
||||
default y
|
||||
depends on SH_MATH_SUPPORT
|
||||
depends on FEATURE_SH_MATH
|
||||
help
|
||||
Enable 64-bit math support in the shell. This will make the shell
|
||||
slightly larger, but will allow computation with very large numbers.
|
||||
@@ -81,14 +78,14 @@ config SH_MATH_SUPPORT_64
|
||||
config FEATURE_SH_EXTRA_QUIET
|
||||
bool "Hide message on interactive shell startup"
|
||||
default y
|
||||
depends on HUSH || ASH
|
||||
depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
help
|
||||
Remove the busybox introduction when starting a shell.
|
||||
|
||||
config FEATURE_SH_STANDALONE
|
||||
bool "Standalone shell"
|
||||
default n
|
||||
depends on (HUSH || ASH)
|
||||
depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
help
|
||||
This option causes busybox shells to use busybox applets
|
||||
in preference to executables in the PATH whenever possible. For
|
||||
@@ -121,7 +118,7 @@ config FEATURE_SH_STANDALONE
|
||||
config FEATURE_SH_NOFORK
|
||||
bool "Run 'nofork' applets directly"
|
||||
default n
|
||||
depends on (HUSH || ASH)
|
||||
depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
help
|
||||
This option causes busybox shells to not execute typical
|
||||
fork/exec/wait sequence, but call <applet>_main directly,
|
||||
@@ -139,7 +136,7 @@ config FEATURE_SH_NOFORK
|
||||
config FEATURE_SH_HISTFILESIZE
|
||||
bool "Use $HISTFILESIZE"
|
||||
default y
|
||||
depends on HUSH || ASH
|
||||
depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
help
|
||||
This option makes busybox shells to use $HISTFILESIZE variable
|
||||
to set shell history size. Note that its max value is capped
|
||||
|
||||
+1
-1
@@ -8,4 +8,4 @@ lib-y:=
|
||||
|
||||
INSERT
|
||||
|
||||
lib-$(CONFIG_SH_MATH_SUPPORT) += math.o
|
||||
lib-$(CONFIG_FEATURE_SH_MATH) += math.o
|
||||
+185
-172
@@ -15,6 +15,140 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config ASH
|
||||
//config: bool "ash"
|
||||
//config: default y
|
||||
//config: depends on !NOMMU
|
||||
//config: help
|
||||
//config: Tha 'ash' shell adds about 60k in the default configuration and is
|
||||
//config: the most complete and most pedantically correct shell included with
|
||||
//config: busybox. This shell is actually a derivative of the Debian 'dash'
|
||||
//config: shell (by Herbert Xu), which was created by porting the 'ash' shell
|
||||
//config: (written by Kenneth Almquist) from NetBSD.
|
||||
//config:
|
||||
//config:config ASH_OPTIMIZE_FOR_SIZE
|
||||
//config: bool "Optimize for size instead of speed"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Compile ash for reduced size at the price of speed.
|
||||
//config:
|
||||
//config:config ASH_INTERNAL_GLOB
|
||||
//config: bool "Use internal glob() implementation"
|
||||
//config: default y # Y is bigger, but because of uclibc glob() bug, let Y be default for now
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Do not use glob() function from libc, use internal implementation.
|
||||
//config: Use this if you are getting "glob.h: No such file or directory"
|
||||
//config: or similar build errors.
|
||||
//config:
|
||||
//config:config ASH_RANDOM_SUPPORT
|
||||
//config: bool "Pseudorandom generator and $RANDOM variable"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enable pseudorandom generator and dynamic variable "$RANDOM".
|
||||
//config: Each read of "$RANDOM" will generate a new pseudorandom value.
|
||||
//config: You can reset the generator by using a specified start value.
|
||||
//config: After "unset RANDOM" the generator will switch off and this
|
||||
//config: variable will no longer have special treatment.
|
||||
//config:
|
||||
//config:config ASH_EXPAND_PRMT
|
||||
//config: bool "Expand prompt string"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: "PS#" may contain volatile content, such as backquote commands.
|
||||
//config: This option recreates the prompt string from the environment
|
||||
//config: variable each time it is displayed.
|
||||
//config:
|
||||
//config:config ASH_BASH_COMPAT
|
||||
//config: bool "bash-compatible extensions"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enable bash-compatible extensions.
|
||||
//config:
|
||||
//config:config ASH_IDLE_TIMEOUT
|
||||
//config: bool "Idle timeout variable"
|
||||
//config: default n
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enables bash-like auto-logout after $TMOUT seconds of idle time.
|
||||
//config:
|
||||
//config:config ASH_JOB_CONTROL
|
||||
//config: bool "Job control"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enable job control in the ash shell.
|
||||
//config:
|
||||
//config:config ASH_ALIAS
|
||||
//config: bool "Alias support"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enable alias support in the ash shell.
|
||||
//config:
|
||||
//config:config ASH_GETOPTS
|
||||
//config: bool "Builtin getopt to parse positional parameters"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enable support for getopts builtin in ash.
|
||||
//config:
|
||||
//config:config ASH_BUILTIN_ECHO
|
||||
//config: bool "Builtin version of 'echo'"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enable support for echo builtin in ash.
|
||||
//config:
|
||||
//config:config ASH_BUILTIN_PRINTF
|
||||
//config: bool "Builtin version of 'printf'"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enable support for printf builtin in ash.
|
||||
//config:
|
||||
//config:config ASH_BUILTIN_TEST
|
||||
//config: bool "Builtin version of 'test'"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enable support for test builtin in ash.
|
||||
//config:
|
||||
//config:config ASH_HELP
|
||||
//config: bool "help builtin"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enable help builtin in ash.
|
||||
//config:
|
||||
//config:config ASH_CMDCMD
|
||||
//config: bool "'command' command to override shell builtins"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enable support for the ash 'command' builtin, which allows
|
||||
//config: you to run the specified command with the specified arguments,
|
||||
//config: even when there is an ash builtin command with the same name.
|
||||
//config:
|
||||
//config:config ASH_MAIL
|
||||
//config: bool "Check for new mail on interactive shells"
|
||||
//config: default y
|
||||
//config: depends on ASH || SH_IS_ASH || BASH_IS_ASH
|
||||
//config: help
|
||||
//config: Enable "check for new mail" function in the ash shell.
|
||||
|
||||
//applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, ash))
|
||||
//applet:IF_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, BB_DIR_BIN, BB_SUID_DROP, ash))
|
||||
|
||||
//kbuild:lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_SH_IS_ASH) += ash.o ash_ptr_hack.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_BASH_IS_ASH) += ash.o ash_ptr_hack.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o
|
||||
|
||||
/*
|
||||
* The following should be set to reflect the type of system you have:
|
||||
@@ -51,13 +185,24 @@
|
||||
# define ENABLE_ASH_INTERNAL_GLOB 1
|
||||
#endif
|
||||
|
||||
#if !ENABLE_ASH_INTERNAL_GLOB && defined(__UCLIBC__)
|
||||
# error uClibc glob() is buggy, use ASH_INTERNAL_GLOB.
|
||||
# error The bug is: for "$PWD"/<pattern> ash will escape e.g. dashes in "$PWD"
|
||||
# error with backslash, even ones which do not need to be: "/a-b" -> "/a\-b"
|
||||
# error glob() should unbackslash them and match. uClibc does not unbackslash,
|
||||
# error fails to match dirname, subsequently not expanding <pattern> in it.
|
||||
// Testcase:
|
||||
// if (glob("/etc/polkit\\-1", 0, NULL, &pglob)) - this returns 0 on uclibc, no bug
|
||||
// if (glob("/etc/polkit\\-1/*", 0, NULL, &pglob)) printf("uclibc bug!\n");
|
||||
#endif
|
||||
|
||||
#if !ENABLE_ASH_INTERNAL_GLOB
|
||||
# include <glob.h>
|
||||
#endif
|
||||
|
||||
#include "unicode.h"
|
||||
#include "shell_common.h"
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
# include "math.h"
|
||||
#endif
|
||||
#if ENABLE_ASH_RANDOM_SUPPORT
|
||||
@@ -86,140 +231,6 @@
|
||||
# error "Do not even bother, ash will not run on NOMMU machine"
|
||||
#endif
|
||||
|
||||
//config:config ASH
|
||||
//config: bool "ash"
|
||||
//config: default y
|
||||
//config: depends on !NOMMU
|
||||
//config: help
|
||||
//config: Tha 'ash' shell adds about 60k in the default configuration and is
|
||||
//config: the most complete and most pedantically correct shell included with
|
||||
//config: busybox. This shell is actually a derivative of the Debian 'dash'
|
||||
//config: shell (by Herbert Xu), which was created by porting the 'ash' shell
|
||||
//config: (written by Kenneth Almquist) from NetBSD.
|
||||
//config:
|
||||
//config:config ASH_OPTIMIZE_FOR_SIZE
|
||||
//config: bool "Optimize for size instead of speed"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Compile ash for reduced size at the price of speed.
|
||||
//config:
|
||||
//config:config ASH_INTERNAL_GLOB
|
||||
//config: bool "Use internal glob() implementation"
|
||||
//config: default n
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Do not use glob() function from libc, use internal implementation.
|
||||
//config: Use this if you are getting "glob.h: No such file or directory"
|
||||
//config: or similar build errors.
|
||||
//config:
|
||||
//config:config ASH_RANDOM_SUPPORT
|
||||
//config: bool "Pseudorandom generator and $RANDOM variable"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enable pseudorandom generator and dynamic variable "$RANDOM".
|
||||
//config: Each read of "$RANDOM" will generate a new pseudorandom value.
|
||||
//config: You can reset the generator by using a specified start value.
|
||||
//config: After "unset RANDOM" the generator will switch off and this
|
||||
//config: variable will no longer have special treatment.
|
||||
//config:
|
||||
//config:config ASH_EXPAND_PRMT
|
||||
//config: bool "Expand prompt string"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: "PS#" may contain volatile content, such as backquote commands.
|
||||
//config: This option recreates the prompt string from the environment
|
||||
//config: variable each time it is displayed.
|
||||
//config:
|
||||
//config:config ASH_BASH_COMPAT
|
||||
//config: bool "bash-compatible extensions"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enable bash-compatible extensions.
|
||||
//config:
|
||||
//config:config ASH_IDLE_TIMEOUT
|
||||
//config: bool "Idle timeout variable"
|
||||
//config: default n
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enables bash-like auto-logout after $TMOUT seconds of idle time.
|
||||
//config:
|
||||
//config:config ASH_JOB_CONTROL
|
||||
//config: bool "Job control"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enable job control in the ash shell.
|
||||
//config:
|
||||
//config:config ASH_ALIAS
|
||||
//config: bool "Alias support"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enable alias support in the ash shell.
|
||||
//config:
|
||||
//config:config ASH_GETOPTS
|
||||
//config: bool "Builtin getopt to parse positional parameters"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enable support for getopts builtin in ash.
|
||||
//config:
|
||||
//config:config ASH_BUILTIN_ECHO
|
||||
//config: bool "Builtin version of 'echo'"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enable support for echo builtin in ash.
|
||||
//config:
|
||||
//config:config ASH_BUILTIN_PRINTF
|
||||
//config: bool "Builtin version of 'printf'"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enable support for printf builtin in ash.
|
||||
//config:
|
||||
//config:config ASH_BUILTIN_TEST
|
||||
//config: bool "Builtin version of 'test'"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enable support for test builtin in ash.
|
||||
//config:
|
||||
//config:config ASH_HELP
|
||||
//config: bool "help builtin"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enable help builtin in ash.
|
||||
//config:
|
||||
//config:config ASH_CMDCMD
|
||||
//config: bool "'command' command to override shell builtins"
|
||||
//config: default y
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enable support for the ash 'command' builtin, which allows
|
||||
//config: you to run the specified command with the specified arguments,
|
||||
//config: even when there is an ash builtin command with the same name.
|
||||
//config:
|
||||
//config:config ASH_MAIL
|
||||
//config: bool "Check for new mail on interactive shells"
|
||||
//config: default n
|
||||
//config: depends on ASH
|
||||
//config: help
|
||||
//config: Enable "check for new mail" function in the ash shell.
|
||||
//config:
|
||||
|
||||
//applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, sh))
|
||||
//applet:IF_FEATURE_BASH_IS_ASH(APPLET_ODDNAME(bash, ash, BB_DIR_BIN, BB_SUID_DROP, bash))
|
||||
|
||||
//kbuild:lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_ASH_RANDOM_SUPPORT) += random.o
|
||||
|
||||
|
||||
/* ============ Hash table sizes. Configurable. */
|
||||
|
||||
@@ -1273,6 +1284,8 @@ ash_msg_and_raise_error(const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
exitstatus = 2;
|
||||
|
||||
va_start(ap, msg);
|
||||
ash_vmsg_and_raise(EXERROR, msg, ap);
|
||||
/* NOTREACHED */
|
||||
@@ -2135,6 +2148,7 @@ lookupvar(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if ENABLE_UNICODE_SUPPORT
|
||||
static void
|
||||
reinit_unicode_for_ash(void)
|
||||
{
|
||||
@@ -2151,6 +2165,9 @@ reinit_unicode_for_ash(void)
|
||||
reinit_unicode(s);
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define reinit_unicode_for_ash() ((void)0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Search the environment of a builtin command.
|
||||
@@ -2732,7 +2749,7 @@ pwdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
|
||||
#define USE_SIT_FUNCTION ENABLE_ASH_OPTIMIZE_FOR_SIZE
|
||||
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
# define SIT_ITEM(a,b,c,d) (a | (b << 4) | (c << 8) | (d << 12))
|
||||
#else
|
||||
# define SIT_ITEM(a,b,c,d) (a | (b << 4) | (c << 8))
|
||||
@@ -3120,7 +3137,7 @@ static const uint8_t syntax_index_table[] ALIGN1 = {
|
||||
({ \
|
||||
if ((c) < 0 || (c) > (PEOF + ENABLE_ASH_ALIAS)) \
|
||||
bb_error_msg_and_die("line:%d c:%d", __LINE__, (c)); \
|
||||
if ((syntax) < 0 || (syntax) > (2 + ENABLE_SH_MATH_SUPPORT)) \
|
||||
if ((syntax) < 0 || (syntax) > (2 + ENABLE_FEATURE_SH_MATH)) \
|
||||
bb_error_msg_and_die("line:%d c:%d", __LINE__, (c)); \
|
||||
((S_I_T[syntax_index_table[c]] >> ((syntax)*4)) & 0xf); \
|
||||
})
|
||||
@@ -4478,7 +4495,7 @@ cmdputs(const char *s)
|
||||
case CTLBACKQ:
|
||||
str = "$(...)";
|
||||
goto dostr;
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
case CTLARI:
|
||||
str = "$((";
|
||||
goto dostr;
|
||||
@@ -5409,11 +5426,11 @@ redirect(union node *redir, int flags)
|
||||
/* Careful to not accidentally "save"
|
||||
* to the same fd as right side fd in N>&M */
|
||||
int minfd = right_fd < 10 ? 10 : right_fd + 1;
|
||||
#if defined(F_DUPFD_CLOEXEC)
|
||||
i = fcntl(fd, F_DUPFD_CLOEXEC, minfd);
|
||||
#else
|
||||
i = fcntl(fd, F_DUPFD, minfd);
|
||||
/* You'd expect copy to be CLOEXECed. Currently these extra "saved" fds
|
||||
* are closed in popredir() in the child, preventing them from leaking
|
||||
* into child. (popredir() also cleans up the mess in case of failures)
|
||||
*/
|
||||
#endif
|
||||
if (i == -1) {
|
||||
i = errno;
|
||||
if (i != EBADF) {
|
||||
@@ -5428,6 +5445,9 @@ redirect(union node *redir, int flags)
|
||||
remember_to_close:
|
||||
i = CLOSED;
|
||||
} else { /* fd is open, save its copy */
|
||||
#if !defined(F_DUPFD_CLOEXEC)
|
||||
fcntl(i, F_SETFD, FD_CLOEXEC);
|
||||
#endif
|
||||
/* "exec fd>&-" should not close fds
|
||||
* which point to script file(s).
|
||||
* Force them to be restored afterwards */
|
||||
@@ -5538,7 +5558,7 @@ redirectsafe(union node *redir, int flags)
|
||||
* We have to deal with backquotes, shell variables, and file metacharacters.
|
||||
*/
|
||||
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
static arith_t
|
||||
ash_arith(const char *s)
|
||||
{
|
||||
@@ -5626,7 +5646,7 @@ static struct arglist exparg;
|
||||
/*
|
||||
* Our own itoa().
|
||||
*/
|
||||
#if !ENABLE_SH_MATH_SUPPORT
|
||||
#if !ENABLE_FEATURE_SH_MATH
|
||||
/* cvtnum() is used even if math support is off (to prepare $? values and such) */
|
||||
typedef long arith_t;
|
||||
# define ARITH_FMT "%ld"
|
||||
@@ -6139,7 +6159,7 @@ expbackq(union node *cmd, int flag)
|
||||
stackblock() + startloc));
|
||||
}
|
||||
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
/*
|
||||
* Expand arithmetic expression. Backup to start of expression,
|
||||
* evaluate, place result in (backed up) result, adjust string position.
|
||||
@@ -6221,7 +6241,7 @@ argstr(char *p, int flags, struct strlist *var_str_list)
|
||||
CTLESC,
|
||||
CTLVAR,
|
||||
CTLBACKQ,
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
CTLENDARI,
|
||||
#endif
|
||||
'\0'
|
||||
@@ -6257,7 +6277,7 @@ argstr(char *p, int flags, struct strlist *var_str_list)
|
||||
c = p[length];
|
||||
if (c) {
|
||||
if (!(c & 0x80)
|
||||
IF_SH_MATH_SUPPORT(|| c == CTLENDARI)
|
||||
IF_FEATURE_SH_MATH(|| c == CTLENDARI)
|
||||
) {
|
||||
/* c == '=' || c == ':' || c == CTLENDARI */
|
||||
length++;
|
||||
@@ -6337,7 +6357,7 @@ argstr(char *p, int flags, struct strlist *var_str_list)
|
||||
expbackq(argbackq->n, flags | inquotes);
|
||||
argbackq = argbackq->next;
|
||||
goto start;
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
case CTLENDARI:
|
||||
p--;
|
||||
expari(flags | inquotes);
|
||||
@@ -9256,7 +9276,7 @@ static int helpcmd(int, char **) FAST_FUNC;
|
||||
#if MAX_HISTORY
|
||||
static int historycmd(int, char **) FAST_FUNC;
|
||||
#endif
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
static int letcmd(int, char **) FAST_FUNC;
|
||||
#endif
|
||||
static int readcmd(int, char **) FAST_FUNC;
|
||||
@@ -9336,7 +9356,7 @@ static const struct builtincmd builtintab[] = {
|
||||
{ BUILTIN_REGULAR "jobs" , jobscmd },
|
||||
{ BUILTIN_REGULAR "kill" , killcmd },
|
||||
#endif
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
{ BUILTIN_NOSPEC "let" , letcmd },
|
||||
#endif
|
||||
{ BUILTIN_ASSIGN "local" , localcmd },
|
||||
@@ -9573,11 +9593,13 @@ evalcommand(union node *cmd, int flags)
|
||||
}
|
||||
|
||||
if (status) {
|
||||
bail:
|
||||
exitstatus = status;
|
||||
|
||||
/* We have a redirection error. */
|
||||
if (spclbltin > 0)
|
||||
raise_exception(EXERROR);
|
||||
bail:
|
||||
exitstatus = status;
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -11385,13 +11407,13 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
|
||||
smallint quotef;
|
||||
smallint dblquote;
|
||||
smallint oldstyle;
|
||||
IF_SH_MATH_SUPPORT(smallint prevsyntax;) /* syntax before arithmetic */
|
||||
IF_FEATURE_SH_MATH(smallint prevsyntax;) /* syntax before arithmetic */
|
||||
#if ENABLE_ASH_EXPAND_PRMT
|
||||
smallint pssyntax; /* we are expanding a prompt string */
|
||||
#endif
|
||||
int varnest; /* levels of variables expansion */
|
||||
IF_SH_MATH_SUPPORT(int arinest;) /* levels of arithmetic expansion */
|
||||
IF_SH_MATH_SUPPORT(int parenlevel;) /* levels of parens in arithmetic */
|
||||
IF_FEATURE_SH_MATH(int arinest;) /* levels of arithmetic expansion */
|
||||
IF_FEATURE_SH_MATH(int parenlevel;) /* levels of parens in arithmetic */
|
||||
int dqvarnest; /* levels of variables expansion within double quotes */
|
||||
|
||||
IF_ASH_BASH_COMPAT(smallint bash_dollar_squote = 0;)
|
||||
@@ -11399,7 +11421,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
|
||||
startlinno = g_parsefile->linno;
|
||||
bqlist = NULL;
|
||||
quotef = 0;
|
||||
IF_SH_MATH_SUPPORT(prevsyntax = 0;)
|
||||
IF_FEATURE_SH_MATH(prevsyntax = 0;)
|
||||
#if ENABLE_ASH_EXPAND_PRMT
|
||||
pssyntax = (syntax == PSSYNTAX);
|
||||
if (pssyntax)
|
||||
@@ -11407,8 +11429,8 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
|
||||
#endif
|
||||
dblquote = (syntax == DQSYNTAX);
|
||||
varnest = 0;
|
||||
IF_SH_MATH_SUPPORT(arinest = 0;)
|
||||
IF_SH_MATH_SUPPORT(parenlevel = 0;)
|
||||
IF_FEATURE_SH_MATH(arinest = 0;)
|
||||
IF_FEATURE_SH_MATH(parenlevel = 0;)
|
||||
dqvarnest = 0;
|
||||
|
||||
STARTSTACKSTR(out);
|
||||
@@ -11515,7 +11537,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
|
||||
}
|
||||
USTPUTC(c, out);
|
||||
break;
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
case CLP: /* '(' in arithmetic */
|
||||
parenlevel++;
|
||||
USTPUTC(c, out);
|
||||
@@ -11566,7 +11588,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
|
||||
} /* for (;;) */
|
||||
endword:
|
||||
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
if (syntax == ARISYNTAX)
|
||||
raise_error_syntax("missing '))'");
|
||||
#endif
|
||||
@@ -11745,7 +11767,7 @@ parsesub: {
|
||||
} else if (c == '(') {
|
||||
/* $(command) or $((arith)) */
|
||||
if (pgetc_eatbnl() == '(') {
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
PARSEARITH();
|
||||
#else
|
||||
raise_error_syntax("you disabled math support for $((arith)) syntax");
|
||||
@@ -12000,7 +12022,7 @@ parsebackq: {
|
||||
goto parsebackq_newreturn;
|
||||
}
|
||||
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
/*
|
||||
* Parse an arithmetic expansion (indicate start of one and set state)
|
||||
*/
|
||||
@@ -13037,7 +13059,7 @@ timescmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
/*
|
||||
* The let builtin. Partially stolen from GNU Bash, the Bourne Again SHell.
|
||||
* Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
|
||||
@@ -13292,15 +13314,6 @@ init(void)
|
||||
//usage:#define ash_full_usage "\n\n"
|
||||
//usage: "Unix shell interpreter"
|
||||
|
||||
//usage:#if ENABLE_FEATURE_SH_IS_ASH
|
||||
//usage:# define sh_trivial_usage ash_trivial_usage
|
||||
//usage:# define sh_full_usage ash_full_usage
|
||||
//usage:#endif
|
||||
//usage:#if ENABLE_FEATURE_BASH_IS_ASH
|
||||
//usage:# define bash_trivial_usage ash_trivial_usage
|
||||
//usage:# define bash_full_usage ash_full_usage
|
||||
//usage:#endif
|
||||
|
||||
/*
|
||||
* Process the shell command line arguments.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
./test.sh: line 1: syntax error: unexpected ")"
|
||||
Done:2
|
||||
./exitcode2.tests: line 11: can't open does_not_exist: no such file
|
||||
Done:1
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
# syntax error should return status 2
|
||||
cat >test.sh <<EOF
|
||||
)
|
||||
EOF
|
||||
chmod +x test.sh
|
||||
$THIS_SH ./test.sh
|
||||
echo Done:$?
|
||||
rm -f test.sh
|
||||
|
||||
# redirection error with special builtin should return status 1
|
||||
(eval cat <does_not_exist)
|
||||
echo Done:$?
|
||||
@@ -0,0 +1,6 @@
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
# Each of these should show only four lines:
|
||||
# fds 0,1,2 are stdio; fd 3 is open by opendir() in ls.
|
||||
# This test detects bugs where redirects leave stray open fds.
|
||||
|
||||
ls -1 /proc/self/fd | wc -l
|
||||
ls -1 /proc/self/fd >/proc/self/fd/1 | wc -l
|
||||
ls -1 /proc/self/fd >/proc/self/fd/1 2>&1 | wc -l
|
||||
echo "`ls -1 /proc/self/fd `" | wc -l
|
||||
echo "`ls -1 /proc/self/fd >/proc/self/fd/1 `" | wc -l
|
||||
echo "`ls -1 /proc/self/fd >/proc/self/fd/1 2>&1 `" | wc -l
|
||||
+170
-176
@@ -82,6 +82,161 @@
|
||||
* $ "export" i=`echo 'aaa bbb'`; echo "$i"
|
||||
* aaa
|
||||
*/
|
||||
//config:config HUSH
|
||||
//config: bool "hush"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: hush is a small shell (25k). It handles the normal flow control
|
||||
//config: constructs such as if/then/elif/else/fi, for/in/do/done, while loops,
|
||||
//config: case/esac. Redirections, here documents, $((arithmetic))
|
||||
//config: and functions are supported.
|
||||
//config:
|
||||
//config: It will compile and work on no-mmu systems.
|
||||
//config:
|
||||
//config: It does not handle select, aliases, tilde expansion,
|
||||
//config: &>file and >&file redirection of stdout+stderr.
|
||||
//config:
|
||||
//config:config HUSH_BASH_COMPAT
|
||||
//config: bool "bash-compatible extensions"
|
||||
//config: default y
|
||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
//config: help
|
||||
//config: Enable bash-compatible extensions.
|
||||
//config:
|
||||
//config:config HUSH_BRACE_EXPANSION
|
||||
//config: bool "Brace expansion"
|
||||
//config: default y
|
||||
//config: depends on HUSH_BASH_COMPAT
|
||||
//config: help
|
||||
//config: Enable {abc,def} extension.
|
||||
//config:
|
||||
//config:config HUSH_HELP
|
||||
//config: bool "help builtin"
|
||||
//config: default y
|
||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
//config: help
|
||||
//config: Enable help builtin in hush. Code size + ~1 kbyte.
|
||||
//config:
|
||||
//config:config HUSH_INTERACTIVE
|
||||
//config: bool "Interactive mode"
|
||||
//config: default y
|
||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
//config: help
|
||||
//config: Enable interactive mode (prompt and command editing).
|
||||
//config: Without this, hush simply reads and executes commands
|
||||
//config: from stdin just like a shell script from a file.
|
||||
//config: No prompt, no PS1/PS2 magic shell variables.
|
||||
//config:
|
||||
//config:config HUSH_SAVEHISTORY
|
||||
//config: bool "Save command history to .hush_history"
|
||||
//config: default y
|
||||
//config: depends on HUSH_INTERACTIVE && FEATURE_EDITING_SAVEHISTORY
|
||||
//config: help
|
||||
//config: Enable history saving in hush.
|
||||
//config:
|
||||
//config:config HUSH_JOB
|
||||
//config: bool "Job control"
|
||||
//config: default y
|
||||
//config: depends on HUSH_INTERACTIVE
|
||||
//config: help
|
||||
//config: Enable job control: Ctrl-Z backgrounds, Ctrl-C interrupts current
|
||||
//config: command (not entire shell), fg/bg builtins work. Without this option,
|
||||
//config: "cmd &" still works by simply spawning a process and immediately
|
||||
//config: prompting for next command (or executing next command in a script),
|
||||
//config: but no separate process group is formed.
|
||||
//config:
|
||||
//config:config HUSH_TICK
|
||||
//config: bool "Process substitution"
|
||||
//config: default y
|
||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
//config: help
|
||||
//config: Enable process substitution `command` and $(command) in hush.
|
||||
//config:
|
||||
//config:config HUSH_IF
|
||||
//config: bool "Support if/then/elif/else/fi"
|
||||
//config: default y
|
||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
//config: help
|
||||
//config: Enable if/then/elif/else/fi in hush.
|
||||
//config:
|
||||
//config:config HUSH_LOOPS
|
||||
//config: bool "Support for, while and until loops"
|
||||
//config: default y
|
||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
//config: help
|
||||
//config: Enable for, while and until loops in hush.
|
||||
//config:
|
||||
//config:config HUSH_CASE
|
||||
//config: bool "Support case ... esac statement"
|
||||
//config: default y
|
||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
//config: help
|
||||
//config: Enable case ... esac statement in hush. +400 bytes.
|
||||
//config:
|
||||
//config:config HUSH_FUNCTIONS
|
||||
//config: bool "Support funcname() { commands; } syntax"
|
||||
//config: default y
|
||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
//config: help
|
||||
//config: Enable support for shell functions in hush. +800 bytes.
|
||||
//config:
|
||||
//config:config HUSH_LOCAL
|
||||
//config: bool "Support local builtin"
|
||||
//config: default y
|
||||
//config: depends on HUSH_FUNCTIONS
|
||||
//config: help
|
||||
//config: Enable support for local variables in functions.
|
||||
//config:
|
||||
//config:config HUSH_RANDOM_SUPPORT
|
||||
//config: bool "Pseudorandom generator and $RANDOM variable"
|
||||
//config: default y
|
||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
//config: help
|
||||
//config: Enable pseudorandom generator and dynamic variable "$RANDOM".
|
||||
//config: Each read of "$RANDOM" will generate a new pseudorandom value.
|
||||
//config:
|
||||
//config:config HUSH_EXPORT_N
|
||||
//config: bool "Support 'export -n' option"
|
||||
//config: default y
|
||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
//config: help
|
||||
//config: export -n unexports variables. It is a bash extension.
|
||||
//config:
|
||||
//config:config HUSH_MODE_X
|
||||
//config: bool "Support 'hush -x' option and 'set -x' command"
|
||||
//config: default y
|
||||
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
|
||||
//config: help
|
||||
//config: This instructs hush to print commands before execution.
|
||||
//config: Adds ~300 bytes.
|
||||
//config:
|
||||
//config:config MSH
|
||||
//config: bool "msh (deprecated: aliased to hush)"
|
||||
//config: default n
|
||||
//config: select HUSH
|
||||
//config: help
|
||||
//config: msh is deprecated and will be removed, please migrate to hush.
|
||||
|
||||
//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_MSH(APPLET_ODDNAME(msh, hush, BB_DIR_BIN, BB_SUID_DROP, hush))
|
||||
//applet:IF_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, hush))
|
||||
//applet:IF_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, hush))
|
||||
|
||||
//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_SH_IS_HUSH) += hush.o match.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_BASH_IS_HUSH) += hush.o match.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o
|
||||
|
||||
/* -i (interactive) and -s (read stdin) are also accepted,
|
||||
* but currently do nothing, therefore aren't shown in help.
|
||||
* NOMMU-specific options are not meant to be used by users,
|
||||
* therefore we don't show them either.
|
||||
*/
|
||||
//usage:#define hush_trivial_usage
|
||||
//usage: "[-nxl] [-c 'SCRIPT' [ARG0 [ARGS]] / FILE [ARGS]]"
|
||||
//usage:#define hush_full_usage "\n\n"
|
||||
//usage: "Unix shell interpreter"
|
||||
|
||||
#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
|
||||
|| defined(__APPLE__) \
|
||||
)
|
||||
@@ -111,172 +266,6 @@
|
||||
# define PIPE_BUF 4096 /* amount of buffering in a pipe */
|
||||
#endif
|
||||
|
||||
//config:config HUSH
|
||||
//config: bool "hush"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: hush is a small shell (25k). It handles the normal flow control
|
||||
//config: constructs such as if/then/elif/else/fi, for/in/do/done, while loops,
|
||||
//config: case/esac. Redirections, here documents, $((arithmetic))
|
||||
//config: and functions are supported.
|
||||
//config:
|
||||
//config: It will compile and work on no-mmu systems.
|
||||
//config:
|
||||
//config: It does not handle select, aliases, tilde expansion,
|
||||
//config: &>file and >&file redirection of stdout+stderr.
|
||||
//config:
|
||||
//config:config HUSH_BASH_COMPAT
|
||||
//config: bool "bash-compatible extensions"
|
||||
//config: default y
|
||||
//config: depends on HUSH
|
||||
//config: help
|
||||
//config: Enable bash-compatible extensions.
|
||||
//config:
|
||||
//config:config HUSH_BRACE_EXPANSION
|
||||
//config: bool "Brace expansion"
|
||||
//config: default y
|
||||
//config: depends on HUSH_BASH_COMPAT
|
||||
//config: help
|
||||
//config: Enable {abc,def} extension.
|
||||
//config:
|
||||
//config:config HUSH_HELP
|
||||
//config: bool "help builtin"
|
||||
//config: default y
|
||||
//config: depends on HUSH
|
||||
//config: help
|
||||
//config: Enable help builtin in hush. Code size + ~1 kbyte.
|
||||
//config:
|
||||
//config:config HUSH_INTERACTIVE
|
||||
//config: bool "Interactive mode"
|
||||
//config: default y
|
||||
//config: depends on HUSH
|
||||
//config: help
|
||||
//config: Enable interactive mode (prompt and command editing).
|
||||
//config: Without this, hush simply reads and executes commands
|
||||
//config: from stdin just like a shell script from a file.
|
||||
//config: No prompt, no PS1/PS2 magic shell variables.
|
||||
//config:
|
||||
//config:config HUSH_SAVEHISTORY
|
||||
//config: bool "Save command history to .hush_history"
|
||||
//config: default y
|
||||
//config: depends on HUSH_INTERACTIVE && FEATURE_EDITING_SAVEHISTORY
|
||||
//config: help
|
||||
//config: Enable history saving in hush.
|
||||
//config:
|
||||
//config:config HUSH_JOB
|
||||
//config: bool "Job control"
|
||||
//config: default y
|
||||
//config: depends on HUSH_INTERACTIVE
|
||||
//config: help
|
||||
//config: Enable job control: Ctrl-Z backgrounds, Ctrl-C interrupts current
|
||||
//config: command (not entire shell), fg/bg builtins work. Without this option,
|
||||
//config: "cmd &" still works by simply spawning a process and immediately
|
||||
//config: prompting for next command (or executing next command in a script),
|
||||
//config: but no separate process group is formed.
|
||||
//config:
|
||||
//config:config HUSH_TICK
|
||||
//config: bool "Process substitution"
|
||||
//config: default y
|
||||
//config: depends on HUSH
|
||||
//config: help
|
||||
//config: Enable process substitution `command` and $(command) in hush.
|
||||
//config:
|
||||
//config:config HUSH_IF
|
||||
//config: bool "Support if/then/elif/else/fi"
|
||||
//config: default y
|
||||
//config: depends on HUSH
|
||||
//config: help
|
||||
//config: Enable if/then/elif/else/fi in hush.
|
||||
//config:
|
||||
//config:config HUSH_LOOPS
|
||||
//config: bool "Support for, while and until loops"
|
||||
//config: default y
|
||||
//config: depends on HUSH
|
||||
//config: help
|
||||
//config: Enable for, while and until loops in hush.
|
||||
//config:
|
||||
//config:config HUSH_CASE
|
||||
//config: bool "Support case ... esac statement"
|
||||
//config: default y
|
||||
//config: depends on HUSH
|
||||
//config: help
|
||||
//config: Enable case ... esac statement in hush. +400 bytes.
|
||||
//config:
|
||||
//config:config HUSH_FUNCTIONS
|
||||
//config: bool "Support funcname() { commands; } syntax"
|
||||
//config: default y
|
||||
//config: depends on HUSH
|
||||
//config: help
|
||||
//config: Enable support for shell functions in hush. +800 bytes.
|
||||
//config:
|
||||
//config:config HUSH_LOCAL
|
||||
//config: bool "Support local builtin"
|
||||
//config: default y
|
||||
//config: depends on HUSH_FUNCTIONS
|
||||
//config: help
|
||||
//config: Enable support for local variables in functions.
|
||||
//config:
|
||||
//config:config HUSH_RANDOM_SUPPORT
|
||||
//config: bool "Pseudorandom generator and $RANDOM variable"
|
||||
//config: default y
|
||||
//config: depends on HUSH
|
||||
//config: help
|
||||
//config: Enable pseudorandom generator and dynamic variable "$RANDOM".
|
||||
//config: Each read of "$RANDOM" will generate a new pseudorandom value.
|
||||
//config:
|
||||
//config:config HUSH_EXPORT_N
|
||||
//config: bool "Support 'export -n' option"
|
||||
//config: default y
|
||||
//config: depends on HUSH
|
||||
//config: help
|
||||
//config: export -n unexports variables. It is a bash extension.
|
||||
//config:
|
||||
//config:config HUSH_MODE_X
|
||||
//config: bool "Support 'hush -x' option and 'set -x' command"
|
||||
//config: default y
|
||||
//config: depends on HUSH
|
||||
//config: help
|
||||
//config: This instructs hush to print commands before execution.
|
||||
//config: Adds ~300 bytes.
|
||||
//config:
|
||||
//config:config MSH
|
||||
//config: bool "msh (deprecated: aliased to hush)"
|
||||
//config: default n
|
||||
//config: select HUSH
|
||||
//config: help
|
||||
//config: msh is deprecated and will be removed, please migrate to hush.
|
||||
//config:
|
||||
|
||||
//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_MSH(APPLET(msh, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_FEATURE_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, sh))
|
||||
//applet:IF_FEATURE_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, bash))
|
||||
|
||||
//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o
|
||||
//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o
|
||||
|
||||
/* -i (interactive) and -s (read stdin) are also accepted,
|
||||
* but currently do nothing, therefore aren't shown in help.
|
||||
* NOMMU-specific options are not meant to be used by users,
|
||||
* therefore we don't show them either.
|
||||
*/
|
||||
//usage:#define hush_trivial_usage
|
||||
//usage: "[-nxl] [-c 'SCRIPT' [ARG0 [ARGS]] / FILE [ARGS]]"
|
||||
//usage:#define hush_full_usage "\n\n"
|
||||
//usage: "Unix shell interpreter"
|
||||
|
||||
//usage:#define msh_trivial_usage hush_trivial_usage
|
||||
//usage:#define msh_full_usage hush_full_usage
|
||||
|
||||
//usage:#if ENABLE_FEATURE_SH_IS_HUSH
|
||||
//usage:# define sh_trivial_usage hush_trivial_usage
|
||||
//usage:# define sh_full_usage hush_full_usage
|
||||
//usage:#endif
|
||||
//usage:#if ENABLE_FEATURE_BASH_IS_HUSH
|
||||
//usage:# define bash_trivial_usage hush_trivial_usage
|
||||
//usage:# define bash_full_usage hush_full_usage
|
||||
//usage:#endif
|
||||
|
||||
|
||||
/* Build knobs */
|
||||
#define LEAK_HUNTING 0
|
||||
@@ -1148,6 +1137,9 @@ static void syntax_error_unexpected_ch(unsigned lineno UNUSED_PARAM, int ch)
|
||||
char msg[2];
|
||||
msg[0] = ch;
|
||||
msg[1] = '\0';
|
||||
#if HUSH_DEBUG >= 2
|
||||
bb_error_msg("hush.c:%u", lineno);
|
||||
#endif
|
||||
bb_error_msg("syntax error: unexpected %s", ch == EOF ? "EOF" : msg);
|
||||
}
|
||||
|
||||
@@ -4011,7 +4003,7 @@ static int i_peek_and_eat_bkslash_nl(struct in_str *input)
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_DOLLAR_OPS
|
||||
#if ENABLE_HUSH_TICK || ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_DOLLAR_OPS
|
||||
/* Subroutines for copying $(...) and `...` things */
|
||||
static int add_till_backquote(o_string *dest, struct in_str *input, int in_dquote);
|
||||
/* '...' */
|
||||
@@ -4179,7 +4171,7 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
#endif /* ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_DOLLAR_OPS */
|
||||
#endif /* ENABLE_HUSH_TICK || ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_DOLLAR_OPS */
|
||||
|
||||
/* Return code: 0 for OK, 1 for syntax error */
|
||||
#if BB_MMU
|
||||
@@ -4333,13 +4325,13 @@ static int parse_dollar(o_string *as_string,
|
||||
o_addchr(dest, SPECIAL_VAR_SYMBOL);
|
||||
break;
|
||||
}
|
||||
#if ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_TICK
|
||||
#if ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_TICK
|
||||
case '(': {
|
||||
unsigned pos;
|
||||
|
||||
ch = i_getch(input);
|
||||
nommu_addchr(as_string, ch);
|
||||
# if ENABLE_SH_MATH_SUPPORT
|
||||
# if ENABLE_FEATURE_SH_MATH
|
||||
if (i_peek_and_eat_bkslash_nl(input) == '(') {
|
||||
ch = i_getch(input);
|
||||
nommu_addchr(as_string, ch);
|
||||
@@ -5008,7 +5000,8 @@ static struct pipe *parse_stream(char **pstring,
|
||||
* if we see {, we call parse_group(..., end_trigger='}')
|
||||
* and it will match } earlier (not here). */
|
||||
syntax_error_unexpected_ch(ch);
|
||||
goto parse_error;
|
||||
G.last_exitcode = 2;
|
||||
goto parse_error1;
|
||||
default:
|
||||
if (HUSH_DEBUG)
|
||||
bb_error_msg_and_die("BUG: unexpected %c\n", ch);
|
||||
@@ -5016,6 +5009,8 @@ static struct pipe *parse_stream(char **pstring,
|
||||
} /* while (1) */
|
||||
|
||||
parse_error:
|
||||
G.last_exitcode = 1;
|
||||
parse_error1:
|
||||
{
|
||||
struct parse_context *pctx;
|
||||
IF_HAS_KEYWORDS(struct parse_context *p2;)
|
||||
@@ -5049,7 +5044,6 @@ static struct pipe *parse_stream(char **pstring,
|
||||
} while (HAS_KEYWORDS && pctx);
|
||||
|
||||
o_free(&dest);
|
||||
G.last_exitcode = 1;
|
||||
#if !BB_MMU
|
||||
if (pstring)
|
||||
*pstring = NULL;
|
||||
@@ -5217,7 +5211,7 @@ static char *encode_then_expand_string(const char *str, int process_bkslash, int
|
||||
return exp_str;
|
||||
}
|
||||
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p)
|
||||
{
|
||||
arith_state_t math_state;
|
||||
@@ -5469,7 +5463,7 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha
|
||||
}
|
||||
#endif
|
||||
else if (exp_op == ':') {
|
||||
#if ENABLE_HUSH_BASH_COMPAT && ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_HUSH_BASH_COMPAT && ENABLE_FEATURE_SH_MATH
|
||||
/* It's ${var:N[:M]} bashism.
|
||||
* Note that in encoded form it has TWO parts:
|
||||
* var:N<SPECIAL_VAR_SYMBOL>M<SPECIAL_VAR_SYMBOL>
|
||||
@@ -5604,7 +5598,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
|
||||
#if ENABLE_HUSH_TICK
|
||||
o_string subst_result = NULL_O_STRING;
|
||||
#endif
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
char arith_buf[sizeof(arith_t)*3 + 2];
|
||||
#endif
|
||||
|
||||
@@ -5698,7 +5692,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
|
||||
val = subst_result.data;
|
||||
goto store_val;
|
||||
#endif
|
||||
#if ENABLE_SH_MATH_SUPPORT
|
||||
#if ENABLE_FEATURE_SH_MATH
|
||||
case '+': { /* <SPECIAL_VAR_SYMBOL>+cmd<SPECIAL_VAR_SYMBOL> */
|
||||
arith_t res;
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
hush: syntax error: unexpected )
|
||||
Done:2
|
||||
hush: can't open 'does_not_exist': No such file or directory
|
||||
Done:1
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
# syntax error should return status 2
|
||||
cat >test.sh <<EOF
|
||||
)
|
||||
EOF
|
||||
chmod +x test.sh
|
||||
$THIS_SH ./test.sh
|
||||
echo Done:$?
|
||||
rm -f test.sh
|
||||
|
||||
# redirection error with special builtin should return status 1
|
||||
(eval cat <does_not_exist)
|
||||
echo Done:$?
|
||||
@@ -0,0 +1,6 @@
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
# Each of these should show only four lines:
|
||||
# fds 0,1,2 are stdio; fd 3 is open by opendir() in ls.
|
||||
# This test detects bugs where redirects leave stray open fds.
|
||||
|
||||
ls -1 /proc/self/fd | wc -l
|
||||
ls -1 /proc/self/fd >/proc/self/fd/1 | wc -l
|
||||
ls -1 /proc/self/fd >/proc/self/fd/1 2>&1 | wc -l
|
||||
echo "`ls -1 /proc/self/fd `" | wc -l
|
||||
echo "`ls -1 /proc/self/fd >/proc/self/fd/1 `" | wc -l
|
||||
echo "`ls -1 /proc/self/fd >/proc/self/fd/1 2>&1 `" | wc -l
|
||||
+1
-1
@@ -63,7 +63,7 @@
|
||||
|
||||
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
|
||||
|
||||
#if ENABLE_SH_MATH_SUPPORT_64
|
||||
#if ENABLE_FEATURE_SH_MATH_64
|
||||
typedef long long arith_t;
|
||||
#define ARITH_FMT "%lld"
|
||||
#define strto_arith_t strtoull
|
||||
|
||||
+2
-1
@@ -11,7 +11,8 @@
|
||||
//config:config LOGREAD
|
||||
//config: bool "logread"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_IPC_SYSLOG
|
||||
//WRONG: it should be compilable without SYSLOG=y:
|
||||
//WRONG: depends on FEATURE_IPC_SYSLOG
|
||||
//config: help
|
||||
//config: If you enabled Circular Buffer support, you almost
|
||||
//config: certainly want to enable this feature as well. This
|
||||
|
||||
@@ -31,6 +31,7 @@ rmdir foo
|
||||
rm foo.zip
|
||||
|
||||
# File containing some damaged encrypted stream
|
||||
optional FEATURE_UNZIP_CDF
|
||||
testing "unzip (bad archive)" "uudecode; unzip bad.zip 2>&1; echo \$?" \
|
||||
"Archive: bad.zip
|
||||
inflating: ]3j½r«IK-%Ix
|
||||
@@ -49,6 +50,7 @@ BDYAAAAMAAEADQAAADIADQAAAEEAAAASw73Ct1DKokohPXQiNzA+FAI1HCcW
|
||||
NzITNFBLBQUKAC4JAA04Cw0EOhZQSwUGAQAABAIAAgCZAAAAeQAAAAIALhM=
|
||||
====
|
||||
"
|
||||
SKIP=
|
||||
|
||||
rm *
|
||||
|
||||
|
||||
Reference in new issue
Block a user