1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
#!/usr/bin/env python
# vim: set ts=4 sw=4 et:
#
# Copyright (C) 2005 Vincent Untz <vuntz@gnome.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
import subprocess
import string
import gconf
import gobject
import lockdownapplier
import lockdownappliergconf
from os.path import exists
from config import *
def can_edit_mandatory ():
try:
engine = gconf.engine_get_for_address (GCONF_MANDATORY_SOURCE)
except gobject.GError:
return False
if engine == None:
return False
try:
#entry = engine.get_entry ("/apps/gconf-editor/can_edit_source",
# None,
# False)
#gconf_engine_get_entry() is not wrapped. Ugly workaround:
client = gconf.client_get_for_engine (engine)
entry = client.get_entry ("/apps/gconf-editor/can_edit_source", "",
False)
except gobject.GError:
return False
if entry != None:
return entry.get_is_writable ()
return False
class PessulusLockdownApplierGconf (lockdownappliergconf.PessulusLockdownApplierGconf):
def __init__ (self,args):
if args.gconfmandatory:
if args.gconfmandatory.find('/var/lib/gconf/users'):
if exists(args.gconfmandatory.split(':')[2]) == False:
make_dir = subprocess.Popen(['mkdir', '-p', args.gconfmandatory.split(':')[2]])
make_dir.wait()
if args.disablemand == True:
self.can_edit_mandatory = False
else:
self.can_edit_mandatory = can_edit_mandatory ()
self.args = args
self.client_mandatory = None
if (self.can_edit_mandatory):
engine = gconf.engine_get_for_address (GCONF_MANDATORY_SOURCE)
self.client_mandatory = gconf.client_get_for_engine (engine)
self.client_default = gconf.client_get_default ()
gcengine = gconf.engine_get_for_address (args.gconfpath)
self.client = gconf.client_get_for_engine (gcengine)
self.custompath = True
if args.gconfmandatory != None:
gcmengine = gconf.engine_get_for_address (args.gconfmandatory)
self.client_mandatory = gconf.client_get_for_engine (gcmengine)
def get_bool (self, key):
value = None
is_mandatory = False
if self.supports_mandatory_settings ():
entry = self.client_mandatory.get_without_default (key)
if entry != None:
is_mandatory = True
value = entry.get_bool ()
else:
value = self.get_gtool_bool (key)
else:
value = self.get_gtool_bool (key)
return (value, is_mandatory)
def get_gtool_bool (self, key):
proc = subprocess.Popen(['sudo', '-u', self.args.gconfuser, 'gconftool-2', '--get', key, '--config-source', self.args.gconfpath], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = proc.stdout.read().strip("\n")
if output == '':
return self.client_default.get_bool(key)
else:
if output == "true":
return bool(1)
else:
return bool(0)
def set_bool (self, key, value, mandatory):
if mandatory:
if self.supports_mandatory_settings ():
self.client_mandatory.set_bool (key, value)
else:
if self.supports_mandatory_settings ():
self.client_mandatory.unset (key)
subprocess.Popen(['sudo', '-u', self.args.gconfuser, 'gconftool-2', '--type', 'bool', '--set', key, str(value), '--config-source', self.args.gconfpath])
def get_list (self, key, list_type):
value = None
is_mandatory = False
if self.supports_mandatory_settings ():
entry = self.client_mandatory.get_without_default (key)
if entry != None:
is_mandatory = True
list = entry.get_list ()
type = entry.get_list_type ()
value = []
for element in list:
if type == gconf.VALUE_STRING:
value.append (element.get_string ())
elif type == gconf.VALUE_BOOL:
value.append (element.get_bool ())
elif type == gconf.VALUE_INT:
value.append (element.get_int ())
elif type == gconf.VALUE_FLOAT:
value.append (element.get_float ())
else:
value = self.get_gtool_list(key, list_type)
else:
value = self.get_gtool_list(key, list_type)
return (value, is_mandatory)
def get_gtool_list (self, key, list_type):
proc = subprocess.Popen(['sudo', '-u', self.args.gconfuser, 'gconftool-2', '--get', key, '--config-source', self.args.gconfpath], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = proc.stdout.read()
if output == '':
return self.client_default.get_list(key, list_type)
else:
output = output.lstrip("[").strip("\n").rstrip("]").split(", ")
value = []
for element in output:
value.append(element.lstrip("'").rstrip("'"))
return (value)
def set_list (self, key, list_type, value, mandatory):
if mandatory:
if self.supports_mandatory_settings ():
self.client_mandatory.set_list (key, list_type, value)
else:
if list_type == gconf.VALUE_STRING:
s_type = "string"
elif list_type == gconf.VALUE_BOOL:
s_type = "bool"
elif list_type == gconf.VALUE_INT:
s_type = "int"
elif list_type == gconf.VALUE_FLOAT:
s_type = "float"
if self.supports_mandatory_settings ():
self.client_mandatory.unset (key)
subprocess.Popen(['sudo', '-u', self.args.gconfuser, 'gconftool-2', '--type', 'list', '--list-type', s_type, '--set', key, str(value), '--config-source', self.args.gconfpath])
|