summaryrefslogtreecommitdiffstats
path: root/source/lib/sysquotas.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/lib/sysquotas.c')
-rw-r--r--source/lib/sysquotas.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/source/lib/sysquotas.c b/source/lib/sysquotas.c
index 094422ac9bc..4a2d88abdf5 100644
--- a/source/lib/sysquotas.c
+++ b/source/lib/sysquotas.c
@@ -177,19 +177,19 @@ static struct {
#ifdef HAVE_XFS_QUOTAS
{"xfs", sys_get_xfs_quota, sys_set_xfs_quota},
#endif /* HAVE_XFS_QUOTAS */
- {NULL, NULL, NULL}
+ {NULL, NULL, NULL}
};
static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
{
const char *get_quota_command;
char **lines = NULL;
-
+
get_quota_command = lp_get_quota_command();
if (get_quota_command && *get_quota_command) {
const char *p;
char *p2;
- pstring syscmd;
+ char *syscmd = NULL;
int _id = -1;
switch(qtype) {
@@ -206,13 +206,16 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
return -1;
}
- slprintf(syscmd, sizeof(syscmd)-1,
- "%s \"%s\" %d %d",
- get_quota_command, path, qtype, _id);
+ if (asprintf(&syscmd, "%s \"%s\" %d %d",
+ get_quota_command, path, qtype, _id) < 0) {
+ return -1;
+ }
DEBUG (3, ("get_quota: Running command %s\n", syscmd));
lines = file_lines_pload(syscmd, NULL);
+ SAFE_FREE(syscmd);
+
if (lines) {
char *line = lines[0];
@@ -325,7 +328,7 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
errno = ENOSYS;
return -1;
-
+
invalid_param:
file_lines_free(lines);
@@ -336,11 +339,11 @@ invalid_param:
static int command_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
{
const char *set_quota_command;
-
+
set_quota_command = lp_set_quota_command();
if (set_quota_command && *set_quota_command) {
- char **lines;
- pstring syscmd;
+ char **lines = NULL;
+ char *syscmd = NULL;
int _id = -1;
switch(qtype) {
@@ -357,37 +360,40 @@ static int command_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
}
#ifdef LARGE_SMB_OFF_T
- slprintf(syscmd, sizeof(syscmd)-1,
+ if (asprintf(&syscmd,
"%s \"%s\" %d %d "
"%u %llu %llu "
- "%llu %llu %llu ",
+ "%llu %llu %llu ",
set_quota_command, path, qtype, _id, dp->qflags,
(long long unsigned)dp->softlimit,(long long unsigned)dp->hardlimit,
(long long unsigned)dp->isoftlimit,(long long unsigned)dp->ihardlimit,
- (long long unsigned)dp->bsize);
+ (long long unsigned)dp->bsize) < 0) {
+ return -1;
+ }
#else /* LARGE_SMB_OFF_T */
- slprintf(syscmd, sizeof(syscmd)-1,
+ if (asprintf(&syscmd,
"%s \"%s\" %d %d "
"%u %lu %lu "
- "%lu %lu %lu ",
+ "%lu %lu %lu ",
set_quota_command, path, qtype, _id, dp->qflags,
(long unsigned)dp->softlimit,(long unsigned)dp->hardlimit,
(long unsigned)dp->isoftlimit,(long unsigned)dp->ihardlimit,
- (long unsigned)dp->bsize);
+ (long unsigned)dp->bsize) < 0) {
+ return -1;
+ }
#endif /* LARGE_SMB_OFF_T */
-
-
DEBUG (3, ("get_quota: Running command %s\n", syscmd));
lines = file_lines_pload(syscmd, NULL);
+ SAFE_FREE(syscmd);
if (lines) {
char *line = lines[0];
DEBUG (3, ("Read output from set_quota, \"%s\"\n", line));
file_lines_free(lines);
-
+
return 0;
}
DEBUG (0, ("set_quota_command failed!\n"));