#include <app_manager.h>
#include <types_internal.h>
#include "DBusServer.h"
-#include "access_control/peer_creds.h"
+#include "access_control/PeerCreds.h"
#include "ClientRequest.h"
ctx::ClientRequest::ClientRequest(int type, int reqId, const char *subj, const char *desc,
- ctx::credentials *creds, const char *sender, GDBusMethodInvocation *inv) :
+ ctx::Credentials *creds, const char *sender, GDBusMethodInvocation *inv) :
RequestInfo(type, reqId, subj, desc),
__credentials(creds),
__dbusSender(sender),
delete __credentials;
}
-const ctx::credentials* ctx::ClientRequest::getCredentials()
+const ctx::Credentials* ctx::ClientRequest::getCredentials()
{
return __credentials;
}
const char* ctx::ClientRequest::getPackageId()
{
if (__credentials)
- return __credentials->package_id;
+ return __credentials->packageId;
return NULL;
}
class ClientRequest : public RequestInfo {
public:
ClientRequest(int type, int reqId, const char *subj, const char *desc,
- credentials *creds, const char *sender, GDBusMethodInvocation *inv);
+ Credentials *creds, const char *sender, GDBusMethodInvocation *inv);
~ClientRequest();
- const credentials* getCredentials();
+ const Credentials* getCredentials();
const char* getPackageId();
const char* getClient();
bool reply(int error);
bool publish(int error, ctx::Json &data);
private:
- credentials *__credentials;
+ Credentials *__credentials;
std::string __dbusSender;
GDBusMethodInvocation *__invocation;
};
#include <types_internal.h>
#include "server.h"
#include "ClientRequest.h"
-#include "access_control/peer_creds.h"
+#include "access_control/PeerCreds.h"
#include "DBusServer.h"
using namespace ctx;
_I("[%d] ReqId: %d, Subject: %s", reqType, reqId, subject);
_SI("Input: %s", input);
- credentials *creds = NULL;
+ Credentials *creds = NULL;
if (!peer_creds::get(__connection, sender, &creds)) {
_E("Peer credentialing failed");
return _reqId;
}
-const ctx::credentials* ctx::RequestInfo::getCredentials()
+const ctx::Credentials* ctx::RequestInfo::getCredentials()
{
return NULL;
}
namespace ctx {
/* Forward declaration */
- class credentials;
+ class Credentials;
class RequestInfo {
public:
const char* getSubject();
ctx::Json& getDescription();
- virtual const credentials* getCredentials();
+ virtual const Credentials* getCredentials();
virtual const char* getPackageId();
/* TODO: remove this getClient() */
virtual const char* getClient();
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cynara-creds-gdbus.h>
+#include <cynara-session.h>
+#include <app_manager.h>
+#include <package_manager.h>
+#include <types_internal.h>
+#include "PeerCreds.h"
+
+ctx::Credentials::Credentials(char *_packageId, char *_client, char *_session, char *_user) :
+ packageId(_packageId),
+ client(_client),
+ session(_session),
+ user(_user)
+{
+}
+
+ctx::Credentials::~Credentials()
+{
+ g_free(packageId);
+ g_free(client);
+ g_free(session);
+ g_free(user);
+}
+
+bool ctx::peer_creds::get(GDBusConnection *connection, const char *uniqueName, ctx::Credentials **creds)
+{
+ pid_t pid = 0;
+ char *app_id = NULL;
+ char *packageId = NULL;
+ gchar *client = NULL;
+ char *session = NULL;
+ gchar *user = NULL;
+ int err;
+
+ err = cynara_creds_gdbus_get_pid(connection, uniqueName, &pid);
+ IF_FAIL_RETURN_TAG(err == CYNARA_API_SUCCESS, false, _E, "Peer credentialing failed");
+
+ app_manager_get_app_id(pid, &app_id);
+ package_manager_get_package_id_by_app_id(app_id, &packageId);
+ _D("AppId: %s, PackageId: %s", app_id, packageId);
+
+ err = cynara_creds_gdbus_get_client(connection, uniqueName, CLIENT_METHOD_DEFAULT, &client);
+ IF_FAIL_CATCH_TAG(err == CYNARA_API_SUCCESS, _E, "Peer credentialing failed");
+
+ session = cynara_session_from_pid(pid);
+ IF_FAIL_CATCH_TAG(session, _E, "Peer credentialing failed");
+
+ err = cynara_creds_gdbus_get_user(connection, uniqueName, USER_METHOD_DEFAULT, &user);
+ IF_FAIL_CATCH_TAG(err == CYNARA_API_SUCCESS, _E, "Peer credentialing failed");
+
+ *creds = new(std::nothrow) Credentials(packageId, client, session, user);
+ IF_FAIL_CATCH_TAG(*creds, _E, "Memory allocation failed");
+
+ return true;
+
+CATCH:
+ g_free(app_id);
+ g_free(packageId);
+ g_free(client);
+ g_free(session);
+ g_free(user);
+ return false;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTEXT_PEER_CREDENTIALS_H_
+#define _CONTEXT_PEER_CREDENTIALS_H_
+
+#include <sys/types.h>
+#include <gio/gio.h>
+#include <string>
+
+namespace ctx {
+
+ class Credentials {
+ public:
+ char *packageId;
+ char *client; /* default: smack label */
+ char *session;
+ char *user; /* default: UID */
+ Credentials(char *_packageId, char *_client, char *_session, char *_user);
+ ~Credentials();
+ };
+
+ namespace peer_creds {
+
+ bool get(GDBusConnection *connection, const char *uniqueName, Credentials **creds);
+
+ } /* namespace peer_creds */
+} /* namespace ctx */
+
+#endif /* End of _CONTEXT_PEER_CREDENTIALS_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string>
+#include <cynara-client.h>
+#include <types_internal.h>
+#include "PeerCreds.h"
+#include "Privilege.h"
+
+class PermissionChecker {
+private:
+ cynara *__cynara;
+
+ PermissionChecker()
+ {
+ if (cynara_initialize(&__cynara, NULL) != CYNARA_API_SUCCESS) {
+ _E("Cynara initialization failed");
+ __cynara = NULL;
+ return;
+ }
+ _I("Cynara initialized");
+ }
+
+ ~PermissionChecker()
+ {
+ if (__cynara)
+ cynara_finish(__cynara);
+
+ _I("Cynara deinitialized");
+ }
+
+public:
+ static PermissionChecker& getInstance()
+ {
+ static PermissionChecker instance;
+ return instance;
+ }
+
+ bool hasPermission(const ctx::Credentials *creds, const char *privilege)
+ {
+ IF_FAIL_RETURN_TAG(__cynara, false, _E, "Cynara not initialized");
+ int ret = cynara_check(__cynara, creds->client, creds->session, creds->user, privilege);
+ return (ret == CYNARA_API_ACCESS_ALLOWED);
+ }
+};
+
+bool ctx::privilege_manager::isAllowed(const ctx::Credentials *creds, const char *privilege)
+{
+ IF_FAIL_RETURN(creds && privilege, true);
+
+ std::string priv = "http://tizen.org/privilege/";
+ priv += privilege;
+
+ return PermissionChecker::getInstance().hasPermission(creds, priv.c_str());
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTEXT_PRIVILEGE_MANAGER_H_
+#define _CONTEXT_PRIVILEGE_MANAGER_H_
+
+#include <string>
+
+#define PRIV_ALARM_SET "alarm.set"
+
+namespace ctx {
+
+ /* Forward declaration */
+ class Credentials;
+
+ namespace privilege_manager {
+
+ bool isAllowed(const Credentials *creds, const char *privilege);
+
+ } /* namespace privilege_manager */
+} /* namespace ctx */
+
+#endif /* End of _CONTEXT_PRIVILEGE_MANAGER_H_ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <cynara-creds-gdbus.h>
-#include <cynara-session.h>
-#include <app_manager.h>
-#include <package_manager.h>
-#include <types_internal.h>
-#include "peer_creds.h"
-
-ctx::credentials::credentials(char *_package_id, char *_client, char *_session, char *_user) :
- package_id(_package_id),
- client(_client),
- session(_session),
- user(_user)
-{
-}
-
-ctx::credentials::~credentials()
-{
- g_free(package_id);
- g_free(client);
- g_free(session);
- g_free(user);
-}
-
-bool ctx::peer_creds::get(GDBusConnection *connection, const char *unique_name, ctx::credentials **creds)
-{
- pid_t pid = 0;
- char *app_id = NULL;
- char *package_id = NULL;
- gchar *client = NULL;
- char *session = NULL;
- gchar *user = NULL;
- int err;
-
- err = cynara_creds_gdbus_get_pid(connection, unique_name, &pid);
- IF_FAIL_RETURN_TAG(err == CYNARA_API_SUCCESS, false, _E, "Peer credentialing failed");
-
- app_manager_get_app_id(pid, &app_id);
- package_manager_get_package_id_by_app_id(app_id, &package_id);
- _D("AppId: %s, PackageId: %s", app_id, package_id);
-
- err = cynara_creds_gdbus_get_client(connection, unique_name, CLIENT_METHOD_DEFAULT, &client);
- IF_FAIL_CATCH_TAG(err == CYNARA_API_SUCCESS, _E, "Peer credentialing failed");
-
- session = cynara_session_from_pid(pid);
- IF_FAIL_CATCH_TAG(session, _E, "Peer credentialing failed");
-
- err = cynara_creds_gdbus_get_user(connection, unique_name, USER_METHOD_DEFAULT, &user);
- IF_FAIL_CATCH_TAG(err == CYNARA_API_SUCCESS, _E, "Peer credentialing failed");
-
- *creds = new(std::nothrow) credentials(package_id, client, session, user);
- IF_FAIL_CATCH_TAG(*creds, _E, "Memory allocation failed");
-
- return true;
-
-CATCH:
- g_free(app_id);
- g_free(package_id);
- g_free(client);
- g_free(session);
- g_free(user);
- return false;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __CONTEXT_PEER_CREDENTIALS_H__
-#define __CONTEXT_PEER_CREDENTIALS_H__
-
-#include <sys/types.h>
-#include <gio/gio.h>
-#include <string>
-
-namespace ctx {
-
- class credentials {
- public:
- char *package_id;
- char *client; /* default: smack label */
- char *session;
- char *user; /* default: UID */
- credentials(char *_package_id, char *_client, char *_session, char *_user);
- ~credentials();
- };
-
- namespace peer_creds {
- bool get(GDBusConnection *connection, const char *unique_name, credentials **creds);
- }
-} /* namespace ctx */
-
-#endif /* End of __CONTEXT_PEER_CREDENTIALS_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string>
-#include <cynara-client.h>
-#include <types_internal.h>
-#include "peer_creds.h"
-#include "privilege.h"
-
-class permission_checker {
-private:
- cynara *__cynara;
-
- permission_checker()
- {
- if (cynara_initialize(&__cynara, NULL) != CYNARA_API_SUCCESS) {
- _E("Cynara initialization failed");
- __cynara = NULL;
- return;
- }
- _I("Cynara initialized");
- }
-
- ~permission_checker()
- {
- if (__cynara)
- cynara_finish(__cynara);
-
- _I("Cynara deinitialized");
- }
-
-public:
- static permission_checker& get_instance()
- {
- static permission_checker instance;
- return instance;
- }
-
- bool has_permission(const ctx::credentials *creds, const char *privilege)
- {
- IF_FAIL_RETURN_TAG(__cynara, false, _E, "Cynara not initialized");
- int ret = cynara_check(__cynara, creds->client, creds->session, creds->user, privilege);
- return (ret == CYNARA_API_ACCESS_ALLOWED);
- }
-};
-
-bool ctx::privilege_manager::is_allowed(const ctx::credentials *creds, const char *privilege)
-{
- IF_FAIL_RETURN(creds && privilege, true);
-
- std::string priv = "http://tizen.org/privilege/";
- priv += privilege;
-
- return permission_checker::get_instance().has_permission(creds, priv.c_str());
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __CONTEXT_PRIVILEGE_MANAGER_H__
-#define __CONTEXT_PRIVILEGE_MANAGER_H__
-
-#include <string>
-
-#define PRIV_ALARM_SET "alarm.set"
-
-namespace ctx {
-
- /* Forward declaration */
- class credentials;
-
- namespace privilege_manager {
-
- bool is_allowed(const credentials *creds, const char *privilege);
-
- } /* namespace ctx::privilege_manager */
-} /* namespace ctx */
-
-#endif /* End of __CONTEXT_PRIVILEGE_MANAGER_H__ */
#include <Json.h>
#include <provider_iface.h>
#include "server.h"
-#include "access_control/privilege.h"
+#include "access_control/Privilege.h"
#include "Request.h"
#include "provider.h"
#include "context_mgr_impl.h"
return (it != provider_handle_map.end());
}
-bool ctx::context_manager_impl::is_allowed(const ctx::credentials *creds, const char *subject)
+bool ctx::context_manager_impl::is_allowed(const ctx::Credentials *creds, const char *subject)
{
IF_FAIL_RETURN(creds, true); /* In case internal requests */
auto it = provider_handle_map.find(subject);
namespace ctx {
/* Forward declaration */
- class credentials;
+ class Credentials;
class RequestInfo;
class context_provider_handler;
void assign_request(ctx::RequestInfo *request);
bool is_supported(const char *subject);
- bool is_allowed(const credentials *creds, const char *subject);
+ bool is_allowed(const Credentials *creds, const char *subject);
bool pop_trigger_item(std::string &subject, int &operation, ctx::Json &attributes, ctx::Json &options, std::string &owner, bool& unregister);
/* From the interface class */
#include <glib.h>
#include <types_internal.h>
#include <Json.h>
-#include "access_control/privilege.h"
+#include "access_control/Privilege.h"
#include "server.h"
#include "Request.h"
#include "provider.h"
provider_info.destroy(provider_info.data);
}
-bool ctx::context_provider_handler::is_allowed(const ctx::credentials *creds)
+bool ctx::context_provider_handler::is_allowed(const ctx::Credentials *creds)
{
IF_FAIL_RETURN(creds, true); /* In case of internal requests */
- return privilege_manager::is_allowed(creds, provider_info.privilege);
+ return privilege_manager::isAllowed(creds, provider_info.privilege);
}
ctx::context_provider_iface* ctx::context_provider_handler::get_provider(ctx::RequestInfo *request)
namespace ctx {
class Json;
- class credentials;
+ class Credentials;
class RequestInfo;
class context_provider_handler {
context_provider_handler(const char *subj, context_provider_info &prvd);
~context_provider_handler();
- bool is_allowed(const credentials *creds);
+ bool is_allowed(const Credentials *creds);
void subscribe(RequestInfo *request);
void unsubscribe(RequestInfo *request);
*/
#include <types_internal.h>
-#include "../access_control/privilege.h"
+#include "../access_control/Privilege.h"
#include "../context_mgr_impl.h"
#include "ContextMonitor.h"
#include "IContextListener.h"