CVS commit: src/libexec/ld.elf_so/arch/hppa

2011-03-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Mar 14 08:20:15 UTC 2011

Added Files:
src/libexec/ld.elf_so/arch/hppa: mdtls.c

Log Message:
First cut at mdtls.c for hppa.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/libexec/ld.elf_so/arch/hppa/mdtls.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/libexec/ld.elf_so/arch/hppa/mdtls.c
diff -u /dev/null src/libexec/ld.elf_so/arch/hppa/mdtls.c:1.1
--- /dev/null	Mon Mar 14 08:20:15 2011
+++ src/libexec/ld.elf_so/arch/hppa/mdtls.c	Mon Mar 14 08:20:15 2011
@@ -0,0 +1,18 @@
+#include sys/cdefs.h
+
+__RCSID($NetBSD: mdtls.c,v 1.1 2011/03/14 08:20:15 skrll Exp $);
+
+#include sys/tls.h
+#include rtld.h
+
+__dso_public void *__tls_get_addr(int[2]);
+
+void *
+__tls_get_addr(int idx[2])
+{
+	void *p;
+
+__asm volatile(mfctl\t27 /* CR_TLS */, %0 : =r (p));
+
+	return _rtld_tls_get_addr(p, idx[0], idx[1]);
+}



CVS commit: src/libexec/ld.elf_so/arch/hppa

2011-03-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Mar 14 08:21:54 UTC 2011

Modified Files:
src/libexec/ld.elf_so/arch/hppa: hppa_reloc.c

Log Message:
Handle some TLS relocs.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
diff -u src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.35 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.36
--- src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.35	Thu Mar 10 12:53:42 2011
+++ src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c	Mon Mar 14 08:21:54 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hppa_reloc.c,v 1.35 2011/03/10 12:53:42 skrll Exp $	*/
+/*	$NetBSD: hppa_reloc.c,v 1.36 2011/03/14 08:21:54 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: hppa_reloc.c,v 1.35 2011/03/10 12:53:42 skrll Exp $);
+__RCSID($NetBSD: hppa_reloc.c,v 1.36 2011/03/14 08:21:54 skrll Exp $);
 #endif /* not lint */
 
 #include stdlib.h
@@ -473,6 +473,32 @@
 			rdbg((COPY (avoid in main)));
 			break;
 
