Re: [Toybox] [PATCH] macOS: move getmountlist.c functions into portability.c.

2018-12-05 Thread David Seikel
> What ever it is, this isn't the first mailman driven mailing list I'm
> having that problem with.  I wonder if there is a simple to use
> "convert base64 encoded ASCII emails to just plain damn ASCII emails"
> utility I can bolt onto my mail filtering pipeline and be done with
> it?

I logged onto the mailman options page, changed "Get MIME or Plain Text
Digests?" from "Plain Text" to "MIME", which the descriptive text
strongly implies it only changes how digests of bundled posts get sent,
not individual posts.  I don't have digests turned on.  Now I'm getting

Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

instead of 

Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64

But my email program still can't quote it.  Something odd at my end.

Still, progress.

-- 
A big old stinking pile of genius that no one wants
coz there are too many silver coated monkeys in the world.
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] macOS: move getmountlist.c functions into portability.c.

2018-12-05 Thread David Seikel
Given the subject of this port of the discussion, apologies for the
lack of attribution in the quotes below.

> > Though now I'm getting annoyed at mailman sending plain ASCII text
> > as base64 encoding.  My email proggy can't handle quoting that.  It
> > didn't used to.  
> 
> I wonder if that's related to me enabling the "header rewrite" option
> to avoid triggering gmail's spam filtering when a mail server has
> that funky sender verification thing that breaks mailing lists?

You would expect something called "header rewrite" would only rewrite
headers, not body, but mailman is proudly a GNU project.

What ever it is, this isn't the first mailman driven mailing list I'm
having that problem with.  I wonder if there is a simple to use
"convert base64 encoded ASCII emails to just plain damn ASCII emails"
utility I can bolt onto my mail filtering pipeline and be done with it?

Or pull my finger out on my "switch email clients" TODO item, and find
one that can cope?  It's gonna take time to evaluate the contenders.

> Apparently it's gotten so bad some open source projects are
> abandoning mailing lists:
> 
>   https://lwn.net/Articles/768483/

That was an interesting read.  I've long been of the opinion that
mailing lists, web forums, bug trackers, and even chat room software,
is all basically conversation based.  There could be a base
conversation system that all the above would just be UI front ends to.
Let each user choose which to use.

Especially bug trackers, users have a tendency to just make bug reports
and support requests with whatever they are using at the time, not the
actual official bug tracker.

-- 
A big old stinking pile of genius that no one wants
coz there are too many silver coated monkeys in the world.
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.

2018-12-05 Thread enh via Toybox
(sent. you can just run `./toybox mktemp -u
tmp.XXX` to see the effect.)
On Wed, Dec 5, 2018 at 5:27 PM enh  wrote:
>
> which seems to have found a bug in the password code?
>
> i'll send you that patch as a follow up to this one, and you can look at why 
> if mktemp reuses that code, long enough templates end in a string of '.'s...
>
> On Wed, Dec 5, 2018 at 4:08 PM enh  wrote:
>>
>> note that you've already got "random ascii" code in password.c --- i have a 
>> half-finished patch that switches mktemp over to reusing that instead...
>>
>> On Wed, Dec 5, 2018 at 3:40 PM Rob Landley  wrote:
>>>
>>> On 12/5/18 5:03 PM, enh via Toybox wrote:
>>> > Multiple bugs:
>>> >
>>> > * We weren't outputting anything in the case where we actually create a
>>> >   file or directory (but all the tests were for the -u case).
>>> >
>>> > * There are more gnarls to the behavior if TEMPLATE contains a '/'. The
>>> >   new tests cover these.
>>>
>>> Sigh. (See attached...)
>>>
>>> Lemme try to reconcile them...
>>>
>>> Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [PATCH] mktemp: yet more tests, and yet more fixes.

2018-12-05 Thread enh via Toybox
In particular this reuses the password.c code for random ASCII bytes.
---
 lib/lib.h |  1 +
 lib/password.c| 35 +--
 tests/mktemp.test |  6 ++
 toys/lsb/mktemp.c | 24 ++--
 4 files changed, 46 insertions(+), 20 deletions(-)

