fix create cert.db 62/32862/1
authorSabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
Fri, 26 Dec 2014 17:16:42 +0000 (18:16 +0100)
committerSabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
Fri, 26 Dec 2014 17:16:42 +0000 (18:16 +0100)
Change-Id: I3a913797499cfbb049ef8536d456dcf019f1008b
Signed-off-by: Sabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
client/include/package-manager.h
client/src/pkgmgr.c
comm/pkgmgr_installer.c
comm/pkgmgr_installer.h
server/src/pkgmgr-server.c
tool/pkg_createdb.c
tool/pkg_createdb_user.c
tool/pkg_info.c

index 717775212a5053ab405247060202210d8bae93e8..f36fb8f036274c6db3e8bb2b0e7f25c11263a879 100644 (file)
@@ -1162,7 +1162,7 @@ int pkgmgr_pkginfo_create_certinfo(pkgmgr_certinfo_h *handle);
  * @param[in]  pkgid                           package ID
  * @return     0 if success, error code(<0) if fail\n
 */
-int pkgmgr_pkginfo_load_certinfo(const char *pkgid, pkgmgr_certinfo_h handle);
+int pkgmgr_pkginfo_load_certinfo(const char *pkgid, pkgmgr_certinfo_h handle, uid_t uid);
 
 /**
  * @brief      This API gets cert value for corresponding cert type.
index a67336f5aea74cf0528a50a8e5d883b7b733cb0a..9dc5fbec8cb9c170a25c7f760e67f01a8766d9a6 100644 (file)
@@ -3026,10 +3026,10 @@ API int pkgmgr_pkginfo_create_certinfo(pkgmgr_certinfo_h *handle)
        return ret;
 }
 
-API int pkgmgr_pkginfo_load_certinfo(const char *pkgid, pkgmgr_certinfo_h handle)
+API int pkgmgr_pkginfo_load_certinfo(const char *pkgid, pkgmgr_certinfo_h handle, uid_t uid)
 {
        int ret = 0;
-       ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle);
+       ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle, uid);
        return ret;
 }
 
index e8207a86d2b8b83a31baf91e0aa99a6c8d7f2156..335ebb2d800420a7f2f32376be3038c2f68b2b0a 100644 (file)
@@ -27,7 +27,6 @@
 #include <string.h>
 #include <getopt.h>
 
-
 #include "pkgmgr_installer.h"
 #include "pkgmgr_installer_config.h"
 
@@ -386,10 +385,10 @@ API int pkgmgr_installer_set_cert_value(pkgmgr_instcertinfo_h handle, pkgmgr_ins
        return ret;
 }
 
-API int pkgmgr_installer_save_certinfo(const char *pkgid, pkgmgr_instcertinfo_h handle)
+API int pkgmgr_installer_save_certinfo(const char *pkgid, pkgmgr_instcertinfo_h handle, uid_t uid)
 {
        int ret = 0;
-       ret = pkgmgrinfo_save_certinfo(pkgid, handle);
+       ret = pkgmgrinfo_save_certinfo(pkgid, handle, uid);
        return ret;
 }
 
index 945584fb895524cadfb80abe544c44fce379294e..01e15f4f1c6946309643f35518fb7539e2141eac 100644 (file)
@@ -21,8 +21,7 @@
  */
 
 
-
-
+#include <sys/types.h>
 
 #ifndef __PKGMGR_INSTALLER_H__
 #define __PKGMGR_INSTALLER_H__