+		case R_TYPE(TLS_DTPMOD32):
+			def = _rtld_find_symdef(symnum, obj, defobj, false);
+			if (def == NULL)
+return -1;
+
+			*where = (Elf_Addr)(defobj-tlsindex);
+
+			rdbg((TLS_DTPMOD32 %s in %s -- %p,
+			obj-strtab + obj-symtab[symnum].st_name,
+			obj-path, (void *)*where));
+
+			break;
+
+		case R_TYPE(TLS_DTPOFF32):
+			def = _rtld_find_symdef(symnum, obj, defobj, false);
+			if (def == NULL)
+return -1;
+
+			*where = (Elf_Addr)(def-st_value);
+
+			rdbg((TLS_DTPOFF32 %s in %s -- %p,
+			obj-strtab + obj-symtab[symnum].st_name,
+			obj-path, (void *)*where));
+
+			break;
+
 		default:
 			rdbg((sym = %lu, type = %lu, offset = %p, 
 			addend = %p, contents = %p, symbol = %s,



CVS commit: src/libexec/ld.elf_so/arch/hppa

2011-03-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Mar 14 08:49:29 UTC 2011

Modified Files:
src/libexec/ld.elf_so/arch/hppa: hppa_reloc.c

Log Message:
More PLABELS are required due to TLS stuff.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
diff -u src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.36 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.37
--- src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.36	Mon Mar 14 08:21:54 2011
+++ src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c	Mon Mar 14 08:49:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hppa_reloc.c,v 1.36 2011/03/14 08:21:54 skrll Exp $	*/
+/*	$NetBSD: hppa_reloc.c,v 1.37 2011/03/14 08:49:29 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: hppa_reloc.c,v 1.36 2011/03/14 08:21:54 skrll Exp $);
+__RCSID($NetBSD: hppa_reloc.c,v 1.37 2011/03/14 08:49:29 skrll Exp $);
 #endif /* not lint */
 
 #include stdlib.h
@@ -114,7 +114,7 @@
  * Because I'm hesitant to use NEW while relocating self,
  * this is a small pool of preallocated PLABELs.
  */
-#define	HPPA_PLABEL_PRE	(14)
+#define	HPPA_PLABEL_PRE	(18)
 static hppa_plabel hppa_plabel_pre[HPPA_PLABEL_PRE];
 static int hppa_plabel_pre_next = 0;
 



CVS commit: src/crypto/dist/ipsec-tools/src/racoon

2011-03-14 Thread VANHULLEBUS Yvan
Module Name:src
Committed By:   vanhu
Date:   Mon Mar 14 09:19:24 UTC 2011

Modified Files:
src/crypto/dist/ipsec-tools/src/racoon: handler.c

Log Message:
check if we got RMCONF_ERR_MULTIPLE from getrmconf_by_ph1() in 
revalidate_ph1tree_rmconf()


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/crypto/dist/ipsec-tools/src/racoon/handler.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/dist/ipsec-tools/src/racoon/handler.c
diff -u src/crypto/dist/ipsec-tools/src/racoon/handler.c:1.36 src/crypto/dist/ipsec-tools/src/racoon/handler.c:1.37
--- src/crypto/dist/ipsec-tools/src/racoon/handler.c:1.36	Fri Mar 11 14:30:07 2011
+++ src/crypto/dist/ipsec-tools/src/racoon/handler.c	Mon Mar 14 09:19:23 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: handler.c,v 1.36 2011/03/11 14:30:07 vanhu Exp $	*/
+/*	$NetBSD: handler.c,v 1.37 2011/03/14 09:19:23 vanhu Exp $	*/
 
 /* Id: handler.c,v 1.28 2006/05/26 12:17:29 manubsd Exp */
 
@@ -1486,6 +1486,7 @@
 static int revalidate_ph1tree_rmconf(void)
 {
 	struct ph1handle *p, *next;
+	struct remoteconf *rmconf;
 
 	for (p = LIST_FIRST(ph1tree); p; p = next) {
 		next = LIST_NEXT(p, chain);
@@ -1495,9 +1496,11 @@
 		if (p-rmconf == NULL)
 			continue;
 
-		p-rmconf = getrmconf_by_ph1(p);
-		if (p-rmconf == NULL || p-rmconf == RMCONF_ERR_MULTIPLE)
+		rmconf = getrmconf_by_ph1(p);
+		if (rmconf == NULL || rmconf == RMCONF_ERR_MULTIPLE)
 			remove_ph1(p);
+		else
+			p-rmconf = rmconf;
 	}
 
 	return 1;



CVS commit: src/tests/usr.bin/shmif_dumpbus

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 09:25:01 UTC 2011

Modified Files:
src/tests/usr.bin/shmif_dumpbus: t_basic.sh

Log Message:
xfail PR bin/44721


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/shmif_dumpbus/t_basic.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/shmif_dumpbus/t_basic.sh
diff -u src/tests/usr.bin/shmif_dumpbus/t_basic.sh:1.4 src/tests/usr.bin/shmif_dumpbus/t_basic.sh:1.5
--- src/tests/usr.bin/shmif_dumpbus/t_basic.sh:1.4	Sun Mar 13 15:40:01 2011
+++ src/tests/usr.bin/shmif_dumpbus/t_basic.sh	Mon Mar 14 09:25:01 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: t_basic.sh,v 1.4 2011/03/13 15:40:01 pooka Exp $
+#	$NetBSD: t_basic.sh,v 1.5 2011/03/14 09:25:01 pooka Exp $
 #
 # Copyright (c) 2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -69,6 +69,7 @@
 
 	unpack_file d_pcap.out
 	atf_check -s exit:0 -o ignore shmif_dumpbus -p pcap shmbus
+	atf_expect_fail PR bin/44721
 	atf_check -s exit:0 -o file:d_pcap.out -e ignore \
 	tcpdump -tt -n -r pcap
 }



CVS commit: src/usr.bin/shmif_dumpbus

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 11:08:29 UTC 2011

Modified Files:
src/usr.bin/shmif_dumpbus: Makefile shmif_dumpbus.c

Log Message:
* attempt to make this endian-independent (tested only on el)
* write via libpcap (since i thought there would be some fancy
  api to deal with endianness.  after doing 80% of the work i
  noticed there wasn't, but went ahead anyway)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/shmif_dumpbus/Makefile
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/shmif_dumpbus/shmif_dumpbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/shmif_dumpbus/Makefile
diff -u src/usr.bin/shmif_dumpbus/Makefile:1.1 src/usr.bin/shmif_dumpbus/Makefile:1.2
--- src/usr.bin/shmif_dumpbus/Makefile:1.1	Wed Jan 12 16:14:24 2011
+++ src/usr.bin/shmif_dumpbus/Makefile	Mon Mar 14 11:08:28 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.1 2011/01/12 16:14:24 pooka Exp $
+#	$NetBSD: Makefile,v 1.2 2011/03/14 11:08:28 pooka Exp $
 #
 
 .include bsd.own.mk
@@ -10,4 +10,6 @@
 SRCS+=		shmif_dumpbus.c shmif_busops.c
 CPPFLAGS+=	-I${SHMIFD}
 
+LDADD+=		-lpcap
+
 .include bsd.prog.mk

Index: src/usr.bin/shmif_dumpbus/shmif_dumpbus.c
diff -u src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.4 src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.5
--- src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.4	Sat Mar 12 18:27:42 2011
+++ src/usr.bin/shmif_dumpbus/shmif_dumpbus.c	Mon Mar 14 11:08:28 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmif_dumpbus.c,v 1.4 2011/03/12 18:27:42 pooka Exp $	*/
+/*	$NetBSD: shmif_dumpbus.c,v 1.5 2011/03/14 11:08:28 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -34,6 +34,8 @@
 #include sys/mman.h
 #include sys/stat.h
 
+#include machine/bswap.h
+
 #include assert.h
 #include err.h
 #include fcntl.h
@@ -55,20 +57,9 @@
 	exit(1);
 }
 
-/*
- * Apparently pcap uses a non-exported structure as the on-disk
- * packet header.  Since that format isn't very likely to change
- * soon, just define a local version
- */
-struct ondisk_pcaphdr {
-	uint32_t ts_sec;
-	uint32_t ts_usec;
-	uint32_t caplen;
-	uint32_t len;
-
-};
-
 #define BUFSIZE 64*1024
+#define SWAPME(a) (doswap ? bswap32(a) : (a))
+#define SWAPME64(a) (doswap ? bswap64(a) : (a))
 int
 main(int argc, char *argv[])
 {
@@ -77,10 +68,11 @@
 	const char *pcapfile = NULL;
 	uint32_t curbus, buslast;
 	struct shmif_mem *bmem;
-	int fd, pfd, i, ch;
+	int fd, i, ch;
 	int bonus;
 	char *buf;
-	bool hflag = false;
+	bool hflag = false, doswap = false, isstdout;
+	pcap_dumper_t *pdump;
 
 	setprogname(argv[0]);
 	while ((ch = getopt(argc, argv, hp:)) != -1) {
@@ -118,45 +110,37 @@
 		err(1, mmap);
 	bmem = busmem;
 
-	if (bmem-shm_magic != SHMIF_MAGIC)
-		errx(1, %s not a shmif bus, argv[0]);
-	if (bmem-shm_version != SHMIF_VERSION)
+	if (bmem-shm_magic != SHMIF_MAGIC) {
+		if (bmem-shm_magic != bswap32(SHMIF_MAGIC))
+			errx(1, %s not a shmif bus, argv[0]);
+		doswap = 1;
+	}
+	if (SWAPME(bmem-shm_version) != SHMIF_VERSION)
 		errx(1, bus vesrsion %d, program %d,
-		bmem-shm_version, SHMIF_VERSION);
+		SWAPME(bmem-shm_version), SHMIF_VERSION);
 	printf(bus version %d, lock: %d, generation: % PRIu64
 	, firstoff: 0x%04x, lastoff: 0x%04x\n,
-	bmem-shm_version, bmem-shm_lock, bmem-shm_gen,
-	bmem-shm_first, bmem-shm_last);
+	SWAPME(bmem-shm_version), SWAPME(bmem-shm_lock),
+	SWAPME64(bmem-shm_gen),
+	SWAPME(bmem-shm_first), SWAPME(bmem-shm_last));
 
 	if (hflag)
 		exit(0);
 
 	if (pcapfile) {
-		struct pcap_file_header phdr;
-
-		if (strcmp(pcapfile, -) == 0) {
-			pfd = STDOUT_FILENO;
-		} else {
-			pfd = open(pcapfile, O_RDWR | O_CREAT | O_TRUNC, 0777);
-			if (pfd == -1)
-err(1, create pcap dump);
-		}
-
-		memset(phdr, 0, sizeof(phdr));
-		phdr.magic = 0xa1b2c3d4; /* tcpdump magic */
-		phdr.version_major = PCAP_VERSION_MAJOR;
-		phdr.version_minor = PCAP_VERSION_MINOR;
-		phdr.snaplen = 1518;
-		phdr.linktype = DLT_EN10MB;
-
-		if (write(pfd, phdr, sizeof(phdr)) != sizeof(phdr))
-			err(1, phdr write);
+		isstdout = strcmp(pcapfile, -) == 0;
+		pcap_t *pcap = pcap_open_dead(DLT_EN10MB, 1518);
+		pdump = pcap_dump_open(pcap, pcapfile);
+		if (pdump == NULL)
+			err(1, cannot open pcap dump file);
 	} else {
-		pfd = -1; /* XXXgcc */
+		/* XXXgcc */
+		isstdout = false;
+		pdump = NULL;
 	}
 	
-	curbus = bmem-shm_first;
-	buslast = bmem-shm_last;
+	curbus = SWAPME(bmem-shm_first);
+	buslast = SWAPME(bmem-shm_last);
 	if (curbus == BUSMEM_DATASIZE)
 		curbus = 0;
 
@@ -166,9 +150,10 @@
 
 	i = 0;
 	while (curbus = buslast || bonus) {
-		struct ondisk_pcaphdr packhdr;
+		struct pcap_pkthdr packhdr;
 		struct shmif_pkthdr sp;
 		uint32_t oldoff;
+		uint32_t curlen;
 		bool wrap;
 
 		assert(curbus  sb.st_size);
@@ -180,38 +165,39 @@
 			bonus = 0;
 
 		assert(curbus  sb.st_size);
+		curlen = SWAPME(sp.sp_len);
 
-		if (sp.sp_len == 0) {
+		if 

CVS commit: src/usr.bin/shmif_dumpbus

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 11:10:35 UTC 2011

Modified Files:
src/usr.bin/shmif_dumpbus: shmif_dumpbus.c

Log Message:
make the code also correctly correct, not just xxxgcc'ly correct


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/shmif_dumpbus/shmif_dumpbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/shmif_dumpbus/shmif_dumpbus.c
diff -u src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.5 src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.6
--- src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.5	Mon Mar 14 11:08:28 2011
+++ src/usr.bin/shmif_dumpbus/shmif_dumpbus.c	Mon Mar 14 11:10:35 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmif_dumpbus.c,v 1.5 2011/03/14 11:08:28 pooka Exp $	*/
+/*	$NetBSD: shmif_dumpbus.c,v 1.6 2011/03/14 11:10:35 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -171,7 +171,7 @@
 			continue;
 		}
 
-		if (!isstdout)
+		if (pcapfile  !isstdout)
 			printf(packet %d, offset 0x%04x, length 0x%04x, 
 			ts %d/%06d\n, i++, curbus,
 			curlen, SWAPME(sp.sp_sec), SWAPME(sp.sp_usec));



CVS commit: src/usr.bin/shmif_dumpbus

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 11:13:22 UTC 2011

Modified Files:
src/usr.bin/shmif_dumpbus: shmif_dumpbus.c

Log Message:
nd actually make the logic clause correct


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/shmif_dumpbus/shmif_dumpbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/shmif_dumpbus/shmif_dumpbus.c
diff -u src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.6 src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.7
--- src/usr.bin/shmif_dumpbus/shmif_dumpbus.c:1.6	Mon Mar 14 11:10:35 2011
+++ src/usr.bin/shmif_dumpbus/shmif_dumpbus.c	Mon Mar 14 11:13:22 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmif_dumpbus.c,v 1.6 2011/03/14 11:10:35 pooka Exp $	*/
+/*	$NetBSD: shmif_dumpbus.c,v 1.7 2011/03/14 11:13:22 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -138,7 +138,7 @@
 		isstdout = false;
 		pdump = NULL;
 	}
-	
+
 	curbus = SWAPME(bmem-shm_first);
 	buslast = SWAPME(bmem-shm_last);
 	if (curbus == BUSMEM_DATASIZE)
@@ -171,7 +171,7 @@
 			continue;
 		}
 
-		if (pcapfile  !isstdout)
+		if (!(pcapfile  isstdout))
 			printf(packet %d, offset 0x%04x, length 0x%04x, 
 			ts %d/%06d\n, i++, curbus,
 			curlen, SWAPME(sp.sp_sec), SWAPME(sp.sp_usec));



CVS commit: src/lib/libterminfo

2011-03-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Mar 14 11:44:21 UTC 2011

Modified Files:
src/lib/libterminfo: termcap.3

Log Message:
OOPS has been reverted.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libterminfo/termcap.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libterminfo/termcap.3
diff -u src/lib/libterminfo/termcap.3:1.5 src/lib/libterminfo/termcap.3:1.6
--- src/lib/libterminfo/termcap.3:1.5	Sun Mar  6 19:27:51 2011
+++ src/lib/libterminfo/termcap.3	Mon Mar 14 07:44:20 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: termcap.3,v 1.5 2011/03/07 00:27:51 christos Exp $
+.\	$NetBSD: termcap.3,v 1.6 2011/03/14 11:44:20 christos Exp $
 .\
 .\ Copyright (c) 2009 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd March 6, 2011
+.Dd March 14, 2011
 .Dt TERMCAP 3
 .Os
 .Sh NAME
@@ -126,11 +126,17 @@
 in line
 .Fa destline ,
 or
+.Dv NULL
+on error conditions such as out of memory.
+Please note that
+.Fn tgoto
+can return an incomplete value on a malformed input sequence.
+Historically
+.Fn tgoto
+used to return
 .Dq OOPS
-if it could not decode
-a
-.Dv %
-sequence.
+on those conditions, so newer programs should now be checking the return
+value.
 .Sh SEE ALSO
 .Xr terminfo 3 ,
 .Xr terminfo 5



CVS commit: src/usr.sbin/rpcbind

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 12:03:45 UTC 2011

Modified Files:
src/usr.sbin/rpcbind: rpcbind.c

Log Message:
remove unnecessary superuser check -- bind will fail if bind fails


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/rpcbind/rpcbind.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/rpcbind/rpcbind.c
diff -u src/usr.sbin/rpcbind/rpcbind.c:1.15 src/usr.sbin/rpcbind/rpcbind.c:1.16
--- src/usr.sbin/rpcbind/rpcbind.c:1.15	Mon Aug 27 19:53:33 2007
+++ src/usr.sbin/rpcbind/rpcbind.c	Mon Mar 14 12:03:45 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpcbind.c,v 1.15 2007/08/27 19:53:33 dsl Exp $	*/
+/*	$NetBSD: rpcbind.c,v 1.16 2011/03/14 12:03:45 pooka Exp $	*/
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -126,8 +126,6 @@
 			rl.rlim_cur = 128;
 		setrlimit(RLIMIT_NOFILE, rl);
 	}
-	if (geteuid()) /* This command allowed only to root */
-		errx(1, Sorry. You are not superuser);
 	nc_handle = setnetconfig(); 	/* open netconfig file */
 	if (nc_handle == NULL)
 		errx(1, could not read /etc/netconfig);



CVS commit: src

2011-03-14 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Mon Mar 14 13:53:56 UTC 2011

Modified Files:
src/distrib/sets/lists/comp: mi
src/lib/libkrb5: Makefile

Log Message:
Add krb5_{mk,rd}_priv(3) links.


To generate a diff of this commit:
cvs rdiff -u -r1.1598 -r1.1599 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.41 -r1.42 src/lib/libkrb5/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.1598 src/distrib/sets/lists/comp/mi:1.1599
--- src/distrib/sets/lists/comp/mi:1.1598	Sat Mar 12 19:52:46 2011
+++ src/distrib/sets/lists/comp/mi	Mon Mar 14 13:53:55 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.1598 2011/03/12 19:52:46 christos Exp $
+#	$NetBSD: mi,v 1.1599 2011/03/14 13:53:55 njoly Exp $
 #
 # Note: don't delete entries from here - mark them as obsolete instead.
 #
@@ -6904,6 +6904,7 @@
 ./usr/share/man/cat3/krb5_make_principal.0	comp-krb5-catman	kerberos,.cat
 ./usr/share/man/cat3/krb5_max_sockaddr_size.0	comp-krb5-catman	kerberos,.cat
 ./usr/share/man/cat3/krb5_mcc_ops.0		comp-krb5-catman	kerberos,.cat
+./usr/share/man/cat3/krb5_mk_priv.0		comp-krb5-catman	kerberos,.cat
 ./usr/share/man/cat3/krb5_mk_rep.0		comp-krb5-catman	kerberos,.cat
 ./usr/share/man/cat3/krb5_mk_rep_exact.0	comp-krb5-catman	kerberos,.cat
 ./usr/share/man/cat3/krb5_mk_rep_extended.0	comp-krb5-catman	kerberos,.cat
@@ -6953,6 +6954,7 @@
 ./usr/share/man/cat3/krb5_rc_store.0		comp-krb5-catman	kerberos,.cat
 ./usr/share/man/cat3/krb5_rcache.0		comp-krb5-catman	kerberos,.cat
 ./usr/share/man/cat3/krb5_rd_error.0		comp-krb5-catman	kerberos,.cat
+./usr/share/man/cat3/krb5_rd_priv.0		comp-krb5-catman	kerberos,.cat
 ./usr/share/man/cat3/krb5_rd_rep.0		comp-krb5-catman	kerberos,.cat
 ./usr/share/man/cat3/krb5_rd_req.0		comp-krb5-catman	kerberos,.cat
 ./usr/share/man/cat3/krb5_rd_req_with_keyblock.0	comp-krb5-catman	kerberos,.cat
@@ -12969,6 +12971,7 @@
 ./usr/share/man/html3/krb5_make_principal.html	comp-krb5-htmlman	kerberos,html
 ./usr/share/man/html3/krb5_max_sockaddr_size.html	comp-krb5-htmlman	kerberos,html
 ./usr/share/man/html3/krb5_mcc_ops.html		comp-krb5-htmlman	kerberos,html
+./usr/share/man/html3/krb5_mk_priv.html		comp-krb5-htmlman	kerberos,html
 ./usr/share/man/html3/krb5_mk_rep.html		comp-krb5-htmlman	kerberos,html
 ./usr/share/man/html3/krb5_mk_rep_exact.html	comp-krb5-htmlman	kerberos,html
 ./usr/share/man/html3/krb5_mk_rep_extended.html	comp-krb5-htmlman	kerberos,html
@@ -13017,6 +13020,7 @@
 ./usr/share/man/html3/krb5_rc_store.html	comp-krb5-htmlman	kerberos,html
 ./usr/share/man/html3/krb5_rcache.html		comp-krb5-htmlman	kerberos,html
 ./usr/share/man/html3/krb5_rd_error.html	comp-krb5-htmlman	kerberos,html
+./usr/share/man/html3/krb5_rd_priv.html		comp-krb5-htmlman	kerberos,html
 ./usr/share/man/html3/krb5_rd_rep.html		comp-krb5-htmlman	kerberos,html
 ./usr/share/man/html3/krb5_rd_req.html		comp-krb5-htmlman	kerberos,html
 ./usr/share/man/html3/krb5_rd_req_with_keyblock.html	comp-krb5-htmlman	kerberos,html
@@ -18956,6 +18960,7 @@
 ./usr/share/man/man3/krb5_make_principal.3	comp-krb5-man		kerberos,.man
 ./usr/share/man/man3/krb5_max_sockaddr_size.3	comp-krb5-man		kerberos,.man
 ./usr/share/man/man3/krb5_mcc_ops.3		comp-krb5-man		kerberos,.man
+./usr/share/man/man3/krb5_mk_priv.3		comp-krb5-man		kerberos,.man
 ./usr/share/man/man3/krb5_mk_rep.3		comp-krb5-man		kerberos,.man
 ./usr/share/man/man3/krb5_mk_rep_exact.3	comp-krb5-man		kerberos,.man
 ./usr/share/man/man3/krb5_mk_rep_extended.3	comp-krb5-man		kerberos,.man
@@ -19005,6 +19010,7 @@
 ./usr/share/man/man3/krb5_rc_store.3		comp-krb5-man		kerberos,.man
 ./usr/share/man/man3/krb5_rcache.3		comp-krb5-man		kerberos,.man
 ./usr/share/man/man3/krb5_rd_error.3		comp-krb5-man		kerberos,.man
+./usr/share/man/man3/krb5_rd_priv.3		comp-krb5-man		kerberos,.man
 ./usr/share/man/man3/krb5_rd_rep.3		comp-krb5-man		kerberos,.man
 ./usr/share/man/man3/krb5_rd_req.3		comp-krb5-man		kerberos,.man
 ./usr/share/man/man3/krb5_rd_req_with_keyblock.3	comp-krb5-man		kerberos,.man

Index: src/lib/libkrb5/Makefile
diff -u src/lib/libkrb5/Makefile:1.41 src/lib/libkrb5/Makefile:1.42
--- src/lib/libkrb5/Makefile:1.41	Mon Jul 20 12:16:37 2009
+++ src/lib/libkrb5/Makefile	Mon Mar 14 13:53:56 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.41 2009/07/20 12:16:37 skrll Exp $
+# $NetBSD: Makefile,v 1.42 2011/03/14 13:53:56 njoly Exp $
 
 USE_FORT?= yes	# network protocol library
 
@@ -531,6 +531,7 @@
 	krb5_krbhst_init.3		krb5_krbhst_next.3		\
 	krb5_krbhst_init.3		krb5_krbhst_next_as_string.3	\
 	krb5_krbhst_init.3		krb5_krbhst_reset.3		\
+	krb5_mk_safe.3			krb5_mk_priv.3			\
 	krb5_mk_req.3			krb5_build_ap_req.3		\
 	krb5_mk_req.3			krb5_mk_rep.3			\
 	krb5_mk_req.3			krb5_mk_rep_exact.3		\
@@ -597,6 +598,7 @@
 	krb5_rd_error.3			krb5_error_from_rd_error.3	\
 	krb5_rd_error.3			krb5_free_error.3		\
 	krb5_rd_error.3			

CVS commit: src/crypto/dist/ipsec-tools/src/racoon

2011-03-14 Thread VANHULLEBUS Yvan
Module Name:src
Committed By:   vanhu
Date:   Mon Mar 14 14:54:07 UTC 2011

Modified Files:
src/crypto/dist/ipsec-tools/src/racoon: handler.c

Log Message:
removed an useless comment


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/crypto/dist/ipsec-tools/src/racoon/handler.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/dist/ipsec-tools/src/racoon/handler.c
diff -u src/crypto/dist/ipsec-tools/src/racoon/handler.c:1.37 src/crypto/dist/ipsec-tools/src/racoon/handler.c:1.38
--- src/crypto/dist/ipsec-tools/src/racoon/handler.c:1.37	Mon Mar 14 09:19:23 2011
+++ src/crypto/dist/ipsec-tools/src/racoon/handler.c	Mon Mar 14 14:54:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: handler.c,v 1.37 2011/03/14 09:19:23 vanhu Exp $	*/
+/*	$NetBSD: handler.c,v 1.38 2011/03/14 14:54:07 vanhu Exp $	*/
 
 /* Id: handler.c,v 1.28 2006/05/26 12:17:29 manubsd Exp */
 
@@ -1447,7 +1447,6 @@
 		 * - delete SPIs in kernel
 		 * - delete generated SPD
 		 * - unbind / rem / del ph2
-		 * - XXX shoudld also send a delete-sa !?
 		 */
 		purge_ipsec_spi(iph2-dst, iph2-approval-head-proto_id,
 		spis, 2);



CVS commit: src/lib/librumphijack

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 15:13:26 UTC 2011

Modified Files:
src/lib/librumphijack: hijack.c

Log Message:
Make fdoffset configurable.  Also, enforce that host descriptors
are smaller than the offset.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/lib/librumphijack/hijack.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumphijack/hijack.c
diff -u src/lib/librumphijack/hijack.c:1.84 src/lib/librumphijack/hijack.c:1.85
--- src/lib/librumphijack/hijack.c:1.84	Thu Mar 10 23:02:56 2011
+++ src/lib/librumphijack/hijack.c	Mon Mar 14 15:13:26 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: hijack.c,v 1.84 2011/03/10 23:02:56 pooka Exp $	*/
+/*  $NetBSD: hijack.c,v 1.85 2011/03/14 15:13:26 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: hijack.c,v 1.84 2011/03/10 23:02:56 pooka Exp $);
+__RCSID($NetBSD: hijack.c,v 1.85 2011/03/14 15:13:26 pooka Exp $);
 
 #define __ssp_weak_name(fun) _hijack_ ## fun
 
@@ -274,6 +274,9 @@
 static bool		fd_isrump(int);
 static enum pathtype	path_isrump(const char *);
 
+/* default FD_SETSIZE is 256 == default fdoff is 128 */
+static int hijack_fdoff = FD_SETSIZE/2;
+
 /*
  * Maintain a mapping table for the usual dup2 suspects.
  * Could use atomic ops to operate on dup2vec, but an application
@@ -647,6 +650,23 @@
 	errx(1, sysctl value should be y(es)/n(o), gave: %s, buf);
 }
 
+static void
+fdoffparser(char *buf)
+{
+	unsigned long fdoff;
+	char *ep;
+
+	if (*buf == '-') {
+		errx(1, fdoff must not be negative);
+	}
+	fdoff = strtoul(buf, ep, 10);
+	if (*ep != '\0')
+		errx(1, invalid fdoff specifier \%s\, buf);
+	if (fdoff = INT_MAX/2 || fdoff  3)
+		errx(1, fdoff out of range);
+	hijack_fdoff = fdoff;
+}
+
 static struct {
 	void (*parsefn)(char *);
 	const char *name;
@@ -657,6 +677,7 @@
 	{ blanketparser, blanket, true },
 	{ vfsparser, vfs, true },
 	{ sysctlparser, sysctl, false },
+	{ fdoffparser, fdoffset, true },
 	{ NULL, NULL, false },
 };
 
@@ -783,16 +804,13 @@
 	}
 }
 
-/* Need runtime selection.  low for now due to FD_SETSIZE */
-#define HIJACK_FDOFF 128
-
 static int
 fd_rump2host(int fd)
 {
 
 	if (fd == -1)
 		return fd;
-	return fd + HIJACK_FDOFF;
+	return fd + hijack_fdoff;
 }
 
 static int
@@ -814,7 +832,7 @@
 {
 
 	if (!isdup2d(fd))
-		return fd - HIJACK_FDOFF;
+		return fd - hijack_fdoff;
 	else
 		return mapdup2(fd);
 }
@@ -823,10 +841,10 @@
 fd_isrump(int fd)
 {
 
-	return isdup2d(fd) || fd = HIJACK_FDOFF;
+	return isdup2d(fd) || fd = hijack_fdoff;
 }
 
-#define assertfd(_fd_) assert(ISDUP2D(_fd_) || (_fd_) = HIJACK_FDOFF)
+#define assertfd(_fd_) assert(ISDUP2D(_fd_) || (_fd_) = hijack_fdoff)
 
 static enum pathtype
 path_isrump(const char *path)
@@ -885,8 +903,8 @@
 	if (fd_isrump(oldd)) {
 		op_fcntl = GETSYSCALL(rump, FCNTL);
 		oldd = fd_host2rump(oldd);
-		if (minfd = HIJACK_FDOFF)
-			minfd -= HIJACK_FDOFF;
+		if (minfd = hijack_fdoff)
+			minfd -= hijack_fdoff;
 		isrump = 1;
 	} else {
 		op_fcntl = GETSYSCALL(host, FCNTL);
@@ -903,15 +921,22 @@
 }
 
 /*
- * dup a host file descriptor so that it doesn't collide with the dup2mask
+ * Check that host fd value does not exceed fdoffset and if necessary
+ * dup the file descriptor so that it doesn't collide with the dup2mask.
  */
 static int
-fd_dupgood(int fd)
+fd_host2host(int fd)
 {
 	int (*op_fcntl)(int, int, ...) = GETSYSCALL(host, FCNTL);
 	int (*op_close)(int) = GETSYSCALL(host, CLOSE);
 	int ofd, i;
 
+	if (fd = hijack_fdoff) {
+		op_close(fd);
+		errno = ENFILE;
+		return -1;
+	}
+
 	for (i = 1; isdup2d(fd); i++) {
 		ofd = fd;
 		fd = op_fcntl(ofd, F_DUPFD, i);
@@ -949,7 +974,7 @@
 	if (isrump)
 		fd = fd_rump2host(fd);
 	else
-		fd = fd_dupgood(fd);
+		fd = fd_host2host(fd);
 
 	DPRINTF((open - %d (%s)\n, fd, whichfd(fd)));
 	return fd;
@@ -1099,7 +1124,7 @@
 	if (isrump)
 		fd = fd_rump2host(fd);
 	else
-		fd = fd_dupgood(fd);
+		fd = fd_host2host(fd);
 	DPRINTF((socket - %d\n, fd));
 
 	return fd;
@@ -1125,7 +1150,7 @@
 	if (fd != -1  isrump)
 		fd = fd_rump2host(fd);
 	else
-		fd = fd_dupgood(fd);
+		fd = fd_host2host(fd);
 
 	DPRINTF(( - %d\n, fd));
 
@@ -1177,7 +1202,7 @@
 		 * So, if fd  HIJACKOFF, we want to do a host closem.
 		 */
 
-		if (fd  HIJACK_FDOFF) {
+		if (fd  hijack_fdoff) {
 			int closemfd = fd;
 
 			if (rumpclient__closenotify(closemfd,
@@ -1203,8 +1228,8 @@
 			}
 		}
 		
-		if (fd = HIJACK_FDOFF)
-			fd -= HIJACK_FDOFF;
+		if (fd = hijack_fdoff)
+			fd -= hijack_fdoff;
 		else
 			fd = 0;
 		fd = MAX(maxdup2+1, fd);



CVS commit: src/lib/librumphijack

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 15:15:47 UTC 2011

Modified Files:
src/lib/librumphijack: hijack.c

Log Message:
fdoff is descriptive enough


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/lib/librumphijack/hijack.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumphijack/hijack.c
diff -u src/lib/librumphijack/hijack.c:1.85 src/lib/librumphijack/hijack.c:1.86
--- src/lib/librumphijack/hijack.c:1.85	Mon Mar 14 15:13:26 2011
+++ src/lib/librumphijack/hijack.c	Mon Mar 14 15:15:47 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: hijack.c,v 1.85 2011/03/14 15:13:26 pooka Exp $	*/
+/*  $NetBSD: hijack.c,v 1.86 2011/03/14 15:15:47 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: hijack.c,v 1.85 2011/03/14 15:13:26 pooka Exp $);
+__RCSID($NetBSD: hijack.c,v 1.86 2011/03/14 15:15:47 pooka Exp $);
 
 #define __ssp_weak_name(fun) _hijack_ ## fun
 
@@ -677,7 +677,7 @@
 	{ blanketparser, blanket, true },
 	{ vfsparser, vfs, true },
 	{ sysctlparser, sysctl, false },
-	{ fdoffparser, fdoffset, true },
+	{ fdoffparser, fdoff, true },
 	{ NULL, NULL, false },
 };
 



CVS commit: src/lib/librumphijack

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 15:21:23 UTC 2011

Modified Files:
src/lib/librumphijack: rumphijack.3

Log Message:
document fdoff


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/librumphijack/rumphijack.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumphijack/rumphijack.3
diff -u src/lib/librumphijack/rumphijack.3:1.11 src/lib/librumphijack/rumphijack.3:1.12
--- src/lib/librumphijack/rumphijack.3:1.11	Thu Mar 10 08:53:04 2011
+++ src/lib/librumphijack/rumphijack.3	Mon Mar 14 15:21:22 2011
@@ -1,4 +1,4 @@
-.\ $NetBSD: rumphijack.3,v 1.11 2011/03/10 08:53:04 wiz Exp $
+.\ $NetBSD: rumphijack.3,v 1.12 2011/03/14 15:21:22 pooka Exp $
 .\
 .\ Copyright (c) 2011 Antti Kantee.  All rights reserved.
 .\
@@ -23,7 +23,7 @@
 .\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\ SUCH DAMAGE.
 .\
-.Dd March 9, 2011
+.Dd March 14, 2011
 .Dt RUMPHIJACK 3
 .Os
 .Sh NAME
@@ -173,6 +173,16 @@
 and
 .Dq no ,
 meaning to call the rump or the host kernel, respectively.
+.It Dq fdoff
+Adjust the library's fd offset to the specified value.
+All rump kernel descriptors have the offset added to them
+before they are returned to the application.
+This should be changed only if the application defines a low non-default
+.Dv FD_SETSIZE
+for
+.Fn select
+or if it opens a very large number of file descriptors.
+The default value is 128.
 .El
 .Pp
 If the environment variable is unset, the default value



CVS commit: src/crypto/dist/ipsec-tools/src/racoon

2011-03-14 Thread VANHULLEBUS Yvan
Module Name:src
Committed By:   vanhu
Date:   Mon Mar 14 15:50:37 UTC 2011

Modified Files:
src/crypto/dist/ipsec-tools/src/racoon: cfparse.y isakmp_xauth.c
isakmp_xauth.h remoteconf.c remoteconf.h rsalist.c rsalist.h

Log Message:
avoid some memory leaks / free memory access when reloading conf and have 
inherited config. patch from Roman Hoog Antink r...@open.ch


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/crypto/dist/ipsec-tools/src/racoon/cfparse.y
cvs rdiff -u -r1.21 -r1.22 \
src/crypto/dist/ipsec-tools/src/racoon/isakmp_xauth.c
cvs rdiff -u -r1.6 -r1.7 \
src/crypto/dist/ipsec-tools/src/racoon/isakmp_xauth.h
cvs rdiff -u -r1.25 -r1.26 \
src/crypto/dist/ipsec-tools/src/racoon/remoteconf.c
cvs rdiff -u -r1.15 -r1.16 \
src/crypto/dist/ipsec-tools/src/racoon/remoteconf.h
cvs rdiff -u -r1.5 -r1.6 src/crypto/dist/ipsec-tools/src/racoon/rsalist.c \
src/crypto/dist/ipsec-tools/src/racoon/rsalist.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/dist/ipsec-tools/src/racoon/cfparse.y
diff -u src/crypto/dist/ipsec-tools/src/racoon/cfparse.y:1.41 src/crypto/dist/ipsec-tools/src/racoon/cfparse.y:1.42
--- src/crypto/dist/ipsec-tools/src/racoon/cfparse.y:1.41	Wed Mar  2 14:58:27 2011
+++ src/crypto/dist/ipsec-tools/src/racoon/cfparse.y	Mon Mar 14 15:50:36 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cfparse.y,v 1.41 2011/03/02 14:58:27 vanhu Exp $	*/
+/*	$NetBSD: cfparse.y,v 1.42 2011/03/14 15:50:36 vanhu Exp $	*/
 
 /* Id: cfparse.y,v 1.66 2006/08/22 18:17:17 manubsd Exp */
 
@@ -145,6 +145,7 @@
 
 static struct secprotospec *newspspec __P((void));
 static void insspspec __P((struct remoteconf *, struct secprotospec *));
+void dupspspec_list __P((struct remoteconf *dst, struct remoteconf *src));
 void flushspspec __P((struct remoteconf *));
 static void adminsock_conf __P((vchar_t *, vchar_t *, vchar_t *, int));
 
@@ -1629,7 +1630,7 @@
 return -1;
 			}
 
-			new = duprmconf(from);
+			new = duprmconf_shallow(from);
 			if (new == NULL) {
 yyerror(failed to duplicate remoteconf from \%s\.,
 	$4-v);
@@ -1674,13 +1675,14 @@
 return -1;
 			}
 
-			new = duprmconf(from);
+			new = duprmconf_shallow(from);
 			if (new == NULL) {
 yyerror(failed to duplicate remoteconf from %s.,
 	saddr2str($4));
 return -1;
 			}
 
+			racoon_free($4);
 			new-remote = $2;
 			cur_rmconf = new;
 		}
@@ -1727,11 +1729,19 @@
 	return -1;
 }
 			}
-			
+
+			if (duprmconf_finish(cur_rmconf))
+return -1;
+
+#if 0
+			/* this pointer copy will never happen, because duprmconf_shallow
+			 * already copied all pointers.
+			 */
 			if (cur_rmconf-spspec == NULL 
 			cur_rmconf-inherited_from != NULL) {
 cur_rmconf-spspec = cur_rmconf-inherited_from-spspec;
 			}
+#endif
 			if (set_isakmp_proposal(cur_rmconf) != 0)
 return -1;
 
@@ -2415,6 +2425,62 @@
 	rmconf-spspec = spspec;
 }
 
+static struct secprotospec *
+dupspspec(spspec)
+	struct secprotospec *spspec;
+{
+	struct secprotospec *new;
+
+	new = newspspec();
+	if (new == NULL) {
+		plog(LLV_ERROR, LOCATION, NULL, 
+		dupspspec: malloc failed\n);
+		return NULL;
+	}
+	memcpy(new, spspec, sizeof(*new));
+
+	if (spspec-gssid) {
+		new-gssid = racoon_strdup(spspec-gssid);
+		STRDUP_FATAL(new-gssid);
+	}
+	if (spspec-remote) {
+		new-remote = racoon_malloc(sizeof(*new-remote));
+		if (new-remote == NULL) {
+			plog(LLV_ERROR, LOCATION, NULL, 
+			dupspspec: malloc failed (remote)\n);
+			return NULL;
+		}
+		memcpy(new-remote, spspec-remote, sizeof(*new-remote));
+	}
+
+	return new;
+}
+
+/*
+ * copy the whole list
+ */
+void
+dupspspec_list(dst, src)
+	struct remoteconf *dst, *src;
+{
+	struct secprotospec *p, *new, *last;
+
+	for(p = src-spspec, last = NULL; p; p = p-next, last = new) {
+		new = dupspspec(p);
+		if (new == NULL)
+			exit(1);
+
+		new-prev = last;
+		new-next = NULL; /* not necessary but clean */
+
+		if (last)
+			last-next = new;
+		else /* first element */
+			dst-spspec = new;
+
+	}
+}
+
 /*
  * delete the whole list
  */
@@ -2430,8 +2496,13 @@
 		if (p-next != NULL)
 			p-next-prev = NULL; /* not necessary but clean */
 
-		racoon_free(p);		  
+		if (p-gssid)
+			racoon_free(p-gssid);
+		if (p-remote)
+			racoon_free(p-remote);
+		racoon_free(p);
 	}
+	rmconf-spspec = NULL;
 }
 
 /* set final acceptable proposal */

Index: src/crypto/dist/ipsec-tools/src/racoon/isakmp_xauth.c
diff -u src/crypto/dist/ipsec-tools/src/racoon/isakmp_xauth.c:1.21 src/crypto/dist/ipsec-tools/src/racoon/isakmp_xauth.c:1.22
--- src/crypto/dist/ipsec-tools/src/racoon/isakmp_xauth.c:1.21	Mon Sep 27 11:57:59 2010
+++ src/crypto/dist/ipsec-tools/src/racoon/isakmp_xauth.c	Mon Mar 14 15:50:36 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: isakmp_xauth.c,v 1.21 2010/09/27 11:57:59 vanhu Exp $	*/
+/*	$NetBSD: isakmp_xauth.c,v 1.22 2011/03/14 15:50:36 vanhu Exp $	*/
 
 /* Id: isakmp_xauth.c,v 

CVS commit: src/tests/lib/librumphijack

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 15:56:41 UTC 2011

Modified Files:
src/tests/lib/librumphijack: h_client.c
Added Files:
src/tests/lib/librumphijack: t_config.sh

Log Message:
test RUMPHIJACK fdoff=8


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/librumphijack/h_client.c
cvs rdiff -u -r0 -r1.1 src/tests/lib/librumphijack/t_config.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/librumphijack/h_client.c
diff -u src/tests/lib/librumphijack/h_client.c:1.5 src/tests/lib/librumphijack/h_client.c:1.6
--- src/tests/lib/librumphijack/h_client.c:1.5	Tue Mar  8 14:53:03 2011
+++ src/tests/lib/librumphijack/h_client.c	Mon Mar 14 15:56:40 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: h_client.c,v 1.5 2011/03/08 14:53:03 pooka Exp $	*/
+/*	$NetBSD: h_client.c,v 1.6 2011/03/14 15:56:40 pooka Exp $	*/
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -113,6 +113,21 @@
 			errx(1, poll unexpected revents);
 
 		exit(0);
+	} else if (strcmp(argv[1], fdoff8) == 0) {
+		int fd;
+
+		do
+			if ((fd = open(/dev/null, O_RDWR)) == -1)
+err(1, open1);
+		while (fd  7);
+		fd = open(/dev/null, O_RDWR);
+		if (fd != -1 || errno != ENFILE)
+			errx(1, unexpected fd8 %d %d, fd, errno);
+		if (fcntl(0, F_MAXFD) != 7)
+			errx(1, fd leak?);
+		if ((fd = open(/rump/dev/null, O_RDWR)) != 8)
+			errx(1, rump open %d %d, fd, errno);
+		exit(0);
 	} else {
 		return ENOTSUP;
 	}

