From bdd23c67742e188db5914a9b263af8d9251a2960 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 29 Feb 2012 16:12:47 +0100 Subject: [PATCH 1/3] feature #1112: Fix unsafe eval in xpath.rb by joining values with \0 --- src/datastore_mad/remotes/fs/cp | 12 ++++++------ src/datastore_mad/remotes/fs/mkfs | 16 +++++++++++----- src/datastore_mad/remotes/fs/rm | 10 +++++----- src/datastore_mad/remotes/vmware/cp | 8 ++++---- src/datastore_mad/remotes/vmware/mkfs | 16 ++++++++++++---- src/datastore_mad/remotes/vmware/rm | 10 +++++----- src/datastore_mad/remotes/xpath.rb | 7 ++++--- 7 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/datastore_mad/remotes/fs/cp b/src/datastore_mad/remotes/fs/cp index 73e5dafaa6..3f99bc4324 100755 --- a/src/datastore_mad/remotes/fs/cp +++ b/src/datastore_mad/remotes/fs/cp @@ -21,7 +21,7 @@ # Several SRC types are supported ############################################################################### -# -------- Set up the environment to source common tools & conf ------------ +# -------- Set up the environment to source common tools & conf ------------ if [ -z "${ONE_LOCATION}" ]; then LIB_LOCATION=/usr/lib/one @@ -34,7 +34,7 @@ fi DRIVER_PATH=$(dirname $0) source ${DRIVER_PATH}/../libfs.sh -# -------- Get cp and datastore arguments from OpenNebula core ------------ +# -------- Get cp and datastore arguments from OpenNebula core ------------ DRV_ACTION=$1 ID=$2 @@ -42,11 +42,11 @@ ID=$2 set_up_datastore $DRV_ACTION XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION" -eval "SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH`" +SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH` DST=`generate_image_path` -# ------------ Copy the image to the repository ------------- +# ------------ Copy the image to the repository ------------- case $SRC in http://*) @@ -63,9 +63,9 @@ http://*) error_message "Not allowed to copy image file $SRC" exit -1 fi - + log "Copying local image $SRC to the image repository" - + exec_and_log "cp -f $SRC $DST" "Error copying $SRC to $DST" exec_and_log "chmod 0660 $DST" diff --git a/src/datastore_mad/remotes/fs/mkfs b/src/datastore_mad/remotes/fs/mkfs index a1dc19fb81..5ec61bdb36 100755 --- a/src/datastore_mad/remotes/fs/mkfs +++ b/src/datastore_mad/remotes/fs/mkfs @@ -21,7 +21,7 @@ # as (FS) ############################################################################### -# -------- Set up the environment to source common tools & conf ------------ +# -------- Set up the environment to source common tools & conf ------------ if [ -z "${ONE_LOCATION}" ]; then LIB_LOCATION=/usr/lib/one @@ -34,16 +34,22 @@ fi DRIVER_PATH=$(dirname $0) source ${DRIVER_PATH}/../libfs.sh -# -------- Get mkfs and datastore arguments from OpenNebula core ------------ +# -------- Get mkfs and datastore arguments from OpenNebula core ------------ DRV_ACTION=$1 ID=$2 set_up_datastore $DRV_ACTION -XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION" -eval "FSTYPE=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE`" -eval "SIZE=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SIZE`" +unset i XPATH_ELEMENTS + +while IFS= read -r -d '' element; do + XPATH_ELEMENTS[i++]="$element" +done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \ + /DS_DRIVER_ACTION_DATA/IMAGE/SIZE) + +FSTYPE="${XPATH_ELEMENTS[0]}" +SIZE="${XPATH_ELEMENTS[1]}" DST=`generate_image_path` diff --git a/src/datastore_mad/remotes/fs/rm b/src/datastore_mad/remotes/fs/rm index d915786ea4..2284c21289 100755 --- a/src/datastore_mad/remotes/fs/rm +++ b/src/datastore_mad/remotes/fs/rm @@ -17,10 +17,10 @@ #--------------------------------------------------------------------------- # ############################################################################### -# This script is used to remove a VM image (SRC) from the image repository +# This script is used to remove a VM image (SRC) from the image repository ############################################################################### -# ------------ Set up the environment to source common tools ------------ +# ------------ Set up the environment to source common tools ------------ if [ -z "${ONE_LOCATION}" ]; then LIB_LOCATION=/usr/lib/one @@ -33,15 +33,15 @@ fi DRIVER_PATH=$(dirname $0) source ${DRIVER_PATH}/../libfs.sh -# -------- Get rm and datastore arguments from OpenNebula core ------------ +# -------- Get rm and datastore arguments from OpenNebula core ------------ DRV_ACTION=$1 ID=$2 XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION" -eval "SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE`" +SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE` -# ------------ Remove the image from the repository ------------ +# ------------ Remove the image from the repository ------------ if [ -e $SRC ] ; then log "Removing $SRC from the image repository" diff --git a/src/datastore_mad/remotes/vmware/cp b/src/datastore_mad/remotes/vmware/cp index c449d1b1ce..0a971e25c4 100755 --- a/src/datastore_mad/remotes/vmware/cp +++ b/src/datastore_mad/remotes/vmware/cp @@ -21,7 +21,7 @@ # Several SRC types are supported ############################################################################### -# -------- Set up the environment to source common tools & conf ------------ +# -------- Set up the environment to source common tools & conf ------------ if [ -z "${ONE_LOCATION}" ]; then LIB_LOCATION=/usr/lib/one @@ -34,7 +34,7 @@ fi DRIVER_PATH=$(dirname $0) source ${DRIVER_PATH}/../libfs.sh -# -------- Get cp and datastore arguments from OpenNebula core ------------ +# -------- Get cp and datastore arguments from OpenNebula core ------------ DRV_ACTION=$1 ID=$2 @@ -42,11 +42,11 @@ ID=$2 set_up_datastore $DRV_ACTION XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION" -eval "SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH`" +SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH` DST=`generate_image_path` -# ------------ Copy the image to the repository ------------- +# ------------ Copy the image to the repository ------------- case $SRC in http://*) diff --git a/src/datastore_mad/remotes/vmware/mkfs b/src/datastore_mad/remotes/vmware/mkfs index a1dc19fb81..e391694db9 100755 --- a/src/datastore_mad/remotes/vmware/mkfs +++ b/src/datastore_mad/remotes/vmware/mkfs @@ -21,7 +21,7 @@ # as (FS) ############################################################################### -# -------- Set up the environment to source common tools & conf ------------ +# -------- Set up the environment to source common tools & conf ------------ if [ -z "${ONE_LOCATION}" ]; then LIB_LOCATION=/usr/lib/one @@ -34,7 +34,7 @@ fi DRIVER_PATH=$(dirname $0) source ${DRIVER_PATH}/../libfs.sh -# -------- Get mkfs and datastore arguments from OpenNebula core ------------ +# -------- Get mkfs and datastore arguments from OpenNebula core ------------ DRV_ACTION=$1 ID=$2 @@ -42,8 +42,16 @@ ID=$2 set_up_datastore $DRV_ACTION XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION" -eval "FSTYPE=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE`" -eval "SIZE=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SIZE`" + +unset i XPATH_ELEMENTS + +while IFS= read -r -d '' element; do + XPATH_ELEMENTS[i++]="$element" +done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \ + /DS_DRIVER_ACTION_DATA/IMAGE/SIZE) + +FSTYPE="${XPATH_ELEMENTS[0]}" +SIZE="${XPATH_ELEMENTS[1]}" DST=`generate_image_path` diff --git a/src/datastore_mad/remotes/vmware/rm b/src/datastore_mad/remotes/vmware/rm index d915786ea4..2284c21289 100755 --- a/src/datastore_mad/remotes/vmware/rm +++ b/src/datastore_mad/remotes/vmware/rm @@ -17,10 +17,10 @@ #--------------------------------------------------------------------------- # ############################################################################### -# This script is used to remove a VM image (SRC) from the image repository +# This script is used to remove a VM image (SRC) from the image repository ############################################################################### -# ------------ Set up the environment to source common tools ------------ +# ------------ Set up the environment to source common tools ------------ if [ -z "${ONE_LOCATION}" ]; then LIB_LOCATION=/usr/lib/one @@ -33,15 +33,15 @@ fi DRIVER_PATH=$(dirname $0) source ${DRIVER_PATH}/../libfs.sh -# -------- Get rm and datastore arguments from OpenNebula core ------------ +# -------- Get rm and datastore arguments from OpenNebula core ------------ DRV_ACTION=$1 ID=$2 XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION" -eval "SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE`" +SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE` -# ------------ Remove the image from the repository ------------ +# ------------ Remove the image from the repository ------------ if [ -e $SRC ] ; then log "Removing $SRC from the image repository" diff --git a/src/datastore_mad/remotes/xpath.rb b/src/datastore_mad/remotes/xpath.rb index dad2f13ce6..3cf8af12b5 100755 --- a/src/datastore_mad/remotes/xpath.rb +++ b/src/datastore_mad/remotes/xpath.rb @@ -45,10 +45,11 @@ values = "" tmp = Base64::decode64(tmp64) xml = REXML::Document.new(tmp).root -ARGV.each { |xpath| +ARGV.each do |xpath| element = xml.elements[xpath] - values << "\'#{element.text}\' " if !element.nil? -} + values << element.text if !element.nil? + values << "\0" +end puts values From bb1303c9e6ae08ff042254b3faf03fcb58a4e484 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 29 Feb 2012 16:15:00 +0100 Subject: [PATCH 2/3] feature #1112: Working mkfs for vmware datastore drivers --- src/datastore_mad/remotes/vmware/mkfs | 28 +++++++++++++++++++++------ src/mad/sh/scripts_common.sh | 3 ++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/datastore_mad/remotes/vmware/mkfs b/src/datastore_mad/remotes/vmware/mkfs index e391694db9..e7e623c713 100755 --- a/src/datastore_mad/remotes/vmware/mkfs +++ b/src/datastore_mad/remotes/vmware/mkfs @@ -55,17 +55,33 @@ SIZE="${XPATH_ELEMENTS[1]}" DST=`generate_image_path` +DISK=$DST/disk.vmdk +DISK_TMP=$DISK.tmp + +IMAGE_FORMAT=vmdk + +umask 0007 # ------------ Create the image to the repository ------------ -MKFS_CMD=`mkfs_command $DST $FSTYPE` +MKFS_CMD=`mkfs_command $DISK_TMP $FSTYPE` -exec_and_log "$DD if=/dev/zero of=$DST bs=1 count=1 seek=${SIZE}M" \ - "Could not create image $DST" +exec_and_log "mkdir -p $DST" \ + "Could not create disk directory $DST" +exec_and_log "$DD if=/dev/zero of=$DISK_TMP bs=1 count=1 seek=${SIZE}M" \ + "Could not create temporary image $DISK_TMP" exec_and_log "$MKFS_CMD" \ - "Unable to create filesystem $FSTYPE in $DST" -exec_and_log "chmod 0660 $DST" + "Unable to create filesystem $FSTYPE in $DISK_TMP" +exec_and_log "$QEMU_IMG convert -O $IMAGE_FORMAT $DISK_TMP $DISK" \ + "Unable to convert to $IMAGE_FORMAT in $DISK_TMP" +exec_and_log "rm -f $DISK_TMP" \ + "Unable to remove temporary disk $DISK_TMP" +exec_and_log "chmod 0660 $DISK" # ---------------- Get the size of the image ------------ -SIZE=`fs_du $DST` + +SIZE=`$QEMU_IMG info $DISK|grep "^virtual size:"|\ + sed 's/^.*(\([0-9]\+\) bytes.*$/\1/g'` + +SIZE=$(($SIZE/1048576)) echo "$DST $SIZE" diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index ea3d484b21..8de8df234d 100755 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -29,12 +29,13 @@ MD5SUM=md5sum MKFS=mkfs MKISOFS=mkisofs MKSWAP=mkswap +QEMU_IMG=qemu-img +READLINK=readlink SCP=scp SED=sed SSH=ssh SUDO=sudo WGET=wget -READLINK=readlink # Used for log messages SCRIPT_NAME=`basename $0` From 7a487c7308812f2f4cff16eab81d56627c67c89d Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 29 Feb 2012 16:15:41 +0100 Subject: [PATCH 3/3] feature #1112: Disable 'http://' sources in vmware cp datastore method --- src/datastore_mad/remotes/vmware/cp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/datastore_mad/remotes/vmware/cp b/src/datastore_mad/remotes/vmware/cp index 0a971e25c4..069bd89b72 100755 --- a/src/datastore_mad/remotes/vmware/cp +++ b/src/datastore_mad/remotes/vmware/cp @@ -49,14 +49,6 @@ DST=`generate_image_path` # ------------ Copy the image to the repository ------------- case $SRC in -http://*) - log "Downloading $SRC to the image repository" - - exec_and_log "$WGET -O $DST $SRC" "Error downloading $SRC" - - exec_and_log "chmod 0660 $DST" - ;; - *) if [ `check_restricted $SRC` -eq 1 ]; then log_error "Not allowed to copy images from $RESTRICTED_DIRS"