Ticket #44655: AuthServicesBackend.patch

File AuthServicesBackend.patch, 6.4 KB (added by RJVB (René Bertin), 10 years ago)

diff for AuthServicesBackend.cpp and kauthaction.cpp

  • kdelibs-4.12.5//kdecore/auth/backends/mac/

    old new  
    11/*
    22*   Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com>
     3*   Modifications (C) 2014 René Bertin <rjvbertin@gmail.com>
    34*
    45*   This program is free software; you can redistribute it and/or modify
    56*   it under the terms of the GNU Lesser General Public License as published by
     
    2122#include <Security/Security.h>
    2223
    2324#include <QtCore/qplugin.h>
     25#include <QtCore/QtCore>
    2426
    2527namespace KAuth
    2628{
     
    3436    if (!s_authRef) {
    3537        AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &s_authRef);
    3638    }
    37 
    3839    return s_authRef;
    3940}
    4041
     42static OSStatus GetActionRights(const QString &action, AuthorizationFlags flags, AuthorizationRef auth=NULL)
     43{
     44    AuthorizationItem item;
     45    item.name = action.toUtf8();
     46    item.valueLength = 0;
     47    item.value = NULL;
     48    item.flags = 0;
     49
     50    AuthorizationRights rights;
     51    rights.count = 1;
     52    rights.items = &item;
     53
     54    OSStatus result = AuthorizationCopyRights( (auth)? auth : authRef(),
     55                                              &rights,
     56                                              kAuthorizationEmptyEnvironment,
     57                                              flags, NULL);
     58    return result;
     59}
     60
     61// On OS X, the suggestion is to make the helper grant the actual privilege. The app does instead a
     62// "pre-authorization", that's equivalent to look at isCallerAuthorized() in policykit.
     63// RJVB: grab the privilege from here, the client.
    4164AuthServicesBackend::AuthServicesBackend()
    4265    : AuthBackend()
    4366{
    44     setCapabilities(AuthorizeFromHelperCapability | CheckActionExistenceCapability);
     67    setCapabilities(AuthorizeFromClientCapability | CheckActionExistenceCapability);
    4568}
    4669
    4770void AuthServicesBackend::setupAction(const QString&)
     
    5174
    5275// On OS X, the suggestion is to make the helper grant the actual privilege. The app does instead a
    5376// "pre-authorization", that's equivalent to look at isCallerAuthorized() in policykit.
     77// RJVB: grab the privilege from here, the client.
    5478Action::AuthStatus AuthServicesBackend::authorizeAction(const QString &action)
    5579{
    56     return actionStatus(action);
     80    OSStatus result = GetActionRights( action, kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed );
     81//    qWarning() << "AuthServicesBackend::authorizeAction(" << action << ") AuthorizationCopyRights returned" << result;
     82    switch (result) {
     83        case errAuthorizationSuccess:
     84            return Action::Authorized;
     85        case errAuthorizationInteractionNotAllowed:
     86        default:
     87            return Action::Denied;
     88    }
    5789}
    5890
    5991Action::AuthStatus AuthServicesBackend::actionStatus(const QString &action)
    6092{
    61     AuthorizationItem item;
    62     item.name = action.toUtf8();
    63     item.valueLength = 0;
    64     item.value = NULL;
    65     item.flags = 0;
    66 
    67     AuthorizationRights rights;
    68     rights.count = 1;
    69     rights.items = &item;
    70 
    71     OSStatus result = AuthorizationCopyRights(authRef(),
    72                       &rights,
    73                       kAuthorizationEmptyEnvironment,
    74                       kAuthorizationFlagExtendRights | kAuthorizationFlagPreAuthorize,
    75                       NULL);
    76 
     93    OSStatus result = GetActionRights( action, kAuthorizationFlagExtendRights | kAuthorizationFlagPreAuthorize );
     94//    qWarning() << "AuthServicesBackend::actionStatus(" << action << ") AuthorizationCopyRights returned" << result;
    7795    switch (result) {
    7896    case errAuthorizationSuccess:
    7997        return Action::Authorized;
     
    101119
    102120    AuthorizationRef auth;
    103121
    104     if (AuthorizationCreateFromExternalForm(&ext, &auth) != noErr)
     122    if (AuthorizationCreateFromExternalForm(&ext, &auth) != noErr){
     123//        qWarning() << "AuthorizationCreateFromExternalForm(" << action << "," << callerID.constData() << ") failed";
    105124        return false;
     125    }
    106126
    107     AuthorizationItem item;
    108     item.name = action.toUtf8();
    109     item.valueLength = 0;
    110     item.value = NULL;
    111     item.flags = 0;
    112 
    113     AuthorizationRights rights;
    114     rights.count = 1;
    115     rights.items = &item;
    116 
    117     OSStatus result = AuthorizationCopyRights(auth,
    118                       &rights,
    119                       kAuthorizationEmptyEnvironment,
    120                       kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed,
    121                       NULL);
     127    OSStatus result = GetActionRights( action, kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed,
     128                      auth);
    122129
    123130    AuthorizationFree(auth, kAuthorizationFlagDefaults);
     131//    qWarning() << "AuthServicesBackend::isCallerAuthorized(" << action << "," << callerID.constData() << ") AuthorizationCopyRights returned" << result;
    124132
    125133    return result == errAuthorizationSuccess;
    126134}
    127135
     136// RJVB: OS X doesn't distinguish between "action doesn't exist" and "action not allowed". So the
     137// best thing we can do is return true and hope that the action will be created if it didn't exist...
    128138bool AuthServicesBackend::actionExists(const QString& action)
    129139{
    130140    OSStatus exists = AuthorizationRightGet(action.toUtf8(), NULL);
     141//    qWarning() << "AuthServicesBackend::actionExists(" << action << ") AuthorizationRightGet returned" << exists;
    131142
    132     return exists == errAuthorizationSuccess;
     143    return true;//exists == errAuthorizationSuccess;
    133144}
    134145
    135146}; // namespace KAuth
  • kdelibs-4.12.5//kdecore/auth/

    old new  
    356356        return executeActions(QList<Action>() << *this, NULL, helperID) ?
    357357            ActionReply::SuccessReply : ActionReply::AuthorizationDeniedReply;
    358358    } else {
     359#if defined(Q_OS_MACX) || defined(__APPLE__) || defined(__MACH__)
     360        if( BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::AuthorizeFromClientCapability ){
     361            // RJVB: authorisation through DBus seems to be flaky (at least when using the OSX keychain ... maybe because DBus
     362            // isn't built with Keychain support in MacPorts?)
     363            return ActionReply::SuccessReply;
     364        }
     365#endif //APPLE
    359366        if (hasHelper()) {
    360367            // Perform the pre auth here
    361368            if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::PreAuthActionCapability) {