Added files:

Index: src/tests/lib/librumphijack/t_config.sh
diff -u /dev/null src/tests/lib/librumphijack/t_config.sh:1.1
--- /dev/null	Mon Mar 14 15:56:41 2011
+++ src/tests/lib/librumphijack/t_config.sh	Mon Mar 14 15:56:40 2011
@@ -0,0 +1,54 @@
+#   $NetBSD: t_config.sh,v 1.1 2011/03/14 15:56:40 pooka Exp $
+#
+# Copyright (c) 2011 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+rumpsrv='rump_server -lrumpvfs'
+export RUMP_SERVER=unix://csock
+
+atf_test_case fdoff cleanup
+fdoff_head()
+{
+atf_set descr RUMPHIJACK fdoff=8
+}
+
+fdoff_body()
+{
+
+	atf_check -s exit:0 rump_server -lrumpvfs ${RUMP_SERVER}
+	export RUMPHIJACK=path=/rump,fdoff=8
+	atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
+	$(atf_get_srcdir)/h_client fdoff8
+}
+
+fdoff_cleanup()
+{
+	rump.halt
+}
+
+atf_init_test_cases()
+{
+	atf_add_test_case fdoff
+}



CVS commit: src/tests/lib/librumphijack

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 15:57:23 UTC 2011

