Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/smbd/quotas.c

    r414 r740  
    2626
    2727#include "includes.h"
     28#include "smbd/smbd.h"
     29#include "system/filesys.h"
    2830
    2931#undef DBGC_CLASS
     
    7476
    7577
     78/*
     79 * nfs quota support
     80 * (essentially taken from FreeBSD / SUNOS5 section)
     81 */
     82#include <rpc/rpc.h>
     83#include <rpc/types.h>
     84#include <rpcsvc/rquota.h>
     85#ifdef HAVE_RPC_NETTYPE_H
     86#include <rpc/nettype.h>
     87#endif
     88#include <rpc/xdr.h>
     89
     90static int my_xdr_getquota_args(XDR *xdrsp, struct getquota_args *args)
     91{
     92        if (!xdr_string(xdrsp, &args->gqa_pathp, RQ_PATHLEN ))
     93                return(0);
     94        if (!xdr_int(xdrsp, &args->gqa_uid))
     95                return(0);
     96        return (1);
     97}
     98
     99static int my_xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr)
     100{
     101        int quotastat;
     102
     103        if (!xdr_int(xdrsp, &quotastat)) {
     104                DEBUG(6,("nfs_quotas: Status bad or zero\n"));
     105                return 0;
     106        }
     107        gqr->status = quotastat;
     108
     109        if (!xdr_int(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsize)) {
     110                DEBUG(6,("nfs_quotas: Block size bad or zero\n"));
     111                return 0;
     112        }
     113        if (!xdr_bool(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_active)) {
     114                DEBUG(6,("nfs_quotas: Active bad or zero\n"));
     115                return 0;
     116        }
     117        if (!xdr_int(xdrsp, (int *)&gqr->getquota_rslt_u.gqr_rquota.rq_bhardlimit)) {
     118                DEBUG(6,("nfs_quotas: Hardlimit bad or zero\n"));
     119                return 0;
     120        }
     121        if (!xdr_int(xdrsp, (int *)&gqr->getquota_rslt_u.gqr_rquota.rq_bsoftlimit)) {
     122                DEBUG(6,("nfs_quotas: Softlimit bad or zero\n"));
     123                return 0;
     124        }
     125        if (!xdr_int(xdrsp, (int *)&gqr->getquota_rslt_u.gqr_rquota.rq_curblocks)) {
     126                DEBUG(6,("nfs_quotas: Currentblocks bad or zero\n"));
     127                return 0;
     128        }
     129        return 1;
     130}
     131
     132static bool nfs_quotas(char *nfspath, uid_t euser_id, uint64_t *bsize,
     133                       uint64_t *dfree, uint64_t *dsize)
     134{
     135        uid_t uid = euser_id;
     136        LINUX_SMB_DISK_QUOTA D;
     137        char *mnttype = nfspath;
     138        CLIENT *clnt;
     139        struct getquota_rslt gqr;
     140        struct getquota_args args;
     141        char *cutstr, *pathname, *host, *testpath;
     142        int len;
     143        static struct timeval timeout = {2,0};
     144        enum clnt_stat clnt_stat;
     145        bool ret = True;
     146
     147        *bsize = *dfree = *dsize = (uint64_t)0;
     148
     149        len=strcspn(mnttype, ":");
     150        pathname=strstr(mnttype, ":");
     151        cutstr = (char *) SMB_MALLOC(len+1);
     152        if (!cutstr)
     153                return False;
     154
     155        memset(cutstr, '\0', len+1);
     156        host = strncat(cutstr,mnttype, sizeof(char) * len );
     157        DEBUG(5,("nfs_quotas: looking for mount on \"%s\"\n", cutstr));
     158        DEBUG(5,("nfs_quotas: of path \"%s\"\n", mnttype));
     159        testpath=strchr_m(mnttype, ':');
     160        args.gqa_pathp = testpath+1;
     161        args.gqa_uid = uid;
     162
     163        DEBUG(5, ("nfs_quotas: Asking for host \"%s\" rpcprog \"%i\" rpcvers "
     164                  "\"%i\" network \"%s\"\n", host, RQUOTAPROG, RQUOTAVERS,
     165                  "udp"));
     166
     167        if ((clnt = clnt_create(host, RQUOTAPROG, RQUOTAVERS, "udp")) == NULL) {
     168                ret = False;
     169                goto out;
     170        }
     171
     172        clnt->cl_auth = authunix_create_default();
     173        DEBUG(9,("nfs_quotas: auth_success\n"));
     174
     175        clnt_stat=clnt_call(clnt,
     176                            RQUOTAPROC_GETQUOTA,
     177                            (const xdrproc_t)my_xdr_getquota_args,
     178                            (caddr_t)&args,
     179                            (const xdrproc_t)my_xdr_getquota_rslt,
     180                            (caddr_t)&gqr, timeout);
     181
     182        if (clnt_stat != RPC_SUCCESS) {
     183                DEBUG(9,("nfs_quotas: clnt_call fail\n"));
     184                ret = False;
     185                goto out;
     186        }
     187
     188        /*
     189         * gqr.status returns 0 if the rpc call fails, 1 if quotas exist, 2 if there is
     190         * no quota set, and 3 if no permission to get the quota.  If 0 or 3 return
     191         * something sensible.
     192         */
     193
     194        switch (gqr.status) {
     195        case 0:
     196                DEBUG(9, ("nfs_quotas: Remote Quotas Failed!  Error \"%i\" \n",
     197                          gqr.status));
     198                ret = False;
     199                goto out;
     200
     201        case 1:
     202                DEBUG(9,("nfs_quotas: Good quota data\n"));
     203                D.softlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bsoftlimit;
     204                D.hardlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bhardlimit;
     205                D.curblocks = gqr.getquota_rslt_u.gqr_rquota.rq_curblocks;
     206                break;
     207
     208        case 2:
     209        case 3:
     210                D.softlimit = 1;
     211                D.curblocks = 1;
     212                DEBUG(9, ("nfs_quotas: Remote Quotas returned \"%i\" \n",
     213                          gqr.status));
     214                break;
     215
     216        default:
     217                DEBUG(9, ("nfs_quotas: Remote Quotas Questionable!  "
     218                          "Error \"%i\" \n", gqr.status));
     219                break;
     220        }
     221
     222        DEBUG(10, ("nfs_quotas: Let`s look at D a bit closer... "
     223                   "status \"%i\" bsize \"%i\" active? \"%i\" bhard "
     224                   "\"%i\" bsoft \"%i\" curb \"%i\" \n",
     225                   gqr.status,
     226                   gqr.getquota_rslt_u.gqr_rquota.rq_bsize,
     227                   gqr.getquota_rslt_u.gqr_rquota.rq_active,
     228                   gqr.getquota_rslt_u.gqr_rquota.rq_bhardlimit,
     229                   gqr.getquota_rslt_u.gqr_rquota.rq_bsoftlimit,
     230                   gqr.getquota_rslt_u.gqr_rquota.rq_curblocks));
     231
     232        if (D.softlimit == 0)
     233                D.softlimit = D.hardlimit;
     234        if (D.softlimit == 0)
     235                return False;
     236
     237        *bsize = gqr.getquota_rslt_u.gqr_rquota.rq_bsize;
     238        *dsize = D.softlimit;
     239
     240        if (D.curblocks == 1)
     241                *bsize = DEV_BSIZE;
     242
     243        if (D.curblocks > D.softlimit) {
     244                *dfree = 0;
     245                *dsize = D.curblocks;
     246        } else
     247                *dfree = D.softlimit - D.curblocks;
     248
     249  out:
     250
     251        if (clnt) {
     252                if (clnt->cl_auth)
     253                        auth_destroy(clnt->cl_auth);
     254                clnt_destroy(clnt);
     255        }
     256
     257        DEBUG(5, ("nfs_quotas: For path \"%s\" returning "
     258                  "bsize %.0f, dfree %.0f, dsize %.0f\n",
     259                  args.gqa_pathp, (double)*bsize, (double)*dfree,
     260                  (double)*dsize));
     261
     262        SAFE_FREE(cutstr);
     263        DEBUG(10,("nfs_quotas: End of nfs_quotas\n" ));
     264        return ret;
     265}
     266
     267/* end of nfs quota section */
     268
    76269#ifdef HAVE_LINUX_DQBLK_XFS_H
    77270#include <linux/dqblk_xfs.h>
     
    251444
    252445        become_root();
     446
     447        if (strcmp(mnt->mnt_type, "nfs") == 0) {
     448                bool retval;
     449                retval = nfs_quotas(mnt->mnt_fsname , euser_id, bsize, dfree, dsize);
     450                unbecome_root();
     451                return retval;
     452        }
    253453
    254454        if (strcmp(mnt->mnt_type, "xfs")==0) {
Note: See TracChangeset for help on using the changeset viewer.