]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Scan output of get quota command with sscanf
authorVolker Lendecke <vl@samba.org>
Wed, 14 Jan 2026 09:17:22 +0000 (10:17 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 20 Jan 2026 11:53:34 +0000 (11:53 +0000)
sscanf can skip white space and also parse uint32/uint64 for us.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/lib/sysquotas.c

index 276513b2a7873c97475939d7afe5b699ad92332c..52e5f384b835268797d26ba9834a7b865c7acd28 100644 (file)
@@ -255,6 +255,7 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
        int _id = -1;
        int error = 0;
        char **argl = NULL;
+       int ret;
 
        get_quota_command = lp_get_quota_command(talloc_tos(), lp_sub);
        if ((get_quota_command == NULL) || (get_quota_command[0] == '\0')) {
@@ -304,87 +305,27 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
 
        DBG_NOTICE("Read output from get_quota, \"%s\"\n", line);
 
-       /* we need to deal with long long unsigned here, if supported */
+       dp->bsize = 1024;
 
-       dp->qflags = smb_strtoul(line, &p2, 10, &error, SMB_STR_STANDARD);
-       if (error != 0) {
-               goto invalid_param;
-       }
-
-       p = p2;
-       while (p && *p && isspace(*p)) {
-               p++;
-       }
-
-       if (p && *p) {
-               dp->curblocks = STR_TO_SMB_BIG_UINT(p, &p);
-       } else {
-               goto invalid_param;
-       }
-
-       while (p && *p && isspace(*p)) {
-               p++;
-       }
-
-       if (p && *p) {
-               dp->softlimit = STR_TO_SMB_BIG_UINT(p, &p);
-       } else {
-               goto invalid_param;
-       }
-
-       while (p && *p && isspace(*p)) {
-               p++;
-       }
-
-       if (p && *p) {
-               dp->hardlimit = STR_TO_SMB_BIG_UINT(p, &p);
-       } else {
-               goto invalid_param;
-       }
-
-       while (p && *p && isspace(*p)) {
-               p++;
-       }
-
-       if (p && *p) {
-               dp->curinodes = STR_TO_SMB_BIG_UINT(p, &p);
-       } else {
-               goto invalid_param;
-       }
-
-       while (p && *p && isspace(*p)) {
-               p++;
-       }
-
-       if (p && *p) {
-               dp->isoftlimit = STR_TO_SMB_BIG_UINT(p, &p);
-       } else {
-               goto invalid_param;
-       }
+       ret = sscanf(line,
+                    "%" SCNu32 " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64
+                    " %" SCNu64 " %" SCNu64 " %" SCNu64,
+                    &dp->qflags,
+                    &dp->curblocks,
+                    &dp->softlimit,
+                    &dp->hardlimit,
+                    &dp->curinodes,
+                    &dp->isoftlimit,
+                    &dp->ihardlimit,
+                    &dp->bsize);
 
-       while (p && *p && isspace(*p)) {
-               p++;
-       }
-
-       if (p && *p) {
-               dp->ihardlimit = STR_TO_SMB_BIG_UINT(p, &p);
-       } else {
-               goto invalid_param;
-       }
-
-       while (p && *p && isspace(*p)) {
-               p++;
-       }
+       TALLOC_FREE(lines);
 
-       if (p && *p) {
-               dp->bsize = STR_TO_SMB_BIG_UINT(p, NULL);
-       } else {
-               dp->bsize = 1024;
+       if (ret != 7) {
+               DBG_ERR("The output of get_quota_command is invalid!\n");
+               return -1;
        }
 
-       TALLOC_FREE(lines);
-       lines = NULL;
-
        DBG_INFO("Parsed output of get_quota, ...\n"
                 "qflags:%" PRIu32 " curblocks:%" PRIu64 " softlimit:%" PRIu64
                 " hardlimit:%" PRIu64 "\n"
@@ -401,7 +342,6 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
        return 0;
 
 invalid_param:
-
        TALLOC_FREE(lines);
        DBG_ERR("The output of get_quota_command is invalid!\n");
        return -1;