]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Convert sys_path_to_bdev to talloc
authorVolker Lendecke <vl@samba.org>
Mon, 26 Jan 2026 14:35:39 +0000 (15:35 +0100)
committerAnoop C S <anoopcs@samba.org>
Sun, 15 Feb 2026 10:42:34 +0000 (10:42 +0000)
Next we'll have sys_dev_to_bdev based on string_list_make, which is
talloc-based.

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

index e68be47f3c9aa105f81266ad79eb444280f5fbc9..648d028c7d815b1399175c0f0e97d6a96d58e98f 100644 (file)
 #endif /* NO_QUOTACTL_USED */
 
 #if defined(HAVE_MNTENT) && defined(HAVE_REALPATH)
-static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
+static int sys_path_to_bdev(TALLOC_CTX *mem_ctx,
+                           const char *path,
+                           char **mntpath,
+                           char **bdev,
+                           char **fs)
 {
        int ret = -1;
        SMB_STRUCT_STAT S;
@@ -127,15 +131,15 @@ static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char
                        continue ;
 
                if (S.st_ex_dev == devno) {
-                       (*mntpath) = SMB_STRDUP(mnt->mnt_dir);
-                       (*bdev) = SMB_STRDUP(mnt->mnt_fsname);
-                       (*fs)   = SMB_STRDUP(mnt->mnt_type);
+                       (*mntpath) = talloc_strdup(mem_ctx, mnt->mnt_dir);
+                       (*bdev) = talloc_strdup(mem_ctx, mnt->mnt_fsname);
+                       (*fs) = talloc_strdup(mem_ctx, mnt->mnt_type);
                        if ((*mntpath)&&(*bdev)&&(*fs)) {
                                ret = 0;
                        } else {
-                               SAFE_FREE(*mntpath);
-                               SAFE_FREE(*bdev);
-                               SAFE_FREE(*fs);
+                               TALLOC_FREE(*mntpath);
+                               TALLOC_FREE(*bdev);
+                               TALLOC_FREE(*fs);
                                ret = -1;
                        }
 
@@ -153,7 +157,11 @@ out:
 #elif defined(HAVE_DEVNM)
 
 /* we have this on HPUX, ... */
-static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
+static int sys_path_to_bdev(TALLOC_CTX *mem_ctx,
+                           const char *path,
+                           char **mntpath,
+                           char **bdev,
+                           char **fs)
 {
        int ret = -1;
        char dev_disk[256];
@@ -180,13 +188,13 @@ static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char
         * but I don't know how
         * --metze
         */
-       (*mntpath) = SMB_STRDUP(path);
-       (*bdev) = SMB_STRDUP(dev_disk);
+       (*mntpath) = talloc_strdup(mem_ctx, path);
+       (*bdev) = talloc_strdup(mem_dev_disk);
        if ((*mntpath)&&(*bdev)) {
                ret = 0;
        } else {
-               SAFE_FREE(*mntpath);
-               SAFE_FREE(*bdev);
+               TALLOC_FREE(*mntpath);
+               TALLOC_FREE(*bdev);
                ret = -1;
        }
 
@@ -197,7 +205,11 @@ static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char
 /* #endif HAVE_DEVNM */
 #else
 /* we should fake this up...*/
-static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
+static int sys_path_to_bdev(TALLOC_CTX *mem_ctx,
+                           const char *path,
+                           char **mntpath,
+                           char **bdev,
+                           char **fs)
 {
        int ret = -1;
 
@@ -208,11 +220,11 @@ static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char
        (*bdev) = NULL;
        (*fs) = NULL;
 
-       (*mntpath) = SMB_STRDUP(path);
+       (*mntpath) = talloc_strdup(mem_ctx, path);
        if (*mntpath) {
                ret = 0;
        } else {
-               SAFE_FREE(*mntpath);
+               TALLOC_FREE(*mntpath);
                ret = -1;
        }
 
@@ -431,7 +443,8 @@ int sys_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DI
                return -1;
        }
 
-       if ((ret=sys_path_to_bdev(path,&mntpath,&bdev,&fs))!=0) {
+       ret = sys_path_to_bdev(talloc_tos(), path, &mntpath, &bdev, &fs);
+       if (ret != 0) {
                DEBUG(0,("sys_path_to_bdev() failed for path [%s]!\n",path));
                return ret;
        }
@@ -466,9 +479,9 @@ int sys_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DI
                }
        }
 
-       SAFE_FREE(mntpath);
-       SAFE_FREE(bdev);
-       SAFE_FREE(fs);
+       TALLOC_FREE(mntpath);
+       TALLOC_FREE(bdev);
+       TALLOC_FREE(fs);
 
        return ret;
 }
@@ -493,7 +506,8 @@ int sys_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DI
                return -1;
        }
 
-       if ((ret=sys_path_to_bdev(path,&mntpath,&bdev,&fs))!=0) {
+       ret = sys_path_to_bdev(talloc_tos(), path, &mntpath, &bdev, &fs);
+       if (ret != 0) {
                DEBUG(0,("sys_path_to_bdev() failed for path [%s]!\n",path));
                return ret;
        }
@@ -528,9 +542,9 @@ int sys_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DI
                }
        }
 
-       SAFE_FREE(mntpath);
-       SAFE_FREE(bdev);
-       SAFE_FREE(fs);
+       TALLOC_FREE(mntpath);
+       TALLOC_FREE(bdev);
+       TALLOC_FREE(fs);
 
        return ret;
 }