[Glibc-bsd-commits] r5141 - in trunk/freebsd-glue: debian src src/crypt src/freebsd-glue src/util src/z

rmh at alioth.debian.org rmh at alioth.debian.org
Thu Nov 28 15:27:16 UTC 2013


Author: rmh
Date: 2013-11-20 13:40:37 +0000 (St, 20 lis 2013)
New Revision: 5141

Added:
   trunk/freebsd-glue/src/Makefile
   trunk/freebsd-glue/src/Makefile.inc
   trunk/freebsd-glue/src/crypt/
   trunk/freebsd-glue/src/crypt/Makefile
   trunk/freebsd-glue/src/crypt/crypt.c
   trunk/freebsd-glue/src/freebsd-glue/
   trunk/freebsd-glue/src/freebsd-glue/Makefile
   trunk/freebsd-glue/src/freebsd-glue/cpuset.c
   trunk/freebsd-glue/src/freebsd-glue/disklabel.c
   trunk/freebsd-glue/src/freebsd-glue/exec.c
   trunk/freebsd-glue/src/freebsd-glue/feature_present.c
   trunk/freebsd-glue/src/freebsd-glue/fstab.c
   trunk/freebsd-glue/src/freebsd-glue/funopen.c
   trunk/freebsd-glue/src/freebsd-glue/getcap.c
   trunk/freebsd-glue/src/freebsd-glue/getosreldate.c
   trunk/freebsd-glue/src/freebsd-glue/linkaddr.c
   trunk/freebsd-glue/src/freebsd-glue/login_class.c
   trunk/freebsd-glue/src/freebsd-glue/mac.c
   trunk/freebsd-glue/src/freebsd-glue/namespace.h
   trunk/freebsd-glue/src/freebsd-glue/random.c
   trunk/freebsd-glue/src/freebsd-glue/socket.c
   trunk/freebsd-glue/src/freebsd-glue/un-namespace.h
   trunk/freebsd-glue/src/get_elf_arch.c
   trunk/freebsd-glue/src/util/
   trunk/freebsd-glue/src/util/Makefile
   trunk/freebsd-glue/src/util/trimdomain.c
   trunk/freebsd-glue/src/z/
   trunk/freebsd-glue/src/z/Makefile
   trunk/freebsd-glue/src/z/zopen.c
Removed:
   trunk/freebsd-glue/src/Makefile
   trunk/freebsd-glue/src/cpuset.c
   trunk/freebsd-glue/src/crypt.c
   trunk/freebsd-glue/src/disklabel.c
   trunk/freebsd-glue/src/exec.c
   trunk/freebsd-glue/src/feature_present.c
   trunk/freebsd-glue/src/fstab.c
   trunk/freebsd-glue/src/funopen.c
   trunk/freebsd-glue/src/get_elf_arch.c
   trunk/freebsd-glue/src/getcap.c
   trunk/freebsd-glue/src/getosreldate.c
   trunk/freebsd-glue/src/linkaddr.c
   trunk/freebsd-glue/src/login_class.c
   trunk/freebsd-glue/src/mac.c
   trunk/freebsd-glue/src/namespace.h
   trunk/freebsd-glue/src/random.c
   trunk/freebsd-glue/src/socket.c
   trunk/freebsd-glue/src/trimdomain.c
   trunk/freebsd-glue/src/un-namespace.h
   trunk/freebsd-glue/src/zopen.c
Modified:
   trunk/freebsd-glue/debian/changelog
   trunk/freebsd-glue/debian/rules
Log:
Split additions for libcrypt, libutil and libz into separate libraries.

