From 417d5587c143c0881299a24f053bb85bff5e4f4f Mon Sep 17 00:00:00 2001 From: "Sabera Djelti (sdi2)" Date: Mon, 22 Sep 2014 17:28:01 +0200 Subject: [PATCH] Add pkg_initdb_user Change-Id: Ia5d480922c86e5b9d926b7ec63d411c5baed9aa3 Signed-off-by: Sabera Djelti (sdi2) --- packaging/pkgmgr.spec | 1 + tool/CMakeLists.txt | 4 ++ tool/pkg_initdb_user.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100755 tool/pkg_initdb_user.c diff --git a/packaging/pkgmgr.spec b/packaging/pkgmgr.spec index e51868b..973a441 100644 --- a/packaging/pkgmgr.spec +++ b/packaging/pkgmgr.spec @@ -143,6 +143,7 @@ update-mime-database /usr/share/mime %{_sysconfdir}/opt/upgrade/pkgmgr.patch.sh %{_bindir}/pkgcmd %attr(06755,root,root) %{_bindir}/pkg_initdb +%attr(755,root,root) %{_bindir}/pkg_initdb_user %{_bindir}/pkg_getsize %{_bindir}/pkginfo %{_bindir}/pkgmgr-install diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt index 0eeb65b..1a4a4c2 100755 --- a/tool/CMakeLists.txt +++ b/tool/CMakeLists.txt @@ -47,6 +47,10 @@ add_executable(pkg_initdb pkg_initdb.c) target_link_libraries(pkg_initdb ${pkgs_initdb_LDFLAGS}) INSTALL(TARGETS pkg_initdb DESTINATION bin) +add_executable(pkg_initdb_user pkg_initdb_user.c) +target_link_libraries(pkg_initdb_user ${pkgs_initdb_LDFLAGS}) +INSTALL(TARGETS pkg_initdb_user DESTINATION bin) + add_executable(pkgmgr-install pkgmgr-install.c) target_link_libraries(pkgmgr-install pkgmgr-client pkgmgr-info ${toolpkgs_LDFLAGS}) install(TARGETS pkgmgr-install DESTINATION bin) diff --git a/tool/pkg_initdb_user.c b/tool/pkg_initdb_user.c new file mode 100755 index 0000000..040b072 --- /dev/null +++ b/tool/pkg_initdb_user.c @@ -0,0 +1,192 @@ +/* + * slp-pkgmgr + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , + * Jaeho Lee , Shobhit Srivastava + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +/* For multi-user support */ +#include + +#define OWNER_ROOT 0 +#define GROUP_MENU 6010 +#define BUFSZE 1024 +#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) + + +#ifdef _E +#undef _E +#endif +#define _E(fmt, arg...) fprintf(stderr, "[PKG_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); + +#ifdef _D +#undef _D +#endif +#define _D(fmt, arg...) fprintf(stderr, "[PKG_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); + +#define SET_DEFAULT_LABEL(x) \ + if(smack_setlabel((x), "*", SMACK_LABEL_ACCESS)) _E("failed chsmack -a \"*\" %s", x) \ + else _D("chsmack -a \"*\" %s", x) + +static int initdb_user_count_package(void) +{ + int total = 0; + + return total; +} + + +char* _manifest_to_package(const char* manifest) +{ + char *package; + + if(manifest == NULL) + return NULL; + + package = strdup(manifest); + if(package == NULL) + return NULL; + + + if (!strstr(package, ".xml")) { + _E("%s is not a manifest file", manifest); + free(package); + return NULL; + } + + return package; +} + + + +int initdb_user_load_directory(const char *directory) +{ + DIR *dir; + struct dirent entry, *result; + int ret; + char buf[BUFSZE]; + + // desktop file + dir = opendir(directory); + if (!dir) { + if (strerror_r(errno, buf, sizeof(buf)) == 0) + _E("Failed to access the [%s] because %s\n", directory, buf); + return -1; + } + + _D("Loading manifest files from %s\n", directory); + + for (ret = readdir_r(dir, &entry, &result); + ret == 0 && result != NULL; + ret = readdir_r(dir, &entry, &result)) { + char *manifest; + + if (entry.d_name[0] == '.') continue; + + manifest = _manifest_to_package(entry.d_name); + if (!manifest) { + _E("Failed to convert file to package[%s]\n", entry.d_name); + continue; + } + + snprintf(buf, sizeof(buf), "%s/%s", directory, manifest); + + fprintf(stderr, "pkg_initdb : manifest file %s\n", buf); + + ret = pkgmgr_parser_check_manifest_validation(buf); + if (ret < 0) { + _E("check manifest validation failed code[%d] %s\n", ret, buf); + fprintf(stderr, "check manifest validation failed code[%d] %s\n", ret, buf); + free(manifest); + continue; + } + + + /*temporarily fixed due to glib abort */ + // pkgmgr_parser_parse_manifest_for_installation(buf, NULL); + + char buf2[BUFSZE]; + snprintf(buf2, sizeof(buf2), "/usr/bin/pkginfo --imd %s", buf); + system(buf2); + + free(manifest); + } + + closedir(dir); + + return 0; +} + +static int __is_authorized() +{ + /* pkg_init db should be called by as root privilege. */ + + uid_t uid = getuid(); + if ((uid_t) OWNER_ROOT != uid) + return 1; + else + return 0; +} + + +int main(int argc, char *argv[]) +{ + int ret; + char *journal = NULL; + + if (!__is_authorized()) { + _E("You are not an authorized user!\n"); + return -1; + } else { + if(remove(getUserPkgParserDBPathUID(getuid()))) + _E(" %s is not removed", getUserPkgParserDBPathUID(getuid())); + asprintf(&journal, "%s-journal", getUserPkgParserDBPathUID(getuid())); + if(remove(journal)) + _E(" %s is not removed", journal); + } + + /* This is for AIL initializing */ + ret = setenv("INITDB", "1", 1); + _D("INITDB : %d", ret); + + ret = initdb_user_count_package(); + if (ret > 0) { + _D("Some Packages in the Package Info DB."); + return 0; + } + ret = initdb_user_load_directory(getUserManifestPath(getuid())); + if (ret == -1) { + _E("cannot load opt manifest directory."); + } + + return 0; +} -- 2.7.4