diff --git a/lib/lib.h b/lib/lib.h
index 14bb7cf6..d51bad4a 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -306,6 +306,7 @@ int pollinate(int in1, int in2, int out1, int
out2, int timeout, int shutdown_ti
 char *ntop(struct sockaddr *sa);

 // password.c
+void get_random_ascii(char *buf, int buflen);
 int get_salt(char *salt, char * algo);

 // commas.c
diff --git a/lib/password.c b/lib/password.c
index b9cc1346..e3598989 100644
--- a/lib/password.c
+++ b/lib/password.c
@@ -8,6 +8,26 @@
 #include "toys.h"
 #include 

+void get_random_ascii(char *buf, int buflen)
+{
+  int i;
+
+  // Read appropriate number of random bytes for salt
+  xgetrandom(libbuf, ((buflen*6)+7)/8, 0);
+
+  // Grab 6 bit chunks and convert to characters in ./0-9a-zA-Z
+  for (i=0; i> (bitpos&7)) & 0x3f;
+bits += 46;
+if (bits > 57) bits += 7;
+if (bits > 90) bits += 6;
+
+buf[i] = bits;
+  }
+}
+
 // generate ID prefix and random salt for given encryption algorithm.
 int get_salt(char *salt, char *algo)
 {
@@ -23,20 +43,7 @@ int get_salt(char *salt, char *algo)

   if (al[i].id) s += sprintf(s, "$%c$", '0'+al[i].id);

-  // Read appropriate number of random bytes for salt
-  xgetrandom(libbuf, ((len*6)+7)/8, 0);
-
-  // Grab 6 bit chunks and convert to characters in ./0-9a-zA-Z
-  for (i=0; i> (bitpos&7)) & 0x3f;
-bits += 46;
-if (bits > 57) bits += 7;
-if (bits > 90) bits += 6;
-
-s[i] = bits;
-  }
+  get_random_ascii(s, len);
   salt[len] = 0;

   return s-salt;
diff --git a/tests/mktemp.test b/tests/mktemp.test
index ee023d6b..0c235469 100755
--- a/tests/mktemp.test
+++ b/tests/mktemp.test
@@ -37,3 +37,9 @@ testing "-p DIR -t TEMPLATE but no TMPDIR" "TMPDIR=
mktemp -u -p DIR -t hello.XX

 # mktemp -u doesn't need to be able to write to the directory.
 testing "-u" "mktemp -u -p /proc | grep -q '^/proc/tmp\...$'
&& echo yes" "yes\n" "" ""
+
+# mktemp needs at least XX in the template.
+testing "bad template" "mktemp -u helloX || echo error" "error\n" "" ""
+
+# mktemp -q shouldn't print the path.
+testing "-q" "mktemp -p /proc -q || echo only-failure" "only-failure\n" "" ""
diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c
index 57d1d118..b9e144dc 100644
--- a/toys/lsb/mktemp.c
+++ b/toys/lsb/mktemp.c
@@ -37,6 +37,7 @@ void mktemp_main(void)
   int template_dir = template && !!strchr(template, '/');
   int flags_dir = (toys.optflags & (FLAG_p|FLAG_t));
   int use_dir = flags_dir && !template_dir;
+  char *s, *e;

   if (template_dir && flags_dir) error_exit("conflicting directories given");

@@ -61,12 +62,23 @@ void mktemp_main(void)
   // TODO: coreutils cleans paths, so -p /t/// would result in /t/xxx...
   template = use_dir ? xmprintf("%s/%s", TT.p, template) : xstrdup(template);

