From 8329a2a463edae1e65d5020eab197a7fa2ad6e98 Mon Sep 17 00:00:00 2001 From: "Sabera Djelti (sdi2)" Date: Mon, 10 Feb 2014 16:04:08 +0100 Subject: [PATCH] Removed hardcoded path for multiuser support Bug-Tizen: PTREL-220 Change-Id: Ifcbf6fab59caaa2d61d442ff974fc23aeb540512 Signed-off-by: Sabera Djelti (sdi2) --- CMakeLists.txt | 5 +-- common/cal_typedef.h | 7 +++-- common/ipc/cal_ipc.h | 6 ++-- native/cal_db.h | 6 ++-- native/cal_db_util.c | 61 +++++++++++++++++++++++++++++++++++++ native/cal_db_util.h | 2 ++ packaging/calendar-service.manifest | 3 -- packaging/calendar-service.spec | 19 +----------- schema/CMakeLists.txt | 8 ++--- schema/initdb.c | 29 ++++++++++-------- server/CMakeLists.txt | 2 +- 11 files changed, 97 insertions(+), 51 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24052ca..bb850a8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ SET(VERSION "${VERSION_MAJOR}.1.15") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -I${CMAKE_SOURCE_DIR}/include") INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0 sqlite3 vconf dlog db-util alarm-service icu-i18n appsvc bundle) +pkg_check_modules(pkgs REQUIRED glib-2.0 sqlite3 vconf dlog db-util alarm-service icu-i18n appsvc bundle libtzplatform-config) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -45,9 +45,6 @@ SET(IMMIGRATION "calendar-service2") CONFIGURE_FILE(calendar.pc.in calendar.pc @ONLY) INSTALL(FILES calendar.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -FILE(GLOB NOTI_FILES ${CMAKE_SOURCE_DIR}/.CALENDAR_SVC_*_CHANGED) -INSTALL(FILES ${NOTI_FILES} DESTINATION /opt/usr/data/calendar-svc) - ADD_SUBDIRECTORY(schema) ADD_SUBDIRECTORY(client) ADD_SUBDIRECTORY(server) diff --git a/common/cal_typedef.h b/common/cal_typedef.h index db1756b..317a0a9 100755 --- a/common/cal_typedef.h +++ b/common/cal_typedef.h @@ -25,11 +25,12 @@ #include #include #include "cal_record.h" +#include #define CAL_TZID_GMT "Etc/GMT" -#define CAL_NOTI_EVENT_CHANGED "/opt/usr/data/calendar-svc/.CALENDAR_SVC_EVENT_CHANGED" -#define CAL_NOTI_TODO_CHANGED "/opt/usr/data/calendar-svc/.CALENDAR_SVC_TODO_CHANGED" -#define CAL_NOTI_CALENDAR_CHANGED "/opt/usr/data/calendar-svc/.CALENDAR_SVC_CALENDAR_CHANGED" +#define CAL_NOTI_EVENT_CHANGED tzplatform_mkpath(TZ_USER_DATA,"calendar-svc/.CALENDAR_SVC_EVENT_CHANGED") +#define CAL_NOTI_TODO_CHANGED tzplatform_mkpath(TZ_USER_DATA,"calendar-svc/.CALENDAR_SVC_TODO_CHANGED") +#define CAL_NOTI_CALENDAR_CHANGED tzplatform_mkpath(TZ_USER_DATA,"calendar-svc/.CALENDAR_SVC_CALENDAR_CHANGED") #define CAL_NOTI_REMINDER_CAHNGED "reminder" /** diff --git a/common/ipc/cal_ipc.h b/common/ipc/cal_ipc.h index ad3a92a..e1721b4 100644 --- a/common/ipc/cal_ipc.h +++ b/common/ipc/cal_ipc.h @@ -17,12 +17,14 @@ * */ +#include + #ifndef __CAL_IPC_H__ #define __CAL_IPC_H__ #define CAL_IPC_SERVICE "cal_svc_ipc" -#define CAL_IPC_SOCKET_PATH "/opt/usr/data/calendar-svc/."CAL_IPC_SERVICE -#define CAL_IPC_SOCKET_PATH_FOR_SUBSCRIPTION "/opt/usr/data/calendar-svc/."CAL_IPC_SERVICE"_for_subscription" +#define CAL_IPC_SOCKET_PATH tzplatform_mkpath(TZ_USER_DATA, "calendar-svc/."CAL_IPC_SERVICE) +#define CAL_IPC_SOCKET_PATH_FOR_SUBSCRIPTION tzplatform_mkpath(TZ_USER_DATA, "calendar-svc/."CAL_IPC_SERVICE"_for_subscription") #define CAL_IPC_MODULE "cal_ipc_module" #define CAL_IPC_MODULE_FOR_SUBSCRIPTION CAL_IPC_MODULE"_for_subscription" diff --git a/native/cal_db.h b/native/cal_db.h index 04b8000..4e14627 100644 --- a/native/cal_db.h +++ b/native/cal_db.h @@ -16,14 +16,16 @@ * limitations under the License. * */ +#include + #ifndef __CALENDAR_SVC_DB_H__ #define __CALENDAR_SVC_DB_H__ #include "calendar_view.h" #include "calendar_list.h" -#define CAL_DB_PATH "/opt/usr/dbspace/.calendar-svc.db" -#define CAL_DB_JOURNAL_PATH "/opt/usr/dbspace/.calendar-svc.db-journal" +#define CAL_DB_PATH tzplatform_mkpath(TZ_USER_DB, ".calendar-svc.db") +#define CAL_DB_JOURNAL_PATH tzplatform_mkpath(TZ_USER_DB, ".calendar-svc.db-journal") // For Security #define CAL_SECURITY_FILE_GROUP 6003 diff --git a/native/cal_db_util.c b/native/cal_db_util.c index a6c807a..d14fedf 100644 --- a/native/cal_db_util.c +++ b/native/cal_db_util.c @@ -27,6 +27,13 @@ #include "cal_db_util.h" +#define DB_PATH tzplatform_getenv(TZ_USER_DB) +#define DATA_PATH tzplatform_getenv(TZ_USER_DATA) +#define CAL_DATA_PATH tzplatform_mkpath(TZ_USER_DATA,"calendar-svc") +// For Security +#define CALS_SECURITY_FILE_GROUP 6003 +#define CALS_SECURITY_DEFAULT_PERMISSION 0660 + static TLS sqlite3 *calendar_db_handle; static TLS int transaction_cnt = 0; static TLS int transaction_ver = 0; @@ -36,8 +43,36 @@ static TLS bool event_change=false; static TLS bool todo_change=false; static TLS bool calendar_change=false; +static inline int create_noti_file(const char* noti_file) +{ + int fd, ret; + fd = creat(noti_file, CALS_SECURITY_DEFAULT_PERMISSION); + if (-1 == fd) + { + printf("open Failed\n"); + return -1; + } + + ret = fchown(fd, -1, CALS_SECURITY_FILE_GROUP); + if (-1 == ret) + { + printf("Failed to fchown\n"); + close(fd); + return -1; + } +} + static inline void __cal_db_util_notify_event_change(void) { + if (-1 == access (DATA_PATH, F_OK)) + { + mkdir(DATA_PATH, 755); + } + if (-1 == access (CAL_DATA_PATH, F_OK)) + { + mkdir(CAL_DATA_PATH, 755); + } + create_noti_file(CAL_NOTI_EVENT_CHANGED); int fd = open(CAL_NOTI_EVENT_CHANGED, O_TRUNC | O_RDWR); if (0 <= fd) { close(fd); @@ -47,6 +82,15 @@ static inline void __cal_db_util_notify_event_change(void) static inline void __cal_db_util_notify_todo_change(void) { + if (-1 == access (DATA_PATH, F_OK)) + { + mkdir(DATA_PATH, 755); + } + if (-1 == access (CAL_DATA_PATH, F_OK)) + { + mkdir(CAL_DATA_PATH, 755); + } + create_noti_file(CAL_NOTI_TODO_CHANGED); int fd = open(CAL_NOTI_TODO_CHANGED, O_TRUNC | O_RDWR); if (0 <= fd) { close(fd); @@ -56,6 +100,15 @@ static inline void __cal_db_util_notify_todo_change(void) static inline void __cal_db_util_notify_calendar_change(void) { + if (-1 == access (DATA_PATH, F_OK)) + { + mkdir(DATA_PATH, 755); + } + if (-1 == access (CAL_DATA_PATH, F_OK)) + { + mkdir(CAL_DATA_PATH, 755); + } + create_noti_file(CAL_NOTI_CALENDAR_CHANGED); int fd = open(CAL_NOTI_CALENDAR_CHANGED, O_TRUNC | O_RDWR); if (0 <= fd) { close(fd); @@ -113,6 +166,14 @@ int _cal_db_util_open(void) int ret = 0; if (!calendar_db_handle) { + if (-1 == access (DB_PATH, F_OK)) + { + mkdir(DB_PATH, 755); + } + if (-1 == access (CAL_DB_PATH, F_OK)) + { + mkdir(DB_PATH, 755); + } ret = db_util_open(CAL_DB_PATH, &calendar_db_handle, 0); retvm_if(SQLITE_OK != ret, CALENDAR_ERROR_DB_FAILED, "db_util_open() Failed(%d).", ret); diff --git a/native/cal_db_util.h b/native/cal_db_util.h index 888e184..7ee36a7 100644 --- a/native/cal_db_util.h +++ b/native/cal_db_util.h @@ -58,4 +58,6 @@ int _cal_db_util_get_next_ver(void); int _cal_db_util_get_transaction_ver(void); +void cal_db_util_set_permission(int fd); + #endif //__CALENDAR_SVC_DB_UTIL_H__ diff --git a/packaging/calendar-service.manifest b/packaging/calendar-service.manifest index 2d2776b..017d22d 100644 --- a/packaging/calendar-service.manifest +++ b/packaging/calendar-service.manifest @@ -2,7 +2,4 @@ - - - diff --git a/packaging/calendar-service.spec b/packaging/calendar-service.spec index 8aa72ca..c7cb08e 100644 --- a/packaging/calendar-service.spec +++ b/packaging/calendar-service.spec @@ -24,6 +24,7 @@ BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(contacts-service2) BuildRequires: pkgconfig(pims-ipc) BuildRequires: pkgconfig(bundle) +BuildRequires: pkgconfig(libtzplatform-config) %description DB library for calendar @@ -63,18 +64,6 @@ ln -s ../calendar.service %{buildroot}%{_unitdir_user}/tizen-middleware.target.w %post /sbin/ldconfig -chown :6003 /opt/usr/data/calendar-svc - -mkdir -p /opt/usr/dbspace - -chown :6003 /opt/usr/dbspace/.calendar-svc.db -chown :6003 /opt/usr/dbspace/.calendar-svc.db-journal -chown :6003 /opt/usr/data/calendar-svc/.CALENDAR_SVC_* - -chmod 660 /opt/usr/dbspace/.calendar-svc.db -chmod 660 /opt/usr/dbspace/.calendar-svc.db-journal -chmod 660 /opt/usr/data/calendar-svc/.CALENDAR_SVC_* - %postun -p /sbin/ldconfig %files @@ -86,12 +75,7 @@ chmod 660 /opt/usr/data/calendar-svc/.CALENDAR_SVC_* %attr(0755,root,root) /etc/rc.d/init.d/calendar-serviced.sh /etc/rc.d/rc3.d/S85calendar-serviced /etc/rc.d/rc5.d/S85calendar-serviced -%dir %attr(0775,root,root) /opt/usr/data/calendar-svc/ -/opt/usr/data/calendar-svc/.CALENDAR_SVC_CALENDAR_CHANGED -/opt/usr/data/calendar-svc/.CALENDAR_SVC_EVENT_CHANGED -/opt/usr/data/calendar-svc/.CALENDAR_SVC_TODO_CHANGED /usr/share/calendar-svc/dft-calendar -%config(noreplace) /opt/usr/dbspace/.calendar-svc.db* %{_unitdir_user}/calendar.service %{_unitdir_user}/tizen-middleware.target.wants/calendar.service @@ -104,4 +88,3 @@ chmod 660 /opt/usr/data/calendar-svc/.CALENDAR_SVC_* %{_libdir}/pkgconfig/calendar.pc #%{_libdir}/pkgconfig/calendar-service-native.pc %{_libdir}/pkgconfig/calendar-service2.pc -/opt/usr/data/calendar-svc/calendar-svc-initdb diff --git a/schema/CMakeLists.txt b/schema/CMakeLists.txt index f3dcc2c..e7a836b 100755 --- a/schema/CMakeLists.txt +++ b/schema/CMakeLists.txt @@ -1,3 +1,4 @@ +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common) LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) SET(TARGET calendar-svc-initdb) @@ -9,7 +10,7 @@ EXECUTE_PROCESS(COMMAND ./generator.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_ SET(INITDBFILE initdb.c) SET(TOOLLIB calendar-service2) -pkg_check_modules(initdb_pkgs REQUIRED db-util dlog) +pkg_check_modules(initdb_pkgs REQUIRED db-util dlog libtzplatform-config) UNSET(EXTRA_CFLAGS) FOREACH(flag ${initdb_pkgs_CFLAGS}) @@ -23,8 +24,3 @@ ADD_EXECUTABLE(${TARGET} ${INITDBFILE}) SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS}) TARGET_LINK_LIBRARIES(${TARGET} ${initdb_pkgs_LDFLAGS}) -#INSTALL(TARGETS ${TARGET} DESTINATION bin) -INSTALL(TARGETS ${TARGET} DESTINATION /opt/usr/data/calendar-svc) - -FILE(GLOB DB_FILES ${CMAKE_SOURCE_DIR}/schema/.calendar-svc.db*) -INSTALL(FILES ${DB_FILES} DESTINATION /opt/usr/dbspace) diff --git a/schema/initdb.c b/schema/initdb.c index 7b849ef..de91d9f 100755 --- a/schema/initdb.c +++ b/schema/initdb.c @@ -16,19 +16,22 @@ * limitations under the License. * */ + #include #include #include #include #include #include - +#include "cal_typedef.h" #include "schema.h" +#include + #define CALS_DB_NAME ".calendar-svc.db" #define CALS_DB_JOURNAL_NAME ".calendar-svc.db-journal" -#define CALS_DB_PATH "/opt/usr/dbspace/"CALS_DB_NAME -#define CALS_DB_JOURNAL_PATH "/opt/usr/dbspace/"CALS_DB_JOURNAL_NAME +#define CALS_DB_PATH tzplatform_mkpath(TZ_USER_DB, ".calendar-svc.db") +#define CALS_DB_JOURNAL_PATH tzplatform_mkpath(TZ_USER_DB, ".calendar-svc.db-journal") // For Security #define CALS_SECURITY_FILE_GROUP 6003 @@ -122,22 +125,24 @@ static inline int check_db_file(char* db_path) snprintf(db_file,sizeof(db_file),"%s%s",db_path, CALS_DB_NAME); } - fd = open(db_file, O_RDONLY); + fd = open(db_file, O_RDONLY); - if (-1 == fd) - { - printf("DB file(%s) is not exist\n", db_file); - return -1; - } - printf("DB file(%s) \n", db_file); - close(fd); - return 0; + if (-1 == fd) + { + printf("DB file(%s) is not exist\n", db_file); + return -1; + } + printf("DB file(%s) \n", db_file); + close(fd); + return 0; } + static inline int check_schema(char* db_path) { if (check_db_file(db_path)) remake_db_file(db_path); + return 0; } diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 93ffad2..e5f60d1 100755 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -66,7 +66,7 @@ SET(LIBSRCS ) INCLUDE(FindPkgConfig) -pkg_check_modules(calserver_pkgs REQUIRED pims-ipc db-util appsvc alarm-service capi-base-common icu-i18n alarm-service) +pkg_check_modules(calserver_pkgs REQUIRED pims-ipc db-util appsvc alarm-service capi-base-common icu-i18n alarm-service libtzplatform-config) FOREACH(flag ${calserver_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -- 2.7.4