Re: [dev] tmux export buffer to pastebin

2013-07-19 Thread Martti Kühne
On Sat, Jul 13, 2013 at 7:50 AM, Kai Hendry  wrote:
> Hi guys,
>
> Since hopefully most of you are running http://st.suckless.org/ and
> tmux, perhaps you'll find this bind interesting:
>


Although I use tmux on a daily basis I'm not sure how relevant this is
for this list.
Also, I'm not particularly impressed by this dump keybind, which is
something I can easily do with my mouse. St luckily has a good
selection feature. When you accidentaly dump something online you
didn't want because you clumsily misfingered tmux' shortcuts... no
thanks.

cheers!
mar77i



Re: [dev] tmux export buffer to pastebin

2013-07-19 Thread stanio
* Kai Hendry 2013-07-13 07:50
> Since hopefully most of you are running http://st.suckless.org/ and
> tmux, perhaps you'll find this bind interesting:
> 
> bind-key p capture-pane -S -32768 \; save-buffer /tmp/tmux-buffer \;
> run "cat /tmp/tmux-buffer | curl -F 'sprunge=<-' http://sprunge.us
> | tmux load-buffer -; tmux show-buffer"

not sure I find it useful as a binding in tmux -- never had this use
case.

But I have already piped some stuff to sprunge from a file since you
posted it. It was very helpful. So, thank you for sharing.

--s_



Re: [dev] tmux export buffer to pastebin

2013-07-19 Thread Chris Down
On 13 July 2013 07:50, Kai Hendry  wrote:
> bind-key p capture-pane -S -32768 \; save-buffer /tmp/tmux-buffer \;
> run "cat /tmp/tmux-buffer | curl -F 'sprunge=<-' http://sprunge.us
> | tmux load-buffer -; tmux show-buffer"

You can just do:

curl -F 'sprunge=@/tmp/tmux-buffer' sprunge.us



Re: [dev] [PATCH] Add compatibility for OpenBSD in tar

2013-07-19 Thread Galos, David
> OpenBSD defines strlcpy function, and the declaration is a bit different
> of the static declartion found in tar.c. The duplication of symbol name
> with different type (one extern and other static, one returning int and
> the other returning size_t) caused tar couldn't compile in OpenBSD.

Since nothing else in sbase makes use of strlcpy I don't think that it's
worth librarizing like this. I did it for consistency in `archive`, as I
populated the Header. It might be better for now to just call it strlmov,
or define a macro STRLCPY.



[dev] [sbase] [patch] Add sha256sum(1)

2013-07-19 Thread sin
Hi,

Added sha256sum(1).

No support for -c.

Thanks,
sin
>From 2f8b277fbef7f7d40051cf2ceb751ea6b1b9b7bd Mon Sep 17 00:00:00 2001
From: sin 
Date: Fri, 19 Jul 2013 14:29:43 +0100
Subject: [PATCH 1/2] Add sha256sum(1)

---
 Makefile  |   4 +-
 sha256.h  |  18 +++
 sha256sum.1   |   8 
 sha256sum.c   |  49 +++
 util/sha256.c | 152 ++
 5 files changed, 230 insertions(+), 1 deletion(-)
 create mode 100644 sha256.h
 create mode 100644 sha256sum.1
 create mode 100644 sha256sum.c
 create mode 100644 util/sha256.c

diff --git a/Makefile b/Makefile
index bd0c38c..da4d0d0 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,8 @@ LIB = \
util/putword.o   \
util/recurse.o   \
util/rm.o\
-   util/sha1.o
+   util/sha1.o  \
+   util/sha256.o
 
 SRC = \
