#include #include #include #include #include #include #include using namespace std; int main(int argc,char * argv[]) { if(argc<3) { throw runtime_error("No enough parameters"); } string source(argv[1]); string destination(argv[2]); Glib::init(); Gio::init(); Glib::RefPtr connection = Gio::DBus::Connection::get_sync(Gio::DBus::BUS_TYPE_SYSTEM); if(!connection) { throw runtime_error("Failed to connect to system bus"); } Glib::RefPtr proxy; proxy = Gio::DBus::Proxy::create_sync(connection, "org.freedesktop.PolicyKit1", "/org/freedesktop/PolicyKit1/Authority", "org.freedesktop.PolicyKit1.Authority"); try { //parameters vector parameters; //subject vector subject; Glib::Variant kind=Glib::Variant::create("unix-process"); map kind_details; kind_details["pid"]=Glib::Variant::create(getppid()); //parent process id kind_details["start-time"]=Glib::Variant::create(0); subject.push_back(kind); subject.push_back(Glib::Variant>::create(kind_details)); parameters.push_back(Glib::VariantContainerBase::create_tuple(subject)); //action id Glib::Variant action_id=Glib::Variant::create("net.lliurex.apt.write-sources-list"); parameters.push_back(action_id); //details map details; parameters.push_back(Glib::Variant>::create(details)); //flags Glib::Variant flags=Glib::Variant::create(1); parameters.push_back(flags); //cancellation_id Glib::Variant cancellation_id=Glib::Variant::create(""); parameters.push_back(cancellation_id); Glib::VariantContainerBase param_container = Glib::VariantContainerBase::create_tuple(parameters); //sync call, 60 seconds timeout Glib::VariantContainerBase ret_base=proxy->call_sync("CheckAuthorization",param_container,60000); Glib::VariantContainerBase ret; ret_base.get_child(ret,0); Glib::Variant is_authorized; Glib::Variant is_challenged; ret.get_child(is_authorized,0); ret.get_child(is_challenged,1); if(is_authorized.get()) { cout<<"Authorization success!"< fsource; Glib::RefPtr fdestination; fsource=Gio::File::create_for_path(source); fdestination=Gio::File::create_for_path(destination); fsource->copy(fdestination,Gio::FILE_COPY_OVERWRITE); } else { throw runtime_error("Authorization failed"); } } catch(Gio::DBus::Error e) { cerr<<"Dbus Error: "<