LCOV - code coverage report
Current view: top level - source3/lib - sysquotas.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 201 303 66.3 %
Date: 2021-09-23 10:06:22 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    System QUOTA function wrappers
       4             :    Copyright (C) Stefan (metze) Metzmacher      2003
       5             :    
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             :    
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             :    
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : 
      21             : #include "includes.h"
      22             : #include "lib/util_file.h"
      23             : #include "lib/util/smb_strtox.h"
      24             : 
      25             : #undef DBGC_CLASS
      26             : #define DBGC_CLASS DBGC_QUOTA
      27             : 
      28             : #ifdef HAVE_SYS_QUOTAS
      29             : 
      30             : #if defined(HAVE_QUOTACTL_4A) 
      31             : 
      32             : /*#endif HAVE_QUOTACTL_4A */
      33             : #elif defined(HAVE_QUOTACTL_4B)
      34             : 
      35             : /*#endif HAVE_QUOTACTL_4B */
      36             : #elif defined(HAVE_QUOTACTL_3)
      37             : 
      38             : #error HAVE_QUOTACTL_3 not implemented
      39             : 
      40             : /* #endif  HAVE_QUOTACTL_3 */
      41             : #else /* NO_QUOTACTL_USED */
      42             : 
      43             : #endif /* NO_QUOTACTL_USED */
      44             : 
      45             : #if defined(HAVE_MNTENT) && defined(HAVE_REALPATH)
      46        2072 : static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
      47             : {
      48        2072 :         int ret = -1;
      49             :         SMB_STRUCT_STAT S;
      50             :         FILE *fp;
      51        2072 :         struct mntent *mnt = NULL;
      52             :         SMB_DEV_T devno;
      53        2072 :         char *stat_mntpath = NULL;
      54             :         char *p;
      55             : 
      56             :         /* find the block device file */
      57        2072 :         (*mntpath) = NULL;
      58        2072 :         (*bdev) = NULL;
      59        2072 :         (*fs) = NULL;
      60             : 
      61        2072 :         if (sys_stat(path, &S, false) != 0) {
      62           0 :                 return -1;
      63             :         }
      64             : 
      65        2072 :         devno = S.st_ex_dev ;
      66             : 
      67        2072 :         stat_mntpath = sys_realpath(path);
      68        2072 :         if (stat_mntpath == NULL) {
      69           0 :                 DBG_WARNING("realpath(%s) failed - %s\n", path,
      70             :                             strerror(errno));
      71           0 :                 goto out;
      72             :         }
      73             : 
      74        2072 :         if (sys_stat(stat_mntpath, &S, false) != 0) {
      75           0 :                 DBG_WARNING("cannot stat real path %s - %s\n", stat_mntpath,
      76             :                             strerror(errno));
      77           0 :                 goto out;
      78             :         }
      79             : 
      80        2072 :         if (S.st_ex_dev != devno) {
      81           0 :                 DBG_WARNING("device on real path has changed\n");
      82           0 :                 goto out;
      83             :         }
      84             : 
      85       13184 :         while (true) {
      86             :                 char save_ch;
      87             : 
      88       15256 :                 p = strrchr(stat_mntpath, '/');
      89       15256 :                 if (p == NULL) {
      90           0 :                         DBG_ERR("realpath for %s does not begin with a '/'\n",
      91             :                                 path);
      92           0 :                         goto out;
      93             :                 }
      94             : 
      95       15256 :                 if (p == stat_mntpath) {
      96        2072 :                         ++p;
      97             :                 }
      98             : 
      99       15256 :                 save_ch = *p;
     100       15256 :                 *p = 0;
     101       15256 :                 if (sys_stat(stat_mntpath, &S, false) != 0) {
     102           0 :                         DBG_WARNING("cannot stat real path component %s - %s\n",
     103             :                                     stat_mntpath, strerror(errno));
     104           0 :                         goto out;
     105             :                 }
     106       15256 :                 if (S.st_ex_dev != devno) {
     107           0 :                         *p = save_ch;
     108           0 :                         break;
     109             :                 }
     110             : 
     111       15256 :                 if (p <= stat_mntpath + 1) {
     112        2072 :                         break;
     113             :                 }
     114             :         }
     115             : 
     116        2072 :         fp = setmntent(MOUNTED,"r");
     117        2072 :         if (fp == NULL) {
     118           0 :                 goto out;
     119             :         }
     120             :   
     121        3660 :         while ((mnt = getmntent(fp))) {
     122        2072 :                 if (!strequal(mnt->mnt_dir, stat_mntpath)) {
     123           0 :                         continue;
     124             :                 }
     125             : 
     126        2072 :                 if ( sys_stat(mnt->mnt_dir, &S, false) == -1 )
     127           0 :                         continue ;
     128             : 
     129        2072 :                 if (S.st_ex_dev == devno) {
     130        2072 :                         (*mntpath) = SMB_STRDUP(mnt->mnt_dir);
     131        2072 :                         (*bdev) = SMB_STRDUP(mnt->mnt_fsname);
     132        2072 :                         (*fs)   = SMB_STRDUP(mnt->mnt_type);
     133        2072 :                         if ((*mntpath)&&(*bdev)&&(*fs)) {
     134        2072 :                                 ret = 0;
     135             :                         } else {
     136           0 :                                 SAFE_FREE(*mntpath);
     137           0 :                                 SAFE_FREE(*bdev);
     138           0 :                                 SAFE_FREE(*fs);
     139           0 :                                 ret = -1;
     140             :                         }
     141             : 
     142        2072 :                         break;
     143             :                 }
     144             :         }
     145             : 
     146        2072 :         endmntent(fp) ;
     147             : 
     148        2072 : out:
     149        2072 :         SAFE_FREE(stat_mntpath);
     150        2072 :         return ret;
     151             : }
     152             : /* #endif HAVE_MNTENT */
     153             : #elif defined(HAVE_DEVNM)
     154             : 
     155             : /* we have this on HPUX, ... */
     156             : static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
     157             : {
     158             :         int ret = -1;
     159             :         char dev_disk[256];
     160             :         SMB_STRUCT_STAT S;
     161             : 
     162             :         if (!path||!mntpath||!bdev||!fs)
     163             :                 smb_panic("sys_path_to_bdev: called with NULL pointer");
     164             : 
     165             :         (*mntpath) = NULL;
     166             :         (*bdev) = NULL;
     167             :         (*fs) = NULL;
     168             :         
     169             :         /* find the block device file */
     170             : 
     171             :         if ((ret=sys_stat(path, &S, false))!=0) {
     172             :                 return ret;
     173             :         }
     174             :         
     175             :         if ((ret=devnm(S_IFBLK, S.st_ex_dev, dev_disk, 256, 1))!=0) {
     176             :                 return ret;     
     177             :         }
     178             : 
     179             :         /* we should get the mntpath right...
     180             :          * but I don't know how
     181             :          * --metze
     182             :          */
     183             :         (*mntpath) = SMB_STRDUP(path);
     184             :         (*bdev) = SMB_STRDUP(dev_disk);
     185             :         if ((*mntpath)&&(*bdev)) {
     186             :                 ret = 0;
     187             :         } else {
     188             :                 SAFE_FREE(*mntpath);
     189             :                 SAFE_FREE(*bdev);
     190             :                 ret = -1;
     191             :         }       
     192             :         
     193             :         
     194             :         return ret;     
     195             : }
     196             : 
     197             : /* #endif HAVE_DEVNM */
     198             : #else
     199             : /* we should fake this up...*/
     200             : static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
     201             : {
     202             :         int ret = -1;
     203             : 
     204             :         if (!path||!mntpath||!bdev||!fs)
     205             :                 smb_panic("sys_path_to_bdev: called with NULL pointer");
     206             : 
     207             :         (*mntpath) = NULL;
     208             :         (*bdev) = NULL;
     209             :         (*fs) = NULL;
     210             :         
     211             :         (*mntpath) = SMB_STRDUP(path);
     212             :         if (*mntpath) {
     213             :                 ret = 0;
     214             :         } else {
     215             :                 SAFE_FREE(*mntpath);
     216             :                 ret = -1;
     217             :         }
     218             : 
     219             :         return ret;
     220             : }
     221             : #endif
     222             : 
     223             : /*********************************************************************
     224             :  Now the list of all filesystem specific quota systems we have found
     225             : **********************************************************************/
     226             : static struct {
     227             :         const char *name;
     228             :         int (*get_quota)(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
     229             :         int (*set_quota)(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
     230             : } sys_quota_backends[] = {
     231             : #ifdef HAVE_JFS_QUOTA_H
     232             :         {"jfs2", sys_get_jfs2_quota,  sys_set_jfs2_quota},
     233             : #endif
     234             : #if defined HAVE_XFS_QUOTAS
     235             :         {"xfs", sys_get_xfs_quota,    sys_set_xfs_quota},
     236             :         {"gfs", sys_get_xfs_quota,    sys_set_xfs_quota},
     237             :         {"gfs2", sys_get_xfs_quota,   sys_set_xfs_quota},
     238             : #endif /* HAVE_XFS_QUOTAS */
     239             : #ifdef HAVE_NFS_QUOTAS
     240             :         {"nfs", sys_get_nfs_quota,    sys_set_nfs_quota},
     241             :         {"nfs4", sys_get_nfs_quota,   sys_set_nfs_quota},
     242             : #endif /* HAVE_NFS_QUOTAS */
     243             :         {NULL,  NULL,                   NULL}
     244             : };
     245             : 
     246        2818 : static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
     247             : {
     248        2334 :         const struct loadparm_substitution *lp_sub =
     249         484 :                 loadparm_s3_global_substitution();
     250             :         const char *get_quota_command;
     251        2818 :         char **lines = NULL;
     252             : 
     253        2818 :         get_quota_command = lp_get_quota_command(talloc_tos(), lp_sub);
     254        2818 :         if (get_quota_command && *get_quota_command) {
     255             :                 const char *p;
     256             :                 char *p2;
     257         746 :                 int _id = -1;
     258         746 :                 int error = 0;
     259         746 :                 char **argl = NULL;
     260             : 
     261         746 :                 switch(qtype) {
     262         405 :                         case SMB_USER_QUOTA_TYPE:
     263             :                         case SMB_USER_FS_QUOTA_TYPE:
     264         405 :                                 _id = id.uid;
     265         405 :                                 break;
     266         341 :                         case SMB_GROUP_QUOTA_TYPE:
     267             :                         case SMB_GROUP_FS_QUOTA_TYPE:
     268         341 :                                 _id = id.gid;
     269         341 :                                 break;
     270           0 :                         default:
     271           0 :                                 DEBUG(0,("invalid quota type.\n"));
     272         404 :                                 return -1;
     273             :                 }
     274             : 
     275         746 :                 argl = talloc_zero_array(talloc_tos(), char *, 5);
     276         746 :                 if (argl == NULL) {
     277           0 :                         return -1;
     278             :                 }
     279         746 :                 argl[0] = talloc_strdup(argl, get_quota_command);
     280         746 :                 if (argl[0] == NULL) {
     281           0 :                         TALLOC_FREE(argl);
     282           0 :                         return -1;
     283             :                 }
     284         746 :                 argl[1] = talloc_strdup(argl, path);
     285         746 :                 if (argl[1] == NULL) {
     286           0 :                         TALLOC_FREE(argl);
     287           0 :                         return -1;
     288             :                 }
     289         746 :                 argl[2] = talloc_asprintf(argl, "%d", qtype);
     290         746 :                 if (argl[2] == NULL) {
     291           0 :                         TALLOC_FREE(argl);
     292           0 :                         return -1;
     293             :                 }
     294         746 :                 argl[3] = talloc_asprintf(argl, "%d", _id);
     295         746 :                 if (argl[3] == NULL) {
     296           0 :                         TALLOC_FREE(argl);
     297           0 :                         return -1;
     298             :                 }
     299         746 :                 argl[4] = NULL;
     300             : 
     301         746 :                 DBG_NOTICE("Running command %s %s %d %d\n",
     302             :                         get_quota_command,
     303             :                         path,
     304             :                         qtype,
     305             :                         _id);
     306             : 
     307         746 :                 lines = file_lines_ploadv(talloc_tos(), argl, NULL);
     308         746 :                 TALLOC_FREE(argl);
     309             : 
     310         746 :                 if (lines) {
     311         746 :                         char *line = lines[0];
     312             : 
     313         746 :                         DEBUG (3, ("Read output from get_quota, \"%s\"\n", line));
     314             : 
     315             :                         /* we need to deal with long long unsigned here, if supported */
     316             : 
     317         746 :                         dp->qflags = smb_strtoul(line,
     318             :                                                  &p2,
     319             :                                                  10,
     320             :                                                  &error,
     321             :                                                  SMB_STR_STANDARD);
     322         746 :                         if (error != 0) {
     323         684 :                                 goto invalid_param;
     324             :                         }
     325             : 
     326         404 :                         p = p2;
     327        1212 :                         while (p && *p && isspace(*p)) {
     328         404 :                                 p++;
     329             :                         }
     330             : 
     331         404 :                         if (p && *p) {
     332         404 :                                 dp->curblocks = STR_TO_SMB_BIG_UINT(p, &p);
     333             :                         } else {
     334           0 :                                 goto invalid_param;
     335             :                         }
     336             : 
     337        1212 :                         while (p && *p && isspace(*p)) {
     338         404 :                                 p++;
     339             :                         }
     340             : 
     341         404 :                         if (p && *p) {
     342         404 :                                 dp->softlimit = STR_TO_SMB_BIG_UINT(p, &p);
     343             :                         } else {
     344           0 :                                 goto invalid_param;
     345             :                         }
     346             : 
     347        1212 :                         while (p && *p && isspace(*p)) {
     348         404 :                                 p++;
     349             :                         }
     350             : 
     351         404 :                         if (p && *p) {
     352         404 :                                 dp->hardlimit = STR_TO_SMB_BIG_UINT(p, &p);
     353             :                         } else {
     354           0 :                                 goto invalid_param;
     355             :                         }
     356             : 
     357        1212 :                         while (p && *p && isspace(*p)) {
     358         404 :                                 p++;
     359             :                         }
     360             : 
     361         404 :                         if (p && *p) {
     362         404 :                                 dp->curinodes = STR_TO_SMB_BIG_UINT(p, &p);
     363             :                         } else {
     364           0 :                                 goto invalid_param;
     365             :                         }
     366             : 
     367        1212 :                         while (p && *p && isspace(*p)) {
     368         404 :                                 p++;
     369             :                         }
     370             : 
     371         404 :                         if (p && *p) {
     372         404 :                                 dp->isoftlimit = STR_TO_SMB_BIG_UINT(p, &p);
     373             :                         } else {
     374           0 :                                 goto invalid_param;
     375             :                         }
     376             : 
     377        1212 :                         while (p && *p && isspace(*p)) {
     378         404 :                                 p++;
     379             :                         }
     380             : 
     381         404 :                         if (p && *p) {
     382         404 :                                 dp->ihardlimit = STR_TO_SMB_BIG_UINT(p, &p);
     383             :                         } else {
     384           0 :                                 goto invalid_param;     
     385             :                         }
     386             : 
     387         808 :                         while (p && *p && isspace(*p)) {
     388           0 :                                 p++;
     389             :                         }
     390             : 
     391         404 :                         if (p && *p) {
     392           0 :                                 dp->bsize = STR_TO_SMB_BIG_UINT(p, NULL);
     393             :                         } else {
     394         404 :                                 dp->bsize = 1024;
     395             :                         }
     396             : 
     397         404 :                         TALLOC_FREE(lines);
     398         404 :                         lines = NULL;
     399             : 
     400         404 :                         DEBUG (3, ("Parsed output of get_quota, ...\n"));
     401             : 
     402         404 :                         DEBUGADD (5,( 
     403             :                                 "qflags:%u curblocks:%llu softlimit:%llu hardlimit:%llu\n"
     404             :                                 "curinodes:%llu isoftlimit:%llu ihardlimit:%llu bsize:%llu\n", 
     405             :                                 dp->qflags,(long long unsigned)dp->curblocks,
     406             :                                 (long long unsigned)dp->softlimit,(long long unsigned)dp->hardlimit,
     407             :                                 (long long unsigned)dp->curinodes,
     408             :                                 (long long unsigned)dp->isoftlimit,(long long unsigned)dp->ihardlimit,
     409             :                                 (long long unsigned)dp->bsize));
     410         404 :                         return 0;
     411             :                 }
     412             : 
     413           0 :                 DEBUG (0, ("get_quota_command failed!\n"));
     414           0 :                 return -1;
     415             :         }
     416             : 
     417        2072 :         errno = ENOSYS;
     418        2072 :         return -1;
     419             : 
     420         342 : invalid_param:
     421             : 
     422         342 :         TALLOC_FREE(lines);
     423         342 :         DEBUG(0,("The output of get_quota_command is invalid!\n"));
     424         342 :         return -1;
     425             : }
     426             : 
     427           4 : static int command_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
     428             : {
     429           4 :         const struct loadparm_substitution *lp_sub =
     430           0 :                 loadparm_s3_global_substitution();
     431             :         const char *set_quota_command;
     432             : 
     433           4 :         set_quota_command = lp_set_quota_command(talloc_tos(), lp_sub);
     434           4 :         if (set_quota_command && *set_quota_command) {
     435           4 :                 char **lines = NULL;
     436           4 :                 int _id = -1;
     437           4 :                 char **argl = NULL;
     438             : 
     439           4 :                 switch(qtype) {
     440           4 :                         case SMB_USER_QUOTA_TYPE:
     441             :                         case SMB_USER_FS_QUOTA_TYPE:
     442           4 :                                 _id = id.uid;
     443           4 :                                 break;
     444           0 :                         case SMB_GROUP_QUOTA_TYPE:
     445             :                         case SMB_GROUP_FS_QUOTA_TYPE:
     446           0 :                                 _id = id.gid;
     447           0 :                                 break;
     448           0 :                         default:
     449           0 :                                 return -1;
     450             :                 }
     451             : 
     452           4 :                 argl = talloc_zero_array(talloc_tos(), char *, 11);
     453           4 :                 if (argl == NULL) {
     454           0 :                         return -1;
     455             :                 }
     456           4 :                 argl[0] = talloc_strdup(argl, set_quota_command);
     457           4 :                 if (argl[0] == NULL) {
     458           0 :                         TALLOC_FREE(argl);
     459           0 :                         return -1;
     460             :                 }
     461           4 :                 argl[1] = talloc_strdup(argl, path);
     462           4 :                 if (argl[1] == NULL) {
     463           0 :                         TALLOC_FREE(argl);
     464           0 :                         return -1;
     465             :                 }
     466           4 :                 argl[2] = talloc_asprintf(argl, "%d", qtype);
     467           4 :                 if (argl[2] == NULL) {
     468           0 :                         TALLOC_FREE(argl);
     469           0 :                         return -1;
     470             :                 }
     471           4 :                 argl[3] = talloc_asprintf(argl, "%d", _id);
     472           4 :                 if (argl[3] == NULL) {
     473           0 :                         TALLOC_FREE(argl);
     474           0 :                         return -1;
     475             :                 }
     476           4 :                 argl[4] = talloc_asprintf(argl, "%u", dp->qflags);
     477           4 :                 if (argl[4] == NULL) {
     478           0 :                         TALLOC_FREE(argl);
     479           0 :                         return -1;
     480             :                 }
     481           4 :                 argl[5] = talloc_asprintf(argl, "%llu",
     482           4 :                                 (long long unsigned)dp->softlimit);
     483           4 :                 if (argl[5] == NULL) {
     484           0 :                         TALLOC_FREE(argl);
     485           0 :                         return -1;
     486             :                 }
     487           4 :                 argl[6] = talloc_asprintf(argl, "%llu",
     488           4 :                                 (long long unsigned)dp->hardlimit);
     489           4 :                 if (argl[6] == NULL) {
     490           0 :                         TALLOC_FREE(argl);
     491           0 :                         return -1;
     492             :                 }
     493           4 :                 argl[7] = talloc_asprintf(argl, "%llu",
     494           4 :                                 (long long unsigned)dp->isoftlimit);
     495           4 :                 if (argl[7] == NULL) {
     496           0 :                         TALLOC_FREE(argl);
     497           0 :                         return -1;
     498             :                 }
     499           4 :                 argl[8] = talloc_asprintf(argl, "%llu",
     500           4 :                                 (long long unsigned)dp->ihardlimit);
     501           4 :                 if (argl[8] == NULL) {
     502           0 :                         TALLOC_FREE(argl);
     503           0 :                         return -1;
     504             :                 }
     505           4 :                 argl[9] = talloc_asprintf(argl, "%llu",
     506           4 :                                 (long long unsigned)dp->bsize);
     507           4 :                 if (argl[9] == NULL) {
     508           0 :                         TALLOC_FREE(argl);
     509           0 :                         return -1;
     510             :                 }
     511           4 :                 argl[10] = NULL;
     512             : 
     513           4 :                 DBG_NOTICE("Running command "
     514             :                         "%s %s %d %d "
     515             :                         "%u %llu %llu "
     516             :                         "%llu %llu %llu ",
     517             :                         set_quota_command,
     518             :                         path,
     519             :                         qtype,
     520             :                         _id,
     521             :                         dp->qflags,
     522             :                         (long long unsigned)dp->softlimit,
     523             :                         (long long unsigned)dp->hardlimit,
     524             :                         (long long unsigned)dp->isoftlimit,
     525             :                         (long long unsigned)dp->ihardlimit,
     526             :                         (long long unsigned)dp->bsize);
     527             : 
     528           4 :                 lines = file_lines_ploadv(talloc_tos(), argl, NULL);
     529           4 :                 TALLOC_FREE(argl);
     530           4 :                 if (lines) {
     531           4 :                         char *line = lines[0];
     532             : 
     533           4 :                         DEBUG (3, ("Read output from set_quota, \"%s\"\n", line));
     534             : 
     535           4 :                         TALLOC_FREE(lines);
     536             : 
     537           4 :                         return 0;
     538             :                 }
     539           0 :                 DEBUG (0, ("set_quota_command failed!\n"));
     540           0 :                 return -1;
     541             :         }
     542             : 
     543           0 :         errno = ENOSYS;
     544           0 :         return -1;
     545             : }
     546             : 
     547        2818 : int sys_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
     548             : {
     549        2818 :         int ret = -1;
     550             :         int i;
     551        2818 :         bool ready = False;
     552        2818 :         char *mntpath = NULL;
     553        2818 :         char *bdev = NULL;
     554        2818 :         char *fs = NULL;
     555             : 
     556        2818 :         if (!path||!dp)
     557           0 :                 smb_panic("sys_get_quota: called with NULL pointer");
     558             : 
     559        2818 :         if (command_get_quota(path, qtype, id, dp)==0) {        
     560         404 :                 return 0;
     561        2414 :         } else if (errno != ENOSYS) {
     562         342 :                 return -1;
     563             :         }
     564             : 
     565        2072 :         if ((ret=sys_path_to_bdev(path,&mntpath,&bdev,&fs))!=0) {
     566           0 :                 DEBUG(0,("sys_path_to_bdev() failed for path [%s]!\n",path));
     567           0 :                 return ret;
     568             :         }
     569             : 
     570        2072 :         errno = 0;
     571        2072 :         DEBUG(10,("sys_get_quota() uid(%u, %u), fs(%s)\n", (unsigned)getuid(), (unsigned)geteuid(), fs));
     572             : 
     573        5602 :         for (i=0;(fs && sys_quota_backends[i].name && sys_quota_backends[i].get_quota);i++) {
     574        4896 :                 if (strcmp(fs,sys_quota_backends[i].name)==0) {
     575        1366 :                         ret = sys_quota_backends[i].get_quota(mntpath, bdev, qtype, id, dp);
     576        1366 :                         if (ret!=0) {
     577           0 :                                 DEBUG(3,("sys_get_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d]: %s.\n",
     578             :                                         fs,mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid),strerror(errno)));
     579             :                         } else {
     580        1366 :                                 DEBUG(10,("sys_get_%s_quota() called for mntpath[%s] bdev[%s] qtype[%d] id[%d].\n",
     581             :                                         fs,mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid)));
     582             :                         }
     583        1366 :                         ready = True;
     584        1366 :                         break;  
     585             :                 }               
     586             :         }
     587             : 
     588        2072 :         if (!ready) {
     589             :                 /* use the default vfs quota functions */
     590         706 :                 ret=sys_get_vfs_quota(mntpath, bdev, qtype, id, dp);
     591         706 :                 if (ret!=0) {
     592           0 :                         DEBUG(3,("sys_get_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d]: %s\n",
     593             :                                 "vfs",mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid),strerror(errno)));
     594             :                 } else {
     595         706 :                         DEBUG(10,("sys_get_%s_quota() called for mntpath[%s] bdev[%s] qtype[%d] id[%d].\n",
     596             :                                 "vfs",mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid)));
     597             :                 }
     598             :         }
     599             : 
     600        2072 :         SAFE_FREE(mntpath);
     601        2072 :         SAFE_FREE(bdev);
     602        2072 :         SAFE_FREE(fs);
     603             : 
     604        2072 :         return ret;
     605             : }
     606             : 
     607           4 : int sys_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp)
     608             : {
     609           4 :         int ret = -1;
     610             :         int i;
     611           4 :         bool ready = False;
     612           4 :         char *mntpath = NULL;
     613           4 :         char *bdev = NULL;
     614           4 :         char *fs = NULL;
     615             : 
     616             :         /* find the block device file */
     617             : 
     618           4 :         if (!path||!dp)
     619           0 :                 smb_panic("get_smb_quota: called with NULL pointer");
     620             : 
     621           4 :         if (command_set_quota(path, qtype, id, dp)==0) {        
     622           4 :                 return 0;
     623           0 :         } else if (errno != ENOSYS) {
     624           0 :                 return -1;
     625             :         }
     626             : 
     627           0 :         if ((ret=sys_path_to_bdev(path,&mntpath,&bdev,&fs))!=0) {
     628           0 :                 DEBUG(0,("sys_path_to_bdev() failed for path [%s]!\n",path));
     629           0 :                 return ret;
     630             :         }
     631             : 
     632           0 :         errno = 0;
     633           0 :         DEBUG(10,("sys_set_quota() uid(%u, %u)\n", (unsigned)getuid(), (unsigned)geteuid())); 
     634             : 
     635           0 :         for (i=0;(fs && sys_quota_backends[i].name && sys_quota_backends[i].set_quota);i++) {
     636           0 :                 if (strcmp(fs,sys_quota_backends[i].name)==0) {
     637           0 :                         ret = sys_quota_backends[i].set_quota(mntpath, bdev, qtype, id, dp);
     638           0 :                         if (ret!=0) {
     639           0 :                                 DEBUG(3,("sys_set_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d]: %s.\n",
     640             :                                         fs,mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid),strerror(errno)));
     641             :                         } else {
     642           0 :                                 DEBUG(10,("sys_set_%s_quota() called for mntpath[%s] bdev[%s] qtype[%d] id[%d].\n",
     643             :                                         fs,mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid)));
     644             :                         }
     645           0 :                         ready = True;
     646           0 :                         break;
     647             :                 }               
     648             :         }
     649             : 
     650           0 :         if (!ready) {
     651             :                 /* use the default vfs quota functions */
     652           0 :                 ret=sys_set_vfs_quota(mntpath, bdev, qtype, id, dp);
     653           0 :                 if (ret!=0) {
     654           0 :                         DEBUG(3,("sys_set_%s_quota() failed for mntpath[%s] bdev[%s] qtype[%d] id[%d]: %s.\n",
     655             :                                 "vfs",mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid),strerror(errno)));
     656             :                 } else {
     657           0 :                         DEBUG(10,("sys_set_%s_quota() called for mntpath[%s] bdev[%s] qtype[%d] id[%d].\n",
     658             :                                 "vfs",mntpath,bdev,qtype,(qtype==SMB_GROUP_QUOTA_TYPE?id.gid:id.uid)));
     659             :                 }
     660             :         }
     661             : 
     662           0 :         SAFE_FREE(mntpath);
     663           0 :         SAFE_FREE(bdev);
     664           0 :         SAFE_FREE(fs);
     665             : 
     666           0 :         return ret;             
     667             : }
     668             : 
     669             : #else /* HAVE_SYS_QUOTAS */
     670             :  void dummy_sysquotas_c(void);
     671             : 
     672             :  void dummy_sysquotas_c(void)
     673             : {
     674             :         return;
     675             : }
     676             : #endif /* HAVE_SYS_QUOTAS */
     677             : 

Generated by: LCOV version 1.13