s3: smbd: Convert sysquotas.c code to use file_lines_ploadv().
authorJeremy Allison <jra@samba.org>
Sat, 18 May 2019 18:08:15 +0000 (11:08 -0700)
committerJeremy Allison <jra@samba.org>
Fri, 24 May 2019 19:00:05 +0000 (19:00 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13964

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/lib/sysquotas.c

index 43a451da596a7f073c1c3d0de34888fd84591adb..864d9dd5c56cd44d4e09dde29f7578a11115cbd8 100644 (file)
@@ -251,9 +251,9 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
        if (get_quota_command && *get_quota_command) {
                const char *p;
                char *p2;
-               char *syscmd = NULL;
                int _id = -1;
                int error = 0;
+               char **argl = NULL;
 
                switch(qtype) {
                        case SMB_USER_QUOTA_TYPE:
@@ -269,15 +269,40 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
                                return -1;
                }
 
-               if (asprintf(&syscmd, "%s %s %d %d",
-                       get_quota_command, path, qtype, _id) < 0) {
+               argl = talloc_zero_array(talloc_tos(), char *, 5);
+               if (argl == NULL) {
                        return -1;
                }
+               argl[0] = talloc_strdup(argl, get_quota_command);
+               if (argl[0] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[1] = talloc_strdup(argl, path);
+               if (argl[1] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[2] = talloc_asprintf(argl, "%d", qtype);
+               if (argl[2] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[3] = talloc_asprintf(argl, "%d", _id);
+               if (argl[3] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[4] = NULL;
 
-               DEBUG (3, ("get_quota: Running command %s\n", syscmd));
+               DBG_NOTICE("Running command %s %s %d %d\n",
+                       get_quota_command,
+                       path,
+                       qtype,
+                       _id);
 
-               lines = file_lines_pload(talloc_tos(), syscmd, NULL);
-               SAFE_FREE(syscmd);
+               lines = file_lines_ploadv(talloc_tos(), argl, NULL);
+               TALLOC_FREE(argl);
 
                if (lines) {
                        char *line = lines[0];
@@ -399,8 +424,8 @@ static int command_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
        set_quota_command = lp_set_quota_command(talloc_tos());
        if (set_quota_command && *set_quota_command) {
                char **lines = NULL;
-               char *syscmd = NULL;
                int _id = -1;
+               char **argl = NULL;
 
                switch(qtype) {
                        case SMB_USER_QUOTA_TYPE:
@@ -415,21 +440,84 @@ static int command_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
                                return -1;
                }
 
-               if (asprintf(&syscmd,
-                       "%s %s %d %d "
-                       "%u %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) < 0) {
+               argl = talloc_zero_array(talloc_tos(), char *, 11);
+               if (argl == NULL) {
                        return -1;
                }
+               argl[0] = talloc_strdup(argl, set_quota_command);
+               if (argl[0] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[1] = talloc_strdup(argl, path);
+               if (argl[1] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[2] = talloc_asprintf(argl, "%d", qtype);
+               if (argl[2] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[3] = talloc_asprintf(argl, "%d", _id);
+               if (argl[3] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[4] = talloc_asprintf(argl, "%u", dp->qflags);
+               if (argl[4] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[5] = talloc_asprintf(argl, "%llu",
+                               (long long unsigned)dp->softlimit);
+               if (argl[5] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[6] = talloc_asprintf(argl, "%llu",
+                               (long long unsigned)dp->hardlimit);
+               if (argl[6] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[7] = talloc_asprintf(argl, "%llu",
+                               (long long unsigned)dp->isoftlimit);
+               if (argl[7] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[8] = talloc_asprintf(argl, "%llu",
+                               (long long unsigned)dp->ihardlimit);
+               if (argl[8] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[9] = talloc_asprintf(argl, "%llu",
+                               (long long unsigned)dp->bsize);
+               if (argl[9] == NULL) {
+                       TALLOC_FREE(argl);
+                       return -1;
+               }
+               argl[10] = NULL;
 
-               DBG_NOTICE("set_quota: Running command %s\n", syscmd);
-
-               lines = file_lines_pload(talloc_tos(), syscmd, NULL);
-               SAFE_FREE(syscmd);
+               DBG_NOTICE("Running command "
+                       "%s %s %d %d "
+                       "%u %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);
+
+               lines = file_lines_ploadv(talloc_tos(), argl, NULL);
+               TALLOC_FREE(argl);
                if (lines) {
                        char *line = lines[0];