From: Rob Landley Date: Sat, 13 Aug 2005 00:26:01 +0000 (-0000) Subject: 1.0 backports of: X-Git-Tag: 1_01~12 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=fc455b2101edbf97331384831de2989ce9cdb731;p=oweals%2Fbusybox.git 1.0 backports of: 10861, 10875, 10881, 10888 ash fix 10865 suid thing? (look at this) 10886 telnet bugfix 10866 ftp fix for RFC 959 compliance. 10867 Remove spurious newline from cp -i prompt. 10874 ksyslogd fix 10876 msh fix 10877 httpd fix 10880, 10889, 11005 dhcp fixes --- diff --git a/busybox/include/applets.h b/busybox/include/applets.h index 21f82f57d..d89500e77 100644 --- a/busybox/include/applets.h +++ b/busybox/include/applets.h @@ -672,7 +672,7 @@ #endif #if !defined(PROTOTYPES) && !defined(MAKE_USAGE) - { 0,NULL,0 } + { 0,NULL,0,0 } }; #endif diff --git a/busybox/include/usage.h b/busybox/include/usage.h index ad4410196..b58c57275 100644 --- a/busybox/include/usage.h +++ b/busybox/include/usage.h @@ -2610,9 +2610,10 @@ "/dev/tty2\n" #define udhcpc_trivial_usage \ - "[-fbnqv] [-c CLIENTID] [-H HOSTNAME] [-i INTERFACE]\n[-p pidfile] [-r IP] [-s script]" + "[-Cfbnqv] [-c CLIENTID] [-H HOSTNAME] [-i INTERFACE]\n[-p pidfile] [-r IP] [-s script]" #define udhcpc_full_usage \ - "\t-c,\t--clientid=CLIENTID\tClient identifier\n" \ + "\t-c,\t--clientid=CLIENTID\tSet client identifier\n" \ + "\t-C,\t--clientid-none\tSuppress default client identifier\n" \ "\t-H,\t--hostname=HOSTNAME\tClient hostname\n" \ "\t-h,\t \tAlias for -H\n" \ "\t-f,\t--foreground\tDo not fork after getting lease\n" \ diff --git a/busybox/libbb/copy_file.c b/busybox/libbb/copy_file.c index 4b349b7fc..f5fecaf73 100644 --- a/busybox/libbb/copy_file.c +++ b/busybox/libbb/copy_file.c @@ -146,7 +146,7 @@ int copy_file(const char *source, const char *dest, int flags) if (dest_exists) { if (flags & FILEUTILS_INTERACTIVE) { - bb_error_msg("overwrite `%s'? ", dest); + fprintf(stderr, "%s: overwrite `%s'? ", bb_applet_name, dest); if (!bb_ask_confirmation()) { close (src_fd); return 0; diff --git a/busybox/networking/ftpgetput.c b/busybox/networking/ftpgetput.c index f6bd82bc8..02c21d9e1 100644 --- a/busybox/networking/ftpgetput.c +++ b/busybox/networking/ftpgetput.c @@ -65,9 +65,9 @@ static int ftpcmd(const char *s1, const char *s2, FILE *stream, char *buf) if (s1) { if (s2) { - fprintf(stream, "%s%s\n", s1, s2); + fprintf(stream, "%s%s\r\n", s1, s2); } else { - fprintf(stream, "%s\n", s1); + fprintf(stream, "%s\r\n", s1); } } do { diff --git a/busybox/networking/httpd.c b/busybox/networking/httpd.c index 94fcfc8c1..e3f4027dc 100644 --- a/busybox/networking/httpd.c +++ b/busybox/networking/httpd.c @@ -1259,6 +1259,8 @@ static int sendCgi(const char *url, post_readed_idx += count; if(post_readed_size == 0) post_readed_idx = 0; + } else { + post_readed_size = post_readed_idx = bodyLen = 0; /* broken pipe to CGI */ } } else if(bodyLen > 0 && post_readed_size == 0 && FD_ISSET(a_c_r, &readSet)) { count = bodyLen > sizeof(wbuf) ? sizeof(wbuf) : bodyLen; @@ -1266,7 +1268,7 @@ static int sendCgi(const char *url, if(count > 0) { post_readed_size += count; bodyLen -= count; - } else { + } else { bodyLen = 0; /* closed */ } } diff --git a/busybox/networking/telnet.c b/busybox/networking/telnet.c index 6ad7712ab..24160057b 100644 --- a/busybox/networking/telnet.c +++ b/busybox/networking/telnet.c @@ -96,6 +96,7 @@ static struct Globalvars { byte charmode; byte telflags; byte gotsig; + byte do_termios; /* buffer to handle telnet negotiations */ char iacbuf[IACBUFSIZE]; short iaclen; /* could even use byte */ @@ -616,12 +617,12 @@ static void fgotsig(int sig) static void rawmode(void) { - tcsetattr(0, TCSADRAIN, &G.termios_raw); + if (G.do_termios) tcsetattr(0, TCSADRAIN, &G.termios_raw); } static void cookmode(void) { - tcsetattr(0, TCSADRAIN, &G.termios_def); + if (G.do_termios) tcsetattr(0, TCSADRAIN, &G.termios_def); } extern int telnet_main(int argc, char** argv) @@ -649,11 +650,12 @@ extern int telnet_main(int argc, char** argv) memset(&G, 0, sizeof G); - if (tcgetattr(0, &G.termios_def) < 0) - exit(1); + if (tcgetattr(0, &G.termios_def) >= 0) { + G.do_termios = 1; - G.termios_raw = G.termios_def; - cfmakeraw(&G.termios_raw); + G.termios_raw = G.termios_def; + cfmakeraw(&G.termios_raw); + } if (argc < 2) bb_show_usage(); diff --git a/busybox/networking/udhcp/dhcpc.c b/busybox/networking/udhcp/dhcpc.c index 91af9153b..e89affe1f 100644 --- a/busybox/networking/udhcp/dhcpc.c +++ b/busybox/networking/udhcp/dhcpc.c @@ -76,7 +76,8 @@ static void __attribute__ ((noreturn)) show_usage(void) { printf( "Usage: udhcpc [OPTIONS]\n\n" -" -c, --clientid=CLIENTID Client identifier\n" +" -c, --clientid=CLIENTID Set client identifier\n" +" -C, --clientid-none Suppress default client identifier\n" " -H, --hostname=HOSTNAME Client hostname\n" " -h Alias for -H\n" " -f, --foreground Do not fork after getting lease\n" @@ -191,9 +192,11 @@ int main(int argc, char *argv[]) long now; int max_fd; int sig; + int no_clientid = 0; static const struct option arg_options[] = { {"clientid", required_argument, 0, 'c'}, + {"clientid-none", no_argument, 0, 'C'}, {"foreground", no_argument, 0, 'f'}, {"background", no_argument, 0, 'b'}, {"hostname", required_argument, 0, 'H'}, @@ -211,11 +214,12 @@ int main(int argc, char *argv[]) /* get options */ while (1) { int option_index = 0; - c = getopt_long(argc, argv, "c:fbH:h:i:np:qr:s:v", arg_options, &option_index); + c = getopt_long(argc, argv, "c:CfbH:h:i:np:qr:s:v", arg_options, &option_index); if (c == -1) break; switch (c) { case 'c': + if (no_clientid) show_usage(); len = strlen(optarg) > 255 ? 255 : strlen(optarg); if (client_config.clientid) free(client_config.clientid); client_config.clientid = xmalloc(len + 2); @@ -224,6 +228,10 @@ int main(int argc, char *argv[]) client_config.clientid[OPT_DATA] = '\0'; strncpy(client_config.clientid + OPT_DATA, optarg, len); break; + case 'C': + if (client_config.clientid) show_usage(); + no_clientid = 1; + break; case 'f': client_config.foreground = 1; break; @@ -273,7 +281,8 @@ int main(int argc, char *argv[]) NULL, client_config.arp) < 0) return 1; - if (!client_config.clientid) { + /* if not set, and not suppressed, setup the default client ID */ + if (!client_config.clientid && !no_clientid) { client_config.clientid = xmalloc(6 + 3); client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID; client_config.clientid[OPT_LEN] = 7; @@ -420,8 +429,10 @@ int main(int argc, char *argv[]) continue; } /* Ignore packets that aren't for us */ - if (memcmp(client_config.arp,packet.chaddr,6)) + if (memcmp(packet.chaddr, client_config.arp, 6)) { + DEBUG(LOG_INFO, "packet does not have our chaddr -- ignoring"); continue; + } if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring"); diff --git a/busybox/shell/ash.c b/busybox/shell/ash.c index d9ea2b0f3..f16edbc38 100644 --- a/busybox/shell/ash.c +++ b/busybox/shell/ash.c @@ -1353,6 +1353,7 @@ struct builtincmd { #define IS_BUILTIN_SPECIAL(builtincmd) ((builtincmd)->name[0] & 1) #define IS_BUILTIN_REGULAR(builtincmd) ((builtincmd)->name[0] & 2) +#define IS_BUILTIN_ASSIGN(builtincmd) ((builtincmd)->name[0] & 4) static const struct builtincmd builtincmd[] = { { BUILTIN_SPEC_REG ".", dotcmd }, @@ -3208,7 +3209,14 @@ parse_command_args(char **argv, const char **path) } #endif - +static inline int +isassignment(const char *p) +{ + const char *q = endofname(p); + if (p == q) + return 0; + return *q == '='; +} /* * Execute a simple command. @@ -3232,6 +3240,8 @@ evalcommand(union node *cmd, int flags) int cmd_is_exec; int status; char **nargv; + struct builtincmd *bcmd; + int pseudovarflag = 0; /* First expand the arguments. */ TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); @@ -3246,11 +3256,21 @@ evalcommand(union node *cmd, int flags) *arglist.lastp = NULL; argc = 0; + if (cmd->ncmd.args) + { + bcmd = find_builtin(cmd->ncmd.args->narg.text); + pseudovarflag = bcmd && IS_BUILTIN_ASSIGN(bcmd); + } + for (argp = cmd->ncmd.args; argp; argp = argp->narg.next) { struct strlist **spp; spp = arglist.lastp; - expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); + if (pseudovarflag && isassignment(argp->narg.text)) + expandarg(argp, &arglist, EXP_VARTILDE); + else + expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); + for (sp = *spp; sp; sp = sp->next) argc++; } @@ -9370,15 +9390,6 @@ static void setprompt(int); -static inline int -isassignment(const char *p) -{ - const char *q = endofname(p); - if (p == q) - return 0; - return *q == '='; -} - /* * Read and parse a command. Returns NEOF on end of file. (NULL is a @@ -12005,7 +12016,7 @@ setvar(const char *name, const char *val, int flags) INTOFF; p = mempcpy(nameeq = ckmalloc(namelen + vallen + 2), name, namelen); *p++ = '\0'; - if (vallen) { + if (val) { p[-1] = '='; p = mempcpy(p, val, vallen); } diff --git a/busybox/shell/cmdedit.c b/busybox/shell/cmdedit.c index 56b789ab6..3380dffe9 100644 --- a/busybox/shell/cmdedit.c +++ b/busybox/shell/cmdedit.c @@ -782,8 +782,8 @@ static int match_compare(const void *a, const void *b) #define QUOT (UCHAR_MAX+1) #define collapse_pos(is, in) { \ - memcpy(int_buf+(is), int_buf+(in), (BUFSIZ+1-(is)-(in))*sizeof(int)); \ - memcpy(pos_buf+(is), pos_buf+(in), (BUFSIZ+1-(is)-(in))*sizeof(int)); } + memmove(int_buf+(is), int_buf+(in), (BUFSIZ+1-(is)-(in))*sizeof(int)); \ + memmove(pos_buf+(is), pos_buf+(in), (BUFSIZ+1-(is)-(in))*sizeof(int)); } static int find_match(char *matchBuf, int *len_with_quotes) { diff --git a/busybox/shell/msh.c b/busybox/shell/msh.c index 2fb0df739..14e875854 100644 --- a/busybox/shell/msh.c +++ b/busybox/shell/msh.c @@ -4290,7 +4290,7 @@ int quoted; } var_name[var_index++] = *src++; - while (isalnum(*src)) + while (isalnum(*src) || *src=='_') var_name[var_index++] = *src++; var_name[var_index] = 0; diff --git a/busybox/sysklogd/syslogd.c b/busybox/sysklogd/syslogd.c index 8c6c44ee0..aecd35d58 100644 --- a/busybox/sysklogd/syslogd.c +++ b/busybox/sysklogd/syslogd.c @@ -441,7 +441,7 @@ static void logMessage(int pri, char *msg) /* if we have a valid socket, send the message */ if (-1 != remotefd) { now = 1; - snprintf(line, sizeof(line), "<%d> %s", pri, msg); + snprintf(line, sizeof(line), "<%d>%s", pri, msg); retry: /* send message to remote logger */