Author: lslezak Date: Fri Jul 18 08:20:06 2008 New Revision: 49236 URL: http://svn.opensuse.org/viewcvs/yast?rev=49236&view=rev Log: - make argument part of the PolicyKit action ID for some generic agents (like .target) Modified: branches/tmp/lslezak/workshop/core/liby2dbus/src/PolKit.cc Modified: branches/tmp/lslezak/workshop/core/liby2dbus/src/PolKit.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/liby2dbus/src/PolKit.cc?rev=49236&r1=49235&r2=49236&view=diff ============================================================================== --- branches/tmp/lslezak/workshop/core/liby2dbus/src/PolKit.cc (original) +++ branches/tmp/lslezak/workshop/core/liby2dbus/src/PolKit.cc Fri Jul 18 08:20:06 2008 @@ -59,27 +59,40 @@ if (s.empty()) return s; - std::string ret(s); - for (std::string::size_type i = 0; i < ret.length(); ++i) + std::string ret; + // reserve enough space in advance, but not more than 255 characters + ret.reserve(s.size() & 255); + + bool was_invalid_char = false; + + for (std::string::size_type i = 0; i < s.length(); ++i) { - char ch = ret[i]; + char ch = s[i]; // skip valid charcters if (islower(ch) || isdigit(ch) || ch == '.' || ch == '-') - continue; - + { + ret.push_back(ch); + was_invalid_char = false; + } // convert uppercase to lowercase - if (isupper(ch)) - ret[i] = static_cast<char>(tolower(ch)); + else if (isupper(ch)) + { + ret.push_back(tolower(ch)); + was_invalid_char = false; + } else - // replace invalid characters - ret[i] = '-'; - } + { + if (!was_invalid_char) + { + // replace invalid characters + ret.push_back('-'); + was_invalid_char = true; + } + } - // max. length is 255 - if (ret.size() > 255) - { - ret = std::string(ret, 0, 255); + if (ret.size() == 255) + break; } return ret; @@ -88,11 +101,20 @@ std::string PolKit::createActionId(const std::string &prefix, const std::string &path, const std::string &method, const std::string &arg, const std::string &opt) { - std::string action_id(prefix + path + "." + method); + std::string action_id(prefix + "." + method + path); + + y2internal("Method: %s", method.c_str()); - // TODO: use arg and opt for gereric agents (like .target.bash) to allow only some arguments + // use arg and opt for generic agents (like .target.bash) to allow only some arguments + if(::strncmp(path.c_str(), ".target.", ::strlen(".target.")) == 0 || + ::strncmp(path.c_str(), ".background.", ::strlen(".background.")) == 0 || + ::strncmp(path.c_str(), ".process.", ::strlen(".process.")) == 0 || + method == "RegisterAgent") + { + action_id += arg + opt; + } - // TODO actionID must contain only [a-z][0-9] and .- characters, max. length is 255 characters + // actionID must contain only [a-z][0-9] and .- characters, max. length is 255 characters action_id = makeValidActionID(action_id); return action_id; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org