#!/bin/sh # # BackWatcher, Inc. # Information Security Solutions # http://www.backwatcher.com/ # support@backwatcher.com # 813-979-1633 # # mkcryptfs # # Make blowfish(3) encrypted virtual filesystem for use with vnd(4), # the Vnode Disk Driver, and vnconfig(8), it's configuration utility. # # 12/16/01 # # Get arguments # while getopts d:f:s:vh option do case "$option" in d) device="$OPTARG" ;; f) file="$OPTARG" ;; s) size="$OPTARG" ;; v) verbose="-v" ;; h) echo "Usage: mkcryptfs [-vh] -d device -f file -s size" echo " -d device vnode device (ie. /dev/svnd0c)" echo " -f file disk image file" echo " -s size size in kilobytes" echo " -v verbose" echo " -h help" exit 1 ;; esac done # # Check syntax # if [ -z "$device" -o -z "$file" -o -z "$size" ] then /bin/echo "syntax error: use -h for help" exit fi # # Make sure we are on an OpenBSD system # if [ "`/usr/bin/uname -s`" != "OpenBSD" ] then /bin/echo "os error: this must be an OpenBSD system" exit fi # # Make sure a "safe" vnd was specified # safe="`/bin/echo "$device" | /usr/bin/grep svnd`" if [ -z "$safe" ] then /bin/echo "device error: you must use a 'safe' vnode device (ie. /dev/svnd0c)" exit fi # # Make sure $size does not exceed the maximum # if [ "$size" -gt 2097151 ] then /bin/echo "size error: maximum size is 2097151k (approximately 2GB)" exit fi # # Create the file with a filesystem on partition c (whole disk) # [ $verbose ] && /bin/echo "Creating $file ..." ddout=`/bin/dd if=/dev/zero of=$file bs=1024 count=$size 2>&1` [ $verbose ] && /bin/echo "$ddout ..." /bin/echo [ $verbose ] && /bin/echo "Associating $file with $device ..." /usr/sbin/vnconfig -ck $verbose $device $file /bin/echo cdevice=`/bin/echo $device | /usr/bin/sed 's/svnd/rsvnd/'` [ $verbose ] && /bin/echo "Creating filesystem on $cdevice ..." newfsout=`/sbin/newfs $cdevice` [ $verbose ] && /bin/echo "$newfsout ..." /bin/echo [ $verbose ] && /bin/echo "Disassociating $file from $device ..." /usr/sbin/vnconfig -u $verbose $device