Modified Files:
src/tests/lib/librumphijack: Makefile

Log Message:
test RUMPHIJACK fdoff=8


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/librumphijack/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/librumphijack/Makefile
diff -u src/tests/lib/librumphijack/Makefile:1.6 src/tests/lib/librumphijack/Makefile:1.7
--- src/tests/lib/librumphijack/Makefile:1.6	Thu Mar  3 11:54:11 2011
+++ src/tests/lib/librumphijack/Makefile	Mon Mar 14 15:57:23 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.6 2011/03/03 11:54:11 pooka Exp $
+#	$NetBSD: Makefile,v 1.7 2011/03/14 15:57:23 pooka Exp $
 #
 
 .include bsd.own.mk
@@ -6,6 +6,7 @@
 TESTSDIR=	${TESTSBASE}/lib/librumphijack
 
 TESTS_SH=	t_asyncio
+TESTS_SH+=	t_config
 TESTS_SH+=	t_cwd
 TESTS_SH+=	t_sh
 TESTS_SH+=	t_tcpip



CVS commit: src/distrib/sets/lists/tests

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 15:57:34 UTC 2011

Modified Files:
src/distrib/sets/lists/tests: mi

Log Message:
test RUMPHIJACK fdoff=8


To generate a diff of this commit:
cvs rdiff -u -r1.270 -r1.271 src/distrib/sets/lists/tests/mi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.270 src/distrib/sets/lists/tests/mi:1.271
--- src/distrib/sets/lists/tests/mi:1.270	Sat Mar 12 14:03:38 2011
+++ src/distrib/sets/lists/tests/mi	Mon Mar 14 15:57:33 2011
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.270 2011/03/12 14:03:38 bouyer Exp $
+# $NetBSD: mi,v 1.271 2011/03/14 15:57:33 pooka Exp $
 #
 # Note: don't delete entries from here - mark them as obsolete instead.
 #