@@ -530,7 +529,7 @@ int pkgmgr_installer_set_cert_value(pkgmgr_instcertinfo_h handle, pkgmgr_instcer
  * @param[in]  handle                          pointer to cert info handle
  * @return     0 if success, error code(<0) if fail\n
 */
-int pkgmgr_installer_save_certinfo(const char *pkgid, pkgmgr_instcertinfo_h handle);
+int pkgmgr_installer_save_certinfo(const char *pkgid, pkgmgr_instcertinfo_h handle, uid_t uid);
 
 /**
  * @brief      This API destroys cert info handle freeing all resources.
index a875508172b7a4288fbee71e6cd4cb4367fa718b..4f5b387caf6df236f0b21114f829549764958a5f 100644 (file)
@@ -29,6 +29,8 @@
 #include <sys/inotify.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+#include <dirent.h>
+#include <sys/types.h>
 #include <fcntl.h>
 #include <glib.h>
 #include <signal.h>
index 1d6a143c0a1adc583094dce366d2b8947bf52f7e..69ef8c2bda93f31273ef5b965b63074d01d19357 100644 (file)
                                                "REFERENCES package_app_info(app_id) " \
                                                "ON DELETE CASCADE)"
 
+#define QUERY_CREATE_TABLE_CERT "create table if not exists package_cert_index_info " \
+                                               "(cert_info text not null, " \
+                                               "cert_id integer, " \
+                                               "cert_ref_count integer, " \
+                                               "PRIMARY KEY(cert_id)); " \
+                                               "create table if not exists package_cert_info " \
+                                               "(package text not null, " \
+                                               "author_root_cert integer, " \
+                                               "author_im_cert integer, " \
+                                               "author_signer_cert integer, " \
+                                               "dist_root_cert integer, " \
+                                               "dist_im_cert integer, " \
+                                               "dist_signer_cert integer, " \
+                                               "dist2_root_cert integer, " \
+                                               "dist2_im_cert integer, " \
+                                               "dist2_signer_cert integer, " \
+                                               "PRIMARY KEY(package)) "
+
 #ifdef _E
 #undef _E
 #endif
@@ -315,6 +333,10 @@ int main(int argc, char *argv[])
                        _E(" %s is not removed",PACKAGE_INFO_DB_FILE);
                if(remove(PACKAGE_INFO_DB_FILE_JOURNAL))
                        _E(" %s is not removed",PACKAGE_INFO_DB_FILE_JOURNAL);
+               if(remove(PKG_CERT_DB_FILE))
+                       _E(" %s is not removed",PKG_CERT_DB_FILE);
+               if(remove(PKG_CERT_DB_FILE_JOURNAL))
+                       _E(" %s is not removed",PKG_CERT_DB_FILE_JOURNAL);
        }
 
        setresuid(GLOBAL_USER, GLOBAL_USER, OWNER_ROOT);
@@ -323,7 +345,13 @@ int main(int argc, char *argv[])
        _D("INITDB : %d", ret);
 
        ret = __createdb_tables(&parser_db, PACKAGE_INFO_DB_FILE, QUERY_CREATE_TABLE_PARSER);
-       _D("create DB  %s", getUserPkgParserDBPathUID(GLOBAL_USER));
+       _D("create DB  %s", PACKAGE_INFO_DB_FILE);
+       if (ret) {
+               _D("Parser DB creation Failed\n");
+               return -1;
+       }
+       ret = __createdb_tables(&cert_db, PKG_CERT_DB_FILE, QUERY_CREATE_TABLE_CERT);
+       _D("create DB  %s", PKG_CERT_DB_FILE);
        if (ret) {
                _D("Parser DB creation Failed\n");
                return -1;
index 553c7777a079563dad13fbc3fab1557226cd3d82..c14aab61afe9635bbc8c30ba013105e74483ac5a 100644 (file)
                                                "REFERENCES package_app_info(app_id) " \
                                                "ON DELETE CASCADE)"
 
+#define QUERY_CREATE_TABLE_CERT "create table if not exists package_cert_index_info " \
+                                               "(cert_info text not null, " \
+                                               "cert_id integer, " \
+                                               "cert_ref_count integer, " \
+                                               "PRIMARY KEY(cert_id)); " \
+                                               "create table if not exists package_cert_info " \
+                                               "(package text not null, " \
+                                               "author_root_cert integer, " \
+                                               "author_im_cert integer, " \
+                                               "author_signer_cert integer, " \
+                                               "dist_root_cert integer, " \
+                                               "dist_im_cert integer, " \
+                                               "dist_signer_cert integer, " \
+                                               "dist2_root_cert integer, " \
+                                               "dist2_im_cert integer, " \
+                                               "dist2_signer_cert integer, " \
+                                               "PRIMARY KEY(package)) "
+
 #ifdef _E
 #undef _E
 #endif
@@ -255,10 +273,7 @@ int main(int argc, char *argv[])
        int ret;
        char *journal = NULL;
        uid_t uid = getuid();
-       sqlite3 *parser_db;
-       sqlite3 *cert_db;
 
-       
        if (!__is_authorized()) {
                _E("You are not an authorized user!\n");
                return -1;
@@ -268,6 +283,11 @@ int main(int argc, char *argv[])
                asprintf(&journal, "%s-journal", getUserPkgParserDBPathUID(uid));
                if(remove(journal))
                        _E(" %s is not removed", journal);
+               if(remove(getUserPkgCertDBPathUID(uid)))
+                       _E(" %s is not removed", getUserPkgCertDBPathUID(uid));
+               asprintf(&journal, "%s-journal", getUserPkgCertDBPathUID(uid));
+               if(remove(journal))
+                       _E(" %s is not removed", journal);
        }
        /* This is for AIL initializing */
        ret = setenv("INITDB", "1", 1);
@@ -279,6 +299,12 @@ int main(int argc, char *argv[])
                _D("Parser DB creation Failed\n");
                return -1;
        }
