Compare commits
2
Commits
master
...
1_23_stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be947c4d97 | ||
|
|
1ecfe811fe |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 23
|
||||
SUBLEVEL = 0
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
|
||||
+5
-7
@@ -542,9 +542,6 @@ static void cookmode(void); // return to "cooked" mode on tty
|
||||
static int mysleep(int);
|
||||
static int readit(void); // read (maybe cursor) key from stdin
|
||||
static int get_one_char(void); // read 1 char from stdin
|
||||
#if !ENABLE_FEATURE_VI_READONLY
|
||||
#define file_insert(fn, p, update_ro_status) file_insert(fn, p)
|
||||
#endif
|
||||
// file_insert might reallocate text[]!
|
||||
static int file_insert(const char *, char *, int);
|
||||
static int file_write(char *, char *, char *);
|
||||
@@ -1325,7 +1322,7 @@ static void colon(char *buf)
|
||||
q = next_line(q);
|
||||
{ // dance around potentially-reallocated text[]
|
||||
uintptr_t ofs = q - text;
|
||||
size = file_insert(fn, q, /*update_ro:*/ 0);
|
||||
size = file_insert(fn, q, 0);
|
||||
q = text + ofs;
|
||||
}
|
||||
if (size < 0)
|
||||
@@ -2905,7 +2902,7 @@ static char *get_input_line(const char *prompt)
|
||||
}
|
||||
|
||||
// might reallocate text[]!
|
||||
static int file_insert(const char *fn, char *p, int update_ro_status)
|
||||
static int file_insert(const char *fn, char *p, int initial)
|
||||
{
|
||||
int cnt = -1;
|
||||
int fd, size;
|
||||
@@ -2918,7 +2915,8 @@ static int file_insert(const char *fn, char *p, int update_ro_status)
|
||||
|
||||
fd = open(fn, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
status_line_bold_errno(fn);
|
||||
if (!initial)
|
||||
status_line_bold_errno(fn);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@@ -2946,7 +2944,7 @@ static int file_insert(const char *fn, char *p, int update_ro_status)
|
||||
close(fd);
|
||||
|
||||
#if ENABLE_FEATURE_VI_READONLY
|
||||
if (update_ro_status
|
||||
if (initial
|
||||
&& ((access(fn, W_OK) < 0) ||
|
||||
/* root will always have access()
|
||||
* so we check fileperms too */
|
||||
|
||||
+27
-30
@@ -196,14 +196,6 @@ struct op {
|
||||
};
|
||||
|
||||
static const struct op operators[] = {
|
||||
{"+", add},
|
||||
{"add", add},
|
||||
{"-", sub},
|
||||
{"sub", sub},
|
||||
{"*", mul},
|
||||
{"mul", mul},
|
||||
{"/", divide},
|
||||
{"div", divide},
|
||||
#if ENABLE_FEATURE_DC_LIBM
|
||||
{"**", power},
|
||||
{"exp", power},
|
||||
@@ -216,28 +208,47 @@ static const struct op operators[] = {
|
||||
{"not", not},
|
||||
{"eor", eor},
|
||||
{"xor", eor},
|
||||
{"+", add},
|
||||
{"add", add},
|
||||
{"-", sub},
|
||||
{"sub", sub},
|
||||
{"*", mul},
|
||||
{"mul", mul},
|
||||
{"/", divide},
|
||||
{"div", divide},
|
||||
{"p", print_no_pop},
|
||||
{"f", print_stack_no_pop},
|
||||
{"o", set_output_base},
|
||||
};
|
||||
|
||||
/* Feed the stack machine */
|
||||
static void stack_machine(const char *argument)
|
||||
{
|
||||
char *end;
|
||||
double d;
|
||||
double number;
|
||||
const struct op *o;
|
||||
|
||||
d = strtod(argument, &end);
|
||||
if (end != argument && *end == '\0') {
|
||||
push(d);
|
||||
return;
|
||||
next:
|
||||
number = strtod(argument, &end);
|
||||
if (end != argument) {
|
||||
argument = end;
|
||||
push(number);
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* We might have matched a digit, eventually advance the argument */
|
||||
argument = skip_whitespace(argument);
|
||||
|
||||
if (*argument == '\0')
|
||||
return;
|
||||
|
||||
o = operators;
|
||||
do {
|
||||
if (strcmp(o->name, argument) == 0) {
|
||||
const size_t name_len = strlen(o->name);
|
||||
if (strncmp(o->name, argument, name_len) == 0) {
|
||||
argument += name_len;
|
||||
o->function();
|
||||
return;
|
||||
goto next;
|
||||
}
|
||||
o++;
|
||||
} while (o != operators + ARRAY_SIZE(operators));
|
||||
@@ -254,25 +265,11 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (!argv[0]) {
|
||||
/* take stuff from stdin if no args are given */
|
||||
char *line;
|
||||
char *cursor;
|
||||
char *token;
|
||||
while ((line = xmalloc_fgetline(stdin)) != NULL) {
|
||||
cursor = line;
|
||||
while (1) {
|
||||
token = skip_whitespace(cursor);
|
||||
if (*token == '\0')
|
||||
break;
|
||||
cursor = skip_non_whitespace(token);
|
||||
if (*cursor != '\0')
|
||||
*cursor++ = '\0';
|
||||
stack_machine(token);
|
||||
}
|
||||
stack_machine(line);
|
||||
free(line);
|
||||
}
|
||||
} else {
|
||||
// why? it breaks "dc -2 2 + p"
|
||||
//if (argv[0][0] == '-')
|
||||
// bb_show_usage();
|
||||
do {
|
||||
stack_machine(*argv);
|
||||
} while (*++argv);
|
||||
|
||||
+13
-7
@@ -51,7 +51,11 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
|
||||
|
||||
info->dnext = info->dprev = info;
|
||||
info->name = xstrdup(fname + 2); /* skip "./" */
|
||||
info->modname = xstrdup(filename2modname(fname, modname));
|
||||
info->modname = xstrdup(
|
||||
filename2modname(
|
||||
bb_get_last_path_component_nostrip(fname),
|
||||
modname
|
||||
));
|
||||
for (ptr = image; ptr < image + len - 10; ptr++) {
|
||||
if (strncmp(ptr, "depends=", 8) == 0) {
|
||||
char *u;
|
||||
@@ -242,17 +246,18 @@ int depmod_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (!(option_mask32 & OPT_n))
|
||||
xfreopen_write("modules.alias", stdout);
|
||||
for (m = modules; m != NULL; m = m->next) {
|
||||
char modname[MODULE_NAME_LEN];
|
||||
const char *fname = bb_basename(m->name);
|
||||
int fnlen = strchrnul(fname, '.') - fname;
|
||||
filename2modname(fname, modname);
|
||||
while (m->aliases) {
|
||||
/* Last word can well be m->modname instead,
|
||||
* but depmod from module-init-tools 3.4
|
||||
* uses module basename, i.e., no s/-/_/g.
|
||||
* (pathname and .ko.* are still stripped)
|
||||
* Mimicking that... */
|
||||
printf("alias %s %.*s\n",
|
||||
printf("alias %s %s\n",
|
||||
(char*)llist_pop(&m->aliases),
|
||||
fnlen, fname);
|
||||
modname);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -260,12 +265,13 @@ int depmod_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (!(option_mask32 & OPT_n))
|
||||
xfreopen_write("modules.symbols", stdout);
|
||||
for (m = modules; m != NULL; m = m->next) {
|
||||
char modname[MODULE_NAME_LEN];
|
||||
const char *fname = bb_basename(m->name);
|
||||
int fnlen = strchrnul(fname, '.') - fname;
|
||||
filename2modname(fname, modname);
|
||||
while (m->symbols) {
|
||||
printf("alias symbol:%s %.*s\n",
|
||||
printf("alias symbol:%s %s\n",
|
||||
(char*)llist_pop(&m->symbols),
|
||||
fnlen, fname);
|
||||
modname);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (colon == NULL)
|
||||
continue;
|
||||
*colon = '\0';
|
||||
filename2modname(tokens[0], name);
|
||||
filename2modname(bb_basename(tokens[0]), name);
|
||||
for (i = 0; argv[i]; i++) {
|
||||
if (fnmatch(argv[i], name, 0) == 0) {
|
||||
modinfo(tokens[0], uts.release, &env);
|
||||
|
||||
+56
-40
@@ -149,9 +149,13 @@ static void replace(char *s, char what, char with)
|
||||
static char *filename2modname(const char *filename, char *modname)
|
||||
{
|
||||
int i;
|
||||
char *from;
|
||||
const char *from;
|
||||
|
||||
from = bb_get_last_path_component_nostrip(filename);
|
||||
// Disabled since otherwise "modprobe dir/name" would work
|
||||
// as if it is "modprobe name". It is unclear why
|
||||
// 'basenamization' was here in the first place.
|
||||
//from = bb_get_last_path_component_nostrip(filename);
|
||||
from = filename;
|
||||
for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++)
|
||||
modname[i] = (from[i] == '-') ? '_' : from[i];
|
||||
modname[i] = '\0';
|
||||
@@ -548,9 +552,23 @@ static int already_loaded(const char *name)
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
#define already_loaded(name) is_rmmod
|
||||
#define already_loaded(name) 0
|
||||
#endif
|
||||
|
||||
static int rmmod(const char *filename)
|
||||
{
|
||||
int r;
|
||||
char modname[MODULE_NAME_LEN];
|
||||
|
||||
filename2modname(filename, modname);
|
||||
r = delete_module(modname, O_NONBLOCK | O_EXCL);
|
||||
dbg1_error_msg("delete_module('%s', O_NONBLOCK | O_EXCL):%d", modname, r);
|
||||
if (r != 0 && !(option_mask32 & OPT_q)) {
|
||||
bb_perror_msg("remove '%s'", modname);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* Given modules definition and module name (or alias, or symbol)
|
||||
* load/remove the module respecting dependencies.
|
||||
@@ -567,26 +585,36 @@ static void process_module(char *name, const char *cmdline_options)
|
||||
module_info **infovec;
|
||||
module_info *info;
|
||||
int infoidx;
|
||||
int is_rmmod = (option_mask32 & OPT_r) != 0;
|
||||
int is_remove = (option_mask32 & OPT_r) != 0;
|
||||
|
||||
dbg1_error_msg("process_module('%s','%s')", name, cmdline_options);
|
||||
|
||||
replace(name, '-', '_');
|
||||
|
||||
dbg1_error_msg("already_loaded:%d is_rmmod:%d", already_loaded(name), is_rmmod);
|
||||
dbg1_error_msg("already_loaded:%d is_remove:%d", already_loaded(name), is_remove);
|
||||
|
||||
if (applet_name[0] == 'r') {
|
||||
/* rmmod.
|
||||
* Does not remove dependencies, no need to scan, just remove.
|
||||
* (compat note: this allows and strips .ko suffix)
|
||||
*/
|
||||
rmmod(name);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* We used to have "is_rmmod != already_loaded(name)" check here, but
|
||||
* We used to have "is_remove != already_loaded(name)" check here, but
|
||||
* modprobe -r pci:v00008086d00007010sv00000000sd00000000bc01sc01i80
|
||||
* won't unload modules (there are more than one)
|
||||
* which have this alias.
|
||||
*/
|
||||
if (!is_rmmod && already_loaded(name)) {
|
||||
if (!is_remove && already_loaded(name)) {
|
||||
dbg1_error_msg("nothing to do for '%s'", name);
|
||||
return;
|
||||
}
|
||||
|
||||
options = NULL;
|
||||
if (!is_rmmod) {
|
||||
if (!is_remove) {
|
||||
char *opt_filename = xasprintf("/etc/modules/%s", name);
|
||||
options = xmalloc_open_read_close(opt_filename, NULL);
|
||||
if (options)
|
||||
@@ -620,7 +648,7 @@ static void process_module(char *name, const char *cmdline_options)
|
||||
0 /* depth */
|
||||
);
|
||||
dbg1_error_msg("dirscan complete");
|
||||
/* Module was not found, or load failed, or is_rmmod */
|
||||
/* Module was not found, or load failed, or is_remove */
|
||||
if (module_found_idx >= 0) { /* module was found */
|
||||
infovec = xzalloc(2 * sizeof(infovec[0]));
|
||||
infovec[0] = &modinfo[module_found_idx];
|
||||
@@ -631,6 +659,14 @@ static void process_module(char *name, const char *cmdline_options)
|
||||
infovec = find_alias(name);
|
||||
}
|
||||
|
||||
if (!infovec) {
|
||||
/* both dirscan and find_alias found nothing */
|
||||
if (!is_remove && applet_name[0] != 'd') /* it wasn't rmmod or depmod */
|
||||
bb_error_msg("module '%s' not found", name);
|
||||
//TODO: _and_die()? or should we continue (un)loading modules listed on cmdline?
|
||||
goto ret;
|
||||
}
|
||||
|
||||
/* There can be more than one module for the given alias. For example,
|
||||
* "pci:v00008086d00007010sv00000000sd00000000bc01sc01i80" matches
|
||||
* ata_piix because it has alias "pci:v00008086d00007010sv*sd*bc*sc*i*"
|
||||
@@ -639,28 +675,15 @@ static void process_module(char *name, const char *cmdline_options)
|
||||
* a *list* of modinfo pointers from find_alias().
|
||||
*/
|
||||
|
||||
/* rmmod or modprobe -r? unload module(s) */
|
||||
if (is_rmmod) {
|
||||
/* modprobe -r? unload module(s) */
|
||||
if (is_remove) {
|
||||
infoidx = 0;
|
||||
while ((info = infovec[infoidx++]) != NULL) {
|
||||
int r;
|
||||
char modname[MODULE_NAME_LEN];
|
||||
|
||||
filename2modname(info->pathname, modname);
|
||||
r = delete_module(modname, O_NONBLOCK | O_EXCL);
|
||||
dbg1_error_msg("delete_module('%s', O_NONBLOCK | O_EXCL):%d", modname, r);
|
||||
int r = rmmod(bb_get_last_path_component_nostrip(info->pathname));
|
||||
if (r != 0) {
|
||||
if (!(option_mask32 & OPT_q))
|
||||
bb_perror_msg("remove '%s'", modname);
|
||||
goto ret;
|
||||
goto ret; /* error */
|
||||
}
|
||||
}
|
||||
|
||||
if (applet_name[0] == 'r') {
|
||||
/* rmmod: do not remove dependencies, exit */
|
||||
goto ret;
|
||||
}
|
||||
|
||||
/* modprobe -r: we do not stop here -
|
||||
* continue to unload modules on which the module depends:
|
||||
* "-r --remove: option causes modprobe to remove a module.
|
||||
@@ -669,14 +692,6 @@ static void process_module(char *name, const char *cmdline_options)
|
||||
*/
|
||||
}
|
||||
|
||||
if (!infovec) {
|
||||
/* both dirscan and find_alias found nothing */
|
||||
if (!is_rmmod && applet_name[0] != 'd') /* it wasn't rmmod or depmod */
|
||||
bb_error_msg("module '%s' not found", name);
|
||||
//TODO: _and_die()? or should we continue (un)loading modules listed on cmdline?
|
||||
goto ret;
|
||||
}
|
||||
|
||||
infoidx = 0;
|
||||
while ((info = infovec[infoidx++]) != NULL) {
|
||||
/* Iterate thru dependencies, trying to (un)load them */
|
||||
@@ -689,7 +704,7 @@ static void process_module(char *name, const char *cmdline_options)
|
||||
}
|
||||
free(deps);
|
||||
|
||||
if (is_rmmod)
|
||||
if (is_remove)
|
||||
continue;
|
||||
|
||||
/* We are modprobe: load it */
|
||||
@@ -892,10 +907,10 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE
|
||||
/* If not rmmod, parse possible module options given on command line.
|
||||
/* If not rmmod/-r, parse possible module options given on command line.
|
||||
* insmod/modprobe takes one module name, the rest are parameters. */
|
||||
options = NULL;
|
||||
if ('r' != applet0) {
|
||||
if (!(option_mask32 & OPT_r)) {
|
||||
char **arg = argv;
|
||||
while (*++arg) {
|
||||
/* Enclose options in quotes */
|
||||
@@ -906,7 +921,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
}
|
||||
#else
|
||||
if ('r' != applet0)
|
||||
if (!(option_mask32 & OPT_r))
|
||||
argv[1] = NULL;
|
||||
#endif
|
||||
|
||||
@@ -930,10 +945,11 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
/* Try to load modprobe.dep.bb */
|
||||
load_dep_bb();
|
||||
if ('r' != applet0) /* not rmmod */
|
||||
load_dep_bb();
|
||||
|
||||
/* Load/remove modules.
|
||||
* Only rmmod loops here, modprobe has only argv[0] */
|
||||
* Only rmmod/modprobe -r loops here, insmod/modprobe has only argv[0] */
|
||||
do {
|
||||
process_module(*argv, options);
|
||||
} while (*++argv);
|
||||
|
||||
+14
-17
@@ -229,26 +229,20 @@ static ALWAYS_INLINE struct module_entry *get_or_add_modentry(const char *module
|
||||
{
|
||||
return helper_get_module(module, 1);
|
||||
}
|
||||
static ALWAYS_INLINE struct module_entry *get_modentry(const char *module)
|
||||
/* So far this function always gets a module pathname, never an alias name.
|
||||
* The crucial difference is that pathname needs dirname stripping,
|
||||
* while alias name must NOT do it!
|
||||
* Testcase where dirname stripping is likely to go wrong: "modprobe devname:snd/timer"
|
||||
*/
|
||||
static ALWAYS_INLINE struct module_entry *get_modentry(const char *pathname)
|
||||
{
|
||||
return helper_get_module(module, 0);
|
||||
return helper_get_module(bb_get_last_path_component_nostrip(pathname), 0);
|
||||
}
|
||||
|
||||
static void add_probe(const char *name)
|
||||
{
|
||||
struct module_entry *m;
|
||||
|
||||
/*
|
||||
* get_or_add_modentry() strips path from name and works
|
||||
* on remaining basename.
|
||||
* This would make "rmmod dir/name" and "modprobe dir/name"
|
||||
* to work like "rmmod name" and "modprobe name",
|
||||
* which is wrong, and can be abused via implicit modprobing:
|
||||
* "ifconfig /usbserial up" tries to modprobe netdev-/usbserial.
|
||||
*/
|
||||
if (strchr(name, '/'))
|
||||
bb_error_msg_and_die("malformed module name '%s'", name);
|
||||
|
||||
m = get_or_add_modentry(name);
|
||||
if (!(option_mask32 & (OPT_REMOVE | OPT_SHOW_DEPS))
|
||||
&& (m->flags & MODULE_FLAG_LOADED)
|
||||
@@ -428,7 +422,7 @@ static int do_modprobe(struct module_entry *m)
|
||||
|
||||
rc = 0;
|
||||
fn = llist_pop(&m->deps); /* we leak it */
|
||||
m2 = get_or_add_modentry(fn);
|
||||
m2 = get_or_add_modentry(bb_get_last_path_component_nostrip(fn));
|
||||
|
||||
if (option_mask32 & OPT_REMOVE) {
|
||||
/* modprobe -r */
|
||||
@@ -510,7 +504,7 @@ static void load_modules_dep(void)
|
||||
colon = last_char_is(tokens[0], ':');
|
||||
if (colon == NULL)
|
||||
continue;
|
||||
*colon = 0;
|
||||
*colon = '\0';
|
||||
|
||||
m = get_modentry(tokens[0]);
|
||||
if (m == NULL)
|
||||
@@ -557,7 +551,6 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
if (opt & OPT_LIST_ONLY) {
|
||||
int i;
|
||||
char name[MODULE_NAME_LEN];
|
||||
char *colon, *tokens[2];
|
||||
parser_t *p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read);
|
||||
|
||||
@@ -569,10 +562,14 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (!colon)
|
||||
continue;
|
||||
*colon = '\0';
|
||||
filename2modname(tokens[0], name);
|
||||
if (!argv[0])
|
||||
puts(tokens[0]);
|
||||
else {
|
||||
char name[MODULE_NAME_LEN];
|
||||
filename2modname(
|
||||
bb_get_last_path_component_nostrip(tokens[0]),
|
||||
name
|
||||
);
|
||||
for (i = 0; argv[i]; i++) {
|
||||
if (fnmatch(argv[i], name, 0) == 0) {
|
||||
puts(tokens[0]);
|
||||
|
||||
+6
-2
@@ -48,13 +48,17 @@ int FAST_FUNC string_to_llist(char *string, llist_t **llist, const char *delim)
|
||||
char* FAST_FUNC filename2modname(const char *filename, char *modname)
|
||||
{
|
||||
int i;
|
||||
char *from;
|
||||
const char *from;
|
||||
|
||||
if (filename == NULL)
|
||||
return NULL;
|
||||
if (modname == NULL)
|
||||
modname = xmalloc(MODULE_NAME_LEN);
|
||||
from = bb_get_last_path_component_nostrip(filename);
|
||||
// Disabled since otherwise "modprobe dir/name" would work
|
||||
// as if it is "modprobe name". It is unclear why
|
||||
// 'basenamization' was here in the first place.
|
||||
//from = bb_get_last_path_component_nostrip(filename);
|
||||
from = filename;
|
||||
for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++)
|
||||
modname[i] = (from[i] == '-') ? '_' : from[i];
|
||||
modname[i] = '\0';
|
||||
|
||||
+7
-2
@@ -1174,8 +1174,13 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
//umask(077); - admin can set umask before starting us
|
||||
|
||||
/* Signals. We'll always take -EPIPE rather than a rude signal, thanks */
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
/* Signals */
|
||||
bb_signals(0
|
||||
/* We'll always take EPIPE rather than a rude signal, thanks */
|
||||
+ (1 << SIGPIPE)
|
||||
/* LIST command spawns chilren. Prevent zombies */
|
||||
+ (1 << SIGCHLD)
|
||||
, SIG_IGN);
|
||||
|
||||
/* Set up options on the command socket (do we need these all? why?) */
|
||||
setsockopt(STDIN_FILENO, IPPROTO_TCP, TCP_NODELAY, &const_int_1, sizeof(const_int_1));
|
||||
|
||||
+78
-20
@@ -38,8 +38,14 @@
|
||||
|
||||
#if 0
|
||||
# define log_io(...) bb_error_msg(__VA_ARGS__)
|
||||
# define SENDFMT(fp, fmt, ...) \
|
||||
do { \
|
||||
log_io("> " fmt, ##__VA_ARGS__); \
|
||||
fprintf(fp, fmt, ##__VA_ARGS__); \
|
||||
} while (0);
|
||||
#else
|
||||
# define log_io(...) ((void)0)
|
||||
# define SENDFMT(fp, fmt, ...) fprintf(fp, fmt, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -55,6 +61,36 @@ static const char P_FTP[] = "ftp";
|
||||
static const char P_HTTP[] = "http";
|
||||
static const char P_HTTPS[] = "https";
|
||||
|
||||
#if ENABLE_FEATURE_WGET_LONG_OPTIONS
|
||||
/* User-specified headers prevent using our corresponding built-in headers. */
|
||||
enum {
|
||||
HDR_HOST = (1<<0),
|
||||
HDR_USER_AGENT = (1<<1),
|
||||
HDR_RANGE = (1<<2),
|
||||
HDR_AUTH = (1<<3) * ENABLE_FEATURE_WGET_AUTHENTICATION,
|
||||
HDR_PROXY_AUTH = (1<<4) * ENABLE_FEATURE_WGET_AUTHENTICATION,
|
||||
};
|
||||
static const char wget_user_headers[] ALIGN1 =
|
||||
"Host:\0"
|
||||
"User-Agent:\0"
|
||||
"Range:\0"
|
||||
# if ENABLE_FEATURE_WGET_AUTHENTICATION
|
||||
"Authorization:\0"
|
||||
"Proxy-Authorization:\0"
|
||||
# endif
|
||||
;
|
||||
# define USR_HEADER_HOST (G.user_headers & HDR_HOST)
|
||||
# define USR_HEADER_USER_AGENT (G.user_headers & HDR_USER_AGENT)
|
||||
# define USR_HEADER_RANGE (G.user_headers & HDR_RANGE)
|
||||
# define USR_HEADER_AUTH (G.user_headers & HDR_AUTH)
|
||||
# define USR_HEADER_PROXY_AUTH (G.user_headers & HDR_PROXY_AUTH)
|
||||
#else /* No long options, no user-headers :( */
|
||||
# define USR_HEADER_HOST 0
|
||||
# define USR_HEADER_USER_AGENT 0
|
||||
# define USR_HEADER_RANGE 0
|
||||
# define USR_HEADER_AUTH 0
|
||||
# define USR_HEADER_PROXY_AUTH 0
|
||||
#endif
|
||||
|
||||
/* Globals */
|
||||
struct globals {
|
||||
@@ -69,6 +105,7 @@ struct globals {
|
||||
#if ENABLE_FEATURE_WGET_LONG_OPTIONS
|
||||
char *post_data;
|
||||
char *extra_headers;
|
||||
unsigned char user_headers; /* Headers mentioned by the user */
|
||||
#endif
|
||||
char *fname_out; /* where to direct output (-O) */
|
||||
const char *proxy_flag; /* Use proxies if env vars are set */
|
||||
@@ -830,43 +867,46 @@ static void download_one_url(const char *url)
|
||||
#endif
|
||||
/* Send HTTP request */
|
||||
if (use_proxy) {
|
||||
fprintf(sfp, "GET %s://%s/%s HTTP/1.1\r\n",
|
||||
SENDFMT(sfp, "GET %s://%s/%s HTTP/1.1\r\n",
|
||||
target.protocol, target.host,
|
||||
target.path);
|
||||
} else {
|
||||
fprintf(sfp, "%s /%s HTTP/1.1\r\n",
|
||||
SENDFMT(sfp, "%s /%s HTTP/1.1\r\n",
|
||||
(option_mask32 & WGET_OPT_POST_DATA) ? "POST" : "GET",
|
||||
target.path);
|
||||
}
|
||||
|
||||
fprintf(sfp, "Host: %s\r\nUser-Agent: %s\r\n",
|
||||
target.host, G.user_agent);
|
||||
if (!USR_HEADER_HOST)
|
||||
SENDFMT(sfp, "Host: %s\r\n", target.host);
|
||||
if (!USR_HEADER_USER_AGENT)
|
||||
SENDFMT(sfp, "User-Agent: %s\r\n", G.user_agent);
|
||||
|
||||
/* Ask server to close the connection as soon as we are done
|
||||
* (IOW: we do not intend to send more requests)
|
||||
*/
|
||||
fprintf(sfp, "Connection: close\r\n");
|
||||
SENDFMT(sfp, "Connection: close\r\n");
|
||||
|
||||
#if ENABLE_FEATURE_WGET_AUTHENTICATION
|
||||
if (target.user) {
|
||||
fprintf(sfp, "Proxy-Authorization: Basic %s\r\n"+6,
|
||||
if (target.user && !USR_HEADER_AUTH) {
|
||||
SENDFMT(sfp, "Proxy-Authorization: Basic %s\r\n"+6,
|
||||
base64enc(target.user));
|
||||
}
|
||||
if (use_proxy && server.user) {
|
||||
fprintf(sfp, "Proxy-Authorization: Basic %s\r\n",
|
||||
if (use_proxy && server.user && !USR_HEADER_PROXY_AUTH) {
|
||||
SENDFMT(sfp, "Proxy-Authorization: Basic %s\r\n",
|
||||
base64enc(server.user));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (G.beg_range != 0)
|
||||
fprintf(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range);
|
||||
if (G.beg_range != 0 && !USR_HEADER_RANGE)
|
||||
SENDFMT(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range);
|
||||
|
||||
#if ENABLE_FEATURE_WGET_LONG_OPTIONS
|
||||
if (G.extra_headers)
|
||||
if (G.extra_headers) {
|
||||
log_io(G.extra_headers);
|
||||
fputs(G.extra_headers, sfp);
|
||||
}
|
||||
|
||||
if (option_mask32 & WGET_OPT_POST_DATA) {
|
||||
fprintf(sfp,
|
||||
SENDFMT(sfp,
|
||||
"Content-Type: application/x-www-form-urlencoded\r\n"
|
||||
"Content-Length: %u\r\n"
|
||||
"\r\n"
|
||||
@@ -876,7 +916,7 @@ static void download_one_url(const char *url)
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
fprintf(sfp, "\r\n");
|
||||
SENDFMT(sfp, "\r\n");
|
||||
}
|
||||
|
||||
fflush(sfp);
|
||||
@@ -1093,7 +1133,9 @@ int wget_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_WGET_LONG_OPTIONS
|
||||
applet_long_options = wget_longopts;
|
||||
#endif
|
||||
opt_complementary = "-1" IF_FEATURE_WGET_TIMEOUT(":T+") IF_FEATURE_WGET_LONG_OPTIONS(":\xfe::");
|
||||
opt_complementary = "-1"
|
||||
IF_FEATURE_WGET_TIMEOUT(":T+")
|
||||
IF_FEATURE_WGET_LONG_OPTIONS(":\xfe::");
|
||||
getopt32(argv, "csqO:P:Y:U:T:" /*ignored:*/ "t:",
|
||||
&G.fname_out, &G.dir_prefix,
|
||||
&G.proxy_flag, &G.user_agent,
|
||||
@@ -1106,16 +1148,32 @@ int wget_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
#if ENABLE_FEATURE_WGET_LONG_OPTIONS
|
||||
if (headers_llist) {
|
||||
int size = 1;
|
||||
char *cp;
|
||||
int size = 0;
|
||||
char *hdr;
|
||||
llist_t *ll = headers_llist;
|
||||
while (ll) {
|
||||
size += strlen(ll->data) + 2;
|
||||
ll = ll->link;
|
||||
}
|
||||
G.extra_headers = cp = xmalloc(size);
|
||||
G.extra_headers = hdr = xmalloc(size + 1);
|
||||
while (headers_llist) {
|
||||
cp += sprintf(cp, "%s\r\n", (char*)llist_pop(&headers_llist));
|
||||
int bit;
|
||||
const char *words;
|
||||
|
||||
size = sprintf(hdr, "%s\r\n",
|
||||
(char*)llist_pop(&headers_llist));
|
||||
/* a bit like index_in_substrings but don't match full key */
|
||||
bit = 1;
|
||||
words = wget_user_headers;
|
||||
while (*words) {
|
||||
if (strstr(hdr, words) == hdr) {
|
||||
G.user_headers |= bit;
|
||||
break;
|
||||
}
|
||||
bit <<= 1;
|
||||
words += strlen(words) + 1;
|
||||
}
|
||||
hdr += size;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
+9
-9
@@ -6746,6 +6746,14 @@ varvalue(char *name, int varflags, int flags, struct strlist *var_str_list)
|
||||
len = strlen(p);
|
||||
if (!(subtype == VSPLUS || subtype == VSLENGTH))
|
||||
memtodest(p, len, syntax, quotes);
|
||||
#if ENABLE_UNICODE_SUPPORT
|
||||
if (subtype == VSLENGTH && len > 0) {
|
||||
reinit_unicode_for_ash();
|
||||
if (unicode_status == UNICODE_ON) {
|
||||
len = unicode_strlen(p);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -6829,15 +6837,7 @@ evalvar(char *p, int flags, struct strlist *var_str_list)
|
||||
varunset(p, var, 0, 0);
|
||||
|
||||
if (subtype == VSLENGTH) {
|
||||
ssize_t n = varlen;
|
||||
if (n > 0) {
|
||||
reinit_unicode_for_ash();
|
||||
if (unicode_status == UNICODE_ON) {
|
||||
const char *val = lookupvar(var);
|
||||
n = unicode_strlen(val);
|
||||
}
|
||||
}
|
||||
cvtnum(n > 0 ? n : 0);
|
||||
cvtnum(varlen > 0 ? varlen : 0);
|
||||
goto record;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user