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
2004-01-06 00:03:12 +03:00
# ifdef HAVE_QUOTACTL_LINUX
# include "samba_linux_quota.h"
/****************************************************************************
Abstract out the v1 Linux quota get calls .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int sys_get_linux_v1_quota ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
2015-05-10 02:33:10 +03:00
uint32_t qflags = 0 ;
2004-01-06 00:03:12 +03:00
struct v1_kern_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
ZERO_STRUCT ( D ) ;
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_v1_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u] \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V1_GETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ) & & errno ! = EDQUOT ) {
return ret ;
}
break ;
case SMB_GROUP_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_v1_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u] \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V1_GETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ) & & errno ! = EDQUOT ) {
return ret ;
}
break ;
case SMB_USER_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_v1_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u]) \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V1_GETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ) = = 0 ) {
qflags | = QUOTAS_DENY_DISK ;
}
break ;
case SMB_GROUP_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_v1_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u]) \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V1_GETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ) = = 0 ) {
qflags | = QUOTAS_DENY_DISK ;
}
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_curblocks ;
2004-01-06 00:03:12 +03:00
dp - > qflags = qflags ;
return ret ;
}
/****************************************************************************
Abstract out the v1 Linux quota set calls .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int sys_set_linux_v1_quota ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
struct v1_kern_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
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 ;
}
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_v1_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u] \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:03:12 +03:00
ret = quotactl ( QCMD ( Q_V1_SETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ;
break ;
case SMB_GROUP_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_v1_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u] \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:03:12 +03:00
ret = quotactl ( QCMD ( Q_V1_SETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ;
break ;
case SMB_USER_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_v1_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u]) \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V1_GETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ) = = 0 ) {
2015-06-19 09:23:23 +03:00
dp - > qflags | = QUOTAS_DENY_DISK ;
2004-01-06 00:03:12 +03:00
}
break ;
case SMB_GROUP_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_v1_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u]) \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V1_GETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ) = = 0 ) {
2015-06-19 09:23:23 +03:00
dp - > qflags | = QUOTAS_DENY_DISK ;
2004-01-06 00:03:12 +03:00
}
break ;
default :
errno = ENOSYS ;
return - 1 ;
}
return ret ;
}
/****************************************************************************
Abstract out the v2 Linux quota get calls .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int sys_get_linux_v2_quota ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
2015-05-10 02:33:10 +03:00
uint32_t qflags = 0 ;
2004-01-06 00:03:12 +03:00
struct v2_kern_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
ZERO_STRUCT ( D ) ;
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_v2_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u] \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V2_GETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ) & & errno ! = EDQUOT ) {
return ret ;
}
break ;
case SMB_GROUP_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_v2_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u] \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V2_GETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ) & & errno ! = EDQUOT ) {
return ret ;
}
break ;
case SMB_USER_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_v2_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u]) \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V2_GETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ) = = 0 ) {
qflags | = QUOTAS_DENY_DISK ;
}
break ;
case SMB_GROUP_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_v2_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u]) \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V2_GETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ) = = 0 ) {
qflags | = QUOTAS_DENY_DISK ;
}
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 ;
}
/****************************************************************************
Abstract out the v2 Linux quota set calls .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int sys_set_linux_v2_quota ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
struct v2_kern_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
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 ;
}
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_v2_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u] \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:03:12 +03:00
ret = quotactl ( QCMD ( Q_V2_SETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ;
break ;
case SMB_GROUP_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_v2_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u] \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:03:12 +03:00
ret = quotactl ( QCMD ( Q_V2_SETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ;
break ;
case SMB_USER_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_v2_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u]) \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V2_GETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ) = = 0 ) {
2015-06-19 09:23:23 +03:00
dp - > qflags | = QUOTAS_DENY_DISK ;
2004-01-06 00:03:12 +03:00
}
break ;
case SMB_GROUP_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_v2_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u]) \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_V2_GETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ) = = 0 ) {
2015-06-19 09:23:23 +03:00
dp - > qflags | = QUOTAS_DENY_DISK ;
2004-01-06 00:03:12 +03:00
}
break ;
default :
errno = ENOSYS ;
return - 1 ;
}
return ret ;
}
/****************************************************************************
Abstract out the generic Linux quota get calls .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int sys_get_linux_gen_quota ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
2015-05-10 02:33:10 +03:00
uint32_t qflags = 0 ;
2004-01-06 00:03:12 +03:00
struct if_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
ZERO_STRUCT ( D ) ;
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_gen_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u] \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_GETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ) & & errno ! = EDQUOT ) {
return ret ;
}
break ;
case SMB_GROUP_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_gen_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u] \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_GETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ) & & errno ! = EDQUOT ) {
return ret ;
}
break ;
case SMB_USER_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_gen_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u]) \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_GETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ) = = 0 ) {
qflags | = QUOTAS_DENY_DISK ;
}
break ;
case SMB_GROUP_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_get_linux_gen_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u]) \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_GETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ) = = 0 ) {
qflags | = QUOTAS_DENY_DISK ;
}
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 ;
}
/****************************************************************************
Abstract out the gen Linux quota set calls .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int sys_set_linux_gen_quota ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
struct if_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
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 :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_gen_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u] \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
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 :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_gen_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u] \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
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 :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_gen_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u]) \n " ,
path , bdev , ( unsigned ) id . uid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_GETQUOTA , USRQUOTA ) , bdev , id . uid , ( caddr_t ) & D ) ) = = 0 ) {
2015-06-19 09:23:23 +03:00
dp - > qflags | = QUOTAS_DENY_DISK ;
2004-01-06 00:03:12 +03:00
}
break ;
case SMB_GROUP_FS_QUOTA_TYPE :
2004-01-15 11:49:30 +03:00
DEBUG ( 10 , ( " sys_set_linux_gen_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u]) \n " ,
path , bdev , ( unsigned ) id . gid ) ) ;
2004-01-06 00:03:12 +03:00
if ( ( ret = quotactl ( QCMD ( Q_GETQUOTA , GRPQUOTA ) , bdev , id . gid , ( caddr_t ) & D ) ) = = 0 ) {
2015-06-19 09:23:23 +03:00
dp - > qflags | = QUOTAS_DENY_DISK ;
2004-01-06 00:03:12 +03:00
}
break ;
default :
errno = ENOSYS ;
return - 1 ;
}
return ret ;
}
/****************************************************************************
Abstract out the Linux quota get calls .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int sys_get_vfs_quota ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
if ( ! path | | ! bdev | | ! dp )
2004-01-06 21:13:32 +03:00
smb_panic ( " sys_set_vfs_quota: called with NULL pointer " ) ;
2004-01-06 00:03:12 +03:00
ZERO_STRUCT ( * dp ) ;
dp - > qtype = qtype ;
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
case SMB_GROUP_QUOTA_TYPE :
if ( ( ret = sys_get_linux_gen_quota ( path , bdev , qtype , id , dp ) ) & & errno ! = EDQUOT ) {
if ( ( ret = sys_get_linux_v2_quota ( path , bdev , qtype , id , dp ) ) & & errno ! = EDQUOT ) {
if ( ( ret = sys_get_linux_v1_quota ( path , bdev , qtype , id , dp ) ) & & errno ! = EDQUOT ) {
return ret ;
}
}
}
if ( ( dp - > curblocks = = 0 ) & &
( dp - > softlimit = = 0 ) & &
( dp - > hardlimit = = 0 ) ) {
/* the upper layer functions don't want empty quota records...*/
return - 1 ;
}
break ;
case SMB_USER_FS_QUOTA_TYPE :
id . uid = getuid ( ) ;
if ( ( ret = sys_get_linux_gen_quota ( path , bdev , qtype , id , dp ) ) & & errno ! = EDQUOT ) {
if ( ( ret = sys_get_linux_v2_quota ( path , bdev , qtype , id , dp ) ) & & errno ! = EDQUOT ) {
ret = sys_get_linux_v1_quota ( path , bdev , qtype , id , dp ) ;
}
}
ret = 0 ;
break ;
case SMB_GROUP_FS_QUOTA_TYPE :
id . gid = getgid ( ) ;
if ( ( ret = sys_get_linux_gen_quota ( path , bdev , qtype , id , dp ) ) & & errno ! = EDQUOT ) {
if ( ( ret = sys_get_linux_v2_quota ( path , bdev , qtype , id , dp ) ) & & errno ! = EDQUOT ) {
ret = sys_get_linux_v1_quota ( path , bdev , qtype , id , dp ) ;
}
}
ret = 0 ;
break ;
default :
errno = ENOSYS ;
return - 1 ;
}
return ret ;
}
/****************************************************************************
Abstract out the Linux quota set calls .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int sys_set_vfs_quota ( const char * path , const char * bdev , enum SMB_QUOTA_TYPE qtype , unid_t id , SMB_DISK_QUOTA * dp )
{
int ret = - 1 ;
2015-05-10 02:33:10 +03:00
uint32_t oldqflags = 0 ;
2004-01-06 00:03:12 +03:00
if ( ! path | | ! bdev | | ! dp )
2004-01-06 21:13:32 +03:00
smb_panic ( " sys_set_vfs_quota: called with NULL pointer " ) ;
2004-01-06 00:03:12 +03:00
oldqflags = dp - > qflags ;
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
case SMB_GROUP_QUOTA_TYPE :
if ( ( ret = sys_set_linux_gen_quota ( path , bdev , qtype , id , dp ) ) ) {
if ( ( ret = sys_set_linux_v2_quota ( path , bdev , qtype , id , dp ) ) ) {
if ( ( ret = sys_set_linux_v1_quota ( path , bdev , qtype , id , dp ) ) ) {
return ret ;
}
}
}
break ;
case SMB_USER_FS_QUOTA_TYPE :
id . uid = getuid ( ) ;
2006-12-01 18:12:22 +03:00
if ( ( ret = sys_set_linux_gen_quota ( path , bdev , qtype , id , dp ) ) ) {
if ( ( ret = sys_set_linux_v2_quota ( path , bdev , qtype , id , dp ) ) ) {
ret = sys_set_linux_v1_quota ( path , bdev , qtype , id , dp ) ;
2004-01-06 00:03:12 +03:00
}
}
if ( oldqflags = = dp - > qflags ) {
ret = 0 ;
} else {
ret = - 1 ;
}
break ;
case SMB_GROUP_FS_QUOTA_TYPE :
id . gid = getgid ( ) ;
2006-12-01 18:12:22 +03:00
if ( ( ret = sys_set_linux_gen_quota ( path , bdev , qtype , id , dp ) ) ) {
if ( ( ret = sys_set_linux_v2_quota ( path , bdev , qtype , id , dp ) ) ) {
ret = sys_set_linux_v1_quota ( path , bdev , qtype , id , dp ) ;
2004-01-06 00:03:12 +03:00
}
}
if ( oldqflags = = dp - > qflags ) {
ret = 0 ;
} else {
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 */