+       ret = __createdb_user_tables(&cert_db, getUserPkgCertDBPathUID(uid), QUERY_CREATE_TABLE_CERT);
+       _D("create DB  %s", getUserPkgCertDBPathUID(uid));
+       if (ret) {
+               _D("Cert DB creation Failed\n");
+               return -1;
+       }
 
        return 0;
 }
index 55d2d407b051ae756fb8121961c5c53a3b8e4fde..cd7d4613c8918b05bc8d0cc952d64dead1460b3c 100644 (file)
@@ -51,8 +51,8 @@ static int __add_pkg_filter(uid_t uid);
 static int __insert_manifest_in_db(char *manifest, uid_t uid);
 static int __remove_manifest_from_db(char *manifest, uid_t uid);
 static int __set_pkginfo_in_db(char *pkgid, uid_t uid);
-static int __set_certinfo_in_db(char *pkgid);
-static int __get_certinfo_from_db(char *pkgid);
+static int __set_certinfo_in_db(char *pkgid, uid_t uid);
+static int __get_certinfo_from_db(char *pkgid, uid_t uid);
 static int __del_certinfo_from_db(char *pkgid);
 static int __get_integer_input_data(void);
 char *__get_string_input_data(void);
@@ -1050,7 +1050,7 @@ static int __del_certinfo_from_db(char *pkgid)
        return 0;
 }
 
-static int __get_certinfo_from_db(char *pkgid)
+static int __get_certinfo_from_db(char *pkgid, uid_t uid)
 {
        if (pkgid == NULL) {
                printf("pkgid is NULL\n");
@@ -1066,7 +1066,7 @@ static int __get_certinfo_from_db(char *pkgid)
                printf("pkgmgr_pkginfo_create_certinfo failed\n");
                return -1;
        }
-       ret = pkgmgr_pkginfo_load_certinfo(pkgid, handle);
+       ret = pkgmgr_pkginfo_load_certinfo(pkgid, handle, uid);
        if (ret < 0) {
                printf("pkgmgr_pkginfo_load_certinfo failed\n");
                return -1;
@@ -1173,7 +1173,7 @@ static int __compare_app_certinfo_from_db(char *lhs_appid, char *rhs_appid, uid_
        return 0;
 }
 
-static int __set_certinfo_in_db(char *pkgid)
+static int __set_certinfo_in_db(char *pkgid, uid_t uid)
 {
        if (pkgid == NULL) {
                printf("pkgid is NULL\n");
@@ -1204,7 +1204,7 @@ static int __set_certinfo_in_db(char *pkgid)
                choice = __get_integer_input_data();
                switch (choice) {
                case 0:
-                       ret = pkgmgr_installer_save_certinfo(pkgid, handle);
+                       ret = pkgmgr_installer_save_certinfo(pkgid, handle, uid);
                        if (ret < 0) {
                                printf("pkgmgr_installer_save_certinfo failed\n");
                                pkgmgr_installer_destroy_certinfo_set_handle(handle);
@@ -2376,13 +2376,13 @@ int main(int argc, char *argv[])
                        goto end;
                }
        } else if (strcmp(argv[1], "--setcert") == 0) {
-               ret = __set_certinfo_in_db(argv[2]);
+               ret = __set_certinfo_in_db(argv[2], getuid());
                if (ret == -1) {
                        printf("set certinfo in db failed\n");
                        goto end;
                }
        } else if (strcmp(argv[1], "--getcert") == 0) {
-               ret = __get_certinfo_from_db(argv[2]);
+               ret = __get_certinfo_from_db(argv[2], getuid());
                if (ret == -1) {
                        printf("get certinfo from db failed\n");
                        goto end;