@@ -1964,6 +1964,7 @@
 ./usr/tests/lib/librumphijack/index.html			tests-lib-tests		atf
 ./usr/tests/lib/librumphijack/netstat.expout			tests-lib-tests		atf
 ./usr/tests/lib/librumphijack/t_asyncio			tests-lib-tests		atf
+./usr/tests/lib/librumphijack/t_config			tests-lib-tests		atf
 ./usr/tests/lib/librumphijack/t_cwd			tests-lib-tests		atf
 ./usr/tests/lib/librumphijack/t_sh			tests-lib-tests		atf
 ./usr/tests/lib/librumphijack/t_tcpip			tests-lib-tests		atf



CVS commit: src/crypto/dist/ipsec-tools/src/racoon

2011-03-14 Thread Timo Teräs
Module Name:src
Committed By:   tteras
Date:   Mon Mar 14 17:18:13 UTC 2011

Modified Files:
src/crypto/dist/ipsec-tools/src/racoon: grabmyaddr.c handler.c isakmp.c
isakmp_inf.c isakmp_quick.c nattraversal.c pfkey.c policy.c
sockmisc.c sockmisc.h throttle.c

Log Message:
Explicitly compare return value of cmpsaddr() against a return value
define to make it more obvious what is the intended action. One more
return value is also added, to fix comparison of security policy
descriptors. Namely, getsp() should not allow wildcard matching (as the
comment says, it does exact matching) - otherwise we get problems when
kernel has generic policy with no ports, and a second similar policy with
ports.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 \
src/crypto/dist/ipsec-tools/src/racoon/grabmyaddr.c
cvs rdiff -u -r1.38 -r1.39 src/crypto/dist/ipsec-tools/src/racoon/handler.c
cvs rdiff -u -r1.69 -r1.70 src/crypto/dist/ipsec-tools/src/racoon/isakmp.c
cvs rdiff -u -r1.45 -r1.46 \
src/crypto/dist/ipsec-tools/src/racoon/isakmp_inf.c
cvs rdiff -u -r1.28 -r1.29 \
src/crypto/dist/ipsec-tools/src/racoon/isakmp_quick.c
cvs rdiff -u -r1.13 -r1.14 \
src/crypto/dist/ipsec-tools/src/racoon/nattraversal.c
cvs rdiff -u -r1.55 -r1.56 src/crypto/dist/ipsec-tools/src/racoon/pfkey.c
cvs rdiff -u -r1.11 -r1.12 src/crypto/dist/ipsec-tools/src/racoon/policy.c
cvs rdiff -u -r1.18 -r1.19 src/crypto/dist/ipsec-tools/src/racoon/sockmisc.c
cvs rdiff -u -r1.12 -r1.13 src/crypto/dist/ipsec-tools/src/racoon/sockmisc.h
cvs rdiff -u -r1.6 -r1.7 src/crypto/dist/ipsec-tools/src/racoon/throttle.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/dist/ipsec-tools/src/racoon/grabmyaddr.c
diff -u src/crypto/dist/ipsec-tools/src/racoon/grabmyaddr.c:1.27 src/crypto/dist/ipsec-tools/src/racoon/grabmyaddr.c:1.28
--- src/crypto/dist/ipsec-tools/src/racoon/grabmyaddr.c:1.27	Fri Dec  3 09:46:24 2010
+++ src/crypto/dist/ipsec-tools/src/racoon/grabmyaddr.c	Mon Mar 14 17:18:12 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: grabmyaddr.c,v 1.27 2010/12/03 09:46:24 tteras Exp $	*/
+/*	$NetBSD: grabmyaddr.c,v 1.28 2011/03/14 17:18:12 tteras Exp $	*/
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  * Copyright (C) 2008 Timo Teras timo.te...@iki.fi.
@@ -100,7 +100,7 @@
 		return TRUE;
 
 	LIST_FOREACH(cfg, configured, chain) {
-		if (cmpsaddr(addr, (struct sockaddr *) cfg-addr) == 0)
+		if (cmpsaddr(addr, (struct sockaddr *) cfg-addr) = CMPSADDR_WILDPORT_MATCH)
 			return TRUE;
 	}
 