Modified: trunk/freebsd-glue/debian/changelog
===================================================================
--- trunk/freebsd-glue/debian/changelog	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/debian/changelog	2013-11-20 13:40:37 UTC (rev 5141)
@@ -6,6 +6,8 @@
   * Move <sys/stdint.h> to <stdint.h>.
   * Add <sys/stdint.h> (as #include stub).
   * Add _PATH_DEVZERO.
+  * Split additions for libcrypt, libutil and libz into separate
+    libraries.
 
  -- Robert Millan <rmh at debian.org>  Fri, 01 Nov 2013 13:38:42 +0100
 

Modified: trunk/freebsd-glue/debian/rules
===================================================================
--- trunk/freebsd-glue/debian/rules	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/debian/rules	2013-11-20 13:40:37 UTC (rev 5141)
@@ -30,7 +30,7 @@
 	dh_prep -a
 	dh_installdirs -a
 	mkdir -p $(DESTDIR)/usr/lib
-	$(PMAKE) install SHLIBDIR=/usr/lib
+	$(PMAKE) install
 	dh_install -a --list-missing
 
 binary: binary-arch binary-indep

Deleted: trunk/freebsd-glue/src/Makefile
===================================================================
--- trunk/freebsd-glue/src/Makefile	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/Makefile	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,36 +0,0 @@
-LIB=	freebsd-glue
-SRCS=	\
-	crypt.c \
-	exec.c \
-	feature_present.c \
-	fstab.c \
-	funopen.c \
-	getcap.c \
-	getosreldate.c \
-	random.c \
-	trimdomain.c \
-	zopen.c \
-	${NULL}
-
-LDADD=	-ldb
-
-CFLAGS = -Wall -g -pipe -fPIC -D_GNU_SOURCE \
-	-Werror \
-	-isystem ../include \
-	-D__FREEBSD_LIBC \
-	${NULL}
-
-SYS!=	dpkg-architecture -qDEB_HOST_GNU_SYSTEM
-
-.if ${SYS} == "kfreebsd-gnu"
-SRCS+=	\
-	cpuset.c \
-	disklabel.c \
-	linkaddr.c \
-	login_class.c \
-	mac.c \
-	socket.c \
-	${NULL}
-.endif
-
-.include <bsd.lib.mk>

Added: trunk/freebsd-glue/src/Makefile
===================================================================
--- trunk/freebsd-glue/src/Makefile	                        (rev 0)
+++ trunk/freebsd-glue/src/Makefile	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,8 @@
+SUBDIR=	\
+	freebsd-glue \
+	util \
+	crypt \
+	z \
+	${NULL}
+
+.include <bsd.subdir.mk>

Added: trunk/freebsd-glue/src/Makefile.inc
===================================================================
--- trunk/freebsd-glue/src/Makefile.inc	                        (rev 0)
+++ trunk/freebsd-glue/src/Makefile.inc	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,8 @@
+#SHLIB_MAJOR = 0
+SHLIBDIR = /lib
+
+CFLAGS = -Wall -g -pipe -fPIC -D_GNU_SOURCE \
+	-Werror \
+	-isystem ../../include \
+	-D__FREEBSD_LIBC \
+	${NULL}

Deleted: trunk/freebsd-glue/src/cpuset.c
===================================================================
--- trunk/freebsd-glue/src/cpuset.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/cpuset.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,34 +0,0 @@
-#include <sys/param.h>
-#include <sys/cpuset.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-
-int
-cpuset (cpusetid_t *setid)
-{
-  return syscall (SYS_cpuset, setid);
-}
-
-int
-cpuset_setid (cpuwhich_t which, id_t id, cpusetid_t setid)
-{
-  return syscall (SYS_cpuset_setid, which, id, setid);
-}
-
-int
-cpuset_getid (cpulevel_t level, cpuwhich_t which, id_t id, cpusetid_t *setid)
-{
-  return syscall (SYS_cpuset_getid, level, which, id, setid);
-}
-
-int
-cpuset_getaffinity (cpulevel_t level, cpuwhich_t which, id_t id, size_t setsize, cpuset_t *mask)
-{
-  return syscall (SYS_cpuset_getaffinity, level, which, id, setsize, mask);
-}
-
-int
-cpuset_setaffinity (cpulevel_t level, cpuwhich_t which, id_t id, size_t setsize, const cpuset_t *mask)
-{
-  return syscall (SYS_cpuset_setaffinity, level, which, id, setsize, mask);
-}

Added: trunk/freebsd-glue/src/crypt/Makefile
===================================================================
--- trunk/freebsd-glue/src/crypt/Makefile	                        (rev 0)
+++ trunk/freebsd-glue/src/crypt/Makefile	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,8 @@
+LIB=	crypt-freebsd
+SRCS=	\
+	crypt.c \
+	${NULL}
+
+LDADD=	-lcrypt
+
+.include <bsd.lib.mk>

Copied: trunk/freebsd-glue/src/crypt/crypt.c (from rev 5123, trunk/freebsd-glue/src/crypt.c)
===================================================================
--- trunk/freebsd-glue/src/crypt/crypt.c	                        (rev 0)
+++ trunk/freebsd-glue/src/crypt/crypt.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,14 @@
+#include <crypt.h>
+#include <string.h>
+
+const char *
+crypt_get_format (void)
+{
+  return "des";
+}
+
+int
+crypt_set_format (const char *string)
+{
+  return !strcmp (string, "des");
+}

Deleted: trunk/freebsd-glue/src/crypt.c
===================================================================
--- trunk/freebsd-glue/src/crypt.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/crypt.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,14 +0,0 @@
-#include <crypt.h>
-#include <string.h>
-
-const char *
-crypt_get_format (void)
-{
-  return "des";
-}
-
-int
-crypt_set_format (const char *string)
-{
-  return !strcmp (string, "des");
-}

Deleted: trunk/freebsd-glue/src/disklabel.c
===================================================================
--- trunk/freebsd-glue/src/disklabel.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/disklabel.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,9 +0,0 @@
-#include <unistd.h>
-#include <sys/disklabel.h>
-
-struct disklabel *
-getdiskbyname (const char *name)
-{
-  /* We don't have disktab(5) */
-  return NULL;
-}

Deleted: trunk/freebsd-glue/src/exec.c
===================================================================
--- trunk/freebsd-glue/src/exec.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/exec.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,9 +0,0 @@
-#include <stdlib.h>	/* setenv */
-#include <unistd.h>	/* execvp */
-
-int
-execvP(const char *name, const char *path, char * const argv[])
-{
-	setenv ("PATH", path, 1);
-	return execvp(name, argv);
-}

Deleted: trunk/freebsd-glue/src/feature_present.c
===================================================================
--- trunk/freebsd-glue/src/feature_present.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/feature_present.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,69 +0,0 @@
-/*-
- * Copyright (c) 2008 Yahoo!, Inc.
- * All rights reserved.
- * Written by: John Baldwin <jhb at FreeBSD.org>
- *
- * 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.
- * 3. Neither the name of the author nor the names of any co-contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
- */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-/*
- * Returns true if the named feature is present in the currently
- * running kernel.  A feature's presence is indicated by an integer
- * sysctl node called kern.feature.<feature> that is non-zero.
- */
-int
-feature_present(const char *feature)
-{
-#ifdef __FreeBSD_kernel__
-	char *mib;
-	size_t len;
-	int i;
-
-	if ((!strcmp(feature, "inet") || !strcmp(feature, "inet6")) && getosreldate() <= 900038)
-		return (1);
-
-	if (asprintf(&mib, "kern.features.%s", feature) < 0)
-		return (0);
-	len = sizeof(i);
-	if (sysctlbyname(mib, &i, &len, NULL, 0) < 0) {
-		free(mib);
-		return (0);
-	}
-	free(mib);
-	if (len != sizeof(i))
-		return (0);
-	return (i != 0);
-#else
-	return (0);
-#endif
-}

Copied: trunk/freebsd-glue/src/freebsd-glue/Makefile (from rev 5123, trunk/freebsd-glue/src/Makefile)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/Makefile	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/Makefile	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,27 @@
+LIB=	freebsd-glue
+SRCS=	\
+	exec.c \
+	feature_present.c \
+	fstab.c \
+	funopen.c \
+	getcap.c \
+	getosreldate.c \
+	random.c \
+	${NULL}
+
+LDADD=	-lbsd -ldb
+
+SYS!=	dpkg-architecture -qDEB_HOST_GNU_SYSTEM
+
+.if ${SYS} == "kfreebsd-gnu"
+SRCS+=	\
+	cpuset.c \
+	disklabel.c \
+	linkaddr.c \
+	login_class.c \
+	mac.c \
+	socket.c \
+	${NULL}
+.endif
+
+.include <bsd.lib.mk>

Copied: trunk/freebsd-glue/src/freebsd-glue/cpuset.c (from rev 5123, trunk/freebsd-glue/src/cpuset.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/cpuset.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/cpuset.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,34 @@
+#include <sys/param.h>
+#include <sys/cpuset.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+int
+cpuset (cpusetid_t *setid)
+{
+  return syscall (SYS_cpuset, setid);
+}
+
+int
+cpuset_setid (cpuwhich_t which, id_t id, cpusetid_t setid)
+{
+  return syscall (SYS_cpuset_setid, which, id, setid);
+}
+
+int
+cpuset_getid (cpulevel_t level, cpuwhich_t which, id_t id, cpusetid_t *setid)
+{
+  return syscall (SYS_cpuset_getid, level, which, id, setid);
+}
+
+int
+cpuset_getaffinity (cpulevel_t level, cpuwhich_t which, id_t id, size_t setsize, cpuset_t *mask)
+{
+  return syscall (SYS_cpuset_getaffinity, level, which, id, setsize, mask);
+}
+
+int
+cpuset_setaffinity (cpulevel_t level, cpuwhich_t which, id_t id, size_t setsize, const cpuset_t *mask)
+{
+  return syscall (SYS_cpuset_setaffinity, level, which, id, setsize, mask);
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/disklabel.c (from rev 5123, trunk/freebsd-glue/src/disklabel.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/disklabel.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/disklabel.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,9 @@
+#include <unistd.h>
+#include <sys/disklabel.h>
+
+struct disklabel *
+getdiskbyname (const char *name)
+{
+  /* We don't have disktab(5) */
+  return NULL;
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/exec.c (from rev 5123, trunk/freebsd-glue/src/exec.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/exec.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/exec.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,9 @@
+#include <stdlib.h>	/* setenv */
+#include <unistd.h>	/* execvp */
+
+int
+execvP(const char *name, const char *path, char * const argv[])
+{
+	setenv ("PATH", path, 1);
+	return execvp(name, argv);
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/feature_present.c (from rev 5123, trunk/freebsd-glue/src/feature_present.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/feature_present.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/feature_present.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (c) 2008 Yahoo!, Inc.
+ * All rights reserved.
+ * Written by: John Baldwin <jhb at FreeBSD.org>
+ *
+ * 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.
+ * 3. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * Returns true if the named feature is present in the currently
+ * running kernel.  A feature's presence is indicated by an integer
+ * sysctl node called kern.feature.<feature> that is non-zero.
+ */
+int
+feature_present(const char *feature)
+{
+#ifdef __FreeBSD_kernel__
+	char *mib;
+	size_t len;
+	int i;
+
+	if ((!strcmp(feature, "inet") || !strcmp(feature, "inet6")) && getosreldate() <= 900038)
+		return (1);
+
+	if (asprintf(&mib, "kern.features.%s", feature) < 0)
+		return (0);
+	len = sizeof(i);
+	if (sysctlbyname(mib, &i, &len, NULL, 0) < 0) {
+		free(mib);
+		return (0);
+	}
+	free(mib);
+	if (len != sizeof(i))
+		return (0);
+	return (i != 0);
+#else
+	return (0);
+#endif
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/fstab.c (from rev 5123, trunk/freebsd-glue/src/fstab.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/fstab.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/fstab.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,16 @@
+#include <fstab.h>
+#include <err.h>
+#include <errno.h>
+#include <string.h>	/* strerror */
+#include <stdio.h>
+
+void
+setfstab (const char *file)
+{
+  fprintf (stderr, "setfstab: %s", strerror (ENOSYS));
+}
+
+const char *getfstab (void)
+{
+  return _PATH_FSTAB;
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/funopen.c (from rev 5123, trunk/freebsd-glue/src/funopen.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/funopen.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/funopen.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+struct cookiebox
+{
+  void *cookie;
+  int (*readfn) (void *, char *, int);
+  int (*writefn) (void *, const char *, int);
+  int (*closefn) (void *);
+};
+
+static ssize_t
+cookiebox_read (void *cookie, char *buf, size_t size)
+{
+  struct cookiebox *cookiebox = cookie;
+  return cookiebox->readfn (cookiebox->cookie, buf, size);
+}
+
+static ssize_t
+cookiebox_write (void *cookie, const char *buf, size_t size)
+{
+  struct cookiebox *cookiebox = cookie;
+  return cookiebox->writefn (cookiebox->cookie, buf, size);
+}
+
+static int
+cookiebox_close (void *cookie)
+{
+  struct cookiebox *cookiebox = cookie;
+  int ret = cookiebox->closefn (cookiebox->cookie);
+  free (cookiebox);
+  return ret;
+}
+
+FILE *
+funopen (const void *cookie, int (*readfn)(void *, char *, int),
+	 int (*writefn)(void *, const char *, int),
+	 fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *))
+{
+  if (seekfn)
+    {
+      errno = ENOSYS;
+      return NULL;
+    }
+
+  cookie_io_functions_t cookiebox_funcs = {
+    .read = cookiebox_read,
+    .write = cookiebox_write,
+    .seek = NULL,
+    .close = cookiebox_close
+  };
+
+  struct cookiebox *cookiebox = malloc (sizeof (*cookiebox));
+  
+  cookiebox->cookie = (void *) cookie;
+  cookiebox->readfn = readfn;
+  cookiebox->writefn = writefn;
+  cookiebox->closefn = closefn;
+
+  return fopencookie ((void *) cookiebox, "r+", cookiebox_funcs);
+}
+
+FILE *
+fropen (void *cookie, int (*readfn)(void *, char *, int))
+{
+  return funopen (cookie, readfn, NULL, NULL, NULL);
+}
+
+FILE *
+fwopen (void *cookie, int (*writefn)(void *, const char *, int))
+{
+  return funopen (cookie, NULL, writefn, NULL, NULL);
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/getcap.c (from rev 5123, trunk/freebsd-glue/src/getcap.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/getcap.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/getcap.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,1055 @@
+/*-
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Casey Leedom of Lawrence Livermore National Laboratory.
+ *
+ * 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.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getcap.c	8.3 (Berkeley) 3/25/94";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <sys/types.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "un-namespace.h"
+
+#include <db.h>
+
+#define	BFRAG		1024
+#define	BSIZE		1024
+#define	ESC		('[' & 037)	/* ASCII ESC */
+#define	MAX_RECURSION	32		/* maximum getent recursion */
+#define	SFRAG		100		/* cgetstr mallocs in SFRAG chunks */
+
+#define RECOK	(char)0
+#define TCERR	(char)1
+#define	SHADOW	(char)2
+
+static size_t	 topreclen;	/* toprec length */
+static char	*toprec;	/* Additional record specified by cgetset() */
+static int	 gottoprec;	/* Flag indicating retrieval of toprecord */
+
+static int	cdbget(DB *, char **, const char *);
+static int 	getent(char **, u_int *, char **, int, const char *, int, char *);
+static int	nfcmp(char *, char *);
+
+/*
+ * Cgetset() allows the addition of a user specified buffer to be added
+ * to the database array, in effect "pushing" the buffer on top of the
+ * virtual database. 0 is returned on success, -1 on failure.
+ */
+int
+cgetset(const char *ent)
+{
+	if (ent == NULL) {
+		if (toprec)
+			free(toprec);
+                toprec = NULL;
+                topreclen = 0;
+                return (0);
+        }
+        topreclen = strlen(ent);
+        if ((toprec = malloc (topreclen + 1)) == NULL) {
+		errno = ENOMEM;
+                return (-1);
+	}
+	gottoprec = 0;
+        (void)strcpy(toprec, ent);
+        return (0);
+}
+
+/*
+ * Cgetcap searches the capability record buf for the capability cap with
+ * type `type'.  A pointer to the value of cap is returned on success, NULL
+ * if the requested capability couldn't be found.
+ *
+ * Specifying a type of ':' means that nothing should follow cap (:cap:).
+ * In this case a pointer to the terminating ':' or NUL will be returned if
+ * cap is found.
+ *
+ * If (cap, '@') or (cap, terminator, '@') is found before (cap, terminator)
+ * return NULL.
+ */
+char *
+cgetcap(char *buf, const char *cap, int type)
+{
+	char *bp;
+	const char *cp;
+
+	bp = buf;
+	for (;;) {
+		/*
+		 * Skip past the current capability field - it's either the
+		 * name field if this is the first time through the loop, or
+		 * the remainder of a field whose name failed to match cap.
+		 */
+		for (;;)
+			if (*bp == '\0')
+				return (NULL);
+			else
+				if (*bp++ == ':')
+					break;
+
+		/*
+		 * Try to match (cap, type) in buf.
+		 */
+		for (cp = cap; *cp == *bp && *bp != '\0'; cp++, bp++)
+			continue;
+		if (*cp != '\0')
+			continue;
+		if (*bp == '@')
+			return (NULL);
+		if (type == ':') {
+			if (*bp != '\0' && *bp != ':')
+				continue;
+			return(bp);
+		}
+		if (*bp != type)
+			continue;
+		bp++;
+		return (*bp == '@' ? NULL : bp);
+	}
+	/* NOTREACHED */
+}
+
+/*
+ * Cgetent extracts the capability record name from the NULL terminated file
+ * array db_array and returns a pointer to a malloc'd copy of it in buf.
+ * Buf must be retained through all subsequent calls to cgetcap, cgetnum,
+ * cgetflag, and cgetstr, but may then be free'd.  0 is returned on success,
+ * -1 if the requested record couldn't be found, -2 if a system error was
+ * encountered (couldn't open/read a file, etc.), and -3 if a potential
+ * reference loop is detected.
+ */
+int
+cgetent(char **buf, char **db_array, const char *name)
+{
+	u_int dummy;
+
+	return (getent(buf, &dummy, db_array, -1, name, 0, NULL));
+}
+
+/*
+ * Getent implements the functions of cgetent.  If fd is non-negative,
+ * *db_array has already been opened and fd is the open file descriptor.  We
+ * do this to save time and avoid using up file descriptors for tc=
+ * recursions.
+ *
+ * Getent returns the same success/failure codes as cgetent.  On success, a
+ * pointer to a malloc'ed capability record with all tc= capabilities fully
+ * expanded and its length (not including trailing ASCII NUL) are left in
+ * *cap and *len.
+ *
+ * Basic algorithm:
+ *	+ Allocate memory incrementally as needed in chunks of size BFRAG
+ *	  for capability buffer.
+ *	+ Recurse for each tc=name and interpolate result.  Stop when all
+ *	  names interpolated, a name can't be found, or depth exceeds
+ *	  MAX_RECURSION.
+ */
+static int
+getent(char **cap, u_int *len, char **db_array, int fd, const char *name,
+    int depth, char *nfield)
+{
+	DB *capdbp;
+	char *r_end, *rp, **db_p;
+	int myfd, eof, foundit, retval;
+	char *record, *cbuf;
+	int tc_not_resolved;
+	char pbuf[_POSIX_PATH_MAX];
+
+	/*
+	 * Return with ``loop detected'' error if we've recursed more than
+	 * MAX_RECURSION times.
+	 */
+	if (depth > MAX_RECURSION)
+		return (-3);
+
+	/*
+	 * Check if we have a top record from cgetset().
+         */
+	if (depth == 0 && toprec != NULL && cgetmatch(toprec, name) == 0) {
+		if ((record = malloc (topreclen + BFRAG)) == NULL) {
+			errno = ENOMEM;
+			return (-2);
+		}
+		(void)strcpy(record, toprec);
+		myfd = 0;
+		db_p = db_array;
+		rp = record + topreclen + 1;
+		r_end = rp + BFRAG;
+		goto tc_exp;
+	}
+	/*
+	 * Allocate first chunk of memory.
+	 */
+	if ((record = malloc(BFRAG)) == NULL) {
+		errno = ENOMEM;
+		return (-2);
+	}
+	r_end = record + BFRAG;
+	foundit = 0;
+	/*
+	 * Loop through database array until finding the record.
+	 */
+
+	for (db_p = db_array; *db_p != NULL; db_p++) {
+		eof = 0;
+
+		/*
+		 * Open database if not already open.
+		 */
+
+		if (fd >= 0) {
+			(void)lseek(fd, (off_t)0, SEEK_SET);
+			myfd = 0;
+		} else {
+			(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p);
+			if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0))
+			     != NULL) {
+				free(record);
+				retval = cdbget(capdbp, &record, name);
+				if (retval < 0) {
+					/* no record available */
+					(void)capdbp->close(capdbp);
+					return (retval);
+				}
+				/* save the data; close frees it */
+				cbuf = strdup(record);
+				if (capdbp->close(capdbp) < 0) {
+					free(cbuf);
+					return (-2);
+				}
+				if (cbuf == NULL) {
+					errno = ENOMEM;
+					return (-2);
+				}
+				*len = strlen(cbuf);
+				*cap = cbuf;
+				return (retval);
+			} else {
+				fd = _open(*db_p, O_RDONLY | O_CLOEXEC, 0);
+				if (fd < 0)
+					continue;
+				myfd = 1;
+			}
+		}
+		/*
+		 * Find the requested capability record ...
+		 */
+		{
+		char buf[BUFSIZ];
+		char *b_end, *bp;
+		int c;
+
+		/*
+		 * Loop invariants:
+		 *	There is always room for one more character in record.
+		 *	R_end always points just past end of record.
+		 *	Rp always points just past last character in record.
+		 *	B_end always points just past last character in buf.
+		 *	Bp always points at next character in buf.
+		 */
+		b_end = buf;
+		bp = buf;
+		for (;;) {
+
+			/*
+			 * Read in a line implementing (\, newline)
+			 * line continuation.
+			 */
+			rp = record;
+			for (;;) {
+				if (bp >= b_end) {
+					int n;
+
+					n = _read(fd, buf, sizeof(buf));
+					if (n <= 0) {
+						if (myfd)
+							(void)_close(fd);
+						if (n < 0) {
+							free(record);
+							return (-2);
+						} else {
+							fd = -1;
+							eof = 1;
+							break;
+						}
+					}
+					b_end = buf+n;
+					bp = buf;
+				}
+
+				c = *bp++;
+				if (c == '\n') {
+					if (rp > record && *(rp-1) == '\\') {
+						rp--;
+						continue;
+					} else
+						break;
+				}
+				*rp++ = c;
+
+				/*
+				 * Enforce loop invariant: if no room
+				 * left in record buffer, try to get
+				 * some more.
+				 */
+				if (rp >= r_end) {
+					u_int pos;
+					size_t newsize;
+
+					pos = rp - record;
+					newsize = r_end - record + BFRAG;
+					record = reallocf(record, newsize);
+					if (record == NULL) {
+						errno = ENOMEM;
+						if (myfd)
+							(void)_close(fd);
+						return (-2);
+					}
+					r_end = record + newsize;
+					rp = record + pos;
+				}
+			}
+				/* loop invariant let's us do this */
+			*rp++ = '\0';
+
+			/*
+			 * If encountered eof check next file.
+			 */
+			if (eof)
+				break;
+
+			/*
+			 * Toss blank lines and comments.
+			 */
+			if (*record == '\0' || *record == '#')
+				continue;
+
+			/*
+			 * See if this is the record we want ...
+			 */
+			if (cgetmatch(record, name) == 0) {
+				if (nfield == NULL || !nfcmp(nfield, record)) {
+					foundit = 1;
+					break;	/* found it! */
+				}
+			}
+		}
+	}
+		if (foundit)
+			break;
+	}
+
+	if (!foundit) {
+		free(record);
+		return (-1);
+	}
+
+	/*
+	 * Got the capability record, but now we have to expand all tc=name
+	 * references in it ...
+	 */
+tc_exp:	{
+		char *newicap, *s;
+		int newilen;
+		u_int ilen;
+		int diff, iret, tclen;
+		char *icap, *scan, *tc, *tcstart, *tcend;
+
+		/*
+		 * Loop invariants:
+		 *	There is room for one more character in record.
+		 *	R_end points just past end of record.
+		 *	Rp points just past last character in record.
+		 *	Scan points at remainder of record that needs to be
+		 *	scanned for tc=name constructs.
+		 */
+		scan = record;
+		tc_not_resolved = 0;
+		for (;;) {
+			if ((tc = cgetcap(scan, "tc", '=')) == NULL)
+				break;
+
+			/*
+			 * Find end of tc=name and stomp on the trailing `:'
+			 * (if present) so we can use it to call ourselves.
+			 */
+			s = tc;
+			for (;;)
+				if (*s == '\0')
+					break;
+				else
+					if (*s++ == ':') {
+						*(s - 1) = '\0';
+						break;
+					}
+			tcstart = tc - 3;
+			tclen = s - tcstart;
+			tcend = s;
+
+			iret = getent(&icap, &ilen, db_p, fd, tc, depth+1,
+				      NULL);
+			newicap = icap;		/* Put into a register. */
+			newilen = ilen;
+			if (iret != 0) {
+				/* an error */
+				if (iret < -1) {
+					if (myfd)
+						(void)_close(fd);
+					free(record);
+					return (iret);
+				}
+				if (iret == 1)
+					tc_not_resolved = 1;
+				/* couldn't resolve tc */
+				if (iret == -1) {
+					*(s - 1) = ':';
+					scan = s - 1;
+					tc_not_resolved = 1;
+					continue;
+
+				}
+			}
+			/* not interested in name field of tc'ed record */
+			s = newicap;
+			for (;;)
+				if (*s == '\0')
+					break;
+				else
+					if (*s++ == ':')
+						break;
+			newilen -= s - newicap;
+			newicap = s;
+
+			/* make sure interpolated record is `:'-terminated */
+			s += newilen;
+			if (*(s-1) != ':') {
+				*s = ':';	/* overwrite NUL with : */
+				newilen++;
+			}
+
+			/*
+			 * Make sure there's enough room to insert the
+			 * new record.
+			 */
+			diff = newilen - tclen;
+			if (diff >= r_end - rp) {
+				u_int pos, tcpos, tcposend;
+				size_t newsize;
+
+				pos = rp - record;
+				newsize = r_end - record + diff + BFRAG;
+				tcpos = tcstart - record;
+				tcposend = tcend - record;
+				record = reallocf(record, newsize);
+				if (record == NULL) {
+					errno = ENOMEM;
+					if (myfd)
+						(void)_close(fd);
+					free(icap);
+					return (-2);
+				}
+				r_end = record + newsize;
+				rp = record + pos;
+				tcstart = record + tcpos;
+				tcend = record + tcposend;
+			}
+
+			/*
+			 * Insert tc'ed record into our record.
+			 */
+			s = tcstart + newilen;
+			bcopy(tcend, s, rp - tcend);
+			bcopy(newicap, tcstart, newilen);
+			rp += diff;
+			free(icap);
+
+			/*
+			 * Start scan on `:' so next cgetcap works properly
+			 * (cgetcap always skips first field).
+			 */
+			scan = s-1;
+		}
+
+	}
+	/*
+	 * Close file (if we opened it), give back any extra memory, and
+	 * return capability, length and success.
+	 */
+	if (myfd)
+		(void)_close(fd);
+	*len = rp - record - 1;	/* don't count NUL */
+	if (r_end > rp)
+		if ((record =
+		     reallocf(record, (size_t)(rp - record))) == NULL) {
+			errno = ENOMEM;
+			return (-2);
+		}
+
+	*cap = record;
+	if (tc_not_resolved)
+		return (1);
+	return (0);
+}
+
+static int
+cdbget(DB *capdbp, char **bp, const char *name)
+{
+	DBT key, data;
+	char *namebuf;
+
+	namebuf = strdup(name);
+	if (namebuf == NULL)
+		return (-2);
+	key.data = namebuf;
+	key.size = strlen(namebuf);
+
+	for (;;) {
+		/* Get the reference. */
+		switch(capdbp->get(capdbp, &key, &data, 0)) {
+		case -1:
+			free(namebuf);
+			return (-2);
+		case 1:
+			free(namebuf);
+			return (-1);
+		}
+
+		/* If not an index to another record, leave. */
+		if (((char *)data.data)[0] != SHADOW)
+			break;
+
+		key.data = (char *)data.data + 1;
+		key.size = data.size - 1;
+	}
+
+	*bp = (char *)data.data + 1;
+	free(namebuf);
+	return (((char *)(data.data))[0] == TCERR ? 1 : 0);
+}
+
+/*
+ * Cgetmatch will return 0 if name is one of the names of the capability
+ * record buf, -1 if not.
+ */
+int
+cgetmatch(const char *buf, const char *name)
+{
+	const char *np, *bp;
+
+	if (name == NULL || *name == '\0')
+		return -1;
+
+	/*
+	 * Start search at beginning of record.
+	 */
+	bp = buf;
+	for (;;) {
+		/*
+		 * Try to match a record name.
+		 */
+		np = name;
+		for (;;)
+			if (*np == '\0')
+				if (*bp == '|' || *bp == ':' || *bp == '\0')
+					return (0);
+				else
+					break;
+			else
+				if (*bp++ != *np++)
+					break;
+
+		/*
+		 * Match failed, skip to next name in record.
+		 */
+		bp--;	/* a '|' or ':' may have stopped the match */
+		for (;;)
+			if (*bp == '\0' || *bp == ':')
+				return (-1);	/* match failed totally */
+			else
+				if (*bp++ == '|')
+					break;	/* found next name */
+	}
+}
+
+
+
+
+
+int
+cgetfirst(char **buf, char **db_array)
+{
+	(void)cgetclose();
+	return (cgetnext(buf, db_array));
+}
+
+static FILE *pfp;
+static int slash;
+static char **dbp;
+
+int
+cgetclose(void)
+{
+	if (pfp != NULL) {
+		(void)fclose(pfp);
+		pfp = NULL;
+	}
+	dbp = NULL;
+	gottoprec = 0;
+	slash = 0;
+	return(0);
+}
+
+/*
+ * Cgetnext() gets either the first or next entry in the logical database
+ * specified by db_array.  It returns 0 upon completion of the database, 1
+ * upon returning an entry with more remaining, and -1 if an error occurs.
+ */
+int
+cgetnext(char **bp, char **db_array)
+{
+	size_t len;
+	int done, hadreaderr, savederrno, status;
+	char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE];
+	u_int dummy;
+
+	if (dbp == NULL)
+		dbp = db_array;
+
+	if (pfp == NULL && (pfp = fopen(*dbp, "re")) == NULL) {
+		(void)cgetclose();
+		return (-1);
+	}
+	for (;;) {
+		if (toprec && !gottoprec) {
+			gottoprec = 1;
+			line = toprec;
+		} else {
+			line = fgetln(pfp, &len);
+			if (line == NULL && pfp) {
+				hadreaderr = ferror(pfp);
+				if (hadreaderr)
+					savederrno = errno;
+				fclose(pfp);
+				pfp = NULL;
+				if (hadreaderr) {
+					cgetclose();
+					errno = savederrno;
+					return (-1);
+				} else {
+					if (*++dbp == NULL) {
+						(void)cgetclose();
+						return (0);
+					} else if ((pfp =
+					    fopen(*dbp, "re")) == NULL) {
+						(void)cgetclose();
+						return (-1);
+					} else
+						continue;
+				}
+			} else
+				line[len - 1] = '\0';
+			if (len == 1) {
+				slash = 0;
+				continue;
+			}
+			if (isspace((unsigned char)*line) ||
+			    *line == ':' || *line == '#' || slash) {
+				if (line[len - 2] == '\\')
+					slash = 1;
+				else
+					slash = 0;
+				continue;
+			}
+			if (line[len - 2] == '\\')
+				slash = 1;
+			else
+				slash = 0;
+		}
+
+
+		/*
+		 * Line points to a name line.
+		 */
+		done = 0;
+		np = nbuf;
+		for (;;) {
+			for (cp = line; *cp != '\0'; cp++) {
+				if (*cp == ':') {
+					*np++ = ':';
+					done = 1;
+					break;
+				}
+				if (*cp == '\\')
+					break;
+				*np++ = *cp;
+			}
+			if (done) {
+				*np = '\0';
+				break;
+			} else { /* name field extends beyond the line */
+				line = fgetln(pfp, &len);
+				if (line == NULL && pfp) {
+					/* Name extends beyond the EOF! */
+					hadreaderr = ferror(pfp);
+					if (hadreaderr)
+						savederrno = errno;
+					fclose(pfp);
+					pfp = NULL;
+					if (hadreaderr) {
+						cgetclose();
+						errno = savederrno;
+						return (-1);
+					} else {
+						cgetclose();
+						return (-1);
+					}
+				} else
+					line[len - 1] = '\0';
+			}
+		}
+		rp = buf;
+		for(cp = nbuf; *cp != '\0'; cp++)
+			if (*cp == '|' || *cp == ':')
+				break;
+			else
+				*rp++ = *cp;
+
+		*rp = '\0';
+		/*
+		 * XXX
+		 * Last argument of getent here should be nbuf if we want true
+		 * sequential access in the case of duplicates.
+		 * With NULL, getent will return the first entry found
+		 * rather than the duplicate entry record.  This is a
+		 * matter of semantics that should be resolved.
+		 */
+		status = getent(bp, &dummy, db_array, -1, buf, 0, NULL);
+		if (status == -2 || status == -3)
+			(void)cgetclose();
+
+		return (status + 1);
+	}
+	/* NOTREACHED */
+}
+
+/*
+ * Cgetstr retrieves the value of the string capability cap from the
+ * capability record pointed to by buf.  A pointer to a decoded, NUL
+ * terminated, malloc'd copy of the string is returned in the char *
+ * pointed to by str.  The length of the string not including the trailing
+ * NUL is returned on success, -1 if the requested string capability
+ * couldn't be found, -2 if a system error was encountered (storage
+ * allocation failure).
+ */
+int
+cgetstr(char *buf, const char *cap, char **str)
+{
+	u_int m_room;
+	char *bp, *mp;
+	int len;
+	char *mem;
+
+	/*
+	 * Find string capability cap
+	 */
+	bp = cgetcap(buf, cap, '=');
+	if (bp == NULL)
+		return (-1);
+
+	/*
+	 * Conversion / storage allocation loop ...  Allocate memory in
+	 * chunks SFRAG in size.
+	 */
+	if ((mem = malloc(SFRAG)) == NULL) {
+		errno = ENOMEM;
+		return (-2);	/* couldn't even allocate the first fragment */
+	}
+	m_room = SFRAG;
+	mp = mem;
+
+	while (*bp != ':' && *bp != '\0') {
+		/*
+		 * Loop invariants:
+		 *	There is always room for one more character in mem.
+		 *	Mp always points just past last character in mem.
+		 *	Bp always points at next character in buf.
+		 */
+		if (*bp == '^') {
+			bp++;
+			if (*bp == ':' || *bp == '\0')
+				break;	/* drop unfinished escape */
+			if (*bp == '?') {
+				*mp++ = '\177';
+				bp++;
+			} else
+				*mp++ = *bp++ & 037;
+		} else if (*bp == '\\') {
+			bp++;
+			if (*bp == ':' || *bp == '\0')
+				break;	/* drop unfinished escape */
+			if ('0' <= *bp && *bp <= '7') {
+				int n, i;
+
+				n = 0;
+				i = 3;	/* maximum of three octal digits */
+				do {
+					n = n * 8 + (*bp++ - '0');
+				} while (--i && '0' <= *bp && *bp <= '7');
+				*mp++ = n;
+			}
+			else switch (*bp++) {
+				case 'b': case 'B':
+					*mp++ = '\b';
+					break;
+				case 't': case 'T':
+					*mp++ = '\t';
+					break;
+				case 'n': case 'N':
+					*mp++ = '\n';
+					break;
+				case 'f': case 'F':
+					*mp++ = '\f';
+					break;
+				case 'r': case 'R':
+					*mp++ = '\r';
+					break;
+				case 'e': case 'E':
+					*mp++ = ESC;
+					break;
+				case 'c': case 'C':
+					*mp++ = ':';
+					break;
+				default:
+					/*
+					 * Catches '\', '^', and
+					 *  everything else.
+					 */
+					*mp++ = *(bp-1);
+					break;
+			}
+		} else
+			*mp++ = *bp++;
+		m_room--;
+
+		/*
+		 * Enforce loop invariant: if no room left in current
+		 * buffer, try to get some more.
+		 */
+		if (m_room == 0) {
+			size_t size = mp - mem;
+
+			if ((mem = reallocf(mem, size + SFRAG)) == NULL)
+				return (-2);
+			m_room = SFRAG;
+			mp = mem + size;
+		}
+	}
+	*mp++ = '\0';	/* loop invariant let's us do this */
+	m_room--;
+	len = mp - mem - 1;
+
+	/*
+	 * Give back any extra memory and return value and success.
+	 */
+	if (m_room != 0)
+		if ((mem = reallocf(mem, (size_t)(mp - mem))) == NULL)
+			return (-2);
+	*str = mem;
+	return (len);
+}
+
+/*
+ * Cgetustr retrieves the value of the string capability cap from the
+ * capability record pointed to by buf.  The difference between cgetustr()
+ * and cgetstr() is that cgetustr does not decode escapes but rather treats
+ * all characters literally.  A pointer to a  NUL terminated malloc'd
+ * copy of the string is returned in the char pointed to by str.  The
+ * length of the string not including the trailing NUL is returned on success,
+ * -1 if the requested string capability couldn't be found, -2 if a system
+ * error was encountered (storage allocation failure).
+ */
+int
+cgetustr(char *buf, const char *cap, char **str)
+{
+	u_int m_room;
+	char *bp, *mp;
+	int len;
+	char *mem;
+
+	/*
+	 * Find string capability cap
+	 */
+	if ((bp = cgetcap(buf, cap, '=')) == NULL)
+		return (-1);
+
+	/*
+	 * Conversion / storage allocation loop ...  Allocate memory in
+	 * chunks SFRAG in size.
+	 */
+	if ((mem = malloc(SFRAG)) == NULL) {
+		errno = ENOMEM;
+		return (-2);	/* couldn't even allocate the first fragment */
+	}
+	m_room = SFRAG;
+	mp = mem;
+
+	while (*bp != ':' && *bp != '\0') {
+		/*
+		 * Loop invariants:
+		 *	There is always room for one more character in mem.
+		 *	Mp always points just past last character in mem.
+		 *	Bp always points at next character in buf.
+		 */
+		*mp++ = *bp++;
+		m_room--;
+
+		/*
+		 * Enforce loop invariant: if no room left in current
+		 * buffer, try to get some more.
+		 */
+		if (m_room == 0) {
+			size_t size = mp - mem;
+
+			if ((mem = reallocf(mem, size + SFRAG)) == NULL)
+				return (-2);
+			m_room = SFRAG;
+			mp = mem + size;
+		}
+	}
+	*mp++ = '\0';	/* loop invariant let's us do this */
+	m_room--;
+	len = mp - mem - 1;
+
+	/*
+	 * Give back any extra memory and return value and success.
+	 */
+	if (m_room != 0)
+		if ((mem = reallocf(mem, (size_t)(mp - mem))) == NULL)
+			return (-2);
+	*str = mem;
+	return (len);
+}
+
+/*
+ * Cgetnum retrieves the value of the numeric capability cap from the
+ * capability record pointed to by buf.  The numeric value is returned in
+ * the long pointed to by num.  0 is returned on success, -1 if the requested
+ * numeric capability couldn't be found.
+ */
+int
+cgetnum(char *buf, const char *cap, long *num)
+{
+	long n;
+	int base, digit;
+	char *bp;
+
+	/*
+	 * Find numeric capability cap
+	 */
+	bp = cgetcap(buf, cap, '#');
+	if (bp == NULL)
+		return (-1);
+
+	/*
+	 * Look at value and determine numeric base:
+	 *	0x... or 0X...	hexadecimal,
+	 * else	0...		octal,
+	 * else			decimal.
+	 */
+	if (*bp == '0') {
+		bp++;
+		if (*bp == 'x' || *bp == 'X') {
+			bp++;
+			base = 16;
+		} else
+			base = 8;
+	} else
+		base = 10;
+
+	/*
+	 * Conversion loop ...
+	 */
+	n = 0;
+	for (;;) {
+		if ('0' <= *bp && *bp <= '9')
+			digit = *bp - '0';
+		else if ('a' <= *bp && *bp <= 'f')
+			digit = 10 + *bp - 'a';
+		else if ('A' <= *bp && *bp <= 'F')
+			digit = 10 + *bp - 'A';
+		else
+			break;
+
+		if (digit >= base)
+			break;
+
+		n = n * base + digit;
+		bp++;
+	}
+
+	/*
+	 * Return value and success.
+	 */
+	*num = n;
+	return (0);
+}
+
+
+/*
+ * Compare name field of record.
+ */
+static int
+nfcmp(char *nf, char *rec)
+{
+	char *cp, tmp;
+	int ret;
+
+	for (cp = rec; *cp != ':'; cp++)
+		;
+
+	tmp = *(cp + 1);
+	*(cp + 1) = '\0';
+	ret = strcmp(nf, rec);
+	*(cp + 1) = tmp;
+
+	return (ret);
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/getosreldate.c (from rev 5123, trunk/freebsd-glue/src/getosreldate.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/getosreldate.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/getosreldate.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 1989, 1993
+ *	The Regents of the University of California.  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.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#include <stddef.h>
+#include <sys/sysctl.h>
+#include <stdlib.h>
+
+int
+getosreldate(void)
+{
+	int value;
+	char *temp;
+
+	if ((temp = getenv("OSVERSION"))) {
+		value = atoi(temp);
+		return (value);
+	}
+
+#ifdef __FreeBSD_kernel__ 
+	int mib[2];
+	size_t size;
+	mib[0] = CTL_KERN;
+	mib[1] = KERN_OSRELDATE;
+	size = sizeof value;
+	if (sysctl(mib, 2, &value, &size, NULL, 0) == -1)
+		return (-1);
+	return (value);
+#else
+	return 0;
+#endif
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/linkaddr.c (from rev 5123, trunk/freebsd-glue/src/linkaddr.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/linkaddr.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/linkaddr.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,155 @@
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  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.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)linkaddr.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if_dl.h>
+#include <string.h>
+
+/* States*/
+#define NAMING	0
+#define GOTONE	1
+#define GOTTWO	2
+#define RESET	3
+/* Inputs */
+#define	DIGIT	(4*0)
+#define	END	(4*1)
+#define DELIM	(4*2)
+#define LETTER	(4*3)
+
+void
+link_addr(addr, sdl)
+	const char *addr;
+	struct sockaddr_dl *sdl;
+{
+	char *cp = sdl->sdl_data;
+	char *cplim = sdl->sdl_len + (char *)sdl;
+	int byte = 0, state = NAMING, new;
+
+	bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1);
+	sdl->sdl_family = AF_LINK;
+	do {
+		state &= ~LETTER;
+		if ((*addr >= '0') && (*addr <= '9')) {
+			new = *addr - '0';
+		} else if ((*addr >= 'a') && (*addr <= 'f')) {
+			new = *addr - 'a' + 10;
+		} else if ((*addr >= 'A') && (*addr <= 'F')) {
+			new = *addr - 'A' + 10;
+		} else if (*addr == 0) {
+			state |= END;
+		} else if (state == NAMING &&
+			   (((*addr >= 'A') && (*addr <= 'Z')) ||
+			   ((*addr >= 'a') && (*addr <= 'z'))))
+			state |= LETTER;
+		else
+			state |= DELIM;
+		addr++;
+		switch (state /* | INPUT */) {
+		case NAMING | DIGIT:
+		case NAMING | LETTER:
+			*cp++ = addr[-1];
+			continue;
+		case NAMING | DELIM:
+			state = RESET;
+			sdl->sdl_nlen = cp - sdl->sdl_data;
+			continue;
+		case GOTTWO | DIGIT:
+			*cp++ = byte;
+			/* FALLTHROUGH */
+		case RESET | DIGIT:
+			state = GOTONE;
+			byte = new;
+			continue;
+		case GOTONE | DIGIT:
+			state = GOTTWO;
+			byte = new + (byte << 4);
+			continue;
+		default: /* | DELIM */
+			state = RESET;
+			*cp++ = byte;
+			byte = 0;
+			continue;
+		case GOTONE | END:
+		case GOTTWO | END:
+			*cp++ = byte;
+			/* FALLTHROUGH */
+		case RESET | END:
+			break;
+		}
+		break;
+	} while (cp < cplim);
+	sdl->sdl_alen = cp - LLADDR(sdl);
+	new = cp - (char *)sdl;
+	if (new > sizeof(*sdl))
+		sdl->sdl_len = new;
+	return;
+}
+
+static char hexlist[] = "0123456789abcdef";
+
+char *
+link_ntoa(sdl)
+	const struct sockaddr_dl *sdl;
+{
+	static char obuf[64];
+	char *out = obuf;
+	int i;
+	u_char *in = (u_char *)LLADDR(sdl);
+	u_char *inlim = in + sdl->sdl_alen;
+	int firsttime = 1;
+
+	if (sdl->sdl_nlen) {
+		bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen);
+		out += sdl->sdl_nlen;
+		if (sdl->sdl_alen)
+			*out++ = ':';
+	}
+	while (in < inlim) {
+		if (firsttime)
+			firsttime = 0;
+		else
+			*out++ = '.';
+		i = *in++;
+		if (i > 0xf) {
+			out[1] = hexlist[i & 0xf];
+			i >>= 4;
+			out[0] = hexlist[i];
+			out += 2;
+		} else
+			*out++ = hexlist[i];
+	}
+	*out = 0;
+	return (obuf);
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/login_class.c (from rev 5123, trunk/freebsd-glue/src/login_class.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/login_class.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/login_class.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,15 @@
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <stddef.h>
+
+int
+getloginclass (char *name, size_t len)
+{
+  return syscall (SYS_getloginclass, name, len);
+}
+
+int
+setloginclass (const char *name)
+{
+  return syscall (SYS_setloginclass, name);
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/mac.c (from rev 5123, trunk/freebsd-glue/src/mac.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/mac.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/mac.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,449 @@
+/*
+ * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
+ * Copyright (c) 2002, 2003 Networks Associates Technology, Inc.
+ * All rights reserved.
+ *
+ * This software was developed by Robert Watson for the TrustedBSD Project.
+ *
+ * This software was developed for the FreeBSD Project in part by Network
+ * Associates Laboratories, the Security Research Division of Network
+ * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
+ * as part of the DARPA CHATS research program.
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <sys/sysctl.h>
+
+#include <dlfcn.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/mac.h>
+
+static int	internal_initialized;
+
+/*
+ * Maintain a list of default label preparations for various object
+ * types.  Each name will appear only once in the list.
+ *
+ * XXXMAC: Not thread-safe.
+ */
+static LIST_HEAD(, label_default) label_default_head;
+struct label_default {
+	char				*ld_name;
+	char				*ld_labels;
+	LIST_ENTRY(label_default)	 ld_entries;
+};
+
+static void
+mac_destroy_labels(void)
+{
+	struct label_default *ld;
+
+	while ((ld = LIST_FIRST(&label_default_head))) {
+		free(ld->ld_name);
+		free(ld->ld_labels);
+		LIST_REMOVE(ld, ld_entries);
+		free(ld);
+	}
+}
+
+static void
+mac_destroy_internal(void)
+{
+
+	mac_destroy_labels();
+
+	internal_initialized = 0;
+}
+
+static int
+mac_add_type(const char *name, const char *labels)
+{
+	struct label_default *ld, *ld_new;
+	char *name_dup, *labels_dup;
+
+	/*
+	 * Speculatively allocate all the memory now to avoid allocating
+	 * later when we will someday hold a mutex.
+	 */
+	name_dup = strdup(name);
+	if (name_dup == NULL) {
+		errno = ENOMEM;
+		return (-1);
+	}
+	labels_dup = strdup(labels);
+	if (labels_dup == NULL) {
+		free(name_dup);
+		errno = ENOMEM;
+		return (-1);
+	}
+	ld_new = malloc(sizeof(*ld));
+	if (ld_new == NULL) {
+		free(name_dup);
+		free(labels_dup);
+		errno = ENOMEM;
+		return (-1);
+	}
+
+	/*
+	 * If the type is already present, replace the current entry
+	 * rather than add a new instance.
+	 */
+	for (ld = LIST_FIRST(&label_default_head); ld != NULL;
+	    ld = LIST_NEXT(ld, ld_entries)) {
+		if (strcmp(name, ld->ld_name) == 0)
+			break;
+	}
+
+	if (ld != NULL) {
+		free(ld->ld_labels);
+		ld->ld_labels = labels_dup;
+		labels_dup = NULL;
+	} else {
+		ld = ld_new;
+		ld->ld_name = name_dup;
+		ld->ld_labels = labels_dup;
+
+		ld_new = NULL;
+		name_dup = NULL;
+		labels_dup = NULL;
+
+		LIST_INSERT_HEAD(&label_default_head, ld, ld_entries);
+	}
+
+	if (name_dup != NULL)
+		free(name_dup);
+	if (labels_dup != NULL)
+		free(labels_dup);
+	if (ld_new != NULL)
+		free(ld_new);
+
+	return (0);
+}
+
+static char *
+next_token(char **string)
+{
+	char *token;
+
+	token = strsep(string, " \t");
+	while (token != NULL && *token == '\0')
+		token = strsep(string, " \t");
+
+	return (token);
+}
+
+static int
+mac_init_internal(int ignore_errors)
+{
+	const char *filename;
+	char line[LINE_MAX];
+	FILE *file;
+	int error;
+
+	error = 0;
+
+	LIST_INIT(&label_default_head);
+
+	if (!issetugid() && getenv("MAC_CONFFILE") != NULL)
+		filename = getenv("MAC_CONFFILE");
+	else
+		filename = MAC_CONFFILE;
+	file = fopen(filename, "re");
+	if (file == NULL)
+		return (0);
+
+	while (fgets(line, LINE_MAX, file)) {
+		char *comment, *parse, *statement;
+
+		if (line[strlen(line)-1] == '\n')
+			line[strlen(line)-1] = '\0';
+		else {
+			if (ignore_errors)
+				continue;
+			fclose(file);
+			error = EINVAL;
+			goto just_return;
+		}
+
+		/* Remove any comment. */
+		comment = line;
+		parse = strsep(&comment, "#");
+
+		/* Blank lines OK. */
+		statement = next_token(&parse);
+		if (statement == NULL)
+			continue;
+
+		if (strcmp(statement, "default_labels") == 0) {
+			char *name, *labels;
+
+			name = next_token(&parse);
+			labels = next_token(&parse);
+			if (name == NULL || labels == NULL ||
+			    next_token(&parse) != NULL) {
+				if (ignore_errors)
+					continue;
+				error = EINVAL;
+				fclose(file);
+				goto just_return;
+			}
+
+			if (mac_add_type(name, labels) == -1) {
+				if (ignore_errors)
+					continue;
+				fclose(file);
+				goto just_return;
+			}
+		} else if (strcmp(statement, "default_ifnet_labels") == 0 ||
+		    strcmp(statement, "default_file_labels") == 0 ||
+		    strcmp(statement, "default_process_labels") == 0) {
+			char *labels, *type;
+
+			if (strcmp(statement, "default_ifnet_labels") == 0)
+				type = "ifnet";
+			else if (strcmp(statement, "default_file_labels") == 0)
+				type = "file";
+			else if (strcmp(statement, "default_process_labels") ==
+			    0)
+				type = "process";
+
+			labels = next_token(&parse);
+			if (labels == NULL || next_token(&parse) != NULL) {
+				if (ignore_errors)
+					continue;
+				error = EINVAL;
+				fclose(file);
+				goto just_return;
+			}
+
+			if (mac_add_type(type, labels) == -1) {
+				if (ignore_errors)
+					continue;
+				fclose(file);
+				goto just_return;
+			}
+		} else {
+			if (ignore_errors)
+				continue;
+			fclose(file);
+			error = EINVAL;
+			goto just_return;
+		}
+	}
+
+	fclose(file);
+
+	internal_initialized = 1;
+
+just_return:
+	if (error != 0)
+		mac_destroy_internal();
+	return (error);
+}
+
+static int
+mac_maybe_init_internal(void)
+{
+
+	if (!internal_initialized)
+		return (mac_init_internal(1));
+	else
+		return (0);
+}
+
+int
+mac_reload(void)
+{
+
+	if (internal_initialized)
+		mac_destroy_internal();
+	return (mac_init_internal(0));
+}
+
+int
+mac_free(struct mac *mac)
+{
+
+	if (mac->m_string != NULL)
+		free(mac->m_string);
+	free(mac);
+
+	return (0);
+}
+
+int
+mac_from_text(struct mac **mac, const char *text)
+{
+
+	*mac = (struct mac *) malloc(sizeof(**mac));
+	if (*mac == NULL)
+		return (ENOMEM);
+
+	(*mac)->m_string = strdup(text);
+	if ((*mac)->m_string == NULL) {
+		free(*mac);
+		*mac = NULL;
+		return (ENOMEM);
+	}
+
+	(*mac)->m_buflen = strlen((*mac)->m_string)+1;
+
+	return (0);
+}
+
+int
+mac_to_text(struct mac *mac, char **text)
+{
+
+	*text = strdup(mac->m_string);
+	if (*text == NULL)
+		return (ENOMEM);
+	return (0);
+}
+
+int
+mac_prepare(struct mac **mac, const char *elements)
+{
+
+	if (strlen(elements) >= MAC_MAX_LABEL_BUF_LEN)
+		return (EINVAL);
+
+	*mac = (struct mac *) malloc(sizeof(**mac));
+	if (*mac == NULL)
+		return (ENOMEM);
+
+	(*mac)->m_string = malloc(MAC_MAX_LABEL_BUF_LEN);
+	if ((*mac)->m_string == NULL) {
+		free(*mac);
+		*mac = NULL;
+		return (ENOMEM);
+	}
+
+	strcpy((*mac)->m_string, elements);
+	(*mac)->m_buflen = MAC_MAX_LABEL_BUF_LEN;
+
+	return (0);
+}
+
+int
+mac_prepare_type(struct mac **mac, const char *name)
+{
+	struct label_default *ld;
+	int error;
+
+	error = mac_maybe_init_internal();
+	if (error != 0)
+		return (error);
+
+	for (ld = LIST_FIRST(&label_default_head); ld != NULL;
+	    ld = LIST_NEXT(ld, ld_entries)) {
+		if (strcmp(name, ld->ld_name) == 0)
+			return (mac_prepare(mac, ld->ld_labels));
+	}
+
+	errno = ENOENT;
+	return (-1);		/* XXXMAC: ENOLABEL */
+}
+
+int
+mac_prepare_ifnet_label(struct mac **mac)
+{
+
+	return (mac_prepare_type(mac, "ifnet"));
+}
+
+int
+mac_prepare_file_label(struct mac **mac)
+{
+
+	return (mac_prepare_type(mac, "file"));
+}
+
+int
+mac_prepare_packet_label(struct mac **mac)
+{
+
+	return (mac_prepare_type(mac, "packet"));
+}
+
+int
+mac_prepare_process_label(struct mac **mac)
+{
+
+	return (mac_prepare_type(mac, "process"));
+}
+
+/*
+ * Simply test whether the TrustedBSD/MAC MIB tree is present; if so,
+ * return 1 to indicate that the system has MAC enabled overall or for
+ * a given policy.
+ */
+int
+mac_is_present(const char *policyname)
+{
+	int mib[5];
+	size_t siz;
+	char *mibname;
+	int error;
+
+	if (policyname != NULL) {
+		if (policyname[strcspn(policyname, ".=")] != '\0') {
+			errno = EINVAL;
+			return (-1);
+		}
+		mibname = malloc(sizeof("security.mac.") - 1 +
+		    strlen(policyname) + sizeof(".enabled"));
+		if (mibname == NULL)
+			return (-1);
+		strcpy(mibname, "security.mac.");
+		strcat(mibname, policyname);
+		strcat(mibname, ".enabled");
+		siz = 5;
+		error = sysctlnametomib(mibname, mib, &siz);
+		free(mibname);
+	} else {
+		siz = 3;
+		error = sysctlnametomib("security.mac", mib, &siz);
+	}
+	if (error == -1) {
+		switch (errno) {
+		case ENOTDIR:
+		case ENOENT:
+			return (0);
+		default:
+			return (error);
+		}
+	}
+	return (1);
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/namespace.h (from rev 5123, trunk/freebsd-glue/src/namespace.h)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/namespace.h	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/namespace.h	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,3 @@
+#ifndef _NAMESPACE_H_
+#define _NAMESPACE_H_
+#endif

Copied: trunk/freebsd-glue/src/freebsd-glue/random.c (from rev 5123, trunk/freebsd-glue/src/random.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/random.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/random.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,50 @@
+/*-
+ * Copyright (c) 2013 Robert Millan <rmh at debian.org>
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ */
+
+#define _GNU_SOURCE 1		/* srandom() */
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <error.h>
+#include <errno.h>
+
+void
+srandomdev (void)
+{
+  int fd;
+  unsigned long seed;
+
+  fd = open ("/dev/random", O_RDONLY);
+  if (fd == -1)
+    error (1, errno, "open");
+
+  if (read (fd, &seed, sizeof (seed)) != sizeof (seed))
+    error (1, errno, "read");
+
+  srandom (seed);
+
+  close (fd);
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/socket.c (from rev 5123, trunk/freebsd-glue/src/socket.c)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/socket.c	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/socket.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,9 @@
+#include <sys/socket.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+int
+setfib (int fib)
+{
+  return syscall (SYS_setfib, fib);
+}

Copied: trunk/freebsd-glue/src/freebsd-glue/un-namespace.h (from rev 5123, trunk/freebsd-glue/src/un-namespace.h)
===================================================================
--- trunk/freebsd-glue/src/freebsd-glue/un-namespace.h	                        (rev 0)
+++ trunk/freebsd-glue/src/freebsd-glue/un-namespace.h	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,3 @@
+#ifndef _UN_NAMESPACE_H_
+#define _UN_NAMESPACE_H_
+#endif

Deleted: trunk/freebsd-glue/src/fstab.c
===================================================================
--- trunk/freebsd-glue/src/fstab.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/fstab.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,16 +0,0 @@
-#include <fstab.h>
-#include <err.h>
-#include <errno.h>
-#include <string.h>	/* strerror */
-#include <stdio.h>
-
-void
-setfstab (const char *file)
-{
-  fprintf (stderr, "setfstab: %s", strerror (ENOSYS));
-}
-
-const char *getfstab (void)
-{
-  return _PATH_FSTAB;
-}

Deleted: trunk/freebsd-glue/src/funopen.c
===================================================================
--- trunk/freebsd-glue/src/funopen.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/funopen.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,74 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-
-struct cookiebox
-{
-  void *cookie;
-  int (*readfn) (void *, char *, int);
-  int (*writefn) (void *, const char *, int);
-  int (*closefn) (void *);
-};
-
-static ssize_t
-cookiebox_read (void *cookie, char *buf, size_t size)
-{
-  struct cookiebox *cookiebox = cookie;
-  return cookiebox->readfn (cookiebox->cookie, buf, size);
-}
-
-static ssize_t
-cookiebox_write (void *cookie, const char *buf, size_t size)
-{
-  struct cookiebox *cookiebox = cookie;
-  return cookiebox->writefn (cookiebox->cookie, buf, size);
-}
-
-static int
-cookiebox_close (void *cookie)
-{
-  struct cookiebox *cookiebox = cookie;
-  int ret = cookiebox->closefn (cookiebox->cookie);
-  free (cookiebox);
-  return ret;
-}
-
-FILE *
-funopen (const void *cookie, int (*readfn)(void *, char *, int),
-	 int (*writefn)(void *, const char *, int),
-	 fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *))
-{
-  if (seekfn)
-    {
-      errno = ENOSYS;
-      return NULL;
-    }
-
-  cookie_io_functions_t cookiebox_funcs = {
-    .read = cookiebox_read,
-    .write = cookiebox_write,
-    .seek = NULL,
-    .close = cookiebox_close
-  };
-
-  struct cookiebox *cookiebox = malloc (sizeof (*cookiebox));
-  
-  cookiebox->cookie = (void *) cookie;
-  cookiebox->readfn = readfn;
-  cookiebox->writefn = writefn;
-  cookiebox->closefn = closefn;
-
-  return fopencookie ((void *) cookiebox, "r+", cookiebox_funcs);
-}
-
-FILE *
-fropen (void *cookie, int (*readfn)(void *, char *, int))
-{
-  return funopen (cookie, readfn, NULL, NULL, NULL);
-}
-
-FILE *
-fwopen (void *cookie, int (*writefn)(void *, const char *, int))
-{
-  return funopen (cookie, NULL, writefn, NULL, NULL);
-}

Deleted: trunk/freebsd-glue/src/get_elf_arch.c
===================================================================
--- trunk/freebsd-glue/src/get_elf_arch.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/get_elf_arch.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,24 +0,0 @@
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <elf.h>
-
-int
-main (int argc, char **argv)
-{
-  int fd;
-  Elf32_Ehdr ehdr;
-
-  fd = open (argv[0], O_RDONLY);
-  if (fd == -1)
-    perror ("open");
-
-  if (read (fd, &ehdr, sizeof (ehdr)) != sizeof (ehdr))
-    perror ("read");
-
-  printf ("#define ELF_ARCH %u\n", ehdr.e_machine);
-
-  close (fd);
-
-  return 0;
-}

Added: trunk/freebsd-glue/src/get_elf_arch.c
===================================================================
--- trunk/freebsd-glue/src/get_elf_arch.c	                        (rev 0)
+++ trunk/freebsd-glue/src/get_elf_arch.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <elf.h>
+
+int
+main (int argc, char **argv)
+{
+  int fd;
+  Elf32_Ehdr ehdr;
+
+  fd = open (argv[0], O_RDONLY);
+  if (fd == -1)
+    perror ("open");
+
+  if (read (fd, &ehdr, sizeof (ehdr)) != sizeof (ehdr))
+    perror ("read");
+
+  printf ("#define ELF_ARCH %u\n", ehdr.e_machine);
+
+  close (fd);
+
+  return 0;
+}

Deleted: trunk/freebsd-glue/src/getcap.c
===================================================================
--- trunk/freebsd-glue/src/getcap.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/getcap.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,1055 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Casey Leedom of Lawrence Livermore National Laboratory.
- *
- * 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.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getcap.c	8.3 (Berkeley) 3/25/94";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "un-namespace.h"
-
-#include <db.h>
-
-#define	BFRAG		1024
-#define	BSIZE		1024
-#define	ESC		('[' & 037)	/* ASCII ESC */
-#define	MAX_RECURSION	32		/* maximum getent recursion */
-#define	SFRAG		100		/* cgetstr mallocs in SFRAG chunks */
-
-#define RECOK	(char)0
-#define TCERR	(char)1
-#define	SHADOW	(char)2
-
-static size_t	 topreclen;	/* toprec length */
-static char	*toprec;	/* Additional record specified by cgetset() */
-static int	 gottoprec;	/* Flag indicating retrieval of toprecord */
-
-static int	cdbget(DB *, char **, const char *);
-static int 	getent(char **, u_int *, char **, int, const char *, int, char *);
-static int	nfcmp(char *, char *);
-
-/*
- * Cgetset() allows the addition of a user specified buffer to be added
- * to the database array, in effect "pushing" the buffer on top of the
- * virtual database. 0 is returned on success, -1 on failure.
- */
-int
-cgetset(const char *ent)
-{
-	if (ent == NULL) {
-		if (toprec)
-			free(toprec);
-                toprec = NULL;
-                topreclen = 0;
-                return (0);
-        }
-        topreclen = strlen(ent);
-        if ((toprec = malloc (topreclen + 1)) == NULL) {
-		errno = ENOMEM;
-                return (-1);
-	}
-	gottoprec = 0;
-        (void)strcpy(toprec, ent);
-        return (0);
-}
-
-/*
- * Cgetcap searches the capability record buf for the capability cap with
- * type `type'.  A pointer to the value of cap is returned on success, NULL
- * if the requested capability couldn't be found.
- *
- * Specifying a type of ':' means that nothing should follow cap (:cap:).
- * In this case a pointer to the terminating ':' or NUL will be returned if
- * cap is found.
- *
- * If (cap, '@') or (cap, terminator, '@') is found before (cap, terminator)
- * return NULL.
- */
-char *
-cgetcap(char *buf, const char *cap, int type)
-{
-	char *bp;
-	const char *cp;
-
-	bp = buf;
-	for (;;) {
-		/*
-		 * Skip past the current capability field - it's either the
-		 * name field if this is the first time through the loop, or
-		 * the remainder of a field whose name failed to match cap.
-		 */
-		for (;;)
-			if (*bp == '\0')
-				return (NULL);
-			else
-				if (*bp++ == ':')
-					break;
-
-		/*
-		 * Try to match (cap, type) in buf.
-		 */
-		for (cp = cap; *cp == *bp && *bp != '\0'; cp++, bp++)
-			continue;
-		if (*cp != '\0')
-			continue;
-		if (*bp == '@')
-			return (NULL);
-		if (type == ':') {
-			if (*bp != '\0' && *bp != ':')
-				continue;
-			return(bp);
-		}
-		if (*bp != type)
-			continue;
-		bp++;
-		return (*bp == '@' ? NULL : bp);
-	}
-	/* NOTREACHED */
-}
-
-/*
- * Cgetent extracts the capability record name from the NULL terminated file
- * array db_array and returns a pointer to a malloc'd copy of it in buf.
- * Buf must be retained through all subsequent calls to cgetcap, cgetnum,
- * cgetflag, and cgetstr, but may then be free'd.  0 is returned on success,
- * -1 if the requested record couldn't be found, -2 if a system error was
- * encountered (couldn't open/read a file, etc.), and -3 if a potential
- * reference loop is detected.
- */
-int
-cgetent(char **buf, char **db_array, const char *name)
-{
-	u_int dummy;
-
-	return (getent(buf, &dummy, db_array, -1, name, 0, NULL));
-}
-
-/*
- * Getent implements the functions of cgetent.  If fd is non-negative,
- * *db_array has already been opened and fd is the open file descriptor.  We
- * do this to save time and avoid using up file descriptors for tc=
- * recursions.
- *
- * Getent returns the same success/failure codes as cgetent.  On success, a
- * pointer to a malloc'ed capability record with all tc= capabilities fully
- * expanded and its length (not including trailing ASCII NUL) are left in
- * *cap and *len.
- *
- * Basic algorithm:
- *	+ Allocate memory incrementally as needed in chunks of size BFRAG
- *	  for capability buffer.
- *	+ Recurse for each tc=name and interpolate result.  Stop when all
- *	  names interpolated, a name can't be found, or depth exceeds
- *	  MAX_RECURSION.
- */
-static int
-getent(char **cap, u_int *len, char **db_array, int fd, const char *name,
-    int depth, char *nfield)
-{
-	DB *capdbp;
-	char *r_end, *rp, **db_p;
-	int myfd, eof, foundit, retval;
-	char *record, *cbuf;
-	int tc_not_resolved;
-	char pbuf[_POSIX_PATH_MAX];
-
-	/*
-	 * Return with ``loop detected'' error if we've recursed more than
-	 * MAX_RECURSION times.
-	 */
-	if (depth > MAX_RECURSION)
-		return (-3);
-
-	/*
-	 * Check if we have a top record from cgetset().
-         */
-	if (depth == 0 && toprec != NULL && cgetmatch(toprec, name) == 0) {
-		if ((record = malloc (topreclen + BFRAG)) == NULL) {
-			errno = ENOMEM;
-			return (-2);
-		}
-		(void)strcpy(record, toprec);
-		myfd = 0;
-		db_p = db_array;
-		rp = record + topreclen + 1;
-		r_end = rp + BFRAG;
-		goto tc_exp;
-	}
-	/*
-	 * Allocate first chunk of memory.
-	 */
-	if ((record = malloc(BFRAG)) == NULL) {
-		errno = ENOMEM;
-		return (-2);
-	}
-	r_end = record + BFRAG;
-	foundit = 0;
-	/*
-	 * Loop through database array until finding the record.
-	 */
-
-	for (db_p = db_array; *db_p != NULL; db_p++) {
-		eof = 0;
-
-		/*
-		 * Open database if not already open.
-		 */
-
-		if (fd >= 0) {
-			(void)lseek(fd, (off_t)0, SEEK_SET);
-			myfd = 0;
-		} else {
-			(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p);
-			if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0))
-			     != NULL) {
-				free(record);
-				retval = cdbget(capdbp, &record, name);
-				if (retval < 0) {
-					/* no record available */
-					(void)capdbp->close(capdbp);
-					return (retval);
-				}
-				/* save the data; close frees it */
-				cbuf = strdup(record);
-				if (capdbp->close(capdbp) < 0) {
-					free(cbuf);
-					return (-2);
-				}
-				if (cbuf == NULL) {
-					errno = ENOMEM;
-					return (-2);
-				}
-				*len = strlen(cbuf);
-				*cap = cbuf;
-				return (retval);
-			} else {
-				fd = _open(*db_p, O_RDONLY | O_CLOEXEC, 0);
-				if (fd < 0)
-					continue;
-				myfd = 1;
-			}
-		}
-		/*
-		 * Find the requested capability record ...
-		 */
-		{
-		char buf[BUFSIZ];
-		char *b_end, *bp;
-		int c;
-
-		/*
-		 * Loop invariants:
-		 *	There is always room for one more character in record.
-		 *	R_end always points just past end of record.
-		 *	Rp always points just past last character in record.
-		 *	B_end always points just past last character in buf.
-		 *	Bp always points at next character in buf.
-		 */
-		b_end = buf;
-		bp = buf;
-		for (;;) {
-
-			/*
-			 * Read in a line implementing (\, newline)
-			 * line continuation.
-			 */
-			rp = record;
-			for (;;) {
-				if (bp >= b_end) {
-					int n;
-
-					n = _read(fd, buf, sizeof(buf));
-					if (n <= 0) {
-						if (myfd)
-							(void)_close(fd);
-						if (n < 0) {
-							free(record);
-							return (-2);
-						} else {
-							fd = -1;
-							eof = 1;
-							break;
-						}
-					}
-					b_end = buf+n;
-					bp = buf;
-				}
-
-				c = *bp++;
-				if (c == '\n') {
-					if (rp > record && *(rp-1) == '\\') {
-						rp--;
-						continue;
-					} else
-						break;
-				}
-				*rp++ = c;
-
-				/*
-				 * Enforce loop invariant: if no room
-				 * left in record buffer, try to get
-				 * some more.
-				 */
-				if (rp >= r_end) {
-					u_int pos;
-					size_t newsize;
-
-					pos = rp - record;
-					newsize = r_end - record + BFRAG;
-					record = reallocf(record, newsize);
-					if (record == NULL) {
-						errno = ENOMEM;
-						if (myfd)
-							(void)_close(fd);
-						return (-2);
-					}
-					r_end = record + newsize;
-					rp = record + pos;
-				}
-			}
-				/* loop invariant let's us do this */
-			*rp++ = '\0';
-
-			/*
-			 * If encountered eof check next file.
-			 */
-			if (eof)
-				break;
-
-			/*
-			 * Toss blank lines and comments.
-			 */
-			if (*record == '\0' || *record == '#')
-				continue;
-
-			/*
-			 * See if this is the record we want ...
-			 */
-			if (cgetmatch(record, name) == 0) {
-				if (nfield == NULL || !nfcmp(nfield, record)) {
-					foundit = 1;
-					break;	/* found it! */
-				}
-			}
-		}
-	}
-		if (foundit)
-			break;
-	}
-
-	if (!foundit) {
-		free(record);
-		return (-1);
-	}
-
-	/*
-	 * Got the capability record, but now we have to expand all tc=name
-	 * references in it ...
-	 */
-tc_exp:	{
-		char *newicap, *s;
-		int newilen;
-		u_int ilen;
-		int diff, iret, tclen;
-		char *icap, *scan, *tc, *tcstart, *tcend;
-
-		/*
-		 * Loop invariants:
-		 *	There is room for one more character in record.
-		 *	R_end points just past end of record.
-		 *	Rp points just past last character in record.
-		 *	Scan points at remainder of record that needs to be
-		 *	scanned for tc=name constructs.
-		 */
-		scan = record;
-		tc_not_resolved = 0;
-		for (;;) {
-			if ((tc = cgetcap(scan, "tc", '=')) == NULL)
-				break;
-
-			/*
-			 * Find end of tc=name and stomp on the trailing `:'
-			 * (if present) so we can use it to call ourselves.
-			 */
-			s = tc;
-			for (;;)
-				if (*s == '\0')
-					break;
-				else
-					if (*s++ == ':') {
-						*(s - 1) = '\0';
-						break;
-					}
-			tcstart = tc - 3;
-			tclen = s - tcstart;
-			tcend = s;
-
-			iret = getent(&icap, &ilen, db_p, fd, tc, depth+1,
-				      NULL);
-			newicap = icap;		/* Put into a register. */
-			newilen = ilen;
-			if (iret != 0) {
-				/* an error */
-				if (iret < -1) {
-					if (myfd)
-						(void)_close(fd);
-					free(record);
-					return (iret);
-				}
-				if (iret == 1)
-					tc_not_resolved = 1;
-				/* couldn't resolve tc */
-				if (iret == -1) {
-					*(s - 1) = ':';
-					scan = s - 1;
-					tc_not_resolved = 1;
-					continue;
-
-				}
-			}
-			/* not interested in name field of tc'ed record */
-			s = newicap;
-			for (;;)
-				if (*s == '\0')
-					break;
-				else
-					if (*s++ == ':')
-						break;
-			newilen -= s - newicap;
-			newicap = s;
-
-			/* make sure interpolated record is `:'-terminated */
-			s += newilen;
-			if (*(s-1) != ':') {
-				*s = ':';	/* overwrite NUL with : */
-				newilen++;
-			}
-
-			/*
-			 * Make sure there's enough room to insert the
-			 * new record.
-			 */
-			diff = newilen - tclen;
-			if (diff >= r_end - rp) {
-				u_int pos, tcpos, tcposend;
-				size_t newsize;
-
-				pos = rp - record;
-				newsize = r_end - record + diff + BFRAG;
-				tcpos = tcstart - record;
-				tcposend = tcend - record;
-				record = reallocf(record, newsize);
-				if (record == NULL) {
-					errno = ENOMEM;
-					if (myfd)
-						(void)_close(fd);
-					free(icap);
-					return (-2);
-				}
-				r_end = record + newsize;
-				rp = record + pos;
-				tcstart = record + tcpos;
-				tcend = record + tcposend;
-			}
-
-			/*
-			 * Insert tc'ed record into our record.
-			 */
-			s = tcstart + newilen;
-			bcopy(tcend, s, rp - tcend);
-			bcopy(newicap, tcstart, newilen);
-			rp += diff;
-			free(icap);
-
-			/*
-			 * Start scan on `:' so next cgetcap works properly
-			 * (cgetcap always skips first field).
-			 */
-			scan = s-1;
-		}
-
-	}
-	/*
-	 * Close file (if we opened it), give back any extra memory, and
-	 * return capability, length and success.
-	 */
-	if (myfd)
-		(void)_close(fd);
-	*len = rp - record - 1;	/* don't count NUL */
-	if (r_end > rp)
-		if ((record =
-		     reallocf(record, (size_t)(rp - record))) == NULL) {
-			errno = ENOMEM;
-			return (-2);
-		}
-
-	*cap = record;
-	if (tc_not_resolved)
-		return (1);
-	return (0);
-}
-
-static int
-cdbget(DB *capdbp, char **bp, const char *name)
-{
-	DBT key, data;
-	char *namebuf;
-
-	namebuf = strdup(name);
-	if (namebuf == NULL)
-		return (-2);
-	key.data = namebuf;
-	key.size = strlen(namebuf);
-
-	for (;;) {
-		/* Get the reference. */
-		switch(capdbp->get(capdbp, &key, &data, 0)) {
-		case -1:
-			free(namebuf);
-			return (-2);
-		case 1:
-			free(namebuf);
-			return (-1);
-		}
-
-		/* If not an index to another record, leave. */
-		if (((char *)data.data)[0] != SHADOW)
-			break;
-
-		key.data = (char *)data.data + 1;
-		key.size = data.size - 1;
-	}
-
-	*bp = (char *)data.data + 1;
-	free(namebuf);
-	return (((char *)(data.data))[0] == TCERR ? 1 : 0);
-}
-
-/*
- * Cgetmatch will return 0 if name is one of the names of the capability
- * record buf, -1 if not.
- */
-int
-cgetmatch(const char *buf, const char *name)
-{
-	const char *np, *bp;
-
-	if (name == NULL || *name == '\0')
-		return -1;
-
-	/*
-	 * Start search at beginning of record.
-	 */
-	bp = buf;
-	for (;;) {
-		/*
-		 * Try to match a record name.
-		 */
-		np = name;
-		for (;;)
-			if (*np == '\0')
-				if (*bp == '|' || *bp == ':' || *bp == '\0')
-					return (0);
-				else
-					break;
-			else
-				if (*bp++ != *np++)
-					break;
-
-		/*
-		 * Match failed, skip to next name in record.
-		 */
-		bp--;	/* a '|' or ':' may have stopped the match */
-		for (;;)
-			if (*bp == '\0' || *bp == ':')
-				return (-1);	/* match failed totally */
-			else
-				if (*bp++ == '|')
-					break;	/* found next name */
-	}
-}
-
-
-
-
-
-int
-cgetfirst(char **buf, char **db_array)
-{
-	(void)cgetclose();
-	return (cgetnext(buf, db_array));
-}
-
-static FILE *pfp;
-static int slash;
-static char **dbp;
-
-int
-cgetclose(void)
-{
-	if (pfp != NULL) {
-		(void)fclose(pfp);
-		pfp = NULL;
-	}
-	dbp = NULL;
-	gottoprec = 0;
-	slash = 0;
-	return(0);
-}
-
-/*
- * Cgetnext() gets either the first or next entry in the logical database
- * specified by db_array.  It returns 0 upon completion of the database, 1
- * upon returning an entry with more remaining, and -1 if an error occurs.
- */
-int
-cgetnext(char **bp, char **db_array)
-{
-	size_t len;
-	int done, hadreaderr, savederrno, status;
-	char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE];
-	u_int dummy;
-
-	if (dbp == NULL)
-		dbp = db_array;
-
-	if (pfp == NULL && (pfp = fopen(*dbp, "re")) == NULL) {
-		(void)cgetclose();
-		return (-1);
-	}
-	for (;;) {
-		if (toprec && !gottoprec) {
-			gottoprec = 1;
-			line = toprec;
-		} else {
-			line = fgetln(pfp, &len);
-			if (line == NULL && pfp) {
-				hadreaderr = ferror(pfp);
-				if (hadreaderr)
-					savederrno = errno;
-				fclose(pfp);
-				pfp = NULL;
-				if (hadreaderr) {
-					cgetclose();
-					errno = savederrno;
-					return (-1);
-				} else {
-					if (*++dbp == NULL) {
-						(void)cgetclose();
-						return (0);
-					} else if ((pfp =
-					    fopen(*dbp, "re")) == NULL) {
-						(void)cgetclose();
-						return (-1);
-					} else
-						continue;
-				}
-			} else
-				line[len - 1] = '\0';
-			if (len == 1) {
-				slash = 0;
-				continue;
-			}
-			if (isspace((unsigned char)*line) ||
-			    *line == ':' || *line == '#' || slash) {
-				if (line[len - 2] == '\\')
-					slash = 1;
-				else
-					slash = 0;
-				continue;
-			}
-			if (line[len - 2] == '\\')
-				slash = 1;
-			else
-				slash = 0;
-		}
-
-
-		/*
-		 * Line points to a name line.
-		 */
-		done = 0;
-		np = nbuf;
-		for (;;) {
-			for (cp = line; *cp != '\0'; cp++) {
-				if (*cp == ':') {
-					*np++ = ':';
-					done = 1;
-					break;
-				}
-				if (*cp == '\\')
-					break;
-				*np++ = *cp;
-			}
-			if (done) {
-				*np = '\0';
-				break;
-			} else { /* name field extends beyond the line */
-				line = fgetln(pfp, &len);
-				if (line == NULL && pfp) {
-					/* Name extends beyond the EOF! */
-					hadreaderr = ferror(pfp);
-					if (hadreaderr)
-						savederrno = errno;
-					fclose(pfp);
-					pfp = NULL;
-					if (hadreaderr) {
-						cgetclose();
-						errno = savederrno;
-						return (-1);
-					} else {
-						cgetclose();
-						return (-1);
-					}
-				} else
-					line[len - 1] = '\0';
-			}
-		}
-		rp = buf;
-		for(cp = nbuf; *cp != '\0'; cp++)
-			if (*cp == '|' || *cp == ':')
-				break;
-			else
-				*rp++ = *cp;
-
-		*rp = '\0';
-		/*
-		 * XXX
-		 * Last argument of getent here should be nbuf if we want true
-		 * sequential access in the case of duplicates.
-		 * With NULL, getent will return the first entry found
-		 * rather than the duplicate entry record.  This is a
-		 * matter of semantics that should be resolved.
-		 */
-		status = getent(bp, &dummy, db_array, -1, buf, 0, NULL);
-		if (status == -2 || status == -3)
-			(void)cgetclose();
-
-		return (status + 1);
-	}
-	/* NOTREACHED */
-}
-
-/*
- * Cgetstr retrieves the value of the string capability cap from the
- * capability record pointed to by buf.  A pointer to a decoded, NUL
- * terminated, malloc'd copy of the string is returned in the char *
- * pointed to by str.  The length of the string not including the trailing
- * NUL is returned on success, -1 if the requested string capability
- * couldn't be found, -2 if a system error was encountered (storage
- * allocation failure).
- */
-int
-cgetstr(char *buf, const char *cap, char **str)
-{
-	u_int m_room;
-	char *bp, *mp;
-	int len;
-	char *mem;
-
-	/*
-	 * Find string capability cap
-	 */
-	bp = cgetcap(buf, cap, '=');
-	if (bp == NULL)
-		return (-1);
-
-	/*
-	 * Conversion / storage allocation loop ...  Allocate memory in
-	 * chunks SFRAG in size.
-	 */
-	if ((mem = malloc(SFRAG)) == NULL) {
-		errno = ENOMEM;
-		return (-2);	/* couldn't even allocate the first fragment */
-	}
-	m_room = SFRAG;
-	mp = mem;
-
-	while (*bp != ':' && *bp != '\0') {
-		/*
-		 * Loop invariants:
-		 *	There is always room for one more character in mem.
-		 *	Mp always points just past last character in mem.
-		 *	Bp always points at next character in buf.
-		 */
-		if (*bp == '^') {
-			bp++;
-			if (*bp == ':' || *bp == '\0')
-				break;	/* drop unfinished escape */
-			if (*bp == '?') {
-				*mp++ = '\177';
-				bp++;
-			} else
-				*mp++ = *bp++ & 037;
-		} else if (*bp == '\\') {
-			bp++;
-			if (*bp == ':' || *bp == '\0')
-				break;	/* drop unfinished escape */
-			if ('0' <= *bp && *bp <= '7') {
-				int n, i;
-
-				n = 0;
-				i = 3;	/* maximum of three octal digits */
-				do {
-					n = n * 8 + (*bp++ - '0');
-				} while (--i && '0' <= *bp && *bp <= '7');
-				*mp++ = n;
-			}
-			else switch (*bp++) {
-				case 'b': case 'B':
-					*mp++ = '\b';
-					break;
-				case 't': case 'T':
-					*mp++ = '\t';
-					break;
-				case 'n': case 'N':
-					*mp++ = '\n';
-					break;
-				case 'f': case 'F':
-					*mp++ = '\f';
-					break;
-				case 'r': case 'R':
-					*mp++ = '\r';
-					break;
-				case 'e': case 'E':
-					*mp++ = ESC;
-					break;
-				case 'c': case 'C':
-					*mp++ = ':';
-					break;
-				default:
-					/*
-					 * Catches '\', '^', and
-					 *  everything else.
-					 */
-					*mp++ = *(bp-1);
-					break;
-			}
-		} else
-			*mp++ = *bp++;
-		m_room--;
-
-		/*
-		 * Enforce loop invariant: if no room left in current
-		 * buffer, try to get some more.
-		 */
-		if (m_room == 0) {
-			size_t size = mp - mem;
-
-			if ((mem = reallocf(mem, size + SFRAG)) == NULL)
-				return (-2);
-			m_room = SFRAG;
-			mp = mem + size;
-		}
-	}
-	*mp++ = '\0';	/* loop invariant let's us do this */
-	m_room--;
-	len = mp - mem - 1;
-
-	/*
-	 * Give back any extra memory and return value and success.
-	 */
-	if (m_room != 0)
-		if ((mem = reallocf(mem, (size_t)(mp - mem))) == NULL)
-			return (-2);
-	*str = mem;
-	return (len);
-}
-
-/*
- * Cgetustr retrieves the value of the string capability cap from the
- * capability record pointed to by buf.  The difference between cgetustr()
- * and cgetstr() is that cgetustr does not decode escapes but rather treats
- * all characters literally.  A pointer to a  NUL terminated malloc'd
- * copy of the string is returned in the char pointed to by str.  The
- * length of the string not including the trailing NUL is returned on success,
- * -1 if the requested string capability couldn't be found, -2 if a system
- * error was encountered (storage allocation failure).
- */
-int
-cgetustr(char *buf, const char *cap, char **str)
-{
-	u_int m_room;
-	char *bp, *mp;
-	int len;
-	char *mem;
-
-	/*
-	 * Find string capability cap
-	 */
-	if ((bp = cgetcap(buf, cap, '=')) == NULL)
-		return (-1);
-
-	/*
-	 * Conversion / storage allocation loop ...  Allocate memory in
-	 * chunks SFRAG in size.
-	 */
-	if ((mem = malloc(SFRAG)) == NULL) {
-		errno = ENOMEM;
-		return (-2);	/* couldn't even allocate the first fragment */
-	}
-	m_room = SFRAG;
-	mp = mem;
-
-	while (*bp != ':' && *bp != '\0') {
-		/*
-		 * Loop invariants:
-		 *	There is always room for one more character in mem.
-		 *	Mp always points just past last character in mem.
-		 *	Bp always points at next character in buf.
-		 */
-		*mp++ = *bp++;
-		m_room--;
-
-		/*
-		 * Enforce loop invariant: if no room left in current
-		 * buffer, try to get some more.
-		 */
-		if (m_room == 0) {
-			size_t size = mp - mem;
-
-			if ((mem = reallocf(mem, size + SFRAG)) == NULL)
-				return (-2);
-			m_room = SFRAG;
-			mp = mem + size;
-		}
-	}
-	*mp++ = '\0';	/* loop invariant let's us do this */
-	m_room--;
-	len = mp - mem - 1;
-
-	/*
-	 * Give back any extra memory and return value and success.
-	 */
-	if (m_room != 0)
-		if ((mem = reallocf(mem, (size_t)(mp - mem))) == NULL)
-			return (-2);
-	*str = mem;
-	return (len);
-}
-
-/*
- * Cgetnum retrieves the value of the numeric capability cap from the
- * capability record pointed to by buf.  The numeric value is returned in
- * the long pointed to by num.  0 is returned on success, -1 if the requested
- * numeric capability couldn't be found.
- */
-int
-cgetnum(char *buf, const char *cap, long *num)
-{
-	long n;
-	int base, digit;
-	char *bp;
-
-	/*
-	 * Find numeric capability cap
-	 */
-	bp = cgetcap(buf, cap, '#');
-	if (bp == NULL)
-		return (-1);
-
-	/*
-	 * Look at value and determine numeric base:
-	 *	0x... or 0X...	hexadecimal,
-	 * else	0...		octal,
-	 * else			decimal.
-	 */
-	if (*bp == '0') {
-		bp++;
-		if (*bp == 'x' || *bp == 'X') {
-			bp++;
-			base = 16;
-		} else
-			base = 8;
-	} else
-		base = 10;
-
-	/*
-	 * Conversion loop ...
-	 */
-	n = 0;
-	for (;;) {
-		if ('0' <= *bp && *bp <= '9')
-			digit = *bp - '0';
-		else if ('a' <= *bp && *bp <= 'f')
-			digit = 10 + *bp - 'a';
-		else if ('A' <= *bp && *bp <= 'F')
-			digit = 10 + *bp - 'A';
-		else
-			break;
-
-		if (digit >= base)
-			break;
-
-		n = n * base + digit;
-		bp++;
-	}
-
-	/*
-	 * Return value and success.
-	 */
-	*num = n;
-	return (0);
-}
-
-
-/*
- * Compare name field of record.
- */
-static int
-nfcmp(char *nf, char *rec)
-{
-	char *cp, tmp;
-	int ret;
-
-	for (cp = rec; *cp != ':'; cp++)
-		;
-
-	tmp = *(cp + 1);
-	*(cp + 1) = '\0';
-	ret = strcmp(nf, rec);
-	*(cp + 1) = tmp;
-
-	return (ret);
-}

Deleted: trunk/freebsd-glue/src/getosreldate.c
===================================================================
--- trunk/freebsd-glue/src/getosreldate.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/getosreldate.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  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.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-#include <stddef.h>
-#include <sys/sysctl.h>
-#include <stdlib.h>
-
-int
-getosreldate(void)
-{
-	int value;
-	char *temp;
-
-	if ((temp = getenv("OSVERSION"))) {
-		value = atoi(temp);
-		return (value);
-	}
-
-#ifdef __FreeBSD_kernel__ 
-	int mib[2];
-	size_t size;
-	mib[0] = CTL_KERN;
-	mib[1] = KERN_OSRELDATE;
-	size = sizeof value;
-	if (sysctl(mib, 2, &value, &size, NULL, 0) == -1)
-		return (-1);
-	return (value);
-#else
-	return 0;
-#endif
-}

Deleted: trunk/freebsd-glue/src/linkaddr.c
===================================================================
--- trunk/freebsd-glue/src/linkaddr.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/linkaddr.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,155 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  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.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)linkaddr.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <net/if_dl.h>
-#include <string.h>
-
-/* States*/
-#define NAMING	0
-#define GOTONE	1
-#define GOTTWO	2
-#define RESET	3
-/* Inputs */
-#define	DIGIT	(4*0)
-#define	END	(4*1)
-#define DELIM	(4*2)
-#define LETTER	(4*3)
-
-void
-link_addr(addr, sdl)
-	const char *addr;
-	struct sockaddr_dl *sdl;
-{
-	char *cp = sdl->sdl_data;
-	char *cplim = sdl->sdl_len + (char *)sdl;
-	int byte = 0, state = NAMING, new;
-
-	bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1);
-	sdl->sdl_family = AF_LINK;
-	do {
-		state &= ~LETTER;
-		if ((*addr >= '0') && (*addr <= '9')) {
-			new = *addr - '0';
-		} else if ((*addr >= 'a') && (*addr <= 'f')) {
-			new = *addr - 'a' + 10;
-		} else if ((*addr >= 'A') && (*addr <= 'F')) {
-			new = *addr - 'A' + 10;
-		} else if (*addr == 0) {
-			state |= END;
-		} else if (state == NAMING &&
-			   (((*addr >= 'A') && (*addr <= 'Z')) ||
-			   ((*addr >= 'a') && (*addr <= 'z'))))
-			state |= LETTER;
-		else
-			state |= DELIM;
-		addr++;
-		switch (state /* | INPUT */) {
-		case NAMING | DIGIT:
-		case NAMING | LETTER:
-			*cp++ = addr[-1];
-			continue;
-		case NAMING | DELIM:
-			state = RESET;
-			sdl->sdl_nlen = cp - sdl->sdl_data;
-			continue;
-		case GOTTWO | DIGIT:
-			*cp++ = byte;
-			/* FALLTHROUGH */
-		case RESET | DIGIT:
-			state = GOTONE;
-			byte = new;
-			continue;
-		case GOTONE | DIGIT:
-			state = GOTTWO;
-			byte = new + (byte << 4);
-			continue;
-		default: /* | DELIM */
-			state = RESET;
-			*cp++ = byte;
-			byte = 0;
-			continue;
-		case GOTONE | END:
-		case GOTTWO | END:
-			*cp++ = byte;
-			/* FALLTHROUGH */
-		case RESET | END:
-			break;
-		}
-		break;
-	} while (cp < cplim);
-	sdl->sdl_alen = cp - LLADDR(sdl);
-	new = cp - (char *)sdl;
-	if (new > sizeof(*sdl))
-		sdl->sdl_len = new;
-	return;
-}
-
-static char hexlist[] = "0123456789abcdef";
-
-char *
-link_ntoa(sdl)
-	const struct sockaddr_dl *sdl;
-{
-	static char obuf[64];
-	char *out = obuf;
-	int i;
-	u_char *in = (u_char *)LLADDR(sdl);
-	u_char *inlim = in + sdl->sdl_alen;
-	int firsttime = 1;
-
-	if (sdl->sdl_nlen) {
-		bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen);
-		out += sdl->sdl_nlen;
-		if (sdl->sdl_alen)
-			*out++ = ':';
-	}
-	while (in < inlim) {
-		if (firsttime)
-			firsttime = 0;
-		else
-			*out++ = '.';
-		i = *in++;
-		if (i > 0xf) {
-			out[1] = hexlist[i & 0xf];
-			i >>= 4;
-			out[0] = hexlist[i];
-			out += 2;
-		} else
-			*out++ = hexlist[i];
-	}
-	*out = 0;
-	return (obuf);
-}

Deleted: trunk/freebsd-glue/src/login_class.c
===================================================================
--- trunk/freebsd-glue/src/login_class.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/login_class.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,15 +0,0 @@
-#include <unistd.h>
-#include <sys/syscall.h>
-#include <stddef.h>
-
-int
-getloginclass (char *name, size_t len)
-{
-  return syscall (SYS_getloginclass, name, len);
-}
-
-int
-setloginclass (const char *name)
-{
-  return syscall (SYS_setloginclass, name);
-}

Deleted: trunk/freebsd-glue/src/mac.c
===================================================================
--- trunk/freebsd-glue/src/mac.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/mac.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,449 +0,0 @@
-/*
- * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
- * Copyright (c) 2002, 2003 Networks Associates Technology, Inc.
- * All rights reserved.
- *
- * This software was developed by Robert Watson for the TrustedBSD Project.
- *
- * This software was developed for the FreeBSD Project in part by Network
- * Associates Laboratories, the Security Research Division of Network
- * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
- * as part of the DARPA CHATS research program.
- *
- * 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 AUTHOR 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 AUTHOR 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/sysctl.h>
-
-#include <dlfcn.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <sys/mac.h>
-
-static int	internal_initialized;
-
-/*
- * Maintain a list of default label preparations for various object
- * types.  Each name will appear only once in the list.
- *
- * XXXMAC: Not thread-safe.
- */
-static LIST_HEAD(, label_default) label_default_head;
-struct label_default {
-	char				*ld_name;
-	char				*ld_labels;
-	LIST_ENTRY(label_default)	 ld_entries;
-};
-
-static void
-mac_destroy_labels(void)
-{
-	struct label_default *ld;
-
-	while ((ld = LIST_FIRST(&label_default_head))) {
-		free(ld->ld_name);
-		free(ld->ld_labels);
-		LIST_REMOVE(ld, ld_entries);
-		free(ld);
-	}
-}
-
-static void
-mac_destroy_internal(void)
-{
-
-	mac_destroy_labels();
-
-	internal_initialized = 0;
-}
-
-static int
-mac_add_type(const char *name, const char *labels)
-{
-	struct label_default *ld, *ld_new;
-	char *name_dup, *labels_dup;
-
-	/*
-	 * Speculatively allocate all the memory now to avoid allocating
-	 * later when we will someday hold a mutex.
-	 */
-	name_dup = strdup(name);
-	if (name_dup == NULL) {
-		errno = ENOMEM;
-		return (-1);
-	}
-	labels_dup = strdup(labels);
-	if (labels_dup == NULL) {
-		free(name_dup);
-		errno = ENOMEM;
-		return (-1);
-	}
-	ld_new = malloc(sizeof(*ld));
-	if (ld_new == NULL) {
-		free(name_dup);
-		free(labels_dup);
-		errno = ENOMEM;
-		return (-1);
-	}
-
-	/*
-	 * If the type is already present, replace the current entry
-	 * rather than add a new instance.
-	 */
-	for (ld = LIST_FIRST(&label_default_head); ld != NULL;
-	    ld = LIST_NEXT(ld, ld_entries)) {
-		if (strcmp(name, ld->ld_name) == 0)
-			break;
-	}
-
-	if (ld != NULL) {
-		free(ld->ld_labels);
-		ld->ld_labels = labels_dup;
-		labels_dup = NULL;
-	} else {
-		ld = ld_new;
-		ld->ld_name = name_dup;
-		ld->ld_labels = labels_dup;
-
-		ld_new = NULL;
-		name_dup = NULL;
-		labels_dup = NULL;
-
-		LIST_INSERT_HEAD(&label_default_head, ld, ld_entries);
-	}
-
-	if (name_dup != NULL)
-		free(name_dup);
-	if (labels_dup != NULL)
-		free(labels_dup);
-	if (ld_new != NULL)
-		free(ld_new);
-
-	return (0);
-}
-
-static char *
-next_token(char **string)
-{
-	char *token;
-
-	token = strsep(string, " \t");
-	while (token != NULL && *token == '\0')
-		token = strsep(string, " \t");
-
-	return (token);
-}
-
-static int
-mac_init_internal(int ignore_errors)
-{
-	const char *filename;
-	char line[LINE_MAX];
-	FILE *file;
-	int error;
-
-	error = 0;
-
-	LIST_INIT(&label_default_head);
-
-	if (!issetugid() && getenv("MAC_CONFFILE") != NULL)
-		filename = getenv("MAC_CONFFILE");
-	else
-		filename = MAC_CONFFILE;
-	file = fopen(filename, "re");
-	if (file == NULL)
-		return (0);
-
-	while (fgets(line, LINE_MAX, file)) {
-		char *comment, *parse, *statement;
-
-		if (line[strlen(line)-1] == '\n')
-			line[strlen(line)-1] = '\0';
-		else {
-			if (ignore_errors)
-				continue;
-			fclose(file);
-			error = EINVAL;
-			goto just_return;
-		}
-
-		/* Remove any comment. */
-		comment = line;
-		parse = strsep(&comment, "#");
-
-		/* Blank lines OK. */
-		statement = next_token(&parse);
-		if (statement == NULL)
-			continue;
-
-		if (strcmp(statement, "default_labels") == 0) {
-			char *name, *labels;
-
-			name = next_token(&parse);
-			labels = next_token(&parse);
-			if (name == NULL || labels == NULL ||
-			    next_token(&parse) != NULL) {
-				if (ignore_errors)
-					continue;
-				error = EINVAL;
-				fclose(file);
-				goto just_return;
-			}
-
-			if (mac_add_type(name, labels) == -1) {
-				if (ignore_errors)
-					continue;
-				fclose(file);
-				goto just_return;
-			}
-		} else if (strcmp(statement, "default_ifnet_labels") == 0 ||
-		    strcmp(statement, "default_file_labels") == 0 ||
-		    strcmp(statement, "default_process_labels") == 0) {
-			char *labels, *type;
-
-			if (strcmp(statement, "default_ifnet_labels") == 0)
-				type = "ifnet";
-			else if (strcmp(statement, "default_file_labels") == 0)
-				type = "file";
-			else if (strcmp(statement, "default_process_labels") ==
-			    0)
-				type = "process";
-
-			labels = next_token(&parse);
-			if (labels == NULL || next_token(&parse) != NULL) {
-				if (ignore_errors)
-					continue;
-				error = EINVAL;
-				fclose(file);
-				goto just_return;
-			}
-
-			if (mac_add_type(type, labels) == -1) {
-				if (ignore_errors)
-					continue;
-				fclose(file);
-				goto just_return;
-			}
-		} else {
-			if (ignore_errors)
-				continue;
-			fclose(file);
-			error = EINVAL;
-			goto just_return;
-		}
-	}
-
-	fclose(file);
-
-	internal_initialized = 1;
-
-just_return:
-	if (error != 0)
-		mac_destroy_internal();
-	return (error);
-}
-
-static int
-mac_maybe_init_internal(void)
-{
-
-	if (!internal_initialized)
-		return (mac_init_internal(1));
-	else
-		return (0);
-}
-
-int
-mac_reload(void)
-{
-
-	if (internal_initialized)
-		mac_destroy_internal();
-	return (mac_init_internal(0));
-}
-
-int
-mac_free(struct mac *mac)
-{
-
-	if (mac->m_string != NULL)
-		free(mac->m_string);
-	free(mac);
-
-	return (0);
-}
-
-int
-mac_from_text(struct mac **mac, const char *text)
-{
-
-	*mac = (struct mac *) malloc(sizeof(**mac));
-	if (*mac == NULL)
-		return (ENOMEM);
-
-	(*mac)->m_string = strdup(text);
-	if ((*mac)->m_string == NULL) {
-		free(*mac);
-		*mac = NULL;
-		return (ENOMEM);
-	}
-
-	(*mac)->m_buflen = strlen((*mac)->m_string)+1;
-
-	return (0);
-}
-
-int
-mac_to_text(struct mac *mac, char **text)
-{
-
-	*text = strdup(mac->m_string);
-	if (*text == NULL)
-		return (ENOMEM);
-	return (0);
-}
-
-int
-mac_prepare(struct mac **mac, const char *elements)
-{
-
-	if (strlen(elements) >= MAC_MAX_LABEL_BUF_LEN)
-		return (EINVAL);
-
-	*mac = (struct mac *) malloc(sizeof(**mac));
-	if (*mac == NULL)
-		return (ENOMEM);
-
-	(*mac)->m_string = malloc(MAC_MAX_LABEL_BUF_LEN);
-	if ((*mac)->m_string == NULL) {
-		free(*mac);
-		*mac = NULL;
-		return (ENOMEM);
-	}
-
-	strcpy((*mac)->m_string, elements);
-	(*mac)->m_buflen = MAC_MAX_LABEL_BUF_LEN;
-
-	return (0);
-}
-
-int
-mac_prepare_type(struct mac **mac, const char *name)
-{
-	struct label_default *ld;
-	int error;
-
-	error = mac_maybe_init_internal();
-	if (error != 0)
-		return (error);
-
-	for (ld = LIST_FIRST(&label_default_head); ld != NULL;
-	    ld = LIST_NEXT(ld, ld_entries)) {
-		if (strcmp(name, ld->ld_name) == 0)
-			return (mac_prepare(mac, ld->ld_labels));
-	}
-
-	errno = ENOENT;
-	return (-1);		/* XXXMAC: ENOLABEL */
-}
-
-int
-mac_prepare_ifnet_label(struct mac **mac)
-{
-
-	return (mac_prepare_type(mac, "ifnet"));
-}
-
-int
-mac_prepare_file_label(struct mac **mac)
-{
-
-	return (mac_prepare_type(mac, "file"));
-}
-
-int
-mac_prepare_packet_label(struct mac **mac)
-{
-
-	return (mac_prepare_type(mac, "packet"));
-}
-
-int
-mac_prepare_process_label(struct mac **mac)
-{
-
-	return (mac_prepare_type(mac, "process"));
-}
-
-/*
- * Simply test whether the TrustedBSD/MAC MIB tree is present; if so,
- * return 1 to indicate that the system has MAC enabled overall or for
- * a given policy.
- */
-int
-mac_is_present(const char *policyname)
-{
-	int mib[5];
-	size_t siz;
-	char *mibname;
-	int error;
-
-	if (policyname != NULL) {
-		if (policyname[strcspn(policyname, ".=")] != '\0') {
-			errno = EINVAL;
-			return (-1);
-		}
-		mibname = malloc(sizeof("security.mac.") - 1 +
-		    strlen(policyname) + sizeof(".enabled"));
-		if (mibname == NULL)
-			return (-1);
-		strcpy(mibname, "security.mac.");
-		strcat(mibname, policyname);
-		strcat(mibname, ".enabled");
-		siz = 5;
-		error = sysctlnametomib(mibname, mib, &siz);
-		free(mibname);
-	} else {
-		siz = 3;
-		error = sysctlnametomib("security.mac", mib, &siz);
-	}
-	if (error == -1) {
-		switch (errno) {
-		case ENOTDIR:
-		case ENOENT:
-			return (0);
-		default:
-			return (error);
-		}
-	}
-	return (1);
-}

Deleted: trunk/freebsd-glue/src/namespace.h
===================================================================
--- trunk/freebsd-glue/src/namespace.h	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/namespace.h	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,3 +0,0 @@
-#ifndef _NAMESPACE_H_
-#define _NAMESPACE_H_
-#endif

Deleted: trunk/freebsd-glue/src/random.c
===================================================================
--- trunk/freebsd-glue/src/random.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/random.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,50 +0,0 @@
-/*-
- * Copyright (c) 2013 Robert Millan <rmh at debian.org>
- *
- * 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 AUTHOR 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 AUTHOR 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.
- *
- */
-
-#define _GNU_SOURCE 1		/* srandom() */
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <error.h>
-#include <errno.h>
-
-void
-srandomdev (void)
-{
-  int fd;
-  unsigned long seed;
-
-  fd = open ("/dev/random", O_RDONLY);
-  if (fd == -1)
-    error (1, errno, "open");
-
-  if (read (fd, &seed, sizeof (seed)) != sizeof (seed))
-    error (1, errno, "read");
-
-  srandom (seed);
-
-  close (fd);
-}

Deleted: trunk/freebsd-glue/src/socket.c
===================================================================
--- trunk/freebsd-glue/src/socket.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/socket.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,9 +0,0 @@
-#include <sys/socket.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-
-int
-setfib (int fib)
-{
-  return syscall (SYS_setfib, fib);
-}

Deleted: trunk/freebsd-glue/src/trimdomain.c
===================================================================
--- trunk/freebsd-glue/src/trimdomain.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/trimdomain.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,113 +0,0 @@
-/*-
- * Copyright (c) 2001 Brian Somers <brian at Awfulhak.org>
- *   Based on original work by Atsushi Murai <amurai at FreeBSD.org>
- * 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 AUTHOR 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 AUTHOR 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.
- *
- */
-
-#include <sys/cdefs.h>
-#include <sys/param.h>
-
-#include <libutil.h>
-#include <string.h>
-#include <unistd.h>
-
-static int	isDISP(const char *);
-
-/*-
- * Trim the current domain name from fullhost, but only if the result
- * is less than or equal to hostsize in length.
- *
- * This function understands $DISPLAY type fullhosts.
- *
- * For example:
- *
- *     trimdomain("abcde.my.domain", 5)       ->   "abcde"
- *     trimdomain("abcde.my.domain", 4)       ->   "abcde.my.domain"
- *     trimdomain("abcde.my.domain:0.0", 9)   ->   "abcde:0.0"
- *     trimdomain("abcde.my.domain:0.0", 8)   ->   "abcde.my.domain:0.0"
- */
-void
-trimdomain(char *fullhost, int hostsize)
-{
-	static size_t dlen;
-	static int first = 1;
-	static char domain[MAXHOSTNAMELEN];
-	char *end, *s;
-	size_t len;
-
-	if (first) {
-		/* XXX: Should we assume that our domain is this persistent ? */
-		first = 0;
-		if (gethostname(domain, sizeof(domain) - 1) == 0 &&
-		    (s = strchr(domain, '.')) != NULL)
-			memmove(domain, s + 1, strlen(s + 1) + 1);
-		else
-			domain[0] = '\0';
-		dlen = strlen(domain);
-	}
-
-	if (domain[0] == '\0')
-		return;
-
-	s = fullhost;
-	end = s + hostsize + 1;
-	if ((s = memchr(s, '.', (size_t)(end - s))) != NULL) {
-		if (strncasecmp(s + 1, domain, dlen) == 0) {
-			if (s[dlen + 1] == '\0') {
-				/* Found -- lose the domain. */
-				*s = '\0';
-			} else if (s[dlen + 1] == ':' &&
-			    isDISP(s + dlen + 2) &&
-			    (len = strlen(s + dlen + 1)) < (size_t)(end - s)) {
-				/* Found -- shuffle the DISPLAY back. */
-				memmove(s, s + dlen + 1, len + 1);
-			}
-		}
-	}
-}
-
-/*
- * Is the given string NN or NN.NN where ``NN'' is an all-numeric string ?
- */
-static int
-isDISP(const char *disp)
-{
-	size_t w;
-	int res;
-
-	w = strspn(disp, "0123456789");
-	res = 0;
-	if (w > 0) {
-		if (disp[w] == '\0')
-			res = 1;	/* NN */
-		else if (disp[w] == '.') {
-			disp += w + 1;
-			w = strspn(disp, "0123456789");
-			if (w > 0 && disp[w] == '\0')
-				res = 1;	/* NN.NN */
-		}
-	}
-	return (res);
-}

Deleted: trunk/freebsd-glue/src/un-namespace.h
===================================================================
--- trunk/freebsd-glue/src/un-namespace.h	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/un-namespace.h	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,3 +0,0 @@
-#ifndef _UN_NAMESPACE_H_
-#define _UN_NAMESPACE_H_
-#endif

Added: trunk/freebsd-glue/src/util/Makefile
===================================================================
--- trunk/freebsd-glue/src/util/Makefile	                        (rev 0)
+++ trunk/freebsd-glue/src/util/Makefile	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,6 @@
+LIB=	util-freebsd
+SRCS=	\
+	trimdomain.c \
+	${NULL}
+
+.include <bsd.lib.mk>

Copied: trunk/freebsd-glue/src/util/trimdomain.c (from rev 5123, trunk/freebsd-glue/src/trimdomain.c)
===================================================================
--- trunk/freebsd-glue/src/util/trimdomain.c	                        (rev 0)
+++ trunk/freebsd-glue/src/util/trimdomain.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,113 @@
+/*-
+ * Copyright (c) 2001 Brian Somers <brian at Awfulhak.org>
+ *   Based on original work by Atsushi Murai <amurai at FreeBSD.org>
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ */
+
+#include <sys/cdefs.h>
+#include <sys/param.h>
+
+#include <libutil.h>
+#include <string.h>
+#include <unistd.h>
+
+static int	isDISP(const char *);
+
+/*-
+ * Trim the current domain name from fullhost, but only if the result
+ * is less than or equal to hostsize in length.
+ *
+ * This function understands $DISPLAY type fullhosts.
+ *
+ * For example:
+ *
+ *     trimdomain("abcde.my.domain", 5)       ->   "abcde"
+ *     trimdomain("abcde.my.domain", 4)       ->   "abcde.my.domain"
+ *     trimdomain("abcde.my.domain:0.0", 9)   ->   "abcde:0.0"
+ *     trimdomain("abcde.my.domain:0.0", 8)   ->   "abcde.my.domain:0.0"
+ */
+void
+trimdomain(char *fullhost, int hostsize)
+{
+	static size_t dlen;
+	static int first = 1;
+	static char domain[MAXHOSTNAMELEN];
+	char *end, *s;
+	size_t len;
+
+	if (first) {
+		/* XXX: Should we assume that our domain is this persistent ? */
+		first = 0;
+		if (gethostname(domain, sizeof(domain) - 1) == 0 &&
+		    (s = strchr(domain, '.')) != NULL)
+			memmove(domain, s + 1, strlen(s + 1) + 1);
+		else
+			domain[0] = '\0';
+		dlen = strlen(domain);
+	}
+
+	if (domain[0] == '\0')
+		return;
+
+	s = fullhost;
+	end = s + hostsize + 1;
+	if ((s = memchr(s, '.', (size_t)(end - s))) != NULL) {
+		if (strncasecmp(s + 1, domain, dlen) == 0) {
+			if (s[dlen + 1] == '\0') {
+				/* Found -- lose the domain. */
+				*s = '\0';
+			} else if (s[dlen + 1] == ':' &&
+			    isDISP(s + dlen + 2) &&
+			    (len = strlen(s + dlen + 1)) < (size_t)(end - s)) {
+				/* Found -- shuffle the DISPLAY back. */
+				memmove(s, s + dlen + 1, len + 1);
+			}
+		}
+	}
+}
+
+/*
+ * Is the given string NN or NN.NN where ``NN'' is an all-numeric string ?
+ */
+static int
+isDISP(const char *disp)
+{
+	size_t w;
+	int res;
+
+	w = strspn(disp, "0123456789");
+	res = 0;
+	if (w > 0) {
+		if (disp[w] == '\0')
+			res = 1;	/* NN */
+		else if (disp[w] == '.') {
+			disp += w + 1;
+			w = strspn(disp, "0123456789");
+			if (w > 0 && disp[w] == '\0')
+				res = 1;	/* NN.NN */
+		}
+	}
+	return (res);
+}

Added: trunk/freebsd-glue/src/z/Makefile
===================================================================
--- trunk/freebsd-glue/src/z/Makefile	                        (rev 0)
+++ trunk/freebsd-glue/src/z/Makefile	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,8 @@
+LIB=	z-freebsd
+SRCS=	\
+	zopen.c \
+	${NULL}
+
+LDADD=	-lz
+
+.include <bsd.lib.mk>

Copied: trunk/freebsd-glue/src/z/zopen.c (from rev 5123, trunk/freebsd-glue/src/zopen.c)
===================================================================
--- trunk/freebsd-glue/src/z/zopen.c	                        (rev 0)
+++ trunk/freebsd-glue/src/z/zopen.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -0,0 +1,43 @@
+/*
+ * Public domain stdio wrapper for libz, written by Johan Danielsson.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libz/zopen.c 84228 2001-09-30 22:39:00Z dillon $");
+
+#include <stdio.h>
+#include <zlib.h>
+
+FILE *zopen(const char *fname, const char *mode);
+
+/* convert arguments */
+static int
+xgzread(void *cookie, char *data, int size)
+{
+    return gzread(cookie, data, size);
+}
+
+static int
+xgzwrite(void *cookie, const char *data, int size)
+{
+    return gzwrite(cookie, (void*)data, size);
+}
+
+static int
+xgzclose(void *cookie)
+{
+    return gzclose(cookie);
+}
+
+FILE *
+zopen(const char *fname, const char *mode)
+{
+    gzFile gz = gzopen(fname, mode);
+    if(gz == NULL)
+	return NULL;
+
+    if(*mode == 'r')
+	return (funopen(gz, xgzread, NULL, NULL, xgzclose));
+    else
+	return (funopen(gz, NULL, xgzwrite, NULL, xgzclose));
+}

Deleted: trunk/freebsd-glue/src/zopen.c
===================================================================
--- trunk/freebsd-glue/src/zopen.c	2013-11-20 13:35:56 UTC (rev 5140)
+++ trunk/freebsd-glue/src/zopen.c	2013-11-20 13:40:37 UTC (rev 5141)
@@ -1,43 +0,0 @@
-/*
- * Public domain stdio wrapper for libz, written by Johan Danielsson.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libz/zopen.c 84228 2001-09-30 22:39:00Z dillon $");
-
-#include <stdio.h>
-#include <zlib.h>
-
-FILE *zopen(const char *fname, const char *mode);
-
-/* convert arguments */
-static int
-xgzread(void *cookie, char *data, int size)
-{
-    return gzread(cookie, data, size);
-}
-
-static int
-xgzwrite(void *cookie, const char *data, int size)
-{
-    return gzwrite(cookie, (void*)data, size);
-}
-
-static int
-xgzclose(void *cookie)
-{
-    return gzclose(cookie);
-}
-
-FILE *
-zopen(const char *fname, const char *mode)
-{
-    gzFile gz = gzopen(fname, mode);
-    if(gz == NULL)
-	return NULL;
-
-    if(*mode == 'r')
-	return (funopen(gz, xgzread, NULL, NULL, xgzclose));
-    else
-	return (funopen(gz, NULL, xgzwrite, NULL, xgzclose));
-}




More information about the Glibc-bsd-commits mailing list