- Change raw pointers to smart pointers
Change-Id: Ia81462b077d447763a73cd9584ad160b0c411170
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
namespace rpc_port {
namespace internal {
namespace rpc_port {
namespace internal {
-AccessController::~AccessController() {}
-
void AccessController::AddPrivilege(std::string privilege) {
privileges_.push_back(std::move(privilege));
}
void AccessController::AddPrivilege(std::string privilege) {
privileges_.push_back(std::move(privilege));
}
-AccessController::Cynara::Cynara() {
- cynara_ = nullptr;
- client_ = nullptr;
- user_ = nullptr;
+AccessController::Cynara::Cynara()
+ : cynara_(nullptr, cynara_finish), client_(nullptr, std::free),
+ user_(nullptr, std::free) {
+ cynara* cynara_inst = nullptr;
- if (cynara_initialize(&cynara_, NULL) != CYNARA_API_SUCCESS) {
+ if (cynara_initialize(&cynara_inst, NULL) != CYNARA_API_SUCCESS) {
LOGE("cynara_initialize() is failed");
LOGE("cynara_initialize() is failed");
+ } else {
+ cynara_.reset(cynara_inst);
-AccessController::Cynara::~Cynara() {
- if (client_)
- free(client_);
- if (user_)
- free(user_);
- if (cynara_)
- cynara_finish(cynara_);
-}
-
int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection,
const char* sender) {
int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection,
const char* sender) {
- int ret;
-
- if (client_) {
- free(client_);
- client_ = nullptr;
- }
-
- if (user_) {
- free(user_);
- user_ = nullptr;
- }
-
- ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT,
- &user_);
+ char* user = nullptr;
+ int ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT,
+ &user);
if (ret != CYNARA_API_SUCCESS) {
LOGE("cynara_creds_gdbus_get_user() is failed : %d", ret);
return -1;
}
if (ret != CYNARA_API_SUCCESS) {
LOGE("cynara_creds_gdbus_get_user() is failed : %d", ret);
return -1;
}
+ char* client = nullptr;
ret = cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT,
ret = cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT,
if (ret != CYNARA_API_SUCCESS) {
LOGE("cynara_creds_gdbus_get_client() is failed : %d", ret);
return -1;
}
if (ret != CYNARA_API_SUCCESS) {
LOGE("cynara_creds_gdbus_get_client() is failed : %d", ret);
return -1;
}
- LOGD("cred client : %s, cred user : %s", client_, user_);
+ LOGD("cred client : %s, cred user : %s", client_.get(), user_.get());
return 0;
}
int AccessController::Cynara::Check(const std::string& privilege) const {
LOGD("check privilege %s", privilege.c_str());
return 0;
}
int AccessController::Cynara::Check(const std::string& privilege) const {
LOGD("check privilege %s", privilege.c_str());
- if (cynara_check(cynara_, client_, "", user_, privilege.c_str()) !=
- CYNARA_API_ACCESS_ALLOWED) {
+ if (cynara_check(cynara_.get(), client_.get(), "", user_.get(),
+ privilege.c_str()) != CYNARA_API_ACCESS_ALLOWED) {
LOGE("cynara_check() is not allowed : %s", privilege.c_str());
return -1;
}
LOGE("cynara_check() is not allowed : %s", privilege.c_str());
return -1;
}
#include <string>
#include <vector>
#include <map>
#include <string>
#include <vector>
#include <map>
namespace rpc_port {
namespace internal {
namespace rpc_port {
namespace internal {
class AccessController {
public:
explicit AccessController(bool trusted = false) : trusted_(trusted) {}
class AccessController {
public:
explicit AccessController(bool trusted = false) : trusted_(trusted) {}
- virtual ~AccessController();
void AddPrivilege(std::string privilege);
void SetTrusted(const bool trusted);
void AddPrivilege(std::string privilege);
void SetTrusted(const bool trusted);
class Cynara {
public:
Cynara();
class Cynara {
public:
Cynara();
int FetchCredsFromDBus(GDBusConnection *connection, const char *sender);
int Check(const std::string& privilege) const;
private:
int FetchCredsFromDBus(GDBusConnection *connection, const char *sender);
int Check(const std::string& privilege) const;
private:
- cynara *cynara_;
- char *client_;
- char *user_;
+ std::unique_ptr<cynara, decltype(cynara_finish)*> cynara_;
+ std::unique_ptr<char, decltype(std::free)*> client_;
+ std::unique_ptr<char, decltype(std::free)*> user_;
};
int SetCache(const std::string& sender);
};
int SetCache(const std::string& sender);