"some permanent logging (switched off by default) and only running chown, chgrp, chmod if mkdir succeeds"

This commit is contained in:
Ralf Becker 2009-03-27 18:05:42 +00:00
parent b54d0dab25
commit 9e8ef4d851

View File

@ -7,7 +7,7 @@
* @package api * @package api
* @subpackage vfs * @subpackage vfs
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2008 by Ralf Becker <RalfBecker-AT-outdoor-training.de> * @copyright (c) 2008-9 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @version $Id$ * @version $Id$
*/ */
@ -22,6 +22,13 @@
*/ */
class vfs_home_hooks class vfs_home_hooks
{ {
/**
* Should we log our calls to the error_log
* 0 - no logging
* 1 - log method calls
*/
const LOG_LEVEL = 0;
/** /**
* Hook called after new accounts have been added * Hook called after new accounts have been added
* *
@ -31,12 +38,15 @@ class vfs_home_hooks
*/ */
static function addAccount($data) static function addAccount($data)
{ {
if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
// create a user-dir // create a user-dir
egw_vfs::$is_root = true; egw_vfs::$is_root = true;
egw_vfs::mkdir($dir='/home/'.$data['account_lid'],0700,0); if (@egw_vfs::mkdir($dir='/home/'.$data['account_lid'],0700,0))
egw_vfs::chown($dir,$data['account_id']); {
egw_vfs::chgrp($dir,0); egw_vfs::chown($dir,$data['account_id']);
egw_vfs::chmod($dir,0700); // only user has access egw_vfs::chgrp($dir,0);
egw_vfs::chmod($dir,0700); // only user has access
}
egw_vfs::$is_root = false; egw_vfs::$is_root = false;
} }
@ -50,6 +60,7 @@ class vfs_home_hooks
*/ */
static function editAccount($data) static function editAccount($data)
{ {
if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
if ($data['account_lid'] == $data['old_loginid']) return; // nothing to do here if ($data['account_lid'] == $data['old_loginid']) return; // nothing to do here
// rename the user-dir // rename the user-dir
@ -68,6 +79,7 @@ class vfs_home_hooks
*/ */
static function deleteAccount($data) static function deleteAccount($data)
{ {
if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
egw_vfs::$is_root = true; egw_vfs::$is_root = true;
if ($data['new_owner'] && ($new_lid = $GLOBALS['egw']->accounts->id2name($data['new_owner']))) if ($data['new_owner'] && ($new_lid = $GLOBALS['egw']->accounts->id2name($data['new_owner'])))
{ {
@ -94,12 +106,15 @@ class vfs_home_hooks
*/ */
static function addGroup($data) static function addGroup($data)
{ {
if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
// create a group-dir // create a group-dir
egw_vfs::$is_root = true; egw_vfs::$is_root = true;
egw_vfs::mkdir($dir='/home/'.$data['account_name'],070,0); if (@egw_vfs::mkdir($dir='/home/'.$data['account_name'],070,0))
egw_vfs::chown($dir,0); {
egw_vfs::chgrp($dir,$data['account_id']); egw_vfs::chown($dir,0);
egw_vfs::chmod($dir,0070); // only group has access egw_vfs::chgrp($dir,$data['account_id']);
egw_vfs::chmod($dir,0070); // only group has access
}
egw_vfs::$is_root = false; egw_vfs::$is_root = false;
} }
@ -113,6 +128,7 @@ class vfs_home_hooks
*/ */
static function editGroup($data) static function editGroup($data)
{ {
if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
if ($data['account_name'] == $data['old_name']) return; // nothing to do here if ($data['account_name'] == $data['old_name']) return; // nothing to do here
// rename the group-dir // rename the group-dir
@ -130,6 +146,7 @@ class vfs_home_hooks
*/ */
static function deleteGroup($data) static function deleteGroup($data)
{ {
if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
// delete the group-directory // delete the group-directory
egw_vfs::$is_root = true; egw_vfs::$is_root = true;
egw_vfs::remove('/home/'.$data['account_name']); egw_vfs::remove('/home/'.$data['account_name']);