Make vconftool printing log messages, adding vconftool2 in a secret way 90/145490/7
authorMyoungJune Park <mj2004.park@samsung.com>
Tue, 22 Aug 2017 11:50:49 +0000 (20:50 +0900)
committerjusung son <jusung07.son@samsung.com>
Thu, 24 Aug 2017 06:24:32 +0000 (06:24 +0000)
Change-Id: I6ae273a92ca3c2ddb81b078ec2429c316ceb1bf9
Signed-off-by: MyoungJune Park <mj2004.park@samsung.com>
Signed-off-by: jusung son <jusung07.son@samsung.com>
client/c_main.c [changed mode: 0644->0755]
packaging/buxton2.spec
vconf-compat/CMakeLists.txt
vconf-compat/vconftool2 [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
index dcd63a8..fd191e3
@@ -38,12 +38,41 @@ struct options {
        gboolean install;
        gint uid;
        gboolean help;
+       gboolean owner;
 };
 
 typedef int (*comm_func)(const struct buxton_layer *layer,
                const char *key, const char *value,
                const char *rpriv, const char *wpriv);
 
+typedef enum _command_type {
+       COMMAND_CHECK = 0,
+       COMMAND_GET,
+       COMMAND_CREATE_STRING,
+       COMMAND_CREATE_INT32,
+       COMMAND_CREATE_UINT32,
+       COMMAND_CREATE_INT64,
+       COMMAND_CREATE_UINT64,
+       COMMAND_CREATE_DOUBLE,
+       COMMAND_CREATE_BOOL,
+       COMMAND_SET_STRING,
+       COMMAND_SET_INT32,
+       COMMAND_SET_UINT32,
+       COMMAND_SET_INT64,
+       COMMAND_SET_UINT64,
+       COMMAND_SET_DOUBLE,
+       COMMAND_SET_BOOL,
+       COMMAND_GET_READ_PRIV,
+       COMMAND_SET_READ_PRIV,
+       COMMAND_GET_WRITE_PRIV,
+       COMMAND_SET_WRITE_PRIV,
+       COMMAND_UNSET,
+       COMMAND_LIST_KEYS,
+       COMMAND_SECURITY_ENABLE,
+       COMMAND_SECURITY_DISABLE,
+       COMMAND_REMOVE_GARBAGE_DATA,
+} command_type_e;
+
 struct command {
        const char *name;
        const char *summary;
@@ -51,6 +80,7 @@ struct command {
        const char *usage;
        comm_func func;
        comm_func dfunc;
+       command_type_e index;
 };
 
 static const struct command const commands[] = {
@@ -61,6 +91,7 @@ static const struct command const commands[] = {
                .usage   = "",
                .func    = c_check,
                .dfunc   = c_check,
+               .index   = COMMAND_CHECK,
        },
        {
                .name    = "get",
@@ -69,6 +100,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY",
                .func    = c_get,
                .dfunc   = c_direct_get,
+               .index   = COMMAND_GET,
        },
        {
                .name    = "create-string",
@@ -77,6 +109,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
                .func    = c_create_str,
                .dfunc   = c_direct_create_str,
+               .index   = COMMAND_CREATE_STRING,
        },
        {
                .name    = "create-int32",
@@ -85,6 +118,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
                .func    = c_create_int32,
                .dfunc   = c_direct_create_int32,
+               .index   = COMMAND_CREATE_INT32,
        },
        {
                .name    = "create-uint32",
@@ -93,6 +127,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
                .func    = c_create_uint32,
                .dfunc   = c_direct_create_uint32,
+               .index   = COMMAND_CREATE_UINT32,
        },
        {
                .name    = "create-int64",
@@ -101,6 +136,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
                .func    = c_create_int64,
                .dfunc   = c_direct_create_int64,
+               .index   = COMMAND_CREATE_INT64,
        },
        {
                .name    = "create-uint64",
@@ -109,6 +145,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
                .func    = c_create_uint64,
                .dfunc   = c_direct_create_uint64,
+               .index   = COMMAND_CREATE_UINT64,
        },
        {
                .name    = "create-double",
@@ -117,6 +154,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
                .func    = c_create_double,
                .dfunc   = c_direct_create_double,
+               .index   = COMMAND_CREATE_DOUBLE,
        },
        {
                .name    = "create-bool",
@@ -125,6 +163,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
                .func    = c_create_bool,
                .dfunc   = c_direct_create_bool,
+               .index   = COMMAND_CREATE_BOOL,
        },
        {
                .name    = "set-string",
@@ -133,6 +172,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE",
                .func    = c_set_str,
                .dfunc   = c_direct_set_str,
+               .index   = COMMAND_SET_STRING,
        },
        {
                .name    = "set-int32",
@@ -141,6 +181,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE",
                .func    = c_set_int32,
                .dfunc   = c_direct_set_int32,
+               .index   = COMMAND_SET_INT32,
        },
        {
                .name    = "set-uint32",
@@ -149,6 +190,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE",
                .func    = c_set_uint32,
                .dfunc   = c_direct_set_uint32,
+               .index   = COMMAND_SET_UINT32,
        },
        {
                .name    = "set-int64",
@@ -157,6 +199,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE",
                .func    = c_set_int64,
                .dfunc   = c_direct_set_int64,
+               .index   = COMMAND_SET_INT64,
        },
        {
                .name    = "set-uint64",
@@ -165,6 +208,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE",
                .func    = c_set_uint64,
                .dfunc   = c_direct_set_uint64,
+               .index   = COMMAND_SET_UINT64,
        },
        {
                .name    = "set-double",
@@ -173,6 +217,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE",
                .func    = c_set_double,
                .dfunc   = c_direct_set_double,
+               .index   = COMMAND_SET_DOUBLE,
        },
        {
                .name    = "set-bool",
@@ -181,6 +226,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY VALUE",
                .func    = c_set_bool,
                .dfunc   = c_direct_set_bool,
+               .index   = COMMAND_SET_BOOL,
        },
        {
                .name    = "get-read-priv",
@@ -189,6 +235,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY",
                .func    = c_get_rpriv,
                .dfunc   = c_direct_get_rpriv,
+               .index   = COMMAND_GET_READ_PRIV,
        },
        {
                .name    = "set-read-priv",
@@ -197,6 +244,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY PRIVILEGE",
                .func    = c_set_rpriv,
                .dfunc   = c_direct_set_rpriv,
+               .index   = COMMAND_SET_READ_PRIV,
        },
        {
                .name    = "get-write-priv",
@@ -205,6 +253,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY",
                .func    = c_get_wpriv,
                .dfunc   = c_direct_get_wpriv,
+               .index   = COMMAND_GET_WRITE_PRIV,
        },
        {
                .name    = "set-write-priv",
@@ -213,6 +262,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY PRIVILEGE",
                .func    = c_set_wpriv,
                .dfunc   = c_direct_set_wpriv,
+               .index   = COMMAND_SET_WRITE_PRIV,
        },
        {
                .name    = "unset",
@@ -221,6 +271,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER KEY",
                .func    = c_unset,
                .dfunc   = c_direct_unset,
+               .index   = COMMAND_UNSET,
        },
        {
                .name    = "list-keys",
@@ -229,6 +280,7 @@ static const struct command const commands[] = {
                .usage   = "LAYER",
                .func    = c_list,
                .dfunc   = c_direct_list,
+               .index   = COMMAND_LIST_KEYS,
        },
        {
                .name    = "security-enable",
@@ -237,6 +289,7 @@ static const struct command const commands[] = {
                .usage   = "",
                .func    = c_enable_security,
                .dfunc   = NULL,
+               .index   = COMMAND_SECURITY_ENABLE,
        },
        {
                .name    = "security-disable",
@@ -245,6 +298,7 @@ static const struct command const commands[] = {
                .usage   = "",
                .func    = c_disable_security,
                .dfunc   = NULL,
+               .index   = COMMAND_SECURITY_DISABLE,
        },
        {
                .name    = "remove-garbage-data",
@@ -253,10 +307,11 @@ static const struct command const commands[] = {
                .usage   = "LAYER",
                .func    = c_direct_remove_garbage,
                .dfunc   = c_direct_remove_garbage,
+               .index   = COMMAND_REMOVE_GARBAGE_DATA,
        },
 };
 
-static const struct command *find_comm(const char *name)
+static const struct command *find_comm(const char *name, command_type_e *index)
 {
        int i;
 
@@ -264,8 +319,10 @@ static const struct command *find_comm(const char *name)
                return NULL;
 
        for (i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) {
-               if (commands[i].name && !strcmp(name, commands[i].name))
+               if (commands[i].name && !strcmp(name, commands[i].name)) {
+                       *index = (command_type_e)i;
                        return &commands[i];
+               }
        }
 
        return NULL;
@@ -356,6 +413,8 @@ static int parse_args(gint *argc, gchar ***argv, struct options *opt)
                        G_OPTION_ARG_INT, &opt->uid, NULL, NULL },
                { "help", 'h', 0,
                        G_OPTION_ARG_NONE, &opt->help, NULL, NULL },
+               { "owner", 'o', 0,
+                       G_OPTION_ARG_NONE, &opt->owner, NULL, NULL },
                { NULL }
        };
 
@@ -393,6 +452,7 @@ int main(int argc, char *argv[])
        int r;
        const struct command *comm;
        comm_func func;
+       command_type_e index;
        struct buxton_layer *layer;
        struct options opt = {
                .confpath = NULL,
@@ -400,6 +460,7 @@ int main(int argc, char *argv[])
                .install = FALSE,
                .uid = 0,
                .help = FALSE,
+               .owner = FALSE,
        };
 
        r = parse_args(&argc, &argv, &opt);
@@ -411,12 +472,16 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
        }
 
-       comm = find_comm(argv[1]);
+       comm = find_comm(argv[1], &index);
        if (!comm) {
                bxt_err("Unknown command '%s'", argv[1]);
                return EXIT_FAILURE;
        }
 
+       if (index >= COMMAND_CREATE_STRING && index <= COMMAND_CREATE_BOOL &&
+               opt.owner == false)
+               printf("[WARNING] CALLING VCONFTOOL OUTSIDE OF VCONF-INTERNAL-KEYS IS NOT ALLOWED.\n");
+
        func = opt.direct ? comm->dfunc : comm->func;
        if (!func) {
                bxt_err("Command '%s' not supported", comm->name);
index 572271b..f3f2b59 100644 (file)
@@ -202,6 +202,7 @@ chsmack -a System %{dbdir}/*
 %manifest %{name}.manifest
 %license LICENSE.Apache-2.0
 %attr(0750,root,system_share) %{_bindir}/vconftool
+%attr(0750,root,system_share) %{_bindir}/vconftool2
 %{_libdir}/libvconf.so.*
 
 %files -n vconf-compat-devel
index 70288c5..75a37a3 100644 (file)
@@ -26,4 +26,5 @@ INSTALL(FILES vconf.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 INSTALL(FILES vconf.h vconf-keys.h DESTINATION ${INCLUDE_INSTALL_DIR}/vconf)
 
 INSTALL(PROGRAMS vconftool DESTINATION bin)
+INSTALL(PROGRAMS vconftool2 DESTINATION bin)
 
diff --git a/vconf-compat/vconftool2 b/vconf-compat/vconftool2
new file mode 100755 (executable)
index 0000000..f2c60de
--- /dev/null
@@ -0,0 +1,311 @@
+#!/bin/sh
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+BUXTONTOOL=/usr/bin/buxton2ctl
+
+OPT_DIRECT=""
+OPT_TYPE=""
+OPT_RECUR=0
+OPT_INIT=""
+OPT_DEBUG=0
+OPT_FORCE=0
+OPT_OWNER="-o"
+
+usage() {
+       COMM=`basename $0`
+cat << EOF
+
+ Usage:
+   $COMM set [set-options] <key name> <value>
+   $COMM get [get-options] <key name>
+   $COMM unset <key name>
+
+ set-options:
+   -t, --type=int|bool|double|string   Type of key
+   -u, --uid=UID                       User ID (for compatibility, ignored)
+   -g, --gid=GID                       Gourp ID (for compatibility, ignored)
+   -i, --install                       Install memory type key
+   -s, --smack=LABEL                   Set a SMACK label (for compatibility, ignored)
+   -f, --force                         Overwrite by force
+
+   ex)
+     $COMM set -t string db/testapp/key1 "This is test"
+     $COMM set -t int -i memory/testapp/status -1
+
+ get-options:
+   -r, --recursive                     Retrieve all keys having the given prefix
+
+   ex)
+     $COMM get db/testapp/key1
+     $COMM get -r db/testapp
+
+EOF
+       exit 1
+}
+
+dbg() {
+       [ ${OPT_DEBUG} -eq 0 ] && return 0
+       echo "$*" >&2
+       return 0
+}
+
+get_layer() {
+       case "$1" in
+       memory*)
+               echo -n "memory"
+               ;;
+       *)
+               echo -n "system"
+               ;;
+       esac
+}
+
+get_key() {
+       [ -z "$1" ] && exit 1
+
+       LAYER=`get_layer $1`
+
+       dbg ${BUXTONTOOL} ${OPT_DIRECT} get ${LAYER} $1
+       RES=`${BUXTONTOOL} ${OPT_DIRECT} get ${LAYER} $1 2>&1`
+       [ $? -ne 0 ] && echo "Error: $RES" && exit 1
+       VAL=`echo "$RES" | sed 's/^.* = //g; s/\(.*\): \(.*\)$/\2 (\1)/g'`
+       echo "$1, value = $VAL"
+}
+
+do_get() {
+       [ -z "${OPT_KEY}" ] && echo "Invalid key name" && usage
+
+       if [ $OPT_RECUR -eq 0 ]; then
+               get_key ${OPT_KEY}
+               exit $?
+       fi
+
+       LAYER=`get_layer ${OPT_KEY}`
+
+       dbg ${BUXTONTOOL} ${OPT_DIRECT} list-keys ${LAYER} | grep ^${OPT_KEY}
+       LIST=`${BUXTONTOOL} ${OPT_DIRECT} list-keys ${LAYER} | grep ^${OPT_KEY}`
+       for k in $LIST; do
+               get_key $k
+       done
+}
+
+do_unset() {
+       [ -z "${OPT_KEY}" ] && echo "Invalid key name" && usage
+
+       LAYER=`get_layer ${OPT_KEY}`
+
+       dbg ${BUXTONTOOL} ${OPT_DIRECT} unset ${LAYER} ${OPT_KEY}
+       RES=`${BUXTONTOOL} ${OPT_DIRECT} unset ${LAYER} ${OPT_KEY} 2>&1`
+       [ $? -ne 0 ] && echo "Error: $RES" && exit 1
+       exit 0
+}
+
+get_type() {
+       case "$1" in
+       int)    echo -n "int32"  ;;
+       bool)   echo -n "bool"   ;;
+       double) echo -n "double" ;;
+       string) echo -n "string" ;;
+       *)      echo -n ""       ;;
+       esac
+}
+
+do_create() {
+       [ -z "${OPT_KEY}" ] && echo "Invalid key name" && usage
+
+       LAYER=`get_layer ${OPT_KEY}`
+       TYPE=`get_type ${OPT_TYPE}`
+       [ -z "${TYPE}" ] && echo "Type '${OPT_TYPE}': Invalid type" && usage
+
+       dbg ${BUXTONTOOL} ${OPT_DIRECT} ${OPT_OWNER} create-${TYPE} \
+               ${LAYER} ${OPT_KEY} \"${OPT_VAL}\" \"\" \"\"
+       RES=`${BUXTONTOOL} ${OPT_DIRECT} ${OPT_OWNER} create-${TYPE} \
+               ${LAYER} ${OPT_KEY} "${OPT_VAL}" "" "" 2>&1`
+       [ $? -ne 0 ] && echo "Error: $RES" && exit 1
+       exit 0
+}
+
+do_set() {
+       [ -z "${OPT_KEY}" ] && echo "Invalid key name" && usage
+
+       LAYER=`get_layer ${OPT_KEY}`
+       TYPE=`get_type ${OPT_TYPE}`
+       [ -z "${TYPE}" ] && echo "Type '${OPT_TYPE}': Invalid type" && usage
+
+       RES=`${BUXTONTOOL} ${OPT_DIRECT} get ${LAYER} ${OPT_KEY} 2>&1`
+       if [ $? -eq 0 ]; then
+               if [ ${OPT_FORCE} -eq 0 ]; then
+                       echo "Key already exist. Use -f option to force update"
+                       exit 1
+               fi
+       fi
+
+       dbg ${BUXTONTOOL} ${OPT_DIRECT} ${OPT_INIT} set-${TYPE} \
+               ${LAYER} ${OPT_KEY} \"${OPT_VAL}\"
+       RES=`${BUXTONTOOL} ${OPT_DIRECT} ${OPT_INIT} set-${TYPE} \
+               ${LAYER} ${OPT_KEY} "${OPT_VAL}" 2>&1`
+       if [ $? -ne 0 ]; then
+               echo "$RES" | grep -q "No such file"
+               if [ $? -eq 0 ]; then
+                       do_create
+                       exit $?
+               fi
+
+               echo "Error: $RES"
+               exit 1
+       fi
+
+       exit 0
+}
+
+do_backup() {
+       [ -z "${OPT_KEY}" ] && echo "Invalid key name" && usage
+       [ -z "${OPT_VAL}" ] && echo "Invalid directory" && usage
+       [ ! -x ${OPT_VAL} ] && echo "${OPT_VAL} directory not exist" && exit 1
+
+       LAYER=`get_layer ${OPT_KEY}`
+
+       dbg ${BUXTONTOOL} ${OPT_DIRECT} get ${LAYER} ${OPT_KEY}
+       RES=`${BUXTONTOOL} ${OPT_DIRECT} get ${LAYER} ${OPT_KEY} 2>&1`
+       [ $? -ne 0 ] && echo "Error: $RES" && exit 1
+       VAL=`echo "$RES" | sed 's/^.* = //g; s/\(.*\): \(.*\)$/\2 (\1)/g'`
+
+       KEY=`echo ${OPT_KEY} | sed 's/\//\+/g'`
+       echo $RES > ${OPT_VAL}/${KEY}
+}
+
+restore_key() {
+       KEY_PATH=$2/$1
+       KEY_NAME=`echo $1 | sed 's/\+/\//g'`
+
+       LAYER=`get_layer ${KEY_NAME}`
+       TYPE=`cat ${KEY_PATH} | sed 's/^.* = //g; s/\(.*\):\(.*\)$/\1/g; s/\(.*\)/\L\1/'`
+       VAL=`cat ${KEY_PATH} | sed 's/^.*: *//g'`
+
+       if [ "${TYPE}" == "boolean" ]
+       then
+               TYPE="bool"
+               if [ "${VAL}" == "True" ]
+               then
+                       VAL="1"
+               else
+                       VAL="0"
+               fi
+       fi
+
+       dbg ${BUXTONTOOL} ${OPT_DIRECT} set-${TYPE} \
+               ${LAYER} ${KEY_NAME} \"${VAL}\"
+       RES=`${BUXTONTOOL} ${OPT_DIRECT} set-${TYPE} \
+               ${LAYER} ${KEY_NAME} "${VAL}" 2>&1`
+       [ $? -ne 0 ] && echo "Error: $RES"
+}
+
+do_restore() {
+       DIR=${OPT_VAL}
+       [ -z "${OPT_KEY}" ] && echo "Invalid key name" && usage
+       [ -z "${DIR}" ] && echo "Invalid directory" && usage
+       [ ! -x ${DIR} ] && echo "${DIR} directory not exist" && exit 1
+
+       if [ "${OPT_KEY}" == "all" ]
+       then
+               KEY_LIST=`ls ${DIR} | grep -G '^memory+\|^db+\|^file+'`
+               for I in $KEY_LIST
+               do
+                       restore_key $I ${DIR}
+               done
+       else
+               KEY_FILE=`echo ${OPT_KEY} | sed 's/\//\+/g'`
+               KEY_PATH=${DIR}/${KEY_FILE}
+               if [ -e ${DIR}/${KEY_FILE} ]
+               then
+                       restore_key ${KEY_FILE} ${DIR}
+               else
+                       echo "There is no backup for ${OPT_KEY}"
+               fi
+       fi
+}
+
+_getopt() {
+       eval set -- `
+               for x in "$@"; do
+                       echo -n "'$x'" \
+                               | sed -e "s/\(.\)'\(.\)/\\1\\\\'\\2/g" \
+                               -e "s/^'\(-[0-9.]*\)'\$/'protect-sign:\1'/g" \
+                               -e "s/$/ /g"
+               done
+       `
+
+       getopt -n `basename $0` \
+               -l type:,recursive,gid:,uid:,force,install,smack:,debug,verbose,quiet \
+               -o t:rg:u:fis:dvq -- "$@" \
+               | sed -e "s/'protect-sign:/'/g"
+}
+
+eval set -- `_getopt "$@"`
+
+while [ "$1" != "--" ]; do
+       case "$1" in
+       -t|--type)
+               OPT_TYPE="$2"
+               shift 2
+               ;;
+       -r|--recursive)
+               OPT_RECUR=1
+               shift
+               ;;
+       -g|--gid|-u|--uid)
+               # ignore
+               shift 2
+               ;;
+       -f|--force)
+               OPT_FORCE=1
+               shift
+               ;;
+       -v|--verbose|-q|--quiet)
+               # ignore
+               shift
+               ;;
+       -i|--install)
+               OPT_INIT="-i"
+               shift
+               ;;
+       -s|--smack)
+               # ignore
+               shift 2
+               ;;
+       -d|--debug)
+               OPT_DEBUG=1
+               shift
+               ;;
+       *)
+               echo "Invalid argument $1"
+               usage
+               ;;
+       esac
+done
+
+shift
+OPT_CMD="$1"
+OPT_KEY="$2"
+OPT_VAL="$3"
+
+# check daemon status
+if [ ! -x ${BUXTONTOOL} ]; then
+       echo "${BUXTONTOOL} not exist" >&2
+       exit 1
+fi
+
+${BUXTONTOOL} check 2>&1 > /dev/null
+if [ $? -ne 0 ]; then
+       OPT_DIRECT="-d"
+fi
+
+case "$OPT_CMD" in
+get)   do_get ;;
+set)   do_set ;;
+unset) do_unset ;;
+backup) do_backup ;;
+restore) do_restore ;;
+*)     usage ;;
+esac
+