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;
const char *usage;
comm_func func;
comm_func dfunc;
+ command_type_e index;
};
static const struct command const commands[] = {
.usage = "",
.func = c_check,
.dfunc = c_check,
+ .index = COMMAND_CHECK,
},
{
.name = "get",
.usage = "LAYER KEY",
.func = c_get,
.dfunc = c_direct_get,
+ .index = COMMAND_GET,
},
{
.name = "create-string",
.usage = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
.func = c_create_str,
.dfunc = c_direct_create_str,
+ .index = COMMAND_CREATE_STRING,
},
{
.name = "create-int32",
.usage = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
.func = c_create_int32,
.dfunc = c_direct_create_int32,
+ .index = COMMAND_CREATE_INT32,
},
{
.name = "create-uint32",
.usage = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
.func = c_create_uint32,
.dfunc = c_direct_create_uint32,
+ .index = COMMAND_CREATE_UINT32,
},
{
.name = "create-int64",
.usage = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
.func = c_create_int64,
.dfunc = c_direct_create_int64,
+ .index = COMMAND_CREATE_INT64,
},
{
.name = "create-uint64",
.usage = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
.func = c_create_uint64,
.dfunc = c_direct_create_uint64,
+ .index = COMMAND_CREATE_UINT64,
},
{
.name = "create-double",
.usage = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
.func = c_create_double,
.dfunc = c_direct_create_double,
+ .index = COMMAND_CREATE_DOUBLE,
},
{
.name = "create-bool",
.usage = "LAYER KEY VALUE READ_PRIV WRITE_PRIV",
.func = c_create_bool,
.dfunc = c_direct_create_bool,
+ .index = COMMAND_CREATE_BOOL,
},
{
.name = "set-string",
.usage = "LAYER KEY VALUE",
.func = c_set_str,
.dfunc = c_direct_set_str,
+ .index = COMMAND_SET_STRING,
},
{
.name = "set-int32",
.usage = "LAYER KEY VALUE",
.func = c_set_int32,
.dfunc = c_direct_set_int32,
+ .index = COMMAND_SET_INT32,
},
{
.name = "set-uint32",
.usage = "LAYER KEY VALUE",
.func = c_set_uint32,
.dfunc = c_direct_set_uint32,
+ .index = COMMAND_SET_UINT32,
},
{
.name = "set-int64",
.usage = "LAYER KEY VALUE",
.func = c_set_int64,
.dfunc = c_direct_set_int64,
+ .index = COMMAND_SET_INT64,
},
{
.name = "set-uint64",
.usage = "LAYER KEY VALUE",
.func = c_set_uint64,
.dfunc = c_direct_set_uint64,
+ .index = COMMAND_SET_UINT64,
},
{
.name = "set-double",
.usage = "LAYER KEY VALUE",
.func = c_set_double,
.dfunc = c_direct_set_double,
+ .index = COMMAND_SET_DOUBLE,
},
{
.name = "set-bool",
.usage = "LAYER KEY VALUE",
.func = c_set_bool,
.dfunc = c_direct_set_bool,
+ .index = COMMAND_SET_BOOL,
},
{
.name = "get-read-priv",
.usage = "LAYER KEY",
.func = c_get_rpriv,
.dfunc = c_direct_get_rpriv,
+ .index = COMMAND_GET_READ_PRIV,
},
{
.name = "set-read-priv",
.usage = "LAYER KEY PRIVILEGE",
.func = c_set_rpriv,
.dfunc = c_direct_set_rpriv,
+ .index = COMMAND_SET_READ_PRIV,
},
{
.name = "get-write-priv",
.usage = "LAYER KEY",
.func = c_get_wpriv,
.dfunc = c_direct_get_wpriv,
+ .index = COMMAND_GET_WRITE_PRIV,
},
{
.name = "set-write-priv",
.usage = "LAYER KEY PRIVILEGE",
.func = c_set_wpriv,
.dfunc = c_direct_set_wpriv,
+ .index = COMMAND_SET_WRITE_PRIV,
},
{
.name = "unset",
.usage = "LAYER KEY",
.func = c_unset,
.dfunc = c_direct_unset,
+ .index = COMMAND_UNSET,
},
{
.name = "list-keys",
.usage = "LAYER",
.func = c_list,
.dfunc = c_direct_list,
+ .index = COMMAND_LIST_KEYS,
},
{
.name = "security-enable",
.usage = "",
.func = c_enable_security,
.dfunc = NULL,
+ .index = COMMAND_SECURITY_ENABLE,
},
{
.name = "security-disable",
.usage = "",
.func = c_disable_security,
.dfunc = NULL,
+ .index = COMMAND_SECURITY_DISABLE,
},
{
.name = "remove-garbage-data",
.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;
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;
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 }
};
int r;
const struct command *comm;
comm_func func;
+ command_type_e index;
struct buxton_layer *layer;
struct options opt = {
.confpath = NULL,
.install = FALSE,
.uid = 0,
.help = FALSE,
+ .owner = FALSE,
};
r = parse_args(&argc, &argv, &opt);
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);
--- /dev/null
+#!/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
+