Permalink
Browse files

Added support to configure what type authentication schema to use, mi…

…nor changes to grub examples

git-svn-id: https://camelo.conectiva/repos/projetos/qtlab/mcc2@8819 aeaf0dc8-91d7-0310-8701-e1fc1a66ab8d
  • Loading branch information...
1 parent 27f7ab9 commit 0bbfe1aad98088efa77ed890ebc49985446e7ef1 wiliam committed Feb 21, 2011
View
@@ -0,0 +1,2 @@
+[policy]
+level=all
@@ -0,0 +1,8 @@
+import os
+import ConfigParser
+
+config = ConfigParser.ConfigParser()
+config.read('/usr/share/mandriva/config/mcc2.cfg')
+
+print config.get('policy', 'level')
+print type(config.get('policy', 'level'))
@@ -0,0 +1,7 @@
+import dbus
+bus = dbus.SystemBus()
+proxy = bus.get_object(
+ 'org.mandrivalinux.mcc2.Grub',
+ '/org/mandrivalinux/mcc2/Grub')
+interface = dbus.Interface(proxy, 'org.mandrivalinux.mcc2.Grub')
+print 'Default boot: %s' % interface.DefaultBoot()
@@ -4,10 +4,4 @@
'org.mandrivalinux.mcc2.Grub',
'/org/mandrivalinux/mcc2/Grub')
interface = dbus.Interface(proxy, 'org.mandrivalinux.mcc2.Grub')
-
-print 'Default boot: %s' % interface.DefaultBoot()
-print 'Password protection: %i' % interface.PasswordProtection()
-print 'Protect old mode: %i' % interface.ProtectOldMode()
-print 'Protect recue mode: %i' % interface.ProtectRescueMode()
-print 'Timeout: %i' % interface.Timeout()
-print 'Vga code: %i' % interface.VgaCode()
+print 'Password protection: %i' % interface.PasswordProtection()
@@ -0,0 +1,7 @@
+import dbus
+bus = dbus.SystemBus()
+proxy = bus.get_object(
+ 'org.mandrivalinux.mcc2.Grub',
+ '/org/mandrivalinux/mcc2/Grub')
+interface = dbus.Interface(proxy, 'org.mandrivalinux.mcc2.Grub')
+print 'Protect old mode: %i' % interface.ProtectOldMode()
@@ -0,0 +1,7 @@
+import dbus
+bus = dbus.SystemBus()
+proxy = bus.get_object(
+ 'org.mandrivalinux.mcc2.Grub',
+ '/org/mandrivalinux/mcc2/Grub')
+interface = dbus.Interface(proxy, 'org.mandrivalinux.mcc2.Grub')
+print 'Protect recue mode: %i' % interface.ProtectRescueMode()
@@ -0,0 +1,7 @@
+import dbus
+bus = dbus.SystemBus()
+proxy = bus.get_object(
+ 'org.mandrivalinux.mcc2.Grub',
+ '/org/mandrivalinux/mcc2/Grub')
+interface = dbus.Interface(proxy, 'org.mandrivalinux.mcc2.Grub')
+print 'Timeout: %i' % interface.Timeout()
@@ -0,0 +1,7 @@
+import dbus
+bus = dbus.SystemBus()
+proxy = bus.get_object(
+ 'org.mandrivalinux.mcc2.Grub',
+ '/org/mandrivalinux/mcc2/Grub')
+interface = dbus.Interface(proxy, 'org.mandrivalinux.mcc2.Grub')
+print 'Vga code: %i' % interface.VgaCode()
@@ -1,41 +1,51 @@
+import ConfigParser
import gobject
import dbus
import dbus.service
import dbus.mainloop.glib
-
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-
from mcc2.parsers.grub.GrubConfig import GrubConfig
-
from mcc2.backends.policykit import check_authorization
__all__ = ['Grub']
+
class Grub(dbus.service.Object):
def __init__(self):
self.__bus = dbus.SystemBus()
bus_name = dbus.service.BusName(
- "org.mandrivalinux.mcc2.Grub",
+ 'org.mandrivalinux.mcc2.Grub',
bus=self.__bus)
dbus.service.Object.__init__(
self,
bus_name,
- "/org/mandrivalinux/mcc2/Grub")
+ '/org/mandrivalinux/mcc2/Grub')
self.__loop = gobject.MainLoop()
self.__grub = grub = GrubConfig()
self.__grub.parse()
+ self.__action = 'org.mandrivalinux.mcc2.auth_admin_keep'
+
+ config = ConfigParser.ConfigParser()
+ config.read('/usr/share/mandriva/config/mcc2.cfg')
+ policy_level = config.get('policy', 'level')
+ if policy_level == 'application':
+ self.__action = 'org.mandrivalinux.mcc2.grub.auth_admin_keep'
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ if policy_level == 'method':
+ self.__action = None
+
+
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
out_signature='a{sv}')
def ListTitles(self):
return self.__grub.get_title_blocks()
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
in_signature='s',
out_signature='i',
sender_keyword='sender',
@@ -48,13 +58,12 @@ def ChangeDefaultBoot(self, name, sender, connection):
Return 0 if successful.
Return 1 if failed.
"""
- check_authorization(sender, connection,
- 'org.mandrivalinux.mcc2.grub.rootpassword')
+ check_authorization(sender, connection, self.__action)
return self.__grub.set_default_boot(name)
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
out_signature='v')
def DefaultBoot(self):
"""Return the name of the default booted option.
@@ -65,7 +74,7 @@ def DefaultBoot(self):
return self.__grub.get_default_boot()
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
in_signature='i',
sender_keyword='sender',
connection_keyword='connection')
@@ -74,20 +83,19 @@ def ChangeTimeout(self, timeout, sender, connection):
active = bool whether timeout is used
timeout = number of seconds
"""
- check_authorization(sender, connection,
- 'org.mandrivalinux.mcc2.grub.rootpassword')
+ check_authorization(sender, connection, self.__action)
self.__grub.set_timeout(timeout)
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
out_signature='i')
def Timeout(self):
"""Return the timeout in seconds used for Grub menu"""
return self.__grub.get_timeout()
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
in_signature='i',
sender_keyword='sender',
connection_keyword='connection')
@@ -101,14 +109,14 @@ def ChangeVgaCode(self, vga, sender, connection):
self.__grub.set_vga_code(vga)
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
out_signature='i')
def VgaCode(self):
"""Return the Grub vga code used, as integer"""
return self.__grub.get_vga_code()
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
in_signature='b',
sender_keyword='sender',
connection_keyword='connection')
@@ -119,34 +127,32 @@ def ChangePasswordProtection(self, active, sender, connection):
@return dbus.Bollean
"""
- check_authorization(sender, connection,
- 'org.mandrivalinux.mcc2.grub.rootpassword')
+ check_authorization(sender, connection, self.__action)
self.__grub.set_password_protection(active)
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
out_signature='b')
def PasswordProtection(self):
"""Boolean, returns whether the Grub menu is password protected"""
return self.__grub.get_password_protection()
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
in_signature='b',
sender_keyword='sender',
connection_keyword='connection')
def ChangeProtectRescueMode(self, active, sender, connection):
"""Change whether the alternate boot option is password protected
active = boolean
"""
- check_authorization(sender, connection,
- 'org.mandrivalinux.mcc2.grub.rootpassword')
+ check_authorization(sender, connection, self.__action)
self.__grub.Change_protect_rescuemode(active)
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
out_signature='b')
def ProtectRescueMode(self):
"""Boolean, returns whether the alternate boot option
@@ -155,28 +161,27 @@ def ProtectRescueMode(self):
return self.__grub.get_protect_rescuemode()
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
in_signature='b',
sender_keyword='sender',
connection_keyword='connection')
def ChangeProtectOldMode(self, active, sender, connection):
"""Change whether old boot options are password protected
active = boolean
"""
- check_authorization(sender, connection,
- 'org.mandrivalinux.mcc2.grub.rootpassword')
+ check_authorization(sender, connection, self.__action)
self.__grub.Change_protect_oldmode(active)
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
out_signature='b')
def ProtectOldMode(self):
"""Boolean, returns whether old boot options are password protected"""
return self.__grub.get_protect_oldmode()
- @dbus.service.method("org.mandrivalinux.mcc2.Grub",
+ @dbus.service.method('org.mandrivalinux.mcc2.Grub',
out_signature='sb',
sender_keyword='sender',
connection_keyword='connection')
@@ -187,8 +192,7 @@ def UpdatePassword(self, password, active, sender, connection):
active = boolean
password = string, must be at least four characters
"""
- check_authorization(sender, connection,
- 'org.mandrivalinux.mcc2.grub.rootpassword')
+ check_authorization(sender, connection, self.__action)
self.__grub.update_password(password, active)
@@ -1,10 +1,9 @@
+import ConfigParser
import gobject
import dbus
import dbus.service
import dbus.mainloop.glib
-
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-
from mcc2.backends.policykit import check_authorization
__all__ = ['Services']
@@ -43,11 +42,23 @@ def __init__(self):
if error.get_dbus_name() == systemd_error:
pass
- self._loop = gobject.MainLoop()
+ self.__loop = gobject.MainLoop()
self.msg = {
'not_running':'org.mandrivalinux.mcc2.Services.Error.SystemdNotRunning'
}
+ self.__action = 'org.mandrivalinux.mcc2.auth_admin_keep'
+
+ config = ConfigParser.ConfigParser()
+ config.read('/usr/share/mandriva/config/mcc2.cfg')
+ policy_level = config.get('policy', 'level')
+
+ if policy_level == 'application':
+ self.__action = 'org.mandrivalinux.mcc2.services.auth_admin_keep'
+
+ if policy_level == 'method':
+ self.__action = None
+
@dbus.service.method("org.mandrivalinux.mcc2.Services",
in_signature='ss',
@@ -67,8 +78,7 @@ def Start(self, name, mode, sender, connection):
if not self.is_systemd_running:
raise dbus.DBusException, self.msg['not_running']
- check_authorization(sender, connection,
- 'org.mandrivalinux.mcc2.services.start')
+ check_authorization(sender, connection, self.__action)
return self.__systemd_interface.StartUnit(name, mode)
@@ -91,8 +101,7 @@ def Stop(self, name, mode, sender, connection):
if not self.is_systemd_running:
raise dbus.DBusException, self.msg['not_running']
- check_authorization(sender, connection,
- 'org.mandrivalinux.mcc2.services.stop')
+ check_authorization(sender, connection, self.__action)
return self.__systemd_interface.StopUnit(name, mode)
@@ -115,8 +124,7 @@ def Restart(self, name, mode, sender, connection):
if not self.is_systemd_running:
raise dbus.DBusException, self.msg['not_running']
- check_authorization(sender, connection,
- 'org.mandrivalinux.mcc2.services.restart')
+ check_authorization(sender, connection, self.__action)
return self.__systemd_interface.RestartUnit(name, mode)
@@ -163,7 +171,7 @@ def ServiceDetails(self, path):
def run(self):
- self._loop.run()
+ self.__loop.run()
@classmethod
Oops, something went wrong.

0 comments on commit 0bbfe1a

Please sign in to comment.