[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] mcookie: new applet
From:       Bernhard Reutner-Fischer <rep.dot.nop () gmail ! com>
Date:       2015-01-29 9:16:24
Message-ID: 1422522984-4315-2-git-send-email-rep.dot.nop () gmail ! com
[Download RAW message or body]

function                                             old     new   delta
mcookie_main                                           -      85     +85
.rodata                                           151360  151421     +61
packed_usage                                       29262   29295     +33
applet_names                                        2357    2365      +8
applet_main                                         2776    2784      +8
applet_nameofs                                       694     696      +2
bb_dump_dump                                        1469    1463      -6
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/1 up/down: 197/-6)            Total: 191 bytes
   text	   data	    bss	    dec	    hex	filename
 809731	   4107	   9552	 823390	  c905e	busybox_old
 809871	   4107	   9552	 823530	  c90ea	busybox_unstripped

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
---
 include/dump.h      |  2 +-
 libbb/dump.c        |  8 +++++++-
 miscutils/mcookie.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 2 deletions(-)
 create mode 100644 miscutils/mcookie.c

diff --git a/include/dump.h b/include/dump.h
index 4c237ef..4041543 100644
--- a/include/dump.h
+++ b/include/dump.h
@@ -16,7 +16,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
 #define	F_UINT		0x200		/* %[ouXx] */
 #define	F_TEXT		0x400		/* no conversions */
 
-enum dump_vflag_t { ALL, DUP, FIRST, WAIT };	/* -v values */
+enum dump_vflag_t { ALL, DUP, FIRST, WAIT, FROM_BUFFER };	/* -v values */
 
 typedef struct PR {
 	struct PR *nextpr;		/* next print unit */
diff --git a/libbb/dump.c b/libbb/dump.c
index 566881a..a747ce4 100644
--- a/libbb/dump.c
+++ b/libbb/dump.c
@@ -376,7 +376,13 @@ static unsigned char *get(priv_dumper_t *dumper)
 	int need, nread;
 	int blocksize = dumper->blocksize;
 
-	if (!dumper->get__curp) {
+	if (dumper->pub.dump_vflag == FROM_BUFFER) {
+		unsigned char *tmp = (unsigned char *) *dumper->argv;
+		if (tmp)
+			++dumper->argv;
+		dumper->address = (off_t)0;
+		return tmp;
+	} else if (!dumper->get__curp) {
 		dumper->address = (off_t)0; /*DBU:[dave@cray.com] initialize,initialize..*/
 		dumper->get__curp = xmalloc(blocksize);
 		dumper->get__savp = xzalloc(blocksize); /* need to be initialized */
diff --git a/miscutils/mcookie.c b/miscutils/mcookie.c
new file mode 100644
index 0000000..6ae994b
--- /dev/null
+++ b/miscutils/mcookie.c
@@ -0,0 +1,54 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * mcookie implementation for busybox
+ *
+ * Copyright (C) 2012 Bernhard Reutner-Fischer
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ *
+ * Generate a 128-bit random hexadecimal number for use with the
+ * Xauthority system.  Typical usage:
+ *   xauth add :0 . `mcookie`
+ *   xauth add :0 . `dd if=/dev/urandom bs=16 count=1 2>/dev/null | hexdump -e '"%08x"'`
+ */
+
+//config:config MCOOKIE
+//config:	bool "mcookie"
+//config:	default y
+//config:	help
+//config:	  generate magic cookies for xauth
+
+//applet:IF_MCOOKIE(APPLET(mcookie, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_MCOOKIE) += mcookie.o
+
+//usage:#define mcookie_trivial_usage
+//usage:       ""
+//usage:#define mcookie_full_usage "\n\n"
+//usage:       "Generate magic cookies for xauth"
+//usage:
+//usage:#define mcookie_example_usage
+//usage:       "xauth add :0 . `mcookie`"
+
+#include "libbb.h"
+#include "dump.h"
+
+int mcookie_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int mcookie_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+{
+	char buf[16];
+	char *fakeargs[2] = {buf,};
+	const char *dump_fmt = "\"\" 8/2 \"%04x\" \"\n\"";
+	dumper_t *dumper = alloc_dumper();
+# ifdef ENABLE_FEATURE_MCOOKIE_FALLBACK
+	ssize_t bytes =
+#endif
+		open_read_close("/dev/urandom", &buf, sizeof(buf));
+# ifdef ENABLE_FEATURE_MCOOKIE_FALLBACK
+	if (bytes < 0)
+		bytes = open_read_close("/dev/random", &buf, sizeof(buf));
+# endif
+	bb_dump_add(dumper, dump_fmt);
+	dumper->dump_vflag = FROM_BUFFER;
+	return bb_dump_dump(dumper, fakeargs);
+}
-- 
2.1.4

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic