Add wrapper to fix TC-320 16/24016/4 accepted/tizen/common/20140707.170447 accepted/tizen/ivi/20140707.200508 submit/tizen_common/20140707.162153 submit/tizen_ivi/20140707.162143
authorBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Mon, 7 Jul 2014 15:12:07 +0000 (17:12 +0200)
committerStephane Desneux <stephane.desneux@open.eurogiciel.org>
Mon, 7 Jul 2014 16:13:04 +0000 (18:13 +0200)
Bug-Tizen: TC-320
Change-Id: I49c734ce61f0598f490223a8222582c460c8ab85
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
packaging/pkgmgr.spec
tool/CMakeLists.txt
tool/pkg_cmd_WA.c [new file with mode: 0644]
tool/pkgcmd.wrapper [new file with mode: 0755]

index 463276ef6f8697c7e69e302446e877e3446841e3..7a989271e07fd72fad93e4d3273bd7da7fdca657 100644 (file)
@@ -139,7 +139,9 @@ update-mime-database /usr/share/mime
 %dir %{_sysconfdir}/package-manager/backendlib
 %dir %{_sysconfdir}/opt/upgrade
 %{_sysconfdir}/opt/upgrade/pkgmgr.patch.sh
-%{_bindir}/pkgcmd
+%attr(4755, root, root) %{_bindir}/pkgcmd
+%{_bindir}/pkgcmd.real
+%attr(755, root, root) %{_bindir}/pkgcmd.wrapper
 %{_bindir}/pkg_initdb
 %{_bindir}/pkg_getsize
 %{_bindir}/pkginfo
index 1ac49d6cbb76a684174b699b746aaad4f758f860..34e1c7ddf8eebad06b83f10385faff7529836d14 100755 (executable)
@@ -22,8 +22,13 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 SET(CMAKE_C_FLAGS_RELEASE "-O2")
 
-add_executable(pkgcmd
+add_executable(pkgcmd.real
                pkg_cmd.c)
+target_link_libraries(pkgcmd.real pkgmgr-client ${pkgs_test_LDFLAGS})
+INSTALL(TARGETS pkgcmd.real DESTINATION bin)
+
+add_executable(pkgcmd
+               pkg_cmd_WA.c)
 target_link_libraries(pkgcmd pkgmgr-client ${pkgs_test_LDFLAGS})
 INSTALL(TARGETS pkgcmd DESTINATION bin)
 
@@ -50,3 +55,5 @@ install(FILES ${CMAKE_BINARY_DIR}/org.tizen.pkgmgr-install.xml DESTINATION /usr/
 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mime.wac.xml DESTINATION /usr/share/mime/packages/)
 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mime.tpk.xml DESTINATION /usr/share/mime/packages/)
 
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgcmd.wrapper DESTINATION /usr/bin/)
+
diff --git a/tool/pkg_cmd_WA.c b/tool/pkg_cmd_WA.c
new file mode 100644 (file)
index 0000000..29dbf5d
--- /dev/null
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE
+#include <unistd.h>
+int main(int argc, char **argv, char **env)
+{
+       setresuid(0,0,0);
+       setresgid(0,0,0);
+       return execve("/usr/bin/pkgcmd.wrapper",argv,env);
+}
diff --git a/tool/pkgcmd.wrapper b/tool/pkgcmd.wrapper
new file mode 100755 (executable)
index 0000000..8746d67
--- /dev/null
@@ -0,0 +1,97 @@
+#!/bin/bash
+
+# This script is a workaround for bug TC-320 where pkgcmd doesn't work with xwalk
+#
+# - the real command pkgcmd is renamed pkgcmd.real
+# - the "new" pkgcmd command is only a small binary with setuid bit (executes as root)
+# - this script "pkgcmd.wrapper" decides what to do depending on arguments
+#
+#                                                          /-> xwalkctl (if install or uninstall)
+# sbdb -> (developer) pkgcmd (gets root) -> pkgcmd.wrapper
+#                                                          \-> pkgcmd.real (original binary in other cases)
+#
+# Authors:!
+#      Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+#      Baptiste Durand <baptiste.durand@open.eurogiciel.org>
+
+DEBUG=0
+
+function debug() {
+       [[ "$DEBUG" == 1 ]] && echo "$0: $@"
+}
+
+TEMP=$(getopt -n 'pkgcmd' -o iurmcgCkaADL:lsd:p:t:n:T:T:S:qh --long install,uninstall,reinstall,move,clear,getsize,check,kill,app-path,activate,deactivate,activate\ with\ Label:,list,show,descriptor:,package-path:,package-type:,package-name:,move-type:,getsize-type:,csc:,quiet,help -- "$@")
+[[ $? != 0 ]] && { echo "pkgcmd.wrapper: invalid options. Terminating..." >&2; exit 1; }
+
+# save initial arguments
+ARGS="$@"
+debug "ARGS: $ARGS"
+
+# change args to getopt output
+eval set -- "$TEMP"
+
+op=
+while true; do
+       case "$1" in
+               -i|--install)           op="install";   shift;;
+               -u|--uninstall)         op="uninstall"; shift;;
+               -t|--package-type)      pkgtype=$2;             shift 2;;
+               -p|--package-path)      pkgpath=$2;             shift 2;;
+               -n|--package-name)      pkgname=$2;             shift 2;;
+
+               # other options (we don't care of)
+               -r|--reinstall) shift;;
+               -m|--move) shift;;
+               -c|--clear) shift;;
+               -g|--getsize) shift;;
+               -C|--check) shift;;
+               -k|--kill) shift;;
+               -a|--app-path) shift;;
+               -A|--activate) shift;;
+               -D|--deactivate) shift;;
+               -l|--list) shift;;
+               -s|--show) shift;;
+               -q|--quiet) shift;;
+               -h|--help) shift;;
+
+               # other options with argument (we don't care of)
+               -L|--activate\ with\ Label) shift 2;;
+               -d|--descriptor) shift 2;;
+               -T|--move-type|--getsize-type) shift 2;;
+               -S|--csc) shift 2;;
+               --) shift; break;;
+       esac
+done
+
+debug "op=$op type=$pkgtype path=$pkgpath name=$pkgname"
+
+# get user to install to from USER env var (or 'guest' as fallback)
+USER=${USER:-guest}
+
+if [[ "$USER" == "root" || "$USER" == "developer" ]]; then
+       # root and developer don't install apps for themselves.
+       # so take the first valid user: check app, check guest
+       if getent passwd | grep -q "^app:"; then
+               USER=app
+       else
+               USER=guest
+       fi
+fi
+
+[[ "$USER" == "root" ]] && USER
+
+shopt -s nocasematch
+if [[ "$op" == "install" && "$pkgtype" =~ wgt ]]; then
+       # call xwalkctl
+       debug exec su - $USER -c "bash -l -c 'xwalkctl -i $pkgpath'"
+          exec su - $USER -c "bash -l -c 'xwalkctl -i $pkgpath'"
+elif [[ "$op" == "uninstall" ]]; then
+       # call xwalkctl
+       debug exec su - $USER -c "bash -l -c 'xwalkctl -u $pkgname'"
+             exec su - $USER -c "bash -l -c 'xwalkctl -u $pkgname'"
+else
+       # launch the real pkgcmd binary if we're not installing or uninstalling
+       debug exec /usr/bin/pkgcmd.real $ARGS
+             exec /usr/bin/pkgcmd.real $ARGS
+fi
+