#include <pkgmgr_installer_info.h>
#include <sys/smack.h>
#include <sys/prctl.h>
-#include <openssl/sha.h>
+
+#include <openssl/evp.h>
+#include <openssl/crypto.h>
+
#include <mntent.h>
#include <cstdlib>
bool isManagedAssembly(const std::string& fileName)
{
- return (iCompare(fileName, fileName.size()-4, ".dll", 0, 4) ||
- iCompare(fileName, fileName.size()-4, ".exe", 0, 4)) &&
- !isNativeImage(fileName);
+ return iCompare(fileName, fileName.size()-4, ".dll", 0, 4) && !isNativeImage(fileName);
}
bool isNativeImage(const std::string& fileName)
return lstat(path.c_str(), &sb) == 0;
}
-bool isDirectory(const std::string& path)
+bool isSymlinkFile(const std::string& path)
{
struct stat sb;
- if (stat(path.c_str(), &sb) != 0) {
+ if (lstat(path.c_str(), &sb) != 0) {
return false;
}
- if (sb.st_mode & S_IFDIR) {
- return true;
- } else {
+ return (sb.st_mode & S_IFMT) == S_IFLNK;
+}
+
+bool isDirectory(const std::string& path)
+{
+ struct stat sb;
+ if (stat(path.c_str(), &sb) != 0) {
return false;
}
+ return (sb.st_mode & S_IFMT) == S_IFDIR;
}
std::string getAssemblyNameFromPath(const std::string& path)
free(label);
}
- // change owner and groups for symbolic link.
+ // change owner and groupsfor symbolic link.
+ // change mode is skipped for symlink because permission of symlink file is meaningless.
if (!lstat(fromPath.c_str(), &info)) {
if (lchown(toPath.c_str(), info.st_uid, info.st_gid) == -1)
_SERR("Failed to change owner and group name");
free(label);
}
- // change owner and groups for generated ni file.
+ // change owner, groups and mode for generated ni file.
if (!stat(fromPath.c_str(), &info)) {
if (chown(toPath.c_str(), info.st_uid, info.st_gid) == -1)
_SERR("Failed to change owner and group name");
+ if (chmod(toPath.c_str(), info.st_mode) == -1)
+ _SERR("Failed to change mode");
}
}
}
_ERR("Failed to copy ownership and permissions from %s to %s", path.c_str(), path2.c_str());
return false;
}
- bf::perms permissions = bf::status(path).permissions();
+ bs::error_code error;
+ bf::perms permissions = bf::status(path, error).permissions();
+ if (error) {
+ _ERR("Failed to copy ownership and permissions : %s", error.message().c_str());
+ return false;
+ }
struct stat stats;
if (stat(path.c_str(), &stats) != 0) {
return false;
}
// Iterate through the source directory
- for (bf::directory_iterator file(path1); file != bf::directory_iterator(); ++file) {
- try {
+ try {
+ for (bf::directory_iterator file(path1); file != bf::directory_iterator(); ++file) {
bf::path current(file->path());
bf::path target = path2 / current.filename();
- if (bf::is_symlink(symlink_status(current))) {
+ if (bf::is_symlink(bf::symlink_status(current))) {
if ((flags & (FS_MERGE_SKIP | FS_MERGE_OVERWRITE)) && exist(target)) {
continue;
}
bf::rename(destination, target);
}
}
- } catch (const bf::filesystem_error& error) {
- _ERR("Failed to copy directory: %s", error.what());
- return false;
}
+ } catch (const bf::filesystem_error& error) {
+ _ERR("Failed to copy directory: %s", error.what());
+ return false;
}
+
return true;
}
std::string SHA256(const std::string& path)
{
+ int bytesRead = 0;
+ const int bufSize = 32768;
+
+ unsigned int digest_len = 0;
+ unsigned char* digest = NULL;
+
+ std::stringstream ss;
+ EVP_MD_CTX *mdctx = NULL;
std::string output = "";
+
FILE *file = fopen(path.c_str(), "rb");
if (!file) {
return output;
}
- unsigned char hash[SHA256_DIGEST_LENGTH];
- SHA256_CTX sha256;
- SHA256_Init(&sha256);
- int bytesRead = 0;
- const int bufSize = 32768;
char *buffer = (char*)malloc(bufSize);
if (!buffer) {
- fclose(file);
- return output;
+ goto cleanup4;
+ }
+
+ mdctx = EVP_MD_CTX_new();
+ if (mdctx == NULL) {
+ _ERR("Message Digest Context creation NULL");
+ goto cleanup3;
+ }
+
+ digest = (unsigned char*)OPENSSL_malloc(EVP_MD_size(EVP_sha256()));
+ if (!digest) {
+ _ERR("Memory Allocation for SHA256 failed");
+ goto cleanup2;
+ }
+
+ if (!EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL)) {
+ _ERR("Message Digest init failed");
+ goto cleanup1;
}
while ((bytesRead = fread(buffer, 1, bufSize, file))) {
- SHA256_Update(&sha256, buffer, bytesRead);
+ if (!EVP_DigestUpdate(mdctx, buffer, bytesRead)) {
+ _ERR("Message Digest update failed");
+ goto cleanup1;
+ }
}
- SHA256_Final(hash, &sha256);
- std::stringstream ss;
- for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
- ss << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i];
+ if (!EVP_DigestFinal_ex(mdctx, digest, &digest_len)) {
+ _ERR("Message Digest Finalization falied");
+ goto cleanup1;
+ }
+
+ for (unsigned int i = 0; i < digest_len; i++) {
+ ss << std::hex << std::setw(2) << std::setfill('0') << (int)digest[i];
}
output = ss.str();
- fclose(file);
+cleanup1:
+ EVP_MD_CTX_free(mdctx);
+cleanup2:
+ OPENSSL_free(digest);
+cleanup3:
free(buffer);
+cleanup4:
+ fclose(file);
return output;
}
}
int pkgmgrMDFilterForeach(pkgmgrinfo_appinfo_metadata_filter_h handle,
- pkgmgrinfo_app_list_cb app_cb,
- void *user_data)
+ pkgmgrinfo_app_list_cb app_cb,
+ void *user_data)
{
uid_t uid = 0;
int ret = 0;
return 0;
}
+void printHWClockLog(const char* format, ...)
+{
+ char buf[1024] = {0,};
+ va_list ap;
+
+ va_start(ap, format);
+ vsnprintf(buf, sizeof(buf), format, ap);
+ va_end(ap);
+
+ prctl(PR_TASK_PERF_USER_TRACE, buf, strlen(buf));
+}
+
+const char* getNCDBStartupHook()
+{
+ return "/home/owner/share/tmp/sdk_tools/netcoredbg/ncdbhook.dll";
+}
+
+bool isNCDBStartupHookProvided()
+{
+ char *env = nullptr;
+ env = getenv("DOTNET_STARTUP_HOOKS");
+ if (env == nullptr)
+ return false;
+
+ // Note, `DOTNET_STARTUP_HOOKS` env could provide list of dlls with ':' delimiter,
+ // for example: "/path1/name1.dll:/path2/name2.dll"
+ while (*env != '\0')
+ {
+ const char *ncdbCur = getNCDBStartupHook();
+ while (*ncdbCur != '\0' && *env != '\0' && *env != ':')
+ {
+ if (*ncdbCur != *env)
+ break;
+
+ ncdbCur++;
+ env++;
+
+ if (*ncdbCur == '\0' && (*env == '\0' || *env == ':'))
+ return true;
+ }
+ while (*env != '\0' && *env != ':')
+ {
+ env++;
+ }
+ if (*env == ':')
+ env++;
+ }
+
+ return false;
+}