Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>pull/1/head
parent
eb2210c944
commit
4606c91f4c
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
|
||||
* Copyright (C) 2010 Dario Freddi <drf@kde.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
#include "polkit-tqt-actiondescription.h"
|
||||
|
||||
#include <tqshared.h>
|
||||
#include <tqstring.h>
|
||||
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// ActionDescription::Data
|
||||
//--------------------------------------
|
||||
|
||||
class ActionDescription::Data : public TQShared
|
||||
{
|
||||
public:
|
||||
Data()
|
||||
{
|
||||
}
|
||||
|
||||
Data(const Data &other) : actionId(other.actionId), description(other.description),
|
||||
message(other.message), vendorName(other.vendorName), vendorUrl(other.vendorUrl),
|
||||
iconName(other.iconName), implicitAny(other.implicitAny),
|
||||
implicitInactive(other.implicitInactive), implicitActive(other.implicitActive)
|
||||
{
|
||||
}
|
||||
|
||||
~Data()
|
||||
{
|
||||
}
|
||||
|
||||
TQString actionId;
|
||||
TQString description;
|
||||
TQString message;
|
||||
TQString vendorName;
|
||||
TQString vendorUrl;
|
||||
TQString iconName;
|
||||
|
||||
ImplicitAuthorization implicitAny;
|
||||
ImplicitAuthorization implicitInactive;
|
||||
ImplicitAuthorization implicitActive;
|
||||
};
|
||||
|
||||
//--------------------------------------
|
||||
// ActionDescription
|
||||
//--------------------------------------
|
||||
|
||||
ActionDescription::ActionDescription() : d(new Data)
|
||||
{
|
||||
}
|
||||
|
||||
ActionDescription::ActionDescription(PolkitActionDescription *pkActionDescription) : d(new Data)
|
||||
{
|
||||
d->actionId = TQString::fromUtf8(polkit_action_description_get_action_id(pkActionDescription));
|
||||
d->description = TQString::fromUtf8(polkit_action_description_get_description(pkActionDescription));
|
||||
d->message = TQString::fromUtf8(polkit_action_description_get_message(pkActionDescription));
|
||||
d->vendorName = TQString::fromUtf8(polkit_action_description_get_vendor_name(pkActionDescription));
|
||||
d->vendorUrl = TQString::fromUtf8(polkit_action_description_get_vendor_url(pkActionDescription));
|
||||
d->iconName = TQString::fromUtf8(polkit_action_description_get_icon_name(pkActionDescription));
|
||||
|
||||
d->implicitAny = static_cast<ImplicitAuthorization>(
|
||||
polkit_action_description_get_implicit_any(pkActionDescription));
|
||||
d->implicitInactive = static_cast<ImplicitAuthorization>(
|
||||
polkit_action_description_get_implicit_inactive(pkActionDescription));
|
||||
d->implicitActive = static_cast<ImplicitAuthorization>(
|
||||
polkit_action_description_get_implicit_active(pkActionDescription));
|
||||
}
|
||||
|
||||
ActionDescription::ActionDescription(const ActionDescription &other) : d(other.d)
|
||||
{
|
||||
d->ref();
|
||||
}
|
||||
|
||||
ActionDescription& ActionDescription::operator=(const ActionDescription &other)
|
||||
{
|
||||
if (d != other.d)
|
||||
{
|
||||
if (d->deref())
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
d = other.d;
|
||||
d->ref();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ActionDescription::~ActionDescription()
|
||||
{
|
||||
if (d->deref())
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
}
|
||||
|
||||
TQString ActionDescription::actionId() const
|
||||
{
|
||||
return d->actionId;
|
||||
}
|
||||
|
||||
TQString ActionDescription::description() const
|
||||
{
|
||||
return d->description;
|
||||
}
|
||||
|
||||
TQString ActionDescription::message() const
|
||||
{
|
||||
return d->message;
|
||||
}
|
||||
|
||||
TQString ActionDescription::vendorName() const
|
||||
{
|
||||
return d->vendorName;
|
||||
}
|
||||
|
||||
TQString ActionDescription::vendorUrl() const
|
||||
{
|
||||
return d->vendorUrl;
|
||||
}
|
||||
|
||||
TQString ActionDescription::iconName() const
|
||||
{
|
||||
return d->iconName;
|
||||
}
|
||||
|
||||
ActionDescription::ImplicitAuthorization ActionDescription::implicitAny() const
|
||||
{
|
||||
return d->implicitAny;
|
||||
}
|
||||
|
||||
ActionDescription::ImplicitAuthorization ActionDescription::implicitInactive() const
|
||||
{
|
||||
return d->implicitInactive;
|
||||
}
|
||||
|
||||
ActionDescription::ImplicitAuthorization ActionDescription::implicitActive() const
|
||||
{
|
||||
return d->implicitActive;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,816 @@
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Daniel Nicoletti <dantti85-pk@yahoo.com.br>
|
||||
* Copyright (C) 2009 Dario Freddi <drf@kde.org>
|
||||
* Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
|
||||
* Copyright (C) 2009 Radek Novacek <rnovacek@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
#include "polkit-tqt-authority.h"
|
||||
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// General functions
|
||||
//--------------------------------------
|
||||
|
||||
Authority *Authority::m_theAuthority = NULL;
|
||||
|
||||
Authority* Authority::instance(PolkitAuthority *authority)
|
||||
{
|
||||
if (!m_theAuthority)
|
||||
{
|
||||
m_theAuthority = new Authority();
|
||||
}
|
||||
return m_theAuthority;
|
||||
}
|
||||
|
||||
Authority::Result polkitResultToResult(PolkitAuthorizationResult *result)
|
||||
{
|
||||
if (polkit_authorization_result_get_is_challenge(result))
|
||||
{
|
||||
return Authority::Challenge;
|
||||
}
|
||||
else if (polkit_authorization_result_get_is_authorized(result))
|
||||
{
|
||||
return Authority::Yes;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Authority::No;
|
||||
}
|
||||
}
|
||||
|
||||
ActionDescription::List actionsToListAndFree(GList *glist)
|
||||
{
|
||||
ActionDescription::List result;
|
||||
for (GList *glist2 = glist; glist2; glist2 = g_list_next(glist2))
|
||||
{
|
||||
gpointer i = glist2->data;
|
||||
result.append(ActionDescription(static_cast<PolkitActionDescription*>(i)));
|
||||
g_object_unref(i);
|
||||
}
|
||||
g_list_free(glist);
|
||||
return result;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Authority::Private
|
||||
//--------------------------------------
|
||||
|
||||
class Authority::Private
|
||||
{
|
||||
public:
|
||||
Private(Authority *qq) : q(qq), pkAuthority(NULL), m_hasError(false)
|
||||
{
|
||||
}
|
||||
|
||||
~Private();
|
||||
|
||||
void init();
|
||||
|
||||
/** Use this method to set the error message to \p message. Set recover to \c true
|
||||
* to try to reinitialize this object with init() method
|
||||
*/
|
||||
void setError(ErrorCode code, const TQString &details = TQString::null, bool recover = false);
|
||||
|
||||
Authority *q;
|
||||
PolkitAuthority *pkAuthority;
|
||||
bool m_hasError;
|
||||
ErrorCode m_lastError;
|
||||
TQString m_errorDetails;
|
||||
|
||||
GCancellable *m_checkAuthorizationCancellable;
|
||||
GCancellable *m_enumerateActionsCancellable;
|
||||
GCancellable *m_registerAuthenticationAgentCancellable;
|
||||
GCancellable *m_unregisterAuthenticationAgentCancellable;
|
||||
GCancellable *m_authenticationAgentResponseCancellable;
|
||||
GCancellable *m_enumerateTemporaryAuthorizationsCancellable;
|
||||
GCancellable *m_revokeTemporaryAuthorizationsCancellable;
|
||||
GCancellable *m_revokeTemporaryAuthorizationCancellable;
|
||||
|
||||
static void pk_config_changed();
|
||||
static void checkAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void enumerateActionsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void registerAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void unregisterAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void authenticationAgentResponseCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void enumerateTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void revokeTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void revokeTemporaryAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
};
|
||||
|
||||
Authority::Private::~Private()
|
||||
{
|
||||
g_object_unref(m_checkAuthorizationCancellable);
|
||||
g_object_unref(m_enumerateActionsCancellable);
|
||||
g_object_unref(m_registerAuthenticationAgentCancellable);
|
||||
g_object_unref(m_unregisterAuthenticationAgentCancellable);
|
||||
g_object_unref(m_authenticationAgentResponseCancellable);
|
||||
g_object_unref(m_enumerateTemporaryAuthorizationsCancellable);
|
||||
g_object_unref(m_revokeTemporaryAuthorizationsCancellable);
|
||||
g_object_unref(m_revokeTemporaryAuthorizationCancellable);
|
||||
}
|
||||
|
||||
void Authority::Private::init()
|
||||
{
|
||||
m_checkAuthorizationCancellable = g_cancellable_new();
|
||||
m_enumerateActionsCancellable = g_cancellable_new();
|
||||
m_registerAuthenticationAgentCancellable = g_cancellable_new();
|
||||
m_unregisterAuthenticationAgentCancellable = g_cancellable_new();
|
||||
m_authenticationAgentResponseCancellable = g_cancellable_new();
|
||||
m_enumerateTemporaryAuthorizationsCancellable = g_cancellable_new();
|
||||
m_revokeTemporaryAuthorizationsCancellable = g_cancellable_new();
|
||||
m_revokeTemporaryAuthorizationCancellable = g_cancellable_new();
|
||||
|
||||
GError *gerror = NULL;
|
||||
if (pkAuthority == NULL)
|
||||
{
|
||||
pkAuthority = polkit_authority_get_sync(NULL, &gerror);
|
||||
if (gerror != NULL)
|
||||
{
|
||||
setError(E_GetAuthority, gerror->message);
|
||||
g_error_free(gerror);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (pkAuthority == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// connect changed signal
|
||||
g_signal_connect(G_OBJECT(pkAuthority), "changed", G_CALLBACK(pk_config_changed), NULL);
|
||||
}
|
||||
|
||||
void Authority::Private::setError(Authority::ErrorCode code, const TQString &details, bool recover)
|
||||
{
|
||||
if (recover)
|
||||
{
|
||||
init();
|
||||
}
|
||||
m_lastError = code;
|
||||
m_errorDetails = details;
|
||||
m_hasError = true;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Authority
|
||||
//--------------------------------------
|
||||
|
||||
Authority::Authority(TQObject *parent) : TQObject(parent), d(new Private(this))
|
||||
{
|
||||
d->init();
|
||||
}
|
||||
|
||||
Authority::~Authority()
|
||||
{
|
||||
g_object_unref(d->pkAuthority);
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool Authority::hasError() const
|
||||
{
|
||||
return d->m_hasError;
|
||||
}
|
||||
|
||||
Authority::ErrorCode Authority::lastError() const
|
||||
{
|
||||
return d->m_lastError;
|
||||
}
|
||||
|
||||
const TQString Authority::errorDetails() const
|
||||
{
|
||||
if (d->m_lastError == E_None)
|
||||
{
|
||||
return TQString::null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return d->m_errorDetails;
|
||||
}
|
||||
}
|
||||
|
||||
void Authority::clearError()
|
||||
{
|
||||
d->m_hasError = false;
|
||||
d->m_lastError = E_None;
|
||||
}
|
||||
|
||||
void Authority::Private::pk_config_changed()
|
||||
{
|
||||
emit Authority::instance()->configChanged();
|
||||
}
|
||||
|
||||
PolkitAuthority* Authority::polkitAuthority() const
|
||||
{
|
||||
return d->pkAuthority;
|
||||
}
|
||||
|
||||
Authority::Result Authority::checkAuthorizationSync(const TQString &actionId,
|
||||
const Subject &subject, AuthorizationFlags flags)
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
if (!subject.isValid())
|
||||
{
|
||||
d->setError(E_WrongSubject);
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
PolkitAuthorizationResult *pk_result = polkit_authority_check_authorization_sync(d->pkAuthority,
|
||||
subject.subject(), actionId.ascii(), NULL, (PolkitCheckAuthorizationFlags)(int)flags,
|
||||
NULL, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
d->setError(E_CheckFailed, error->message);
|
||||
g_error_free(error);
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
if (!pk_result)
|
||||
{
|
||||
d->setError(E_UnknownResult);
|
||||
return Unknown;
|
||||
}
|
||||
else
|
||||
{
|
||||
Authority::Result res = polkitResultToResult(pk_result);
|
||||
g_object_unref(pk_result);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
void Authority::checkAuthorization(const TQString &actionId, const Subject &subject, AuthorizationFlags flags)
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!subject.isValid())
|
||||
{
|
||||
d->setError(E_WrongSubject);
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_check_authorization(d->pkAuthority, subject.subject(), actionId.ascii(), NULL,
|
||||
(PolkitCheckAuthorizationFlags)(int)flags, d->m_checkAuthorizationCancellable,
|
||||
d->checkAuthorizationCallback, this);
|
||||
}
|
||||
|
||||
void Authority::Private::checkAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority*)user_data;
|
||||
if (!authority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
PolkitAuthorizationResult *pkResult = polkit_authority_check_authorization_finish(
|
||||
(PolkitAuthority*)object, result, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1)
|
||||
{
|
||||
authority->d->setError(E_CheckFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
if (pkResult != NULL)
|
||||
{
|
||||
emit authority->checkAuthorizationFinished(polkitResultToResult(pkResult));
|
||||
g_object_unref(pkResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
authority->d->setError(E_UnknownResult);
|
||||
}
|
||||
}
|
||||
|
||||
void Authority::checkAuthorizationCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_checkAuthorizationCancellable))
|
||||
{
|
||||
g_cancellable_cancel(d->m_checkAuthorizationCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
ActionDescription::List Authority::enumerateActionsSync()
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return ActionDescription::List();
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
GList *glist = polkit_authority_enumerate_actions_sync(d->pkAuthority, NULL, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
d->setError(E_EnumFailed, error->message);
|
||||
g_error_free(error);
|
||||
return ActionDescription::List();
|
||||
}
|
||||
|
||||
return actionsToListAndFree(glist);
|
||||
}
|
||||
|
||||
void Authority::enumerateActions()
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_enumerate_actions(d->pkAuthority, d->m_enumerateActionsCancellable,
|
||||
d->enumerateActionsCallback, Authority::instance());
|
||||
}
|
||||
|
||||
void Authority::Private::enumerateActionsCallback(GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority*)user_data;
|
||||
if (!authority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
GError *error = NULL;
|
||||
GList *list = polkit_authority_enumerate_actions_finish((PolkitAuthority*)object, result, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1)
|
||||
{
|
||||
authority->d->setError(E_EnumFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
emit authority->enumerateActionsFinished(actionsToListAndFree(list));
|
||||
}
|
||||
|
||||
void Authority::enumerateActionsCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_enumerateActionsCancellable))
|
||||
{
|
||||
g_cancellable_cancel(d->m_enumerateActionsCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
bool Authority::registerAuthenticationAgentSync(const Subject &subject, const TQString &locale,
|
||||
const TQString &objectPath)
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!subject.isValid())
|
||||
{
|
||||
d->setError(E_WrongSubject);
|
||||
return false;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
gboolean result = polkit_authority_register_authentication_agent_sync(d->pkAuthority,
|
||||
subject.subject(), locale.ascii(), objectPath.ascii(), NULL, &error);
|
||||
if (error)
|
||||
{
|
||||
d->setError(E_RegisterFailed, error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::registerAuthenticationAgent(const Subject &subject, const TQString &locale,
|
||||
const TQString &objectPath)
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!subject.isValid())
|
||||
{
|
||||
d->setError(E_WrongSubject);
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_register_authentication_agent(d->pkAuthority, subject.subject(), locale.ascii(),
|
||||
objectPath.ascii(), d->m_registerAuthenticationAgentCancellable,
|
||||
d->registerAuthenticationAgentCallback, this);
|
||||
}
|
||||
|
||||
void Authority::Private::registerAuthenticationAgentCallback(GObject *object, GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority*)user_data;
|
||||
if (!authority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
GError *error = NULL;
|
||||
bool res = polkit_authority_register_authentication_agent_finish((PolkitAuthority*)object, result, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1)
|
||||
{
|
||||
authority->d->setError(E_EnumFailed , error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
emit authority->registerAuthenticationAgentFinished(res);
|
||||
}
|
||||
|
||||
void Authority::registerAuthenticationAgentCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_registerAuthenticationAgentCancellable))
|
||||
{
|
||||
g_cancellable_cancel(d->m_registerAuthenticationAgentCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
bool Authority::unregisterAuthenticationAgentSync(const Subject &subject, const TQString &objectPath)
|
||||
{
|
||||
if (d->pkAuthority)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!subject.isValid())
|
||||
{
|
||||
d->setError(E_WrongSubject);
|
||||
return false;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
bool result = polkit_authority_unregister_authentication_agent_sync(d->pkAuthority,
|
||||
subject.subject(), objectPath.utf8().data(), NULL, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
d->setError(E_UnregisterFailed, error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::unregisterAuthenticationAgent(const Subject &subject, const TQString &objectPath)
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!subject.isValid())
|
||||
{
|
||||
d->setError(E_WrongSubject);
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_unregister_authentication_agent(d->pkAuthority, subject.subject(),
|
||||
objectPath.utf8().data(), d->m_unregisterAuthenticationAgentCancellable,
|
||||
d->unregisterAuthenticationAgentCallback, this);
|
||||
}
|
||||
|
||||
void Authority::Private::unregisterAuthenticationAgentCallback(GObject *object,
|
||||
GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority*)user_data;
|
||||
if (!authority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
GError *error = NULL;
|
||||
bool res = polkit_authority_unregister_authentication_agent_finish((PolkitAuthority*)object,
|
||||
result, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1)
|
||||
{
|
||||
authority->d->setError(E_UnregisterFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
emit authority->unregisterAuthenticationAgentFinished(res);
|
||||
}
|
||||
|
||||
void Authority::unregisterAuthenticationAgentCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_unregisterAuthenticationAgentCancellable))
|
||||
{
|
||||
g_cancellable_cancel(d->m_unregisterAuthenticationAgentCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
bool Authority::authenticationAgentResponseSync(const TQString &cookie, const Identity &identity)
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cookie.isEmpty() || !identity.isValid())
|
||||
{
|
||||
d->setError(E_CookieOrIdentityEmpty);
|
||||
return false;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
bool result = polkit_authority_authentication_agent_response_sync(d->pkAuthority,
|
||||
cookie.utf8().data(), identity.identity(), NULL, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
d->setError(E_AgentResponseFailed, error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::authenticationAgentResponse(const TQString &cookie, const Identity &identity)
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (cookie.isEmpty() || !identity.isValid())
|
||||
{
|
||||
d->setError(E_CookieOrIdentityEmpty);
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_authentication_agent_response(d->pkAuthority, cookie.utf8().data(),
|
||||
identity.identity(), d->m_authenticationAgentResponseCancellable,
|
||||
d->authenticationAgentResponseCallback, this);
|
||||
}
|
||||
|
||||
void Authority::Private::authenticationAgentResponseCallback(GObject *object, GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority*)user_data;
|
||||
if (!authority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
GError *error = NULL;
|
||||
bool res = polkit_authority_authentication_agent_response_finish((PolkitAuthority*)object, result,
|
||||
&error);
|
||||
if (error != NULL)
|
||||
{
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1)
|
||||
{
|
||||
authority->d->setError(E_AgentResponseFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
emit authority->authenticationAgentResponseFinished(res);
|
||||
}
|
||||
|
||||
void Authority::authenticationAgentResponseCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_authenticationAgentResponseCancellable))
|
||||
{
|
||||
g_cancellable_cancel(d->m_authenticationAgentResponseCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
TemporaryAuthorization::List Authority::enumerateTemporaryAuthorizationsSync(const Subject &subject)
|
||||
{
|
||||
TemporaryAuthorization::List result;
|
||||
|
||||
GError *error = NULL;
|
||||
GList *glist = polkit_authority_enumerate_temporary_authorizations_sync(d->pkAuthority,
|
||||
subject.subject(), NULL, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
d->setError(E_EnumFailed, error->message);
|
||||
g_error_free(error);
|
||||
return result;
|
||||
}
|
||||
|
||||
GList *glist2;
|
||||
for (glist2 = glist; glist2 != NULL; glist2 = g_list_next(glist2))
|
||||
{
|
||||
result.append(TemporaryAuthorization((PolkitTemporaryAuthorization*)glist2->data));
|
||||
g_object_unref(glist2->data);
|
||||
}
|
||||
g_list_free(glist);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::Private::enumerateTemporaryAuthorizationsCallback(GObject *object,
|
||||
GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority*)user_data;
|
||||
if (!authority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
GList *glist = polkit_authority_enumerate_temporary_authorizations_finish((PolkitAuthority*)object,
|
||||
result, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1)
|
||||
{
|
||||
authority->d->setError(E_EnumFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
TemporaryAuthorization::List res;
|
||||
GList *glist2;
|
||||
for (glist2 = glist; glist2 != NULL; glist2 = g_list_next(glist2))
|
||||
{
|
||||
res.append(TemporaryAuthorization((PolkitTemporaryAuthorization*)glist2->data));
|
||||
g_object_unref(glist2->data);
|
||||
}
|
||||
g_list_free(glist);
|
||||
emit authority->enumerateTemporaryAuthorizationsFinished(res);
|
||||
}
|
||||
|
||||
void Authority::enumerateTemporaryAuthorizationsCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_enumerateTemporaryAuthorizationsCancellable))
|
||||
{
|
||||
g_cancellable_cancel(d->m_enumerateTemporaryAuthorizationsCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
bool Authority::revokeTemporaryAuthorizationsSync(const Subject &subject)
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
bool result = polkit_authority_revoke_temporary_authorizations_sync(d->pkAuthority,
|
||||
subject.subject(), NULL, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
d->setError(E_RevokeFailed, error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::revokeTemporaryAuthorizations(const Subject &subject)
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_revoke_temporary_authorizations(d->pkAuthority, subject.subject(),
|
||||
d->m_revokeTemporaryAuthorizationsCancellable,
|
||||
d->revokeTemporaryAuthorizationsCallback, this);
|
||||
}
|
||||
|
||||
void Authority::Private::revokeTemporaryAuthorizationsCallback(GObject *object,
|
||||
GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority*)user_data;
|
||||
if (!authority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
bool res = polkit_authority_revoke_temporary_authorizations_finish((PolkitAuthority*)object, result, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1)
|
||||
{
|
||||
authority->d->setError(E_RevokeFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
emit authority->revokeTemporaryAuthorizationsFinished(res);
|
||||
}
|
||||
|
||||
void Authority::revokeTemporaryAuthorizationsCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_revokeTemporaryAuthorizationsCancellable))
|
||||
{
|
||||
g_cancellable_cancel(d->m_revokeTemporaryAuthorizationsCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
bool Authority::revokeTemporaryAuthorizationSync(const TQString &id)
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
bool result = polkit_authority_revoke_temporary_authorization_by_id_sync(d->pkAuthority,
|
||||
id.utf8().data(), NULL, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
d->setError(E_RevokeFailed, error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::revokeTemporaryAuthorization(const TQString &id)
|
||||
{
|
||||
if (Authority::instance()->hasError())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_revoke_temporary_authorization_by_id(d->pkAuthority, id.utf8().data(),
|
||||
d->m_revokeTemporaryAuthorizationCancellable,
|
||||
d->revokeTemporaryAuthorizationCallback, this);
|
||||
}
|
||||
|
||||
void Authority::Private::revokeTemporaryAuthorizationCallback(GObject *object,
|
||||
GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority*)user_data;
|
||||
if (!authority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
bool res = polkit_authority_revoke_temporary_authorization_by_id_finish((PolkitAuthority*)object,
|
||||
result, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1)
|
||||
{
|
||||
authority->d->setError(E_RevokeFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
emit authority->revokeTemporaryAuthorizationFinished(res);
|
||||
}
|
||||
|
||||
void Authority::revokeTemporaryAuthorizationCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_revokeTemporaryAuthorizationCancellable))
|
||||
{
|
||||
g_cancellable_cancel(d->m_revokeTemporaryAuthorizationCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "polkit-tqt-authority.moc"
|
||||
|
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Radek Novacek <rnovacek@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
#include "polkit-tqt-details.h"
|
||||
|
||||
#include <tqshared.h>
|
||||
#include <tqstring.h>
|
||||
#include <tqstringlist.h>
|
||||
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Details::Data
|
||||
//--------------------------------------
|
||||
|
||||
class Details::Data : public TQShared
|
||||
{
|
||||
public:
|
||||
Data() : details(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Data(const Data &other) : details(other.details)
|
||||
{
|
||||
g_object_ref(details);
|
||||
}
|
||||
|
||||
Data(PolkitDetails *_details) : details(_details)
|
||||
{
|
||||
g_object_ref(details);
|
||||
}
|
||||
|
||||
~Data()
|
||||
{
|
||||
g_object_unref(details);
|
||||
}
|
||||
|
||||
PolkitDetails *details;
|
||||
};
|
||||
|
||||
//--------------------------------------
|
||||
// Details
|
||||
//--------------------------------------
|
||||
|
||||
Details::Details() : d(new Data)
|
||||
{
|
||||
d->details = polkit_details_new();
|
||||
}
|
||||
|
||||
Details::Details(PolkitDetails *pkDetails) : d(new Data(pkDetails))
|
||||
{
|
||||
}
|
||||
|
||||
Details::Details(const Details &other) : d(other.d)
|
||||
{
|
||||
d->ref();
|
||||
}
|
||||
|
||||
Details& Details::operator=(const Details &other)
|
||||
{
|
||||
if (d != other.d)
|
||||
{
|
||||
if (d->deref())
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
d = other.d;
|
||||
d->ref();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Details::~Details()
|
||||
{
|
||||
if (d->deref())
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
}
|
||||
|
||||
TQString Details::lookup(const TQString &key) const
|
||||
{
|
||||
const gchar *result = polkit_details_lookup(d->details, key.utf8().data());
|
||||
if (result != NULL)
|
||||
{
|
||||
return TQString::fromUtf8(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return TQString::null;
|
||||
}
|
||||
}
|
||||
|
||||
void Details::insert(const TQString &key, const TQString &value)
|
||||
{
|
||||
polkit_details_insert(d->details, key.utf8().data(), value.utf8().data());
|
||||
}
|
||||
|
||||
TQStringList Details::keys() const
|
||||
{
|
||||
gchar **result = polkit_details_get_keys(d->details);
|
||||
TQStringList list;
|
||||
int len = g_strv_length(result);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
list.append(TQString::fromUtf8(result[i]));
|
||||
}
|
||||
g_strfreev(result);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,219 @@
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Lukas Tinkl <ltinkl@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
#include "polkit-tqt-identity.h"
|
||||
|
||||
#include <tqshared.h>
|
||||
#include <tqstring.h>
|
||||
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Identity::Data
|
||||
//--------------------------------------
|
||||
|
||||
class Identity::Data : public TQShared
|
||||
{
|
||||
public:
|
||||
Data() : identity(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Data(const Data &other) : identity(other.identity)
|
||||
{
|
||||
g_object_ref(identity);
|
||||
}
|
||||
|
||||
Data(PolkitIdentity *_identity) : identity(_identity)
|
||||
{
|
||||
g_object_ref(identity);
|
||||
}
|
||||
|
||||
~Data()
|
||||
{
|
||||
g_object_unref(identity);
|
||||
}
|
||||
|
||||
PolkitIdentity *identity;
|
||||
};
|
||||
|
||||
//--------------------------------------
|
||||
// Identity
|
||||
//--------------------------------------
|
||||
|
||||
Identity::Identity() : d(new Data)
|
||||
{
|
||||
}
|
||||
|
||||
Identity::Identity(PolkitIdentity *pkIdentity) : d(new Data(pkIdentity))
|
||||
{
|
||||
}
|
||||
|
||||
Identity::Identity(const Identity &other) : d(other.d)
|
||||
{
|
||||
d->ref();
|
||||
}
|
||||
|
||||
Identity& Identity::operator=(const Identity &other)
|
||||
{
|
||||
if (d != other.d)
|
||||
{
|
||||
if (d->deref())
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
d = other.d;
|
||||
d->ref();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Identity::~Identity()
|
||||
{
|
||||
if (d->deref())
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
}
|
||||
|
||||
bool Identity::isValid() const
|
||||
{
|
||||
return (d->identity != NULL);
|
||||
}
|
||||
|
||||
PolkitIdentity* Identity::identity() const
|
||||
{
|
||||
return d->identity;
|
||||
}
|
||||
|
||||
void Identity::setIdentity(PolkitIdentity *identity)
|
||||
{
|
||||
if (d->identity != identity)
|
||||
{
|
||||
g_object_unref(d->identity);
|
||||
d->identity = identity;
|
||||
g_object_ref(identity);
|
||||
}
|
||||
}
|
||||
|
||||
TQString Identity::toString() const
|
||||
{
|
||||
if (!d->identity)
|
||||
{
|
||||
return TQString::null;
|
||||
}
|
||||
return TQString::fromUtf8(polkit_identity_to_string(d->identity));
|
||||
}
|
||||
|
||||
Identity Identity::fromString(const TQString &string)
|
||||
{
|
||||
if (string.isEmpty())
|
||||
{
|
||||
tqWarning(TQString("Cannot create valid Identity from empty string."));
|
||||
return Identity();
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
PolkitIdentity *poliden = polkit_identity_from_string(string.utf8().data(), &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
tqWarning(TQString("Cannot create valid Identity from string: %1").arg(error->message));
|
||||
return Identity();
|
||||
}
|
||||
|
||||
return Identity(poliden);
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// UnixUserIdentity
|
||||
//--------------------------------------
|
||||
|
||||
UnixUserIdentity::UnixUserIdentity(const TQString &name) : Identity()
|
||||
{
|
||||
GError *error = NULL;
|
||||
setIdentity(polkit_unix_user_new_for_name(name.utf8().data(), &error));
|
||||
if (error != NULL)
|
||||
{
|
||||
tqWarning(TQString("Cannot create UnixUserIdentity: %1").arg(error->message));
|
||||
setIdentity(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
UnixUserIdentity::UnixUserIdentity(uid_t uid) : Identity()
|
||||
{
|
||||
setIdentity(polkit_unix_user_new(uid));
|
||||
}
|
||||
|
||||
UnixUserIdentity::UnixUserIdentity(PolkitUnixUser *pkUnixUser)
|
||||
: Identity((PolkitIdentity*)pkUnixUser)
|
||||
{
|
||||
}
|
||||
|
||||
uid_t UnixUserIdentity::uid() const
|
||||
{
|
||||
return polkit_unix_user_get_uid((PolkitUnixUser*)identity());
|
||||
}
|
||||
|
||||
void UnixUserIdentity::setUid(uid_t uid)
|
||||
{
|
||||
polkit_unix_user_set_uid((PolkitUnixUser*)identity(), uid);
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// UnixGroupIdentity
|
||||
//--------------------------------------
|
||||
|
||||
UnixGroupIdentity::UnixGroupIdentity(const TQString &name) : Identity()
|
||||
{
|
||||
GError *error = NULL;
|
||||
setIdentity(polkit_unix_group_new_for_name(name.utf8().data(), &error));
|
||||
if (error != NULL)
|
||||
{
|
||||
tqWarning(TQString("Cannot create UnixGroupIdentity: %1").arg(error->message));
|
||||
setIdentity(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
UnixGroupIdentity::UnixGroupIdentity(gid_t gid) : Identity()
|
||||
{
|
||||
setIdentity(polkit_unix_group_new(gid));
|
||||
}
|
||||
|
||||
UnixGroupIdentity::UnixGroupIdentity(PolkitUnixGroup *pkUnixGroup)
|
||||
: Identity((PolkitIdentity*)pkUnixGroup)
|
||||
{
|
||||
}
|
||||
|
||||
gid_t UnixGroupIdentity::gid() const
|
||||
{
|
||||
return polkit_unix_group_get_gid((PolkitUnixGroup*)identity());
|
||||
}
|
||||
|
||||
void UnixGroupIdentity::setGid(gid_t gid)
|
||||
{
|
||||
polkit_unix_group_set_gid((PolkitUnixGroup*)identity(), gid);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* This file is part of the PolKit-tqt project
|
||||
* Copyright (C) 2009 Radek Novacek <rnovacek@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
#include "polkit-tqt-temporaryauthorization.h"
|
||||
#include "polkit-tqt-authority.h"
|
||||
|
||||
#include <tqdatetime.h>
|
||||
#include <tqshared.h>
|
||||
#include <tqstring.h>
|
||||
|
||||
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// TemporaryAuthorization::Data
|
||||
//--------------------------------------
|
||||
|
||||
class TemporaryAuthorization::Data : public TQShared
|
||||
{
|
||||
public:
|
||||
Data() : id(TQString::null) , actionId(TQString::null), subject(),
|
||||
timeObtained(TQDateTime()), timeExpires(TQDateTime())
|
||||
{
|
||||
}
|
||||
|
||||
Data(const Data& other) : id(other.id), actionId(other.actionId), subject(other.subject),
|
||||
timeObtained(other.timeObtained), timeExpires(other.timeExpires)
|
||||
{
|
||||
}
|
||||
|
||||
~Data()
|
||||
{
|
||||
}
|
||||
|
||||
TQString id;
|
||||
TQString actionId;
|
||||
Subject subject;
|
||||
TQDateTime timeObtained;
|
||||
TQDateTime timeExpires;
|
||||
};
|
||||
|
||||
//--------------------------------------
|
||||
// TemporaryAuthorization
|
||||
//--------------------------------------
|
||||
|
||||
TemporaryAuthorization::TemporaryAuthorization() : d(new Data)
|
||||
{
|
||||
}
|
||||
|
||||
TemporaryAuthorization::TemporaryAuthorization(PolkitTemporaryAuthorization *pkTemporaryAuthorization) : d(new Data)
|
||||
{
|
||||
d->id = TQString::fromUtf8(polkit_temporary_authorization_get_id(pkTemporaryAuthorization));
|
||||
d->actionId = TQString::fromUtf8(polkit_temporary_authorization_get_action_id(pkTemporaryAuthorization));
|
||||
d->subject = Subject::fromString(polkit_subject_to_string(polkit_temporary_authorization_get_subject(pkTemporaryAuthorization)));
|
||||
d->timeObtained = TQDateTime();
|
||||
d->timeObtained.setTime_t(polkit_temporary_authorization_get_time_obtained(pkTemporaryAuthorization));
|
||||
d->timeExpires = TQDateTime();
|
||||
d->timeExpires.setTime_t(polkit_temporary_authorization_get_time_expires(pkTemporaryAuthorization));
|
||||
}
|
||||
|
||||
TemporaryAuthorization::TemporaryAuthorization(const TemporaryAuthorization &other) : d(other.d)
|
||||
{
|
||||
d->ref();
|
||||
}
|
||||
|
||||
TemporaryAuthorization& TemporaryAuthorization::operator=(const PolkitTQt::TemporaryAuthorization& other)
|
||||
{
|
||||
if (d != other.d)
|
||||
{
|
||||
if (d->deref())
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
d = other.d;
|
||||
d->ref();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
TemporaryAuthorization::~TemporaryAuthorization()
|
||||
{
|
||||
if (d->deref())
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
}
|
||||
|
||||
TQString TemporaryAuthorization::id() const
|
||||
{
|
||||
return d->id;
|
||||
}
|
||||
|
||||
TQString TemporaryAuthorization::actionId() const
|
||||
{
|
||||
return d->actionId;
|
||||
}
|
||||
|
||||
Subject TemporaryAuthorization::subject() const
|
||||
{
|
||||
return d->subject;
|
||||
}
|
||||
|
||||
TQDateTime TemporaryAuthorization::obtainedAt() const
|
||||
{
|
||||
return d->timeObtained;
|
||||
}
|
||||
|
||||
TQDateTime TemporaryAuthorization::expirationTime() const
|
||||
{
|
||||
return d->timeExpires;
|
||||
}
|
||||
|
||||
bool TemporaryAuthorization::revoke()
|
||||
{
|
||||
Authority::instance()->revokeTemporaryAuthorization(id());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,148 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
|
||||
* Copyright (C) 2010 Dario Freddi <drf@kde.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "polkittqt1-actiondescription.h"
|
||||
|
||||
#include <TQtCore/TQString>
|
||||
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
class ActionDescription::Data : public TQSharedData
|
||||
{
|
||||
public:
|
||||
Data() {}
|
||||
Data(const Data& other)
|
||||
: TQSharedData(other)
|
||||
, actionId(other.actionId)
|
||||
, description(other.description)
|
||||
, message(other.message)
|
||||
, vendorName(other.vendorName)
|
||||
, vendorUrl(other.vendorUrl)
|
||||
, iconName(other.iconName)
|
||||
, implicitAny(other.implicitAny)
|
||||
, implicitInactive(other.implicitInactive)
|
||||
, implicitActive(other.implicitActive)
|
||||
{
|
||||
}
|
||||
virtual ~Data() {}
|
||||
|
||||
TQString actionId;
|
||||
TQString description;
|
||||
TQString message;
|
||||
TQString vendorName;
|
||||
TQString vendorUrl;
|
||||
TQString iconName;
|
||||
|
||||
ActionDescription::ImplicitAuthorization implicitAny;
|
||||
ActionDescription::ImplicitAuthorization implicitInactive;
|
||||
ActionDescription::ImplicitAuthorization implicitActive;
|
||||
};
|
||||
|
||||
ActionDescription::ActionDescription()
|
||||
: d(new Data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ActionDescription::ActionDescription(PolkitActionDescription *polkitActionDescription)
|
||||
: d(new Data)
|
||||
{
|
||||
g_type_init();
|
||||
|
||||
d->actionId = TQString::fromUtf8(polkit_action_description_get_action_id(polkitActionDescription));
|
||||
d->description = TQString::fromUtf8(polkit_action_description_get_description(polkitActionDescription));
|
||||
d->message = TQString::fromUtf8(polkit_action_description_get_message(polkitActionDescription));
|
||||
d->vendorName = TQString::fromUtf8(polkit_action_description_get_vendor_name(polkitActionDescription));
|
||||
d->vendorUrl = TQString::fromUtf8(polkit_action_description_get_vendor_url(polkitActionDescription));
|
||||
d->iconName = TQString::fromUtf8(polkit_action_description_get_icon_name(polkitActionDescription));
|
||||
|
||||
d->implicitAny = static_cast<ActionDescription::ImplicitAuthorization>(polkit_action_description_get_implicit_any(
|
||||
polkitActionDescription));
|
||||
d->implicitInactive = static_cast<ActionDescription::ImplicitAuthorization>(polkit_action_description_get_implicit_inactive(
|
||||
polkitActionDescription));
|
||||
d->implicitActive = static_cast<ActionDescription::ImplicitAuthorization>(polkit_action_description_get_implicit_active(
|
||||
polkitActionDescription));
|
||||
}
|
||||
|
||||
ActionDescription::ActionDescription(const PolkitTQt::ActionDescription& other)
|
||||
: d(other.d)
|
||||
{
|
||||
}
|
||||
|
||||
ActionDescription& ActionDescription::operator=(const PolkitTQt::ActionDescription& other)
|
||||
{
|
||||
d = other.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ActionDescription::~ActionDescription()
|
||||
{
|
||||
}
|
||||
|
||||
TQString ActionDescription::actionId() const
|
||||
{
|
||||
return d->actionId;
|
||||
}
|
||||
|
||||
TQString ActionDescription::description() const
|
||||
{
|
||||
return d->description;
|
||||
}
|
||||
|
||||
TQString ActionDescription::message() const
|
||||
{
|
||||
return d->message;
|
||||
}
|
||||
|
||||
TQString ActionDescription::vendorName() const
|
||||
{
|
||||
return d->vendorName;
|
||||
}
|
||||
|
||||
TQString ActionDescription::vendorUrl() const
|
||||
{
|
||||
return d->vendorUrl;
|
||||
}
|
||||
|
||||
TQString ActionDescription::iconName() const
|
||||
{
|
||||
return d->iconName;
|
||||
}
|
||||
|
||||
ActionDescription::ImplicitAuthorization ActionDescription::implicitAny() const
|
||||
{
|
||||
return d->implicitAny;
|
||||
}
|
||||
|
||||
ActionDescription::ImplicitAuthorization ActionDescription::implicitInactive() const
|
||||
{
|
||||
return d->implicitInactive;
|
||||
}
|
||||
|
||||
ActionDescription::ImplicitAuthorization ActionDescription::implicitActive() const
|
||||
{
|
||||
return d->implicitActive;
|
||||
}
|
||||
|
||||
}
|
@ -1,855 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Daniel Nicoletti <dantti85-pk@yahoo.com.br>
|
||||
* Copyright (C) 2009 Dario Freddi <drf@kde.org>
|
||||
* Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
|
||||
* Copyright (C) 2009 Radek Novacek <rnovacek@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "polkittqt1-authority.h"
|
||||
|
||||
#include <TQtDBus/TQDBusInterface>
|
||||
#include <TQtDBus/TQDBusReply>
|
||||
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
class AuthorityHelper
|
||||
{
|
||||
public:
|
||||
AuthorityHelper() : q(0) {}
|
||||
~AuthorityHelper() {
|
||||
delete q;
|
||||
}
|
||||
Authority *q;
|
||||
};
|
||||
|
||||
TQ_GLOBAL_STATIC(AuthorityHelper, s_globalAuthority)
|
||||
|
||||
Authority *Authority::instance(PolkitAuthority *authority)
|
||||
{
|
||||
if (!s_globalAuthority()->q) {
|
||||
new Authority(authority);
|
||||
}
|
||||
|
||||
return s_globalAuthority()->q;
|
||||
}
|
||||
|
||||
Authority::Result polkitResultToResult(PolkitAuthorizationResult *result)
|
||||
{
|
||||
if (polkit_authorization_result_get_is_challenge(result)) {
|
||||
return Authority::Challenge;
|
||||
} else if (polkit_authorization_result_get_is_authorized(result)) {
|
||||
return Authority::Yes;
|
||||
} else {
|
||||
return Authority::No;
|
||||
}
|
||||
}
|
||||
|
||||
ActionDescription::List actionsToListAndFree(GList *glist)
|
||||
{
|
||||
ActionDescription::List result;
|
||||
for (GList *glist2 = glist; glist2; glist2 = g_list_next(glist2)) {
|
||||
gpointer i = glist2->data;
|
||||
result.append(ActionDescription(static_cast<PolkitActionDescription *>(i)));
|
||||
g_object_unref(i);
|
||||
}
|
||||
|
||||
g_list_free(glist);
|
||||
return result;
|
||||
}
|
||||
|
||||
class Authority::Private
|
||||
{
|
||||
public:
|
||||
// Polkit will return NULL on failures, hence we use it instead of 0
|
||||
Private(Authority *qq) : q(qq)
|
||||
, pkAuthority(NULL)
|
||||
, m_hasError(false) {}
|
||||
|
||||
~Private();
|
||||
|
||||
void init();
|
||||
|
||||
/** Use this method to set the error message to \p message. Set recover to \c true
|
||||
* to try to reinitialize this object with init() method
|
||||
*/
|
||||
void setError(Authority::ErrorCode code, const TQString &details = TQString(), bool recover = false);
|
||||
|
||||
void dbusFilter(const TQDBusMessage &message);
|
||||
void dbusSignalAdd(const TQString &service, const TQString &path, const TQString &interface, const TQString &name);
|
||||
void seatSignalsConnect(const TQString &seat);
|
||||
|
||||
Authority *q;
|
||||
PolkitAuthority *pkAuthority;
|
||||
bool m_hasError;
|
||||
Authority::ErrorCode m_lastError;
|
||||
TQString m_errorDetails;
|
||||
TQDBusConnection *m_systemBus;
|
||||
GCancellable *m_checkAuthorizationCancellable,
|
||||
*m_enumerateActionsCancellable,
|
||||
*m_registerAuthenticationAgentCancellable,
|
||||
*m_unregisterAuthenticationAgentCancellable,
|
||||
*m_authenticationAgentResponseCancellable,
|
||||
*m_enumerateTemporaryAuthorizationsCancellable,
|
||||
*m_revokeTemporaryAuthorizationsCancellable,
|
||||
*m_revokeTemporaryAuthorizationCancellable;
|
||||
|
||||
|
||||
static void pk_config_changed();
|
||||
static void checkAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void enumerateActionsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void registerAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void unregisterAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void authenticationAgentResponseCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void enumerateTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void revokeTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
static void revokeTemporaryAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
};
|
||||
|
||||
Authority::Private::~Private()
|
||||
{
|
||||
g_object_unref(m_checkAuthorizationCancellable);
|
||||
g_object_unref(m_enumerateActionsCancellable);
|
||||
g_object_unref(m_registerAuthenticationAgentCancellable);
|
||||
g_object_unref(m_unregisterAuthenticationAgentCancellable);
|
||||
g_object_unref(m_authenticationAgentResponseCancellable);
|
||||
g_object_unref(m_enumerateTemporaryAuthorizationsCancellable);
|
||||
g_object_unref(m_revokeTemporaryAuthorizationsCancellable);
|
||||
g_object_unref(m_revokeTemporaryAuthorizationCancellable);
|
||||
}
|
||||
|
||||
Authority::Authority(PolkitAuthority *authority, TQObject *parent)
|
||||
: TQObject(parent)
|
||||
, d(new Private(this))
|
||||
{
|
||||
qRegisterMetaType<PolkitTQt::Authority::Result> ();
|
||||
qRegisterMetaType<PolkitTQt::ActionDescription::List>();
|
||||
|
||||
Q_ASSERT(!s_globalAuthority()->q);
|
||||
s_globalAuthority()->q = this;
|
||||
|
||||
if (authority) {
|
||||
d->pkAuthority = authority;
|
||||
}
|
||||
|
||||
d->init();
|
||||
}
|
||||
|
||||
Authority::~Authority()
|
||||
{
|
||||
if (d->pkAuthority != NULL) {
|
||||
g_object_unref(d->pkAuthority);
|
||||
}
|
||||
|
||||
delete d;
|
||||
}
|
||||
|
||||
void Authority::Private::init()
|
||||
{
|
||||
TQDBusError error;
|
||||
TQDBusError dbus_error;
|
||||
|
||||
g_type_init();
|
||||
|
||||
m_checkAuthorizationCancellable = g_cancellable_new();
|
||||
m_enumerateActionsCancellable = g_cancellable_new();
|
||||
m_registerAuthenticationAgentCancellable = g_cancellable_new();
|
||||
m_unregisterAuthenticationAgentCancellable = g_cancellable_new();
|
||||
m_authenticationAgentResponseCancellable = g_cancellable_new();
|
||||
m_enumerateTemporaryAuthorizationsCancellable = g_cancellable_new();
|
||||
m_revokeTemporaryAuthorizationsCancellable = g_cancellable_new();
|
||||
m_revokeTemporaryAuthorizationCancellable = g_cancellable_new();
|
||||
|
||||
#ifndef POLKIT_TQT_1_COMPATIBILITY_MODE
|
||||
GError *gerror = NULL;
|
||||
#endif
|
||||
if (pkAuthority == NULL) {
|
||||
#ifndef POLKIT_TQT_1_COMPATIBILITY_MODE
|
||||
pkAuthority = polkit_authority_get_sync(NULL, &gerror);
|
||||
if (gerror != NULL) {
|
||||
setError(E_GetAuthority, gerror->message);
|
||||
g_error_free(gerror);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
pkAuthority = polkit_authority_get();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (pkAuthority == NULL) {
|
||||
#ifdef POLKIT_TQT_1_COMPATIBILITY_MODE
|
||||
(E_GetAuthority);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// connect changed signal
|
||||
g_signal_connect(G_OBJECT(pkAuthority), "changed", G_CALLBACK(pk_config_changed), NULL);
|
||||
|
||||
// need to listen to NameOwnerChanged
|
||||
dbusSignalAdd("org.freedesktop.DBus", "/", "org.freedesktop.DBus", "NameOwnerChanged");
|
||||
|
||||
TQString consoleKitService("org.freedesktop.ConsoleKit");
|
||||
TQString consoleKitManagerPath("/org/freedesktop/ConsoleKit/Manager");
|
||||
TQString consoleKitManagerInterface("org.freedesktop.ConsoleKit.Manager");
|
||||
TQString consoleKitSeatInterface("org.freedesktop.ConsoleKit.Seat");
|
||||
|
||||
// first, add signals SeadAdded and SeatRemoved from ConsoleKit Manager
|
||||
dbusSignalAdd(consoleKitService, consoleKitManagerPath, consoleKitManagerInterface, "SeatAdded");
|
||||
dbusSignalAdd(consoleKitService, consoleKitManagerPath, consoleKitManagerInterface, "SeatRemoved");
|
||||
|
||||
// then we need to extract all seats from ConsoleKit
|
||||
TQDBusMessage msg = TQDBusMessage::createMethodCall(consoleKitService, consoleKitManagerPath, consoleKitManagerInterface, "GetSeats");
|
||||
msg = TQDBusConnection::systemBus().call(msg);
|
||||
if (!msg.arguments().isEmpty()) {
|
||||
// this method returns a list with present seats
|
||||
TQList<TQString> seats;
|
||||
qVariantValue<TQDBusArgument> (msg.arguments()[0]) >> seats;
|
||||
// it can be multiple seats present so connect all their signals
|
||||
TQ_FOREACH(const TQString &seat, seats) {
|
||||
seatSignalsConnect(seat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Authority::Private::setError(Authority::ErrorCode code, const TQString &details, bool recover)
|
||||
{
|
||||
if (recover) {
|
||||
init();
|
||||
}
|
||||
m_lastError = code;
|
||||
m_errorDetails = details;
|
||||
m_hasError = true;
|
||||
}
|
||||
|
||||
void Authority::Private::seatSignalsConnect(const TQString &seat)
|
||||
{
|
||||
TQString consoleKitService("org.freedesktop.ConsoleKit");
|
||||
TQString consoleKitSeatInterface("org.freedesktop.ConsoleKit.Seat");
|
||||
// we want to connect to all slots of the seat
|
||||
dbusSignalAdd(consoleKitService, seat, consoleKitSeatInterface, "DeviceAdded");
|
||||
dbusSignalAdd(consoleKitService, seat, consoleKitSeatInterface, "DeviceRemoved");
|
||||
dbusSignalAdd(consoleKitService, seat, consoleKitSeatInterface, "SessionAdded");
|
||||
dbusSignalAdd(consoleKitService, seat, consoleKitSeatInterface, "SessionRemoved");
|
||||
dbusSignalAdd(consoleKitService, seat, consoleKitSeatInterface, "ActiveSessionChanged");
|
||||
}
|
||||
|
||||
void Authority::Private::dbusSignalAdd(const TQString &service, const TQString &path, const TQString &interface, const TQString &name)
|
||||
{
|
||||
// FIXME: This code seems to be nonfunctional - it needs to be fixed somewhere (is it TQt BUG?)
|
||||
TQDBusConnection::systemBus().connect(service, path, interface, name,
|
||||
q, SLOT(dbusFilter(const TQDBusMessage &)));
|
||||
}
|
||||
|
||||
void Authority::Private::dbusFilter(const TQDBusMessage &message)
|
||||
{
|
||||
if (message.type() == TQDBusMessage::SignalMessage) {
|
||||
TQ_EMIT q->consoleKitDBChanged();
|
||||
|
||||
// TODO: Test this with the multiseat support
|
||||
if (message.member() == "SeatAdded") {
|
||||
seatSignalsConnect(qVariantValue<TQDBusObjectPath> (message.arguments()[0]).path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Authority::hasError() const
|
||||
{
|
||||
return d->m_hasError;
|
||||
}
|
||||
|
||||
Authority::ErrorCode Authority::lastError() const
|
||||
{
|
||||
return d->m_lastError;
|
||||
}
|
||||
|
||||
const TQString Authority::errorDetails() const
|
||||
{
|
||||
if (d->m_lastError == E_None) {
|
||||
return TQString();
|
||||
} else {
|
||||
return d->m_errorDetails;
|
||||
}
|
||||
}
|
||||
|
||||
void Authority::clearError()
|
||||
{
|
||||
d->m_hasError = false;
|
||||
d->m_lastError = E_None;
|
||||
}
|
||||
|
||||
void Authority::Private::pk_config_changed()
|
||||
{
|
||||
TQ_EMIT Authority::instance()->configChanged();
|
||||
}
|
||||
|
||||
PolkitAuthority *Authority::polkitAuthority() const
|
||||
{
|
||||
return d->pkAuthority;
|
||||
}
|
||||
|
||||
Authority::Result Authority::checkAuthorizationSync(const TQString &actionId, const Subject &subject, AuthorizationFlags flags)
|
||||
{
|
||||
PolkitAuthorizationResult *pk_result;
|
||||
GError *error = NULL;
|
||||
|
||||
if (Authority::instance()->hasError()) {
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
if (!subject.isValid()) {
|
||||
d->setError(E_WrongSubject);
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
pk_result = polkit_authority_check_authorization_sync(d->pkAuthority,
|
||||
subject.subject(),
|
||||
actionId.toAscii().data(),
|
||||
NULL,
|
||||
(PolkitCheckAuthorizationFlags)(int)flags,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
if (error != NULL) {
|
||||
d->setError(E_CheckFailed, error->message);
|
||||
g_error_free(error);
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
if (!pk_result) {
|
||||
d->setError(E_UnknownResult);
|
||||
return Unknown;
|
||||
} else {
|
||||
Authority::Result res = polkitResultToResult(pk_result);
|
||||
g_object_unref(pk_result);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
void Authority::checkAuthorization(const TQString &actionId, const Subject &subject, AuthorizationFlags flags)
|
||||
{
|
||||
if (Authority::instance()->hasError()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!subject.isValid()) {
|
||||
d->setError(E_WrongSubject);
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_check_authorization(d->pkAuthority,
|
||||
subject.subject(),
|
||||
actionId.toAscii().data(),
|
||||
NULL,
|
||||
(PolkitCheckAuthorizationFlags)(int)flags,
|
||||
d->m_checkAuthorizationCancellable,
|
||||
d->checkAuthorizationCallback, this);
|
||||
}
|
||||
|
||||
void Authority::Private::checkAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority *) user_data;
|
||||
|
||||
Q_ASSERT(authority != NULL);
|
||||
|
||||
GError *error = NULL;
|
||||
PolkitAuthorizationResult *pkResult = polkit_authority_check_authorization_finish((PolkitAuthority *) object, result, &error);
|
||||
|
||||
if (error != NULL) {
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1) {
|
||||
authority->d->setError(E_CheckFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
if (pkResult != NULL) {
|
||||
Q_EMIT authority->checkAuthorizationFinished(polkitResultToResult(pkResult));
|
||||
g_object_unref(pkResult);
|
||||
} else {
|
||||
authority->d->setError(E_UnknownResult);
|
||||
}
|
||||
}
|
||||
|
||||
void Authority::checkAuthorizationCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_checkAuthorizationCancellable)) {
|
||||
g_cancellable_cancel(d->m_checkAuthorizationCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
ActionDescription::List Authority::enumerateActionsSync()
|
||||
{
|
||||
if (Authority::instance()->hasError()) {
|
||||
return ActionDescription::List();
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
|
||||
GList *glist = polkit_authority_enumerate_actions_sync(d->pkAuthority,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
if (error != NULL) {
|
||||
d->setError(E_EnumFailed, error->message);
|
||||
g_error_free(error);
|
||||
return ActionDescription::List();
|
||||
}
|
||||
|
||||
return actionsToListAndFree(glist);
|
||||
}
|
||||
|
||||
void Authority::enumerateActions()
|
||||
{
|
||||
if (Authority::instance()->hasError()) {
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_enumerate_actions(d->pkAuthority,
|
||||
d->m_enumerateActionsCancellable,
|
||||
d->enumerateActionsCallback,
|
||||
Authority::instance());
|
||||
}
|
||||
|
||||
void Authority::Private::enumerateActionsCallback(GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority *) user_data;
|
||||
Q_ASSERT(authority != NULL);
|
||||
GError *error = NULL;
|
||||
GList *list = polkit_authority_enumerate_actions_finish((PolkitAuthority *) object, result, &error);
|
||||
if (error != NULL) {
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1) {
|
||||
authority->d->setError(E_EnumFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
TQ_EMIT authority->enumerateActionsFinished(actionsToListAndFree(list));
|
||||
}
|
||||
|
||||
void Authority::enumerateActionsCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_enumerateActionsCancellable)) {
|
||||
g_cancellable_cancel(d->m_enumerateActionsCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
bool Authority::registerAuthenticationAgentSync(const Subject &subject, const TQString &locale, const TQString &objectPath)
|
||||
{
|
||||
if (Authority::instance()->hasError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
gboolean result;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!subject.isValid()) {
|
||||
d->setError(E_WrongSubject);
|
||||
return false;
|
||||
}
|
||||
|
||||
result = polkit_authority_register_authentication_agent_sync(d->pkAuthority,
|
||||
subject.subject(), locale.toAscii().data(),
|
||||
objectPath.toAscii().data(), NULL, &error);
|
||||
|
||||
if (error) {
|
||||
d->setError(E_RegisterFailed, error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::registerAuthenticationAgent(const Subject &subject, const TQString &locale, const TQString &objectPath)
|
||||
{
|
||||
if (Authority::instance()->hasError()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!subject.isValid()) {
|
||||
d->setError(E_WrongSubject);
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_register_authentication_agent(d->pkAuthority,
|
||||
subject.subject(),
|
||||
locale.toAscii().data(),
|
||||
objectPath.toAscii().data(),
|
||||
d->m_registerAuthenticationAgentCancellable,
|
||||
d->registerAuthenticationAgentCallback,
|
||||
this);
|
||||
}
|
||||
|
||||
void Authority::Private::registerAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority *) user_data;
|
||||
Q_ASSERT(authority != NULL);
|
||||
GError *error = NULL;
|
||||
bool res = polkit_authority_register_authentication_agent_finish((PolkitAuthority *) object, result, &error);
|
||||
if (error != NULL) {
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1) {
|
||||
authority->d->setError(E_EnumFailed , error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
TQ_EMIT authority->registerAuthenticationAgentFinished(res);
|
||||
}
|
||||
|
||||
void Authority::registerAuthenticationAgentCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_registerAuthenticationAgentCancellable)) {
|
||||
g_cancellable_cancel(d->m_registerAuthenticationAgentCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
bool Authority::unregisterAuthenticationAgentSync(const Subject &subject, const TQString &objectPath)
|
||||
{
|
||||
if (d->pkAuthority) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!subject.isValid()) {
|
||||
d->setError(E_WrongSubject);
|
||||
return false;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
|
||||
bool result = polkit_authority_unregister_authentication_agent_sync(d->pkAuthority,
|
||||
subject.subject(),
|
||||
objectPath.toUtf8().data(),
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
if (error != NULL) {
|
||||
d->setError(E_UnregisterFailed, error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::unregisterAuthenticationAgent(const Subject &subject, const TQString &objectPath)
|
||||
{
|
||||
if (Authority::instance()->hasError()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!subject.isValid()) {
|
||||
d->setError(E_WrongSubject);
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_unregister_authentication_agent(d->pkAuthority,
|
||||
subject.subject(),
|
||||
objectPath.toUtf8().data(),
|
||||
d->m_unregisterAuthenticationAgentCancellable,
|
||||
d->unregisterAuthenticationAgentCallback,
|
||||
this);
|
||||
}
|
||||
|
||||
void Authority::Private::unregisterAuthenticationAgentCallback(GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority *) user_data;
|
||||
Q_ASSERT(authority);
|
||||
GError *error = NULL;
|
||||
bool res = polkit_authority_unregister_authentication_agent_finish((PolkitAuthority *) object, result, &error);
|
||||
if (error != NULL) {
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1) {
|
||||
authority->d->setError(E_UnregisterFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
TQ_EMIT authority->unregisterAuthenticationAgentFinished(res);
|
||||
}
|
||||
|
||||
void Authority::unregisterAuthenticationAgentCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_unregisterAuthenticationAgentCancellable)) {
|
||||
g_cancellable_cancel(d->m_unregisterAuthenticationAgentCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
bool Authority::authenticationAgentResponseSync(const TQString &cookie, const Identity &identity)
|
||||
{
|
||||
if (Authority::instance()->hasError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cookie.isEmpty() || !identity.isValid()) {
|
||||
d->setError(E_CookieOrIdentityEmpty);
|
||||
return false;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
|
||||
bool result = polkit_authority_authentication_agent_response_sync(d->pkAuthority,
|
||||
cookie.toUtf8().data(),
|
||||
identity.identity(),
|
||||
NULL,
|
||||
&error);
|
||||
if (error != NULL) {
|
||||
d->setError(E_AgentResponseFailed, error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::authenticationAgentResponse(const TQString &cookie, const Identity &identity)
|
||||
{
|
||||
if (Authority::instance()->hasError()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cookie.isEmpty() || !identity.isValid()) {
|
||||
d->setError(E_CookieOrIdentityEmpty);
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_authentication_agent_response(d->pkAuthority,
|
||||
cookie.toUtf8().data(),
|
||||
identity.identity(),
|
||||
d->m_authenticationAgentResponseCancellable,
|
||||
d->authenticationAgentResponseCallback,
|
||||
this);
|
||||
}
|
||||
|
||||
void Authority::Private::authenticationAgentResponseCallback(GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority *) user_data;
|
||||
Q_ASSERT(authority);
|
||||
GError *error = NULL;
|
||||
bool res = polkit_authority_authentication_agent_response_finish((PolkitAuthority *) object, result, &error);
|
||||
if (error != NULL) {
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1) {
|
||||
authority->d->setError(E_AgentResponseFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
TQ_EMIT authority->authenticationAgentResponseFinished(res);
|
||||
}
|
||||
|
||||
void Authority::authenticationAgentResponseCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_authenticationAgentResponseCancellable)) {
|
||||
g_cancellable_cancel(d->m_authenticationAgentResponseCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
TemporaryAuthorization::List Authority::enumerateTemporaryAuthorizationsSync(const Subject &subject)
|
||||
{
|
||||
TemporaryAuthorization::List result;
|
||||
|
||||
GError *error = NULL;
|
||||
GList *glist = polkit_authority_enumerate_temporary_authorizations_sync(d->pkAuthority,
|
||||
subject.subject(),
|
||||
NULL,
|
||||
&error);
|
||||
if (error != NULL) {
|
||||
d->setError(E_EnumFailed, error->message);
|
||||
g_error_free(error);
|
||||
return result;
|
||||
}
|
||||
|
||||
GList *glist2;
|
||||
for (glist2 = glist; glist2 != NULL; glist2 = g_list_next(glist2)) {
|
||||
result.append(TemporaryAuthorization((PolkitTemporaryAuthorization *) glist2->data));
|
||||
g_object_unref(glist2->data);
|
||||
}
|
||||
|
||||
g_list_free(glist);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::Private::enumerateTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority *) user_data;
|
||||
Q_ASSERT(authority);
|
||||
GError *error = NULL;
|
||||
|
||||
GList *glist = polkit_authority_enumerate_temporary_authorizations_finish((PolkitAuthority *) object, result, &error);
|
||||
|
||||
if (error != NULL) {
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1) {
|
||||
authority->d->setError(E_EnumFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
TemporaryAuthorization::List res;
|
||||
GList *glist2;
|
||||
for (glist2 = glist; glist2 != NULL; glist2 = g_list_next(glist2)) {
|
||||
res.append(TemporaryAuthorization((PolkitTemporaryAuthorization *) glist2->data));
|
||||
g_object_unref(glist2->data);
|
||||
}
|
||||
|
||||
g_list_free(glist);
|
||||
|
||||
TQ_EMIT authority->enumerateTemporaryAuthorizationsFinished(res);
|
||||
}
|
||||
|
||||
void Authority::enumerateTemporaryAuthorizationsCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_enumerateTemporaryAuthorizationsCancellable)) {
|
||||
g_cancellable_cancel(d->m_enumerateTemporaryAuthorizationsCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
bool Authority::revokeTemporaryAuthorizationsSync(const Subject &subject)
|
||||
{
|
||||
bool result;
|
||||
if (Authority::instance()->hasError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
result = polkit_authority_revoke_temporary_authorizations_sync(d->pkAuthority,
|
||||
subject.subject(),
|
||||
NULL,
|
||||
&error);
|
||||
if (error != NULL) {
|
||||
d->setError(E_RevokeFailed, error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::revokeTemporaryAuthorizations(const Subject &subject)
|
||||
{
|
||||
if (Authority::instance()->hasError()) {
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_revoke_temporary_authorizations(d->pkAuthority,
|
||||
subject.subject(),
|
||||
d->m_revokeTemporaryAuthorizationsCancellable,
|
||||
d->revokeTemporaryAuthorizationsCallback,
|
||||
this);
|
||||
}
|
||||
|
||||
void Authority::Private::revokeTemporaryAuthorizationsCallback(GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority *) user_data;
|
||||
Q_ASSERT(authority != NULL);
|
||||
GError *error = NULL;
|
||||
|
||||
bool res = polkit_authority_revoke_temporary_authorizations_finish((PolkitAuthority *) object, result, &error);
|
||||
|
||||
if (error != NULL) {
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1) {
|
||||
authority->d->setError(E_RevokeFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
TQ_EMIT authority->revokeTemporaryAuthorizationsFinished(res);
|
||||
}
|
||||
|
||||
void Authority::revokeTemporaryAuthorizationsCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_revokeTemporaryAuthorizationsCancellable)) {
|
||||
g_cancellable_cancel(d->m_revokeTemporaryAuthorizationsCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
bool Authority::revokeTemporaryAuthorizationSync(const TQString &id)
|
||||
{
|
||||
bool result;
|
||||
if (Authority::instance()->hasError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
result = polkit_authority_revoke_temporary_authorization_by_id_sync(d->pkAuthority,
|
||||
id.toUtf8().data(),
|
||||
NULL,
|
||||
&error);
|
||||
if (error != NULL) {
|
||||
d->setError(E_RevokeFailed, error->message);
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Authority::revokeTemporaryAuthorization(const TQString &id)
|
||||
{
|
||||
if (Authority::instance()->hasError()) {
|
||||
return;
|
||||
}
|
||||
|
||||
polkit_authority_revoke_temporary_authorization_by_id(d->pkAuthority,
|
||||
id.toUtf8().data(),
|
||||
d->m_revokeTemporaryAuthorizationCancellable,
|
||||
d->revokeTemporaryAuthorizationCallback,
|
||||
this);
|
||||
}
|
||||
|
||||
void Authority::Private::revokeTemporaryAuthorizationCallback(GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
Authority *authority = (Authority *) user_data;
|
||||
Q_ASSERT(authority != NULL);
|
||||
GError *error = NULL;
|
||||
|
||||
bool res = polkit_authority_revoke_temporary_authorization_by_id_finish((PolkitAuthority *) object, result, &error);
|
||||
|
||||
if (error != NULL) {
|
||||
// We don't want to set error if this is cancellation of some action
|
||||
if (error->code != 1) {
|
||||
authority->d->setError(E_RevokeFailed, error->message);
|
||||
}
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
TQ_EMIT authority->revokeTemporaryAuthorizationFinished(res);
|
||||
}
|
||||
|
||||
void Authority::revokeTemporaryAuthorizationCancel()
|
||||
{
|
||||
if (!g_cancellable_is_cancelled(d->m_revokeTemporaryAuthorizationCancellable)) {
|
||||
g_cancellable_cancel(d->m_revokeTemporaryAuthorizationCancellable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "polkittqt1-authority.moc"
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Radek Novacek <rnovacek@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "polkittqt1-details.h"
|
||||
|
||||
#include <TQtCore/TQStringList>
|
||||
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
class Details::Data : public TQSharedData
|
||||
{
|
||||
public:
|
||||
Data() {}
|
||||
Data(const Data &other)
|
||||
: TQSharedData(other)
|
||||
, polkitDetails(other.polkitDetails)
|
||||
{
|
||||
g_object_ref(polkitDetails);
|
||||
}
|
||||
~Data()
|
||||
{
|
||||
g_object_unref(polkitDetails);
|
||||
}
|
||||
|
||||
PolkitDetails *polkitDetails;
|
||||
};
|
||||
|
||||
Details::Details()
|
||||
: d(new Data)
|
||||
{
|
||||
g_type_init();
|
||||
d->polkitDetails = polkit_details_new();
|
||||
}
|
||||
|
||||
Details::Details(PolkitDetails *pkDetails)
|
||||
: d(new Data)
|
||||
{
|
||||
g_type_init();
|
||||
d->polkitDetails = pkDetails;
|
||||
}
|
||||
|
||||
Details::~Details()
|
||||
{
|
||||
}
|
||||
|
||||
Details& Details::operator=(const PolkitTQt::Details& other)
|
||||
{
|
||||
d = other.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TQString Details::lookup(const TQString &key) const
|
||||
{
|
||||
const gchar *result = polkit_details_lookup(d->polkitDetails, key.toUtf8().data());
|
||||
if (result != NULL) {
|
||||
return TQString::fromUtf8(result);
|
||||
} else {
|
||||
return TQString();
|
||||
}
|
||||
}
|
||||
|
||||
void Details::insert(const TQString &key, const TQString &value)
|
||||
{
|
||||
polkit_details_insert(d->polkitDetails, key.toUtf8().data(), value.toUtf8().data());
|
||||
}
|
||||
|
||||
TQStringList Details::keys() const
|
||||
{
|
||||
gchar **result = polkit_details_get_keys(d->polkitDetails);
|
||||
TQStringList list;
|
||||
int len = g_strv_length(result);
|
||||
for (int i = 0; i < len; i++) {
|
||||
list.append(TQString::fromUtf8(result[i]));
|
||||
}
|
||||
g_strfreev(result);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
@ -1,227 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Polkit-tqt project
|
||||
* Copyright (C) 2009 Lukas Tinkl <ltinkl@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "polkittqt1-identity.h"
|
||||
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
#include <TQtCore/TQDebug>
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
class Identity::Data : public TQSharedData
|
||||
{
|
||||
public:
|
||||
Data() : identity(0) {}
|
||||
Data(const Data& other)
|
||||
: TQSharedData(other)
|
||||
, identity(other.identity)
|
||||
{
|
||||
if (identity) {
|
||||
g_object_ref(identity);
|
||||
}
|
||||
}
|
||||
~Data()
|
||||
{
|
||||
if (identity) {
|
||||
g_object_unref(identity);
|
||||
}
|
||||
}
|
||||
|
||||
PolkitIdentity *identity;
|
||||
};
|
||||
|
||||
Identity::Identity()
|
||||
: d(new Data)
|
||||
{
|
||||
g_type_init();
|
||||
}
|
||||
|
||||
Identity::Identity(PolkitIdentity *polkitIdentity)
|
||||
: d(new Data)
|
||||
{
|
||||
g_type_init();
|
||||
d->identity = polkitIdentity;
|
||||
|
||||
if (d->identity) {
|
||||
g_object_ref(d->identity);
|
||||
}
|
||||
}
|
||||
|
||||
Identity::Identity(const PolkitTQt::Identity& other)
|
||||
: d(other.d)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Identity::~Identity()
|
||||
{
|
||||
}
|
||||
|
||||
Identity& Identity::operator=(const PolkitTQt::Identity& other)
|
||||
{
|
||||
d = other.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Identity::isValid() const
|
||||
{
|
||||
return d->identity != NULL;
|
||||
}
|
||||
|
||||
PolkitIdentity *Identity::identity() const
|
||||
{
|
||||
return d->identity;
|
||||
}
|
||||
|
||||
void Identity::setIdentity(PolkitIdentity *identity)
|
||||
{
|
||||
if (d->identity == identity) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->identity) {
|
||||
g_object_unref(d->identity);
|
||||
}
|
||||
|
||||
d->identity = identity;
|
||||
|
||||
if (d->identity) {
|
||||
g_object_ref(d->identity);
|
||||
}
|
||||
}
|
||||
|
||||
TQString Identity::toString() const
|
||||
{
|
||||
Q_ASSERT(d->identity);
|
||||
return TQString::fromUtf8(polkit_identity_to_string(d->identity));
|
||||
}
|
||||
|
||||
Identity Identity::fromString(const TQString &string)
|
||||
{
|
||||
GError *error = NULL;
|
||||
PolkitIdentity *pkIdentity = polkit_identity_from_string(string.toUtf8().data(), &error);
|
||||
if (error != NULL) {
|
||||
tqWarning() << TQString("Cannot create Identity from string: %1").arg(error->message);
|
||||
return Identity();
|
||||
}
|
||||
return Identity(pkIdentity);
|
||||
}
|
||||
|
||||
UnixGroupIdentity Identity::toUnixGroupIdentity()
|
||||
{
|
||||
UnixGroupIdentity *ugid = static_cast< UnixGroupIdentity* >(this);
|
||||
if (!ugid) {
|
||||
return UnixGroupIdentity();
|
||||
}
|
||||
|
||||
return *ugid;
|
||||
}
|
||||
|
||||
UnixUserIdentity Identity::toUnixUserIdentity()
|
||||
{
|
||||
UnixUserIdentity *uuid = static_cast< UnixUserIdentity* >(this);
|
||||
if (!uuid) {
|
||||
return UnixUserIdentity();
|
||||
}
|
||||
|
||||
return *uuid;
|
||||
}
|
||||
|
||||
UnixUserIdentity::UnixUserIdentity(const TQString &name)
|
||||
: Identity()
|
||||
{
|
||||
GError *error = NULL;
|
||||
setIdentity(polkit_unix_user_new_for_name(name.toUtf8().data(), &error));
|
||||
if (error != NULL) {
|
||||
tqWarning() << TQString("Cannot create UnixUserIdentity: %1").arg(error->message);
|
||||
setIdentity(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
UnixUserIdentity::UnixUserIdentity(uid_t uid)
|
||||
: Identity()
|
||||
{
|
||||
setIdentity(polkit_unix_user_new(uid));
|
||||
}
|
||||
|
||||
UnixUserIdentity::UnixUserIdentity(PolkitUnixUser *pkUnixUser)
|
||||
: Identity((PolkitIdentity *)pkUnixUser)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UnixUserIdentity::UnixUserIdentity()
|
||||
: Identity()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uid_t UnixUserIdentity::uid() const
|
||||
{
|
||||
return polkit_unix_user_get_uid((PolkitUnixUser *) identity());
|
||||
}
|
||||
|
||||
void UnixUserIdentity::setUid(uid_t uid)
|
||||
{
|
||||
polkit_unix_user_set_uid((PolkitUnixUser *) identity(), uid);
|
||||
}
|
||||
|
||||
UnixGroupIdentity::UnixGroupIdentity(const TQString &name)
|
||||
: Identity()
|
||||
{
|
||||
GError *error = NULL;
|
||||
setIdentity(polkit_unix_group_new_for_name(name.toUtf8().data(), &error));
|
||||
if (error != NULL) {
|
||||
tqWarning() << TQString("Cannot create UnixGroupIdentity: %1").arg(error->message);
|
||||
setIdentity(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
UnixGroupIdentity::UnixGroupIdentity(gid_t gid)
|
||||
: Identity()
|
||||
{
|
||||
setIdentity(polkit_unix_group_new(gid));
|
||||
}
|
||||
|
||||
UnixGroupIdentity::UnixGroupIdentity(PolkitUnixGroup *pkUnixGroup)
|
||||
: Identity((PolkitIdentity *) pkUnixGroup)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UnixGroupIdentity::UnixGroupIdentity()
|
||||
: Identity()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
gid_t UnixGroupIdentity::gid() const
|
||||
{
|
||||
return polkit_unix_group_get_gid((PolkitUnixGroup *) identity());
|
||||
}
|
||||
|
||||
void UnixGroupIdentity::setGid(gid_t gid)
|
||||
{
|
||||
polkit_unix_group_set_gid((PolkitUnixGroup *) identity(), gid);
|
||||
}
|
||||
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* This file is part of the PolKit1-tqt project
|
||||
* Copyright (C) 2009 Radek Novacek <rnovacek@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "polkittqt1-temporaryauthorization.h"
|
||||
#include "polkittqt1-authority.h"
|
||||
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
namespace PolkitTQt
|
||||
{
|
||||
|
||||
class TemporaryAuthorization::Data : public TQSharedData
|
||||
{
|
||||
public:
|
||||
Data() {}
|
||||
Data(const Data& other)
|
||||
: TQSharedData(other)
|
||||
, id(other.id)
|
||||
, actionId(other.actionId)
|
||||
, subject(other.subject)
|
||||
, timeObtained(other.timeObtained)
|
||||
, timeExpires(other.timeExpires)
|
||||
{
|
||||
}
|
||||
~Data() {}
|
||||
|
||||
TQString id;
|
||||
TQString actionId;
|
||||
Subject subject;
|
||||
TQDateTime timeObtained;
|
||||
TQDateTime timeExpires;
|
||||
};
|
||||
|
||||
TemporaryAuthorization::TemporaryAuthorization(PolkitTemporaryAuthorization *pkTemporaryAuthorization)
|
||||
: d(new Data)
|
||||
{
|
||||
g_type_init();
|
||||
d->id = TQString::fromUtf8(polkit_temporary_authorization_get_id(pkTemporaryAuthorization));
|
||||
d->actionId = TQString::fromUtf8(polkit_temporary_authorization_get_action_id(pkTemporaryAuthorization));
|
||||
d->subject = Subject::fromString(polkit_subject_to_string(polkit_temporary_authorization_get_subject(pkTemporaryAuthorization)));
|
||||
d->timeObtained = TQDateTime::fromTime_t(polkit_temporary_authorization_get_time_obtained(pkTemporaryAuthorization));
|
||||
d->timeExpires = TQDateTime::fromTime_t(polkit_temporary_authorization_get_time_expires(pkTemporaryAuthorization));
|
||||
g_object_unref(pkTemporaryAuthorization);
|
||||
}
|
||||
|
||||
TemporaryAuthorization::TemporaryAuthorization(const PolkitTQt::TemporaryAuthorization& other)
|
||||
: d(other.d)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TemporaryAuthorization::TemporaryAuthorization()
|
||||
: d(new Data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TemporaryAuthorization& TemporaryAuthorization::operator=(const PolkitTQt::TemporaryAuthorization& other)
|
||||
{
|
||||
d = other.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TemporaryAuthorization::~TemporaryAuthorization()
|
||||
{
|
||||
}
|
||||
|
||||
TQString TemporaryAuthorization::id() const
|
||||
{
|
||||
return d->id;
|
||||
}
|
||||
|
||||
TQString TemporaryAuthorization::actionId() const
|
||||
{
|
||||
return d->actionId;
|
||||
}
|
||||
|
||||
Subject TemporaryAuthorization::subject() const
|
||||
{
|
||||
//tqFatal(polkit_subject_to_string(polkit_temporary_authorization_get_subject(d->temporaryAuthorization)));
|
||||
return d->subject;//Subject::fromString(polkit_subject_to_string(d->subject));
|
||||
}
|
||||
|
||||
TQDateTime TemporaryAuthorization::obtainedAt() const
|
||||
{
|
||||
return d->timeObtained;
|
||||
}
|
||||
|
||||
TQDateTime TemporaryAuthorization::expirationTime() const
|
||||
{
|
||||
return d->timeExpires;
|
||||
}
|
||||
|
||||
bool TemporaryAuthorization::revoke()
|
||||
{
|
||||
Authority::instance()->revokeTemporaryAuthorization(id());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1 +1 @@
|
||||
#include "../polkittqt1-actiondescription.h"
|
||||
#include "../polkit-tqt-actiondescription.h"
|
||||
|
@ -1 +1 @@
|
||||
#include "../polkittqt1-authority.h"
|
||||
#include "../polkit-tqt-authority.h"
|
||||
|
@ -1 +1 @@
|
||||
#include "../polkittqt1-details.h"
|
||||
#include "../polkit-tqt-details.h"
|
||||
|
@ -1 +1 @@
|
||||
#include "../polkittqt1-identity.h"
|
||||
#include "../polkit-tqt-identity.h"
|
||||
|
@ -1 +1 @@
|
||||
#include "../polkittqt1-temporaryauthorization.h"
|
||||
#include "../polkit-tqt-temporaryauthorization.h"
|
||||
|
Loading…
Reference in new issue