Permalink
Browse files

master branch update

  • Loading branch information...
Botao Sun
Botao Sun committed Sep 19, 2011
1 parent 823a70d commit a755ddfc9d15506d167f2a925b8b0c8de3fe274a
View
@@ -0,0 +1,33 @@
+--blank-lines-after-declarations
+--blank-lines-after-procedures
+--break-before-boolean-operator
+--no-blank-lines-after-commas
+--braces-on-if-line
+--braces-on-struct-decl-line
+--comment-indentation25
+--declaration-comment-column25
+--no-comment-delimiters-on-blank-lines
+--cuddle-else
+--continuation-indentation4
+--case-indentation0
+--else-endif-column33
+--space-after-cast
+--line-comments-indentation0
+--declaration-indentation1
+--dont-format-first-column-comments
+--dont-format-comments
+--honour-newlines
+--indent-level4
+/* changed from 0 to 4 */
+--parameter-indentation4
+--line-length78 /* changed from 75 */
+--continue-at-parentheses
+--no-space-after-function-call-names
+--dont-break-procedure-type
+--dont-star-comments
+--leave-optional-blank-lines
+--dont-space-special-semicolon
+--tab-size4
+/* additions by Mark */
+--case-brace-indentation0
+--leave-preprocessor-space
View
@@ -80,8 +80,15 @@ int main(int argc, char **argv)
printf("#define NUM_APPLETS %u\n", NUM_APPLETS);
if (NUM_APPLETS == 1) {
+ char *dash_to_underscore, *p;
printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
- printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].name);
+ /* Example: "ether-wake" -> "ether_wake" */
+ p = dash_to_underscore = strdup(applets[0].name);
+ p--;
+ while (*++p)
+ if (*p == '-')
+ *p = '_';
+ printf("#define SINGLE_APPLET_MAIN %s_main\n", dash_to_underscore);
}
printf("\n");
View
@@ -203,7 +203,7 @@ int tail_main(int argc, char **argv)
int fd = fds[i];
if (ENABLE_FEATURE_FANCY_TAIL && fd < 0)
- continue; /* may happen with -E */
+ continue; /* may happen with -F */
if (nfiles > header_threshhold) {
tail_xprint_header(fmt, argv[i]);
@@ -252,14 +252,14 @@ int tail_main(int argc, char **argv)
* Used only by +N code ("start from Nth", 1-based): */
seen = 1;
newlines_seen = 0;
- while ((nread = tail_read(fd, buf, tailbufsize-taillen)) > 0) {
+ while ((nread = tail_read(fd, buf, tailbufsize - taillen)) > 0) {
if (G.from_top) {
int nwrite = nread;
if (seen < count) {
/* We need to skip a few more bytes/lines */
if (COUNT_BYTES) {
nwrite -= (count - seen);
- seen = count;
+ seen += nread;
} else {
char *s = buf;
do {
View
@@ -51,19 +51,25 @@ device nodes if your system needs something more than the default root/root
660 permissions.
The file has the format:
- <device regex> <uid>:<gid> <permissions>
- or @<maj[,min1[-min2]]> <uid>:<gid> <permissions>
+ [-]<device regex> <uid>:<gid> <permissions>
+or
+ @<maj[,min1[-min2]]> <uid>:<gid> <permissions>
+or
+ $envvar=<regex> <uid>:<gid> <permissions>
For example:
- hd[a-z][0-9]* 0:3 660
+ hd[a-z][0-9]* 0:3 660
The config file parsing stops at the first matching line. If no line is
matched, then the default of 0:0 660 is used. To set your own default, simply
create your own total match like so:
+
.* 1:1 777
You can rename/move device nodes by using the next optional field.
+
<device regex> <uid>:<gid> <permissions> [=path]
+
So if you want to place the device node into a subdirectory, make sure the path
has a trailing /. If you want to rename the device node, just place the name.
hda 0:3 660 =drives/
View
@@ -239,7 +239,6 @@ IF_MAKEMIME(APPLET(makemime, BB_DIR_BIN, BB_SUID_DROP))
IF_MAN(APPLET(man, BB_DIR_SBIN, BB_SUID_DROP))
IF_MATCHPATHCON(APPLET(matchpathcon, BB_DIR_USR_SBIN, BB_SUID_DROP))
IF_MD5SUM(APPLET_NOEXEC(md5sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, md5sum))
-IF_MDEV(APPLET(mdev, BB_DIR_SBIN, BB_SUID_DROP))
IF_MICROCOM(APPLET(microcom, BB_DIR_USR_BIN, BB_SUID_DROP))
IF_MKDIR(APPLET_NOFORK(mkdir, mkdir, BB_DIR_BIN, BB_SUID_DROP, mkdir))
IF_MKFS_VFAT(APPLET_ODDNAME(mkdosfs, mkfs_vfat, BB_DIR_SBIN, BB_SUID_DROP, mkfs_vfat))
View
@@ -57,10 +57,13 @@ void FAST_FUNC launch_helper(const char **argv)
G.helper_pid = xvfork();
i = (!G.helper_pid) * 2; // for parent:0, for child:2
- close(pipes[i + 1]); // 1 or 3 - closing one write end
- close(pipes[2 - i]); // 2 or 0 - closing one read end
- xmove_fd(pipes[i], STDIN_FILENO); // 0 or 2 - using other read end
- xmove_fd(pipes[3 - i], STDOUT_FILENO); // 3 or 1 - other write end
+ close(pipes[i + 1]); // 1 or 3 - closing one write end
+ close(pipes[2 - i]); // 2 or 0 - closing one read end
+ xmove_fd(pipes[i], STDIN_FILENO); // 0 or 2 - using other read end
+ xmove_fd(pipes[3 - i], STDOUT_FILENO); // 3 or 1 - using other write end
+ // End result:
+ // parent stdout [3] -> child stdin [2]
+ // child stdout [1] -> parent stdin [0]
if (!G.helper_pid) {
// child: try to execute connection helper
View
@@ -26,18 +26,18 @@
//usage: "\n Examples:"
//usage: "\n -H 'exec openssl s_client -quiet -tls1 -starttls smtp"
//usage: "\n -connect smtp.gmail.com:25' <email.txt"
-//usage: "\n [4<username_and_passwd.txt | -au<username> -ap<password>]"
+//usage: "\n [4<username_and_passwd.txt | -auUSER -apPASS]"
//usage: "\n -H 'exec openssl s_client -quiet -tls1"
//usage: "\n -connect smtp.gmail.com:465' <email.txt"
-//usage: "\n [4<username_and_passwd.txt | -au<username> -ap<password>]"
+//usage: "\n [4<username_and_passwd.txt | -auUSER -apPASS]"
//usage: "\n -S HOST[:PORT] Server"
-//usage: "\n -au<username> Username for AUTH LOGIN"
-//usage: "\n -ap<password> Password for AUTH LOGIN"
-//usage: "\n -am<method> Authentication method. Ignored. LOGIN is implied"
+//usage: "\n -auUSER Username for AUTH LOGIN"
+//usage: "\n -apPASS Password for AUTH LOGIN"
+////usage: "\n -amMETHOD Authentication method. Ignored. LOGIN is implied"
//usage: "\n"
//usage: "\nOther options are silently ignored; -oi -t is implied"
//usage: IF_MAKEMIME(
-//usage: "\nUse makemime applet to create message with attachments"
+//usage: "\nUse makemime to create emails with attachments"
//usage: )
#include "libbb.h"
@@ -66,7 +66,7 @@ static int smtp_checkp(const char *fmt, const char *param, int code)
// if not equal -> die saying msg
while ((answer = xmalloc_fgetline(stdin)) != NULL) {
if (verbose)
- bb_error_msg("recv:'%.*s' %d", (int)(strchrnul(answer, '\r') - answer), answer, verbose);
+ bb_error_msg("recv:'%.*s'", (int)(strchrnul(answer, '\r') - answer), answer);
if (strlen(answer) <= 3 || '-' != answer[3])
break;
free(answer);
@@ -75,10 +75,11 @@ static int smtp_checkp(const char *fmt, const char *param, int code)
int n = atoi(answer);
if (timeout)
alarm(0);
- free(msg);
free(answer);
- if (-1 == code || n == code)
+ if (-1 == code || n == code) {
+ free(msg);
return n;
+ }
}
bb_error_msg_and_die("%s failed", msg);
}
@@ -176,11 +177,35 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
const char *args[] = { "sh", "-c", opt_connect, NULL };
// plug it in
launch_helper(args);
- // vanilla connection
+ // Now:
+ // our stdout will go to helper's stdin,
+ // helper's stdout will be available on our stdin.
+
+ // Wait for initial server message.
+ // If helper (such as openssl) invokes STARTTLS, the initial 220
+ // is swallowed by helper (and not repeated after TLS is initiated).
+ // We will send NOOP cmd to server and check the response.
+ // We should get 220+250 on plain connection, 250 on STARTTLSed session.
+ //
+ // The problem here is some servers delay initial 220 message,
+ // and consider client to be a spammer if it starts sending cmds
+ // before 220 reached it. The code below is unsafe in this regard:
+ // in non-STARTTLSed case, we potentially send NOOP before 220
+ // is sent by server.
+ // Ideas? (--delay SECS opt? --assume-starttls-helper opt?)
+ code = smtp_check("NOOP", -1);
+ if (code == 220)
+ // we got 220 - this is not STARTTLSed connection,
+ // eat 250 response to our NOOP
+ smtp_check(NULL, 250);
+ else
+ if (code != 250)
+ bb_error_msg_and_die("SMTP init failed");
} else {
+ // vanilla connection
int fd;
// host[:port] not explicitly specified? -> use $SMTPHOST
- // no $SMTPHOST ? -> use localhost
+ // no $SMTPHOST? -> use localhost
if (!(opts & OPT_S)) {
opt_connect = getenv("SMTPHOST");
if (!opt_connect)
@@ -191,25 +216,14 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
// and make ourselves a simple IO filter
xmove_fd(fd, STDIN_FILENO);
xdup2(STDIN_FILENO, STDOUT_FILENO);
- }
- // N.B. from now we know nothing about network :)
- // wait for initial server OK
- // N.B. if we used openssl the initial 220 answer is already swallowed during openssl TLS init procedure
- // so we need to kick the server to see whether we are ok
- code = smtp_check("NOOP", -1);
- // 220 on plain connection, 250 on openssl-helped TLS session
- if (220 == code)
- smtp_check(NULL, 250); // reread the code to stay in sync
- else if (250 != code)
- bb_error_msg_and_die("INIT failed");
+ // Wait for initial server 220 message
+ smtp_check(NULL, 220);
+ }
// we should start with modern EHLO
- if (250 != smtp_checkp("EHLO %s", domain, -1)) {
+ if (250 != smtp_checkp("EHLO %s", domain, -1))
smtp_checkp("HELO %s", domain, 250);
- }
- if (ENABLE_FEATURE_CLEAN_UP)
- free(domain);
// perform authentication
if (opts & OPT_a) {
@@ -224,7 +238,7 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
}
// set sender
- // N.B. we have here a very loosely defined algotythm
+ // N.B. we have here a very loosely defined algorythm
// since sendmail historically offers no means to specify secrets on cmdline.
// 1) server can require no authentication ->
// we must just provide a (possibly fake) reply address.
@@ -241,8 +255,6 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
// G.user = xuid2uname(getuid());
// opt_from = xasprintf("%s@%s", G.user, domain);
//}
- //if (ENABLE_FEATURE_CLEAN_UP)
- // free(domain);
smtp_checkp("MAIL FROM:<%s>", opt_from, 250);
// process message
@@ -272,26 +284,26 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
if (0 == strncasecmp("To:", s, 3) || 0 == strncasecmp("Bcc:" + 1, s, 3)) {
rcptto(sane_address(s+3));
goto addheader;
+ }
// Bcc: header adds blind copy (hidden) recipient
- } else if (0 == strncasecmp("Bcc:", s, 4)) {
+ if (0 == strncasecmp("Bcc:", s, 4)) {
rcptto(sane_address(s+4));
free(s);
// N.B. Bcc: vanishes from headers!
-
- // other headers go verbatim
-
- // N.B. RFC2822 2.2.3 "Long Header Fields" allows for headers to occupy several lines.
- // Continuation is denoted by prefixing additional lines with whitespace(s).
- // Thanks (stefan.seyfried at googlemail.com) for pointing this out.
- } else if (strchr(s, ':') || (list && skip_whitespace(s) != s)) {
+ } else
+ if (strchr(s, ':') || (list && skip_whitespace(s) != s)) {
+ // other headers go verbatim
+ // N.B. RFC2822 2.2.3 "Long Header Fields" allows for headers to occupy several lines.
+ // Continuation is denoted by prefixing additional lines with whitespace(s).
+ // Thanks (stefan.seyfried at googlemail.com) for pointing this out.
addheader:
// N.B. we allow MAX_HEADERS generic headers at most to prevent attacks
if (MAX_HEADERS && ++nheaders >= MAX_HEADERS)
goto bail;
llist_add_to_end(&list, s);
- // a line without ":" (an empty line too, by definition) doesn't look like a valid header
- // so stop "analyze headers" mode
} else {
+ // a line without ":" (an empty line too, by definition) doesn't look like a valid header
+ // so stop "analyze headers" mode
reenter:
// put recipients specified on cmdline
while (*argv) {
View
@@ -405,19 +405,17 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_e)
edir(env_dir);
- // FIXME: chrooted jail must have /etc/passwd if we move this after chroot!
- // OTOH chroot fails for non-roots!
- // SOLUTION: cache uid/gid before chroot, apply uid/gid after
+ if (opt & (OPT_u|OPT_U))
+ xget_uidgid(&ugid, set_user);
+
+ // chrooted jail must have /etc/passwd if we move this after chroot.
+ // OTOH chroot fails for non-roots.
+ // Solution: cache uid/gid before chroot, apply uid/gid after.
if (opt & OPT_U) {
- xget_uidgid(&ugid, env_user);
xsetenv("GID", utoa(ugid.gid));
xsetenv("UID", utoa(ugid.uid));
}
- if (opt & OPT_u) {
- xget_uidgid(&ugid, set_user);
- }
-
if (opt & OPT_root) {
xchdir(root);
xchroot(".");
View
@@ -278,7 +278,7 @@ static void parse_syslogdcfg(const char *file)
parser_t *parser;
parser = config_open2(file ? file : "/etc/syslog.conf",
- file ? xfopen_for_read : fopen_or_warn_stdin);
+ file ? xfopen_for_read : fopen_for_read);
if (!parser)
/* didn't find default /etc/syslog.conf */
/* proceed as if we built busybox without config support */
@@ -678,7 +678,7 @@ static void timestamp_and_log(int pri, char *msg, int len)
if (LOG_PRI(pri) < G.logLevel) {
#if ENABLE_FEATURE_IPC_SYSLOG
if ((option_mask32 & OPT_circularlog) && G.shbuf) {
- log_to_shmem(msg);
+ log_to_shmem(G.printbuf);
return;
}
#endif
View
@@ -14,4 +14,12 @@ testing "tail: +N with N > file length" \
"0\n" \
"" "qw"
+testing "tail: -c +N with largish N" \
+ "
+ dd if=/dev/zero bs=16k count=1 2>/dev/null | tail -c +8200 | wc -c;
+ dd if=/dev/zero bs=16k count=1 2>/dev/null | tail -c +8208 | wc -c;
+ " \
+ "8185\n8177\n" \
+ "" ""
+
exit $FAILCOUNT
Oops, something went wrong.

0 comments on commit a755ddf

Please sign in to comment.