@@ -116,7 +116,7 @@
 
 	/* Already open? */
 	LIST_FOREACH(my, opened, chain) {
-		if (cmpsaddr(addr, (struct sockaddr *) my-addr) == 0)
+		if (cmpsaddr(addr, (struct sockaddr *) my-addr) = CMPSADDR_WILDPORT_MATCH)
 			return TRUE;
 	}
 
@@ -156,7 +156,7 @@
 
 	LIST_FOREACH(cfg, configured, chain) {
 		if (addr != NULL 
-		cmpsaddr(addr, (struct sockaddr *) cfg-addr) != 0)
+		cmpsaddr(addr, (struct sockaddr *) cfg-addr)  CMPSADDR_WILDPORT_MATCH)
 			continue;
 		if (!myaddr_open((struct sockaddr *) cfg-addr, cfg-udp_encap))
 			return FALSE;
@@ -262,7 +262,7 @@
 	struct myaddr *my;
 
 	LIST_FOREACH(my, opened, chain) {
-		if (cmpsaddr((struct sockaddr *) my-addr, addr) == 0)
+		if (cmpsaddr((struct sockaddr *) my-addr, addr) = CMPSADDR_WILDPORT_MATCH)
 			return my-fd;
 	}
 
@@ -276,7 +276,7 @@
 	struct myaddr *my;
 
 	LIST_FOREACH(my, opened, chain) {
-		if (cmpsaddr((struct sockaddr *) my-addr, addr) == 0)
+		if (cmpsaddr((struct sockaddr *) my-addr, addr) = CMPSADDR_WILDPORT_MATCH)
 			return extract_port((struct sockaddr *) my-addr);
 	}
 

