agent.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. ''' Agent running in user session, responsible for asking the user about policy
  21. decisions.'''
  22. import pydbus
  23. import gi
  24. gi.require_version('Gtk', '3.0')
  25. from gi.repository import GLib
  26. import qubespolicy.rpcconfirmation
  27. class PolicyAgent(object):
  28. dbus = """
  29. <node>
  30. <interface name='org.qubesos.PolicyAgent'>
  31. <method name='Ask'>
  32. <arg type='s' name='source' direction='in'/>
  33. <arg type='s' name='service_name' direction='in'/>
  34. <arg type='as' name='targets' direction='in'/>
  35. <arg type='s' name='default_target' direction='in'/>
  36. <arg type='a{ss}' name='icons' direction='in'/>
  37. <arg type='s' name='response' direction='out'/>
  38. </method>
  39. </interface>
  40. </node>
  41. """
  42. def Ask(self, source, service_name, targets, default_target,
  43. icons):
  44. entries_info = {}
  45. for target in targets:
  46. entries_info[target] = {}
  47. entries_info[target]['icon'] = icons.get(target, None)
  48. response = qubespolicy.rpcconfirmation.confirm_rpc(
  49. entries_info, source, service_name,
  50. targets, default_target or None)
  51. return response or ''
  52. def main():
  53. loop = GLib.MainLoop()
  54. bus = pydbus.SystemBus()
  55. obj = PolicyAgent()
  56. bus.publish('org.qubesos.PolicyAgent', obj)
  57. loop.run()
  58. if __name__ == '__main__':
  59. main()