2004-01-06 00:03:12 +03:00
/*
Unix SMB / CIFS implementation .
System QUOTA function wrappers for LINUX
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
2004-01-06 00:03:12 +03: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/>.
2004-01-06 00:03:12 +03:00
*/
# include "includes.h"
2004-01-15 11:49:30 +03:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_QUOTA
2005-09-12 13:38:22 +04:00
# ifndef HAVE_SYS_QUOTAS
# ifdef HAVE_QUOTACTL_LINUX
# undef HAVE_QUOTACTL_LINUX
# endif
# endif
2016-05-23 23:14:12 +03:00
# ifdef HAVE_QUOTACTL_LINUX
2004-01-06 00:03:12 +03:00
2016-05-23 22:07:39 +03:00
# include <sys/quota.h>
2004-01-06 00:03:12 +03:00
/****************************************************************************
2016-05-23 23:14:12 +03:00
Linux quota get calls .
2004-01-06 00:03:12 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2016-05-23 23:14:12 +03:00
int sys_get_vfs_quota ( const char * path , const char * bdev ,
enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
2004-01-06 00:03:12 +03:00
{
int ret = - 1 ;
2015-05-10 02:33:10 +03:00
uint32_t qflags = 0 ;
2016-05-23 22:07:39 +03:00
struct dqblk D ;
2008-10-14 03:59:36 +04:00
uint64_t bsize = ( uint64_t ) QUOTABLOCK_SIZE ;
2004-01-06 00:03:12 +03:00
2016-05-23 23:14:12 +03:00
if ( ! path | | ! bdev | | ! dp ) {
smb_panic ( " sys_get_vfs_quota: called with NULL pointer " ) ;
}
ZERO_STRUCT ( * dp ) ;
dp - > qtype = qtype ;
2004-01-06 00:03:12 +03:00
ZERO_STRUCT ( D ) ;
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
2016-05-23 23:14:12 +03:00
DEBUG ( 10 , ( " sys_get_vfs_quota: path[%s] bdev[%s] "
" SMB_USER_QUOTA_TYPE uid[%u] \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-15 11:49:30 +03:00
2016-05-26 10:24:58 +03:00
if ( ( ret = quotactl ( QCMD ( Q_GETQUOTA , USRQUOTA ) , bdev ,
id . uid , ( caddr_t ) & D ) ) ) {
2004-01-06 00:03:12 +03:00
return ret ;
}
break ;
case SMB_GROUP_QUOTA_TYPE :
2016-05-23 23:14:12 +03:00
DEBUG ( 10 , ( " sys_get_vfs_quota: path[%s] bdev[%s] "
" SMB_GROUP_QUOTA_TYPE gid[%u] \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-15 11:49:30 +03:00
2016-05-26 10:24:58 +03:00
if ( ( ret = quotactl ( QCMD ( Q_GETQUOTA , GRPQUOTA ) , bdev ,
id . gid , ( caddr_t ) & D ) ) ) {
2004-01-06 00:03:12 +03:00
return ret ;
}
break ;
case SMB_USER_FS_QUOTA_TYPE :
2016-05-23 23:14:12 +03:00
DEBUG ( 10 , ( " sys_get_vfs_quota: path[%s] bdev[%s] "
" SMB_USER_FS_QUOTA_TYPE (uid[%u]) \n " ,
path , bdev , ( unsigned ) geteuid ( ) ) ) ;
2004-01-15 11:49:30 +03:00
2016-05-23 23:14:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_GETQUOTA , USRQUOTA ) , bdev ,
geteuid ( ) , ( caddr_t ) & D ) ) = = 0 ) {
2004-01-06 00:03:12 +03:00
qflags | = QUOTAS_DENY_DISK ;
}
2016-05-23 23:14:12 +03:00
ret = 0 ;
2004-01-06 00:03:12 +03:00
break ;
case SMB_GROUP_FS_QUOTA_TYPE :
2016-05-23 23:14:12 +03:00
DEBUG ( 10 , ( " sys_get_vfs_quota: path[%s] bdev[%s] "
" SMB_GROUP_FS_QUOTA_TYPE (gid[%u]) \n " ,
path , bdev , ( unsigned ) getgid ( ) ) ) ;
2004-01-15 11:49:30 +03:00
2016-05-23 23:14:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_GETQUOTA , GRPQUOTA ) , bdev ,
getgid ( ) , ( caddr_t ) & D ) ) = = 0 ) {
2004-01-06 00:03:12 +03:00
qflags | = QUOTAS_DENY_DISK ;
}
2016-05-23 23:14:12 +03:00
ret = 0 ;
2004-01-06 00:03:12 +03:00
break ;
default :
errno = ENOSYS ;
return - 1 ;
}
dp - > bsize = bsize ;
2008-10-14 03:59:36 +04:00
dp - > softlimit = ( uint64_t ) D . dqb_bsoftlimit ;
dp - > hardlimit = ( uint64_t ) D . dqb_bhardlimit ;
dp - > ihardlimit = ( uint64_t ) D . dqb_ihardlimit ;
dp - > isoftlimit = ( uint64_t ) D . dqb_isoftlimit ;
dp - > curinodes = ( uint64_t ) D . dqb_curinodes ;
dp - > curblocks = ( uint64_t ) D . dqb_curspace / bsize ;
2004-01-06 00:03:12 +03:00
dp - > qflags = qflags ;
return ret ;
}
/****************************************************************************
2016-05-23 23:14:12 +03:00
Linux quota set calls .
2004-01-06 00:03:12 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2016-05-23 23:14:12 +03:00
int sys_set_vfs_quota ( const char * path , const char * bdev ,
enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
2004-01-06 00:03:12 +03:00
{
int ret = - 1 ;
2016-05-23 22:07:39 +03:00
struct dqblk D ;
2008-10-14 03:59:36 +04:00
uint64_t bsize = ( uint64_t ) QUOTABLOCK_SIZE ;
2016-05-23 23:14:12 +03:00
bool cur_enf , new_enf ;
if ( ! path | | ! bdev | | ! dp ) {
smb_panic ( " sys_set_vfs_quota: called with NULL pointer " ) ;
}
2004-01-06 00:03:12 +03:00
ZERO_STRUCT ( D ) ;
if ( bsize = = dp - > bsize ) {
D . dqb_bsoftlimit = dp - > softlimit ;
D . dqb_bhardlimit = dp - > hardlimit ;
D . dqb_ihardlimit = dp - > ihardlimit ;
D . dqb_isoftlimit = dp - > isoftlimit ;
} else {
D . dqb_bsoftlimit = ( dp - > softlimit * dp - > bsize ) / bsize ;
D . dqb_bhardlimit = ( dp - > hardlimit * dp - > bsize ) / bsize ;
D . dqb_ihardlimit = ( dp - > ihardlimit * dp - > bsize ) / bsize ;
D . dqb_isoftlimit = ( dp - > isoftlimit * dp - > bsize ) / bsize ;
}
2005-10-13 18:59:47 +04:00
D . dqb_valid = QIF_LIMITS ;
2004-01-06 00:03:12 +03:00
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
2016-05-23 23:14:12 +03:00
DEBUG ( 10 , ( " sys_set_vfs_quota: path[%s] bdev[%s] "
" SMB_USER_QUOTA_TYPE uid[%u] \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-15 11:49:30 +03:00
2004-01-06 00:03:12 +03:00
ret = quotactl ( QCMD ( Q_SETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ;
break ;
case SMB_GROUP_QUOTA_TYPE :
2016-05-23 23:14:12 +03:00
DEBUG ( 10 , ( " sys_set_vfs_quota: path[%s] bdev[%s] "
" SMB_GROUP_QUOTA_TYPE gid[%u] \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-15 11:49:30 +03:00
2004-01-06 00:03:12 +03:00
ret = quotactl ( QCMD ( Q_SETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ;
break ;
case SMB_USER_FS_QUOTA_TYPE :
2016-05-23 23:14:12 +03:00
DEBUG ( 10 , ( " sys_set_vfs_quota: path[%s] bdev[%s] "
" SMB_USER_FS_QUOTA_TYPE (uid[%u]) \n " ,
path , bdev , ( unsigned ) geteuid ( ) ) ) ;
ret = quotactl ( QCMD ( Q_GETQUOTA , USRQUOTA ) , bdev ,
geteuid ( ) , ( caddr_t ) & D ) ;
cur_enf = ( ret = = 0 ) ;
new_enf = ( ( dp - > qflags & QUOTAS_DENY_DISK ) ! = 0 ) ;
/* We're not changing quota enforcement, so return
* success
* IFF the wanted state is identical to the current
* state */
if ( cur_enf = = new_enf ) {
2004-01-06 00:03:12 +03:00
ret = 0 ;
} else {
2016-05-23 23:14:12 +03:00
errno = EPERM ;
2004-01-06 00:03:12 +03:00
ret = - 1 ;
}
2016-05-23 23:14:12 +03:00
2004-01-06 00:03:12 +03:00
break ;
case SMB_GROUP_FS_QUOTA_TYPE :
2016-05-23 23:14:12 +03:00
DEBUG ( 10 , ( " sys_set_vfs_quota: path[%s] bdev[%s] "
" SMB_GROUP_FS_QUOTA_TYPE (gid[%u]) \n " ,
path , bdev , ( unsigned ) getgid ( ) ) ) ;
ret = quotactl ( QCMD ( Q_GETQUOTA , GRPQUOTA ) , bdev ,
getgid ( ) , ( caddr_t ) & D ) ;
cur_enf = ( ret = = 0 ) ;
new_enf = ( ( dp - > qflags & QUOTAS_DENY_DISK ) ! = 0 ) ;
/* We're not changing quota enforcement, so return
* success
* IFF the wanted state is identical to the current
* state */
if ( cur_enf = = new_enf ) {
2004-01-06 00:03:12 +03:00
ret = 0 ;
} else {
2016-05-23 23:14:12 +03:00
errno = EPERM ;
2004-01-06 00:03:12 +03:00
ret = - 1 ;
}
break ;
default :
errno = ENOSYS ;
return - 1 ;
}
return ret ;
}
2004-01-06 21:13:32 +03:00
# else /* HAVE_QUOTACTL_LINUX */
2005-05-02 21:49:43 +04:00
void dummy_sysquotas_linux ( void ) ;
2004-01-06 21:13:32 +03:00
void dummy_sysquotas_linux ( void ) { }
2004-01-06 00:03:12 +03:00
# endif /* HAVE_QUOTACTL_LINUX */