Index: src/crypto/dist/ipsec-tools/src/racoon/handler.c
diff -u src/crypto/dist/ipsec-tools/src/racoon/handler.c:1.38 src/crypto/dist/ipsec-tools/src/racoon/handler.c:1.39
--- src/crypto/dist/ipsec-tools/src/racoon/handler.c:1.38	Mon Mar 14 14:54:07 2011
+++ src/crypto/dist/ipsec-tools/src/racoon/handler.c	Mon Mar 14 17:18:12 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: handler.c,v 1.38 2011/03/14 14:54:07 vanhu Exp $	*/
+/*	$NetBSD: handler.c,v 1.39 2011/03/14 17:18:12 tteras Exp $	*/
 
 /* Id: handler.c,v 1.28 2006/05/26 12:17:29 manubsd Exp */
 
@@ -120,11 +120,11 @@
 	LIST_FOREACH(p, ph1tree, chain) {
 		if (sel != NULL) {
 			if (sel-local != NULL 
-			cmpsaddr(sel-local, p-local) != 0)
+			cmpsaddr(sel-local, p-local)  CMPSADDR_WILDPORT_MATCH)
 continue;
 
 			if (sel-remote != NULL 
-			cmpsaddr(sel-remote, p-remote) != 0)
+			cmpsaddr(sel-remote, p-remote)  CMPSADDR_WILDPORT_MATCH)
 continue;
 		}
 
@@ -300,8 +300,8 @@
 		if (p-status  PHASE1ST_DYING)
 			continue;
 
-		if (cmpsaddr(iph1-local, p-local) == 0
-		  cmpsaddr(iph1-remote, p-remote) == 0)
+		if (cmpsaddr(iph1-local, p-local) == CMPSADDR_MATCH
+		  cmpsaddr(iph1-remote, p-remote) == CMPSADDR_MATCH)
 			migrate_ph12(p, iph1);
 	}
 }
