Permalink
Browse files

Add the new pbimount / pbime commands, which will be used internally

by the PBI format to do the mounting / runtime of a target PBI app
  • Loading branch information...
1 parent 3890273 commit 94b18f3c646454853adb2d98724b1afd44b58696 @kmoore134 kmoore134 committed Oct 3, 2013
@@ -17,6 +17,7 @@ else
fi
DIR=`dirname $0`
+DIR=`realpath $DIR`
cd ${DIR}
# Install the app
@@ -123,4 +124,6 @@ make install DEFINES=""
chown root:wheel pbiwrapper
chmod 644 pbiwrapper
mv pbiwrapper ${LB}/share/pbi-manager/.pbiwrapper-`uname -m`
-cp ldconfig ${LB}/share/pbi-manager/ldconfig-pbi
+
+# Install the pbime wrapper
+cd ${DIR}/pbime && make install
@@ -0,0 +1,9 @@
+
+all: pbime
+
+pbime: pbime.c
+ ${CC} -lutil -o pbime pbime.c
+
+install: pbime
+ install -o root -g wheel -m 4751 pbime /usr/pbi/.pbime
+ install -o root -g wheel -m 755 pbimount /usr/pbi/.pbimount
@@ -0,0 +1,113 @@
+/*-
+ * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
+ * Copyright (c) 2007 Bill Moran/Collaborative Fusion
+ * Copyright (c) 2013 Kris Moore/PC-BSD Software <kris@pcbsd.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/param.h>
+#include <sys/jail.h>
+#include <sys/types.h>
+
+#include <err.h>
+#include <errno.h>
+#include <login_cap.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pwd.h>
+#include <unistd.h>
+#include <string.h>
+
+static void usage(void);
+
+int
+main(int argc, char *argv[])
+{
+ char newchroot[2048];
+ char mountscript[4096];
+ int jid, ngroups;
+ uid_t huid;
+ struct passwd *husername, *jusername;
+ gid_t groups[NGROUPS];
+ login_cap_t *lcap;
+
+ if (argc < 4)
+ usage();
+ /* Get the current user ID and user name in the host system */
+ huid = getuid();
+ husername = getpwuid(huid);
+
+ /* Run the mount script */
+ if ( (strlen("/usr/pbi/.pbimount") + strlen(argv[1]) + strlen(argv[2])) > 4090)
+ err(1, "Max length exceeded for pbidir / mntdir");
+
+ if ( strlen("argv[2]") + strlen("/virtbase") > 2040)
+ err(1, "Max length exceeded for virtbase");
+ strcpy(newchroot, argv[1]);
+ strcat(newchroot, "/virtbase");
+
+ strcpy(mountscript, "/usr/pbi/.pbimount ");
+ strcat(mountscript, argv[1]);
+ strcat(mountscript, " ");
+ strcat(mountscript, argv[2]);
+ //printf( "mountscript: %s \n", mountscript);
+ if ( system(mountscript) != 0 )
+ err(1, "Failed mounting PBI");
+
+ if (chdir(newchroot) == -1 || chroot(".") == -1)
+ err(1, "Could not chroot to: %s", newchroot);
+
+ /* Get the user name in the jail */
+ jusername = getpwuid(huid);
+ if (jusername == NULL || strcmp(husername->pw_name, jusername->pw_name) != 0)
+ err(1, "Username mapping failed");
+ //if (chdir("/") == -1)
+ // err(1, "chdir(): /");
+ lcap = login_getpwclass(jusername);
+ if (lcap = NULL)
+ err(1, "getpwclass: %s", jusername);
+ ngroups = NGROUPS;
+ if (getgrouplist(jusername->pw_name, jusername->pw_gid, groups, &ngroups) != 0)
+ err(1, "getgrouplist: %s", jusername->pw_name);
+ if (setgroups(ngroups, groups) != 0)
+ err(1, "setgroups");
+ if (setgid(jusername->pw_gid) != 0)
+ err(1, "setgid");
+ if (setusercontext(lcap, jusername, jusername->pw_uid,
+ LOGIN_SETALL & ~LOGIN_SETGROUP & ~LOGIN_SETLOGIN) != 0)
+ err(1, "setusercontext");
+ login_close(lcap);
+ if (execvp(argv[3], argv + 3) == -1)
+ err(1, "execvp(): %s", argv[3]);
+ exit(0);
+}
+
+static void
+usage(void)
+{
+
+ fprintf(stderr, "usage: pbime mntdir pbidir command [...]\n");
+ exit(1);
+}
@@ -0,0 +1,109 @@
+#!/bin/sh
+
+NULLFS="/root/mount_nullfs"
+
+is_mounted() {
+ mount | grep -q "on ${1} ("
+ return $?
+}
+
+check_pbidir() {
+ if [ -d "${1}/pbimeta" ] ; then return ; fi
+ echo "Error: Invalid PBI: ${1}"
+ exit 1
+}
+
+get_pdir() {
+ pDir="${1}"
+ if [ ! -d "${pDir}/virtbase" ] ; then
+ mkdir -p ${pDir}/virtbase
+ fi
+ if [ ! -d "${pDir}/run" ] ; then
+ mkdir -p ${pDir}/run
+ fi
+}
+
+mount_pbifile() {
+ if [ ! -d "$pDir" ] ; then
+ mkdir -p "${pDir}"
+ else
+ # Check to see if it is already mounted
+ mount | grep -q "on ${pDir} (ufs,"
+ if [ $? -eq 0 ] ; then return; fi
+ fi
+ MD=`mdconfig -a -t vnode -f ${1}`
+ mount -r -t ufs /dev/${MD}.uzip "${pDir}"
+}
+
+mount_dirs() {
+ is_mounted "${pDir}/virtbase" || $NULLFS / ${pDir}/virtbase
+ is_mounted "${pDir}/virtbase/dev" || mount -t devfs devfs ${pDir}/virtbase/dev
+ is_mounted "${pDir}/virtbase/usr/local" || $NULLFS ${1}/local ${pDir}/virtbase/usr/local
+ is_mounted "${pDir}/virtbase/var/run" || mount -t unionfs -o noatime ${pDir}/run ${pDir}/virtbase/var/run
+ is_mounted "${pDir}/virtbase/usr/local/etc" || $NULLFS ${1}/etc ${pDir}/virtbase/usr/local/etc
+ is_mounted "${pDir}/virtbase/compat/linux" || $NULLFS ${1}/linux ${pDir}/virtbase/compat/linux
+ if [ -d "${pDir}/virtbase/usr/local/etc/fonts" ] ; then
+ is_mounted "${pDir}/virtbase/usr/local/etc/fonts" || $NULLFS /usr/local/etc/fonts ${pDir}/virtbase/usr/local/etc/fonts
+ fi
+ if [ -d "${pDir}/virtbase/usr/local/lib/X11/fonts" ] ; then
+ is_mounted "${pDir}/virtbase/usr/local/lib/X11/fonts" || $NULLFS /usr/local/lib/X11/fonts ${pDir}/virtbase/usr/local/lib/X11/fonts
+ fi
+ if [ -d "${pDir}/virtbase/usr/local/lib/X11/icons" ] ; then
+ is_mounted "${pDir}/virtbase/usr/local/lib/X11/icons" || $NULLFS /usr/local/lib/X11/icons ${pDir}/virtbase/usr/local/lib/X11/icons
+ fi
+ is_mounted "${pDir}/virtbase/tmp" || $NULLFS /tmp ${pDir}/virtbase/tmp
+ is_mounted "${pDir}/virtbase/usr/home" || $NULLFS /usr/home ${pDir}/virtbase/usr/home
+ for i in `ls -d /usr/home/* 2>/dev/null`
+ do
+ is_mounted "${i}"
+ if [ $? -eq 0 ] ;then
+ is_mounted "${pDir}/virtbase${i}" || $NULLFS ${i} ${pDir}/virtbase${i}
+ fi
+
+ done
+
+ chroot ${pDir}/virtbase /etc/rc.d/ldconfig start >/dev/null 2>/dev/null
+}
+
+umount_pbidir() {
+ is_mounted "${pDir}/virtbase/usr/local/etc/fonts" && umount ${pDir}/virtbase/usr/local/etc/fonts
+ is_mounted "${pDir}/virtbase/usr/local/etc" && umount ${pDir}/virtbase/usr/local/etc
+ is_mounted "${pDir}/virtbase/usr/local/lib/X11/fonts" && umount ${pDir}/virtbase/usr/local/lib/X11/fonts
+ is_mounted "${pDir}/virtbase/usr/local/lib/X11/icons" && umount ${pDir}/virtbase/usr/local/lib/X11/icons
+ is_mounted "${pDir}/virtbase/usr/local" && umount ${pDir}/virtbase/usr/local
+ is_mounted "${pDir}/virtbase/tmp" && umount ${pDir}/virtbase/tmp
+ is_mounted "${pDir}/virtbase/dev" && umount ${pDir}/virtbase/dev
+ is_mounted "${pDir}/virtbase/var/run" && umount ${pDir}/virtbase/var/run
+ is_mounted "${pDir}/virtbase/compat/linux" && umount ${pDir}/virtbase/compat/linux
+ for i in `ls -d ${pDir}/virtbase/usr/home/* 2>/dev/null`
+ do
+ is_mounted "${i}" && umount ${i}
+ done
+ is_mounted "${pDir}/virtbase/usr/home" && umount ${pDir}/virtbase/usr/home
+ is_mounted "${pDir}/virtbase" && umount ${pDir}/virtbase
+}
+
+
+# Doing an unmount?
+if [ "$1" = "umount" ] ; then
+ get_pdir "$2"
+ umount_pbidir "$2"
+ exit 0
+fi
+
+if [ -z "$1" -o -z "$2" ] ; then
+ echo "Missing args: mountdir / pbidir"
+ exit 1
+fi
+
+MNTBASEDIR="`dirname $2`"
+
+if [ ! -d "$MNTBASEDIR" ] ; then
+ mkdir -p ${MNTBASEDIR}
+ echo "Do not manually remove this directory!" > ${MNTBASEDIR}/DONOTDELETE
+fi
+
+# Lets begin the mount process
+get_pdir "$1"
+check_pbidir "${2}"
+mount_dirs "${2}"
@@ -1 +0,0 @@
-/usr/pbi/virtualbox-amd64/lib/virtualbox:/usr/pbi/virtualbox-amd64/lib/qt4::/usr/pbi/virtualbox-amd64/lib
@@ -1,84 +0,0 @@
-#!/bin/sh
-#
-# $FreeBSD$
-#
-# Modified ldconfig for creating PBI hints files
-
-# PROVIDE: ldconfig
-# REQUIRE: mountcritremote FILESYSTEMS
-# BEFORE: DAEMON
-
-. /etc/rc.subr
-
-name="ldconfig"
-ldconfig_command="/sbin/ldconfig"
-start_cmd="ldconfig_start"
-stop_cmd=":"
-
-if [ ! -d "/usr/local/var/run" ] ; then
- mkdir -p "/usr/local/var/run"
-fi
-
-ldconfig_start()
-{
- local _files _ins
-
- _ins=
- ldconfig=${ldconfig_command}
- checkyesno ldconfig_insecure && _ins="-i"
- if [ -x "${ldconfig_command}" ]; then
- _LDC="/lib /usr/lib"
- for i in ${ldconfig_local_dirs}; do
- if [ -d "${i}" ]; then
- _files=`find ${i} -type f`
- if [ -n "${_files}" ]; then
- ldconfig_paths="${ldconfig_paths} `cat ${_files} | sort -u`"
- fi
- fi
- done
- for i in ${ldconfig_paths} /etc/ld-elf.so.conf; do
- if [ -r "${i}" ]; then
- _LDC="${_LDC} ${i}"
- fi
- done
- ${ldconfig} -elf -f /usr/local/var/run/ld-elf.so.hints ${_ins} ${_LDC}
-
- case `sysctl -n hw.machine_arch` in
- amd64)
- for i in ${ldconfig_local32_dirs}; do
- if [ -d "${i}" ]; then
- _files=`find ${i} -type f`
- if [ -n "${_files}" ]; then
- ldconfig32_paths="${ldconfig32_paths} `cat ${_files} | sort -u`"
- fi
- fi
- done
- _LDC=""
- for i in ${ldconfig32_paths}; do
- if [ -r "${i}" ]; then
- _LDC="${_LDC} ${i}"
- fi
- done
- ${ldconfig} -32 -f /usr/local/var/run/ld-elf32.so.hints -m ${_ins} ${_LDC}
- ;;
- esac
-
- # Legacy aout support for i386 only
- case `sysctl -n hw.machine_arch` in
- i386)
- # Default the a.out ldconfig path.
- : ${ldconfig_paths_aout=${ldconfig_paths}}
- _LDC=""
- for i in /usr/lib/aout ${ldconfig_paths_aout} /etc/ld.so.conf; do
- if [ -r "${i}" ]; then
- _LDC="${_LDC} ${i}"
- fi
- done
- ${ldconfig} -aout -f /usr/local/var/run/ld.so.hints ${_ins} ${_LDC}
- ;;
- esac
- fi
-}
-
-load_rc_config $name
-run_rc_command "$1"
Oops, something went wrong.

0 comments on commit 94b18f3

Please sign in to comment.