[yast-commit] r49109 - in /branches/tmp/lslezak/workshop/core/scr/src: DBusMsg.cc DBusServer.cc
Author: lslezak Date: Tue Jul 15 17:23:45 2008 New Revision: 49109 URL: http://svn.opensuse.org/viewcvs/yast?rev=49109&view=rev Log: - fixed argument check in the DBus server Modified: branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc branches/tmp/lslezak/workshop/core/scr/src/DBusServer.cc Modified: branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc?rev=49109&r1=49108&r2=49109&view=diff ============================================================================== --- branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc (original) +++ branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc Tue Jul 15 17:23:45 2008 @@ -257,8 +257,6 @@ { // send YCPTerm as a list: [ name [args] ] YCPTerm t = val->asTerm(); - y2internal("Sending TERM size: %d", t->size()); - y2internal("Sending TERM name: %s, list: %s", t->name().c_str(), t->args()->toString().c_str()); YCPString term_name(t->name()); YCPList term_list(t->args()); Modified: branches/tmp/lslezak/workshop/core/scr/src/DBusServer.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/scr/src/DBusServer.cc?rev=49109&r1=49108&r2=49109&view=diff ============================================================================== --- branches/tmp/lslezak/workshop/core/scr/src/DBusServer.cc (original) +++ branches/tmp/lslezak/workshop/core/scr/src/DBusServer.cc Tue Jul 15 17:23:45 2008 @@ -67,106 +67,103 @@ // check this is a method call for the right object, interface & method if (request.type() == DBUS_MESSAGE_TYPE_METHOD_CALL && request.interface() == "org.opensuse.yast.SCR.Methods" && request.path() == "/SCR") { - int args = request.arguments(); + std::string method(request.method()); - if (args == 0) - { - // return an ERROR - reply.createError(request, "Missing arguments", DBUS_ERROR_INVALID_ARGS); - } - else - { - YCPValue arg0 = request.getYCPValue(0); + YCPValue arg0; + YCPPath pth; - if (!arg0.isNull() && arg0->isPath()) - { - YCPPath pth = arg0->asPath(); + bool check_ok = false; - // DBus doesn't support YCPPath type, string is used as a workaround - std::string path_str(pth->toString()); + // check missing arguments + if (method == "Read" || method == "Write" || method == "Execute" || + method == "Dir" || method == "Error" || method == "UnregisterAgent" || + method == "UnmountAgent" || method == "RegisterAgent") + { + if (request.arguments() == 0) + { + // return an ERROR + reply.createError(request, "Missing arguments", DBUS_ERROR_INVALID_ARGS); + } + else + { + arg0 = request.getYCPValue(0); - if (path_str.empty()) + if (arg0.isNull() || !arg0->isPath()) { - reply.createError(request, "Argument 'path' is empty", DBUS_ERROR_INVALID_ARGS); + // return an ERROR + reply.createError(request, "Expecting YCPPath as the first argument", DBUS_ERROR_INVALID_ARGS); } else { - std::string method(request.method()); + pth = arg0->asPath(); + check_ok = true; + } + } + } + else if (method == "UnregisterAllAgents" || method != "RegisterNewAgents") + { + check_ok = true; + } - if (method == "Read" || method == "Write" || method == "Execute" || - method == "Dir" || method == "Error" || method == "UnregisterAgent" || - method == "UnregisterAllAgents" || method == "UnmountAgent" || - method == "RegisterNewAgents" || method == "RegisterAgent") - { - YCPValue arg = request.getYCPValue(1); - YCPValue opt = request.getYCPValue(2); + if (check_ok) + { + YCPValue arg = request.getYCPValue(1); + YCPValue opt = request.getYCPValue(2); #ifdef HAVE_POLKIT - std::string caller(request.sender()), arg_str, opt_str; + std::string caller(request.sender()), arg_str, opt_str; - if (!arg.isNull()) - { - arg_str = arg->toString(); - } - - if (!opt.isNull()) - { - opt_str = opt->toString(); - } - - // PolicyKit check - if (!isActionAllowed(caller, path_str, method, arg_str, opt_str)) - { - // access denied - reply.createError(request, "System policy does not allow you to do the action", DBUS_ERROR_ACCESS_DENIED); - } - else -#endif - { - YCPValue ret; + if (!arg.isNull()) + { + arg_str = arg->toString(); + } - if (method == "Read") - ret = sa->Read(pth, arg, opt); - else if (method == "Write") - ret = sa->Write(pth, arg, opt); - else if (method == "Execute") - ret = sa->Execute(pth, arg, opt); - else if (method == "Dir") - ret = sa->Dir(pth); - else if (method == "Error") - ret = sa->Error(pth); - else if (method == "UnregisterAgent") - ret = sa->UnregisterAgent(pth); - else if (method == "UnregisterAllAgents") - ret = sa->UnregisterAllAgents(); - else if (method == "UnmountAgent") - ret = sa->UnmountAgent(pth); - else if (method == "RegisterNewAgents") - ret = sa->RegisterNewAgents(); - else if (method == "RegisterAgent") - ret = sa->RegisterAgent(pth, arg); - else - y2internal("Unhandled method %s", method.c_str()); - - reply.createReply(request); - - if (!ret.isNull()) - { - reply.addYCPValue(ret); - } - } - } - else - { - y2warning("Unknown requested method %s", method.c_str()); - reply.createError(request, ("Unknown method: " + method).c_str(), DBUS_ERROR_UNKNOWN_METHOD); - // don't create a standard reply - } - } + if (!opt.isNull()) + { + opt_str = opt->toString(); + } + + // PolicyKit check + if (!isActionAllowed(caller, pth->toString(), method, arg_str, opt_str)) + { + // access denied + reply.createError(request, "System policy does not allow you to do the action", DBUS_ERROR_ACCESS_DENIED); } else +#endif { - reply.createError(request, "First argument must be a path", DBUS_ERROR_INVALID_ARGS); + YCPValue ret; + + if (method == "Read") + ret = sa->Read(pth, arg, opt); + else if (method == "Write") + ret = sa->Write(pth, arg, opt); + else if (method == "Execute") + ret = sa->Execute(pth, arg, opt); + else if (method == "Dir") + ret = sa->Dir(pth); + else if (method == "Error") + ret = sa->Error(pth); + else if (method == "UnregisterAgent") + ret = sa->UnregisterAgent(pth); + else if (method == "UnregisterAllAgents") + ret = sa->UnregisterAllAgents(); + else if (method == "UnmountAgent") + ret = sa->UnmountAgent(pth); + else if (method == "RegisterNewAgents") + ret = sa->RegisterNewAgents(); + else if (method == "RegisterAgent") + 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); + } } } } -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
lslezak@svn.opensuse.org