basename.c \
@@ -80,6 +81,7 @@ SRC = \
unlink.c   \
seq.c  \
sha1sum.c  \
+   sha256sum.c\
wc.c   \
who.c  \
yes.c
diff --git a/sha256.h b/sha256.h
new file mode 100644
index 000..5968b8e
--- /dev/null
+++ b/sha256.h
@@ -0,0 +1,18 @@
+/* public domain sha256 implementation based on fips180-3 */
+
+struct sha256 {
+   uint64_t len;/* processed message length */
+   uint32_t h[8];   /* hash state */
+   uint8_t buf[64]; /* message block buffer */
+};
+
+enum { SHA256_DIGEST_LENGTH = 32 };
+
+/* reset state */
+void sha256_init(void *ctx);
+/* process message */
+void sha256_update(void *ctx, const void *m, unsigned long len);
+/* get message digest */
+/* state is ruined after sum, keep a copy if multiple sum is needed */
+/* part of the message might be left in s, zero it if secrecy is needed */
+void sha256_sum(void *ctx, uint8_t md[SHA256_DIGEST_LENGTH]);
diff --git a/sha256sum.1 b/sha256sum.1
new file mode 100644
index 000..494b9df
--- /dev/null
+++ b/sha256sum.1
@@ -0,0 +1,8 @@
+.TH SHA256SUM 1 sbase\-VERSION
+.SH NAME
+sha256sum \- compute SHA256 message digest
+.SH SYNOPSIS
+.B sha256sum
+.RI [ file ...]
+.SH DESCRIPTION
+Print SHA256 (256-bit) checksums. With no file, read standard input.
diff --git a/sha256sum.c b/sha256sum.c
new file mode 100644
index 000..ce97435
--- /dev/null
+++ b/sha256sum.c
@@ -0,0 +1,49 @@
+/* See LICENSE file for copyright and license details. */
+#include 
+#include 
+#include 
+#include "util.h"
+#include "crypt.h"
+#include "sha256.h"
+
+struct sha256 s;
+struct crypt_ops sha256_ops = {
+   sha256_init,
+   sha256_update,
+   sha256_sum,
+   &s,
+};
+
+static void
+usage(void)
+{
+   eprintf("usage: %s [file...]\n", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+   FILE *fp;
+   uint8_t md[SHA256_DIGEST_LENGTH];
+
+   ARGBEGIN {
+   default:
+   usage();
+   } ARGEND;
+
+   if (argc == 0) {
+   cryptsum(&sha256_ops, stdin, "", md);
+   mdprint(md, "", sizeof(md));
+   } else {
+   for (; argc > 0; argc--) {
+   if ((fp = fopen(*argv, "r")) == NULL)
+   eprintf("fopen %s:", *argv);
+   cryptsum(&sha256_ops, fp, *argv, md);
+   mdprint(md, *argv, sizeof(md));
+   fclose(fp);
+   argv++;
+   }
+   }
+
+   return 0;
+}
diff --git a/util/sha256.c b/util/sha256.c
new file mode 100644
index 000..94db29b
--- /dev/null
+++ b/util/sha256.c
@@ -0,0 +1,152 @@
+/*
+ * public domain sha256 crypt implementation
+ *
+ * original sha crypt design: http://people.redhat.com/drepper/SHA-crypt.txt
+ * in this implementation at least 32bit int is assumed,
+ * key length is limited, the $5$ prefix is mandatory, '\n' and ':' is rejected
+ * in the salt and rounds= setting must contain a valid iteration count,
+ * on error "*" is returned.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../sha256.h"
+
+/* public domain sha256 implementation based on fips180-3 */
+
+static uint32_t ror(uint32_t n, int k) { return (n >> k) | (n << (32-k)); }
+#define Ch(x,y,z)  (z ^ (x & (y ^ z)))
+#define Maj(x,y,z) ((x & y) | (z & (x | y)))
+#define S0(x)  (ror(x,2) ^ ror(x,13) ^ ror(x,22))
+#define S1(x)  (ror(x,6) ^ ror(x,11) ^ ror(x,25))
+#define R0(x)  (ror(x,7) ^ ror(x,18) ^ (x>>3))
+#define R1(x)  (ror(x,17) ^ ror(x,19) ^ (x>>10))
+
+static const uint32_t K[64] = {
+0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 
0x923f82a4, 0xab1c5ed5,
+0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 
0x9bdc06a7, 0xc19bf174,
+0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 
0x5cb0a9dc, 0x76f988da,
+0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 
0x06ca6351, 0x14292967,
+0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 
0x81c2c92e, 0x92722c85,
+0xa2bfe8a1, 

[dev] [sbase] [patch] Do not hardcode the size of md

2013-07-19 Thread sin
Just to be more consistent.
>From 9ed3cde216a7aeca0af1371b3890a50b852f4d51 Mon Sep 17 00:00:00 2001
From: sin 
Date: Fri, 19 Jul 2013 14:31:42 +0100
Subject: [PATCH 2/2] Do not hardcode the size of md

---
 util/md5.c  | 2 +-
 util/sha1.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/md5.c b/util/md5.c
index b68f729..dc2ca8e 100644
--- a/util/md5.c
+++ b/util/md5.c
@@ -105,7 +105,7 @@ void md5_init(void *ctx)
s->h[3] = 0x10325476;
 }
 
-void md5_sum(void *ctx, uint8_t md[16])
+void md5_sum(void *ctx, uint8_t md[MD5_DIGEST_LENGTH])
 {
struct md5 *s = ctx;
int i;
diff --git a/util/sha1.c b/util/sha1.c
index a298f9f..4003bae 100644
--- a/util/sha1.c
+++ b/util/sha1.c
@@ -101,7 +101,7 @@ void sha1_init(void *ctx)
s->h[4] = 0xC3D2E1F0;
 }
 
-void sha1_sum(void *ctx, uint8_t md[20])
+void sha1_sum(void *ctx, uint8_t md[SHA1_DIGEST_LENGTH])
 {
struct sha1 *s = ctx;
int i;
-- 
1.8.3.3



[dev] [sbase] [patch v2] Add sha256sum(1)

2013-07-19 Thread sin
Forgot to update $(HDR) in Makefile.
>From 9794df52d6af13e67815d796f05e53c6b0b1402a Mon Sep 17 00:00:00 2001
From: sin 
Date: Fri, 19 Jul 2013 14:29:43 +0100
Subject: [PATCH] Add sha256sum(1)

---
 Makefile  |   6 ++-
 sha256.h  |  18 +++
 sha256sum.1   |   8 
 sha256sum.c   |  49 +++
 util/sha256.c | 152 ++
 5 files changed, 231 insertions(+), 2 deletions(-)
 create mode 100644 sha256.h
 create mode 100644 sha256sum.1
 create mode 100644 sha256sum.c
 create mode 100644 util/sha256.c

diff --git a/Makefile b/Makefile
index bd0c38c..a904c47 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ include config.mk
 .POSIX:
 .SUFFIXES: .c .o
 
-HDR = crypt.h fs.h text.h md5.h sha1.h util.h arg.h
+HDR = crypt.h fs.h text.h md5.h sha1.h sha256.h util.h arg.h
 LIB = \
util/afgets.o\
util/agetcwd.o   \
@@ -20,7 +20,8 @@ LIB = \
util/putword.o   \
util/recurse.o   \
util/rm.o\
-   util/sha1.o
+   util/sha1.o  \
+   util/sha256.o
 
 SRC = \
basename.c \
@@ -80,6 +81,7 @@ SRC = \
unlink.c   \
seq.c  \
sha1sum.c  \
+   sha256sum.c\
wc.c   \
who.c  \
yes.c
diff --git a/sha256.h b/sha256.h
new file mode 100644
index 000..5968b8e
--- /dev/null
+++ b/sha256.h
@@ -0,0 +1,18 @@
+/* public domain sha256 implementation based on fips180-3 */
+
+struct sha256 {
+   uint64_t len;/* processed message length */
+   uint32_t h[8];   /* hash state */
+   uint8_t buf[64]; /* message block buffer */
+};
+
+enum { SHA256_DIGEST_LENGTH = 32 };
+
+/* reset state */
+void sha256_init(void *ctx);
+/* process message */
+void sha256_update(void *ctx, const void *m, unsigned long len);
+/* get message digest */
+/* state is ruined after sum, keep a copy if multiple sum is needed */
+/* part of the message might be left in s, zero it if secrecy is needed */
+void sha256_sum(void *ctx, uint8_t md[SHA256_DIGEST_LENGTH]);
diff --git a/sha256sum.1 b/sha256sum.1
new file mode 100644
index 000..494b9df
--- /dev/null
+++ b/sha256sum.1
@@ -0,0 +1,8 @@
+.TH SHA256SUM 1 sbase\-VERSION
+.SH NAME
+sha256sum \- compute SHA256 message digest
+.SH SYNOPSIS
+.B sha256sum
+.RI [ file ...]
+.SH DESCRIPTION
+Print SHA256 (256-bit) checksums. With no file, read standard input.
diff --git a/sha256sum.c b/sha256sum.c
new file mode 100644
index 000..ce97435
--- /dev/null
+++ b/sha256sum.c
@@ -0,0 +1,49 @@
+/* See LICENSE file for copyright and license details. */
+#include 
+#include 
+#include 
+#include "util.h"
+#include "crypt.h"
+#include "sha256.h"
+
+struct sha256 s;
+struct crypt_ops sha256_ops = {
+   sha256_init,
+   sha256_update,
+   sha256_sum,
+   &s,
+};
+
+static void
+usage(void)
+{
+   eprintf("usage: %s [file...]\n", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+   FILE *fp;
+   uint8_t md[SHA256_DIGEST_LENGTH];
+
+   ARGBEGIN {
+   default:
+   usage();
+   } ARGEND;
+
+   if (argc == 0) {
+   cryptsum(&sha256_ops, stdin, "", md);
+   mdprint(md, "", sizeof(md));
+   } else {
+   for (; argc > 0; argc--) {
+   if ((fp = fopen(*argv, "r")) == NULL)
+   eprintf("fopen %s:", *argv);
+   cryptsum(&sha256_ops, fp, *argv, md);
+   mdprint(md, *argv, sizeof(md));
+   fclose(fp);
+   argv++;
+   }
+   }
+
+   return 0;
+}
diff --git a/util/sha256.c b/util/sha256.c
new file mode 100644
index 000..94db29b
--- /dev/null
+++ b/util/sha256.c
@@ -0,0 +1,152 @@
+/*
+ * public domain sha256 crypt implementation
+ *
+ * original sha crypt design: http://people.redhat.com/drepper/SHA-crypt.txt
+ * in this implementation at least 32bit int is assumed,
+ * key length is limited, the $5$ prefix is mandatory, '\n' and ':' is rejected
+ * in the salt and rounds= setting must contain a valid iteration count,
+ * on error "*" is returned.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../sha256.h"
+
+/* public domain sha256 implementation based on fips180-3 */
+
+static uint32_t ror(uint32_t n, int k) { return (n >> k) | (n << (32-k)); }
+#define Ch(x,y,z)  (z ^ (x & (y ^ z)))
+#define Maj(x,y,z) ((x & y) | (z & (x | y)))
+#define S0(x)  (ror(x,2) ^ ror(x,13) ^ ror(x,22))
+#define S1(x)  (ror(x,6) ^ ror(x,11) ^ ror(x,25))
+#define R0(x)  (ror(x,7) ^ ror(x,18) ^ (x>>3))
+#define R1(x)  (ror(x,17) ^ ror(x,19) ^ (x>>10))
+
+static const uint32_t K[64] = {
+0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 
0x923f82a4, 0xab1c5ed5,
+0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 
0x9bdc06a7, 0xc19bf174,
+0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 
0x5cb0a9dc, 0x7

Re: [dev] [sbase] [patch] Add sha256sum(1)

2013-07-19 Thread Szabolcs Nagy
* sin  [2013-07-19 16:34:07 +0300]:
> +/*
> + * public domain sha256 crypt implementation
> + *
> + * original sha crypt design: http://people.redhat.com/drepper/SHA-crypt.txt
> + * in this implementation at least 32bit int is assumed,
> + * key length is limited, the $5$ prefix is mandatory, '\n' and ':' is 
> rejected
> + * in the salt and rounds= setting must contain a valid iteration count,
> + * on error "*" is returned.
> + */

this comment for the sha2 based crypt implementation
not for the hash function

(it turns out the sha2 based password hashing, widely
used on linux systems (default on most distributions),
has atrociously bad design so we had to make some
changes in musl hence the comment)



Re: [dev] [PATCH] Add compatibility for OpenBSD in tar

2013-07-19 Thread Roberto E. Vargas Caballero
On Fri, Jul 19, 2013 at 09:19:41AM -0400, Galos, David wrote:
> > OpenBSD defines strlcpy function, and the declaration is a bit different
> > of the static declartion found in tar.c. The duplication of symbol name
> > with different type (one extern and other static, one returning int and
> > the other returning size_t) caused tar couldn't compile in OpenBSD.
> 
> Since nothing else in sbase makes use of strlcpy I don't think that it's
> worth librarizing like this. I did it for consistency in `archive`, as I
> populated the Header. It might be better for now to just call it strlmov,
> or define a macro STRLCPY.

If we are going to use only in this file then maybe is better use the snprintf
directly.

-- 
Roberto E. Vargas Caballero

k...@shike2.com
http://www.shike2.com



[dev] [sbase] [patch] Remove trailing whitespace

2013-07-19 Thread sin

>From 32020667bde97a75741340ff926a804c135c29f5 Mon Sep 17 00:00:00 2001
From: sin 
Date: Fri, 19 Jul 2013 17:05:28 +0100
Subject: [PATCH] Remove trailing whitespace

---
 tar.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/tar.c b/tar.c
index 3481942..3de49fb 100644
--- a/tar.c
+++ b/tar.c
@@ -35,8 +35,8 @@ enum {
 };
 
 enum Type {
-   REG = '0', HARDLINK = '1', SYMLINK = '2', CHARDEV = '3', 
-   BLOCKDEV = '4', DIRECTORY = '5', FIFO = '6' 
+   REG = '0', HARDLINK = '1', SYMLINK = '2', CHARDEV = '3',
+   BLOCKDEV = '4', DIRECTORY = '5', FIFO = '6'
 };
 
 static void putoctal(char *, unsigned, int);
@@ -49,7 +49,7 @@ static void xt(int (*)(char*, int, char[Blksiz]));
 
 static FILE *tarfile;
 
-static void 
+static void
 usage(void)
 {
eprintf("usage: tar [-f tarfile] [-C dir] [-]x|t\n"
@@ -58,7 +58,7 @@ usage(void)
"   tar [-C dir] x|tf tarfile\n");
 }
 
-int 
+int
 main(int argc, char *argv[])
 {
char *file = NULL, *dir = ".", *ap;
@@ -142,13 +142,13 @@ putoctal(char *dst, unsigned num, int n)
snprintf(dst, n, "%.*o", n-1, num);
 }
 
-int 
+int
 strlcpy(char *dst, const char *src, int n)
 {
return snprintf(dst, n, "%s", src);
 }
 
-int 
+int
 archive(const char* path, const struct stat* sta, int type)
 {
unsigned char b[Blksiz];
@@ -209,10 +209,10 @@ archive(const char* path, const struct stat* sta, int 
type)
fwrite(b, Blksiz, 1, tarfile);
}
fclose(f);
-   return 0;   
+   return 0;
 }
 
-int 
+int
 unarchive(char *fname, int l, char b[Blksiz])
 {
char lname[101];
@@ -255,7 +255,7 @@ unarchive(char *fname, int l, char b[Blksiz])
default:
fprintf(stderr, "usupported tarfiletype %c\n", h->type);
}
-   if(getuid() == 0 && chown(fname, strtoul(h->uid, 0, 8), 
+   if(getuid() == 0 && chown(fname, strtoul(h->uid, 0, 8),
 strtoul(h->gid, 0, 8)))
perror(fname);
 
@@ -269,7 +269,7 @@ unarchive(char *fname, int l, char b[Blksiz])
return 0;
 }
 
-int 
+int
 print(char * fname, int l, char b[Blksiz])
 {
puts(fname);
-- 
1.8.3.3



Re: [dev] [PATCH] Add compatibility for OpenBSD in tar

2013-07-19 Thread sin
On Fri, Jul 19, 2013 at 04:29:23PM +0200, Roberto E. Vargas Caballero wrote:
> On Fri, Jul 19, 2013 at 09:19:41AM -0400, Galos, David wrote:
> > > OpenBSD defines strlcpy function, and the declaration is a bit different
> > > of the static declartion found in tar.c. The duplication of symbol name
> > > with different type (one extern and other static, one returning int and
> > > the other returning size_t) caused tar couldn't compile in OpenBSD.
> > 
> > Since nothing else in sbase makes use of strlcpy I don't think that it's
> > worth librarizing like this. I did it for consistency in `archive`, as I
> > populated the Header. It might be better for now to just call it strlmov,
> > or define a macro STRLCPY.
> 
> If we are going to use only in this file then maybe is better use the snprintf
> directly.

+1 - that makes more sense.

Thanks,
sin



[dev] [sbase] [patch] Change sprintf to snprintf

2013-07-19 Thread sin

>From 7b1ebb6295aade41f4a0269ac473fff1dbc19bf3 Mon Sep 17 00:00:00 2001
From: sin 
Date: Fri, 19 Jul 2013 17:08:15 +0100
Subject: [PATCH] Change sprintf to snprintf

cal.c:40: warning: sprintf() is often misused, please use snprintf()
---
 cal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cal.c b/cal.c
index f1ba10d..2c42ccd 100644
--- a/cal.c
+++ b/cal.c
@@ -37,7 +37,7 @@ drawcal(int year, int month, int day, int ncols, int nmons, 
int fday)
cur = moff % 12;
yoff = year + moff / 12;
 
-   sprintf(str, "%s %d", smon[cur], yoff);
+   snprintf(str, sizeof(str), "%s %d", smon[cur], yoff);
printf("%-20s   ", str);
count[i] = 1;
}
-- 
1.8.3.3



Re: [dev] [PATCH] Add compatibility for OpenBSD in tar

2013-07-19 Thread Galos, David
>> If we are going to use only in this file then maybe is better use the 
>> snprintf
>> directly.
>
> +1 - that makes more sense.

Then, that is what we'll do.

Also, sin, I'm looking over your patches, and I'll try to add them tonight.



[dev] [PATCH] Add RGB color definition

2013-07-19 Thread Roberto E. Vargas Caballero
From: "Roberto E. Vargas Caballero" 

It is impossible allocate all the RGB colors using a static
array, so it is necessary move DC.col into a pointer and use
dinamic memory.

Since the color definition is not used to much is not a bad idea
use realloc each time. It means the color definition arry will
increase its size until user resets the terminal.

If this sequence is used a lot we should check if the color
is already defined and look for a way ef releasing colors
not used (and maybe a better allocation scheme).
---
 st.c | 124 +--
 1 file changed, 84 insertions(+), 40 deletions(-)

diff --git a/st.c b/st.c
index 947373f..3f693d9 100644
--- a/st.c
+++ b/st.c
@@ -306,7 +306,7 @@ typedef struct {
 
 /* Drawing Context */
 typedef struct {
-   Colour col[LEN(colorname) < 256 ? 256 : LEN(colorname)];
+   Colour *col;
Font font, bfont, ifont, ibfont;
GC gc;
 } DC;
@@ -354,7 +354,7 @@ static void tsetdirtattr(int);
 static void tsetmode(bool, bool, int *, int);
 static void tfulldirt(void);
 static void techo(char *, int);
-
+static int tdefcolor(int *, int *, int);
 static inline bool match(uint, uint);
 static void ttynew(void);
 static void ttyread(void);
@@ -366,6 +366,8 @@ static void xhints(void);
 static void xclear(int, int, int, int);
 static void xdrawcursor(void);
 static void xinit(void);
+
+static int xnewcolor(uint, uint, uint);
 static void xloadcols(void);
 static int xsetcolorname(int, const char *);
 static int xloadfont(Font *, FcPattern *);
@@ -451,6 +453,7 @@ static int oldbutton = 3; /* button event on startup: 3 = 
release */
 
 static char *usedfont = NULL;
 static int usedfontsize = 0;
+static size_t numcolours;
 
 /* Font Ring Cache */
 enum {
@@ -1618,9 +1621,57 @@ tdeleteline(int n) {
tscrollup(term.c.y, n);
 }
 
+int
+tdefcolor(int *attr, int *npar, int l) {
+   int idx = -1;
+   uint r, g, b;
+
+   switch (attr[*npar + 1]) {
+   case 2: /* direct colour in RGB space */
+   if (*npar + 4 >= l) {
+   fprintf(stderr,
+   "erresc(38): Incorrect number of parameters 
(%d)\n",
+   *npar);
+   break;
+   }
+   r = attr[*npar + 2];
+   g = attr[*npar + 3];
+   b = attr[*npar + 4];
+   *npar += 4;
+   if(!BETWEEN(r, 0, 255) || !BETWEEN(g, 0, 255) || !BETWEEN(b, 0, 
255))
+   fprintf(stderr, "erresc: bad rgb color (%d,%d,%d)\n",
+   r, g, b);
+   else
+   idx = xnewcolor(r, g, b);
+   break;
+   case 5: /* indexed colour */
+   if (*npar + 2 >= l) {
+   fprintf(stderr,
+   "erresc(38): Incorrect number of parameters 
(%d)\n",
+   *npar);
+   break;
+   }
+   *npar += 2;
+   if(!BETWEEN(attr[*npar], 0, 255))
+   fprintf(stderr, "erresc: bad fgcolor %d\n", 
attr[*npar]);
+   else
+   idx = attr[*npar];
+   break;
+   case 0: /* implemented defined (only foreground) */
+   case 1: /* transparent */
+   case 3: /* direct colour in CMY space */
+   case 4: /* direct colour in CMYK space */
+   default:
+   fprintf(stderr,
+   "erresc(38): gfx attr %d unknown\n", attr[*npar]);
+   }
+
+   return idx;
+}
+
 void
 tsetattr(int *attr, int l) {
-   int i;
+   int i, idx;
 
for(i = 0; i < l; i++) {
switch(attr[i]) {
@@ -1665,39 +1716,15 @@ tsetattr(int *attr, int l) {
term.c.attr.mode &= ~ATTR_REVERSE;
break;
case 38:
-   if(i + 2 < l && attr[i + 1] == 5) {
-   i += 2;
-   if(BETWEEN(attr[i], 0, 255)) {
-   term.c.attr.fg = attr[i];
-   } else {
-   fprintf(stderr,
-   "erresc: bad fgcolor %d\n",
-   attr[i]);
-   }
-   } else {
-   fprintf(stderr,
-   "erresc(38): gfx attr %d unknown\n",
-   attr[i]);
-   }
+   if ((idx = tdefcolor(attr, &i, l)) >= 0)
+   term.c.attr.fg = idx;
break;
case 39:
term.c.attr.fg = defaultfg;
break;
case 48:
-   if(i + 2 < l && attr[i + 1] =

[dev] [PATCH v2] Add compatibility for OpenBSD in tar

2013-07-19 Thread Roberto E. Vargas Caballero
From: "Roberto E. Vargas Caballero" 

OpenBSD defines strlcpy function, and the declaration is a bit different
of the static declartion found in tar.c. The duplication of symbol name
with different type (one extern and other static, one returning int and
the other returning size_t) caused tar couldn't compile in OpenBSD.
---
 tar.c | 17 +
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/tar.c b/tar.c
index 3481942..c367633 100644
--- a/tar.c
+++ b/tar.c
@@ -40,7 +40,6 @@ enum Type {
 };
 
 static void putoctal(char *, unsigned, int);
-static int strlcpy(char *, const char *, int n);
 static int archive(const char *, const struct stat *, int);
 static int unarchive(char *, int, char[Blksiz]);
 static int print(char *, int , char[Blksiz]);
@@ -143,12 +142,6 @@ putoctal(char *dst, unsigned num, int n)
 }
 
 int 
-strlcpy(char *dst, const char *src, int n)
-{
-   return snprintf(dst, n, "%s", src);
-}
-
-int 
 archive(const char* path, const struct stat* sta, int type)
 {
unsigned char b[Blksiz];
@@ -166,7 +159,7 @@ archive(const char* path, const struct stat* sta, int type)
gr = getgrgid(st.st_gid);
 
memset(b, 0, sizeof b);
-   strlcpy (h->name,  path,  sizeof h->name);
+   snprintf(h->name, sizeof h->name, "%s", path);
putoctal(h->mode,  (unsigned)st.st_mode&0777, sizeof h->mode);
putoctal(h->uid,   (unsigned)st.st_uid,   sizeof h->uid);
putoctal(h->gid,   (unsigned)st.st_gid,   sizeof h->gid);
@@ -174,8 +167,8 @@ archive(const char* path, const struct stat* sta, int type)
putoctal(h->mtime, (unsigned)st.st_mtime, sizeof h->mtime);
memcpy(h->magic,   "ustar",   sizeof h->magic);
memcpy(h->version, "00",  sizeof h->version);
-   strlcpy(h->uname,  pw->pw_name,   sizeof h->uname);
-   strlcpy(h->gname,  gr->gr_name,   sizeof h->gname);
+   snprintf(h->uname, sizeof h->uname, "%s", pw->pw_name);
+   snprintf(h->gname, sizeof h->gname, "%s", gr->gr_name);
 
mode = st.st_mode;
if(S_ISREG(mode)) {
@@ -229,7 +222,7 @@ unarchive(char *fname, int l, char b[Blksiz])
break;
case HARDLINK:
case SYMLINK:
-   strlcpy(lname, h->link, sizeof lname);
+   snprintf(lname, sizeof lname, "%s", h->link);
if(!((h->type == HARDLINK) ? link : symlink)(lname, fname))
perror(fname);
break;
@@ -291,7 +284,7 @@ xt(int (*fn)(char*, int, char[Blksiz]))
Header *h = (void*)b;
 
while(fread(b, Blksiz, 1, tarfile) && h->name[0] != '\0') {
-   strlcpy(fname, h->name, sizeof fname);
+   snprintf(fname, sizeof fname, "%s", h->name);
fn(fname, strtol(h->size, 0, 8), b);
}
 }
-- 
1.8.3.2




Re: [dev] [sbase] [patch] Add sha256sum(1)

2013-07-19 Thread Galos, David
>> +/*
>> + * public domain sha256 crypt implementation
>> + *
>> + * original sha crypt design: http://people.redhat.com/drepper/SHA-crypt.txt
>> + * in this implementation at least 32bit int is assumed,
>> + * key length is limited, the $5$ prefix is mandatory, '\n' and ':' is 
>> rejected
>> + * in the salt and rounds= setting must contain a valid iteration count,
>> + * on error "*" is returned.
>> + */
>
> this comment for the sha2 based crypt implementation
> not for the hash function

Is there some replacement text that you suggest? I figure we might as well
note where this sha2 implementation originates from. Is anything further
than the fact that it's public domain known?



Re: [dev] [sbase] [patch] Do not hardcode the size of md

2013-07-19 Thread Galos, David
> Just to be more consistent.
Applied!



Re: [dev] [sbase] [patch] Change sprintf to snprintf

2013-07-19 Thread Galos, David
Applied



Re: [dev] [sbase] [patch] Remove trailing whitespace

2013-07-19 Thread Galos, David
Applied



Re: [dev] [PATCH v2] Add compatibility for OpenBSD in tar

2013-07-19 Thread Galos, David
> OpenBSD defines strlcpy function, and the declaration is a bit different
> of the static declartion found in tar.c. The duplication of symbol name
> with different type (one extern and other static, one returning int and
> the other returning size_t) caused tar couldn't compile in OpenBSD.

I have applied this. In the future, could you send your patches as
attachments? It would make my life easier.



Re: [dev] [sbase] [patch] Change contact info

2013-07-19 Thread Galos, David
Applied



Re: [dev] [PATCH v2] Add compatibility for OpenBSD in tar

2013-07-19 Thread Roberto E. Vargas Caballero
On Sat, Jul 20, 2013 at 01:28:59AM -0400, Galos, David wrote:
> > OpenBSD defines strlcpy function, and the declaration is a bit different
> > of the static declartion found in tar.c. The duplication of symbol name
> > with different type (one extern and other static, one returning int and
> > the other returning size_t) caused tar couldn't compile in OpenBSD.
> 
> I have applied this. In the future, could you send your patches as
> attachments? It would make my life easier.

Ok, but take a look of git am (it applies a patch from a mailbox).

-- 
Roberto E. Vargas Caballero

k...@shike2.com
http://www.shike2.com



Re: [dev] [surf] Patch for high dpi screens

2013-07-19 Thread Anselm R Garbe
On 16 July 2013 10:42, Nick  wrote:
> The attached patch ensures surf adheres more closely to the CSS spec
> in making one px equal to 1/96 inch, regardless of the actual screen
> pixel density. This is a typical web-style cop-out for the fact that
> many stupid web designers only write things in terms of ~96dpi
> desktop monitors. It sucks, but hey, it's the web.
>
> One issue with this is that with a high DPI monitor, input fields
> are zoomed too much, but that's presumably a bug in webkit (at least
> the version I'm using, 1.8.1).
>
> I'm not sure whether the default in config.def.h should be false. It
> depends on what proportion of monitors badly misrepresent their
> dimensions, I suppose.
>
> But anyway, this should probably be applied, as it's needed for
> websites to be viewable with devices with a DPI different from that
> of a traditional desktop.

Thanks, applied.

Best regards,
Anselm



Re: [dev] [dwm] [patch] Fix warning about XKeycodeToKeysym

2013-07-19 Thread Anselm R Garbe
Hi Alexander,

On 15 July 2013 17:11, Alexander Rødseth  wrote:
> I read the git log after having submitted the patch and I understand
> that this issue has been looked at and various solutions has been
> considered already. Hopefully there will be a good way to resolve this
> in the future.

Well, as long as such functions are only declared deprecated in very
recent X.org versions, I don't think that the X.org guys will remove
them anytime soon, as this would mean that a lot of X11 clients would
break. This particular function has been in use for decades one way or
another, so I'm quite relaxed with such a warning...

Best regards,
Anselm