From b2c4fd56d0e724b1ec3efa59b194acf7e77558d1 Mon Sep 17 00:00:00 2001 From: Tomasz Lewandowski Date: Fri, 31 Mar 2017 08:00:28 -0700 Subject: [PATCH] Add 'persAdminUserDataCopy' implementation. Change-Id: I2defa5ebee6b083275a474eec61eedb303225c10 --- .../inc/private/ssw_pers_admin_database_helper.h | 14 ++ .../inc/private/ssw_pers_admin_files_helper.h | 10 + Administrator/src/ssw_pers_admin_access_lib.c | 16 +- Administrator/src/ssw_pers_admin_database_helper.c | 202 ++++++++++++++++++++- Administrator/src/ssw_pers_admin_files_helper.c | 54 ++++++ Administrator/src/ssw_pers_admin_service.c | 139 +++++++++++++- test/persadmin_tool/src/persadmin_tool.c | 50 +++-- 7 files changed, 453 insertions(+), 32 deletions(-) diff --git a/Administrator/inc/private/ssw_pers_admin_database_helper.h b/Administrator/inc/private/ssw_pers_admin_database_helper.h index 6155765..a8f7f9d 100644 --- a/Administrator/inc/private/ssw_pers_admin_database_helper.h +++ b/Administrator/inc/private/ssw_pers_admin_database_helper.h @@ -75,6 +75,20 @@ sint_t persadmin_delete_keys_by_filter(PersASSelectionType_e type, pstr_t pchDBP */ sint_t persadmin_copy_keys_by_filter(PersASSelectionType_e type, pstr_t pchdestDBPath, pstr_t pchsourceDBPath, uint32_t user_no, uint32_t seat_no); + /** + * @brief copies keys filtered by user name and seat number from user to user + * + * @param pchsourceDBPath[in] source DB path + * @param src_user_no [in] the source user ID + * @param src_seat_no [in] the source seat number (seat 1 to 4; 0 is for all seats) + * @param dst_user_no [in] the destination user ID + * @param dst_seat_no [in] the destination seat number (seat 1 to 4; 0 is for all seats) + * + * @return 0 for success, negative value otherwise; + * + */ +sint_t persadmin_copy_keys_by_filter_from_to_user(PersASSelectionType_e type, char* pchsourceDBPath, uint32_t src_user_no, uint32_t src_seat_no, uint32_t dst_user_no, uint32_t dst_seat_no); + #ifdef __cplusplus diff --git a/Administrator/inc/private/ssw_pers_admin_files_helper.h b/Administrator/inc/private/ssw_pers_admin_files_helper.h index 915a27f..4d3291a 100644 --- a/Administrator/inc/private/ssw_pers_admin_files_helper.h +++ b/Administrator/inc/private/ssw_pers_admin_files_helper.h @@ -192,6 +192,16 @@ sint_t persadmin_get_folder_size( pconststr_t folderPath ); */ bool_t persadmin_check_for_same_file_content(pstr_t file1Path, pstr_t file2Path); + /** + * \brief Checks if element pointed by path is a symlink or not + * + * \param path [in] absolute path to one of the files to be checked + * \return true if the symlink or false if not + */ +bool_t isSymLink( const char* path ); + +bool_t checkAndFixFolderPath( char* path); + #ifdef __cplusplus } #endif /* extern "C" { */ diff --git a/Administrator/src/ssw_pers_admin_access_lib.c b/Administrator/src/ssw_pers_admin_access_lib.c index d56298c..806c3c2 100644 --- a/Administrator/src/ssw_pers_admin_access_lib.c +++ b/Administrator/src/ssw_pers_admin_access_lib.c @@ -946,18 +946,20 @@ long persAdminUserDataCopy(unsigned int src_user_no, unsigned int src_seat_no, u long errorCode = PAS_FAILURE ; /* check params */ - if((src_user_no <= PERSADMIN_MAX_USER_NO) && (src_seat_no <= PERSADMIN_MAX_SEAT_NO) && (dest_user_no <= PERSADMIN_MAX_USER_NO) && (dest_seat_no <= PERSADMIN_MAX_SEAT_NO)) + if( + (src_user_no <= PERSADMIN_MAX_USER_NO) && (src_seat_no <= PERSADMIN_MAX_SEAT_NO || src_seat_no == (unsigned int)PERSIST_SELECT_ALL_USERS) && + (dest_user_no <= PERSADMIN_MAX_USER_NO) && (dest_seat_no <= PERSADMIN_MAX_SEAT_NO || dest_seat_no == (unsigned int)PERSIST_SELECT_ALL_SEATS) + ) { - + bEverythingOK = true; } - else - { - bEverythingOK = false ; + + if(!bEverythingOK) + { errorCode = PAS_FAILURE_INVALID_PARAMETER ; printf("%s Invalid params - src_user_no=%d src_seat_no=%d dest_user_no=%d dest_seat_no=%d \n", FuncName, src_user_no, src_seat_no, dest_user_no, dest_seat_no) ; } - if(bEverythingOK) { if(persadmin_lockSyncSem(&pSynchSem)) @@ -996,7 +998,7 @@ long persAdminUserDataCopy(unsigned int src_user_no, unsigned int src_seat_no, u if(bEverythingOK) { - sRequest.eRequest = PAS_Req_DataBackupCreate ; + sRequest.eRequest = PAS_Req_UserDataCopy ; sRequest.src_user_no = src_user_no ; sRequest.src_seat_no = src_seat_no ; sRequest.dest_user_no = dest_user_no ; diff --git a/Administrator/src/ssw_pers_admin_database_helper.c b/Administrator/src/ssw_pers_admin_database_helper.c index 6ca10b9..484b05c 100644 --- a/Administrator/src/ssw_pers_admin_database_helper.c +++ b/Administrator/src/ssw_pers_admin_database_helper.c @@ -59,14 +59,214 @@ DLT_IMPORT_CONTEXT (persAdminSvcDLTCtx) pchDBPaths_out += toWrite; \ } +static int persadmin_priv_copy_keys_by_filter_from_to_user(PersASSelectionType_e type, char* pchsourceDBPath, unsigned int src_user_no, unsigned src_seat_no, unsigned int dst_user_no, unsigned int dst_seat_no); static int persadmin_priv_copy_keys_by_filter (PersASSelectionType_e type, char* pchdestDBPath, char* pchsourceDBPath, unsigned int user_no, unsigned int seat_no); static int persadmin_priv_delete_keys_by_filter (PersASSelectionType_e type, char* pchDBPath, unsigned int user_no, unsigned int seat_no); -static sint_t persadmin_priv_filter_keys_in_list (PersASSelectionType_e type, unsigned int user_no, unsigned int seat_no, pstr_t pUnfilteredList, pstr_t pFilteredList_out, sint_t iListSize) ; +static sint_t persadmin_priv_filter_keys_in_list (PersASSelectionType_e type, unsigned int user_no, unsigned int seat_no, pstr_t pUnfilteredList, pstr_t pFilteredList_out, sint_t iListSize); + static int persadmin_priv_get_all_local_db_names ( const char * pchRootPath, const char * pchAppName, char* pchDBPaths_out, int bufSize ); static int persadmin_priv_get_all_shared_db_names ( const char * pchRootPath, char* pchDBPaths_out, int bufSize ); static int persadmin_priv_get_all_shared_group_db_names ( const char * pchRootPath, const char * pchDataPathFormat, const char * dbName, const char * defaultDbName, char* pchDBPaths_out, int * bufferSize ); + +bool replaceUserInKey( char* key, unsigned int src_user_no, unsigned int dest_user_no, char* updatedKey ) +{ + int idx = -1; + char* found = strstr( key, PERS_ORG_USER_FOLDER_NAME); + + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING("key to be replaced in: "), DLT_STRING(key)); + if (found ) + { + idx = found - key; + } + else + { + idx = -1; + } + + if (idx != -1) + { + idx += strlen(PERS_ORG_USER_FOLDER_NAME); + char outKeyPart1[PERS_DB_MAX_SIZE_KEY_DATA]; + char outKeyPart2[PERS_DB_MAX_SIZE_KEY_DATA]; + + char* res1 = strncpy(outKeyPart1, key, idx); + outKeyPart1[idx] = '\0'; + size_t numOfUserDigits = (src_user_no > 9 ? 2 : 1); + idx += numOfUserDigits + 2; + res1 = strncpy(outKeyPart2, key + idx, strlen(key) - idx); + int res_id_len = strlen(key) - idx; + outKeyPart2[res_id_len] = '\0'; + sprintf(updatedKey, "%s/%d/%s", outKeyPart1, dest_user_no, outKeyPart2 ); + + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING("key to be replaced out: "), DLT_STRING(updatedKey)); + return true; + } + else + { + return false; + } +} + + +static int persadmin_priv_copy_keys_by_filter_from_to_user(PersASSelectionType_e type, char* pchsourceDBPath, unsigned int src_user_no, unsigned src_seat_no, unsigned int dst_user_no, unsigned int dst_seat_no) +{ + sint_t s32Result = PAS_FAILURE ; + + bool_t bEverythingOK = true ; + pstr_t pSrcUnfilteredList = NIL ; + pstr_t pSrcListFiltered = NIL ; + sint_t iSrcListUnfilteredSize = 0 ; + sint_t iSrcListFilteredSize = 0 ; + + sint_t iHandlerSrcDB = -1 ; + sint_t iHandlerDestDB = -1 ; + + /* get a list of the keys in pchsourceDBPath */ + iHandlerSrcDB = persComDbOpen(pchsourceDBPath, false) ; + if(iHandlerSrcDB >= 0) + { + iSrcListUnfilteredSize = persComDbGetSizeKeysList(iHandlerSrcDB) ; + if(iSrcListUnfilteredSize > 0) + { + pSrcUnfilteredList = (pstr_t)malloc(iSrcListUnfilteredSize) ; + pSrcListFiltered = (pstr_t)malloc(iSrcListUnfilteredSize) ; + if((NIL != pSrcUnfilteredList) && (NIL != pSrcListFiltered)) + { + if(iSrcListUnfilteredSize != persComDbGetKeysList(iHandlerSrcDB, pSrcUnfilteredList, iSrcListUnfilteredSize)) + { + bEverythingOK = false ; + } + } + else + { + bEverythingOK = false ; + s32Result = PAS_FAILURE_OUT_OF_MEMORY ; + } + } + else + { + if(iSrcListUnfilteredSize < 0) + { + bEverythingOK = false ; + } + } + } + else + { + bEverythingOK = false ; + s32Result = iHandlerSrcDB ; + } + + if(bEverythingOK && (iSrcListUnfilteredSize > 0)) + { + iSrcListFilteredSize = persadmin_priv_filter_keys_in_list(type, src_user_no, src_seat_no, pSrcUnfilteredList, pSrcListFiltered, iSrcListUnfilteredSize) ; + } + + if(bEverythingOK && (iSrcListFilteredSize > 0)) + { + sint_t iPosInList = 0 ; + pstr_t pCurrentKeyName = NIL ; + + while(bEverythingOK && (iPosInList < iSrcListFilteredSize)) + { + pCurrentKeyName = pSrcListFiltered + iPosInList ; + + str_t keyData[PERS_DB_MAX_SIZE_KEY_DATA] ; + sint_t iDataSize = persComDbReadKey(iHandlerSrcDB, pCurrentKeyName, keyData, sizeof(keyData)) ; + + if(iDataSize >= 0) + { + char updatedKey[PERS_DB_MAX_SIZE_KEY_DATA]; + bool_t replaceSuccess = replaceUserInKey( pCurrentKeyName, src_user_no, dst_user_no, updatedKey ); + if ( replaceSuccess ) + { + sint_t iError; + iError = persComDbWriteKey(iHandlerSrcDB, updatedKey, keyData, iDataSize) ; + + if(iError < 0) + { + bEverythingOK = false ; + s32Result = iError ; + } + + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), + DLT_STRING("persadmin_priv_copy_keys_by_filter_from_to_user - persComDbWriteKey"), + DLT_STRING(updatedKey), + DLT_STRING("size = "), DLT_INT(iDataSize), + DLT_STRING((iError >= 0) ? "OK" : "FAILED")) ; + } + else + { + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), + DLT_STRING("persadmin_priv_copy_keys_by_filter_from_to_user - persComDbWriteKey"), + DLT_STRING("cannot replace user_no in key: "), + DLT_STRING(pCurrentKeyName)) ; + } + } + + + iPosInList += strlen(pCurrentKeyName) + 1 ; /* 1 <=> list items separator */ + } + } + + if(pSrcUnfilteredList != NIL) + { + free(pSrcUnfilteredList) ; + } + if(pSrcListFiltered!= NIL) + { + free(pSrcListFiltered) ; + } + + if(iHandlerSrcDB >= 0) + { + persComDbClose(iHandlerSrcDB) ; + } + /* + if(iHandlerDestDB >= 0) + { + persComDbClose(iHandlerDestDB) ; + } + */ + + return bEverythingOK ? PAS_SUCCESS : s32Result ; +} /* persadmin_priv_copy_keys_by_filter_from_to_user() */ + + +int persadmin_copy_keys_by_filter_from_to_user(PersASSelectionType_e type, char* pchsourceDBPath, unsigned int src_user_no, unsigned int src_seat_no, unsigned int dst_user_no, unsigned int dst_seat_no) +{ + sint_t s32Result = PAS_SUCCESS; + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("persadmin_copy_keys_by_filter_from_to_user") ); + if( (NIL == pchsourceDBPath) || (PersASSelectionType_All > type ) || (PersASSelectionType_LastEntry < type )) + { + // set error; + s32Result = PAS_FAILURE_INVALID_PARAMETER; + // some info; + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_ERROR, DLT_STRING(LT_HDR), DLT_STRING("persadmin_copy_keys_by_filter_from_to_user -"), + DLT_STRING("invalid input parameters")); + } + + if( PAS_SUCCESS == s32Result ) + { + // some info; + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("persadmin_copy_keys_by_filter_from_to_user "), + DLT_INT(src_user_no), DLT_INT(src_seat_no), DLT_INT(dst_user_no), DLT_INT(dst_seat_no), + DLT_STRING("from user "), + DLT_STRING("\""), DLT_INT(src_user_no), DLT_STRING("\" "), + DLT_STRING("to user"), + DLT_STRING("\""), DLT_INT(dst_user_no), DLT_STRING("\" ")); + + if( 0 <= persadmin_check_if_file_exists(pchsourceDBPath, false) ) + { + //copy data between users; + s32Result = persadmin_priv_copy_keys_by_filter_from_to_user(type, pchsourceDBPath, src_user_no, src_seat_no, dst_user_no, dst_seat_no); + } + } + return s32Result; +} /* persadmin_copy_keys_by_filter_from_to_user() */ + /** * @brief get the names of an application's databases based on the databases' type (local/shared) * @usage: diff --git a/Administrator/src/ssw_pers_admin_files_helper.c b/Administrator/src/ssw_pers_admin_files_helper.c index a8db038..88843c5 100644 --- a/Administrator/src/ssw_pers_admin_files_helper.c +++ b/Administrator/src/ssw_pers_admin_files_helper.c @@ -1643,3 +1643,57 @@ bool_t persadmin_check_for_same_file_content(pstr_t file1Path, pstr_t file2Path) return true; }/*DG C8ISQP-ISQP Metric 10-SSW_Administrator_0001*/ + + +bool_t isSymLink( const char* path ) +{ + struct stat statinfo; + lstat(path, &statinfo); + if ( S_ISLNK(statinfo.st_mode) ) + { + return true; + } + else + { + return false; + } +} + + +bool_t checkAndFixFolderPath( char* path) +{ + //folder path check + if(NIL == path) + { + (void)snprintf(g_msg, sizeof(g_msg), "checkAndFixFolderPath: invalid params") ; + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_DEBUG, DLT_STRING(LT_HDR), DLT_STRING(g_msg)); + return false ; + } + else + { + if(path[0] != '/') + { + (void)snprintf(g_msg, sizeof(g_msg), "checkAndFixFolderPath: not an absolute path (%s)", path) ; + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_DEBUG, DLT_STRING(LT_HDR), DLT_STRING(g_msg)); + return false; + } + else + { + /* make sure path ends with '/' */ + sint_t len = (sint_t)strlen(path) ; + if(len < (PERSADMIN_MAX_PATH_LENGHT-1)) /* to allow adding of ending '/' */ + { + if('/' != path[len-1]) + { + (void)strcat(path, "/") ; + } + } + else + { + (void)snprintf(g_msg, sizeof(g_msg), "checkAndFixFolderPath: path too long (%s)", path) ; + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_DEBUG, DLT_STRING(LT_HDR), DLT_STRING(g_msg)); + return false; + } + } + } +} diff --git a/Administrator/src/ssw_pers_admin_service.c b/Administrator/src/ssw_pers_admin_service.c index b4e867a..29df143 100644 --- a/Administrator/src/ssw_pers_admin_service.c +++ b/Administrator/src/ssw_pers_admin_service.c @@ -57,7 +57,7 @@ #include "ssw_pers_admin_dbus.h" #include "ssw_pers_admin_pcl.h" #include "ssw_pers_admin_service.h" - +#include "ssw_pers_admin_files_helper.h" /* ---------- local defines, macros, constants and type definitions ------------ */ @@ -110,6 +110,20 @@ static mqd_t g_mqdMsgQueueResponse = OS_INVALID_HANDLE; /* ---------------------- local functions declarations ---------------------------------- */ /** + * \brief Copies filtered values between selected users. + * + * \param type: filter type + * \param sourceAppPath: path to database file + * \param src_user_no: source user number + * \param src_seat_no: source seat number + * \param dest_user_no: destination user number + * \param dest_seat_no: destination seat number + * + * \return appropriate error code + **/ +static long persadmin_copy_keys_from_to_user( PersASSelectionType_e type, char* sourceAppPath, unsigned int src_user_no, unsigned int src_seat_no, unsigned int dest_user_no, unsigned int dest_seat_no); + +/** * \brief Access lib thread. Thread responsible to perform (on behalf of the clients) * the requests available in persistence_admin_service.h * @@ -270,6 +284,76 @@ long persadmin_resource_config_change_properties(char* resource_config_file) return (long)PAS_FAILURE_OPERATION_NOT_SUPPORTED; } +/** + * \brief Copies filtered values between selected users. + * + * \param type: filter type + * \param sourceAppPath: path to database file + * \param src_user_no: source user number + * \param src_seat_no: source seat number + * \param dest_user_no: destination user number + * \param dest_seat_no: destination seat number + * + * \return appropriate error code + **/ +static long persadmin_copy_keys_from_to_user( PersASSelectionType_e type, char* sourceAppPath, unsigned int src_user_no, unsigned int src_seat_no, unsigned int dest_user_no, unsigned int dest_seat_no) +{ + if (!checkAndFixFolderPath( sourceAppPath)) + { + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_WARN, DLT_STRING(LT_HDR), DLT_STRING("Application source path is incorrect. Path: "), DLT_STRING(sourceAppPath) ); + return PAS_FAILURE_INVALID_PARAMETER; + } + + str_t fileAbsPath[PERSADMIN_MAX_PATH_LENGHT+1]; + + sint_t iSizeOfFilesList = 0; + pstr_t pFilesList = NIL; + iSizeOfFilesList = persadmin_list_folder_get_size(sourceAppPath, PersadminFilterAll, false); + pFilesList = (pstr_t) malloc((size_t)iSizeOfFilesList * sizeof(str_t)); + persadmin_list_folder(sourceAppPath, pFilesList, iSizeOfFilesList, PersadminFilterAll, false); + + sint_t iPosInList = 0; + while(true && (iPosInList < iSizeOfFilesList)) + { + pstr_t pCurrentFileName = pFilesList + iPosInList; + sint_t iSizeOfCurrentFileName = strlen(pCurrentFileName); + iPosInList += (iSizeOfCurrentFileName + 1); // 1 <=> '\0' + (void)snprintf(fileAbsPath, sizeof(fileAbsPath), "%s%s", sourceAppPath, pCurrentFileName ); + + struct stat sb; + lstat(fileAbsPath, &sb); + if (S_ISREG(sb.st_mode)) + { + pstr_t filename[PERS_ORG_MAX_LENGTH_PATH_FILENAME]; + persadmin_get_filename(fileAbsPath, filename, sizeof(filename)); + + if ((strcmp(filename, PERS_ORG_LOCAL_CACHE_DB_NAME) == 0) || (strcmp(filename, PERS_ORG_LOCAL_WT_DB_NAME) == 0)) + { + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("Copying keys from user no: "), DLT_INT(src_user_no), DLT_STRING(" to user no: "), DLT_INT(dest_user_no), DLT_STRING(" in file: "), DLT_STRING(fileAbsPath) ); + persadmin_copy_keys_by_filter_from_to_user(PersASSelectionType_User, fileAbsPath, src_user_no, src_seat_no, dest_user_no, dest_seat_no); + } + } + else if (S_ISDIR(sb.st_mode)) + { + str_t userFolderPath[PERSADMIN_MAX_PATH_LENGHT+1]; + (void)snprintf(userFolderPath, sizeof(userFolderPath), "%s/%d", fileAbsPath, src_user_no ); + if( 0 == persadmin_check_if_file_exists(userFolderPath, true) ) + { + str_t destUserFolderPath[PERSADMIN_MAX_PATH_LENGHT+1]; + (void)snprintf(destUserFolderPath, sizeof(destUserFolderPath), "%s/%d", fileAbsPath, dest_user_no ); + persadmin_copy_folder( userFolderPath, destUserFolderPath, PersadminFilterAll, true); //to do: check ret val + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("Copying user files from "), DLT_STRING(userFolderPath), DLT_STRING(" to "),DLT_STRING(destUserFolderPath) ); + + } + else + { + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("Source user files folder path doesn't exist: "), DLT_STRING(userFolderPath) ); + } + } + } + return PAS_SUCCESS; +} + /** * \brief Allow the copy of user related data between different users @@ -283,18 +367,57 @@ long persadmin_resource_config_change_properties(char* resource_config_file) */ long persadmin_user_data_copy(unsigned int src_user_no, unsigned int src_seat_no, unsigned int dest_user_no, unsigned int dest_seat_no) { - DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_ERROR, DLT_STRING(LT_HDR); + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR); DLT_STRING("persadmin_user_data_copy("); DLT_UINT(src_user_no); DLT_UINT(src_seat_no); DLT_UINT(dest_user_no); DLT_UINT(dest_seat_no); - DLT_STRING(")")); - - DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_ERROR, DLT_STRING(LT_HDR); - DLT_STRING("persadmin_user_data_copy - NOT IMPLEMENTED")); - - return (long)PAS_FAILURE_OPERATION_NOT_SUPPORTED; + DLT_STRING(")")); + + str_t sourceRootPath[PERSADMIN_MAX_PATH_LENGHT+1]; + strcpy( sourceRootPath, PERS_ORG_LOCAL_APP_CACHE_PATH_); + + //checking source folder path + if (!checkAndFixFolderPath( sourceRootPath)) + { + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_ERROR, DLT_STRING(LT_HDR), DLT_STRING("persadmin_user_data_copy - source path is incorrect"), DLT_STRING(sourceRootPath)); + return PAS_FAILURE_INVALID_PARAMETER; + } + + str_t folderAbsPath[PERSADMIN_MAX_PATH_LENGHT+1]; + + //Get list of folders under "sourceRootPath" + sint_t iSizeOfFoldersList = 0; + pstr_t pFoldersList = NIL; + iSizeOfFoldersList = persadmin_list_folder_get_size(sourceRootPath, PersadminFilterAll, false); + pFoldersList = (pstr_t) malloc((size_t)iSizeOfFoldersList * sizeof(str_t)); + persadmin_list_folder(sourceRootPath, pFoldersList, iSizeOfFoldersList, PersadminFilterAll, false); + + sint_t iPosInList = 0; + + while(true && (iPosInList < iSizeOfFoldersList)) + { + pstr_t pCurrentFolderName = pFoldersList + iPosInList; + sint_t iSizeOfCurrentFolderPath = strlen(pCurrentFolderName); + iPosInList += (iSizeOfCurrentFolderPath + 1); /* 1 <=> '\0' */ + (void)snprintf(folderAbsPath, sizeof(folderAbsPath), "%s%s", sourceRootPath, pCurrentFolderName ); + + DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("persadmin_user_data_copy - folder path "), DLT_STRING(folderAbsPath)); + + if (strcmp(pCurrentFolderName, PERS_ORG_SHARED_FOLDER_NAME ) != 0 ) + { + persadmin_copy_keys_from_to_user(PersASSelectionType_User, folderAbsPath, src_user_no, src_seat_no, dest_user_no, dest_seat_no); + } + else + { + str_t sharedPublicSrcAbsPath[PERSADMIN_MAX_PATH_LENGHT+1]; + (void)snprintf(sharedPublicSrcAbsPath, sizeof(sharedPublicSrcAbsPath), "%s/%s", folderAbsPath, PERS_ORG_PUBLIC_FOLDER_NAME ); + persadmin_copy_keys_from_to_user(PersASSelectionType_User, sharedPublicSrcAbsPath, src_user_no, src_seat_no, dest_user_no, dest_seat_no); + } + + } + return PAS_SUCCESS; } diff --git a/test/persadmin_tool/src/persadmin_tool.c b/test/persadmin_tool/src/persadmin_tool.c index 97288a0..9c923ae 100644 --- a/test/persadmin_tool/src/persadmin_tool.c +++ b/test/persadmin_tool/src/persadmin_tool.c @@ -34,6 +34,7 @@ typedef enum _pastool_commands_e PASTOOL_CMD_RECOVERY, PASTOOL_CMD_IMPORT, PASTOOL_CMD_RESTORE, + PASTOOL_CMD_COPY_USER_DATA, PASTOOL_CMD_SHOW_HELP, /* add new entries here */ PASTOOL_CMD_LAST_ENTRY @@ -64,6 +65,7 @@ static const pastool_command_name_s a_sCommandNames[] = {PASTOOL_CMD_RECOVERY, 7, "recovery"}, {PASTOOL_CMD_IMPORT, 4, "import"}, {PASTOOL_CMD_RESTORE, 7, "restore"}, + {PASTOOL_CMD_COPY_USER_DATA,7, "copy_user_data"}, {PASTOOL_CMD_SHOW_HELP, 2, "help"}, {PASTOOL_CMD_SHOW_HELP, 2, "-help"}, {PASTOOL_CMD_SHOW_HELP, 2, "-h"}, @@ -205,12 +207,15 @@ static void pastool_printHelp(void) DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("-----------------------------------------------------------------------------------------")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("| help | mandatory | mandatory | na | na | na |")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("-----------------------------------------------------------------------------------------")); + DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("|copy_user_data| empty | 1 | empty | mandatory | mandatory |")); + DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("-----------------------------------------------------------------------------------------")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("path meaning:")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" for install : abs pathname to input installation file (.tar.gz)")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" for backup : abs pathname to output backup file (.tar.gz)")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" for recovery : abs pathname to input backup file (.tar.gz)")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" for export : abs path to destination folder")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" for import : abs path to source folder")); + DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" for copy_user_data : copy user data from X to Y - only 2 last params relevant")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" for restore : choose one of: FactoryDefault or ConfigDefault")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("selection type meaning:")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" <<0>> : select all data/files: (node+user)->(application+shared)")); @@ -225,6 +230,7 @@ static void pastool_printHelp(void) DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" /usr/bin/persadmin_tool backup /tmp/backup 2 MyApp 2 -1")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" /usr/bin/persadmin_tool export /tmp/export 0")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" /usr/bin/persadmin_tool restore FactoryDefault 2 MyApp -1 -1")); + DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(" /usr/bin/persadmin_tool copy_user_data '' 1 '' 1 2")); DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING("==========================================================================================")); } @@ -345,26 +351,38 @@ static bool_t pastool_executeCommand(pastool_input_s* psArguments) { bEverythingOK = false ; } - break ; + break; } case PASTOOL_CMD_RESTORE: + { + PersASDefaultSource_e defaultSource = PersASDefaultSource_Configurable; + if(0 == strcmp(psArguments->path, "ConfigDefault")) + { + defaultSource = PersASDefaultSource_Configurable; + } + result = persAdminDataRestore(psArguments->eSelectionType, defaultSource, psArguments->appName, psArguments->user_no, psArguments->seat_no); + snprintf(g_msg, sizeof(g_msg), "persAdminDataRestore(<<%d>>, <<%s>>, <<%s>>, <<%d>>, <<%d>>) returned <<%ld>>", + psArguments->eSelectionType, (PersASDefaultSource_Configurable==defaultSource)?"ConfigDefault":"FactoryDefault", + psArguments->appName, psArguments->user_no, psArguments->seat_no, result) ; + DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(g_msg)); + if(result < 0) + { + bEverythingOK = false ; + } + break; + } + case PASTOOL_CMD_COPY_USER_DATA: + { + result = persAdminUserDataCopy(psArguments->user_no, -1, psArguments->seat_no, -1); + snprintf(g_msg, sizeof(g_msg), "persAdminUserDataCopy(<<%d>>, <<%d>> ) returned <<%ld>>", + psArguments->user_no, psArguments->seat_no, result) ; + DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(g_msg)); + if(result < 0) { - PersASDefaultSource_e defaultSource = PersASDefaultSource_Configurable; - if(0 == strcmp(psArguments->path, "ConfigDefault")) - { - defaultSource = PersASDefaultSource_Configurable; - } - result = persAdminDataRestore(psArguments->eSelectionType, defaultSource, psArguments->appName, psArguments->user_no, psArguments->seat_no); - snprintf(g_msg, sizeof(g_msg), "persAdminDataRestore(<<%d>>, <<%s>>, <<%s>>, <<%d>>, <<%d>>) returned <<%ld>>", - psArguments->eSelectionType, (PersASDefaultSource_Configurable==defaultSource)?"ConfigDefault":"FactoryDefault", - psArguments->appName, psArguments->user_no, psArguments->seat_no, result) ; - DLT_LOG(persadminToolDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), DLT_STRING(g_msg)); - if(result < 0) - { - bEverythingOK = false ; - } - break ; + bEverythingOK = false ; } + break; + } default: { /* not possible, but just to be sure */ -- 2.5.0