-  if (toys.optflags & FLAG_u) {
-template = mktemp(template);
-  } else if (toys.optflags & FLAG_d ? !mkdtemp(template) :
mkstemp(template) == -1) {
-if (toys.optflags & FLAG_q) toys.exitval = 1;
-else perror_exit("Failed to create %s %s/%s",
-toys.optflags & FLAG_d ? "directory" : "file", TT.p, template);
+  // Point `s` and `e` to the start and end of the last region of XXes.
+  s = e = strrchr(template, 'X');
+  if (!e || e == template || *(e-1) != 'X') error_exit("need XX in template");
+  while (s >= template && *(s-1) == 'X') --s;
+
+  while (1) {
+struct stat sb;
+
+get_random_ascii(s, (e-s+1));
+if ((FLAG(u) && lstat(template, ) == -1 && errno == ENOENT) ||
+(FLAG(d) && mkdir(template, 0700) != -1) ||
+(open(template, O_CREAT|O_CLOEXEC, 0500) != -1)) break;
+if (errno == EEXIST) continue;
+if (FLAG(q)) {
+  toys.exitval = 1;
+  return;
+} else perror_exit("%s", template);
   }
   xputs(template);

-- 
2.20.0.rc1.387.gf8505762e3-goog
From 7a7fffaf7835f52d0b9e2f25cb1beb4774ab0eb8 Mon Sep 17 00:00:00 2001
From: Elliott Hughes 
Date: Wed, 5 Dec 2018 17:30:14 -0800
Subject: [PATCH] mktemp: yet more tests, and yet more fixes.

In particular this reuses the password.c code for random ASCII bytes.
---
 lib/lib.h |  1 +
 lib/password.c| 35 +--
 tests/mktemp.test |  6 ++
 toys/lsb/mktemp.c | 24 ++--
 4 files changed, 46 insertions(+), 20 deletions(-)

diff --git a/lib/lib.h b/lib/lib.h
index 14bb7cf6..d51bad4a 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -306,6 +306,7 @@ int pollinate(int in1, int in2, int out1, int out2, int timeout, int shutdown_ti
 char *ntop(struct sockaddr *sa);
 
 // password.c
+void get_random_ascii(char *buf, int buflen);
 int get_salt(char *salt, char * algo);
 
 // commas.c
diff --git a/lib/password.c b/lib/password.c

Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.

2018-12-05 Thread enh via Toybox
which seems to have found a bug in the password code?

i'll send you that patch as a follow up to this one, and you can look at
why if mktemp reuses that code, long enough templates end in a string of
'.'s...

On Wed, Dec 5, 2018 at 4:08 PM enh  wrote:

> note that you've already got "random ascii" code in password.c --- i have
> a half-finished patch that switches mktemp over to reusing that instead...
>
> On Wed, Dec 5, 2018 at 3:40 PM Rob Landley  wrote:
>
>> On 12/5/18 5:03 PM, enh via Toybox wrote:
>> > Multiple bugs:
>> >
>> > * We weren't outputting anything in the case where we actually create a
>> >   file or directory (but all the tests were for the -u case).
>> >
>> > * There are more gnarls to the behavior if TEMPLATE contains a '/'. The
>> >   new tests cover these.
>>
>> Sigh. (See attached...)
>>
>> Lemme try to reconcile them...
>>
>> Rob
>>
>
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.

2018-12-05 Thread enh via Toybox
note that you've already got "random ascii" code in password.c --- i have a
half-finished patch that switches mktemp over to reusing that instead...

On Wed, Dec 5, 2018 at 3:40 PM Rob Landley  wrote:

> On 12/5/18 5:03 PM, enh via Toybox wrote:
> > Multiple bugs:
> >
> > * We weren't outputting anything in the case where we actually create a
> >   file or directory (but all the tests were for the -u case).
> >
> > * There are more gnarls to the behavior if TEMPLATE contains a '/'. The
> >   new tests cover these.
>
> Sigh. (See attached...)
>
> Lemme try to reconcile them...
>
> Rob
>
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] mktemp: fix the tests and the logic.

2018-12-05 Thread Rob Landley
On 12/5/18 5:03 PM, enh via Toybox wrote:
> Multiple bugs:
> 
> * We weren't outputting anything in the case where we actually create a
>   file or directory (but all the tests were for the -u case).
> 
> * There are more gnarls to the behavior if TEMPLATE contains a '/'. The
>   new tests cover these.

Sigh. (See attached...)

Lemme try to reconcile them...

Rob
diff --git a/lib/portability.c b/lib/portability.c
index a80ca56..5c754d7 100644
--- a/lib/portability.c
+++ b/lib/portability.c
@@ -30,18 +30,20 @@ pid_t xfork(void)
 }
 #endif
 
-void xgetrandom(void *buf, unsigned buflen, unsigned flags)
+int xgetrandom(void *buf, unsigned buflen, unsigned flags)
 {
   int fd;
 
 #if CFG_TOYBOX_GETRANDOM
-  if (buflen == getrandom(buf, buflen, flags)) return;
-  if (!CFG_TOYBOX_ON_ANDROID || errno!=ENOSYS) perror_exit("getrandom");
+  if (buflen == getrandom(buf, buflen, flags&~WARN_ONLY)) return 1;
+  if (errno!=ENOSYS && !(flags_ONLY)) perror_exit("getrandom");
 #endif
-
-  fd = xopen(flags ? "/dev/random" : "/dev/urandom", O_RDONLY);
+  fd = xopen(flags ? "/dev/random" : "/dev/urandom",O_RDONLY|(flags_ONLY));
+  if (fd == -1) return 0;
   xreadall(fd, buf, buflen);
   close(fd);
+
+  return 1;
 }
 
 #if defined(__APPLE__)
diff --git a/lib/portability.h b/lib/portability.h
index 21d0b8a..60d4049 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -266,7 +266,7 @@ extern CODE prioritynames[], facilitynames[];
 #if CFG_TOYBOX_GETRANDOM
 #include 
 #endif
-void xgetrandom(void *buf, unsigned len, unsigned flags);
+int xgetrandom(void *buf, unsigned len, unsigned flags);
 
 // Android's bionic libc doesn't have confstr.
 #ifdef __BIONIC__
diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c
index 112f84c..6d159d6 100644
--- a/toys/lsb/mktemp.c
+++ b/toys/lsb/mktemp.c
@@ -34,12 +34,9 @@ GLOBALS(
 void mktemp_main(void)
 {
   char *template = *toys.optargs;
-  int use_dir = (toys.optflags & (FLAG_p|FLAG_t));
+  int use_dir = (toys.optflags & (FLAG_p|FLAG_t)), len;
 
-  if (!template) {
-template = "tmp.XX";
-use_dir = 1;
-  }
+  if (!template) template = "tmp.XX";
 
   // Normally, the precedence is DIR (if set), $TMPDIR (if set), /tmp.
   // With -t it's $TMPDIR, DIR, /tmp.
@@ -48,17 +45,38 @@ void mktemp_main(void)
 
 if (toys.optflags & FLAG_t) {
   if (tmpdir && *tmpdir) TT.p = tmpdir;
-} else {
-  if (!TT.p || !*TT.p) TT.p = tmpdir;
-}
+} else if (!TT.p || !*TT.p) TT.p = tmpdir;
 if (!TT.p || !*TT.p) TT.p = "/tmp";
   }
 
   // TODO: coreutils cleans paths, so -p /t/// would result in /t/xxx...
   template = use_dir ? xmprintf("%s/%s", TT.p, template) : xstrdup(template);
+  len = strlen(template);
+  if (len<3 || strcmp(template+len-3, "XXX")) perror_exit("need XXX");
 
