summaryrefslogtreecommitdiff
path: root/source3/lib/sysquotas_linux.c
diff options
context:
space:
mode:
authorUri Simchoni <uri@samba.org>2016-05-23 23:14:12 +0300
committerUri Simchoni <uri@samba.org>2016-05-26 18:54:12 +0200
commit847eff3b4be5925dea0a23829a3bdbf13a50073a (patch)
tree1db6ecb39a331899885c25d525359c68c8da26bd /source3/lib/sysquotas_linux.c
parent38356bed8064e2b4be2923ae2073800248db749f (diff)
downloadsamba-847eff3b4be5925dea0a23829a3bdbf13a50073a.tar.gz
s3-sysquotas-linux - cleanup
Now that the module supports only the current Linux quota interface, it does not need a two-level hierarchy. Signed-off-by: Uri Simchoni <uri@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Uri Simchoni <uri@samba.org> Autobuild-Date(master): Thu May 26 18:54:12 CEST 2016 on sn-devel-144
Diffstat (limited to 'source3/lib/sysquotas_linux.c')
-rw-r--r--source3/lib/sysquotas_linux.c188
1 files changed, 73 insertions, 115 deletions
diff --git a/source3/lib/sysquotas_linux.c b/source3/lib/sysquotas_linux.c
index 2de3c85106a..55d1518c0eb 100644
--- a/source3/lib/sysquotas_linux.c
+++ b/source3/lib/sysquotas_linux.c
@@ -29,26 +29,35 @@
#endif
#endif
-#ifdef HAVE_QUOTACTL_LINUX
+#ifdef HAVE_QUOTACTL_LINUX
#include <sys/quota.h>
/****************************************************************************
- Abstract out the generic Linux quota get calls.
+ 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 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;
uint32_t qflags = 0;
struct dqblk D;
uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
+ if (!path || !bdev || !dp) {
+ smb_panic("sys_get_vfs_quota: called with NULL pointer");
+ }
+
+ ZERO_STRUCT(*dp);
+ dp->qtype = qtype;
+
ZERO_STRUCT(D);
switch (qtype) {
case SMB_USER_QUOTA_TYPE:
- DEBUG(10,("sys_get_linux_gen_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u]\n",
- path, bdev, (unsigned)id.uid));
+ DEBUG(10, ("sys_get_vfs_quota: path[%s] bdev[%s] "
+ "SMB_USER_QUOTA_TYPE uid[%u]\n",
+ path, bdev, (unsigned)id.uid));
if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), bdev, id.uid, (caddr_t)&D))&&errno != EDQUOT) {
return ret;
@@ -56,8 +65,9 @@ static int sys_get_linux_gen_quota(const char *path, const char *bdev, enum SMB_
break;
case SMB_GROUP_QUOTA_TYPE:
- DEBUG(10,("sys_get_linux_gen_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u]\n",
- path, bdev, (unsigned)id.gid));
+ DEBUG(10, ("sys_get_vfs_quota: path[%s] bdev[%s] "
+ "SMB_GROUP_QUOTA_TYPE gid[%u]\n",
+ path, bdev, (unsigned)id.gid));
if ((ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), bdev, id.gid, (caddr_t)&D))&&errno != EDQUOT) {
return ret;
@@ -65,22 +75,29 @@ static int sys_get_linux_gen_quota(const char *path, const char *bdev, enum SMB_
break;
case SMB_USER_FS_QUOTA_TYPE:
- DEBUG(10,("sys_get_linux_gen_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u])\n",
- path, bdev, (unsigned)id.uid));
+ DEBUG(10, ("sys_get_vfs_quota: path[%s] bdev[%s] "
+ "SMB_USER_FS_QUOTA_TYPE (uid[%u])\n",
+ path, bdev, (unsigned)geteuid()));
- if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), bdev, id.uid, (caddr_t)&D))==0) {
+ if ((ret = quotactl(QCMD(Q_GETQUOTA, USRQUOTA), bdev,
+ geteuid(), (caddr_t)&D)) == 0) {
qflags |= QUOTAS_DENY_DISK;
}
+ ret = 0;
+
break;
case SMB_GROUP_FS_QUOTA_TYPE:
- DEBUG(10,("sys_get_linux_gen_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u])\n",
- path, bdev, (unsigned)id.gid));
+ DEBUG(10, ("sys_get_vfs_quota: path[%s] bdev[%s] "
+ "SMB_GROUP_FS_QUOTA_TYPE (gid[%u])\n",
+ path, bdev, (unsigned)getgid()));
- if ((ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), bdev, id.gid, (caddr_t)&D))==0) {
+ if ((ret = quotactl(QCMD(Q_GETQUOTA, GRPQUOTA), bdev,
+ getgid(), (caddr_t)&D)) == 0) {
qflags |= QUOTAS_DENY_DISK;
}
+ ret = 0;
break;
default:
errno = ENOSYS;
@@ -102,13 +119,19 @@ static int sys_get_linux_gen_quota(const char *path, const char *bdev, enum SMB_
}
/****************************************************************************
- Abstract out the gen Linux quota set calls.
+ 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 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;
struct dqblk D;
uint64_t bsize = (uint64_t)QUOTABLOCK_SIZE;
+ bool cur_enf, new_enf;
+
+ if (!path || !bdev || !dp) {
+ smb_panic("sys_set_vfs_quota: called with NULL pointer");
+ }
ZERO_STRUCT(D);
@@ -127,122 +150,57 @@ static int sys_set_linux_gen_quota(const char *path, const char *bdev, enum SMB_
switch (qtype) {
case SMB_USER_QUOTA_TYPE:
- DEBUG(10,("sys_set_linux_gen_quota: path[%s] bdev[%s] SMB_USER_QUOTA_TYPE uid[%u]\n",
- path, bdev, (unsigned)id.uid));
+ DEBUG(10, ("sys_set_vfs_quota: path[%s] bdev[%s] "
+ "SMB_USER_QUOTA_TYPE uid[%u]\n",
+ path, bdev, (unsigned)id.uid));
ret = quotactl(QCMD(Q_SETQUOTA,USRQUOTA), bdev, id.uid, (caddr_t)&D);
break;
case SMB_GROUP_QUOTA_TYPE:
- DEBUG(10,("sys_set_linux_gen_quota: path[%s] bdev[%s] SMB_GROUP_QUOTA_TYPE gid[%u]\n",
- path, bdev, (unsigned)id.gid));
+ DEBUG(10, ("sys_set_vfs_quota: path[%s] bdev[%s] "
+ "SMB_GROUP_QUOTA_TYPE gid[%u]\n",
+ path, bdev, (unsigned)id.gid));
ret = quotactl(QCMD(Q_SETQUOTA,GRPQUOTA), bdev, id.gid, (caddr_t)&D);
break;
case SMB_USER_FS_QUOTA_TYPE:
- DEBUG(10,("sys_set_linux_gen_quota: path[%s] bdev[%s] SMB_USER_FS_QUOTA_TYPE (uid[%u])\n",
- path, bdev, (unsigned)id.uid));
-
- if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), bdev, id.uid, (caddr_t)&D))==0) {
- dp->qflags |= QUOTAS_DENY_DISK;
- }
-
- break;
- case SMB_GROUP_FS_QUOTA_TYPE:
- DEBUG(10,("sys_set_linux_gen_quota: path[%s] bdev[%s] SMB_GROUP_FS_QUOTA_TYPE (gid[%u])\n",
- path, bdev, (unsigned)id.gid));
-
- if ((ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), bdev, id.gid, (caddr_t)&D))==0) {
- dp->qflags |= QUOTAS_DENY_DISK;
- }
-
- 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)
- smb_panic("sys_set_vfs_quota: called with NULL pointer");
-
- ZERO_STRUCT(*dp);
- dp->qtype = qtype;
-
- switch (qtype) {
- case SMB_USER_QUOTA_TYPE:
- case SMB_GROUP_QUOTA_TYPE:
- ret=sys_get_linux_gen_quota(path, bdev, qtype, id, dp);
- break;
- case SMB_USER_FS_QUOTA_TYPE:
- id.uid = getuid();
-
- sys_get_linux_gen_quota(path, bdev, qtype, id, dp);
-
- ret = 0;
- break;
- case SMB_GROUP_FS_QUOTA_TYPE:
- id.gid = getgid();
-
- sys_get_linux_gen_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;
- uint32_t oldqflags = 0;
-
- if (!path||!bdev||!dp)
- smb_panic("sys_set_vfs_quota: called with NULL pointer");
-
- 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))) {
- return ret;
- }
- break;
- case SMB_USER_FS_QUOTA_TYPE:
- id.uid = getuid();
-
- sys_set_linux_gen_quota(path, bdev, qtype, id, dp);
-
- if (oldqflags == dp->qflags) {
+ 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) {
ret = 0;
} else {
+ errno = EPERM;
ret = -1;
}
+
break;
case SMB_GROUP_FS_QUOTA_TYPE:
- id.gid = getgid();
-
- sys_set_linux_gen_quota(path, bdev, qtype, id, dp);
-
- if (oldqflags == dp->qflags) {
+ 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) {
ret = 0;
} else {
+ errno = EPERM;
ret = -1;
}