2003-05-12 05:20:17 +04:00
/*
Unix SMB / CIFS implementation .
System QUOTA function wrappers
Copyright ( C ) Stefan ( metze ) Metzmacher 2003
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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-05-12 05:20:17 +04:00
( 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
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-05-12 05:20:17 +04:00
*/
# include "includes.h"
2016-02-16 19:09:43 +03:00
# include "lib/util_file.h"
2020-07-03 09:11:20 +03:00
# include "lib/util/smb_strtox.h"
2003-05-12 05:20:17 +04:00
2004-01-15 11:49:30 +03:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_QUOTA
2003-05-14 18:38:11 +04:00
# ifdef HAVE_SYS_QUOTAS
2003-05-12 05:20:17 +04:00
# if defined(HAVE_QUOTACTL_4A)
/*#endif HAVE_QUOTACTL_4A */
# elif defined(HAVE_QUOTACTL_4B)
/*#endif HAVE_QUOTACTL_4B */
# elif defined(HAVE_QUOTACTL_3)
# error HAVE_QUOTACTL_3 not implemented
/* #endif HAVE_QUOTACTL_3 */
# else /* NO_QUOTACTL_USED */
# endif /* NO_QUOTACTL_USED */
2016-01-19 00:34:48 +03:00
# if defined(HAVE_MNTENT) && defined(HAVE_REALPATH)
2003-05-12 05:20:17 +04:00
static int sys_path_to_bdev ( const char * path , char * * mntpath , char * * bdev , char * * fs )
{
int ret = - 1 ;
SMB_STRUCT_STAT S ;
FILE * fp ;
2016-01-19 00:34:48 +03:00
struct mntent * mnt = NULL ;
2003-05-12 05:20:17 +04:00
SMB_DEV_T devno ;
2016-01-19 00:34:48 +03:00
char * stat_mntpath = NULL ;
char * p ;
2003-05-12 05:20:17 +04:00
/* find the block device file */
( * mntpath ) = NULL ;
( * bdev ) = NULL ;
( * fs ) = NULL ;
2016-01-19 00:34:48 +03:00
if ( sys_stat ( path , & S , false ) ! = 0 ) {
return - 1 ;
}
2003-05-12 05:20:17 +04:00
2009-06-29 18:11:13 +04:00
devno = S . st_ex_dev ;
2003-05-12 05:20:17 +04:00
2016-01-19 00:34:48 +03:00
stat_mntpath = sys_realpath ( path ) ;
if ( stat_mntpath = = NULL ) {
DBG_WARNING ( " realpath(%s) failed - %s \n " , path ,
strerror ( errno ) ) ;
goto out ;
}
if ( sys_stat ( stat_mntpath , & S , false ) ! = 0 ) {
DBG_WARNING ( " cannot stat real path %s - %s \n " , stat_mntpath ,
strerror ( errno ) ) ;
goto out ;
}
if ( S . st_ex_dev ! = devno ) {
DBG_WARNING ( " device on real path has changed \n " ) ;
goto out ;
}
while ( true ) {
2016-10-07 11:05:07 +03:00
char save_ch ;
2016-01-19 00:34:48 +03:00
p = strrchr ( stat_mntpath , ' / ' ) ;
if ( p = = NULL ) {
DBG_ERR ( " realpath for %s does not begin with a '/' \n " ,
path ) ;
goto out ;
}
if ( p = = stat_mntpath ) {
+ + p ;
}
2016-10-07 11:05:07 +03:00
save_ch = * p ;
2016-01-19 00:34:48 +03:00
* p = 0 ;
if ( sys_stat ( stat_mntpath , & S , false ) ! = 0 ) {
DBG_WARNING ( " cannot stat real path component %s - %s \n " ,
stat_mntpath , strerror ( errno ) ) ;
goto out ;
}
if ( S . st_ex_dev ! = devno ) {
2016-10-07 11:05:07 +03:00
* p = save_ch ;
2016-01-19 00:34:48 +03:00
break ;
}
if ( p < = stat_mntpath + 1 ) {
break ;
}
}
2003-05-12 05:20:17 +04:00
fp = setmntent ( MOUNTED , " r " ) ;
2005-11-07 22:18:00 +03:00
if ( fp = = NULL ) {
2016-01-19 00:34:48 +03:00
goto out ;
2005-11-07 22:18:00 +03:00
}
2003-05-12 05:20:17 +04:00
while ( ( mnt = getmntent ( fp ) ) ) {
2016-01-19 00:34:48 +03:00
if ( ! strequal ( mnt - > mnt_dir , stat_mntpath ) ) {
continue ;
}
2009-11-27 15:08:51 +03:00
if ( sys_stat ( mnt - > mnt_dir , & S , false ) = = - 1 )
2003-05-12 05:20:17 +04:00
continue ;
2009-06-29 18:11:13 +04:00
if ( S . st_ex_dev = = devno ) {
2004-12-17 00:12:29 +03:00
( * mntpath ) = SMB_STRDUP ( mnt - > mnt_dir ) ;
( * bdev ) = SMB_STRDUP ( mnt - > mnt_fsname ) ;
( * fs ) = SMB_STRDUP ( mnt - > mnt_type ) ;
2003-05-12 05:20:17 +04:00
if ( ( * mntpath ) & & ( * bdev ) & & ( * fs ) ) {
ret = 0 ;
} else {
SAFE_FREE ( * mntpath ) ;
SAFE_FREE ( * bdev ) ;
SAFE_FREE ( * fs ) ;
ret = - 1 ;
}
break ;
}
}
endmntent ( fp ) ;
2016-01-19 00:34:48 +03:00
out :
SAFE_FREE ( stat_mntpath ) ;
2003-05-12 05:20:17 +04:00
return ret ;
}
/* #endif HAVE_MNTENT */
# elif defined(HAVE_DEVNM)
/* we have this on HPUX, ... */
static int sys_path_to_bdev ( const char * path , char * * mntpath , char * * bdev , char * * fs )
{
int ret = - 1 ;
char dev_disk [ 256 ] ;
SMB_STRUCT_STAT S ;
if ( ! path | | ! mntpath | | ! bdev | | ! fs )
smb_panic ( " sys_path_to_bdev: called with NULL pointer " ) ;
( * mntpath ) = NULL ;
( * bdev ) = NULL ;
( * fs ) = NULL ;
/* find the block device file */
2009-11-27 15:08:51 +03:00
if ( ( ret = sys_stat ( path , & S , false ) ) ! = 0 ) {
2003-05-12 05:20:17 +04:00
return ret ;
}
2009-06-29 18:11:13 +04:00
if ( ( ret = devnm ( S_IFBLK , S . st_ex_dev , dev_disk , 256 , 1 ) ) ! = 0 ) {
2003-05-12 05:20:17 +04:00
return ret ;
}
/* we should get the mntpath right...
* but I don ' t know how
* - - metze
*/
2004-12-17 00:12:29 +03:00
( * mntpath ) = SMB_STRDUP ( path ) ;
( * bdev ) = SMB_STRDUP ( dev_disk ) ;
2003-05-12 05:20:17 +04:00
if ( ( * mntpath ) & & ( * bdev ) ) {
ret = 0 ;
} else {
SAFE_FREE ( * mntpath ) ;
SAFE_FREE ( * bdev ) ;
ret = - 1 ;
}
return ret ;
}
/* #endif HAVE_DEVNM */
# else
/* we should fake this up...*/
static int sys_path_to_bdev ( const char * path , char * * mntpath , char * * bdev , char * * fs )
{
int ret = - 1 ;
if ( ! path | | ! mntpath | | ! bdev | | ! fs )
smb_panic ( " sys_path_to_bdev: called with NULL pointer " ) ;
( * mntpath ) = NULL ;
( * bdev ) = NULL ;
( * fs ) = NULL ;
2004-12-17 00:12:29 +03:00
( * mntpath ) = SMB_STRDUP ( path ) ;
2003-05-12 05:20:17 +04:00
if ( * mntpath ) {
ret = 0 ;
} else {
SAFE_FREE ( * mntpath ) ;
ret = - 1 ;
}
return ret ;
}
# endif
/*********************************************************************
Now the list of all filesystem specific quota systems we have found
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static struct {
const char * name ;
int ( * get_quota ) ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp ) ;
int ( * set_quota ) ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp ) ;
} sys_quota_backends [ ] = {
2019-02-06 01:52:33 +03:00
# ifdef HAVE_JFS_QUOTA_H
{ " jfs2 " , sys_get_jfs2_quota , sys_set_jfs2_quota } ,
# endif
2012-09-07 15:13:49 +04:00
# if defined HAVE_XFS_QUOTAS
2003-05-12 05:20:17 +04:00
{ " xfs " , sys_get_xfs_quota , sys_set_xfs_quota } ,
2012-09-18 15:57:30 +04:00
{ " gfs " , sys_get_xfs_quota , sys_set_xfs_quota } ,
{ " gfs2 " , sys_get_xfs_quota , sys_set_xfs_quota } ,
2004-01-14 05:51:41 +03:00
# endif /* HAVE_XFS_QUOTAS */
2010-08-06 12:21:09 +04:00
# ifdef HAVE_NFS_QUOTAS
{ " nfs " , sys_get_nfs_quota , sys_set_nfs_quota } ,
2012-09-06 09:58:00 +04:00
{ " nfs4 " , sys_get_nfs_quota , sys_set_nfs_quota } ,
2010-08-06 12:21:09 +04:00
# endif /* HAVE_NFS_QUOTAS */
2007-11-16 01:19:52 +03:00
{ NULL , NULL , NULL }
2003-05-12 05:20:17 +04:00
} ;
static int command_get_quota ( const char * path , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
2019-11-04 19:43:45 +03:00
const struct loadparm_substitution * lp_sub =
loadparm_s3_global_substitution ( ) ;
2003-05-12 05:20:17 +04:00
const char * get_quota_command ;
2006-03-13 22:47:18 +03:00
char * * lines = NULL ;
2007-11-16 01:19:52 +03:00
2019-11-04 19:43:45 +03:00
get_quota_command = lp_get_quota_command ( talloc_tos ( ) , lp_sub ) ;
2003-05-12 05:20:17 +04:00
if ( get_quota_command & & * get_quota_command ) {
const char * p ;
char * p2 ;
int _id = - 1 ;
2019-01-28 14:54:07 +03:00
int error = 0 ;
2019-05-18 21:08:15 +03:00
char * * argl = NULL ;
2003-05-12 05:20:17 +04:00
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
case SMB_USER_FS_QUOTA_TYPE :
_id = id . uid ;
break ;
case SMB_GROUP_QUOTA_TYPE :
case SMB_GROUP_FS_QUOTA_TYPE :
_id = id . gid ;
break ;
default :
DEBUG ( 0 , ( " invalid quota type. \n " ) ) ;
return - 1 ;
}
2022-01-12 14:15:08 +03:00
argl = str_list_make_empty ( talloc_tos ( ) ) ;
str_list_add_printf ( & argl , " %s " , get_quota_command ) ;
str_list_add_printf ( & argl , " %s " , path ) ;
str_list_add_printf ( & argl , " %d " , qtype ) ;
str_list_add_printf ( & argl , " %d " , _id ) ;
2019-05-18 21:08:15 +03:00
if ( argl = = NULL ) {
2007-11-16 01:19:52 +03:00
return - 1 ;
}
2003-05-12 05:20:17 +04:00
2019-05-18 21:08:15 +03:00
DBG_NOTICE ( " Running command %s %s %d %d \n " ,
get_quota_command ,
path ,
qtype ,
_id ) ;
2003-05-12 05:20:17 +04:00
2019-05-18 21:08:15 +03:00
lines = file_lines_ploadv ( talloc_tos ( ) , argl , NULL ) ;
TALLOC_FREE ( argl ) ;
2007-11-16 01:19:52 +03:00
2003-05-12 05:20:17 +04:00
if ( lines ) {
char * line = lines [ 0 ] ;
2003-10-10 00:58:11 +04:00
DEBUG ( 3 , ( " Read output from get_quota, \" %s \" \n " , line ) ) ;
2003-05-12 05:20:17 +04:00
/* we need to deal with long long unsigned here, if supported */
2019-06-04 10:04:15 +03:00
dp - > qflags = smb_strtoul ( line ,
& p2 ,
10 ,
& error ,
SMB_STR_STANDARD ) ;
2019-01-28 14:54:07 +03:00
if ( error ! = 0 ) {
goto invalid_param ;
}
2003-05-12 05:20:17 +04:00
p = p2 ;
2006-03-13 22:47:18 +03:00
while ( p & & * p & & isspace ( * p ) ) {
2003-05-12 05:20:17 +04:00
p + + ;
2006-03-13 22:47:18 +03:00
}
if ( p & & * p ) {
2003-05-12 05:20:17 +04:00
dp - > curblocks = STR_TO_SMB_BIG_UINT ( p , & p ) ;
2006-03-13 22:47:18 +03:00
} else {
2003-05-12 05:20:17 +04:00
goto invalid_param ;
2006-03-13 22:47:18 +03:00
}
while ( p & & * p & & isspace ( * p ) ) {
2003-05-12 05:20:17 +04:00
p + + ;
2006-03-13 22:47:18 +03:00
}
if ( p & & * p ) {
2003-05-12 05:20:17 +04:00
dp - > softlimit = STR_TO_SMB_BIG_UINT ( p , & p ) ;
2006-03-13 22:47:18 +03:00
} else {
2003-05-12 05:20:17 +04:00
goto invalid_param ;
2006-03-13 22:47:18 +03:00
}
while ( p & & * p & & isspace ( * p ) ) {
2003-05-12 05:20:17 +04:00
p + + ;
2006-03-13 22:47:18 +03:00
}
if ( p & & * p ) {
2003-05-12 05:20:17 +04:00
dp - > hardlimit = STR_TO_SMB_BIG_UINT ( p , & p ) ;
2006-03-13 22:47:18 +03:00
} else {
2003-05-12 05:20:17 +04:00
goto invalid_param ;
2006-03-13 22:47:18 +03:00
}
while ( p & & * p & & isspace ( * p ) ) {
2003-05-12 05:20:17 +04:00
p + + ;
2006-03-13 22:47:18 +03:00
}
if ( p & & * p ) {
2003-05-12 05:20:17 +04:00
dp - > curinodes = STR_TO_SMB_BIG_UINT ( p , & p ) ;
2006-03-13 22:47:18 +03:00
} else {
2003-05-12 05:20:17 +04:00
goto invalid_param ;
2006-03-13 22:47:18 +03:00
}
while ( p & & * p & & isspace ( * p ) ) {
2003-05-12 05:20:17 +04:00
p + + ;
2006-03-13 22:47:18 +03:00
}
if ( p & & * p ) {
2003-05-12 05:20:17 +04:00
dp - > isoftlimit = STR_TO_SMB_BIG_UINT ( p , & p ) ;
2006-03-13 22:47:18 +03:00
} else {
2003-05-12 05:20:17 +04:00
goto invalid_param ;
2006-03-13 22:47:18 +03:00
}
while ( p & & * p & & isspace ( * p ) ) {
2003-05-12 05:20:17 +04:00
p + + ;
2006-03-13 22:47:18 +03:00
}
if ( p & & * p ) {
2003-05-12 05:20:17 +04:00
dp - > ihardlimit = STR_TO_SMB_BIG_UINT ( p , & p ) ;
2006-03-13 22:47:18 +03:00
} else {
2003-05-12 05:20:17 +04:00
goto invalid_param ;
2006-03-13 22:47:18 +03:00
}
while ( p & & * p & & isspace ( * p ) ) {
2003-05-12 05:20:17 +04:00
p + + ;
2006-03-13 22:47:18 +03:00
}
if ( p & & * p ) {
2003-05-12 05:20:17 +04:00
dp - > bsize = STR_TO_SMB_BIG_UINT ( p , NULL ) ;
2006-03-13 22:47:18 +03:00
} else {
2003-05-12 05:20:17 +04:00
dp - > bsize = 1024 ;
2006-03-13 22:47:18 +03:00
}
2008-10-12 19:34:43 +04:00
TALLOC_FREE ( lines ) ;
2006-03-13 22:47:18 +03:00
lines = NULL ;
2003-05-12 05:20:17 +04:00
DEBUG ( 3 , ( " Parsed output of get_quota, ... \n " ) ) ;
DEBUGADD ( 5 , (
2023-08-09 01:01:33 +03:00
" qflags:% " PRIu32 " curblocks:% " PRIu64 " softlimit:% " PRIu64 " hardlimit:% " PRIu64 " \n "
" curinodes:% " PRIu64 " isoftlimit:% " PRIu64 " ihardlimit:% " PRIu64 " bsize:% " PRIu64 " \n " ,
dp - > qflags , dp - > curblocks ,
dp - > softlimit , dp - > hardlimit ,
dp - > curinodes ,
dp - > isoftlimit , dp - > ihardlimit ,
dp - > bsize ) ) ;
2003-05-12 05:20:17 +04:00
return 0 ;
}
DEBUG ( 0 , ( " get_quota_command failed! \n " ) ) ;
return - 1 ;
}
errno = ENOSYS ;
return - 1 ;
2007-11-16 01:19:52 +03:00
2003-05-12 05:20:17 +04:00
invalid_param :
2006-03-13 22:47:18 +03:00
2008-10-12 19:34:43 +04:00
TALLOC_FREE ( lines ) ;
2003-05-12 05:20:17 +04:00
DEBUG ( 0 , ( " The output of get_quota_command is invalid! \n " ) ) ;
return - 1 ;
}
static int command_set_quota ( const char * path , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
2019-11-05 14:01:45 +03:00
const struct loadparm_substitution * lp_sub =
loadparm_s3_global_substitution ( ) ;
2003-05-12 05:20:17 +04:00
const char * set_quota_command ;
2007-11-16 01:19:52 +03:00
2019-11-05 14:01:45 +03:00
set_quota_command = lp_set_quota_command ( talloc_tos ( ) , lp_sub ) ;
2003-05-12 05:20:17 +04:00
if ( set_quota_command & & * set_quota_command ) {
2007-11-16 01:19:52 +03:00
char * * lines = NULL ;
2003-05-12 05:20:17 +04:00
int _id = - 1 ;
2019-05-18 21:08:15 +03:00
char * * argl = NULL ;
2003-05-12 05:20:17 +04:00
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
case SMB_USER_FS_QUOTA_TYPE :
_id = id . uid ;
break ;
case SMB_GROUP_QUOTA_TYPE :
case SMB_GROUP_FS_QUOTA_TYPE :
_id = id . gid ;
break ;
default :
return - 1 ;
}
2022-01-12 14:19:00 +03:00
argl = str_list_make_empty ( talloc_tos ( ) ) ;
str_list_add_printf ( & argl , " %s " , set_quota_command ) ;
str_list_add_printf ( & argl , " %s " , path ) ;
str_list_add_printf ( & argl , " %d " , qtype ) ;
str_list_add_printf ( & argl , " %d " , _id ) ;
str_list_add_printf ( & argl , " %u " , dp - > qflags ) ;
str_list_add_printf (
2023-08-09 01:01:33 +03:00
& argl , " % " PRIu64 , dp - > softlimit ) ;
2022-01-12 14:19:00 +03:00
str_list_add_printf (
2023-08-09 01:01:33 +03:00
& argl , " % " PRIu64 , dp - > hardlimit ) ;
2022-01-12 14:19:00 +03:00
str_list_add_printf (
2023-08-09 01:01:33 +03:00
& argl , " % " PRIu64 , dp - > isoftlimit ) ;
2022-01-12 14:19:00 +03:00
str_list_add_printf (
2023-08-09 01:01:33 +03:00
& argl , " % " PRIu64 , dp - > ihardlimit ) ;
2022-01-12 14:19:00 +03:00
str_list_add_printf (
2023-08-09 01:01:33 +03:00
& argl , " % " PRIu64 , dp - > bsize ) ;
2019-05-18 21:08:15 +03:00
if ( argl = = NULL ) {
2007-11-16 01:19:52 +03:00
return - 1 ;
}
2003-05-12 05:20:17 +04:00
2019-05-18 21:08:15 +03:00
DBG_NOTICE ( " Running command "
" %s %s %d %d "
2023-08-01 06:49:36 +03:00
" % " PRIu32 " % " PRIu64 " % " PRIu64 " "
" % " PRIu64 " % " PRIu64 " % " PRIu64 " \n " ,
2019-05-18 21:08:15 +03:00
set_quota_command ,
path ,
qtype ,
_id ,
dp - > qflags ,
2023-08-01 06:49:36 +03:00
dp - > softlimit ,
dp - > hardlimit ,
dp - > isoftlimit ,
dp - > ihardlimit ,
dp - > bsize ) ;
2019-05-18 21:08:15 +03:00
lines = file_lines_ploadv ( talloc_tos ( ) , argl , NULL ) ;
TALLOC_FREE ( argl ) ;
2003-05-12 05:20:17 +04:00
if ( lines ) {
char * line = lines [ 0 ] ;
DEBUG ( 3 , ( " Read output from set_quota, \" %s \" \n " , line ) ) ;
2008-10-12 19:34:43 +04:00
TALLOC_FREE ( lines ) ;
2007-11-16 01:19:52 +03:00
2003-05-12 05:20:17 +04:00
return 0 ;
}
DEBUG ( 0 , ( " set_quota_command failed! \n " ) ) ;
return - 1 ;
}
errno = ENOSYS ;
return - 1 ;
}
int sys_get_quota ( const char * path , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
int i ;
2007-10-19 04:40:25 +04:00
bool ready = False ;
2003-05-12 05:20:17 +04:00
char * mntpath = NULL ;
char * bdev = NULL ;
char * fs = NULL ;
if ( ! path | | ! dp )
smb_panic ( " sys_get_quota: called with NULL pointer " ) ;
if ( command_get_quota ( path , qtype , id , dp ) = = 0 ) {
return 0 ;
} else if ( errno ! = ENOSYS ) {
return - 1 ;
}
if ( ( ret = sys_path_to_bdev ( path , & mntpath , & bdev , & fs ) ) ! = 0 ) {
2003-07-29 22:07:13 +04:00
DEBUG ( 0 , ( " sys_path_to_bdev() failed for path [%s]! \n " , path ) ) ;
2003-05-12 05:20:17 +04:00
return ret ;
}
2004-01-15 11:49:30 +03:00
errno = 0 ;
2012-09-14 22:46:45 +04:00
DEBUG ( 10 , ( " sys_get_quota() uid(%u, %u), fs(%s) \n " , ( unsigned ) getuid ( ) , ( unsigned ) geteuid ( ) , fs ) ) ;
2004-01-15 11:49:30 +03:00
2003-05-12 05:20:17 +04:00
for ( i = 0 ; ( fs & & sys_quota_backends [ i ] . name & & sys_quota_backends [ i ] . get_quota ) ; i + + ) {
if ( strcmp ( fs , sys_quota_backends [ i ] . name ) = = 0 ) {
ret = sys_quota_backends [ i ] . get_quota ( mntpath , bdev , qtype , id , dp ) ;
2003-07-29 22:07:13 +04:00
if ( ret ! = 0 ) {
2004-01-15 11:49:30 +03:00
DEBUG ( 3 , ( " sys_get_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d]: %s. \n " ,
fs , mntpath , bdev , qtype , ( qtype = = SMB_GROUP_QUOTA_TYPE ? id . gid : id . uid ) , strerror ( errno ) ) ) ;
} else {
DEBUG ( 10 , ( " sys_get_%s_quota() called for mntpath[%s] bdev[%s] qtype[%d] id[%d]. \n " ,
fs , mntpath , bdev , qtype , ( qtype = = SMB_GROUP_QUOTA_TYPE ? id . gid : id . uid ) ) ) ;
2003-07-29 22:07:13 +04:00
}
2003-05-12 05:20:17 +04:00
ready = True ;
break ;
}
}
if ( ! ready ) {
/* use the default vfs quota functions */
2003-07-29 22:07:13 +04:00
ret = sys_get_vfs_quota ( mntpath , bdev , qtype , id , dp ) ;
if ( ret ! = 0 ) {
2004-01-15 11:49:30 +03:00
DEBUG ( 3 , ( " sys_get_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d]: %s \n " ,
" vfs " , mntpath , bdev , qtype , ( qtype = = SMB_GROUP_QUOTA_TYPE ? id . gid : id . uid ) , strerror ( errno ) ) ) ;
} else {
DEBUG ( 10 , ( " sys_get_%s_quota() called for mntpath[%s] bdev[%s] qtype[%d] id[%d]. \n " ,
" vfs " , mntpath , bdev , qtype , ( qtype = = SMB_GROUP_QUOTA_TYPE ? id . gid : id . uid ) ) ) ;
2003-07-29 22:07:13 +04:00
}
2003-05-12 05:20:17 +04:00
}
SAFE_FREE ( mntpath ) ;
SAFE_FREE ( bdev ) ;
SAFE_FREE ( fs ) ;
return ret ;
}
int sys_set_quota ( const char * path , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
int i ;
2007-10-19 04:40:25 +04:00
bool ready = False ;
2003-05-12 05:20:17 +04:00
char * mntpath = NULL ;
char * bdev = NULL ;
char * fs = NULL ;
/* find the block device file */
if ( ! path | | ! dp )
smb_panic ( " get_smb_quota: called with NULL pointer " ) ;
if ( command_set_quota ( path , qtype , id , dp ) = = 0 ) {
return 0 ;
} else if ( errno ! = ENOSYS ) {
return - 1 ;
}
if ( ( ret = sys_path_to_bdev ( path , & mntpath , & bdev , & fs ) ) ! = 0 ) {
2003-07-29 22:07:13 +04:00
DEBUG ( 0 , ( " sys_path_to_bdev() failed for path [%s]! \n " , path ) ) ;
2003-05-12 05:20:17 +04:00
return ret ;
}
2004-01-15 11:49:30 +03:00
errno = 0 ;
DEBUG ( 10 , ( " sys_set_quota() uid(%u, %u) \n " , ( unsigned ) getuid ( ) , ( unsigned ) geteuid ( ) ) ) ;
2003-05-12 05:20:17 +04:00
for ( i = 0 ; ( fs & & sys_quota_backends [ i ] . name & & sys_quota_backends [ i ] . set_quota ) ; i + + ) {
if ( strcmp ( fs , sys_quota_backends [ i ] . name ) = = 0 ) {
ret = sys_quota_backends [ i ] . set_quota ( mntpath , bdev , qtype , id , dp ) ;
2003-07-29 22:07:13 +04:00
if ( ret ! = 0 ) {
2004-01-15 11:49:30 +03:00
DEBUG ( 3 , ( " sys_set_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d]: %s. \n " ,
fs , mntpath , bdev , qtype , ( qtype = = SMB_GROUP_QUOTA_TYPE ? id . gid : id . uid ) , strerror ( errno ) ) ) ;
} else {
DEBUG ( 10 , ( " sys_set_%s_quota() called for mntpath[%s] bdev[%s] qtype[%d] id[%d]. \n " ,
fs , mntpath , bdev , qtype , ( qtype = = SMB_GROUP_QUOTA_TYPE ? id . gid : id . uid ) ) ) ;
2003-07-29 22:07:13 +04:00
}
2003-05-12 05:20:17 +04:00
ready = True ;
break ;
}
}
if ( ! ready ) {
/* use the default vfs quota functions */
ret = sys_set_vfs_quota ( mntpath , bdev , qtype , id , dp ) ;
2003-07-29 22:07:13 +04:00
if ( ret ! = 0 ) {
2004-01-15 11:49:30 +03:00
DEBUG ( 3 , ( " sys_set_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d]: %s. \n " ,
" vfs " , mntpath , bdev , qtype , ( qtype = = SMB_GROUP_QUOTA_TYPE ? id . gid : id . uid ) , strerror ( errno ) ) ) ;
} else {
DEBUG ( 10 , ( " sys_set_%s_quota() called for mntpath[%s] bdev[%s] qtype[%d] id[%d]. \n " ,
" vfs " , mntpath , bdev , qtype , ( qtype = = SMB_GROUP_QUOTA_TYPE ? id . gid : id . uid ) ) ) ;
2003-07-29 22:07:13 +04:00
}
2003-05-12 05:20:17 +04:00
}
SAFE_FREE ( mntpath ) ;
SAFE_FREE ( bdev ) ;
SAFE_FREE ( fs ) ;
return ret ;
}
2003-05-14 18:38:11 +04:00
# else /* HAVE_SYS_QUOTAS */
2005-05-02 21:49:43 +04:00
void dummy_sysquotas_c ( void ) ;
2003-05-14 18:38:11 +04:00
void dummy_sysquotas_c ( void )
{
return ;
}
# endif /* HAVE_SYS_QUOTAS */
2003-05-12 05:20:17 +04:00