/*
- * Copyright (c) 2014-2019 Samsung Electronics Co., Ltd. All rights reserved
+ * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd. All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
RawBuffer CKMLogic::removeUserData(uid_t user)
{
- int retCode = CKM_API_SUCCESS;
-
if (m_accessControl.isSystemService(user))
user = SYSTEM_DB_UID;
m_userDataMap.erase(user);
- FileSystem fs(user);
- fs.removeUserData();
+ const int retCode = FileSystem(user).removeUserData()
+ ? CKM_API_ERROR_FILE_SYSTEM
+ : CKM_API_SUCCESS;
return MessageBuffer::Serialize(retCode).Pop();
}
int FileSystem::removeUserData() const
{
- int err, retCode = 0;
-
- if (unlink(getDBPath().c_str())) {
- retCode = -1;
- err = errno;
- LogDebug("Error in unlink user database: " << getDBPath()
- << "Errno: " << errno << " " << GetErrnoString(err));
- }
-
- if (unlink(getDKEKPath().c_str())) {
- retCode = -1;
- err = errno;
- LogDebug("Error in unlink user DKEK: " << getDKEKPath()
- << "Errno: " << errno << " " << GetErrnoString(err));
- }
-
- if (unlink(getDBDEKPath().c_str())) {
- retCode = -1;
- err = errno;
- LogDebug("Error in unlink user DBDEK: " << getDBDEKPath()
- << "Errno: " << errno << " " << GetErrnoString(err));
- }
-
- if (unlink(getRemovedAppsPath().c_str())) {
- retCode = -1;
- err = errno;
- LogDebug("Error in unlink user's Removed Apps File: " << getRemovedAppsPath()
- << "Errno: " << errno << " " << GetErrnoString(err));
- }
-
- return retCode;
+ const auto unlinkUserPath = [](const std::string &path, const char *logDesc) {
+ if (!unlink(path.c_str()))
+ return 0;
+ const auto err = errno;
+ if (ENOENT == err)
+ return 0;
+ LogDebug("Error in unlink user" << logDesc << ": " << path
+ << "Errno: " << err << " " << GetErrnoString(err));
+ return -1;
+ };
+
+ return unlinkUserPath(getDBPath(), " database")
+ | unlinkUserPath(getDKEKPath(), " DKEK")
+ | unlinkUserPath(getDBDEKPath(), " DBDEK")
+ | unlinkUserPath(getRemovedAppsPath(), "'s Removed Apps File");
}
FileLock FileSystem::lock()
/*
- * Copyright (c) 2000-2019 Samsung Electronics Co., Ltd. All rights reserved
+ * Copyright (c) 2000-2020 Samsung Electronics Co., Ltd. All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <string>
#include <file-lock.h>
+#define wur __attribute__((warn_unused_result))
+
namespace CKM {
typedef std::vector<ClientId> ClientIdVector;
typedef std::vector<uid_t> UidVector;
-class FileSystem {
+class FileSystem final {
public:
explicit FileSystem(uid_t uid);
- std::string getDBPath() const;
+ wur std::string getDBPath() const;
// Domain Key Encryption Key
- RawBuffer getDKEK() const;
+ wur RawBuffer getDKEK() const;
void saveDKEK(const RawBuffer &buffer) const;
// Database Data Encryption Key
- RawBuffer getDBDEK() const;
+ wur RawBuffer getDBDEK() const;
void saveDBDEK(const RawBuffer &buffer) const;
// Remove all ckm data related to user
- int removeUserData() const;
+ wur int removeUserData() const;
void addRemovedApp(const ClientId &app) const;
- ClientIdVector clearRemovedsApps() const;
-
- static int init();
- static UidVector getUIDsFromDBFile();
- static FileLock lock();
+ wur ClientIdVector clearRemovedsApps() const;
- virtual ~FileSystem() {}
+ wur static int init();
+ wur static UidVector getUIDsFromDBFile();
+ wur static FileLock lock();
-protected:
- std::string getDKEKPath() const;
- std::string getDBDEKPath() const;
- RawBuffer loadFile(const std::string &path) const;
+private:
+ wur std::string getDKEKPath() const;
+ wur std::string getDBDEKPath() const;
+ wur RawBuffer loadFile(const std::string &path) const;
void saveFile(const std::string &path, const RawBuffer &buffer) const;
- std::string getRemovedAppsPath() const;
+ wur std::string getRemovedAppsPath() const;
uid_t m_uid;
};