64 if not sys.argv[1] in ['cf', 'configure']: |
64 if not sys.argv[1] in ['cf', 'configure']: |
65 self.__chkenv() |
65 self.__chkenv() |
66 |
66 |
67 def __findCfgFile(self): |
67 def __findCfgFile(self): |
68 for path in ['/root', '/usr/local/etc', '/etc']: |
68 for path in ['/root', '/usr/local/etc', '/etc']: |
69 if os.path.isfile(path+'/vmm.cfg'): |
69 tmp = os.path.join(path, 'vmm.cfg') |
70 self.__cfgFileName = path+'/vmm.cfg' |
70 if os.path.isfile(tmp): |
|
71 self.__cfgFileName = tmp |
71 break |
72 break |
72 if not len(self.__cfgFileName): |
73 if not len(self.__cfgFileName): |
73 raise VMMException( |
74 raise VMMException( |
74 _(u"No »vmm.cfg« found in: /root:/usr/local/etc:/etc"), |
75 _(u"No »vmm.cfg« found in: /root:/usr/local/etc:/etc"), |
75 ERR.CONF_NOFILE) |
76 ERR.CONF_NOFILE) |
287 self.__makedir(domdirdirs[1], self.__Cfg.getint('domdir', 'mode'), 0, |
288 self.__makedir(domdirdirs[1], self.__Cfg.getint('domdir', 'mode'), 0, |
288 gid) |
289 gid) |
289 os.chdir(oldpwd) |
290 os.chdir(oldpwd) |
290 |
291 |
291 def __subscribeFL(self, folderlist, uid, gid): |
292 def __subscribeFL(self, folderlist, uid, gid): |
292 fname = self.__Cfg.get('maildir', 'name') + '/subscriptions' |
293 fname = os.path.join(self.__Cfg.get('maildir','name'), 'subscriptions') |
293 sf = file(fname, 'w') |
294 sf = file(fname, 'w') |
294 for f in folderlist: |
295 for f in folderlist: |
295 sf.write(f+'\n') |
296 sf.write(f+'\n') |
296 sf.flush() |
297 sf.flush() |
297 sf.close() |
298 sf.close() |
323 self.__makedir('%s' % uid, mode, uid, gid) |
324 self.__makedir('%s' % uid, mode, uid, gid) |
324 os.chdir('%s' % uid) |
325 os.chdir('%s' % uid) |
325 for folder in folders: |
326 for folder in folders: |
326 self.__makedir(folder, mode, uid, gid) |
327 self.__makedir(folder, mode, uid, gid) |
327 for subdir in subdirs: |
328 for subdir in subdirs: |
328 self.__makedir(folder+'/'+subdir, mode, uid, gid) |
329 self.__makedir(os.path.join(folder, subdir), mode, uid, gid) |
329 self.__subscribeFL([f.replace(maildir+'/.', '') for f in folders[1:]], |
330 self.__subscribeFL([f.replace(maildir+'/.', '') for f in folders[1:]], |
330 uid, gid) |
331 uid, gid) |
331 os.chdir(oldpwd) |
332 os.chdir(oldpwd) |
332 |
333 |
333 def __userDirDelete(self, domdir, uid, gid): |
334 def __userDirDelete(self, domdir, uid, gid): |
345 _(u'Owner/group mismatch in home directory detected.'), |
346 _(u'Owner/group mismatch in home directory detected.'), |
346 ERR.MAILDIR_PERM_MISMATCH) |
347 ERR.MAILDIR_PERM_MISMATCH) |
347 rmtree(userdir, ignore_errors=True) |
348 rmtree(userdir, ignore_errors=True) |
348 else: |
349 else: |
349 raise VMMException(_(u"No such directory: %s") % |
350 raise VMMException(_(u"No such directory: %s") % |
350 domdir+'/'+userdir, ERR.NO_SUCH_DIRECTORY) |
351 os.path.join(domdir, userdir), ERR.NO_SUCH_DIRECTORY) |
351 |
352 |
352 def __domDirDelete(self, domdir, gid): |
353 def __domDirDelete(self, domdir, gid): |
353 if gid > 0: |
354 if gid > 0: |
354 if not self.__isdir(domdir): |
355 if not self.__isdir(domdir): |
355 return |
356 return |
356 basedir = '%s' % self.__Cfg.get('domdir', 'base') |
357 basedir = self.__Cfg.get('domdir', 'base') |
357 domdirdirs = domdir.replace(basedir+'/', '').split('/') |
358 domdirdirs = domdir.replace(basedir+'/', '').split('/') |
|
359 domdirparent = os.path.join(basedir, domdirdirs[0]) |
358 if basedir.count('..') or domdir.count('..'): |
360 if basedir.count('..') or domdir.count('..'): |
359 raise VMMException( |
361 raise VMMException( |
360 _(u'FATAL: ".." in domain directory path detected.'), |
362 _(u'FATAL: ".." in domain directory path detected.'), |
361 ERR.FOUND_DOTS_IN_PATH) |
363 ERR.FOUND_DOTS_IN_PATH) |
362 if os.path.isdir('%s/%s' % (basedir, domdirdirs[0])): |
364 if os.path.isdir(domdirparent): |
363 os.chdir('%s/%s' % (basedir, domdirdirs[0])) |
365 os.chdir(domdirparent) |
364 if os.lstat(domdirdirs[1]).st_gid != gid: |
366 if os.lstat(domdirdirs[1]).st_gid != gid: |
365 raise VMMException( |
367 raise VMMException( |
366 _(u'FATAL: group mismatch in domain directory detected'), |
368 _(u'FATAL: group mismatch in domain directory detected'), |
367 ERR.DOMAINDIR_GROUP_MISMATCH) |
369 ERR.DOMAINDIR_GROUP_MISMATCH) |
368 rmtree(domdirdirs[1], ignore_errors=True) |
370 rmtree(domdirdirs[1], ignore_errors=True) |