# HG changeset patch # User Sylvain Thénault # Date 1278576183 -7200 # Node ID 3d707b8f8a4d62f77fbfb7e9b0b06a7511274924 # Parent 1390a408d8b333d488a5ce7c632c55cfeb5bc1fb [web configuration] ensure data home directory / uicache file belong to daemon user and are writeable diff -r 1390a408d8b3 -r 3d707b8f8a4d cwconfig.py --- a/cwconfig.py Thu Jul 08 08:54:45 2010 +0200 +++ b/cwconfig.py Thu Jul 08 10:03:03 2010 +0200 @@ -991,6 +991,29 @@ """write down current configuration""" self.generate_config(open(self.main_config_file(), 'w')) + def check_writeable_uid_directory(self, path): + """check given directory path exists, belongs to the user running the + server process and is writeable. + + If not, try to fix this, leting exception propagate when not possible. + """ + if not exists(path): + os.makedirs(path) + if self['uid']: + try: + uid = int(self['uid']) + except ValueError: + from pwd import getpwnam + uid = getpwnam(self['uid']).pw_uid + else: + uid = os.getuid() + fstat = os.stat(path) + if fstat.st_uid != uid: + os.chown(path, uid, os.getgid()) + import stat + if not (fstat.st_mode & stat.S_IWUSR): + os.chmod(path, fstat.st_mode | stat.S_IWUSR) + @cached def instance_md5_version(self): import hashlib diff -r 1390a408d8b3 -r 3d707b8f8a4d etwist/server.py --- a/etwist/server.py Thu Jul 08 08:54:45 2010 +0200 +++ b/etwist/server.py Thu Jul 08 10:03:03 2010 +0200 @@ -402,6 +402,7 @@ def run(config, vreg=None, debug=None): if debug is not None: config.debugmode = debug + config.check_writeable_uid_directory(config.appdatahome) # create the site root_resource = CubicWebRootResource(config, vreg=vreg) website = server.Site(root_resource) diff -r 1390a408d8b3 -r 3d707b8f8a4d server/serverconfig.py --- a/server/serverconfig.py Thu Jul 08 08:54:45 2010 +0200 +++ b/server/serverconfig.py Thu Jul 08 10:03:03 2010 +0200 @@ -15,9 +15,8 @@ # # You should have received a copy of the GNU Lesser General Public License along # with CubicWeb. If not, see . -"""server.serverconfig definition +"""server.serverconfig definition""" -""" __docformat__ = "restructuredtext en" from os.path import join, exists diff -r 1390a408d8b3 -r 3d707b8f8a4d web/webconfig.py --- a/web/webconfig.py Thu Jul 08 08:54:45 2010 +0200 +++ b/web/webconfig.py Thu Jul 08 10:03:03 2010 +0200 @@ -15,9 +15,8 @@ # # You should have received a copy of the GNU Lesser General Public License along # with CubicWeb. If not, see . -"""common web configuration for twisted/modpython instances +"""web ui configuration for cubicweb instances""" -""" __docformat__ = "restructuredtext en" _ = unicode @@ -335,8 +334,10 @@ def _build_ui_properties(self): # self.datadir_url[:-1] to remove trailing / from cubicweb.web.propertysheet import PropertySheet + cachedir = join(self.appdatahome, 'uicache') + self.check_writeable_uid_directory(cachedir) self.uiprops = PropertySheet( - join(self.appdatahome, 'uicache'), + cachedir, data=lambda x: self.datadir_url + x, datadir_url=self.datadir_url[:-1]) self._init_uiprops(self.uiprops)