Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2afdcc77cc | ||
|
|
c74f1d2cb4 | ||
|
|
62b7083c13 | ||
|
|
39bf15ba3e | ||
|
|
37277a23fe | ||
|
|
e3821088af | ||
|
|
4a80eb142a | ||
|
|
1574aff942 | ||
|
|
f5b9a22678 | ||
|
|
1123922320 | ||
|
|
ce5ba9277b | ||
|
|
20f02c3c87 | ||
|
|
277636670c | ||
|
|
4e71661e3a | ||
|
|
59675c625d |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 28
|
||||
SUBLEVEL = 0
|
||||
SUBLEVEL = 1
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
|
||||
@@ -107,9 +107,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
}
|
||||
}
|
||||
else if (existing_sb.st_mtime >= file_header->mtime) {
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
&& !S_ISDIR(file_header->mode)
|
||||
) {
|
||||
if (!S_ISDIR(file_header->mode)) {
|
||||
bb_error_msg("%s not created: newer or "
|
||||
"same age file exists", dst_name);
|
||||
}
|
||||
@@ -125,7 +123,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
/* Handle hard links separately */
|
||||
if (hard_link) {
|
||||
res = link(hard_link, dst_name);
|
||||
if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
if (res != 0) {
|
||||
/* shared message */
|
||||
bb_perror_msg("can't create %slink '%s' to '%s'",
|
||||
"hard", dst_name, hard_link
|
||||
@@ -165,10 +163,9 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
}
|
||||
case S_IFDIR:
|
||||
res = mkdir(dst_name, file_header->mode);
|
||||
if ((res == -1)
|
||||
if ((res != 0)
|
||||
&& (errno != EISDIR) /* btw, Linux doesn't return this */
|
||||
&& (errno != EEXIST)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("can't make dir %s", dst_name);
|
||||
}
|
||||
@@ -198,27 +195,16 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
*
|
||||
* Untarring bug.tar would otherwise place evil.py in '/tmp'.
|
||||
*/
|
||||
if (!unsafe_symlink_target(file_header->link_target)) {
|
||||
res = symlink(file_header->link_target, dst_name);
|
||||
if (res != 0
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
/* shared message */
|
||||
bb_perror_msg("can't create %slink '%s' to '%s'",
|
||||
"sym",
|
||||
dst_name, file_header->link_target
|
||||
);
|
||||
}
|
||||
}
|
||||
create_or_remember_symlink(&archive_handle->symlink_placeholders,
|
||||
file_header->link_target,
|
||||
dst_name);
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFIFO:
|
||||
res = mknod(dst_name, file_header->mode, file_header->device);
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
if (res != 0) {
|
||||
bb_perror_msg("can't create node %s", dst_name);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -152,6 +152,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
struct tar_header_t tar;
|
||||
char *cp;
|
||||
int tar_typeflag; /* can be "char", "int" seems give smaller code */
|
||||
int i, sum_u, sum;
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
int sum_s;
|
||||
@@ -253,10 +254,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
* POSIX says that checksum is done on unsigned bytes, but
|
||||
* Sun and HP-UX gets it wrong... more details in
|
||||
* GNU tar source. */
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
sum_s = ' ' * sizeof(tar.chksum);
|
||||
#endif
|
||||
sum_u = ' ' * sizeof(tar.chksum);
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
sum_s = sum_u;
|
||||
#endif
|
||||
for (i = 0; i < 148; i++) {
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
@@ -269,27 +270,22 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
#endif
|
||||
}
|
||||
/* This field does not need special treatment (getOctal) */
|
||||
{
|
||||
char *endp; /* gcc likes temp var for &endp */
|
||||
sum = strtoul(tar.chksum, &endp, 8);
|
||||
if ((*endp != '\0' && *endp != ' ')
|
||||
|| (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
|
||||
) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
}
|
||||
/* don't use xstrtoul, tar.chksum may have leading spaces */
|
||||
sum = strtoul(tar.chksum, NULL, 8);
|
||||
if (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) {
|
||||
/* Most tarfiles have tar.chksum NUL or space terminated, but
|
||||
* github.com decided to be "special" and have unterminated field:
|
||||
* 0090: 30343300 30303031 33323731 30000000 |043.000132710...|
|
||||
* ^^^^^^^^|
|
||||
* Need to use GET_OCTAL. This overwrites tar.typeflag ---+
|
||||
* (the '0' char immediately after chksum in example above) with NUL.
|
||||
*/
|
||||
tar_typeflag = (uint8_t)tar.typeflag; /* save it */
|
||||
sum = GET_OCTAL(tar.chksum);
|
||||
if (sum_u != sum
|
||||
IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)
|
||||
) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
|
||||
/* 0 is reserved for high perf file, treat as normal file */
|
||||
if (!tar.typeflag) tar.typeflag = '0';
|
||||
parse_names = (tar.typeflag >= '0' && tar.typeflag <= '7');
|
||||
|
||||
/* getOctal trashes subsequent field, therefore we call it
|
||||
/* GET_OCTAL trashes subsequent field, therefore we call it
|
||||
* on fields in reverse order */
|
||||
if (tar.devmajor[0]) {
|
||||
char t = tar.prefix[0];
|
||||
@@ -299,6 +295,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
file_header->device = makedev(major, minor);
|
||||
tar.prefix[0] = t;
|
||||
}
|
||||
|
||||
/* 0 is reserved for high perf file, treat as normal file */
|
||||
if (tar_typeflag == '\0') tar_typeflag = '0';
|
||||
parse_names = (tar_typeflag >= '0' && tar_typeflag <= '7');
|
||||
|
||||
file_header->link_target = NULL;
|
||||
if (!p_linkname && parse_names && tar.linkname[0]) {
|
||||
file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname));
|
||||
@@ -332,7 +333,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
/* Set bits 12-15 of the files mode */
|
||||
/* (typeflag was not trashed because chksum does not use getOctal) */
|
||||
switch (tar.typeflag) {
|
||||
switch (tar_typeflag) {
|
||||
case '1': /* hardlink */
|
||||
/* we mark hardlinks as regular files with zero size and a link name */
|
||||
file_header->mode |= S_IFREG;
|
||||
@@ -381,7 +382,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
case 'x': { /* pax extended header */
|
||||
if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
|
||||
goto skip_ext_hdr;
|
||||
process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
|
||||
process_pax_hdr(archive_handle, file_header->size, (tar_typeflag == 'g'));
|
||||
goto again_after_align;
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
/* See http://www.gnu.org/software/tar/manual/html_node/Extensions.html */
|
||||
@@ -419,7 +420,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
skip_ext_hdr:
|
||||
{
|
||||
off_t sz;
|
||||
bb_error_msg("warning: skipping header '%c'", tar.typeflag);
|
||||
bb_error_msg("warning: skipping header '%c'", tar_typeflag);
|
||||
sz = (file_header->size + 511) & ~(off_t)511;
|
||||
archive_handle->offset += sz;
|
||||
sz >>= 9; /* sz /= 512 but w/o contortions for signed div */
|
||||
@@ -429,7 +430,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
goto again_after_align;
|
||||
}
|
||||
default:
|
||||
bb_error_msg_and_die("unknown typeflag: 0x%x", tar.typeflag);
|
||||
bb_error_msg_and_die("unknown typeflag: 0x%x", tar_typeflag);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
|
||||
@@ -5,44 +5,37 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
int FAST_FUNC unsafe_symlink_target(const char *target)
|
||||
void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders,
|
||||
const char *target,
|
||||
const char *linkname)
|
||||
{
|
||||
const char *dot;
|
||||
|
||||
if (target[0] == '/') {
|
||||
const char *var;
|
||||
unsafe:
|
||||
var = getenv("EXTRACT_UNSAFE_SYMLINKS");
|
||||
if (var) {
|
||||
if (LONE_CHAR(var, '1'))
|
||||
return 0; /* pretend it's safe */
|
||||
return 1; /* "UNSAFE!" */
|
||||
}
|
||||
bb_error_msg("skipping unsafe symlink to '%s' in archive,"
|
||||
" set %s=1 to extract",
|
||||
target,
|
||||
"EXTRACT_UNSAFE_SYMLINKS"
|
||||
if (target[0] == '/' || strstr(target, "..")) {
|
||||
llist_add_to(symlink_placeholders,
|
||||
xasprintf("%s%c%s", linkname, '\0', target)
|
||||
);
|
||||
/* Prevent further messages */
|
||||
setenv("EXTRACT_UNSAFE_SYMLINKS", "0", 0);
|
||||
return 1; /* "UNSAFE!" */
|
||||
return;
|
||||
}
|
||||
if (symlink(target, linkname) != 0) {
|
||||
/* shared message */
|
||||
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
|
||||
"sym", linkname, target
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
dot = target;
|
||||
for (;;) {
|
||||
dot = strchr(dot, '.');
|
||||
if (!dot)
|
||||
return 0; /* safe target */
|
||||
void FAST_FUNC create_symlinks_from_list(llist_t *list)
|
||||
{
|
||||
while (list) {
|
||||
char *target;
|
||||
|
||||
/* Is it a path component starting with ".."? */
|
||||
if ((dot[1] == '.')
|
||||
&& (dot == target || dot[-1] == '/')
|
||||
/* Is it exactly ".."? */
|
||||
&& (dot[2] == '/' || dot[2] == '\0')
|
||||
) {
|
||||
goto unsafe;
|
||||
target = list->data + strlen(list->data) + 1;
|
||||
if (symlink(target, list->data)) {
|
||||
/* shared message */
|
||||
bb_error_msg_and_die("can't create %slink '%s' to '%s'",
|
||||
"sym",
|
||||
list->data, target
|
||||
);
|
||||
}
|
||||
/* NB: it can even be trailing ".", should only add 1 */
|
||||
dot += 1;
|
||||
list = list->link;
|
||||
}
|
||||
}
|
||||
@@ -1244,6 +1244,8 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
while (get_header_tar(tar_handle) == EXIT_SUCCESS)
|
||||
bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */
|
||||
|
||||
create_symlinks_from_list(tar_handle->symlink_placeholders);
|
||||
|
||||
/* Check that every file that should have been extracted was */
|
||||
while (tar_handle->accept) {
|
||||
if (!find_list_entry(tar_handle->reject, tar_handle->accept->data)
|
||||
|
||||
+14
-11
@@ -343,7 +343,9 @@ static void unzip_create_leading_dirs(const char *fn)
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
static void unzip_extract_symlink(zip_header_t *zip, const char *dst_fn)
|
||||
static void unzip_extract_symlink(llist_t **symlink_placeholders,
|
||||
zip_header_t *zip,
|
||||
const char *dst_fn)
|
||||
{
|
||||
char *target;
|
||||
|
||||
@@ -368,15 +370,9 @@ static void unzip_extract_symlink(zip_header_t *zip, const char *dst_fn)
|
||||
target[xstate.mem_output_size] = '\0';
|
||||
#endif
|
||||
}
|
||||
if (!unsafe_symlink_target(target)) {
|
||||
//TODO: libbb candidate
|
||||
if (symlink(target, dst_fn)) {
|
||||
/* shared message */
|
||||
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
|
||||
"sym", dst_fn, target
|
||||
);
|
||||
}
|
||||
}
|
||||
create_or_remember_symlink(symlink_placeholders,
|
||||
target,
|
||||
dst_fn);
|
||||
free(target);
|
||||
}
|
||||
#endif
|
||||
@@ -488,6 +484,9 @@ int unzip_main(int argc, char **argv)
|
||||
llist_t *zaccept = NULL;
|
||||
llist_t *zreject = NULL;
|
||||
char *base_dir = NULL;
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
llist_t *symlink_placeholders = NULL;
|
||||
#endif
|
||||
int i;
|
||||
char key_buf[80]; /* must match size used by my_fgets80 */
|
||||
|
||||
@@ -952,7 +951,7 @@ int unzip_main(int argc, char **argv)
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
if (S_ISLNK(file_mode)) {
|
||||
if (dst_fd != STDOUT_FILENO) /* not -p? */
|
||||
unzip_extract_symlink(&zip, dst_fn);
|
||||
unzip_extract_symlink(&symlink_placeholders, &zip, dst_fn);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
@@ -988,6 +987,10 @@ int unzip_main(int argc, char **argv)
|
||||
total_entries++;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
create_symlinks_from_list(symlink_placeholders);
|
||||
#endif
|
||||
|
||||
if ((opts & OPT_l) && quiet <= 1) {
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
|
||||
+18
-3
@@ -47,6 +47,7 @@
|
||||
//usage: "\n -f Overwrite"
|
||||
//usage: "\n -i Prompt before overwrite"
|
||||
//usage: "\n -l,-s Create (sym)links"
|
||||
//usage: "\n -T Treat DEST as a normal file"
|
||||
//usage: "\n -u Copy only newer files"
|
||||
|
||||
#include "libbb.h"
|
||||
@@ -92,13 +93,18 @@ int cp_main(int argc, char **argv)
|
||||
"no-dereference\0" No_argument "P"
|
||||
"recursive\0" No_argument "R"
|
||||
"symbolic-link\0" No_argument "s"
|
||||
"no-target-directory\0" No_argument "T"
|
||||
"verbose\0" No_argument "v"
|
||||
"update\0" No_argument "u"
|
||||
"remove-destination\0" No_argument "\xff"
|
||||
"parents\0" No_argument "\xfe"
|
||||
);
|
||||
#else
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR);
|
||||
flags = getopt32(argv, "^"
|
||||
FILEUTILS_CP_OPTSTR
|
||||
"\0"
|
||||
"-2:l--s:s--l:Pd:rRd:Rd:apdR"
|
||||
);
|
||||
#endif
|
||||
/* Options of cp from GNU coreutils 6.10:
|
||||
* -a, --archive
|
||||
@@ -121,6 +127,8 @@ int cp_main(int argc, char **argv)
|
||||
* remove each existing destination file before attempting to open
|
||||
* --parents
|
||||
* use full source file name under DIRECTORY
|
||||
* -T, --no-target-directory
|
||||
* treat DEST as a normal file
|
||||
* NOT SUPPORTED IN BBOX:
|
||||
* --backup[=CONTROL]
|
||||
* make a backup of each existing destination file
|
||||
@@ -139,8 +147,6 @@ int cp_main(int argc, char **argv)
|
||||
* override the usual backup suffix
|
||||
* -t, --target-directory=DIRECTORY
|
||||
* copy all SOURCE arguments into DIRECTORY
|
||||
* -T, --no-target-directory
|
||||
* treat DEST as a normal file
|
||||
* -x, --one-file-system
|
||||
* stay on this file system
|
||||
* -Z, --context=CONTEXT
|
||||
@@ -175,6 +181,12 @@ int cp_main(int argc, char **argv)
|
||||
if (d_flags < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (flags & FILEUTILS_NO_TARGET_DIR) { /* -T */
|
||||
if (!(s_flags & 2) && (d_flags & 2))
|
||||
/* cp -T NOTDIR DIR */
|
||||
bb_error_msg_and_die("'%s' is a directory", last);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
//bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
|
||||
// flags, FILEUTILS_RMDEST, OPT_parents);
|
||||
@@ -192,11 +204,14 @@ int cp_main(int argc, char **argv)
|
||||
if (!((s_flags | d_flags) & 2)
|
||||
/* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */
|
||||
|| ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
|
||||
|| (flags & FILEUTILS_NO_TARGET_DIR)
|
||||
) {
|
||||
/* Do a simple copy */
|
||||
dest = last;
|
||||
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
|
||||
}
|
||||
} else if (flags & FILEUTILS_NO_TARGET_DIR) {
|
||||
bb_error_msg_and_die("too many arguments");
|
||||
}
|
||||
|
||||
while (1) {
|
||||
|
||||
@@ -11,13 +11,13 @@ echo "* Upping iface $if"
|
||||
ip link set dev $if up
|
||||
|
||||
>>udhcpd.leases
|
||||
sed 's/^interface.*$/interface '"$if/" -i udhcpc.conf
|
||||
sed 's/^interface.*$/interface '"$if/" -i udhcpd.conf
|
||||
|
||||
echo "* Starting udhcpd"
|
||||
exec \
|
||||
env - PATH="$PATH" \
|
||||
softlimit \
|
||||
setuidgid root \
|
||||
udhcpd -f -vv udhcpc.conf
|
||||
udhcpd -f -vv udhcpd.conf
|
||||
|
||||
exit $?
|
||||
File renamed without changes.
+14
-9
@@ -64,6 +64,9 @@ typedef struct archive_handle_t {
|
||||
/* Currently processed file's header */
|
||||
file_header_t *file_header;
|
||||
|
||||
/* List of symlink placeholders */
|
||||
llist_t *symlink_placeholders;
|
||||
|
||||
/* Process the header component, e.g. tar -t */
|
||||
void FAST_FUNC (*action_header)(const file_header_t *);
|
||||
|
||||
@@ -119,15 +122,14 @@ typedef struct archive_handle_t {
|
||||
#define ARCHIVE_RESTORE_DATE (1 << 0)
|
||||
#define ARCHIVE_CREATE_LEADING_DIRS (1 << 1)
|
||||
#define ARCHIVE_UNLINK_OLD (1 << 2)
|
||||
#define ARCHIVE_EXTRACT_QUIET (1 << 3)
|
||||
#define ARCHIVE_EXTRACT_NEWER (1 << 4)
|
||||
#define ARCHIVE_DONT_RESTORE_OWNER (1 << 5)
|
||||
#define ARCHIVE_DONT_RESTORE_PERM (1 << 6)
|
||||
#define ARCHIVE_NUMERIC_OWNER (1 << 7)
|
||||
#define ARCHIVE_O_TRUNC (1 << 8)
|
||||
#define ARCHIVE_REMEMBER_NAMES (1 << 9)
|
||||
#define ARCHIVE_EXTRACT_NEWER (1 << 3)
|
||||
#define ARCHIVE_DONT_RESTORE_OWNER (1 << 4)
|
||||
#define ARCHIVE_DONT_RESTORE_PERM (1 << 5)
|
||||
#define ARCHIVE_NUMERIC_OWNER (1 << 6)
|
||||
#define ARCHIVE_O_TRUNC (1 << 7)
|
||||
#define ARCHIVE_REMEMBER_NAMES (1 << 8)
|
||||
#if ENABLE_RPM
|
||||
#define ARCHIVE_REPLACE_VIA_RENAME (1 << 10)
|
||||
#define ARCHIVE_REPLACE_VIA_RENAME (1 << 9)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -197,7 +199,10 @@ void seek_by_jump(int fd, off_t amount) FAST_FUNC;
|
||||
void seek_by_read(int fd, off_t amount) FAST_FUNC;
|
||||
|
||||
const char *strip_unsafe_prefix(const char *str) FAST_FUNC;
|
||||
int unsafe_symlink_target(const char *target) FAST_FUNC;
|
||||
void create_or_remember_symlink(llist_t **symlink_placeholders,
|
||||
const char *target,
|
||||
const char *linkname) FAST_FUNC;
|
||||
void create_symlinks_from_list(llist_t *list) FAST_FUNC;
|
||||
|
||||
void data_align(archive_handle_t *archive_handle, unsigned boundary) FAST_FUNC;
|
||||
const llist_t *find_list_entry(const llist_t *list, const char *filename) FAST_FUNC;
|
||||
|
||||
+4
-3
@@ -404,10 +404,11 @@ enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing th
|
||||
/* -P = -d (mapped in cp.c) */
|
||||
FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE, /* -v */
|
||||
FILEUTILS_UPDATE = 1 << 13, /* -u */
|
||||
FILEUTILS_NO_TARGET_DIR = 1 << 14, /* -T */
|
||||
#if ENABLE_SELINUX
|
||||
FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 14, /* -c */
|
||||
FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 15, /* -c */
|
||||
#endif
|
||||
FILEUTILS_RMDEST = 1 << (15 - !ENABLE_SELINUX), /* --remove-destination */
|
||||
FILEUTILS_RMDEST = 1 << (16 - !ENABLE_SELINUX), /* --remove-destination */
|
||||
/*
|
||||
* Hole. cp may have some bits set here,
|
||||
* they should not affect remove_file()/copy_file()
|
||||
@@ -417,7 +418,7 @@ enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing th
|
||||
#endif
|
||||
FILEUTILS_IGNORE_CHMOD_ERR = 1 << 31,
|
||||
};
|
||||
#define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvu" IF_SELINUX("c")
|
||||
#define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvuT" IF_SELINUX("c")
|
||||
extern int remove_file(const char *path, int flags) FAST_FUNC;
|
||||
/* NB: without FILEUTILS_RECUR in flags, it will basically "cat"
|
||||
* the source, not copy (unless "source" is a directory).
|
||||
|
||||
@@ -113,7 +113,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
|
||||
if (G_filter.up && !(ifi->ifi_flags & IFF_UP))
|
||||
return 0;
|
||||
|
||||
memset(tb, 0, sizeof(tb));
|
||||
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
|
||||
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
|
||||
if (tb[IFLA_IFNAME] == NULL) {
|
||||
bb_error_msg("nil ifname");
|
||||
@@ -227,7 +227,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
|
||||
if (G_filter.flushb && n->nlmsg_type != RTM_NEWADDR)
|
||||
return 0;
|
||||
|
||||
memset(rta_tb, 0, sizeof(rta_tb));
|
||||
//memset(rta_tb, 0, sizeof(rta_tb)); - parse_rtattr does this
|
||||
parse_rtattr(rta_tb, IFA_MAX, IFA_RTA(ifa), n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa)));
|
||||
|
||||
if (!rta_tb[IFA_LOCAL])
|
||||
@@ -535,7 +535,7 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush)
|
||||
continue;
|
||||
if (G_filter.pfx.family || G_filter.label) {
|
||||
struct rtattr *tb[IFA_MAX+1];
|
||||
memset(tb, 0, sizeof(tb));
|
||||
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
|
||||
parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), IFA_PAYLOAD(n));
|
||||
if (!tb[IFA_LOCAL])
|
||||
tb[IFA_LOCAL] = tb[IFA_ADDRESS];
|
||||
|
||||
@@ -110,11 +110,13 @@ static int FAST_FUNC print_neigh(const struct sockaddr_nl *who UNUSED_PARAM,
|
||||
return 0;
|
||||
if (G_filter.index && G_filter.index != r->ndm_ifindex)
|
||||
return 0;
|
||||
if (!(G_filter.state&r->ndm_state) &&
|
||||
!(r->ndm_flags & NTF_PROXY) &&
|
||||
(r->ndm_state || !(G_filter.state & 0x100)) &&
|
||||
(r->ndm_family != AF_DECnet))
|
||||
if (!(G_filter.state&r->ndm_state)
|
||||
&& !(r->ndm_flags & NTF_PROXY)
|
||||
&& (r->ndm_state || !(G_filter.state & 0x100))
|
||||
&& (r->ndm_family != AF_DECnet)
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
parse_rtattr(tb, NDA_MAX, NDA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
|
||||
if (len < 0)
|
||||
bb_error_msg_and_die("wrong nlmsg len %d", len);
|
||||
|
||||
memset(tb, 0, sizeof(tb));
|
||||
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
|
||||
parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
|
||||
|
||||
#if HAVE_RTA_TABLE
|
||||
@@ -1081,7 +1081,7 @@ static int iproute_get(char **argv)
|
||||
bb_error_msg_and_die("wrong len %d", len);
|
||||
}
|
||||
|
||||
memset(tb, 0, sizeof(tb));
|
||||
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
|
||||
parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
|
||||
|
||||
if (tb[RTA_PREFSRC]) {
|
||||
|
||||
@@ -63,7 +63,7 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
|
||||
if (len < 0)
|
||||
return -1;
|
||||
|
||||
memset(tb, 0, sizeof(tb));
|
||||
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
|
||||
parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
|
||||
|
||||
if (r->rtm_family == AF_INET)
|
||||
|
||||
@@ -401,6 +401,8 @@ int FAST_FUNC rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data
|
||||
|
||||
void FAST_FUNC parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
|
||||
{
|
||||
memset(tb, 0, (max + 1) * sizeof(tb[0]));
|
||||
|
||||
while (RTA_OK(rta, len)) {
|
||||
if (rta->rta_type <= max) {
|
||||
tb[rta->rta_type] = rta;
|
||||
|
||||
@@ -51,7 +51,7 @@ int FAST_FUNC ll_remember_index(const struct sockaddr_nl *who UNUSED_PARAM,
|
||||
if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifi)))
|
||||
return -1;
|
||||
|
||||
memset(tb, 0, sizeof(tb));
|
||||
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
|
||||
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(n));
|
||||
if (tb[IFLA_IFNAME] == NULL)
|
||||
return 0;
|
||||
|
||||
@@ -30,7 +30,7 @@ int ssl_client_main(int argc UNUSED_PARAM, char **argv)
|
||||
// INIT_G();
|
||||
|
||||
tls = new_tls_state();
|
||||
opt = getopt32(argv, "s:#r:#n:", &tls->ofd, &tls->ifd, &sni);
|
||||
opt = getopt32(argv, "s:+r:+n:", &tls->ofd, &tls->ifd, &sni);
|
||||
if (!(opt & 2)) {
|
||||
/* -r N defaults to -s N */
|
||||
tls->ifd = tls->ofd;
|
||||
|
||||
+13
-9
@@ -57,17 +57,21 @@
|
||||
|
||||
/* nullifies tb on error */
|
||||
#define __parse_rtattr_nested_compat(tb, max, rta, len) \
|
||||
({if ((RTA_PAYLOAD(rta) >= len) && \
|
||||
(RTA_PAYLOAD(rta) >= RTA_ALIGN(len) + sizeof(struct rtattr))) { \
|
||||
rta = RTA_DATA(rta) + RTA_ALIGN(len); \
|
||||
parse_rtattr_nested(tb, max, rta); \
|
||||
} else \
|
||||
memset(tb, 0, sizeof(struct rtattr *) * (max + 1)); \
|
||||
})
|
||||
({ \
|
||||
if ((RTA_PAYLOAD(rta) >= len) \
|
||||
&& (RTA_PAYLOAD(rta) >= RTA_ALIGN(len) + sizeof(struct rtattr)) \
|
||||
) { \
|
||||
rta = RTA_DATA(rta) + RTA_ALIGN(len); \
|
||||
parse_rtattr_nested(tb, max, rta); \
|
||||
} else \
|
||||
memset(tb, 0, sizeof(struct rtattr *) * (max + 1)); \
|
||||
})
|
||||
|
||||
#define parse_rtattr_nested_compat(tb, max, rta, data, len) \
|
||||
({data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \
|
||||
__parse_rtattr_nested_compat(tb, max, rta, len); })
|
||||
({ \
|
||||
data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \
|
||||
__parse_rtattr_nested_compat(tb, max, rta, len); \
|
||||
})
|
||||
|
||||
#define show_details (0) /* not implemented. Does anyone need it? */
|
||||
#define use_iec (0) /* not currently documented in the upstream manpage */
|
||||
|
||||
+8
-3
@@ -269,17 +269,22 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
tcp = (applet_name[0] == 't');
|
||||
|
||||
/* "+": stop on first non-option */
|
||||
#ifdef SSLSVD
|
||||
opts = getopt32(argv, "^+"
|
||||
"c:+C:i:x:u:l:Eb:+hpt:vU:/:Z:K:" /* -c NUM, -b NUM */
|
||||
"\0"
|
||||
/* 3+ args, -i at most once, -p implies -h, -v is a counter */
|
||||
"\0" "-3:i--i:ph:vv",
|
||||
"-3:i--i:ph:vv",
|
||||
&cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
|
||||
&backlog, &str_t, &ssluser, &root, &cert, &key, &verbose
|
||||
);
|
||||
#else
|
||||
/* "+": stop on first non-option */
|
||||
opts = getopt32(argv, "+c:+C:i:x:u:l:Eb:hpt:v",
|
||||
opts = getopt32(argv, "^+"
|
||||
"c:+C:i:x:u:l:Eb:+hpt:v" /* -c NUM, -b NUM */
|
||||
"\0"
|
||||
/* 3+ args, -i at most once, -p implies -h, -v is a counter */
|
||||
"-3:i--i:ph:vv",
|
||||
&cmax, &str_C, &instructs, &instructs, &user, &preset_local_hostname,
|
||||
&backlog, &str_t, &verbose
|
||||
);
|
||||
|
||||
+53
-39
@@ -84,23 +84,23 @@
|
||||
# define dbg_der(...) ((void)0)
|
||||
#endif
|
||||
|
||||
#define RECORD_TYPE_CHANGE_CIPHER_SPEC 20
|
||||
#define RECORD_TYPE_ALERT 21
|
||||
#define RECORD_TYPE_HANDSHAKE 22
|
||||
#define RECORD_TYPE_APPLICATION_DATA 23
|
||||
#define RECORD_TYPE_CHANGE_CIPHER_SPEC 20 /* 0x14 */
|
||||
#define RECORD_TYPE_ALERT 21 /* 0x15 */
|
||||
#define RECORD_TYPE_HANDSHAKE 22 /* 0x16 */
|
||||
#define RECORD_TYPE_APPLICATION_DATA 23 /* 0x17 */
|
||||
|
||||
#define HANDSHAKE_HELLO_REQUEST 0
|
||||
#define HANDSHAKE_CLIENT_HELLO 1
|
||||
#define HANDSHAKE_SERVER_HELLO 2
|
||||
#define HANDSHAKE_HELLO_VERIFY_REQUEST 3
|
||||
#define HANDSHAKE_NEW_SESSION_TICKET 4
|
||||
#define HANDSHAKE_CERTIFICATE 11
|
||||
#define HANDSHAKE_SERVER_KEY_EXCHANGE 12
|
||||
#define HANDSHAKE_CERTIFICATE_REQUEST 13
|
||||
#define HANDSHAKE_SERVER_HELLO_DONE 14
|
||||
#define HANDSHAKE_CERTIFICATE_VERIFY 15
|
||||
#define HANDSHAKE_CLIENT_KEY_EXCHANGE 16
|
||||
#define HANDSHAKE_FINISHED 20
|
||||
#define HANDSHAKE_HELLO_REQUEST 0 /* 0x00 */
|
||||
#define HANDSHAKE_CLIENT_HELLO 1 /* 0x01 */
|
||||
#define HANDSHAKE_SERVER_HELLO 2 /* 0x02 */
|
||||
#define HANDSHAKE_HELLO_VERIFY_REQUEST 3 /* 0x03 */
|
||||
#define HANDSHAKE_NEW_SESSION_TICKET 4 /* 0x04 */
|
||||
#define HANDSHAKE_CERTIFICATE 11 /* 0x0b */
|
||||
#define HANDSHAKE_SERVER_KEY_EXCHANGE 12 /* 0x0c */
|
||||
#define HANDSHAKE_CERTIFICATE_REQUEST 13 /* 0x0d */
|
||||
#define HANDSHAKE_SERVER_HELLO_DONE 14 /* 0x0e */
|
||||
#define HANDSHAKE_CERTIFICATE_VERIFY 15 /* 0x0f */
|
||||
#define HANDSHAKE_CLIENT_KEY_EXCHANGE 16 /* 0x10 */
|
||||
#define HANDSHAKE_FINISHED 20 /* 0x14 */
|
||||
|
||||
#define SSL_NULL_WITH_NULL_NULL 0x0000
|
||||
#define SSL_RSA_WITH_NULL_MD5 0x0001
|
||||
@@ -512,10 +512,12 @@ static void bad_record_die(tls_state_t *tls, const char *expected, int len)
|
||||
bb_error_msg("got bad TLS record (len:%d) while expecting %s", len, expected);
|
||||
if (len > 0) {
|
||||
uint8_t *p = tls->inbuf;
|
||||
while (len > 0) {
|
||||
if (len > 99)
|
||||
len = 99; /* don't flood, a few lines should be enough */
|
||||
do {
|
||||
fprintf(stderr, " %02x", *p++);
|
||||
len--;
|
||||
}
|
||||
} while (len != 0);
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
xfunc_die();
|
||||
@@ -671,9 +673,11 @@ static void xwrite_encrypted(tls_state_t *tls, unsigned size, unsigned type)
|
||||
// AES_128_CBC Block 16 16 16
|
||||
// AES_256_CBC Block 32 16 16
|
||||
|
||||
/* Fill IV and padding in outbuf */
|
||||
tls_get_random(buf - AES_BLOCKSIZE, AES_BLOCKSIZE); /* IV */
|
||||
dbg("before crypt: 5 hdr + %u data + %u hash bytes\n", size, tls->MAC_size);
|
||||
dbg("before crypt: 5 hdr + %u data + %u hash bytes\n",
|
||||
size - tls->MAC_size, tls->MAC_size);
|
||||
|
||||
/* Fill IV and padding in outbuf */
|
||||
// RFC is talking nonsense:
|
||||
// "Padding that is added to force the length of the plaintext to be
|
||||
// an integral multiple of the block cipher's block length."
|
||||
@@ -773,7 +777,7 @@ static const char *alert_text(int code)
|
||||
return itoa(code);
|
||||
}
|
||||
|
||||
static int tls_xread_record(tls_state_t *tls)
|
||||
static int tls_xread_record(tls_state_t *tls, const char *expected)
|
||||
{
|
||||
struct record_hdr *xhdr;
|
||||
int sz;
|
||||
@@ -796,13 +800,16 @@ static int tls_xread_record(tls_state_t *tls)
|
||||
if (total >= RECHDR_LEN && target == MAX_INBUF) {
|
||||
xhdr = (void*)tls->inbuf;
|
||||
target = RECHDR_LEN + (0x100 * xhdr->len16_hi + xhdr->len16_lo);
|
||||
if (target > MAX_INBUF) {
|
||||
/* malformed input (too long): yell and die */
|
||||
tls->buffered_size = 0;
|
||||
tls->ofs_to_buffered = total;
|
||||
tls_error_die(tls);
|
||||
|
||||
if (target > MAX_INBUF /* malformed input (too long) */
|
||||
|| xhdr->proto_maj != TLS_MAJ
|
||||
|| xhdr->proto_min != TLS_MIN
|
||||
) {
|
||||
sz = total < target ? total : target;
|
||||
if (sz > 24)
|
||||
sz = 24; /* don't flood */
|
||||
bad_record_die(tls, expected, sz);
|
||||
}
|
||||
/* can also check type/proto_maj/proto_min here */
|
||||
dbg("xhdr type:%d ver:%d.%d len:%d\n",
|
||||
xhdr->type, xhdr->proto_maj, xhdr->proto_min,
|
||||
0x100 * xhdr->len16_hi + xhdr->len16_lo
|
||||
@@ -1137,13 +1144,11 @@ static void find_key_in_der_cert(tls_state_t *tls, uint8_t *der, int len)
|
||||
static int tls_xread_handshake_block(tls_state_t *tls, int min_len)
|
||||
{
|
||||
struct record_hdr *xhdr;
|
||||
int len = tls_xread_record(tls);
|
||||
int len = tls_xread_record(tls, "handshake record");
|
||||
|
||||
xhdr = (void*)tls->inbuf;
|
||||
if (len < min_len
|
||||
|| xhdr->type != RECORD_TYPE_HANDSHAKE
|
||||
|| xhdr->proto_maj != TLS_MAJ
|
||||
|| xhdr->proto_min != TLS_MIN
|
||||
) {
|
||||
bad_record_die(tls, "handshake record", len);
|
||||
}
|
||||
@@ -1195,7 +1200,9 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
|
||||
// 0023 0000 - session_ticket
|
||||
// 000a 0008 0006001700180019 - supported_groups
|
||||
// 000b 0002 0100 - ec_point_formats
|
||||
// 000d 0016 00140401040305010503060106030301030302010203 - signature_algorithms
|
||||
// 000d 0016 0014 0401 0403 0501 0503 0601 0603 0301 0303 0201 0203 - signature_algorithms
|
||||
// wolfssl library sends this option, RFC 7627 (closes a security weakness, some servers may require it. TODO?):
|
||||
// 0017 0000 - extended master secret
|
||||
};
|
||||
struct client_hello *record;
|
||||
int len;
|
||||
@@ -1354,7 +1361,7 @@ static void get_server_cert(tls_state_t *tls)
|
||||
xhdr = (void*)tls->inbuf;
|
||||
certbuf = (void*)(xhdr + 1);
|
||||
if (certbuf[0] != HANDSHAKE_CERTIFICATE)
|
||||
tls_error_die(tls);
|
||||
bad_record_die(tls, "certificate", len);
|
||||
dbg("<< CERTIFICATE\n");
|
||||
// 4392 bytes:
|
||||
// 0b 00|11|24 00|11|21 00|05|b0 30|82|05|ac|30|82|04|94|a0|03|02|01|02|02|11|00|9f|85|bf|66|4b|0c|dd|af|ca|50|86|79|50|1b|2b|e4|30|0d...
|
||||
@@ -1611,6 +1618,7 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
|
||||
// <------- Finished
|
||||
// Application Data <------> Application Data
|
||||
int len;
|
||||
int got_cert_req;
|
||||
|
||||
send_client_hello_and_alloc_hsd(tls, sni);
|
||||
get_server_hello(tls);
|
||||
@@ -1638,7 +1646,8 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
|
||||
len = tls_xread_handshake_block(tls, 4);
|
||||
}
|
||||
|
||||
if (tls->inbuf[RECHDR_LEN] == HANDSHAKE_CERTIFICATE_REQUEST) {
|
||||
got_cert_req = (tls->inbuf[RECHDR_LEN] == HANDSHAKE_CERTIFICATE_REQUEST);
|
||||
if (got_cert_req) {
|
||||
dbg("<< CERTIFICATE_REQUEST\n");
|
||||
// RFC 5246: "If no suitable certificate is available,
|
||||
// the client MUST send a certificate message containing no
|
||||
@@ -1647,7 +1656,9 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
|
||||
// Client certificates are sent using the Certificate structure
|
||||
// defined in Section 7.4.2."
|
||||
// (i.e. the same format as server certs)
|
||||
send_empty_client_cert(tls);
|
||||
|
||||
/*send_empty_client_cert(tls); - WRONG (breaks handshake hash calc) */
|
||||
/* need to hash _all_ server replies first, up to ServerHelloDone */
|
||||
len = tls_xread_handshake_block(tls, 4);
|
||||
}
|
||||
|
||||
@@ -1657,6 +1668,9 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
|
||||
// 0e 000000 (len:0)
|
||||
dbg("<< SERVER_HELLO_DONE\n");
|
||||
|
||||
if (got_cert_req)
|
||||
send_empty_client_cert(tls);
|
||||
|
||||
send_client_key_exchange(tls);
|
||||
|
||||
send_change_cipher_spec(tls);
|
||||
@@ -1667,7 +1681,7 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
|
||||
send_client_finished(tls);
|
||||
|
||||
/* Get CHANGE_CIPHER_SPEC */
|
||||
len = tls_xread_record(tls);
|
||||
len = tls_xread_record(tls, "switch to encrypted traffic");
|
||||
if (len != 1 || memcmp(tls->inbuf, rec_CHANGE_CIPHER_SPEC, 6) != 0)
|
||||
bad_record_die(tls, "switch to encrypted traffic", len);
|
||||
dbg("<< CHANGE_CIPHER_SPEC\n");
|
||||
@@ -1685,9 +1699,9 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
|
||||
}
|
||||
|
||||
/* Get (encrypted) FINISHED from the server */
|
||||
len = tls_xread_record(tls);
|
||||
len = tls_xread_record(tls, "'server finished'");
|
||||
if (len < 4 || tls->inbuf[RECHDR_LEN] != HANDSHAKE_FINISHED)
|
||||
tls_error_die(tls);
|
||||
bad_record_die(tls, "'server finished'", len);
|
||||
dbg("<< FINISHED\n");
|
||||
/* application data can be sent/received */
|
||||
|
||||
@@ -1763,7 +1777,7 @@ void FAST_FUNC tls_run_copy_loop(tls_state_t *tls)
|
||||
if (pfds[1].revents) {
|
||||
dbg("NETWORK HAS DATA\n");
|
||||
read_record:
|
||||
nread = tls_xread_record(tls);
|
||||
nread = tls_xread_record(tls, "encrypted data");
|
||||
if (nread < 1) {
|
||||
/* TLS protocol has no real concept of one-sided shutdowns:
|
||||
* if we get "TLS EOF" from the peer, writes will fail too
|
||||
@@ -1775,7 +1789,7 @@ void FAST_FUNC tls_run_copy_loop(tls_state_t *tls)
|
||||
break;
|
||||
}
|
||||
if (tls->inbuf[0] != RECORD_TYPE_APPLICATION_DATA)
|
||||
bb_error_msg_and_die("unexpected record type %d", tls->inbuf[0]);
|
||||
bad_record_die(tls, "encrypted data", nread);
|
||||
xwrite(STDOUT_FILENO, tls->inbuf + RECHDR_LEN, nread);
|
||||
/* We may already have a complete next record buffered,
|
||||
* can process it without network reads (and possible blocking)
|
||||
|
||||
@@ -314,7 +314,7 @@ int udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
|
||||
|
||||
void udhcp_sp_setup(void) FAST_FUNC;
|
||||
void udhcp_sp_fd_set(struct pollfd *pfds, int extra_fd) FAST_FUNC;
|
||||
int udhcp_sp_read(struct pollfd *pfds) FAST_FUNC;
|
||||
int udhcp_sp_read(void) FAST_FUNC;
|
||||
|
||||
int udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac) FAST_FUNC;
|
||||
|
||||
|
||||
@@ -277,11 +277,11 @@ static void option_to_env(uint8_t *option, uint8_t *option_end)
|
||||
* | |
|
||||
* +-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
//move_from_unaligned32(v32, option + 4 + 4);
|
||||
//*new_env() = xasprintf("lease=%u", (unsigned)v32);
|
||||
move_from_unaligned32(v32, option + 4 + 4);
|
||||
*new_env() = xasprintf("ipv6prefix_lease=%u", (unsigned)v32);
|
||||
|
||||
sprint_nip6(ipv6str, option + 4 + 4 + 1);
|
||||
*new_env() = xasprintf("ipv6prefix=%s/%u", ipv6str, (unsigned)(option[4 + 4]));
|
||||
sprint_nip6(ipv6str, option + 4 + 4 + 4 + 1);
|
||||
*new_env() = xasprintf("ipv6prefix=%s/%u", ipv6str, (unsigned)(option[4 + 4 + 4]));
|
||||
break;
|
||||
#if ENABLE_FEATURE_UDHCPC6_RFC3646
|
||||
case D6_OPT_DNS_SERVERS: {
|
||||
@@ -1378,13 +1378,12 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* yah, I know, *you* say it would never happen */
|
||||
timeout = INT_MAX;
|
||||
continue; /* back to main loop */
|
||||
} /* if select timed out */
|
||||
} /* if poll timed out */
|
||||
|
||||
/* select() didn't timeout, something happened */
|
||||
/* poll() didn't timeout, something happened */
|
||||
|
||||
/* Is it a signal? */
|
||||
/* note: udhcp_sp_read checks poll result before reading */
|
||||
switch (udhcp_sp_read(pfds)) {
|
||||
switch (udhcp_sp_read()) {
|
||||
case SIGUSR1:
|
||||
client_config.first_secs = 0; /* make secs field count from 0 */
|
||||
already_waited_sec = 0;
|
||||
@@ -1419,7 +1418,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
/* Is it a packet? */
|
||||
if (listen_mode == LISTEN_NONE || !pfds[1].revents)
|
||||
if (!pfds[1].revents)
|
||||
continue; /* no */
|
||||
|
||||
{
|
||||
|
||||
@@ -1576,13 +1576,12 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* yah, I know, *you* say it would never happen */
|
||||
timeout = INT_MAX;
|
||||
continue; /* back to main loop */
|
||||
} /* if select timed out */
|
||||
} /* if poll timed out */
|
||||
|
||||
/* select() didn't timeout, something happened */
|
||||
/* poll() didn't timeout, something happened */
|
||||
|
||||
/* Is it a signal? */
|
||||
/* note: udhcp_sp_read checks poll result before reading */
|
||||
switch (udhcp_sp_read(pfds)) {
|
||||
switch (udhcp_sp_read()) {
|
||||
case SIGUSR1:
|
||||
client_config.first_secs = 0; /* make secs field count from 0 */
|
||||
already_waited_sec = 0;
|
||||
@@ -1617,7 +1616,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
/* Is it a packet? */
|
||||
if (listen_mode == LISTEN_NONE || !pfds[1].revents)
|
||||
if (!pfds[1].revents)
|
||||
continue; /* no */
|
||||
|
||||
{
|
||||
|
||||
+34
-17
@@ -853,6 +853,9 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Would rather not do read_config before daemonization -
|
||||
* otherwise NOMMU machines will parse config twice */
|
||||
read_config(argv[0] ? argv[0] : DHCPD_CONF_FILE);
|
||||
/* prevent poll timeout overflow */
|
||||
if (server_config.auto_time > INT_MAX / 1000)
|
||||
server_config.auto_time = INT_MAX / 1000;
|
||||
|
||||
/* Make sure fd 0,1,2 are open */
|
||||
bb_sanitize_stdio();
|
||||
@@ -914,21 +917,31 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
udhcp_sp_fd_set(pfds, server_socket);
|
||||
tv = timeout_end - monotonic_sec();
|
||||
retval = 0;
|
||||
if (!server_config.auto_time || tv > 0) {
|
||||
retval = poll(pfds, 2, server_config.auto_time ? tv * 1000 : -1);
|
||||
}
|
||||
if (retval == 0) {
|
||||
write_leases();
|
||||
goto continue_with_autotime;
|
||||
}
|
||||
if (retval < 0 && errno != EINTR) {
|
||||
log1("error on select");
|
||||
continue;
|
||||
|
||||
new_tv:
|
||||
tv = -1;
|
||||
if (server_config.auto_time) {
|
||||
tv = timeout_end - monotonic_sec();
|
||||
if (tv <= 0) {
|
||||
write_leases:
|
||||
write_leases();
|
||||
goto continue_with_autotime;
|
||||
}
|
||||
tv *= 1000;
|
||||
}
|
||||
|
||||
switch (udhcp_sp_read(pfds)) {
|
||||
/* Block here waiting for either signal or packet */
|
||||
retval = poll(pfds, 2, tv);
|
||||
if (retval <= 0) {
|
||||
if (retval == 0)
|
||||
goto write_leases;
|
||||
if (errno == EINTR)
|
||||
goto new_tv;
|
||||
/* < 0 and not EINTR: should not happen */
|
||||
bb_perror_msg_and_die("poll");
|
||||
}
|
||||
|
||||
if (pfds[0].revents) switch (udhcp_sp_read()) {
|
||||
case SIGUSR1:
|
||||
bb_error_msg("received %s", "SIGUSR1");
|
||||
write_leases();
|
||||
@@ -938,12 +951,16 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_error_msg("received %s", "SIGTERM");
|
||||
write_leases();
|
||||
goto ret0;
|
||||
case 0: /* no signal: read a packet */
|
||||
break;
|
||||
default: /* signal or error (probably EINTR): back to select */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Is it a packet? */
|
||||
if (!pfds[1].revents)
|
||||
continue; /* no */
|
||||
|
||||
/* Note: we do not block here, we block on poll() instead.
|
||||
* Blocking here would prevent SIGTERM from working:
|
||||
* socket read inside this call is restarted on caught signals.
|
||||
*/
|
||||
bytes = udhcp_recv_kernel_packet(&packet, server_socket);
|
||||
if (bytes < 0) {
|
||||
/* bytes can also be -2 ("bad packet data") */
|
||||
|
||||
@@ -40,6 +40,7 @@ void FAST_FUNC udhcp_sp_setup(void)
|
||||
xpiped_pair(signal_pipe);
|
||||
close_on_exec_on(signal_pipe.rd);
|
||||
close_on_exec_on(signal_pipe.wr);
|
||||
ndelay_on(signal_pipe.rd);
|
||||
ndelay_on(signal_pipe.wr);
|
||||
bb_signals(0
|
||||
+ (1 << SIGUSR1)
|
||||
@@ -61,20 +62,20 @@ void FAST_FUNC udhcp_sp_fd_set(struct pollfd pfds[2], int extra_fd)
|
||||
pfds[1].fd = extra_fd;
|
||||
pfds[1].events = POLLIN;
|
||||
}
|
||||
/* this simplifies "is extra_fd ready?" tests elsewhere: */
|
||||
pfds[1].revents = 0;
|
||||
}
|
||||
|
||||
/* Read a signal from the signal pipe. Returns 0 if there is
|
||||
* no signal, -1 on error (and sets errno appropriately), and
|
||||
* your signal on success */
|
||||
int FAST_FUNC udhcp_sp_read(struct pollfd pfds[2])
|
||||
int FAST_FUNC udhcp_sp_read(void)
|
||||
{
|
||||
unsigned char sig;
|
||||
|
||||
if (!pfds[0].revents)
|
||||
return 0;
|
||||
|
||||
/* Can't block here, fd is in nonblocking mode */
|
||||
if (safe_read(signal_pipe.rd, &sig, 1) != 1)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
return sig;
|
||||
}
|
||||
+13
-6
@@ -140,15 +140,22 @@ log message, you can use a pattern like this instead
|
||||
//usage:#define svlogd_full_usage "\n\n"
|
||||
//usage: "Read log data from stdin and write to rotated log files in DIRs"
|
||||
//usage: "\n"
|
||||
//usage: "\n""-r C Replace non-printable characters with C"
|
||||
//usage: "\n""-R CHARS Also replace CHARS with C (default _)"
|
||||
//usage: "\n""-t Timestamp with @tai64n"
|
||||
//usage: "\n""-tt Timestamp with yyyy-mm-dd_hh:mm:ss.sssss"
|
||||
//usage: "\n""-ttt Timestamp with yyyy-mm-ddThh:mm:ss.sssss"
|
||||
//usage: "\n""-v Verbose"
|
||||
//usage: "\n"
|
||||
//usage: "\n""DIR/config file modifies behavior:"
|
||||
//usage: "\n""sSIZE - when to rotate logs"
|
||||
//usage: "\n""sSIZE - when to rotate logs (default 1000000, 0 disables)"
|
||||
//usage: "\n""nNUM - number of files to retain"
|
||||
/*usage: "\n""NNUM - min number files to retain" - confusing */
|
||||
/*usage: "\n""tSEC - rotate file if it get SEC seconds old" - confusing */
|
||||
///////: "\n""NNUM - min number files to retain" - confusing
|
||||
///////: "\n""tSEC - rotate file if it get SEC seconds old" - confusing
|
||||
//usage: "\n""!PROG - process rotated log with PROG"
|
||||
/*usage: "\n""uIPADDR - send log over UDP" - unsupported */
|
||||
/*usage: "\n""UIPADDR - send log over UDP and DONT log" - unsupported */
|
||||
/*usage: "\n""pPFX - prefix each line with PFX" - unsupported */
|
||||
///////: "\n""uIPADDR - send log over UDP" - unsupported
|
||||
///////: "\n""UIPADDR - send log over UDP and DONT log" - unsupported
|
||||
///////: "\n""pPFX - prefix each line with PFX" - unsupported
|
||||
//usage: "\n""+,-PATTERN - (de)select line for logging"
|
||||
//usage: "\n""E,ePATTERN - (de)select line for stderr"
|
||||
|
||||
|
||||
+1
-1
@@ -10858,7 +10858,7 @@ shiftcmd(int argc UNUSED_PARAM, char **argv)
|
||||
if (argv[1])
|
||||
n = number(argv[1]);
|
||||
if (n > shellparam.nparam)
|
||||
n = 0; /* bash compat, was = shellparam.nparam; */
|
||||
return 1;
|
||||
INT_OFF;
|
||||
shellparam.nparam -= n;
|
||||
for (ap1 = shellparam.p; --n >= 0; ap1++) {
|
||||
|
||||
+5
-5
@@ -279,7 +279,7 @@ optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_BZ2
|
||||
testing "tar does not extract into symlinks" "\
|
||||
>>/tmp/passwd && uudecode -o input && tar xf input 2>&1 && rm passwd; cat /tmp/passwd; echo \$?
|
||||
" "\
|
||||
tar: skipping unsafe symlink to '/tmp/passwd' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
|
||||
tar: can't create symlink 'passwd' to '/tmp/passwd'
|
||||
0
|
||||
" \
|
||||
"" "\
|
||||
@@ -299,7 +299,7 @@ optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_BZ2
|
||||
testing "tar -k does not extract into symlinks" "\
|
||||
>>/tmp/passwd && uudecode -o input && tar xf input -k 2>&1 && rm passwd; cat /tmp/passwd; echo \$?
|
||||
" "\
|
||||
tar: skipping unsafe symlink to '/tmp/passwd' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
|
||||
tar: can't create symlink 'passwd' to '/tmp/passwd'
|
||||
0
|
||||
" \
|
||||
"" "\
|
||||
@@ -324,11 +324,11 @@ rm -rf etc usr
|
||||
' "\
|
||||
etc/ssl/certs/3b2716e5.0
|
||||
etc/ssl/certs/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem
|
||||
tar: skipping unsafe symlink to '/usr/share/ca-certificates/mozilla/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.crt' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
|
||||
etc/ssl/certs/f80cc7f6.0
|
||||
usr/share/ca-certificates/mozilla/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.crt
|
||||
0
|
||||
etc/ssl/certs/3b2716e5.0 -> EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem
|
||||
etc/ssl/certs/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem -> /usr/share/ca-certificates/mozilla/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.crt
|
||||
etc/ssl/certs/f80cc7f6.0 -> EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem
|
||||
" \
|
||||
"" ""
|
||||
@@ -346,9 +346,9 @@ ls symlink/bb_test_evilfile
|
||||
' "\
|
||||
anything.txt
|
||||
symlink
|
||||
tar: skipping unsafe symlink to '/tmp' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
|
||||
symlink/bb_test_evilfile
|
||||
0
|
||||
tar: can't create symlink 'symlink' to '/tmp'
|
||||
1
|
||||
ls: /tmp/bb_test_evilfile: No such file or directory
|
||||
ls: bb_test_evilfile: No such file or directory
|
||||
symlink/bb_test_evilfile
|
||||
|
||||
+2
-2
@@ -81,8 +81,8 @@ static struct mntent *getmntent_r(FILE* stream, struct mntent* result,
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ignored: -v -t -i */
|
||||
#define OPTION_STRING "fldnra" "vt:i"
|
||||
/* ignored: -c -v -t -i */
|
||||
#define OPTION_STRING "fldnra" "cvt:i"
|
||||
#define OPT_FORCE (1 << 0) // Same as MNT_FORCE
|
||||
#define OPT_LAZY (1 << 1) // Same as MNT_DETACH
|
||||
#define OPT_FREELOOP (1 << 2)
|
||||
|
||||
Reference in new issue
Block a user