const std::string& getBusName() const;
- Credential* getCredential();
-
- ServiceBase* getHostService();
-
// If the GVariant 'param' is floating, it is consumed.
void publish(const std::string& signalName, GVariant* param);
+ ServiceBase& getHostService();
+
+ bool isVerified();
+
+ bool hasPrivilege(const char* privil) const;
+
+ uid_t getUid() const;
+
+ std::string getClientId() const;
+
+ bool isSystem() const;
+
+ static bool isSystemUid(uid_t uid);
+
protected:
ClientBase(ServiceBase* hostService, const std::string& busName);
private:
+ bool __getCredential();
+
ServiceBase* __hostService;
std::string __busName;
Credential* __credential;
#define HANDLE_GERROR(Err) \
do { if ((Err)) { _E("GError: %s", Err->message); g_error_free(Err); Err = NULL; } } while (0)
+#define EMPTY_STR ""
+
#endif /* __CONTEXT_TYPES_H__ */
MethodCall(ClientBase* client, const std::string& methodName, GVariant* param, GDBusMethodInvocation* invocation);
~MethodCall();
- ClientBase* getSender();
const std::string& getMethodName() const;
// The returned GVariant object should be not freed.
bool reply(GVariant* param);
bool reply(int error);
+ void publish(const std::string& signalName, GVariant* param);
+
+ bool hasPrivilege(const char* privil);
+
+ uid_t getUid();
+
+ std::string getClientId();
+
+ bool isSystem();
+
+ ClientBase& getSender();
+
private:
ClientBase* __client;
std::string __methodName;
namespace ctx {
- class Credential;
+ class ClientBase;
class EXPORT_API PlatformDatabase : public Database {
public:
PlatformDatabase(const std::string& dbName, uid_t uid);
- PlatformDatabase(const std::string& dbName, const Credential& credential);
- PlatformDatabase(const std::string& dbName, const Credential* credential);
+ PlatformDatabase(const std::string& dbName, const ClientBase& client);
+ PlatformDatabase(const std::string& dbName, const ClientBase* client);
PlatformDatabase(const std::string& dbName);
};
*/
#include <ServiceBase.h>
-#include <Credential.h>
#include <MethodCall.h>
#include <ClientBase.h>
+#include "Credential.h"
using namespace ctx;
return __busName;
}
-Credential* ClientBase::getCredential()
+bool ClientBase::__getCredential()
{
if (__credential)
- return __credential;
+ return true;
__credential = new(std::nothrow) Credential(__hostService->getConnection(), __busName);
- IF_FAIL_RETURN_TAG(__credential, NULL, _E, "Memory allocation failed");
+ IF_FAIL_RETURN_TAG(__credential, false, _E, "Memory allocation failed");
- return __credential;
+ return true;
}
-ServiceBase* ClientBase::getHostService()
+ServiceBase& ClientBase::getHostService()
{
- return __hostService;
+ return *__hostService;
}
void ClientBase::publish(const std::string& signalName, GVariant* param)
{
- __hostService->publish(__busName, signalName, param);
+ getHostService().publish(__busName, signalName, param);
+}
+
+bool ClientBase::isVerified()
+{
+ IF_FAIL_RETURN(__getCredential(), false);
+ return __credential->valid();
+}
+
+bool ClientBase::hasPrivilege(const char* privil) const
+{
+ return __credential->hasPrivilege(privil);
+}
+
+uid_t ClientBase::getUid() const
+{
+ return __credential->getUid();
+}
+
+std::string ClientBase::getClientId() const
+{
+ return __credential->getClientId();
+}
+
+bool ClientBase::isSystem() const
+{
+ return __credential->isSystem();
+}
+
+bool ClientBase::isSystemUid(uid_t uid)
+{
+ return Credential::isSystemUid(uid);
}
#include <cynara-session.h>
#include <cynara-client.h>
#include <ScopeMutex.h>
-#include <Credential.h>
+#include "Credential.h"
#define CACHE_SIZE 100
Credential::Credential(GDBusConnection* conn, const std::string& busName) :
__pid(0),
- __uid(0),
+ __uid(ROOT_UID),
__clientId(NULL),
__session(NULL),
__user(NULL),
bool Credential::hasPrivilege(const char* privil) const
{
IF_FAIL_RETURN(privil, true);
- IF_FAIL_RETURN_TAG(__clientId && __session && __user, false, _W, "Unidentified peer");
+ IF_FAIL_RETURN_TAG(valid(), false, _W, "Unidentified peer");
static PrivilegeChecker privilegeChecker;
#include <string>
#include <ContextTypes.h>
+#define ROOT_UID 0
+
namespace ctx {
class EXPORT_API Credential {
g_dbus_method_invocation_return_error_literal(__invocation, CTX_ERROR_DOMAIN, E_FAILED, "");
}
-ClientBase* MethodCall::getSender()
+ClientBase& MethodCall::getSender()
{
- return __client;
+ return *__client;
}
const std::string& MethodCall::getMethodName() const
return true;
}
+
+void MethodCall::publish(const std::string& signalName, GVariant* param)
+{
+ getSender().publish(signalName, param);
+}
+
+bool MethodCall::hasPrivilege(const char* privil)
+{
+ return getSender().hasPrivilege(privil);
+}
+
+uid_t MethodCall::getUid()
+{
+ return getSender().getUid();
+}
+
+std::string MethodCall::getClientId()
+{
+ return getSender().getClientId();
+}
+
+bool MethodCall::isSystem()
+{
+ return getSender().isSystem();
+}
#include <sqlite3.h>
#include <tzplatform_config.h>
#include <ScopeMutex.h>
-#include <Credential.h>
#include <Tuple.h>
+#include <ClientBase.h>
#include <PlatformDatabase.h>
#define ROOT_UID ((uid_t)0)
static std::string __getPath(const std::string& dbName, uid_t uid)
{
- if (Credential::isSystemUid(uid)) {
+ if (ClientBase::isSystemUid(uid)) {
return __getSystemPath(dbName);
} else {
return __getUserPath(dbName, uid);
{
}
-PlatformDatabase::PlatformDatabase(const std::string& dbName, const Credential& credential) :
- PlatformDatabase(dbName, credential.getUid())
+PlatformDatabase::PlatformDatabase(const std::string& dbName) :
+ PlatformDatabase(dbName, ROOT_UID)
{
}
-PlatformDatabase::PlatformDatabase(const std::string& dbName, const Credential* credential) :
- PlatformDatabase(dbName, credential->getUid())
+PlatformDatabase::PlatformDatabase(const std::string& dbName, const ClientBase& client) :
+ PlatformDatabase(dbName, client.getUid())
{
}
-PlatformDatabase::PlatformDatabase(const std::string& dbName) :
- PlatformDatabase(dbName, ROOT_UID)
+PlatformDatabase::PlatformDatabase(const std::string& dbName, const ClientBase* client) :
+ PlatformDatabase(dbName, client->getUid())
{
}
ClientBase* client = createClient(busName);
IF_FAIL_RETURN_TAG(client, NULL, _E, "Memory allocation failed");
+ if (!client->isVerified()) {
+ delete client;
+ return NULL;
+ }
+
ClientInfo info = {client, __watch(busName, client)};
__clients[busName] = info;
GVariant* param, gpointer userData)
{
ClientBase* client = static_cast<ClientBase*>(userData);
- client->getHostService()->__removeClient(client->getBusName());
+ client->getHostService().__removeClient(client->getBusName());
}
void ServiceBase::__removeClient(const std::string& busName)