@@ -547,11 +547,11 @@
 continue;
 
 			if (sel-src 

CVS commit: src/tests/kernel

2011-03-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 14 20:41:25 UTC 2011

Modified Files:
src/tests/kernel: t_posix_fadvise.c

Log Message:
Use /dev/null instead of stdin for fd.  Otherwise if the tests are
run with stdin as a pipe (e.g. from cron) the test fails with ESPIPE.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/t_posix_fadvise.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/t_posix_fadvise.c
diff -u src/tests/kernel/t_posix_fadvise.c:1.5 src/tests/kernel/t_posix_fadvise.c:1.6
--- src/tests/kernel/t_posix_fadvise.c:1.5	Thu Dec 30 22:23:13 2010
+++ src/tests/kernel/t_posix_fadvise.c	Mon Mar 14 20:41:25 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: t_posix_fadvise.c,v 1.5 2010/12/30 22:23:13 pooka Exp $ */
+/* $NetBSD: t_posix_fadvise.c,v 1.6 2011/03/14 20:41:25 pooka Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
 #include sys/cdefs.h
 __COPYRIGHT(@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.);
-__RCSID($NetBSD: t_posix_fadvise.c,v 1.5 2010/12/30 22:23:13 pooka Exp $);
+__RCSID($NetBSD: t_posix_fadvise.c,v 1.6 2011/03/14 20:41:25 pooka Exp $);
 
 #include sys/fcntl.h
 
@@ -88,11 +88,13 @@
 
 ATF_TC_BODY(posix_fadvise, tc)
 {
-	int fd = STDIN_FILENO;
+	int fd;
 	int pipe_fds[2];
 	int badfd = 10;
 	int ret;
 
+	RL(fd = open(/dev/null, O_RDWR));
+
 	(void)close(badfd);
 	RL(pipe(pipe_fds));
 



CVS commit: src/external/cddl/osnet/dist/common/acl

2011-03-14 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Mar 15 00:48:04 UTC 2011

Modified Files:
src/external/cddl/osnet/dist/common/acl: acl_common.c

Log Message:
Don't define acl_alloc and acl_free during kernel builds.
Fixes module build with clang.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/cddl/osnet/dist/common/acl/acl_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/cddl/osnet/dist/common/acl/acl_common.c
diff -u src/external/cddl/osnet/dist/common/acl/acl_common.c:1.3 src/external/cddl/osnet/dist/common/acl/acl_common.c:1.4
--- src/external/cddl/osnet/dist/common/acl/acl_common.c:1.3	Wed Mar  9 23:55:46 2011
+++ src/external/cddl/osnet/dist/common/acl/acl_common.c	Tue Mar 15 00:48:04 2011
@@ -423,6 +423,7 @@
 #endif
 }
 
+#if !defined(_KERNEL)
 acl_t *
 acl_alloc(enum acl_type type)
 {
@@ -468,6 +469,7 @@
 
 	cacl_free(aclp, sizeof (acl_t));
 }
+#endif
 
 static uint32_t
 access_mask_set(int haswriteperm, int hasreadperm, int isowner, int isallow)



CVS commit: src/lib/libc/gen

2011-03-14 Thread Eric Haszlakiewicz
Module Name:src
Committed By:   erh
Date:   Tue Mar 15 03:47:04 UTC 2011

Modified Files:
src/lib/libc/gen: Makefile.inc
Added Files:
src/lib/libc/gen: commaize_number.3 commaize_number.c

Log Message:
PR#7540, add a commaize_number function, which inserts comma into a string
 of digits to make it more readable.  This is soon to be used in /bin/ls.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/lib/libc/gen/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/libc/gen/commaize_number.3 \
src/lib/libc/gen/commaize_number.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/gen/Makefile.inc
diff -u src/lib/libc/gen/Makefile.inc:1.174 src/lib/libc/gen/Makefile.inc:1.175
--- src/lib/libc/gen/Makefile.inc:1.174	Sat Mar 12 19:52:48 2011
+++ src/lib/libc/gen/Makefile.inc	Tue Mar 15 03:47:04 2011
@@ -1,11 +1,12 @@
-#	$NetBSD: Makefile.inc,v 1.174 2011/03/12 19:52:48 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.175 2011/03/15 03:47:04 erh Exp $
 #	from: @(#)Makefile.inc	8.6 (Berkeley) 5/4/95
 
 # gen sources
 .PATH: ${ARCHDIR}/gen ${.CURDIR}/gen
 
 SRCS+= 	_errno.c alarm.c alphasort.c arc4random.c assert.c basename.c clock.c \
-	closedir.c closefrom.c confstr.c ctermid.c ctype_.c daemon.c \
+	closedir.c closefrom.c commaize_number.c \
+	confstr.c ctermid.c ctype_.c daemon.c \
 	dehumanize_number.c devname.c dirname.c disklabel.c err.c errx.c \
 	errlist.c errno.c execl.c execle.c execlp.c execv.c execvp.c \
 	extattr.c fmtcheck.c fmtmsg.c fnmatch.c fstab.c ftok.c \
@@ -50,7 +51,8 @@
 
 .include ${ARCHDIR}/gen/Makefile.inc
 
-MAN+=	alarm.3 arc4random.3 basename.3 bswap.3 clock.3 closefrom.3 confstr.3 \
+MAN+=	alarm.3 arc4random.3 basename.3 bswap.3 clock.3 closefrom.3 \
+	commaize_number.3 confstr.3 \
 	cpuset.3 ctermid.3 ctype.3 daemon.3 devname.3 directory.3 dirname.3 \
 	endutxent.3 err.3 exec.3 extattr.3 \
 	fmtcheck.3 fmtmsg.3 fnmatch.3 fpclassify.3 fpgetmask.3 \

Added files:

Index: src/lib/libc/gen/commaize_number.3
diff -u /dev/null src/lib/libc/gen/commaize_number.3:1.1
--- /dev/null	Tue Mar 15 03:47:04 2011
+++ src/lib/libc/gen/commaize_number.3	Tue Mar 15 03:47:04 2011
@@ -0,0 +1,83 @@
+.\	$NetBSD: commaize_number.3,v 1.1 2011/03/15 03:47:04 erh Exp $
+.\
+.\ Copyright (c) 2011 The NetBSD Foundation, Inc.
+.\ All rights reserved.
+.\
+.\ This code is derived from software contributed to The NetBSD Foundation
+.\ by Eric Haszlakiewicz.
+.\
+.\ Redistribution and use in source and binary forms, with or without
+.\ modification, are permitted provided that the following conditions
+.\ are met:
+.\ 1. Redistributions of source code must retain the above copyright
+.\notice, this list of conditions and the following disclaimer.
+.\ 2. Redistributions in binary form must reproduce the above copyright
+.\notice, this list of conditions and the following disclaimer in the
+.\documentation and/or other materials provided with the distribution.
+.\
+.\ THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\ PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\ POSSIBILITY OF SUCH DAMAGE.
+.\
+.Dd March 12, 2011
+.Dt COMMAIZE_NUMBER 3
+.Os
+.Sh NAME
+.Nm commaize_number
+.Nd format a number into a human readable form by adding commas (actually, the locale specific thousands separator)
+.Sh SYNOPSIS
+.In stdlib.h
+.Ft int
+.Fn commaize_number char *buffer size_t len int64_t number
+.Sh DESCRIPTION
+The
+.Fn commaize_number
+function formats the signed 64 bit quantity given in
+.Fa number
+into
+.Fa buffer ,
+which 
+must be at least
+.Fa len
+bytes long.
+.Pp
+If the formatted number would be too long to fit into
+.Fa buffer ,
+then an error is returned.
+.Sh RETURN VALUES
+.Fn commaize_number
+returns the number of characters stored in
+.Fa buffer
+(excluding the terminating NUL) upon success, or \-1 upon failure with 
+.Va errno
+set to indicate the error.
+.Sh ERRORS
+.Fn commaize_number
+will fail and nothing will be written to
+.Fa buffer
+if:
+.Bl -tag -width Er
+.It Bq Er ENOMEM
+The formatted number, including commas and terminating NUL, is too long to fit in
+.Fa len
+bytes.
+.El
+.Sh SEE ALSO
+.Xr humanize_number 9 ,
+.Xr setlocale 3 ,
+.Xr ls 1 .
+.Sh HISTORY
+.Fn humanize_number
+first appeared in
+.Nx 

CVS commit: src/bin/ls

2011-03-14 Thread Eric Haszlakiewicz
Module Name:src
Committed By:   erh
Date:   Tue Mar 15 03:52:38 UTC 2011

Modified Files:
src/bin/ls: ls.1 ls.c ls.h print.c

Log Message:
PR#7540, add a -M option to ls which causes sizes (and number of blocks) to be
displayed with comma separators (or a locale specific separator).


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/bin/ls/ls.1
cvs rdiff -u -r1.67 -r1.68 src/bin/ls/ls.c
cvs rdiff -u -r1.17 -r1.18 src/bin/ls/ls.h
cvs rdiff -u -r1.48 -r1.49 src/bin/ls/print.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/ls/ls.1
diff -u src/bin/ls/ls.1:1.66 src/bin/ls/ls.1:1.67
--- src/bin/ls/ls.1:1.66	Fri Dec 17 19:20:42 2010
+++ src/bin/ls/ls.1	Tue Mar 15 03:52:37 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: ls.1,v 1.66 2010/12/17 19:20:42 njoly Exp $
+.\	$NetBSD: ls.1,v 1.67 2011/03/15 03:52:37 erh Exp $
 .\
 .\ Copyright (c) 1980, 1990, 1991, 1993, 1994
 .\	The Regents of the University of California.  All rights reserved.
@@ -129,7 +129,9 @@
 options, causing the sizes to be reported in bytes displayed in a human
 readable format.
 Overrides
-.Fl k .
+.Fl k
+and
+.Fl M .
 .It Fl i
 For each file, print the file's file serial number (inode number).
 .It Fl k
@@ -142,7 +144,9 @@
 .Fl h
 flags overrides the previous flag.
 See also
-.Fl h .
+.Fl h 
+and
+.Fl M .
 .It Fl L
 For each file, if it's a link, evaluate file information and file type
 of the referenced file and not the link itself; however still print
@@ -156,6 +160,18 @@
 (See below.)
 A total sum for all the file sizes is output on a line before the long
 listing.
+.It Fl M
+Modifies the
+.Fl l
+and
+.Fl s
+options, causing the sizes or block counts reported to be separated with 
+commas (or a locale appropriate separator) resulting in a more readable
+output.
+Overrides 
+.Fl h .
+Does not override
+.Fl k .
 .It Fl m
 Stream output format; list files across the page, separated by commas.
 .It Fl n

Index: src/bin/ls/ls.c
diff -u src/bin/ls/ls.c:1.67 src/bin/ls/ls.c:1.68
--- src/bin/ls/ls.c:1.67	Thu Jul  8 20:43:34 2010
+++ src/bin/ls/ls.c	Tue Mar 15 03:52:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ls.c,v 1.67 2010/07/08 20:43:34 rmind Exp $	*/
+/*	$NetBSD: ls.c,v 1.68 2011/03/15 03:52:37 erh Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = @(#)ls.c	8.7 (Berkeley) 8/5/94;
 #else
-__RCSID($NetBSD: ls.c,v 1.67 2010/07/08 20:43:34 rmind Exp $);
+__RCSID($NetBSD: ls.c,v 1.68 2011/03/15 03:52:37 erh Exp $);
 #endif
 #endif /* not lint */
 
@@ -91,6 +91,7 @@
 int f_flags;			/* show flags associated with a file */
 int f_grouponly;		/* long listing without owner */
 int f_humanize;			/* humanize the size field */
+int f_commas;   /* separate size field with comma */
 int f_inode;			/* print inode */
 int f_listdir;			/* list actual directory, not contents */
 int f_listdot;			/* list files beginning with . */
@@ -137,7 +138,7 @@
 		f_listdot = 1;
 
 	fts_options = FTS_PHYSICAL;
-	while ((ch = getopt(argc, argv, 1ABCFLRSTWabcdfghiklmnopqrstuwx)) != -1) {
+	while ((ch = getopt(argc, argv, 1ABCFLMRSTWabcdfghiklmnopqrstuwx)) != -1) {
 		switch (ch) {
 		/*
 		 * The -1, -C, -l, -m and -x options all override each other so
@@ -230,6 +231,11 @@
 		case 'h':
 			f_humanize = 1;
 			kflag = 0;
+			f_commas = 0;
+			break;
+		case 'M':
+			f_humanize = 0;
+			f_commas = 1;
 			break;
 		case 'n':
 			f_numericonly = 1;
@@ -603,6 +609,8 @@
 			(void)snprintf(buf, sizeof(buf), %llu,
 			(long long)howmany(maxblock, blocksize));
 			d.s_block = strlen(buf);
+			if (f_commas) /* allow for commas before every third digit */
+d.s_block += (d.s_block - 1) / 3;
 		}
 		d.s_flags = maxflags;
 		d.s_group = maxgroup;
@@ -617,6 +625,8 @@
 			(void)snprintf(buf, sizeof(buf), %llu,
 			(long long)maxsize);
 			d.s_size = strlen(buf);
+			if (f_commas) /* allow for commas before every third digit */
+d.s_size += (d.s_size - 1) / 3;
 		}
 		d.s_user = maxuser;
 		if (bcfile) {

Index: src/bin/ls/ls.h
diff -u src/bin/ls/ls.h:1.17 src/bin/ls/ls.h:1.18
--- src/bin/ls/ls.h:1.17	Sat Feb 14 08:02:04 2009
+++ src/bin/ls/ls.h	Tue Mar 15 03:52:38 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ls.h,v 1.17 2009/02/14 08:02:04 lukem Exp $	*/
+/*	$NetBSD: ls.h,v 1.18 2011/03/15 03:52:38 erh Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,6 +42,7 @@
 extern int f_flags;		/* show flags associated with a file */
 extern int f_grouponly;		/* long listing without owner */
 extern int f_humanize;		/* humanize size field */
+extern int f_commas;/* separate size field with commas */
 extern int f_inode;		/* print inode */
 extern int f_longform;		/* long listing format */
 extern int f_octal;		/* print octal escapes for nongraphic characters */

Index: src/bin/ls/print.c
diff -u src/bin/ls/print.c:1.48 src/bin/ls/print.c:1.49
--- src/bin/ls/print.c:1.48	Wed Aug 18 02:53:54 2010
+++ src/bin/ls/print.c	Tue Mar