Author: lslezak Date: Fri Feb 13 13:49:28 2009 New Revision: 55495 URL: http://svn.opensuse.org/viewcvs/yast?rev=55495&view=rev Log: - SCR DBus service - use DBusServerBase as a common library, fixed interface name expansion Modified: branches/tmp/lslezak/core/configure.in.in branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.cc branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.h branches/tmp/lslezak/core/dbus/SCR_service/SCR_dbus_server.cc branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h branches/tmp/lslezak/core/dbus/namespace_service/Yast_dbus_names.h.in branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h Modified: branches/tmp/lslezak/core/configure.in.in URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/configure.in.in?rev=55495&r1=55494&r2=55495&view=diff ============================================================================== --- branches/tmp/lslezak/core/configure.in.in (original) +++ branches/tmp/lslezak/core/configure.in.in Fri Feb 13 13:49:28 2009 @@ -138,10 +138,12 @@ YAST_SCR_SERVICE=org.opensuse.yast.SCR +YAST_SCR_INTERFACE=org.opensuse.yast.SCR YAST_SCR_SERVICE_METHODS=$YAST_SCR_SERVICE.Methods # @ybindir@ expands to ${prefix}/lib/..., force full expansion here YAST_SCR_SERVICE_DIR=$ybindir AC_SUBST(YAST_SCR_SERVICE) +AC_SUBST(YAST_SCR_INTERFACE) AC_SUBST(YAST_SCR_SERVICE_METHODS) AC_SUBST(YAST_SCR_SERVICE_DIR) AC_SUBST(ACCESS_MODE) Modified: branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.cc?rev=55495&r1=55494&r2=55495&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.cc (original) +++ branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.cc Fri Feb 13 13:49:28 2009 @@ -5,6 +5,8 @@ */ +#include "ScriptingAgent.h" + #include "DBusServer.h" #include "DBusMsg.h" @@ -18,24 +20,9 @@ #define TIMEOUT 15 /* 30 secs idle timeout */ -extern "C" -{ -// nanosleep() -#include <time.h> -// stat() -#include <sys/stat.h> -} - -// ostringstream -#include <sstream> -// use atomic type in signal handler (see bnc#434509) -static sig_atomic_t finish = 0; - - -DBusServer::DBusServer() +DBusServer::DBusServer() : cb(this) { - dbus_threads_init_default(); sa = new ScriptingAgent(); } @@ -47,476 +34,201 @@ } } - -// connect to DBus, request a service name -bool DBusServer::connect() -{ - return connection.connect(DBUS_BUS_SYSTEM, YAST_SCR_SERVICE); -} - -// reset idle timer -void DBusServer::resetTimer() -{ - ::alarm(TIMEOUT); -} - -// NOTE: this is a signal handler, do only really necessary tasks here! -// be aware of non-reentrant functions! -void sig_timer(int signal, siginfo_t *info, void *data) -{ - if (signal == SIGALRM) - { - // set the finish flag for the main loop - finish = true; - } -} - -// register signal handler for idle timeout -void DBusServer::registerSignalHandler() +void DBusServer::registerFunctions() { - struct sigaction new_action, old_action; + // parameters + DBusArgument param1("parmeter1", DBusMsg::YCPValueSignature()); + DBusArgument param2("parmeter2", DBusMsg::YCPValueSignature()); + DBusArgument param3("parmeter3", DBusMsg::YCPValueSignature()); - // use sa_sigaction parameter - new_action.sa_flags = SA_SIGINFO; - new_action.sa_sigaction = &sig_timer; - ::sigemptyset(&new_action.sa_mask); + // parameter list + DBusSignature::Params p; + p.push_back(param1); - if (::sigaction(SIGALRM, &new_action, &old_action)) - { - y2error("Cannot register SIGALRM handler!"); - } -} + DBusSignature sig_0param; + sig_0param.retval = DBusArgument("ret", DBusMsg::YCPValueSignature()); -// check if clients are still running, -// remove finished clients -bool DBusServer::canFinish() -{ - for(Clients::iterator it = clients.begin(); - it != clients.end();) - { - DBusCaller caller = it->second; + DBusSignature sig_1param(sig_0param); + sig_1param.params = p; - if (!caller.isRunning()) - { - Clients::iterator remove_it(it); + DBusSignature sig_2param(sig_1param); + p.push_back(param2); + sig_2param.params = p; - // move the current iterator - it++; + DBusSignature sig_3param(sig_2param); + p.push_back(param3); + sig_3param.params = p; - y2milestone("Removing client %s (pid %d) from list", (remove_it->first).c_str(), caller.getPid()); + std::string object(SCR_OBJECT_PATH); - clients.erase(remove_it); - } - else - { - // the process is still running - // no need to check the other clients - // we have to still run for at least this client - y2debug("Client %s PID %d is still running", (it->first).c_str(), caller.getPid()); - break; - } + if (!object.empty() && object[0] == '/') + { + object.erase(object.begin()); } - // if there is no client the server can be finished - return clients.size() == 0; + // register the manager object: register_function(object, interface, method, signature, handler) + register_method(object, YAST_SCR_INTERFACE, METHOD_READ, sig_3param, cb); + register_method(object, YAST_SCR_INTERFACE, METHOD_WRITE, sig_3param, cb); + register_method(object, YAST_SCR_INTERFACE, METHOD_EXECUTE, sig_3param, cb); + register_method(object, YAST_SCR_INTERFACE, METHOD_DIR, sig_1param, cb); + register_method(object, YAST_SCR_INTERFACE, METHOD_ERROR, sig_1param, cb); + register_method(object, YAST_SCR_INTERFACE, METHOD_UNREGISTER, sig_1param, cb); + register_method(object, YAST_SCR_INTERFACE, METHOD_UNREGISTER_ALL, sig_0param, cb); + register_method(object, YAST_SCR_INTERFACE, METHOD_REGISTER_NEW, sig_0param, cb); + register_method(object, YAST_SCR_INTERFACE, METHOD_REGISTER, sig_2param, cb); + register_method(object, YAST_SCR_INTERFACE, METHOD_UNMOUNT, sig_1param, cb); } -/** - * Server that exposes a method call and waits for it to be called - */ -void DBusServer::run(bool forever) +bool DBusServer::connect() { - y2milestone("Listening for incoming DBus messages..."); + registerFunctions(); + return DBusServerBase::connect(SYSTEM, YAST_SCR_SERVICE); +} - if (forever) - y2milestone("Timer disabled"); - else - registerSignalHandler(); +DBusMsg DBusServer::handler(const DBusMsg &request) +{ + // create a reply to the message + DBusMsg reply; + reply.createReply(request); - // mainloop - while (true) + y2milestone("Received request from %s: interface: %s, method: %s, arguments: %d", request.sender().c_str(), + request.interface().c_str(), request.method().c_str(), request.arguments()); + + // check this is a method call for the right object, interface & method + if (request.type() == DBUS_MESSAGE_TYPE_METHOD_CALL + && request.interface() == YAST_SCR_INTERFACE + && request.path() == SCR_OBJECT_PATH) { - // the time is over - if (finish) - { - y2milestone("Timeout signal received"); - - if (canFinish()) - { - break; - } - else - { - // reset the flag - finish = false; - - // set a new timer - resetTimer(); - } - } + std::string method(request.method()); - // try reading a message from DBus - DBusMsg request(connection.receive()); + YCPValue arg0; + YCPPath pth; - // check if a message was received - if (request.empty()) - { - /* run the mainloop only on message or after(!) reaching the idle timeout */ - connection.setTimeout((TIMEOUT+1)*1000); /* returns on message or timeout */ - continue; - } + bool check_ok = false; - // reset the timer when a message is received - if (! forever) - resetTimer(); - - // create a reply to the message - DBusMsg reply; - - y2milestone("Received request from %s: interface: %s, method: %s", request.sender().c_str(), - request.interface().c_str(), request.method().c_str()); - - // check this is a method call for the right object, interface & method - if (request.type() == DBUS_MESSAGE_TYPE_METHOD_CALL - && request.interface() == YAST_SCR_INTERFACE - && request.path() == SCR_OBJECT_PATH) + // check missing arguments + if (method == METHOD_READ + || method == METHOD_WRITE + || method == METHOD_EXECUTE + || method == METHOD_DIR + || method == METHOD_ERROR + || method == METHOD_UNREGISTER + || method == METHOD_UNMOUNT + || method == METHOD_REGISTER) { - std::string method(request.method()); - - YCPValue arg0; - YCPPath pth; - - bool check_ok = false; - - // check missing arguments - if (method == METHOD_READ - || method == METHOD_WRITE - || method == METHOD_EXECUTE - || method == METHOD_DIR - || method == METHOD_ERROR - || method == METHOD_UNREGISTER - || method == METHOD_UNMOUNT - || method == METHOD_REGISTER) - { - if (request.arguments() == 0) - { - // return an ERROR - reply.createError(request, "Missing arguments", DBUS_ERROR_INVALID_ARGS); - } - else - { - arg0 = request.getYCPValue(0); - - if (arg0.isNull() || !arg0->isPath()) - { - // return an ERROR - reply.createError(request, "Expecting YCPPath as the first argument", DBUS_ERROR_INVALID_ARGS); - } - else - { - pth = arg0->asPath(); - check_ok = true; - } - } - } - else if (method == METHOD_UNREGISTER_ALL || method != METHOD_REGISTER_NEW) + if (request.arguments() == 0) { - check_ok = true; + // return an ERROR + reply.createError(request, "Missing arguments", DBUS_ERROR_INVALID_ARGS); } - - if (check_ok) + else { - YCPValue arg = request.getYCPValue(1); - YCPValue opt = request.getYCPValue(2); - - std::string caller(request.sender()); - -#ifdef HAVE_POLKIT - std::string arg_str, opt_str; - - if (!arg.isNull()) - { - arg_str = arg->toString(); - } - - if (!opt.isNull()) - { - opt_str = opt->toString(); - } + arg0 = request.getYCPValue(0); - // PolicyKit check - if (!isActionAllowed(caller, pth->toString(), method, arg_str, opt_str)) + if (arg0.isNull() || !arg0->isPath()) { - // access denied - reply.createError(request, "System policy does not allow you to do the action", DBUS_ERROR_ACCESS_DENIED); + // return an ERROR + reply.createError(request, "Expecting YCPPath as the first argument", DBUS_ERROR_INVALID_ARGS); } else -#endif { - y2debug("Request from: %s", caller.c_str()); - // remember the client - if (clients.find(caller) == clients.end()) - { - DBusCaller c(caller, connection); - // insert the dbus name and PID - Clients::value_type new_client(caller, c); - y2milestone("Added new client %s (pid %d)", caller.c_str(), c.getPid()); - clients.insert(new_client); - } - - - YCPValue ret; - - if (method == METHOD_READ) - ret = sa->Read(pth, arg, opt); - else if (method == METHOD_WRITE) - ret = sa->Write(pth, arg, opt); - else if (method == METHOD_EXECUTE) - ret = sa->Execute(pth, arg, opt); - else if (method == METHOD_DIR) - { - ret = sa->Dir(pth); - if (ret.isNull()) - ret = YCPList(); - } - else if (method == METHOD_ERROR) - ret = sa->Error(pth); - else if (method == METHOD_UNREGISTER) - ret = sa->UnregisterAgent(pth); - else if (method == METHOD_UNREGISTER_ALL) - ret = sa->UnregisterAllAgents(); - else if (method == METHOD_UNMOUNT) - ret = sa->UnmountAgent(pth); - else if (method == METHOD_REGISTER_NEW) - ret = sa->RegisterNewAgents(); - else if (method == METHOD_REGISTER) - ret = sa->RegisterAgent(pth, arg); - else - y2internal("Unhandled method %s", method.c_str()); - - reply.createReply(request); - - if (!ret.isNull()) - { - y2milestone("Result: %s", ret->toString().c_str()); - reply.addYCPValue(ret); - } - else - reply.addYCPValue(YCPVoid()); + pth = arg0->asPath(); + check_ok = true; } } } - // handle Introspection request from "org.freedesktop.DBus.Introspectable" "Introspect" - else if (request.isMethodCall(DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) + else if (method == METHOD_UNREGISTER_ALL || method != METHOD_REGISTER_NEW) { - y2milestone("Requesting path: %s", request.path().c_str()); - // define all exported methods here - const char *introspect = (request.path() != SCR_OBJECT_PATH) ? -// introcpection data for the root node -DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE -"<node>" -" <interface name='"DBUS_INTERFACE_INTROSPECTABLE"'>" -" <method name='Introspect'>" -" <arg name='xml_data' type='s' direction='out'/>" -" </method>" -" </interface>" -" <node name='SCR'/>" -"</node>" : - -// introcpection data for SCR node -DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE -"<node>" -" <interface name='"YAST_SCR_INTERFACE"'>" -" <method name='"METHOD_READ"'>" -" <arg name='path' type='(bsv)' direction='in'/>" -" <arg name='arg' type='(bsv)' direction='in'/>" -" <arg name='opt' type='(bsv)' direction='in'/>" -" <arg name='ret' type='(bsv)' direction='out'/>" -" </method>" -" <method name='"METHOD_WRITE"'>" -" <arg name='path' type='(bsv)' direction='in'/>" -" <arg name='arg' type='(bsv)' direction='in'/>" -" <arg name='opt' type='(bsv)' direction='in'/>" -" <arg name='ret' type='(bsv)' direction='out'/>" -" </method>" -" <method name='"METHOD_EXECUTE"'>" -" <arg name='path' type='(bsv)' direction='in'/>" -" <arg name='arg' type='(bsv)' direction='in'/>" -" <arg name='opt' type='(bsv)' direction='in'/>" -" <arg name='ret' type='(bsv)' direction='out'/>" -" </method>" -" <method name='"METHOD_DIR"'>" -" <arg name='path' type='(bsv)' direction='in'/>" -" <arg name='ret' type='(bsv)' direction='out'/>" -" </method>" -" <method name='"METHOD_ERROR"'>" -" <arg name='path' type='(bsv)' direction='in'/>" -" <arg name='ret' type='(bsv)' direction='out'/>" -" </method>" -" <method name='"METHOD_UNREGISTER"'>" -" <arg name='path' type='(bsv)' direction='in'/>" -" <arg name='ret' type='(bsv)' direction='out'/>" -" </method>" -" <method name='"METHOD_UNREGISTER_ALL"'>" -" <arg name='ret' type='(bsv)' direction='out'/>" -" </method>" -" <method name='"METHOD_REGISTER_NEW"'>" -" <arg name='ret' type='(bsv)' direction='out'/>" -" </method>" -" <method name='"METHOD_REGISTER"'>" -" <arg name='path' type='(bsv)' direction='in'/>" -" <arg name='arg' type='(bsv)' direction='in'/>" -" <arg name='ret' type='(bsv)' direction='out'/>" -" </method>" -" <method name='"METHOD_UNMOUNT"'>" -" <arg name='path' type='(bsv)' direction='in'/>" -" <arg name='ret' type='(bsv)' direction='out'/>" -" </method>" -" </interface>" -" <interface name='"DBUS_INTERFACE_INTROSPECTABLE"'>" -" <method name='Introspect'>" -" <arg name='xml_data' type='s' direction='out'/>" -" </method>" -" </interface>" -"</node>"; - - // create a reply to the request - reply.createReply(request); - reply.addString(introspect); + check_ok = true; } - else if (request.type() == DBUS_MESSAGE_TYPE_METHOD_CALL) - { - y2warning("Ignoring unknown interface or method call: interface: %s, method: %s", - request.interface().c_str(), request.method().c_str()); - // report error - reply.createError(request, "Unknown object, interface or method", DBUS_ERROR_UNKNOWN_METHOD); - } - else if (request.type() == DBUS_MESSAGE_TYPE_ERROR) + y2internal("check_ok: %d", check_ok); + + if (check_ok) { - DBusError error; - dbus_error_init(&error); + YCPValue arg = request.getYCPValue(1); + YCPValue opt = request.getYCPValue(2); - dbus_set_error_from_message(&error, request.getMessage()); + std::string caller(request.sender()); - if (dbus_error_is_set(&error)) - { - y2error("Received an error: %s: %s", error.name, error.message); - } + y2debug("Request from: %s", caller.c_str()); - dbus_error_free(&error); - } - else if (request.type() == DBUS_MESSAGE_TYPE_SIGNAL) - { - y2error("Received a signal: interface: %s method: %s", request.interface().c_str(), request.method().c_str()); - } + // remember the client + register_client(caller); - // was a reply set? - if (!reply.empty()) - { - // send the reply - if (!connection.send(reply)) + YCPValue ret; + + if (method == METHOD_READ) + ret = sa->Read(pth, arg, opt); + else if (method == METHOD_WRITE) + ret = sa->Write(pth, arg, opt); + else if (method == METHOD_EXECUTE) + ret = sa->Execute(pth, arg, opt); + else if (method == METHOD_DIR) { - y2error("Cannot send the result"); + ret = sa->Dir(pth); + if (ret.isNull()) + ret = YCPList(); } + else if (method == METHOD_ERROR) + ret = sa->Error(pth); + else if (method == METHOD_UNREGISTER) + ret = sa->UnregisterAgent(pth); + else if (method == METHOD_UNREGISTER_ALL) + ret = sa->UnregisterAllAgents(); + else if (method == METHOD_UNMOUNT) + ret = sa->UnmountAgent(pth); + else if (method == METHOD_REGISTER_NEW) + ret = sa->RegisterNewAgents(); + else if (method == METHOD_REGISTER) + ret = sa->RegisterAgent(pth, arg); else + y2internal("Unhandled method %s", method.c_str()); + + if (!ret.isNull()) { - y2milestone("Flushing connection..."); - connection.flush(); - y2milestone("...done"); + y2milestone("Result: %s", ret->toString().c_str()); + reply.addYCPValue(ret); } + else + reply.addYCPValue(YCPVoid()); } - - y2milestone("Message processed"); } - y2milestone("Finishing the DBus service"); + y2internal("Finishing the callback"); + + return reply; } -#ifdef HAVE_POLKIT -// check if action is allowed by PolicyKit -bool DBusServer::isActionAllowed(const std::string &caller, const std::string &path, const std::string &method, - const std::string &arg, const std::string &opt) +DBusServer::actionList DBusServer::createActionId(const DBusMsg &msg) { - // create actionId - static const char *polkit_prefix = POLKIT_PREFIX; + actionList ret; +#ifdef HAVE_POLKIT // check the access right to all methods at first (see bnc#449794) - std::string action_id(PolKit::createActionId(polkit_prefix, "", method, "", "")); - - if (policykit.isDBusUserAuthorized(action_id, caller, connection.getConnection())) - { - y2security("User is authorized to do action %s", action_id.c_str()); - return true; - } - else - { - y2debug("User is NOT authorized to do action %s", action_id.c_str()); - } + std::string action_id(PolKit::createActionId(POLKIT_PREFIX, "", msg.method(), "", "")); - action_id = PolKit::createActionId(polkit_prefix, path, method, arg, opt); + ret.push_back(action_id); - bool ret = false; + YCPValue arg = msg.getYCPValue(1); + YCPValue opt = msg.getYCPValue(2); - // check the policy here - if (policykit.isDBusUserAuthorized(action_id, caller, connection.getConnection())) + std::string arg_str, opt_str; + + if (!arg.isNull()) { - y2security("User is authorized to do action %s", action_id.c_str()); - ret = true; + arg_str = arg->toString(); } - else + + if (!opt.isNull()) { - y2security("User is NOT authorized to do action %s", action_id.c_str()); + opt_str = opt->toString(); } - return ret; -} -#endif - + action_id = PolKit::createActionId(POLKIT_PREFIX, msg.path(), msg.method(), arg_str, opt_str); -bool DBusServer::isProcessRunning(pid_t pid) -{ - ostringstream sstr; - sstr << "/proc/" << pid; - - struct stat stat_result; - bool ret = ::stat(sstr.str().c_str(), &stat_result) == 0; + ret.push_back(action_id); +#endif - y2milestone("Process /proc/%d is running: %s", pid, ret ? "true" : "false"); return ret; } - -pid_t DBusServer::callerPid(const std::string &bus_name) -{ - pid_t pid; - DBusMsg query; - - // ask the DBus server for the PID of the caller - query.createCall(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS"/Bus", - DBUS_SERVICE_DBUS, "GetConnectionUnixProcessID"); - - query.addString(bus_name); - - // send the request - DBusMsg reply(connection.call(query)); - - // read the answer - DBusMessageIter iter; - dbus_message_iter_init(reply.getMessage(), &iter); - - int type = dbus_message_iter_get_arg_type(&iter); - y2debug("Message type: %d, %c", type, (char)type); - - if (type == DBUS_TYPE_UINT32) - { - dbus_message_iter_get_basic(&iter, &pid); - } - else - { - y2internal("Unexpected type in PID reply %d (%c)", type, (char)type); - } - - y2milestone("Message from PID %d", pid); - - return pid; -} Modified: branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.h?rev=55495&r1=55494&r2=55495&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.h (original) +++ branches/tmp/lslezak/core/dbus/SCR_service/DBusServer.h Fri Feb 13 13:49:28 2009 @@ -6,47 +6,26 @@ #ifndef DBUSSERVER_H #define DBUSSERVER_H -#include "config.h" +#include "DBusServerBase.h" -#include <dbus/dbus.h> +class ScriptingAgent; -#include "DBusConn.h" -#include "DBusCaller.h" -#include "ScriptingAgent.h" - -#ifdef HAVE_POLKIT -#include "PolKit.h" -#endif - -extern "C" -{ -#include <unistd.h> -#include <signal.h> -} - -class DBusServer +class DBusServer : public DBusServerBase { public: DBusServer(); - ~DBusServer(); + virtual ~DBusServer(); - bool connect(); - /** - * Runs the server - * @param forever for debugging, disables exiting after timeout - */ - void run(bool forever = false); + virtual bool connect(); - private: - DBusConn connection; + protected: -#ifdef HAVE_POLKIT - PolKit policykit; - bool isActionAllowed(const std::string &caller, const std::string &path, - const std::string &method, const std::string &arg, const std::string &opt); -#endif + virtual actionList createActionId(const DBusMsg &msg); + + + private: // SCR access ScriptingAgent *sa; @@ -55,13 +34,24 @@ DBusServer(const DBusServer&); DBusServer& operator=(const DBusServer&); - void resetTimer(); - void registerSignalHandler(); - bool canFinish(); + void registerFunctions(); + + DBusMsg handler(const DBusMsg &request); + + class Callback : public std::function<DBusMsg (const DBusMsg &request)> + { + DBusServer *ms; + + public: + + Callback(DBusServer *s) : ms(s) {} + ~Callback() {} - typedef std::map<std::string, DBusCaller> Clients; + DBusMsg operator()(const DBusMsg &request) + { return ms ? ms->handler(request) : DBusMsg(); } + }; - Clients clients; + Callback cb; }; Modified: branches/tmp/lslezak/core/dbus/SCR_service/SCR_dbus_server.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/SCR_service/SCR_dbus_server.cc?rev=55495&r1=55494&r2=55495&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/SCR_service/SCR_dbus_server.cc (original) +++ branches/tmp/lslezak/core/dbus/SCR_service/SCR_dbus_server.cc Fri Feb 13 13:49:28 2009 @@ -4,6 +4,8 @@ */ #include "DBusServer.h" +#include <cstring> +#include <iostream> int main(int argc, char **argv) { @@ -21,7 +23,7 @@ badopts = true; } if (badopts) - y2error ("Usage: %s [--disable-timer]", argv[0]); + std::cerr << "Usage: " << argv[0] << " [--disable-timer]\n"; bool connected = server.connect(); Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc?rev=55495&r1=55494&r2=55495&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc Fri Feb 13 13:49:28 2009 @@ -592,7 +592,7 @@ return reply; } -std::string DBusModulesServer::createActionId(const DBusMsg &msg) +DBusModulesServer::actionList DBusModulesServer::createActionId(const DBusMsg &msg) { // actionId: <prefix>.<namespace>.<method> std::string ret(msg.interface() == YAST_DBUS_MGR_INTERFACE @@ -620,6 +620,9 @@ ret = PolKit::makeValidActionID(ret); } - return ret; + actionList retlist; + retlist.push_back(ret); + + return retlist; } Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h?rev=55495&r1=55494&r2=55495&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h Fri Feb 13 13:49:28 2009 @@ -33,7 +33,7 @@ protected: - virtual std::string createActionId(const DBusMsg &msg); + virtual actionList createActionId(const DBusMsg &msg); private: Modified: branches/tmp/lslezak/core/dbus/namespace_service/Yast_dbus_names.h.in URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespace_service/Yast_dbus_names.h.in?rev=55495&r1=55494&r2=55495&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/Yast_dbus_names.h.in (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/Yast_dbus_names.h.in Fri Feb 13 13:49:28 2009 @@ -21,4 +21,10 @@ // prefix for PolicyKit action IDs - manager calls #define YAST_POLKIT_PREFIX_MANAGER "org.opensuse.yast.module_manager" + +#define YAST_DBUS_MANAGER_IMPORT_METHOD "Import" +#define YAST_DBUS_MANAGER_UNLOCK_METHOD "Unlock" +#define YAST_DBUS_MANAGER_LOCK_METHOD "Lock" + + #endif Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc?rev=55495&r1=55494&r2=55495&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.cc Fri Feb 13 13:49:28 2009 @@ -1077,3 +1077,8 @@ return DBUS_MESSAGE_TYPE_INVALID; } + +const char *DBusMsg::YCPValueSignature() +{ + return "(bsv)"; +} Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h?rev=55495&r1=55494&r2=55495&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusMsg.h Fri Feb 13 13:49:28 2009 @@ -60,6 +60,8 @@ std::string path() const; std::string sender() const; + static const char *YCPValueSignature(); + private: bool addValue(int type, void* data); Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc?rev=55495&r1=55494&r2=55495&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc Fri Feb 13 13:49:28 2009 @@ -426,46 +426,47 @@ { #ifdef HAVE_POLKIT // create actionId - std::string action_id(createActionId(msg)); - y2debug("PolicyKit check: action %s from %s", action_id.c_str(), msg.sender().c_str()); + actionList actions_id(createActionId(msg)); - bool ret = false; - - if (action_id.empty()) + if (actions_id.empty()) { // no actionId -> return the default (forbidden) - return ret; + return false; } - if (!PolKit::isValidActionID(action_id)) + for(actionList::iterator it = actions_id.begin(); + it != actions_id.end(); ++it) { - y2error("Invalid action ID: %s", action_id.c_str()); - return ret; - } + if (!PolKit::isValidActionID(*it)) + { + y2error("Invalid action ID: %s", it->c_str()); + return false; + } - // check the policy here - if (policykit.isDBusUserAuthorized(action_id, msg.sender(), connection.getConnection())) - { - y2security("User is authorized to do action %s", action_id.c_str()); - ret = true; - } - else - { - y2security("User is NOT authorized to do action %s", action_id.c_str()); + // check the policy here + if (policykit.isDBusUserAuthorized(*it, msg.sender(), connection.getConnection())) + { + y2security("User is authorized to do action %s", it->c_str()); + return true; + } + else + { + y2security("User is NOT authorized to do action %s", it->c_str()); + } } - return ret; + return false; #else // no PolicyKit -> enable action return true; #endif } -std::string DBusServerBase::createActionId(const DBusMsg &msg) +DBusServerBase::actionList DBusServerBase::createActionId(const DBusMsg &msg) { - // default implementation is empty string + // default implementation is empty list // the inherited classes should redefine it - return std::string(); + return actionList(); } void DBusServerBase::unregister_client(const std::string &bus_id) Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h?rev=55495&r1=55494&r2=55495&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h Fri Feb 13 13:49:28 2009 @@ -50,8 +50,10 @@ void unregister_client(const std::string &bus_id); void register_client(const std::string &bus_id); + typedef std::list<std::string> actionList; + // create PolicyKit action ID for the received message - virtual std::string createActionId(const DBusMsg &msg); + virtual actionList createActionId(const DBusMsg &msg); std::string service_name; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org