+  // In theory you just xputs(mktemp(template)) for -u, in practice there's
+  // link-time deprecation warnings if you do that. So we fake up our own:
   if (toys.optflags & FLAG_u) {
-xputs(mktemp(template));
+long long rr;
+char *s = template+len;
+
+// Fall back to random-ish if xgetrandom fails.
+if (!xgetrandom(, sizeof(rr), WARN_ONLY)) {
+  struct timespec ts;
+
+  clock_gettime(CLOCK_REALTIME, );
+  rr = ts.tv_nsec*65537+(long)template+getpid()+(long)
+}
+// Replace X with 64 chars from posix portable character set (all but "_").
+while (--s>template) {
+  if (*s != 'X') break;
+  *s = '-'+(rr&63);
+  if (*s>'.') ++*s;
+  if (*s>'9') (*s) += 7;
+  if (*s>'Z') (*s) += 6;
+  rr>>=6;
+}
+xputs(template);
   } else if (toys.optflags & FLAG_d ? !mkdtemp(template) : mkstemp(template) == -1) {
 if (toys.optflags & FLAG_q) toys.exitval = 1;
 else perror_exit("Failed to create %s %s/%s",
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [PATCH] mktemp: fix the tests and the logic.

2018-12-05 Thread enh via Toybox
Multiple bugs:

* We weren't outputting anything in the case where we actually create a
  file or directory (but all the tests were for the -u case).

* There are more gnarls to the behavior if TEMPLATE contains a '/'. The
  new tests cover these.

Additionally, I've realized that glibc's mktemp(3) doesn't seem to do
exactly what we want (it only seems to randomize 6 'X's), so we'll need
to implement our own mktemp(3) replacement anyway. I'll do that in a
separate patch, though, because folks are understandably upset that I
broke mktemp...
---
 tests/mktemp.test | 11 ++-
 toys/lsb/mktemp.c |  9 +++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/tests/mktemp.test b/tests/mktemp.test
index ee7702dc..ee023d6b 100755
--- a/tests/mktemp.test
+++ b/tests/mktemp.test
@@ -6,11 +6,20 @@

 # mktemp by default should use tmp.XX as the template,
 # and $TMPDIR as the directory.
-testing "default" "TMPDIR=/t mktemp -u | grep -q '^/t/tmp\...$' &&
echo yes" "yes\n" "" ""
+testing "default" "TMPDIR=. mktemp | grep -q '^./tmp\...$' && echo
yes" "yes\n" "" ""
+
+# Test that -d creates a directory and the default is a file.
+testing "dir" "test -d `TMPDIR=. mktemp -d` && echo yes" "yes\n" "" ""
+testing "file" "test -f `TMPDIR=. mktemp` && echo yes" "yes\n" "" ""

 # mktemp with a template should *not* use $TMPDIR.
 testing "TEMPLATE" "TMPDIR=/t mktemp -u hello. | grep -q
'^hello\.$' && echo yes" "yes\n" "" ""

+# mktemp with a template that includes a '/' should ignore $TMPDIR
+testing "/ TEMPLATE" "TMPDIR=/t mktemp -u /x/hello. | grep -q
'^/x/hello\.$' && echo yes" "yes\n" "" ""
+# ...and setting DIR is an error.
+testing "/ TEMPLATE -p DIR" "TMPDIR=/t mktemp -p DIR -u /x/hello.
|| echo error" "error\n" "" ""
+
 # mktemp with -t and a template should use $TMPDIR.
 testing "-t TEMPLATE" "TMPDIR=/t mktemp -u -t hello. | grep -q
'^/t/hello\.$' && echo yes" "yes\n" "" ""

diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c
index 112f84c4..57d1d118 100644
--- a/toys/lsb/mktemp.c
+++ b/toys/lsb/mktemp.c
@@ -34,7 +34,11 @@ GLOBALS(
 void mktemp_main(void)
 {
   char *template = *toys.optargs;
-  int use_dir = (toys.optflags & (FLAG_p|FLAG_t));
+  int template_dir = template && !!strchr(template, '/');
+  int flags_dir = (toys.optflags & (FLAG_p|FLAG_t));
+  int use_dir = flags_dir && !template_dir;
+
+  if (template_dir && flags_dir) error_exit("conflicting directories
given");

   if (!template) {
 template = "tmp.XX";
@@ -58,12 +62,13 @@ void mktemp_main(void)
   template = use_dir ? xmprintf("%s/%s", TT.p, template) :
xstrdup(template);

   if (toys.optflags & FLAG_u) {
-xputs(mktemp(template));
+template = mktemp(template);
   } else if (toys.optflags & FLAG_d ? !mkdtemp(template) :
mkstemp(template) == -1) {
 if (toys.optflags & FLAG_q) toys.exitval = 1;
 else perror_exit("Failed to create %s %s/%s",
 toys.optflags & FLAG_d ? "directory" : "file", TT.p, template);
   }
+  xputs(template);

   if (CFG_TOYBOX_FREE) free(template);
 }
-- 
2.20.0.rc1.387.gf8505762e3-goog
From 8996abae1662e30bb1307a4708b3803ecb9133c3 Mon Sep 17 00:00:00 2001
From: Elliott Hughes 
Date: Wed, 5 Dec 2018 14:57:42 -0800
Subject: [PATCH] mktemp: fix the tests and the logic.

Multiple bugs:

* We weren't outputting anything in the case where we actually create a
  file or directory (but all the tests were for the -u case).

* There are more gnarls to the behavior if TEMPLATE contains a '/'. The
  new tests cover these.

Additionally, I've realized that glibc's mktemp(3) doesn't seem to do
exactly what we want (it only seems to randomize 6 'X's), so we'll need
to implement our own mktemp(3) replacement anyway. I'll do that in a
separate patch, though, because folks are understandably upset that I
broke mktemp...
---
 tests/mktemp.test | 11 ++-
 toys/lsb/mktemp.c |  9 +++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/tests/mktemp.test b/tests/mktemp.test
index ee7702dc..ee023d6b 100755
--- a/tests/mktemp.test
+++ b/tests/mktemp.test
@@ -6,11 +6,20 @@
 
 # mktemp by default should use tmp.XX as the template,
 # and $TMPDIR as the directory.
-testing "default" "TMPDIR=/t mktemp -u | grep -q '^/t/tmp\...$' && echo yes" "yes\n" "" ""
+testing "default" "TMPDIR=. mktemp | grep -q '^./tmp\...$' && echo yes" "yes\n" "" ""
+
+# Test that -d creates a directory and the default is a file.
+testing "dir" "test -d `TMPDIR=. mktemp -d` && echo yes" "yes\n" "" ""
+testing "file" "test -f `TMPDIR=. mktemp` && echo yes" "yes\n" "" ""
 
 # mktemp with a template should *not* use $TMPDIR.
 testing "TEMPLATE" "TMPDIR=/t mktemp -u hello. | grep -q '^hello\.$' && echo yes" "yes\n" "" ""
 
+# mktemp with a template that includes a '/' should ignore $TMPDIR
+testing "/ TEMPLATE" "TMPDIR=/t mktemp -u /x/hello. | grep -q '^/x/hello\.$' && echo 

Re: [Toybox] [PATCH] mktemp: add -t and fix behavior.

2018-12-05 Thread enh via Toybox
On Wed, Dec 5, 2018 at 10:12 AM enh  wrote:
>
> On Wed, Dec 5, 2018 at 9:57 AM Rob Landley  wrote:
> >
> > On 12/5/18 9:56 AM, enh via Toybox wrote:
> > > Yes, that's what we've been talking about for days. Search for mktemp and 
> > > glibc.
> > >
> > > Bionic will warm you at compile time instead, and musl should be silent.
> >
> > He's not gonna be the last one to notice, though.
> >
> > Sigh, I may need to add a mktemp in portability.c...
>
> i don't think that's a good idea. we really _shouldn't_ be using
> mktemp(3) *except* to implement mktemp(1)'s -u --- just inlining
> "replace each X with a byte from getrandom" into mktemp(1) makes more
> sense.

(in an lstat(2) loop, that is. which does make me wonder what the
expected behavior of `mktemp -u` is if the directory also isn't
readable...)

>
> > Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] mktemp: add -t and fix behavior.

2018-12-05 Thread enh via Toybox
On Wed, Dec 5, 2018 at 9:57 AM Rob Landley  wrote:
>
> On 12/5/18 9:56 AM, enh via Toybox wrote:
> > Yes, that's what we've been talking about for days. Search for mktemp and 
> > glibc.
> >
> > Bionic will warm you at compile time instead, and musl should be silent.
>
> He's not gonna be the last one to notice, though.
>
> Sigh, I may need to add a mktemp in portability.c...

i don't think that's a good idea. we really _shouldn't_ be using
mktemp(3) *except* to implement mktemp(1)'s -u --- just inlining
"replace each X with a byte from getrandom" into mktemp(1) makes more
sense.

> Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] mktemp: add -t and fix behavior.

2018-12-05 Thread Rob Landley
On 12/5/18 9:56 AM, enh via Toybox wrote:
> Yes, that's what we've been talking about for days. Search for mktemp and 
> glibc. 
> 
> Bionic will warm you at compile time instead, and musl should be silent. 

He's not gonna be the last one to notice, though.

Sigh, I may need to add a mktemp in portability.c...

Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] macOS: move getmountlist.c functions into portability.c.

2018-12-05 Thread Rob Landley
On 12/5/18 6:31 AM, David Seikel wrote:
>> There's something strange about gmail and this mailing list.  I still
>> can read your messages only from Elliot Hughes' replies (And of
>> course I saw that message since you Cc'ed me). I can't even find your
>> messages in the "Spam" folder in Thunderbird!
> 
> Switching to no longer using gmail seems to have worked for me.
> 
> Though now I'm getting annoyed at mailman sending plain ASCII text as
> base64 encoding.  My email proggy can't handle quoting that.  It didn't
> used to.

I wonder if that's related to me enabling the "header rewrite" option to avoid
triggering gmail's spam filtering when a mail server has that funky sender
verification thing that breaks mailing lists?

Apparently it's gotten so bad some open source projects are abandoning mailing
lists:

  https://lwn.net/Articles/768483/

Given that everything else is subject to cloud rot, I'm pretty sure the ones
that _don't_ abandon mailing lists will outlive the ones that do. But it'll be
some years before that shakes out. (When microsoft finally kills github it's
gonna suck for the digital archaeologists.)

Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] mktemp: add -t and fix behavior.

2018-12-05 Thread enh via Toybox
Yes, that's what we've been talking about for days. Search for mktemp and
glibc.

Bionic will warm you at compile time instead, and musl should be silent.

On Wed, Dec 5, 2018, 03:11 Reverend Homer  Oops, now I have link-time warning:
>
>
> ld: generated/obj/mktemp.o: in function `mktemp_main':
>
> mktemp.c:(.text.mktemp_main+0xa9): warning: the use of `mktemp' is
> dangerous,
> better use `mkstemp' or `mkdtemp'
>
>
> R.H.
>
> On 29/11/2018 03:15, enh via Toybox wrote:
> > The new tests pass on the host (coreutils 8.28) and with toybox after
> > this patch is applied.
> > ---
> >   tests/mktemp.test | 21 +
> >   toys/lsb/mktemp.c | 29 -
> >   2 files changed, 37 insertions(+), 13 deletions(-)
> >   create mode 100755 tests/mktemp.test
> >
> > diff --git a/tests/mktemp.test b/tests/mktemp.test
> > new file mode 100755
> > index 000..d09d2c4
> > --- /dev/null
> > +++ b/tests/mktemp.test
> > @@ -0,0 +1,21 @@
> > +#!/bin/bash
> > +
> > +[ -f testing.sh ] && . testing.sh
> > +
> > +#testing "name" "command" "result" "infile" "stdin"
> > +
> > +# mktemp by default should use tmp.XX as the template,
> > +# and $TMPDIR as the directory.
> > +testing "mktemp" "TMPDIR=/t mktemp -u | grep -q
> > '^/t/tmp\...$' && echo yes" "yes\n" "" ""
> > +
> > +# mktemp with a template should *not* use $TMPDIR.
> > +testing "mktemp TEMPLATE" "TMPDIR=/t mktemp -u hello. | grep
> > -q '^hello\.$' && echo yes" "yes\n" "" ""
> > +
> > +# mktemp with -t and a template should use $TMPDIR.
> > +testing "mktemp -t TEMPLATE" "TMPDIR=/t mktemp -u -t hello. |
> > grep -q '^/t/hello\.$' && echo yes" "yes\n" "" ""
> > +
> > +# mktemp with -p DIR and a template should use DIR.
> > +testing "mktemp -p DIR TEMPLATE" "TMPDIR=/t mktemp -u -p DIR
> > hello. | grep -q '^DIR/hello\.$' && echo yes" "yes\n"
> > "" ""
> > +
> > +# mktemp -p DIR and -t: -t wins.
> > +testing "mktemp -p DIR -t TEMPLATE" "TMPDIR=/t mktemp -u -p DIR -t
> > hello. | grep -q '^/t/hello\.$' && echo yes" "yes\n"
> > "" ""
> > diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c
> > index 21bb9b3..440cf6b 100644
> > --- a/toys/lsb/mktemp.c
> > +++ b/toys/lsb/mktemp.c
> > @@ -4,7 +4,7 @@
> >*
> >*
> http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/mktemp.html
> >
> > -USE_MKTEMP(NEWTOY(mktemp, ">1uqd(directory)p(tmpdir):", TOYFLAG_BIN))
> > +USE_MKTEMP(NEWTOY(mktemp, ">1uqd(directory)p(tmpdir):t", TOYFLAG_BIN))
> >
> >   config MKTEMP
> > bool "mktemp"
> > @@ -17,11 +17,11 @@ config MKTEMP
> >   -d Create directory instead of file (--directory)
> >   -p Put new file in DIR (--tmpdir)
> >   -q Quiet, no error messages
> > +-t Prepend $TMPDIR or /tmp if unset
> >   -u Don't create anything, just print what would be created
> >
> >   Each X in TEMPLATE is replaced with a random printable character.
> The
> > -default TEMPLATE is tmp.XX, and the default DIR is $TMPDIR if
> set,
> > -else "/tmp".
> > +default TEMPLATE is tmp.XX.
> >   */
> >
> >   #define FOR_mktemp
> > @@ -33,24 +33,27 @@ GLOBALS(
> >
> >   void mktemp_main(void)
> >   {
> > -  int d_flag = toys.optflags & FLAG_d;
> > char *template = *toys.optargs;
> >
> > -  if (!template) template = "tmp.XX";
> > +  if (!template) {
> > +toys.optflags |= FLAG_t;
> > +template = "tmp.XX";
> > +  }
> >
> > -  if (!TT.p) TT.p = getenv("TMPDIR");
> > +  if (!TT.p || (toys.optflags & FLAG_t)) TT.p = getenv("TMPDIR");
> > if (!TT.p || !*TT.p) TT.p = "/tmp";
> >
> > -  template = strchr(template, '/') ? xstrdup(template)
> > - : xmprintf("%s/%s", TT.p, template);
> > +  // TODO: coreutils cleans paths, so -p /t/// would result in /t/xxx...
> > +  template = (strchr(template, '/') || !(toys.optflags &
> (FLAG_p|FLAG_t)))
> > +  ? xstrdup(template) : xmprintf("%s/%s", TT.p, template);
> >
> > -  if (d_flag ? !mkdtemp(template) : mkstemp(template) == -1) {
> > +  if (toys.optflags & FLAG_u) {
> > +mktemp(template);
> > +xputs(template);
> > +  } else if (toys.optflags & FLAG_d ? !mkdtemp(template) :
> > mkstemp(template) == -1) {
> >   if (toys.optflags & FLAG_q) toys.exitval = 1;
> >   else perror_exit("Failed to create %s %s/%s",
> > - d_flag ? "directory" : "file", TT.p, template);
> > -  } else {
> > -if (toys.optflags & FLAG_u) unlink(template);
> > -xputs(template);
> > +toys.optflags & FLAG_d ? "directory" : "file", TT.p, template);
> > }
> >
> > if (CFG_TOYBOX_FREE) free(template);
> >
> > ___
> > Toybox mailing list
> > Toybox@lists.landley.net
> > http://lists.landley.net/listinfo.cgi/toybox-landley.net
> ___
> Toybox mailing list
> Toybox@lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
>

Re: [Toybox] [PATCH] macOS: move getmountlist.c functions into portability.c.

2018-12-05 Thread David Seikel
> There's something strange about gmail and this mailing list.  I still
> can read your messages only from Elliot Hughes' replies (And of
> course I saw that message since you Cc'ed me). I can't even find your
> messages in the "Spam" folder in Thunderbird!

Switching to no longer using gmail seems to have worked for me.

Though now I'm getting annoyed at mailman sending plain ASCII text as
base64 encoding.  My email proggy can't handle quoting that.  It didn't
used to.

-- 
A big old stinking pile of genius that no one wants
coz there are too many silver coated monkeys in the world.
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] mktemp: add -t and fix behavior.

2018-12-05 Thread Reverend Homer

Oops, now I have link-time warning:


ld: generated/obj/mktemp.o: in function `mktemp_main':

mktemp.c:(.text.mktemp_main+0xa9): warning: the use of `mktemp' is dangerous, 
better use `mkstemp' or `mkdtemp'



R.H.

On 29/11/2018 03:15, enh via Toybox wrote:

The new tests pass on the host (coreutils 8.28) and with toybox after
this patch is applied.
---
  tests/mktemp.test | 21 +
  toys/lsb/mktemp.c | 29 -
  2 files changed, 37 insertions(+), 13 deletions(-)
  create mode 100755 tests/mktemp.test

diff --git a/tests/mktemp.test b/tests/mktemp.test
new file mode 100755
index 000..d09d2c4
--- /dev/null
+++ b/tests/mktemp.test
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+# mktemp by default should use tmp.XX as the template,
+# and $TMPDIR as the directory.
+testing "mktemp" "TMPDIR=/t mktemp -u | grep -q
'^/t/tmp\...$' && echo yes" "yes\n" "" ""
+
+# mktemp with a template should *not* use $TMPDIR.
+testing "mktemp TEMPLATE" "TMPDIR=/t mktemp -u hello. | grep
-q '^hello\.$' && echo yes" "yes\n" "" ""
+
+# mktemp with -t and a template should use $TMPDIR.
+testing "mktemp -t TEMPLATE" "TMPDIR=/t mktemp -u -t hello. |
grep -q '^/t/hello\.$' && echo yes" "yes\n" "" ""
+
+# mktemp with -p DIR and a template should use DIR.
+testing "mktemp -p DIR TEMPLATE" "TMPDIR=/t mktemp -u -p DIR
hello. | grep -q '^DIR/hello\.$' && echo yes" "yes\n"
"" ""
+
+# mktemp -p DIR and -t: -t wins.
+testing "mktemp -p DIR -t TEMPLATE" "TMPDIR=/t mktemp -u -p DIR -t
hello. | grep -q '^/t/hello\.$' && echo yes" "yes\n"
"" ""
diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c
index 21bb9b3..440cf6b 100644
--- a/toys/lsb/mktemp.c
+++ b/toys/lsb/mktemp.c
@@ -4,7 +4,7 @@
   *
   * 
http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/mktemp.html

-USE_MKTEMP(NEWTOY(mktemp, ">1uqd(directory)p(tmpdir):", TOYFLAG_BIN))
+USE_MKTEMP(NEWTOY(mktemp, ">1uqd(directory)p(tmpdir):t", TOYFLAG_BIN))

  config MKTEMP
bool "mktemp"
@@ -17,11 +17,11 @@ config MKTEMP
  -d Create directory instead of file (--directory)
  -p Put new file in DIR (--tmpdir)
  -q Quiet, no error messages
+-t Prepend $TMPDIR or /tmp if unset
  -u Don't create anything, just print what would be created

  Each X in TEMPLATE is replaced with a random printable character. The
-default TEMPLATE is tmp.XX, and the default DIR is $TMPDIR if set,
-else "/tmp".
+default TEMPLATE is tmp.XX.
  */

  #define FOR_mktemp
@@ -33,24 +33,27 @@ GLOBALS(

  void mktemp_main(void)
  {
-  int d_flag = toys.optflags & FLAG_d;
char *template = *toys.optargs;

-  if (!template) template = "tmp.XX";
+  if (!template) {
+toys.optflags |= FLAG_t;
+template = "tmp.XX";
+  }

-  if (!TT.p) TT.p = getenv("TMPDIR");
+  if (!TT.p || (toys.optflags & FLAG_t)) TT.p = getenv("TMPDIR");
if (!TT.p || !*TT.p) TT.p = "/tmp";

-  template = strchr(template, '/') ? xstrdup(template)
- : xmprintf("%s/%s", TT.p, template);
+  // TODO: coreutils cleans paths, so -p /t/// would result in /t/xxx...
+  template = (strchr(template, '/') || !(toys.optflags & (FLAG_p|FLAG_t)))
+  ? xstrdup(template) : xmprintf("%s/%s", TT.p, template);

-  if (d_flag ? !mkdtemp(template) : mkstemp(template) == -1) {
+  if (toys.optflags & FLAG_u) {
+mktemp(template);
+xputs(template);
+  } else if (toys.optflags & FLAG_d ? !mkdtemp(template) :
mkstemp(template) == -1) {
  if (toys.optflags & FLAG_q) toys.exitval = 1;
  else perror_exit("Failed to create %s %s/%s",
- d_flag ? "directory" : "file", TT.p, template);
-  } else {
-if (toys.optflags & FLAG_u) unlink(template);
-xputs(template);
+toys.optflags & FLAG_d ? "directory" : "file", TT.p, template);
}

if (CFG_TOYBOX_FREE) free(template);

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] macOS: move getmountlist.c functions into portability.c.

2018-12-05 Thread Reverend Homer
There's something strange about gmail and this mailing list.  I still can read 
your messages only from Elliot Hughes' replies (And of course I saw that 
message since you Cc'ed me). I can't even find your messages in the "Spam" 
folder in Thunderbird!



Confused,

R.H.

On 05/12/2018 01:15, Rob Landley wrote:

On 12/4/18 3:34 PM, enh via Toybox wrote:

it'll fail to build if you actually try to build a toy that needs these :-)
On Tue, Dec 4, 2018 at 1:28 PM Reverend Homer  wrote:

Oddy enough for that one I got your reply, but not Revend Homer's, and going
through the spam filter (about 35 things from the buildroot list and such had
wound up in there since I last checked)... still didn't find it.

I suspect gmail did the "refuse delivery" thing, except I didn't get unsubcribed
from the list again? (Does it have a third "accept delivery but discard and not
even put it in the spam folder" option?)

Wheee,

Rob

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net