From 04af2822099948279095acc4bc38f5dd4576c7c9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 5 May 1996 11:25:33 +0000 Subject: move quotas support out of server.c (This used to be commit 1ed5645a5d150de4e5e788c2389aa3cbe70a8faf) --- source3/smbd/quotas.c | 330 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 source3/smbd/quotas.c (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c new file mode 100644 index 0000000000..32c9fc35d3 --- /dev/null +++ b/source3/smbd/quotas.c @@ -0,0 +1,330 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + support for quotas + Copyright (C) Andrew Tridgell 1992-1995 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +#ifdef QUOTAS + +#ifdef LINUX +/**************************************************************************** +try to get the disk space from disk quotas (LINUX version) +****************************************************************************/ +/* +If you didn't make the symlink to the quota package, too bad :( +*/ +#include "quota/quotactl.c" +#include "quota/hasquota.c" +static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +{ + uid_t euser_id; + struct dqblk D; + struct stat S; + dev_t devno ; + struct mntent *mnt; + FILE *fp; + int found ; + int qcmd, fd ; + char *qfpathname; + + /* find the block device file */ + + if ( stat(path, &S) == -1 ) + return(False) ; + + devno = S.st_dev ; + + fp = setmntent(MOUNTED,"r"); + found = False ; + + while ((mnt = getmntent(fp)) != (struct mntent *) 0) { + if ( stat(mnt->mnt_dir,&S) == -1 ) + continue ; + if (S.st_dev == devno) { + found = True ; + break ; + } + } + endmntent(fp) ; + + if ( ! found ) + return(False) ; + + qcmd = QCMD(Q_GETQUOTA, USRQUOTA); + + if (hasmntopt(mnt, MNTOPT_NOAUTO) || hasmntopt(mnt, MNTOPT_NOQUOTA)) + return(False) ; + + if (!hasquota(mnt, USRQUOTA, &qfpathname)) + return(False) ; + + euser_id = geteuid(); + seteuid(0); + + if (quotactl(qcmd, mnt->mnt_fsname, euser_id, (caddr_t)&D) != 0) { + if ((fd = open(qfpathname, O_RDONLY)) < 0) { + seteuid(euser_id); + return(False); + } + lseek(fd, (long) dqoff(euser_id), L_SET); + switch (read(fd, &D, sizeof(struct dqblk))) { + case 0:/* EOF */ + memset((caddr_t)&D, 0, sizeof(struct dqblk)); + break; + case sizeof(struct dqblk): /* OK */ + break; + default: /* ERROR */ + close(fd); + seteuid(euser_id); + return(False); + } + } + seteuid(euser_id); + *bsize=1024; + + if (D.dqb_bsoftlimit==0) + return(False); + if ((D.dqb_curblocks>D.dqb_bsoftlimit)||(D.dqb_curinodes>D.dqb_isoftlimit)) + { + *dfree = 0; + *dsize = D.dqb_curblocks; + } + else { + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + *dsize = D.dqb_bsoftlimit; + } + return (True); +} + +#elif defined(CRAY) +/**************************************************************************** +try to get the disk space from disk quotas (CRAY VERSION) +****************************************************************************/ +static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +{ + struct mntent *mnt; + FILE *fd; + struct stat sbuf; + dev_t devno ; + static dev_t devno_cached = 0 ; + static char name[MNTMAXSTR] ; + struct q_request request ; + struct qf_header header ; + static int quota_default = 0 ; + int found ; + + if ( stat(path,&sbuf) == -1 ) + return(False) ; + + devno = sbuf.st_dev ; + + if ( devno != devno_cached ) { + + devno_cached = devno ; + + if ((fd = setmntent(KMTAB)) == NULL) + return(False) ; + + found = False ; + + while ((mnt = getmntent(fd)) != NULL) { + + if ( stat(mnt->mnt_dir,&sbuf) == -1 ) + continue ; + + if (sbuf.st_dev == devno) { + + found = True ; + break ; + + } + + } + + strcpy(name,mnt->mnt_dir) ; + endmntent(fd) ; + + if ( ! found ) + return(False) ; + } + + request.qf_magic = QF_MAGIC ; + request.qf_entry.id = geteuid() ; + + if (quotactl(name, Q_GETQUOTA, &request) == -1) + return(False) ; + + if ( ! request.user ) + return(False) ; + + if ( request.qf_entry.user_q.f_quota == QFV_DEFAULT ) { + + if ( ! quota_default ) { + + if ( quotactl(name, Q_GETHEADER, &header) == -1 ) + return(False) ; + else + quota_default = header.user_h.def_fq ; + } + + *dfree = quota_default ; + + }else if ( request.qf_entry.user_q.f_quota == QFV_PREVENT ) { + + *dfree = 0 ; + + }else{ + + *dfree = request.qf_entry.user_q.f_quota ; + + } + + *dsize = request.qf_entry.user_q.f_use ; + + if ( *dfree ) + *dfree -= *dsize ; + + if ( *dfree < 0 ) + *dfree = 0 ; + + *bsize = 4096 ; /* Cray blocksize */ + + return(True) ; + +} + + +#elif defined(SUNOS5) + +#include +#include + +/**************************************************************************** +try to get the disk space from disk quotas (solaris 2 version) +****************************************************************************/ +/* Quota code by Peter Urbanec (amiga@cse.unsw.edu.au) */ +static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +{ + uid_t user_id, euser_id; + int r; + struct dqblk D; + struct quotctl command; + int file; + + if((file=open(path, O_RDONLY))<0) return(False); + + euser_id = geteuid(); + user_id = getuid(); + + setuid(0); /* Solaris seems to want to give info only to super-user */ + seteuid(0); + + command.op = Q_GETQUOTA; + command.uid = euser_id; + command.addr = (caddr_t) &D; + + if(ioctl(file, Q_QUOTACTL, &command)<0) + { + close(file); + DEBUG(2,("disk_quotas ioctl (Solaris) failed\n")); + return(False); + } + close(file); + + setuid(user_id); /* Restore the original UID status */ + seteuid(euser_id); + + /* Use softlimit to determine disk space. A user exceeding the quota is told + * that there's no space left. Writes might actually work for a bit if the + * hardlimit is set higher than softlimit. Effectively the disk becomes + * made of rubber latex and begins to expand to accommodate the user :-) + */ + + *bsize = 512; + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + *dsize = D.dqb_bsoftlimit; + if(*dfree < 0) + { + *dfree = 0; + *dsize = D.dqb_curblocks; + } + +DEBUG(5,("disk_quotas for path \"%s\" returning bsize %d, dfree %d, dsize %d\n", + path,*bsize,*dfree,*dsize)); + + return(True); +} + +#else + +/**************************************************************************** +try to get the disk space from disk quotas - default version +****************************************************************************/ +static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +{ + uid_t user_id, euser_id; + int r; + char dev_disk[256]; + struct dqblk D; + struct stat S; + /* find the block device file */ + if ((stat(path, &S)<0) || + (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 0)<0)) return (False); + + euser_id = geteuid(); + +#ifdef USE_SETRES + /* for HPUX, real uid must be same as euid to execute quotactl for euid */ + user_id = getuid(); + setresuid(euser_id,-1,-1); +#endif + r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); + #ifdef USE_SETRES + if (setresuid(user_id,-1,-1)) + DEBUG(5,("Unable to reset uid to %d\n", user_id)); + #endif + /* Use softlimit to determine disk space, except when it has been exceeded */ + *bsize = 1024; + if (r) + { + if (errno == EDQUOT) + { + *dfree =0; + *dsize =D.dqb_curblocks; + return (True); + } + else return(False); + } + /* Use softlimit to determine disk space, except when it has been exceeded */ + if ((D.dqb_curblocks>D.dqb_bsoftlimit)||(D.dqb_curfiles>D.dqb_fsoftlimit)) + { + *dfree = 0; + *dsize = D.dqb_curblocks; + } + else { + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + *dsize = D.dqb_bsoftlimit; + } + return (True); +} + +#endif +#endif -- cgit From 58734631b4233ec08b7a262587e400792f31f185 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 31 May 1996 15:13:29 +0000 Subject: Lots of changes! - add faq info on NT printer handling - add "delete readonly" option to help rcs users - add stuff to man pages on new printer options - add "proxy name resolution" option - add "command string" -c option to smbclient (thanks Ken) - split time functions into time.c - rearrange the quotas stuff a bit and fix some bugs - complete rehash of the time handling code thanks to Paul Eggert - fix nmblookup output a bit - add plp print queue parsing from Bertrand Wallrich (This used to be commit 635b56f19c817527c52e9bbde31faa6a8a47777b) --- source3/smbd/quotas.c | 55 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 13 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 32c9fc35d3..81f2dcaab5 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -1,3 +1,4 @@ +#ifdef QUOTAS /* Unix SMB/Netbios implementation. Version 1.9. @@ -19,12 +20,28 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "includes.h" +/* + * This is one of the most system dependent parts of Samba, and its + * done a litle differently. Each system has its own way of doing + * things :-( + */ + +#include "includes.h" -#ifdef QUOTAS #ifdef LINUX + +#ifdef __KERNEL__ +# undef __KERNEL__ +# include +# define __KERNEL__ +#else +# include +#endif + +#include + /**************************************************************************** try to get the disk space from disk quotas (LINUX version) ****************************************************************************/ @@ -115,6 +132,10 @@ static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } #elif defined(CRAY) + +#include +#include + /**************************************************************************** try to get the disk space from disk quotas (CRAY VERSION) ****************************************************************************/ @@ -214,6 +235,7 @@ static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) #elif defined(SUNOS5) +#include #include #include @@ -228,30 +250,33 @@ static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) struct dqblk D; struct quotctl command; int file; + int ret; if((file=open(path, O_RDONLY))<0) return(False); euser_id = geteuid(); user_id = getuid(); - setuid(0); /* Solaris seems to want to give info only to super-user */ - seteuid(0); - command.op = Q_GETQUOTA; command.uid = euser_id; command.addr = (caddr_t) &D; - if(ioctl(file, Q_QUOTACTL, &command)<0) - { - close(file); - DEBUG(2,("disk_quotas ioctl (Solaris) failed\n")); - return(False); - } - close(file); + setuid(0); /* Solaris seems to want to give info only to super-user */ + seteuid(0); + + ret = ioctl(file, Q_QUOTACTL, &command); setuid(user_id); /* Restore the original UID status */ seteuid(euser_id); + if (ret < 0) { + close(file); + DEBUG(2,("disk_quotas ioctl (Solaris) failed\n")); + return(False); + } + close(file); + + /* Use softlimit to determine disk space. A user exceeding the quota is told * that there's no space left. Writes might actually work for a bit if the * hardlimit is set higher than softlimit. Effectively the disk becomes @@ -275,6 +300,9 @@ DEBUG(5,("disk_quotas for path \"%s\" returning bsize %d, dfree %d, dsize %d\n" #else +#include +#include + /**************************************************************************** try to get the disk space from disk quotas - default version ****************************************************************************/ @@ -327,4 +355,5 @@ static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } #endif -#endif +#endif /* QUOTAS */ + -- cgit From 5607ff396c375976e440f9c955a313ddd58e3bbd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Jun 1996 06:53:43 +0000 Subject: add dummy quotas fn fix typo in reply to backup lists (This used to be commit bc4a2994377ab078d3d1a900f79fda9dfe4d0e6a) --- source3/smbd/quotas.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 81f2dcaab5..d5be15264e 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -355,5 +355,9 @@ static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } #endif + +#else +/* this keeps fussy compilers happy */ + void quotas_dummy(void) {} #endif /* QUOTAS */ -- cgit From 4eba893b02334953b0f1bc082dcba6f930f9ff80 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Jun 1996 04:33:37 +0000 Subject: - added comments to byteorder.h explaining how it works. - fixed problem with installscripts if srcdir is not set - fixed ptr init bug in interface.c - changed default lookup type in nmblookup to match nbtstat under NT - new quotas fixes for sunos and solaris (This used to be commit e775576f026d282473256aeac6fef65a85acd98e) --- source3/smbd/quotas.c | 108 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 92 insertions(+), 16 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index d5be15264e..4216aa1199 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -29,6 +29,7 @@ #include "includes.h" +extern int DEBUGLEVEL; #ifdef LINUX @@ -50,7 +51,7 @@ If you didn't make the symlink to the quota package, too bad :( */ #include "quota/quotactl.c" #include "quota/hasquota.c" -static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) { uid_t euser_id; struct dqblk D; @@ -139,7 +140,7 @@ static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) /**************************************************************************** try to get the disk space from disk quotas (CRAY VERSION) ****************************************************************************/ -static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) { struct mntent *mnt; FILE *fd; @@ -233,48 +234,119 @@ static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } -#elif defined(SUNOS5) +#elif defined(SUNOS5) || defined(SUNOS4) -#include #include +#if defined(SUNOS5) #include +#include +#else /* defined(SUNOS4) */ +#include +#include +#endif /**************************************************************************** try to get the disk space from disk quotas (solaris 2 version) ****************************************************************************/ /* Quota code by Peter Urbanec (amiga@cse.unsw.edu.au) */ -static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) { uid_t user_id, euser_id; - int r; + int ret; struct dqblk D; +#if defined(SUNOS5) struct quotctl command; int file; - int ret; - - if((file=open(path, O_RDONLY))<0) return(False); + struct mnttab mnt; + static char name[MNT_LINE_MAX] ; +#else + struct mntent *mnt; + static char name[MNTMAXSTR] ; +#endif + FILE *fd; + struct stat sbuf; + dev_t devno ; + static dev_t devno_cached = 0 ; + int found ; + + if ( stat(path,&sbuf) == -1 ) + return(False) ; + + devno = sbuf.st_dev ; +DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%o\n", path,devno)); + if ( devno != devno_cached ) { + devno_cached = devno ; +#if defined(SUNOS5) + if ((fd = fopen(MNTTAB, "r")) == NULL) + return(False) ; + + found = False ; + while (getmntent(fd, &mnt) == 0) { + if ( stat(mnt.mnt_mountp,&sbuf) == -1 ) + continue ; +DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt.mnt_mountp,sbuf.st_dev)); + if (sbuf.st_dev == devno) { + found = True ; + break ; + } + } + + strcpy(name,mnt.mnt_mountp) ; + strcat(name,"/quotas") ; + fclose(fd) ; +#else + if ((fd = setmntent(MOUNTED, "r")) == NULL) + return(False) ; + + found = False ; + while ((mnt = getmntent(fd)) != NULL) { + if ( stat(mnt->mnt_dir,&sbuf) == -1 ) + continue ; +DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt->mnt_dir,sbuf.st_dev)); + if (sbuf.st_dev == devno) { + found = True ; + break ; + } + } + + strcpy(name,mnt->mnt_fsname) ; + endmntent(fd) ; +#endif + + if ( ! found ) + return(False) ; + } euser_id = geteuid(); user_id = getuid(); - command.op = Q_GETQUOTA; - command.uid = euser_id; - command.addr = (caddr_t) &D; - setuid(0); /* Solaris seems to want to give info only to super-user */ seteuid(0); +#if defined(SUNOS5) +DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); + if((file=open(name, O_RDONLY))<0) { + setuid(user_id); /* Restore the original UID status */ + seteuid(euser_id); + return(False); + } + command.op = Q_GETQUOTA; + command.uid = euser_id; + command.addr = (caddr_t) &D; ret = ioctl(file, Q_QUOTACTL, &command); + close(file); +#else +DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name)); + ret = quotactl(Q_GETQUOTA, name, euser_id, &D); +#endif setuid(user_id); /* Restore the original UID status */ seteuid(euser_id); if (ret < 0) { - close(file); DEBUG(2,("disk_quotas ioctl (Solaris) failed\n")); return(False); } - close(file); /* Use softlimit to determine disk space. A user exceeding the quota is told @@ -283,6 +355,8 @@ static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) * made of rubber latex and begins to expand to accommodate the user :-) */ + if (D.dqb_bsoftlimit==0) + return(False); *bsize = 512; *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; *dsize = D.dqb_bsoftlimit; @@ -306,7 +380,7 @@ DEBUG(5,("disk_quotas for path \"%s\" returning bsize %d, dfree %d, dsize %d\n" /**************************************************************************** try to get the disk space from disk quotas - default version ****************************************************************************/ -static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) { uid_t user_id, euser_id; int r; @@ -341,6 +415,8 @@ static BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } else return(False); } + if (D.dqb_bsoftlimit==0) + return(False); /* Use softlimit to determine disk space, except when it has been exceeded */ if ((D.dqb_curblocks>D.dqb_bsoftlimit)||(D.dqb_curfiles>D.dqb_fsoftlimit)) { -- cgit From 7e3b4a1c0df1434eb3d02f93c736ce065f9898d8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Jun 1996 04:38:24 +0000 Subject: got rid of a lot of redundent header files as we now globally generate prototypes automatically using "make proto". This is much less prone to error than the old method of manually adding prototypes (This used to be commit b551dc98f7cc194a5fc2e67a4ebae7fd67a01bbc) --- source3/smbd/quotas.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 4216aa1199..6ba20faa6c 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -273,7 +273,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) return(False) ; devno = sbuf.st_dev ; -DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%o\n", path,devno)); + DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%o\n", path,devno)); if ( devno != devno_cached ) { devno_cached = devno ; #if defined(SUNOS5) @@ -284,7 +284,8 @@ DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%o\n", path,devno)); while (getmntent(fd, &mnt) == 0) { if ( stat(mnt.mnt_mountp,&sbuf) == -1 ) continue ; -DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt.mnt_mountp,sbuf.st_dev)); + DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", + mnt.mnt_mountp,sbuf.st_dev)); if (sbuf.st_dev == devno) { found = True ; break ; @@ -302,7 +303,8 @@ DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt.mnt_mountp,sbuf.st_dev)); while ((mnt = getmntent(fd)) != NULL) { if ( stat(mnt->mnt_dir,&sbuf) == -1 ) continue ; -DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt->mnt_dir,sbuf.st_dev)); + DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", + mnt->mnt_dir,sbuf.st_dev)); if (sbuf.st_dev == devno) { found = True ; break ; @@ -324,7 +326,7 @@ DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt->mnt_dir,sbuf.st_dev)); seteuid(0); #if defined(SUNOS5) -DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); + DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); if((file=open(name, O_RDONLY))<0) { setuid(user_id); /* Restore the original UID status */ seteuid(euser_id); @@ -336,7 +338,7 @@ DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); ret = ioctl(file, Q_QUOTACTL, &command); close(file); #else -DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name)); + DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name)); ret = quotactl(Q_GETQUOTA, name, euser_id, &D); #endif -- cgit From 53a9501444e3e00797e464ad4550db3e99921c87 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Tue, 10 Dec 1996 17:58:11 +0000 Subject: Fixed quota support for FreeBsd. jra@cygnus.com (This used to be commit d1009c53517c3cfc536cb6436a702441c27be448) --- source3/smbd/quotas.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 6ba20faa6c..3e22e26ba3 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -376,8 +376,12 @@ DEBUG(5,("disk_quotas for path \"%s\" returning bsize %d, dfree %d, dsize %d\n" #else +#ifdef __FreeBSD__ +#include +#else #include #include +#endif /**************************************************************************** try to get the disk space from disk quotas - default version @@ -389,9 +393,11 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) char dev_disk[256]; struct dqblk D; struct stat S; +#ifndef __FreeBSD__ /* find the block device file */ if ((stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 0)<0)) return (False); +#endif euser_id = geteuid(); @@ -399,12 +405,17 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) /* for HPUX, real uid must be same as euid to execute quotactl for euid */ user_id = getuid(); setresuid(euser_id,-1,-1); -#endif r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); - #ifdef USE_SETRES if (setresuid(user_id,-1,-1)) DEBUG(5,("Unable to reset uid to %d\n", user_id)); +#else +#if defined(__FreeBSD__) + r= quotactl(path,Q_GETQUOTA,euser_id,(char *) &D); +#else + r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); #endif +#endif + /* Use softlimit to determine disk space, except when it has been exceeded */ *bsize = 1024; if (r) @@ -420,8 +431,11 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) if (D.dqb_bsoftlimit==0) return(False); /* Use softlimit to determine disk space, except when it has been exceeded */ - if ((D.dqb_curblocks>D.dqb_bsoftlimit)||(D.dqb_curfiles>D.dqb_fsoftlimit)) - { + if ((D.dqb_curblocks>D.dqb_bsoftlimit) +#if !defined(__FreeBSD__) +||(D.dqb_curfiles>D.dqb_fsoftlimit)) +#endif + ) { *dfree = 0; *dsize = D.dqb_curblocks; } -- cgit From 869f24e0b1915ec8d3e14f8850417474200e687e Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Wed, 15 Jan 1997 01:53:25 +0000 Subject: locking.c proto.h shmem.c smb.h status.c : Changed shm_ prefixes to smb_shm_ prefixes as shm_ is a POSIX.4 prefix. Updated fd code in FAST_SHARE_MODE code to work with new fd indirection. quotas.c: Fixed #ifdef not on position zero. Jeremy. (jra@cygnus.com). (This used to be commit c9a9d56642cc34369a42f48a28116e466240d303) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 3e22e26ba3..aec349dfd1 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -413,7 +413,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) r= quotactl(path,Q_GETQUOTA,euser_id,(char *) &D); #else r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); - #endif +#endif #endif /* Use softlimit to determine disk space, except when it has been exceeded */ -- cgit From 3e2f9c3dee3895b44a367ec1b1b2d9b1b3b00e7c Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Fri, 7 Mar 1997 17:24:22 +0000 Subject: quotas.c: Fixed typo in #ifdef'ed compile. ufc.c: Added pre-declaration of _ufc_doit(). jra@cygnus.com (This used to be commit 7c690e020ffae9a56c678ae46ae87283a1aa92fe) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index aec349dfd1..05b40ada0f 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -433,7 +433,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) /* Use softlimit to determine disk space, except when it has been exceeded */ if ((D.dqb_curblocks>D.dqb_bsoftlimit) #if !defined(__FreeBSD__) -||(D.dqb_curfiles>D.dqb_fsoftlimit)) +||(D.dqb_curfiles>D.dqb_fsoftlimit) #endif ) { *dfree = 0; -- cgit From 0f1f0ceb9519368188f695e18e2341ccfd1b2d15 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 8 May 1997 01:14:17 +0000 Subject: 'The mother of all checkins' :-). Jeremy Allison (jallison@whistle.com) Wed May 7 1997: Update for 1.9.17alpha1 release - 'browsefix release' designed to make browsing across subnets work. byteorder.h: Updated copyright to 1997. charcnv.c: Updated copyright to 1997. charset.c Updated copyright to 1997. charset.h Updated copyright to 1997. client.c Updated copyright to 1997. clientutil.c Updated copyright to 1997. dir.c Updated copyright to 1997. fault.c Updated copyright to 1997. includes.h Updated copyright to 1997. interface.c Updated copyright to 1997. ipc.c Updated copyright to 1997. kanji.c Updated copyright to 1997. kanji.h Updated copyright to 1997. loadparm.c Updated copyright to 1997. locking.c Updated copyright to 1997. mangle.c Updated copyright to 1997. message.c Updated copyright to 1997. nameannounce.c Made use of WINS subnet explicit. Added reset_announce_timer() so announcement can be made immediately when we become a master. Expanded code to do sync with dmb. namebrowse.c Removed redundent checks for AM_MASTER in sync code. Made use of WINS subnet explicit. namedbname.c Made use of WINS subnet explicit. namedbresp.c Made use of WINS subnet explicit. namedbserver.c Made use of WINS subnet explicit. namedbsubnet.c Explicitly add workgroup to WINS subnet when we become a dmb. Made use of WINS subnet explicit. namedbwork.c Made use of WINS subnet explicit. Removed redundent check_work_servertype() function. nameelect.c Explicitly add workgroup to WINS subnet when we become a master browser. Made use of WINS subnet explicit. namelogon.c Updated copyright to 1997. namepacket.c Updated copyright to 1997. namequery.c Updated copyright to 1997. nameresp.c Made use of WINS subnet explicit. Made nmbd fail if configured as master browser and one exists already. nameserv.c Made use of WINS subnet explicit. Remove redundent logon server and domain master code. nameserv.h Add emumerate subnet macros. nameservreply.c Made use of WINS subnet explicit. nameservresp.c Updated copyright to 1997. namework.c Made use of WINS subnet explicit. Updated code to add sync browser entries to add subnet parameter. nmbd.c Added sanity check for misconfigured nmbd. nmblib.c Updated copyright to 1997. nmblookup.c Updated copyright to 1997. nmbsync.c Removed redundent AM_ANY_MASTER check. params.c Updated copyright to 1997. password.c Updated copyright to 1997. pipes.c Updated copyright to 1997. predict.c Updated copyright to 1997. printing.c Updated copyright to 1997. proto.h Changed protos for new nmbd code. quotas.c Updated copyright to 1997. replace.c Updated copyright to 1997. reply.c Updated copyright to 1997. server.c Updated copyright to 1997. shmem.c Updated copyright to 1997. smb.h Updated copyright to 1997. smbencrypt.c Updated copyright to 1997. smbpasswd.c Updated copyright to 1997. smbrun.c Updated copyright to 1997. status.c Updated copyright to 1997. system.c Updated copyright to 1997. testparm.c Updated copyright to 1997. testprns.c Updated copyright to 1997. time.c Updated copyright to 1997. trans2.c Updated copyright to 1997. trans2.h Updated copyright to 1997. uid.c Updated copyright to 1997. username.c Updated copyright to 1997. util.c Updated copyright to 1997. version.h Changed to 1.9.17alpha1. (This used to be commit cf23a155a1315f50d488794a2caf88402bf3e3e6) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 05b40ada0f..eba76d4c74 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -3,7 +3,7 @@ Unix SMB/Netbios implementation. Version 1.9. support for quotas - Copyright (C) Andrew Tridgell 1992-1995 + Copyright (C) Andrew Tridgell 1992-1997 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit From c6e63aa896a10656f6205828e744b722fc72f8ac Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Wed, 11 Jun 1997 01:03:06 +0000 Subject: Makefile: Added quoata changes for Linux from Thorvald Natvig Makefile.RPM: Added quoata changes for Linux from Thorvald Natvig charset.c: Large changes to add multiple client code pages. charset.h: Changed charset_initialise() proto. client.c: Fixed message sending bug. Changed charset_initialise(). ipc.c: Fixed #ifdef compile problems. loadparm.c: Added "client code page" option. nmbd.c: Changed charset_initialise(). Fixed lmhosts read. nmblookup.c: Changed charset_initialise(). proto.h: Added lp_client_code_page(void). quotas.c: Added quoata changes for Linux from Thorvald Natvig reply.c: Changed debug level. Made SMBecho ignore tid. server.c: Changed charset_initialise(). smb.h: Added DEFAULT_CLIENT_CODE_PAGE as 850. smbpasswd.c: Changed charset_initialise(). status.c: Changed charset_initialise(). testparm.c: Changed charset_initialise(). testprns.c: Changed charset_initialise(). Jeremy Allison (jallison@whistle.com) (This used to be commit 957025bace1bcff34d21a6caeca498e85abccb23) --- source3/smbd/quotas.c | 94 +++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 52 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index eba76d4c74..a1d29bcd12 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -33,47 +33,43 @@ extern int DEBUGLEVEL; #ifdef LINUX -#ifdef __KERNEL__ -# undef __KERNEL__ -# include -# define __KERNEL__ -#else -# include -#endif +#include +#include +#include #include +#include + +_syscall4(int, quotactl, int, cmd, const char *, special, int, id, caddr_t, addr); /**************************************************************************** try to get the disk space from disk quotas (LINUX version) ****************************************************************************/ -/* -If you didn't make the symlink to the quota package, too bad :( -*/ -#include "quota/quotactl.c" -#include "quota/hasquota.c" + BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) { uid_t euser_id; + int r; + char dev_disk[256]; struct dqblk D; struct stat S; - dev_t devno ; - struct mntent *mnt; FILE *fp; - int found ; - int qcmd, fd ; - char *qfpathname; + struct mntent *mnt; + int devno; + int found; /* find the block device file */ - if ( stat(path, &S) == -1 ) + if ( stat(path, &S) == -1 ) { return(False) ; + } devno = S.st_dev ; fp = setmntent(MOUNTED,"r"); found = False ; - while ((mnt = getmntent(fp)) != (struct mntent *) 0) { + while ((mnt = getmntent(fp))) { if ( stat(mnt->mnt_dir,&S) == -1 ) continue ; if (S.st_dev == devno) { @@ -83,48 +79,42 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } endmntent(fp) ; - if ( ! found ) - return(False) ; - - qcmd = QCMD(Q_GETQUOTA, USRQUOTA); - - if (hasmntopt(mnt, MNTOPT_NOAUTO) || hasmntopt(mnt, MNTOPT_NOQUOTA)) - return(False) ; - - if (!hasquota(mnt, USRQUOTA, &qfpathname)) - return(False) ; - - euser_id = geteuid(); - seteuid(0); - - if (quotactl(qcmd, mnt->mnt_fsname, euser_id, (caddr_t)&D) != 0) { - if ((fd = open(qfpathname, O_RDONLY)) < 0) { - seteuid(euser_id); + if (!found) { return(False); } - lseek(fd, (long) dqoff(euser_id), L_SET); - switch (read(fd, &D, sizeof(struct dqblk))) { - case 0:/* EOF */ - memset((caddr_t)&D, 0, sizeof(struct dqblk)); - break; - case sizeof(struct dqblk): /* OK */ - break; - default: /* ERROR */ - close(fd); + + euser_id=geteuid(); + seteuid(0); + r=quotactl(QCMD(Q_GETQUOTA,USRQUOTA), mnt->mnt_fsname, euser_id, (caddr_t)&D); seteuid(euser_id); - return(False); + + /* Use softlimit to determine disk space, except when it has been exceeded */ + *bsize = 1024; + if (r) + { + if (errno == EDQUOT) + { + *dfree =0; + *dsize =D.dqb_curblocks; + return (True); } + else return(False); } - seteuid(euser_id); - *bsize=1024; - - if (D.dqb_bsoftlimit==0) - return(False); - if ((D.dqb_curblocks>D.dqb_bsoftlimit)||(D.dqb_curinodes>D.dqb_isoftlimit)) + /* Use softlimit to determine disk space, except when it has been exceeded */ + if ( + (D.dqb_bsoftlimit && D.dqb_curblocks>=D.dqb_bsoftlimit) || + (D.dqb_bhardlimit && D.dqb_curblocks>=D.dqb_bhardlimit) || + (D.dqb_isoftlimit && D.dqb_curinodes>=D.dqb_isoftlimit) || + (D.dqb_ihardlimit && D.dqb_curinodes>=D.dqb_ihardlimit) + ) { *dfree = 0; *dsize = D.dqb_curblocks; } + else if (D.dqb_bsoftlimit==0 && D.dqb_bhardlimit==0) + { + return(False); + } else { *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; *dsize = D.dqb_bsoftlimit; -- cgit From 594f8a43610e0407f6842f76c8d80e180e7daed4 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Wed, 2 Jul 1997 01:19:41 +0000 Subject: Fixed compile warnings for FreeBsd & Linux. Jeremy (jallison@whistle.com). (This used to be commit 93352e1aae9a1af7036cf56da820356cefe3698b) --- source3/smbd/quotas.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index a1d29bcd12..e6a6f61568 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -50,7 +50,6 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) { uid_t euser_id; int r; - char dev_disk[256]; struct dqblk D; struct stat S; FILE *fp; @@ -378,12 +377,12 @@ try to get the disk space from disk quotas - default version ****************************************************************************/ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) { - uid_t user_id, euser_id; + uid_t euser_id; int r; - char dev_disk[256]; struct dqblk D; - struct stat S; #ifndef __FreeBSD__ + char dev_disk[256]; + struct stat S; /* find the block device file */ if ((stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 0)<0)) return (False); @@ -392,12 +391,16 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) euser_id = geteuid(); #ifdef USE_SETRES - /* for HPUX, real uid must be same as euid to execute quotactl for euid */ - user_id = getuid(); - setresuid(euser_id,-1,-1); - r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); - if (setresuid(user_id,-1,-1)) - DEBUG(5,("Unable to reset uid to %d\n", user_id)); + { + uid_t user_id; + + /* for HPUX, real uid must be same as euid to execute quotactl for euid */ + user_id = getuid(); + setresuid(euser_id,-1,-1); + r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); + if (setresuid(user_id,-1,-1)) + DEBUG(5,("Unable to reset uid to %d\n", user_id)); + } #else #if defined(__FreeBSD__) r= quotactl(path,Q_GETQUOTA,euser_id,(char *) &D); -- cgit From 25eae02948b40667495fbb021dd130180180a05e Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Tue, 8 Jul 1997 16:54:44 +0000 Subject: Makefile: Added AIX targets from Ole Holm Nielsen chgpasswd.c: Added Samba/GPL notice (for obvious reasons). clitar.c: Updated Copyright date to include 1997 (for obvious reasons). getsmbpass.c: Updated Copyright date to include 1997 (for obvious reasons). includes.h: Added stropts for solaris. loadparm.c: Changed comment for hide files option. nameconf.c: Updated Copyright date to include 1997 (for obvious reasons). nmbd.c: Updated Copyright date to include 1997 (for obvious reasons). pcap.c: Updated Copyright date to include 1997 (for obvious reasons). proto.h: Re-added accidentaly deleted smb_shm_ calls. quotas.c: Added AIX quota patch from Ole Holm Nielsen server.c: Optimization on calling is_hidden_path. Updated Copyrights. smb.h: Changed DEFAULT_FILES_TO_HIDE from "*/.*" to ".*". smbpass.c: Updated Copyright date to include 1997 (for obvious reasons). ufc.c: Updated Copyright date to include 1997 (for obvious reasons). util.c: Added last component code to is_in_path(). Jeremy (jallison@whistle.com) (This used to be commit 9385ae1005f13c8ed51f1319e3949b5c8571e62d) --- source3/smbd/quotas.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index e6a6f61568..262eea3100 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -367,7 +367,14 @@ DEBUG(5,("disk_quotas for path \"%s\" returning bsize %d, dfree %d, dsize %d\n" #ifdef __FreeBSD__ #include -#else +#elif AIX +/* AIX quota patch from Ole Holm Nielsen */ +#include +/* AIX 4.X: Rename members of the dqblk structure (ohnielse@fysik.dtu.dk) */ +#define dqb_curfiles dqb_curinodes +#define dqb_fhardlimit dqb_ihardlimit +#define dqb_fsoftlimit dqb_isoftlimit +#else /* !__FreeBSD__ && !AIX */ #include #include #endif @@ -380,7 +387,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) uid_t euser_id; int r; struct dqblk D; -#ifndef __FreeBSD__ +#if !defined(__FreeBSD__) && !defined(AIX) char dev_disk[256]; struct stat S; /* find the block device file */ @@ -401,13 +408,17 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) if (setresuid(user_id,-1,-1)) DEBUG(5,("Unable to reset uid to %d\n", user_id)); } -#else +#else /* USE_SETRES */ #if defined(__FreeBSD__) r= quotactl(path,Q_GETQUOTA,euser_id,(char *) &D); -#else +#elif defined(AIX) + /* AIX has both USER and GROUP quotas: + Get the USER quota (ohnielse@fysik.dtu.dk) */ + r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D); +#else /* !__FreeBSD__ && !AIX */ r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); -#endif -#endif +#endif /* !__FreeBSD__ && !AIX */ +#endif /* USE_SETRES */ /* Use softlimit to determine disk space, except when it has been exceeded */ *bsize = 1024; -- cgit From 8b904f4ecc7b6bd6558d40fda4184112bbb10366 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 17 Jul 1997 20:11:58 +0000 Subject: Makefile: Added krb5 option from Nathan Neulinger includes.h: Added krb5 option from Nathan Neulinger , added SGI5 fix. password.c: Added krb5 option from Nathan Neulinger quotas.c: Added inode quote fix. reply.c: removed redundent code. server.c: Changed error debug to 0, removed redundent check. util.c: Added close_low_fd() to become_daemon - fix for rsh from Johnathan Knight. Jeremy (jallison@whistle.com) (This used to be commit 256afb764828b0a6dad5529d62501bc9ea2807ee) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 262eea3100..8cbe46d9e1 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -437,7 +437,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) /* Use softlimit to determine disk space, except when it has been exceeded */ if ((D.dqb_curblocks>D.dqb_bsoftlimit) #if !defined(__FreeBSD__) -||(D.dqb_curfiles>D.dqb_fsoftlimit) +||((D.dqb_curfiles>D.dqb_fsoftlimit) && (D.dqb_fsoftlimit != 0)) #endif ) { *dfree = 0; -- cgit From 15ae50ca5203bc4c04567e400ba041a4d1757b2b Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 24 Jul 1997 17:25:11 +0000 Subject: Makefile: Added UNIXWARE 2.x with shadow passwords from fja@extratech.com client.c: Made prompt appear at debug level 0. Fixed strcasecmp redefinition. Caused client to use set_blocking rather than making fcntl calls itself. dir.c: Removed redundent snum parameters. includes.h: Added SCO fixes. loadparm.c: Made default 'files to hide' a null string. nmbd.c: Removed O_NONBLOCK from pid file open for platforms that dont have it. proto.h: Changed snum to cnum where needed. Changed is_xx_path to is_in_path (now called via MACRO). quotas.c: Swapped setuid/seteuid calls when restoring uid. reply.c: Removed redundent snum parameters. server.c: Changed snum to cnum where needed. Setup new veto_list, hide_list namelists. Added standard_sub changes from Stefaan A Eeckels and Paul Rippin shmem.c: Changed cast for sizeof to be int before negating. smb.h: Added new veto_list, hide_list entries to connections. Added IS_PRINT, IS_HIDDEN_PATH, IS_VETO_PATH macros. trans2.c: Removed redundent snum parameters. util.c: Added standard_sub_basic changes from Stefaan A Eeckels and Paul Rippin Fixed up veto/hidden path processing so the paths are pres-parsed and checked for wildcards (for speed). Jeremy (jallison@whistle.com) (This used to be commit 9afa36f7874cfd527aa6ef1e7965c1d35d46ab1f) --- source3/smbd/quotas.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 8cbe46d9e1..883c2c050d 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -331,8 +331,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) ret = quotactl(Q_GETQUOTA, name, euser_id, &D); #endif - setuid(user_id); /* Restore the original UID status */ - seteuid(euser_id); + seteuid(euser_id); /* Restore the original uid status. */ + setuid(user_id); if (ret < 0) { DEBUG(2,("disk_quotas ioctl (Solaris) failed\n")); -- cgit From e9269c67a59ffa741123cb2ce3ab8dfb97136dec Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Tue, 19 Aug 1997 19:22:26 +0000 Subject: Makefile: Changed for HPUX10 tidyup. includes.h: Changed for HPUX10 tidyup. ipc.c: Fixed bug where getting local server list from NT browsers would fail. nmbsync.c: Fixed bug where getting local server list from NT browsers would fail. proto.h: Changed for crash bug on SCO with USE_MMAP. quotas.c: Added OSF quotas (patch from Bret Giddings ). Rolled back solaris uid change - I think it was wrong. reply.c: Changed for crash bug on SCO with USE_MMAP. server.c: Removed Lukes changes. Changed for crash bug on SCO with USE_MMAP. smb.h: Changed for crash bug on SCO with USE_MMAP. smbpasswd.c:Fixed crash bug with Lukes changes. uid.c: Removed Lukes changes. util.c: Fixed I18N bug with extended char filenames and widelinks = no. Jeremy (jallison@whistle.com) (This used to be commit bf1c79f7fd7f9beec4f9f4e58337cadceeb1cb38) --- source3/smbd/quotas.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 883c2c050d..d19d386e27 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -331,8 +331,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) ret = quotactl(Q_GETQUOTA, name, euser_id, &D); #endif - seteuid(euser_id); /* Restore the original uid status. */ - setuid(user_id); + setuid(user_id); /* Restore the original uid status. */ + seteuid(euser_id); if (ret < 0) { DEBUG(2,("disk_quotas ioctl (Solaris) failed\n")); @@ -363,6 +363,47 @@ DEBUG(5,("disk_quotas for path \"%s\" returning bsize %d, dfree %d, dsize %d\n" return(True); } + +#elif defined(OSF1) +#include + +/**************************************************************************** +try to get the disk space from disk quotas - OFS1 version +****************************************************************************/ +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +{ + uid_t user_id, euser_id; + int r; + struct dqblk D; + struct stat S; + + euser_id = geteuid(); + user_id = getuid(); + + setreuid(euser_id, euser_id); + r= quotactl(path,QCMD(Q_GETQUOTA, USRQUOTA),euser_id,(char *) &D); + if (setreuid(user_id, euser_id) == -1) + DEBUG(5,("Unable to reset uid to %d\n", user_id)); + + *bsize = DEV_BSIZE; + + if (r) + return(False); + + /* Use softlimit to determine disk space, except when it has been exceeded */ + + if (D.dqb_bsoftlimit==0) + return(False); + + if ((D.dqb_curblocks>D.dqb_bsoftlimit)) { + *dfree = 0; + *dsize = D.dqb_curblocks; + } else { + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + *dsize = D.dqb_bsoftlimit; + } + return (True); +} #else #ifdef __FreeBSD__ -- cgit From 81eb442e88e8231b8e9c556c1ee393e99269af78 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 23 Sep 1997 19:19:06 +0000 Subject: Checkin to sync up oplock development code so that NT domain development code won't diverge. Makefile: Fixed make proto (again). Added GLIBC2 fixes for Linux. includes.h: Added GLIBC2 fixes for Linux. proto.h: Much tidier. quotas.c: OSF/1 quota fix. reply.c: Fix from Ray Frush for zero NT timestamps. server.c util.c: First oplock checkin - nowhere near finished so bracketed with #ifdef USE_OPLOCKS. Done to make sync with NT domain code easier. Jeremy (jallison@whistle.com) (This used to be commit 7dce7d84473beb5663b14a8ab32781970819c19d) --- source3/smbd/quotas.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index d19d386e27..d4f746c9e3 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -373,22 +373,34 @@ try to get the disk space from disk quotas - OFS1 version BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) { uid_t user_id, euser_id; - int r; + int r, save_errno; struct dqblk D; struct stat S; euser_id = geteuid(); user_id = getuid(); - setreuid(euser_id, euser_id); + setreuid(euser_id, -1); r= quotactl(path,QCMD(Q_GETQUOTA, USRQUOTA),euser_id,(char *) &D); - if (setreuid(user_id, euser_id) == -1) + if (r) + save_errno = errno; + + if (setreuid(user_id, -1) == -1) DEBUG(5,("Unable to reset uid to %d\n", user_id)); *bsize = DEV_BSIZE; if (r) - return(False); + { + if (save_errno == EDQUOT) // disk quota exceeded + { + *dfree = 0; + *dsize = D.dqb_curblocks; + return (True); + } + else + return (False); + } /* Use softlimit to determine disk space, except when it has been exceeded */ -- cgit From 74113cd60ecceaf73fce83e84dbcd58b498f2cb1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 8 Oct 1997 20:34:13 +0000 Subject: Makefile: Split definitions for SGI4,5,6. includes.h: Split definitions for SGI4,5,6. pipes.c: Moved Luke's #ifdef to remove warnings. quotas.c: Two changes for FreeBSD and SGI. server.c: Quota changes for large filesystems. Jeremy (jallison@whistle.com) (This used to be commit b8ff5543b9fa45095caa9f24aeb22a1dcc1cd308) --- source3/smbd/quotas.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index d4f746c9e3..8810bcd909 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -416,10 +416,132 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } return (True); } + +#elif defined (SGI6) +/**************************************************************************** +try to get the disk space from disk quotas (IRIX 6.2 version) +****************************************************************************/ + +#include +#include + +BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +{ + uid_t euser_id; + int r; + struct dqblk D; + struct fs_disk_quota F; + struct stat S; + FILE *fp; + struct mntent *mnt; + int devno; + int found; + + /* find the block device file */ + + if ( stat(path, &S) == -1 ) { + return(False) ; + } + + devno = S.st_dev ; + + fp = setmntent(MOUNTED,"r"); + found = False ; + + while ((mnt = getmntent(fp))) { + if ( stat(mnt->mnt_dir,&S) == -1 ) + continue ; + if (S.st_dev == devno) { + found = True ; + break ; + } + } + endmntent(fp) ; + + if (!found) { + return(False); + } + + euser_id=geteuid(); + seteuid(0); + + /* Use softlimit to determine disk space, except when it has been exceeded */ + + *bsize = 512; + + if ( 0 == strcmp ( mnt->mnt_type, "efs" )) + { + r=quotactl (Q_GETQUOTA, mnt->mnt_fsname, euser_id, (caddr_t) &D); + + if (r==-1) + return(False); + + /* Use softlimit to determine disk space, except when it has been exceeded */ + if ( + (D.dqb_bsoftlimit && D.dqb_curblocks>=D.dqb_bsoftlimit) || + (D.dqb_bhardlimit && D.dqb_curblocks>=D.dqb_bhardlimit) || + (D.dqb_fsoftlimit && D.dqb_curfiles>=D.dqb_fsoftlimit) || + (D.dqb_fhardlimit && D.dqb_curfiles>=D.dqb_fhardlimit) + ) + { + *dfree = 0; + *dsize = D.dqb_curblocks; + } + else if (D.dqb_bsoftlimit==0 && D.dqb_bhardlimit==0) + { + return(False); + } + else + { + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + *dsize = D.dqb_bsoftlimit; + } + + } + else if ( 0 == strcmp ( mnt->mnt_type, "xfs" )) + { + r=quotactl (Q_XGETQUOTA, mnt->mnt_fsname, euser_id, (caddr_t) &F); + + if (r==-1) + return(False); + + /* Use softlimit to determine disk space, except when it has been exceeded */ + if ( + (F.d_blk_softlimit && F.d_bcount>=F.d_blk_softlimit) || + (F.d_blk_hardlimit && F.d_bcount>=F.d_blk_hardlimit) || + (F.d_ino_softlimit && F.d_icount>=F.d_ino_softlimit) || + (F.d_ino_hardlimit && F.d_icount>=F.d_ino_hardlimit) + ) + { + /* + * Fixme!: these are __uint64_t, this may truncate values + */ + *dfree = 0; + *dsize = (int) F.d_bcount; + } + else if (F.d_blk_softlimit==0 && F.d_blk_hardlimit==0) + { + return(False); + } + else + { + *dfree = (int)(F.d_blk_softlimit - F.d_bcount); + *dsize = (int)F.d_blk_softlimit; + } + + } + else + return(False); + + return (True); + +} + #else #ifdef __FreeBSD__ #include +#include #elif AIX /* AIX quota patch from Ole Holm Nielsen */ #include @@ -463,7 +585,25 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } #else /* USE_SETRES */ #if defined(__FreeBSD__) - r= quotactl(path,Q_GETQUOTA,euser_id,(char *) &D); + { + /* FreeBSD patches from Marty Moll */ + uid_t user_id; + gid_t egrp_id; + + /* Need to be root to get quotas in FreeBSD */ + user_id = getuid(); + egrp_id = getegid(); + setuid(0); + seteuid(0); + r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D); + + /* As FreeBSD has group quotas, if getting the user + quota fails, try getting the group instead. */ + if (r) + r= quotactl(path,QCMD(Q_GETQUOTA,GRPQUOTA),egrp_id,(char *) &D); + setuid(user_id); + seteuid(euser_id); + } #elif defined(AIX) /* AIX has both USER and GROUP quotas: Get the USER quota (ohnielse@fysik.dtu.dk) */ @@ -474,7 +614,12 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) #endif /* USE_SETRES */ /* Use softlimit to determine disk space, except when it has been exceeded */ +#if defined(__FreeBSD__) + *bsize = DEV_BSIZE; +#else /* !__FreeBSD__ */ *bsize = 1024; +#endif /*!__FreeBSD__ */ + if (r) { if (errno == EDQUOT) -- cgit From 9f804556c4d0bb68f9b7acaf2b679bc0a02ea8f9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 17 Nov 1997 19:16:38 +0000 Subject: loadparm.c : Added "veto oplock files" parameter. make_printerdef.c: Fixed warning. quotas.c: Fixed irix root errors. server.c: Fixed oplock reference count bug. smb.h: Added IS_VETO_OPLOCK_PATH(). Jeremy. (This used to be commit c28487df63e29bc0f8d2ece876a07a2a076d4c73) --- source3/smbd/quotas.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 8810bcd909..562d8fd5db 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -473,6 +473,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) { r=quotactl (Q_GETQUOTA, mnt->mnt_fsname, euser_id, (caddr_t) &D); + seteuid(euser_id); /* Restore the original uid status. */ + if (r==-1) return(False); @@ -502,6 +504,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) { r=quotactl (Q_XGETQUOTA, mnt->mnt_fsname, euser_id, (caddr_t) &F); + seteuid(euser_id); /* Restore the original uid status. */ + if (r==-1) return(False); @@ -531,7 +535,10 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } else + { + seteuid(euser_id); /* Restore the original uid status. */ return(False); + } return (True); -- cgit From d1e796d8577a666e5ef14f9bb462c080300dca3e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 23 Dec 1997 07:15:59 +0000 Subject: Fixes to compile under OpenBSD from "Todd T. Fries" Jeremy. (This used to be commit 3c9292505914e2119fa7b1973c9fbbe1742262b2) --- source3/smbd/quotas.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 562d8fd5db..8333fa7cf2 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -546,7 +546,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) #else -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__OpenBSD__) #include #include #elif AIX @@ -556,7 +556,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) #define dqb_curfiles dqb_curinodes #define dqb_fhardlimit dqb_ihardlimit #define dqb_fsoftlimit dqb_isoftlimit -#else /* !__FreeBSD__ && !AIX */ +#else /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ #include #include #endif @@ -569,7 +569,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) uid_t euser_id; int r; struct dqblk D; -#if !defined(__FreeBSD__) && !defined(AIX) +#if !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) char dev_disk[256]; struct stat S; /* find the block device file */ @@ -591,7 +591,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) DEBUG(5,("Unable to reset uid to %d\n", user_id)); } #else /* USE_SETRES */ -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) { /* FreeBSD patches from Marty Moll */ uid_t user_id; @@ -615,17 +615,17 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) /* AIX has both USER and GROUP quotas: Get the USER quota (ohnielse@fysik.dtu.dk) */ r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D); -#else /* !__FreeBSD__ && !AIX */ +#else /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); -#endif /* !__FreeBSD__ && !AIX */ +#endif /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ #endif /* USE_SETRES */ /* Use softlimit to determine disk space, except when it has been exceeded */ -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) *bsize = DEV_BSIZE; -#else /* !__FreeBSD__ */ +#else /* !__FreeBSD__ && !__OpenBSD__ */ *bsize = 1024; -#endif /*!__FreeBSD__ */ +#endif /*!__FreeBSD__ && !__OpenBSD__ */ if (r) { @@ -641,7 +641,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) return(False); /* Use softlimit to determine disk space, except when it has been exceeded */ if ((D.dqb_curblocks>D.dqb_bsoftlimit) -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) ||((D.dqb_curfiles>D.dqb_fsoftlimit) && (D.dqb_fsoftlimit != 0)) #endif ) { -- cgit From 55f400bd84f26027f5ec9b7fa06b22895de7557c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 22 Jan 1998 13:27:43 +0000 Subject: This is *not* a big change (although it looks like one). This is merely updating the Copyright statements from 1997 to 1998. It's a once a year thing :-). NO OTHER CHANGES WERE MADE. Jeremy. (This used to be commit b9c16977231efb274e08856f7f3f4408dad6d96c) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 8333fa7cf2..0a366e5ee6 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -3,7 +3,7 @@ Unix SMB/Netbios implementation. Version 1.9. support for quotas - Copyright (C) Andrew Tridgell 1992-1997 + Copyright (C) Andrew Tridgell 1992-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit From 5d7c8375e4ffb017ef0f9eed7e619e533b3e8d12 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 24 Mar 1998 00:37:53 +0000 Subject: clientgen.c ipc.c smbpasswd.c: Fixes for warnings (from Herb). quotas.c: Linux quota fix. util.c: Ensure smb_read_error is zero in all calls that can set it. lib/rpc/include/rpc_misc.h lib/rpc/include/rpc_netlogon.h lib/rpc/parse/parse_misc.c lib/rpc/parse/parse_net.c lib/rpc/server/srv_netlog.c : Modify Luke's code to call SamOEMhash(). Jeremy. (This used to be commit 7f749708383b8b36c3f23a5fbc5cbdf39bc8e555) --- source3/smbd/quotas.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 0a366e5ee6..df85f79b9b 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -115,6 +115,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) return(False); } else { + if (D.dqb_bsoftlimit == 0) + D.dqb_bsoftlimit = D.dqb_bhardlimit; *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; *dsize = D.dqb_bsoftlimit; } -- cgit From f888868f46a5418bac9ab528497136c152895305 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 May 1998 00:55:32 +0000 Subject: This is a security audit change of the main source. It removed all ocurrences of the following functions : sprintf strcpy strcat The replacements are slprintf, safe_strcpy and safe_strcat. It should not be possible to use code in Samba that uses sprintf, strcpy or strcat, only the safe_equivalents. Once Andrew has fixed the slprintf implementation then this code will be moved back to the 1.9.18 code stream. Jeremy. (This used to be commit 2d774454005f0b54e5684cf618da7060594dfcbb) --- source3/smbd/quotas.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index df85f79b9b..ee08e48e65 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -138,7 +138,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) struct stat sbuf; dev_t devno ; static dev_t devno_cached = 0 ; - static char name[MNTMAXSTR] ; + static pstring name; struct q_request request ; struct qf_header header ; static int quota_default = 0 ; @@ -172,7 +172,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } - strcpy(name,mnt->mnt_dir) ; + pstrcpy(name,mnt->mnt_dir) ; endmntent(fd) ; if ( ! found ) @@ -249,10 +249,10 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) struct quotctl command; int file; struct mnttab mnt; - static char name[MNT_LINE_MAX] ; + static pstring name; #else struct mntent *mnt; - static char name[MNTMAXSTR] ; + static pstring name; #endif FILE *fd; struct stat sbuf; @@ -283,8 +283,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } } - strcpy(name,mnt.mnt_mountp) ; - strcat(name,"/quotas") ; + pstrcpy(name,mnt.mnt_mountp) ; + pstrcat(name,"/quotas") ; fclose(fd) ; #else if ((fd = setmntent(MOUNTED, "r")) == NULL) @@ -302,7 +302,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } } - strcpy(name,mnt->mnt_fsname) ; + pstrcpy(name,mnt->mnt_fsname) ; endmntent(fd) ; #endif -- cgit From 64578c0589a3a741f81fb55c16eeb882128da00b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 29 Jul 1998 03:08:05 +0000 Subject: merge from the autoconf2 branch to the main branch (This used to be commit 3bda7ac417107a7b01d91805ca71c4330657ed21) --- source3/smbd/quotas.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index ee08e48e65..dbdbd49921 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -581,7 +581,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) euser_id = geteuid(); -#ifdef USE_SETRES +#ifdef HPUX { uid_t user_id; @@ -592,7 +592,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) if (setresuid(user_id,-1,-1)) DEBUG(5,("Unable to reset uid to %d\n", user_id)); } -#else /* USE_SETRES */ +#else #if defined(__FreeBSD__) || defined(__OpenBSD__) { /* FreeBSD patches from Marty Moll */ @@ -620,7 +620,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) #else /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); #endif /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ -#endif /* USE_SETRES */ +#endif /* HAVE_SETRES */ /* Use softlimit to determine disk space, except when it has been exceeded */ #if defined(__FreeBSD__) || defined(__OpenBSD__) -- cgit From 18556274139cc5a00593471bd745354d98a35303 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 1 Sep 1998 20:11:54 +0000 Subject: More abstraction of file system data types, to move to a 64 bit file interface for the NT SMB's. Created a new define, SMB_STRUCT_STAT that currently is defined to be struct stat - this wil change to a user defined type containing 64 bit info when the correct wrappers are written for 64 bit stat(), fstat() and lstat() calls. Also changed all sys_xxxx() calls that were previously just wrappers to the same call prefixed by a dos_to_unix() call into dos_xxxx() calls. This makes it explicit when a pathname translation is being done, and when it is not. Now, all sys_xxx() calls are meant to be wrappers to mask OS differences, and not silently converting filenames on the fly. Jeremy. (This used to be commit 28aa182dbffaa4ffd86047e608400de4b26e80eb) --- source3/smbd/quotas.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index dbdbd49921..7f1cd5ce79 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -51,7 +51,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) uid_t euser_id; int r; struct dqblk D; - struct stat S; + SMB_STRUCT_STAT S; FILE *fp; struct mntent *mnt; int devno; @@ -135,7 +135,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) { struct mntent *mnt; FILE *fd; - struct stat sbuf; + SMB_STRUCT_STAT sbuf; dev_t devno ; static dev_t devno_cached = 0 ; static pstring name; @@ -255,7 +255,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) static pstring name; #endif FILE *fd; - struct stat sbuf; + SMB_STRUCT_STAT sbuf; dev_t devno ; static dev_t devno_cached = 0 ; int found ; @@ -377,7 +377,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) uid_t user_id, euser_id; int r, save_errno; struct dqblk D; - struct stat S; + SMB_STRUCT_STAT S; euser_id = geteuid(); user_id = getuid(); @@ -433,7 +433,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) int r; struct dqblk D; struct fs_disk_quota F; - struct stat S; + SMB_STRUCT_STAT S; FILE *fp; struct mntent *mnt; int devno; @@ -573,7 +573,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) struct dqblk D; #if !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) char dev_disk[256]; - struct stat S; + SMB_STRUCT_STAT S; /* find the block device file */ if ((stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 0)<0)) return (False); -- cgit From 7bb86c1b132bce31a006ea9768a54db7a45fe1a5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 Sep 1998 18:40:31 +0000 Subject: Ok - this is the 64 bit widening check in. It changes the configure to check for stat64 and friends, and then changes much of Samba to use the data type SMB_OFF_T for file size information. stat/fstat/lstat/lseek/ftruncate have now become sys_stat etc. to hide the 64 bit calls if needed. Note that this still does not expose 64 bit functionality to the client, as the changes to the reply_xxx smb's are not yet done. This code change should make these changes possible. Still to do before full 64 bit-ness to the client: fcntl lock code. statfs code widening of dev_t and ino_t (now possible due to SMB_DEV_T and SMB_OFF_T types being in place). Let me know if wierd things happen after this check-in and I'll fix them :-). Jeremy. (This used to be commit 14500936c321d15995c963766aac67bf1f4e3824) --- source3/smbd/quotas.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 7f1cd5ce79..b7a538e189 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -54,12 +54,12 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) SMB_STRUCT_STAT S; FILE *fp; struct mntent *mnt; - int devno; + SMB_DEV_T devno; int found; /* find the block device file */ - if ( stat(path, &S) == -1 ) { + if ( sys_stat(path, &S) == -1 ) { return(False) ; } @@ -69,7 +69,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) found = False ; while ((mnt = getmntent(fp))) { - if ( stat(mnt->mnt_dir,&S) == -1 ) + if ( sys_stat(mnt->mnt_dir,&S) == -1 ) continue ; if (S.st_dev == devno) { found = True ; @@ -136,15 +136,15 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) struct mntent *mnt; FILE *fd; SMB_STRUCT_STAT sbuf; - dev_t devno ; - static dev_t devno_cached = 0 ; + SMB_DEV_T devno ; + static SMB_DEV_T devno_cached = 0 ; static pstring name; struct q_request request ; struct qf_header header ; static int quota_default = 0 ; int found ; - if ( stat(path,&sbuf) == -1 ) + if ( sys_stat(path,&sbuf) == -1 ) return(False) ; devno = sbuf.st_dev ; @@ -160,7 +160,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) while ((mnt = getmntent(fd)) != NULL) { - if ( stat(mnt->mnt_dir,&sbuf) == -1 ) + if ( sys_stat(mnt->mnt_dir,&sbuf) == -1 ) continue ; if (sbuf.st_dev == devno) { @@ -256,11 +256,11 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) #endif FILE *fd; SMB_STRUCT_STAT sbuf; - dev_t devno ; - static dev_t devno_cached = 0 ; + SMB_DEV_T devno ; + static SMB_DEV_T devno_cached = 0 ; int found ; - if ( stat(path,&sbuf) == -1 ) + if ( sys_stat(path,&sbuf) == -1 ) return(False) ; devno = sbuf.st_dev ; @@ -273,7 +273,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) found = False ; while (getmntent(fd, &mnt) == 0) { - if ( stat(mnt.mnt_mountp,&sbuf) == -1 ) + if ( sys_stat(mnt.mnt_mountp,&sbuf) == -1 ) continue ; DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt.mnt_mountp,sbuf.st_dev)); @@ -292,7 +292,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) found = False ; while ((mnt = getmntent(fd)) != NULL) { - if ( stat(mnt->mnt_dir,&sbuf) == -1 ) + if ( sys_stat(mnt->mnt_dir,&sbuf) == -1 ) continue ; DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt->mnt_dir,sbuf.st_dev)); @@ -436,12 +436,12 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) SMB_STRUCT_STAT S; FILE *fp; struct mntent *mnt; - int devno; + SMB_DEV_T devno; int found; /* find the block device file */ - if ( stat(path, &S) == -1 ) { + if ( sys_stat(path, &S) == -1 ) { return(False) ; } @@ -451,7 +451,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) found = False ; while ((mnt = getmntent(fp))) { - if ( stat(mnt->mnt_dir,&S) == -1 ) + if ( sys_stat(mnt->mnt_dir,&S) == -1 ) continue ; if (S.st_dev == devno) { found = True ; @@ -575,7 +575,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) char dev_disk[256]; SMB_STRUCT_STAT S; /* find the block device file */ - if ((stat(path, &S)<0) || + if ((sys_stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 0)<0)) return (False); #endif -- cgit From fc62d6bf368c950e1e51bc42771cce8b299df42c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 17 Oct 1998 17:41:13 +0000 Subject: Small tidyups for gcc in 'preen' mode.... Jeremy. (This used to be commit 60dc1a4a00a22088d33369588b0d5eb292cf084a) --- source3/smbd/quotas.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index b7a538e189..716c2357c6 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -661,6 +661,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) #else /* this keeps fussy compilers happy */ + void quotas_dummy(void); void quotas_dummy(void) {} #endif /* QUOTAS */ -- cgit From 01e04614c7c466fdbdc398c782acaa931965f925 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Nov 1998 02:25:28 +0000 Subject: Makefile.in configure configure.in include/proto.h smbd/noquotas.c smbd/quotas.c: Added quotas patch for autoconf from Dejan Ilic . printing/printing.c: Filenames with spaces patch from Allan Bjorklund utils/nmblookup.c: Fix usage() function. smbd/reply.c: Split out the security=server and security=domain checks into check_server_security() and check_domain_security() to aid the writing of the 'hack' appliance mode invented by John Schimmel. Jeremy. (This used to be commit f09ab9b52251087a58af92ec753537ca34a970fc) --- source3/smbd/quotas.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 716c2357c6..d610bbe15a 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -1,4 +1,3 @@ -#ifdef QUOTAS /* Unix SMB/Netbios implementation. Version 1.9. @@ -658,10 +657,3 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } #endif - -#else -/* this keeps fussy compilers happy */ - void quotas_dummy(void); - void quotas_dummy(void) {} -#endif /* QUOTAS */ - -- cgit From 4bd1feb68c4f5134293d87433da932c20cded915 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 6 Nov 1998 18:40:51 +0000 Subject: lib/charcnv.c: Improved debug comment. libsmb/namequery.c: Fix to remove 2 second wait is we are doing a unicast and got a reply. smbd/dfree.c: smbd/noquotas.c: smbd/quotas.c: Fixes from Dejan Ilic for the quota code. utils/smbpasswd.c: Fixes to allow smbpasswd to be called from swat. Jeremy. (This used to be commit b5981c0149ad8c6f13ea87db450080616538b5d5) --- source3/smbd/quotas.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index d610bbe15a..d5ecf73451 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -45,7 +45,7 @@ _syscall4(int, quotactl, int, cmd, const char *, special, int, id, caddr_t, addr try to get the disk space from disk quotas (LINUX version) ****************************************************************************/ -BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t euser_id; int r; @@ -130,7 +130,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) /**************************************************************************** try to get the disk space from disk quotas (CRAY VERSION) ****************************************************************************/ -BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) + +BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { struct mntent *mnt; FILE *fd; @@ -227,6 +228,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) #elif defined(SUNOS5) || defined(SUNOS4) #include +#include #if defined(SUNOS5) #include #include @@ -236,10 +238,11 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) #endif /**************************************************************************** -try to get the disk space from disk quotas (solaris 2 version) -****************************************************************************/ +try to get the disk space from disk quotas (SunOS & Solaris2 version) /* Quota code by Peter Urbanec (amiga@cse.unsw.edu.au) */ -BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +****************************************************************************/ + +BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t user_id, euser_id; int ret; @@ -249,7 +252,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) int file; struct mnttab mnt; static pstring name; -#else +#else /* SunOS4 */ struct mntent *mnt; static pstring name; #endif @@ -285,7 +288,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) pstrcpy(name,mnt.mnt_mountp) ; pstrcat(name,"/quotas") ; fclose(fd) ; -#else +#else /* SunOS4 */ if ((fd = setmntent(MOUNTED, "r")) == NULL) return(False) ; @@ -336,7 +339,7 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) seteuid(euser_id); if (ret < 0) { - DEBUG(2,("disk_quotas ioctl (Solaris) failed\n")); + DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); return(False); } @@ -349,17 +352,18 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) if (D.dqb_bsoftlimit==0) return(False); - *bsize = 512; + *bsize = DEV_BSIZE; *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; *dsize = D.dqb_bsoftlimit; + if(*dfree < 0) { *dfree = 0; *dsize = D.dqb_curblocks; } -DEBUG(5,("disk_quotas for path \"%s\" returning bsize %d, dfree %d, dsize %d\n", - path,*bsize,*dfree,*dsize)); + DEBUG(5,("disk_quotas for path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n", + path,(double)*bsize,(double)*dfree,(double)*dsize)); return(True); } @@ -371,7 +375,8 @@ DEBUG(5,("disk_quotas for path \"%s\" returning bsize %d, dfree %d, dsize %d\n" /**************************************************************************** try to get the disk space from disk quotas - OFS1 version ****************************************************************************/ -BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) + +BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t user_id, euser_id; int r, save_errno; @@ -426,7 +431,7 @@ try to get the disk space from disk quotas (IRIX 6.2 version) #include #include -BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) +BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t euser_id; int r; @@ -518,11 +523,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) (F.d_ino_hardlimit && F.d_icount>=F.d_ino_hardlimit) ) { - /* - * Fixme!: these are __uint64_t, this may truncate values - */ *dfree = 0; - *dsize = (int) F.d_bcount; + *dsize = F.d_bcount; } else if (F.d_blk_softlimit==0 && F.d_blk_hardlimit==0) { @@ -530,8 +532,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) } else { - *dfree = (int)(F.d_blk_softlimit - F.d_bcount); - *dsize = (int)F.d_blk_softlimit; + *dfree = (F.d_blk_softlimit - F.d_bcount); + *dsize = F.d_blk_softlimit; } } @@ -565,7 +567,8 @@ BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) /**************************************************************************** try to get the disk space from disk quotas - default version ****************************************************************************/ -BOOL disk_quotas(char *path, int *bsize, int *dfree, int *dsize) + +BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t euser_id; int r; -- cgit From e4f974c611c179a5e7827ec8325e01811db6540b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Nov 1998 20:33:37 +0000 Subject: Makefile.in: Removed rpc_server/srv_ldap_helpers.c per J.F.'s instructions. client/client.c: client/clitar.c: include/client.h: smbwrapper/smbw_dir.c: smbwrapper/smbw_stat.c: smbwrapper/smbw.c: lib/util.c: Converted all use of 'mode' to uint16. smbd/quotas.c: Fixed stupid comment bug I put in there :-(. printing/printing.c: Fix from J.F. to new code. Jeremy. (This used to be commit bacd3e9d2036a804e73644a28fc498f229c8446c) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index d5ecf73451..6df668e279 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -239,7 +239,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U /**************************************************************************** try to get the disk space from disk quotas (SunOS & Solaris2 version) -/* Quota code by Peter Urbanec (amiga@cse.unsw.edu.au) */ +Quota code by Peter Urbanec (amiga@cse.unsw.edu.au). ****************************************************************************/ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) -- cgit From 2164685b9f959814af2067aa0dcac2d1b2ac0bc5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Nov 1998 02:07:07 +0000 Subject: include/smb.h: Re-added zero pointer protection to ZERO_STRUCTP. lib/util_sock.c: Added strerror() calls to getpeername failures (which seem to be giving IRIX trouble at the moment). rpc_parse/parse_sec.c: Changed use of ZERO_STRUCTPN to ZERO_STRUCTP which again does zero pointer protection. smbd/quotas.c: Fixed typo. Jeremy. (This used to be commit b62f008974c96e0302d6c146cf49bc2045bef005) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 6df668e279..5cd5a895c6 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -373,7 +373,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U #include /**************************************************************************** -try to get the disk space from disk quotas - OFS1 version +try to get the disk space from disk quotas - OSF1 version ****************************************************************************/ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) -- cgit From 768761820e8d7481c586c4e0ab4ac7cb36d18c4b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 17 Nov 1998 20:50:07 +0000 Subject: Added the same open()/fopen()/creat()/mmap() -> sys_XXX calls. Tidied up some of the mess (no other word for it). Still doesn't compile cleanly. There are calls with incorrect parameters that don't seem to be doing the right thing. This code still needs surgery :-(. Jeremy. (This used to be commit 18ff93a9abbf68ee8c59c0af3e57c63e4a015dac) --- source3/smbd/quotas.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 5cd5a895c6..afabb1befd 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -270,7 +270,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U if ( devno != devno_cached ) { devno_cached = devno ; #if defined(SUNOS5) - if ((fd = fopen(MNTTAB, "r")) == NULL) + if ((fd = sys_fopen(MNTTAB, "r")) == NULL) return(False) ; found = False ; @@ -320,7 +320,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U #if defined(SUNOS5) DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); - if((file=open(name, O_RDONLY))<0) { + if((file=sys_open(name, O_RDONLY,0))<0) { setuid(user_id); /* Restore the original UID status */ seteuid(euser_id); return(False); -- cgit From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/smbd/quotas.c | 111 +++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 56 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index afabb1befd..badc0562bc 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -47,7 +47,6 @@ try to get the disk space from disk quotas (LINUX version) BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { - uid_t euser_id; int r; struct dqblk D; SMB_STRUCT_STAT S; @@ -55,6 +54,9 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U struct mntent *mnt; SMB_DEV_T devno; int found; + uid_t euser_id; + + euser_id = geteuid(); /* find the block device file */ @@ -81,10 +83,10 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U return(False); } - euser_id=geteuid(); - seteuid(0); + save_re_uid(); + set_effective_uid(0); r=quotactl(QCMD(Q_GETQUOTA,USRQUOTA), mnt->mnt_fsname, euser_id, (caddr_t)&D); - seteuid(euser_id); + restore_re_uid(); /* Use softlimit to determine disk space, except when it has been exceeded */ *bsize = 1024; @@ -212,11 +214,10 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U *dsize = request.qf_entry.user_q.f_use ; - if ( *dfree ) - *dfree -= *dsize ; - - if ( *dfree < 0 ) + if ( *dfree < *dsize ) *dfree = 0 ; + else + *dfree -= *dsize ; *bsize = 4096 ; /* Cray blocksize */ @@ -244,7 +245,7 @@ Quota code by Peter Urbanec (amiga@cse.unsw.edu.au). BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { - uid_t user_id, euser_id; + uid_t euser_id; int ret; struct dqblk D; #if defined(SUNOS5) @@ -261,6 +262,8 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U SMB_DEV_T devno ; static SMB_DEV_T devno_cached = 0 ; int found ; + + euser_id = geteuid(); if ( sys_stat(path,&sbuf) == -1 ) return(False) ; @@ -312,18 +315,14 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U return(False) ; } - euser_id = geteuid(); - user_id = getuid(); - - setuid(0); /* Solaris seems to want to give info only to super-user */ - seteuid(0); + save_re_uid(); + set_effective_uid(0); #if defined(SUNOS5) DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); if((file=sys_open(name, O_RDONLY,0))<0) { - setuid(user_id); /* Restore the original UID status */ - seteuid(euser_id); - return(False); + restore_re_uid(); + return(False); } command.op = Q_GETQUOTA; command.uid = euser_id; @@ -335,8 +334,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U ret = quotactl(Q_GETQUOTA, name, euser_id, &D); #endif - setuid(user_id); /* Restore the original uid status. */ - seteuid(euser_id); + restore_re_uid(); if (ret < 0) { DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); @@ -353,14 +351,13 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U if (D.dqb_bsoftlimit==0) return(False); *bsize = DEV_BSIZE; - *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; *dsize = D.dqb_bsoftlimit; - if(*dfree < 0) - { + if (D.dqb_curblocks > D.dqb_bsoftlimit) { *dfree = 0; *dsize = D.dqb_curblocks; - } + } else + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; DEBUG(5,("disk_quotas for path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n", path,(double)*bsize,(double)*dfree,(double)*dsize)); @@ -378,21 +375,26 @@ try to get the disk space from disk quotas - OSF1 version BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { - uid_t user_id, euser_id; int r, save_errno; struct dqblk D; SMB_STRUCT_STAT S; + uid_t euser_id; + /* + * This code presumes that OSF1 will only + * give out quota info when the real uid + * matches the effective uid. JRA. + */ euser_id = geteuid(); - user_id = getuid(); + save_re_uid(); + if (set_re_uid() != 0) return False; - setreuid(euser_id, -1); r= quotactl(path,QCMD(Q_GETQUOTA, USRQUOTA),euser_id,(char *) &D); - if (r) + if (r) { save_errno = errno; + } - if (setreuid(user_id, -1) == -1) - DEBUG(5,("Unable to reset uid to %d\n", user_id)); + restore_re_uid(); *bsize = DEV_BSIZE; @@ -423,7 +425,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U return (True); } -#elif defined (SGI6) +#elif defined (IRIX6) /**************************************************************************** try to get the disk space from disk quotas (IRIX 6.2 version) ****************************************************************************/ @@ -469,7 +471,8 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U } euser_id=geteuid(); - seteuid(0); + save_re_uid(); + set_effective_uid(0); /* Use softlimit to determine disk space, except when it has been exceeded */ @@ -479,7 +482,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U { r=quotactl (Q_GETQUOTA, mnt->mnt_fsname, euser_id, (caddr_t) &D); - seteuid(euser_id); /* Restore the original uid status. */ + restore_re_uid(); if (r==-1) return(False); @@ -510,7 +513,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U { r=quotactl (Q_XGETQUOTA, mnt->mnt_fsname, euser_id, (caddr_t) &F); - seteuid(euser_id); /* Restore the original uid status. */ + restore_re_uid(); if (r==-1) return(False); @@ -539,8 +542,8 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U } else { - seteuid(euser_id); /* Restore the original uid status. */ - return(False); + restore_re_uid(); + return(False); } return (True); @@ -570,9 +573,9 @@ try to get the disk space from disk quotas - default version BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { - uid_t euser_id; int r; struct dqblk D; + uid_t euser_id; #if !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) char dev_disk[256]; SMB_STRUCT_STAT S; @@ -584,36 +587,32 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U euser_id = geteuid(); #ifdef HPUX - { - uid_t user_id; - - /* for HPUX, real uid must be same as euid to execute quotactl for euid */ - user_id = getuid(); - setresuid(euser_id,-1,-1); - r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); - if (setresuid(user_id,-1,-1)) - DEBUG(5,("Unable to reset uid to %d\n", user_id)); - } + /* for HPUX, real uid must be same as euid to execute quotactl for euid */ + save_re_uid(); + if (set_re_uid() != 0) return False; + + r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); + + restore_re_uid(); #else #if defined(__FreeBSD__) || defined(__OpenBSD__) { /* FreeBSD patches from Marty Moll */ - uid_t user_id; gid_t egrp_id; - /* Need to be root to get quotas in FreeBSD */ - user_id = getuid(); + save_re_uid(); + set_effective_uid(0); + egrp_id = getegid(); - setuid(0); - seteuid(0); r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D); /* As FreeBSD has group quotas, if getting the user quota fails, try getting the group instead. */ - if (r) - r= quotactl(path,QCMD(Q_GETQUOTA,GRPQUOTA),egrp_id,(char *) &D); - setuid(user_id); - seteuid(euser_id); + if (r) { + r= quotactl(path,QCMD(Q_GETQUOTA,GRPQUOTA),egrp_id,(char *) &D); + } + + restore_re_uid(); } #elif defined(AIX) /* AIX has both USER and GROUP quotas: @@ -622,7 +621,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U #else /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); #endif /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ -#endif /* HAVE_SETRES */ +#endif /* HPUX */ /* Use softlimit to determine disk space, except when it has been exceeded */ #if defined(__FreeBSD__) || defined(__OpenBSD__) -- cgit From 3e07f63b7c13049a49f3c1bf8a436b147390ecae Mon Sep 17 00:00:00 2001 From: Shirish Kalele Date: Mon, 13 Mar 2000 17:38:13 +0000 Subject: Cleaned up call_trans2getdfsreferral for when MS_DFS is not defined. (This used to be commit 2b99318341a3f3a3ac138fe96ad271726bf1552c) --- source3/smbd/quotas.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 145 insertions(+), 2 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index badc0562bc..329f261f27 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -30,6 +30,17 @@ extern int DEBUGLEVEL; +#if defined(VXFS_QUOTA) + +/* + * In addition to their native filesystems, some systems have Veritas VxFS. + * Declare here, define at end: reduces likely "include" interaction problems. + * David Lee + */ +BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize); + +#endif /* VXFS_QUOTA */ + #ifdef LINUX #include @@ -251,7 +262,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U #if defined(SUNOS5) struct quotctl command; int file; - struct mnttab mnt; + static struct mnttab mnt; static pstring name; #else /* SunOS4 */ struct mntent *mnt; @@ -338,7 +349,18 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U if (ret < 0) { DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); - return(False); + +#if defined(SUNOS5) && defined(VXFS_QUOTA) + /* If normal quotactl() fails, try vxfs private calls */ + set_effective_uid(euser_id); + DEBUG(5,("disk_quotas: mount type \"%s\"\n", mnt.mnt_fstype)); + if ( 0 == strcmp ( mnt.mnt_fstype, "vxfs" )) { + ret = disk_quotas_vxfs(name, path, bsize, dfree, dsize); + return(ret); + } +#else + return(False); +#endif } @@ -659,3 +681,124 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U } #endif + +#if defined(VXFS_QUOTA) + +/**************************************************************************** +Try to get the disk space from Veritas disk quotas. + David Lee August 1999. + +Background assumptions: + Potentially under many Operating Systems. Initially Solaris 2. + + My guess is that Veritas is largely, though not entirely, + independent of OS. So I have separated it out. + + There may be some details. For example, OS-specific "include" files. + + It is understood that HPUX 10 somehow gets Veritas quotas without + any special effort; if so, this routine need not be compiled in. + Dirk De Wachter + +Warning: + It is understood that Veritas do not publicly support this ioctl interface. + Rather their preference would be for the user (us) to call the native + OS and then for the OS itself to call through to the VxFS filesystem. + Presumably HPUX 10, see above, does this. + +Hints for porting: + Add your OS to "IFLIST" below. + Get it to compile successfully: + Almost certainly "include"s require attention: see SUNOS5. + In the main code above, arrange for it to be called: see SUNOS5. + Test! + +****************************************************************************/ + +/* "IFLIST" + * This "if" is a list of ports: + * if defined(OS1) || defined(OS2) || ... + */ +#if defined(SUNOS5) + +#if defined(SUNOS5) +#include +#endif +#include +#include +#include +#include +#include + +BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +{ + uid_t user_id, euser_id; + int ret; + struct vx_dqblk D; + struct vx_quotctl quotabuf; + struct vx_genioctl genbuf; + pstring qfname; + int file; + + /* + * "name" may or may not include a trailing "/quotas". + * Arranging consistency of calling here in "quotas.c" may not be easy and + * it might be easier to examine and adjust it here. + * Fortunately, VxFS seems not to mind at present. + */ + pstrcpy(qfname, name) ; + /* pstrcat(qfname, "/quotas") ; */ /* possibly examine and adjust "name" */ + + euser_id = geteuid(); + set_effective_uid(0); + + DEBUG(5,("disk_quotas: looking for VxFS quotas file \"%s\"\n", qfname)); + if((file=sys_open(qfname, O_RDONLY,0))<0) { + set_effective_uid(euser_id); + return(False); + } + genbuf.ioc_cmd = VX_QUOTACTL; + genbuf.ioc_up = (void *) "abuf; + + quotabuf.cmd = VX_GETQUOTA; + quotabuf.uid = euser_id; + quotabuf.addr = (caddr_t) &D; + ret = ioctl(file, VX_ADMIN_IOCTL, &genbuf); + close(file); + + set_effective_uid(euser_id); + + if (ret < 0) { + DEBUG(5,("disk_quotas ioctl (VxFS) failed. Error = %s\n", strerror(errno) )); + return(False); + } + + /* Use softlimit to determine disk space. A user exceeding the quota is told + * that there's no space left. Writes might actually work for a bit if the + * hardlimit is set higher than softlimit. Effectively the disk becomes + * made of rubber latex and begins to expand to accommodate the user :-) + */ + DEBUG(5,("disk_quotas for path \"%s\" block c/s/h %ld/%ld/%ld; file c/s/h %ld/%ld/%ld\n", + path, D.dqb_curblocks, D.dqb_bsoftlimit, D.dqb_bhardlimit, + D.dqb_curfiles, D.dqb_fsoftlimit, D.dqb_fhardlimit)); + + if (D.dqb_bsoftlimit==0) + return(False); + *bsize = DEV_BSIZE; + *dsize = D.dqb_bsoftlimit; + + if (D.dqb_curblocks > D.dqb_bsoftlimit) { + *dfree = 0; + *dsize = D.dqb_curblocks; + } else + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + + DEBUG(5,("disk_quotas for path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n", + path,(double)*bsize,(double)*dfree,(double)*dsize)); + + return(True); +} + +#endif /* SUNOS5 || ... */ + +#endif /* VXFS_QUOTA */ -- cgit From 4379d359a8cdcc5b2d4ebf713a0ac32b1c7df4d2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Apr 2000 21:02:45 +0000 Subject: Fix for soft quotas not being set from Norbert Püschel Jeremy. (This used to be commit 5480ecf24bc7c97f25a5a6aee7e24eba7e87a458) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source3/smbd/quotas.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 329f261f27..1e81443c5e 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -363,6 +363,11 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U #endif } + /* If softlimit is zero, set it equal to hardlimit. + */ + + if (D.dqb_bsoftlimit==0) + D.dqb_bsoftlimit = D.dqb_bhardlimit; /* Use softlimit to determine disk space. A user exceeding the quota is told * that there's no space left. Writes might actually work for a bit if the @@ -432,6 +437,12 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U return (False); } + /* If softlimit is zero, set it equal to hardlimit. + */ + + if (D.dqb_bsoftlimit==0) + D.dqb_bsoftlimit = D.dqb_bhardlimit; + /* Use softlimit to determine disk space, except when it has been exceeded */ if (D.dqb_bsoftlimit==0) @@ -662,6 +673,13 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U } else return(False); } + + /* If softlimit is zero, set it equal to hardlimit. + */ + + if (D.dqb_bsoftlimit==0) + D.dqb_bsoftlimit = D.dqb_bhardlimit; + if (D.dqb_bsoftlimit==0) return(False); /* Use softlimit to determine disk space, except when it has been exceeded */ @@ -773,6 +791,12 @@ BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_B return(False); } + /* If softlimit is zero, set it equal to hardlimit. + */ + + if (D.dqb_bsoftlimit==0) + D.dqb_bsoftlimit = D.dqb_bhardlimit; + /* Use softlimit to determine disk space. A user exceeding the quota is told * that there's no space left. Writes might actually work for a bit if the * hardlimit is set higher than softlimit. Effectively the disk becomes -- cgit From 7e9736703cba8a1d6378b1c089fd5dc865a7a303 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Mon, 4 Dec 2000 17:16:44 +0000 Subject: Remove C++ style comments (This used to be commit 80c192244fdb07e8e9cf4c0376bbea60dde244a0) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 1e81443c5e..9bbc027cf7 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -427,7 +427,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U if (r) { - if (save_errno == EDQUOT) // disk quota exceeded + if (save_errno == EDQUOT) /* disk quota exceeded */ { *dfree = 0; *dsize = D.dqb_curblocks; -- cgit From 8e99021e65f2d358b2ffc89e31bc2499c9b74690 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Feb 2001 21:46:01 +0000 Subject: Fixes from Toomas Soome code unicode problems, plus a solaris quota update fix. Jeremy. (This used to be commit 9efd7a778b7b172d76af922c3dda8ec31d74bd7d) --- source3/smbd/quotas.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 9bbc027cf7..7808d269f9 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -244,6 +244,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U #if defined(SUNOS5) #include #include +#include #else /* defined(SUNOS4) */ #include #include @@ -264,6 +265,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U int file; static struct mnttab mnt; static pstring name; + pstring devopt; #else /* SunOS4 */ struct mntent *mnt; static pstring name; @@ -272,7 +274,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U SMB_STRUCT_STAT sbuf; SMB_DEV_T devno ; static SMB_DEV_T devno_cached = 0 ; - int found ; + static int found ; euser_id = geteuid(); @@ -280,7 +282,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U return(False) ; devno = sbuf.st_dev ; - DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%o\n", path,devno)); + DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", path,devno)); if ( devno != devno_cached ) { devno_cached = devno ; #if defined(SUNOS5) @@ -288,12 +290,17 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U return(False) ; found = False ; + slprintf(devopt, sizeof(devopt) - 1, "dev=%x", devno); while (getmntent(fd, &mnt) == 0) { - if ( sys_stat(mnt.mnt_mountp,&sbuf) == -1 ) - continue ; - DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", - mnt.mnt_mountp,sbuf.st_dev)); - if (sbuf.st_dev == devno) { + if( !hasmntopt(&mnt, devopt) ) + continue; + + DEBUG(5,("disk_quotas: testing \"%s\" %s\n", mnt.mnt_mountp,devopt)); + + /* quotas are only on vxfs, UFS or NFS, but nfs is not supported here */ + if ( strcmp( mnt.mnt_fstype, MNTTYPE_UFS ) == 0 || + strcmp( mnt.mnt_fstype, "vxfs" ) == 0 ) + { found = True ; break ; } @@ -322,10 +329,11 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U endmntent(fd) ; #endif - if ( ! found ) - return(False) ; } + if ( ! found ) + return(False) ; + save_re_uid(); set_effective_uid(0); -- cgit From 303c152f03c5cb4a8872673b548a7ee4caae2eb3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Mar 2001 02:43:34 +0000 Subject: Added NFS quota support for Solaris 5.x from Alan Romeril . sun1.samba.org is down at the moment so I can't test the compile on this. I'm sure Solaris people using quotas will scream if I've meesed anything up :-). Jeremy. (This used to be commit 3d2c59bfe0bc30d8cecf0af81b74d4232b09bdb2) --- source3/smbd/quotas.c | 391 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 279 insertions(+), 112 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 7808d269f9..57d7e36f10 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -250,6 +250,166 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U #include #endif +#if defined(SUNOS5) + +/**************************************************************************** + Allows querying of remote hosts for quotas on NFS mounted shares. + Supports normal NFS and AMD mounts. + Alan Romeril July 2K. +****************************************************************************/ + +#include +#include +#include +#include +#include + +static int quotastat; + +static int xdr_getquota_args(XDR *xdrsp, struct getquota_args *args) +{ + if (!xdr_string(xdrsp, &args->gqa_pathp, RQ_PATHLEN )) + return(0); + if (!xdr_int(xdrsp, &args->gqa_uid)) + return(0); + return (1); +} + +static int xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) +{ + gqr_status status; + union { + rquota gqr_rquota; + } getquota_rslt_u; + + if (!xdr_int(xdrsp, "astat)) { + DEBUG(6,("nfs_quotas: Status bad or zero\n")); + return 0; + } + if (!xdr_int32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsize)) { + DEBUG(6,("nfs_quotas: Block size bad or zero\n")); + return 0; + } + if (!xdr_bool(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_active)) { + DEBUG(6,("nfs_quotas: Active bad or zero\n")); + return 0; + } + if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bhardlimit)) { + DEBUG(6,("nfs_quotas: Hardlimit bad or zero\n")); + return 0; + } + if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsoftlimit)) { + DEBUG(6,("nfs_quotas: Softlimit bad or zero\n")); + return 0; + } + if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_curblocks)) { + DEBUG(6,("nfs_quotas: Currentblocks bad or zero\n")); + return 0; + } + return (1); +} + +/* Restricted to SUNOS5 for the moment, I haven`t access to others to test. */ +static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +{ + uid_t uid = euser_id; + struct dqblk D; + char *mnttype = nfspath; + CLIENT *clnt; + struct getquota_rslt gqr; + struct getquota_args args; + char *cutstr, *pathname, *host, *testpath; + int len; + static struct timeval timeout = {2,0}; + enum clnt_stat clnt_stat; + + len=strcspn(mnttype, ":"); + pathname=strstr(mnttype, ":"); + cutstr = (char *) malloc(sizeof(char) * len ); + if (!cutstr) + return False; + + host = strncat(cutstr,mnttype, sizeof(char) * len ); + DEBUG(5,("nfs_quotas: looking for mount on \"%s\"\n", cutstr)); + DEBUG(5,("nfs_quotas: of path \"%s\"\n", mnttype)); + testpath=strchr(mnttype, ':'); + args.gqa_pathp = testpath+1; + args.gqa_uid = uid; + + DEBUG(5,("nfs_quotas: Asking for host \"%s\" rpcprog \"%i\" rpcvers \"%i\" +network \"%s\"\n", host, RQUOTAPROG, RQUOTAVERS, "udp")); + + if ((clnt = clnt_create(host, RQUOTAPROG, RQUOTAVERS, "udp")) != NULL) { + clnt->cl_auth = authunix_create_default(); + DEBUG(9,("nfs_quotas: auth_success\n")); + + clnt_stat=clnt_call(clnt, RQUOTAPROC_GETQUOTA, xdr_getquota_args, (caddr_t)&args, + xdr_getquota_rslt, (caddr_t)&gqr, timeout); + if (clnt_stat == RPC_SUCCESS) + DEBUG(9,("nfs_quotas: rpccall_success\n")); + }; + + + /* + * quotastat returns 0 if the rpc call fails, 1 if quotas exist, 2 if there is + * no quota set, and 3 if no permission to get the quota. If 0 or 3 return + * something sensible. + */ + + if (quotastat == 1) { + DEBUG(9,("nfs_quotas: Good quota data\n")); + D.dqb_bsoftlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bsoftlimit; + D.dqb_bhardlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bhardlimit; + D.dqb_curblocks = gqr.getquota_rslt_u.gqr_rquota.rq_curblocks; + } + + if (quotastat == 0 || quotastat == 3) { + D.dqb_bsoftlimit = 1; + D.dqb_curblocks = 1; + DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", quotastat )); + } + + if (quotastat == 2) { + DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", quotastat )); + auth_destroy(clnt->cl_auth); + clnt_destroy(clnt); + free(cutstr); + return(False); + } + + DEBUG(10,("nfs_quotas: Let`s look at D a bit closer... status \"%i\" bsize \"%i\" active? \"%i\" \ +bhard \"%i\" bsoft \"%i\" curb \"%i\" \n", + quotastat, + gqr.getquota_rslt_u.gqr_rquota.rq_bsize, + gqr.getquota_rslt_u.gqr_rquota.rq_active, + gqr.getquota_rslt_u.gqr_rquota.rq_bhardlimit, + gqr.getquota_rslt_u.gqr_rquota.rq_bsoftlimit, + gqr.getquota_rslt_u.gqr_rquota.rq_curblocks)); + + *bsize = gqr.getquota_rslt_u.gqr_rquota.rq_bsize; + *dsize = D.dqb_bsoftlimit; + + if (D.dqb_curblocks == D.dqb_curblocks == 1) + *bsize = 512; + + if (D.dqb_curblocks > D.dqb_bsoftlimit) { + *dfree = 0; + *dsize = D.dqb_curblocks; + } else + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + + auth_destroy(clnt->cl_auth); + clnt_destroy(clnt); + + DEBUG(5,("nfs_quotas: For path \"%s\" returning bsize %.0f, dfree %.0f, dsize \ +%.0f\n",args.gqa_pathp,(double)*bsize,(double)*dfree,(double)*dsize)); + + free(cutstr); + DEBUG(10,("nfs_quotas: End of nfs_quotas\n" )); + return(True); +} +#endif + /**************************************************************************** try to get the disk space from disk quotas (SunOS & Solaris2 version) Quota code by Peter Urbanec (amiga@cse.unsw.edu.au). @@ -257,147 +417,154 @@ Quota code by Peter Urbanec (amiga@cse.unsw.edu.au). BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { - uid_t euser_id; - int ret; - struct dqblk D; + uid_t euser_id; + int ret; + struct dqblk D; #if defined(SUNOS5) - struct quotctl command; - int file; - static struct mnttab mnt; - static pstring name; - pstring devopt; + struct quotctl command; + int file; + static struct mnttab mnt; + static pstring name; + pstring devopt; #else /* SunOS4 */ - struct mntent *mnt; - static pstring name; + struct mntent *mnt; + static pstring name; #endif - FILE *fd; - SMB_STRUCT_STAT sbuf; - SMB_DEV_T devno ; - static SMB_DEV_T devno_cached = 0 ; - static int found ; + FILE *fd; + SMB_STRUCT_STAT sbuf; + SMB_DEV_T devno ; + static SMB_DEV_T devno_cached = 0 ; + static int found ; - euser_id = geteuid(); + euser_id = geteuid(); - if ( sys_stat(path,&sbuf) == -1 ) - return(False) ; + if ( sys_stat(path,&sbuf) == -1 ) + return(False) ; - devno = sbuf.st_dev ; - DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", path,devno)); - if ( devno != devno_cached ) { - devno_cached = devno ; + devno = sbuf.st_dev ; + DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", path,devno)); + if ( devno != devno_cached ) { + devno_cached = devno ; #if defined(SUNOS5) - if ((fd = sys_fopen(MNTTAB, "r")) == NULL) - return(False) ; + if ((fd = sys_fopen(MNTTAB, "r")) == NULL) + return(False) ; - found = False ; - slprintf(devopt, sizeof(devopt) - 1, "dev=%x", devno); - while (getmntent(fd, &mnt) == 0) { - if( !hasmntopt(&mnt, devopt) ) - continue; - - DEBUG(5,("disk_quotas: testing \"%s\" %s\n", mnt.mnt_mountp,devopt)); - - /* quotas are only on vxfs, UFS or NFS, but nfs is not supported here */ - if ( strcmp( mnt.mnt_fstype, MNTTYPE_UFS ) == 0 || - strcmp( mnt.mnt_fstype, "vxfs" ) == 0 ) - { - found = True ; - break ; - } - } + found = False ; + slprintf(devopt, sizeof(devopt) - 1, "dev=%x", devno); + while (getmntent(fd, &mnt) == 0) { + if( !hasmntopt(&mnt, devopt) ) + continue; + + DEBUG(5,("disk_quotas: testing \"%s\" %s\n", mnt.mnt_mountp,devopt)); + + /* quotas are only on vxfs, UFS or NFS */ + if ( strcmp( mnt.mnt_fstype, MNTTYPE_UFS ) == 0 || + strcmp( mnt.mnt_fstype, "nfs" ) == 0 ) || + strcmp( mnt.mnt_fstype, "vxfs" ) == 0 ) { + found = True ; + break; + } + } - pstrcpy(name,mnt.mnt_mountp) ; - pstrcat(name,"/quotas") ; - fclose(fd) ; + pstrcpy(name,mnt.mnt_mountp) ; + pstrcat(name,"/quotas") ; + fclose(fd) ; #else /* SunOS4 */ - if ((fd = setmntent(MOUNTED, "r")) == NULL) - return(False) ; + if ((fd = setmntent(MOUNTED, "r")) == NULL) + return(False) ; - found = False ; - while ((mnt = getmntent(fd)) != NULL) { - if ( sys_stat(mnt->mnt_dir,&sbuf) == -1 ) - continue ; - DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", - mnt->mnt_dir,sbuf.st_dev)); - if (sbuf.st_dev == devno) { - found = True ; - break ; - } - } + found = False ; + while ((mnt = getmntent(fd)) != NULL) { + if ( sys_stat(mnt->mnt_dir,&sbuf) == -1 ) + continue ; + DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt->mnt_dir,sbuf.st_dev)); + if (sbuf.st_dev == devno) { + found = True ; + break; + } + } - pstrcpy(name,mnt->mnt_fsname) ; - endmntent(fd) ; + pstrcpy(name,mnt->mnt_fsname) ; + endmntent(fd) ; #endif - - } + } - if ( ! found ) - return(False) ; + if ( ! found ) + return(False) ; - save_re_uid(); - set_effective_uid(0); + save_re_uid(); + set_effective_uid(0); #if defined(SUNOS5) - DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); - if((file=sys_open(name, O_RDONLY,0))<0) { - restore_re_uid(); - return(False); - } - command.op = Q_GETQUOTA; - command.uid = euser_id; - command.addr = (caddr_t) &D; - ret = ioctl(file, Q_QUOTACTL, &command); - close(file); + if ( strcmp( mnt.mnt_fstype, "nfs" ) == 0) { + BOOL retval; + DEBUG(5,("disk_quotas: looking for mountpath (NFS) \"%s\"\n", mnt.mnt_special)); + retval = nfs_quotas(mnt.mnt_special, euser_id, bsize, dfree, dsize); + restore_re_uid(); + return retval; + } + + DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); + if((file=sys_open(name, O_RDONLY,0))<0) { + restore_re_uid(); + return(False); + } + command.op = Q_GETQUOTA; + command.uid = euser_id; + command.addr = (caddr_t) &D; + ret = ioctl(file, Q_QUOTACTL, &command); + close(file); #else - DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name)); - ret = quotactl(Q_GETQUOTA, name, euser_id, &D); + DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name)); + ret = quotactl(Q_GETQUOTA, name, euser_id, &D); #endif - restore_re_uid(); + restore_re_uid(); - if (ret < 0) { - DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); + if (ret < 0) { + DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); #if defined(SUNOS5) && defined(VXFS_QUOTA) - /* If normal quotactl() fails, try vxfs private calls */ - set_effective_uid(euser_id); - DEBUG(5,("disk_quotas: mount type \"%s\"\n", mnt.mnt_fstype)); - if ( 0 == strcmp ( mnt.mnt_fstype, "vxfs" )) { - ret = disk_quotas_vxfs(name, path, bsize, dfree, dsize); - return(ret); - } + /* If normal quotactl() fails, try vxfs private calls */ + set_effective_uid(euser_id); + DEBUG(5,("disk_quotas: mount type \"%s\"\n", mnt.mnt_fstype)); + if ( 0 == strcmp ( mnt.mnt_fstype, "vxfs" )) { + BOOL retval; + retval = disk_quotas_vxfs(name, path, bsize, dfree, dsize); + return(retval); + } #else - return(False); + return(False); #endif - } + } - /* If softlimit is zero, set it equal to hardlimit. - */ + /* If softlimit is zero, set it equal to hardlimit. + */ - if (D.dqb_bsoftlimit==0) - D.dqb_bsoftlimit = D.dqb_bhardlimit; - - /* Use softlimit to determine disk space. A user exceeding the quota is told - * that there's no space left. Writes might actually work for a bit if the - * hardlimit is set higher than softlimit. Effectively the disk becomes - * made of rubber latex and begins to expand to accommodate the user :-) - */ - - if (D.dqb_bsoftlimit==0) - return(False); - *bsize = DEV_BSIZE; - *dsize = D.dqb_bsoftlimit; - - if (D.dqb_curblocks > D.dqb_bsoftlimit) { - *dfree = 0; - *dsize = D.dqb_curblocks; - } else - *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + if (D.dqb_bsoftlimit==0) + D.dqb_bsoftlimit = D.dqb_bhardlimit; + + /* Use softlimit to determine disk space. A user exceeding the quota is told + * that there's no space left. Writes might actually work for a bit if the + * hardlimit is set higher than softlimit. Effectively the disk becomes + * made of rubber latex and begins to expand to accommodate the user :-) + */ + + if (D.dqb_bsoftlimit==0) + return(False); + *bsize = DEV_BSIZE; + *dsize = D.dqb_bsoftlimit; + + if (D.dqb_curblocks > D.dqb_bsoftlimit) { + *dfree = 0; + *dsize = D.dqb_curblocks; + } else + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; - DEBUG(5,("disk_quotas for path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n", - path,(double)*bsize,(double)*dfree,(double)*dsize)); + DEBUG(5,("disk_quotas for path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n", + path,(double)*bsize,(double)*dfree,(double)*dsize)); - return(True); + return(True); } -- cgit From c3eb491c9233c37c5d96cb6712ed8ccea1bd606c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Mar 2001 08:08:04 +0000 Subject: Removed NFS quotas code for Solaris as Alan wants to re-write it. Jeremy. (This used to be commit 13c9823eb19baa4b1262ad0fd416d9ecbc92b160) --- source3/smbd/quotas.c | 391 +++++++++++++++----------------------------------- 1 file changed, 112 insertions(+), 279 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 57d7e36f10..7808d269f9 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -250,166 +250,6 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U #include #endif -#if defined(SUNOS5) - -/**************************************************************************** - Allows querying of remote hosts for quotas on NFS mounted shares. - Supports normal NFS and AMD mounts. - Alan Romeril July 2K. -****************************************************************************/ - -#include -#include -#include -#include -#include - -static int quotastat; - -static int xdr_getquota_args(XDR *xdrsp, struct getquota_args *args) -{ - if (!xdr_string(xdrsp, &args->gqa_pathp, RQ_PATHLEN )) - return(0); - if (!xdr_int(xdrsp, &args->gqa_uid)) - return(0); - return (1); -} - -static int xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) -{ - gqr_status status; - union { - rquota gqr_rquota; - } getquota_rslt_u; - - if (!xdr_int(xdrsp, "astat)) { - DEBUG(6,("nfs_quotas: Status bad or zero\n")); - return 0; - } - if (!xdr_int32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsize)) { - DEBUG(6,("nfs_quotas: Block size bad or zero\n")); - return 0; - } - if (!xdr_bool(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_active)) { - DEBUG(6,("nfs_quotas: Active bad or zero\n")); - return 0; - } - if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bhardlimit)) { - DEBUG(6,("nfs_quotas: Hardlimit bad or zero\n")); - return 0; - } - if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsoftlimit)) { - DEBUG(6,("nfs_quotas: Softlimit bad or zero\n")); - return 0; - } - if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_curblocks)) { - DEBUG(6,("nfs_quotas: Currentblocks bad or zero\n")); - return 0; - } - return (1); -} - -/* Restricted to SUNOS5 for the moment, I haven`t access to others to test. */ -static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) -{ - uid_t uid = euser_id; - struct dqblk D; - char *mnttype = nfspath; - CLIENT *clnt; - struct getquota_rslt gqr; - struct getquota_args args; - char *cutstr, *pathname, *host, *testpath; - int len; - static struct timeval timeout = {2,0}; - enum clnt_stat clnt_stat; - - len=strcspn(mnttype, ":"); - pathname=strstr(mnttype, ":"); - cutstr = (char *) malloc(sizeof(char) * len ); - if (!cutstr) - return False; - - host = strncat(cutstr,mnttype, sizeof(char) * len ); - DEBUG(5,("nfs_quotas: looking for mount on \"%s\"\n", cutstr)); - DEBUG(5,("nfs_quotas: of path \"%s\"\n", mnttype)); - testpath=strchr(mnttype, ':'); - args.gqa_pathp = testpath+1; - args.gqa_uid = uid; - - DEBUG(5,("nfs_quotas: Asking for host \"%s\" rpcprog \"%i\" rpcvers \"%i\" -network \"%s\"\n", host, RQUOTAPROG, RQUOTAVERS, "udp")); - - if ((clnt = clnt_create(host, RQUOTAPROG, RQUOTAVERS, "udp")) != NULL) { - clnt->cl_auth = authunix_create_default(); - DEBUG(9,("nfs_quotas: auth_success\n")); - - clnt_stat=clnt_call(clnt, RQUOTAPROC_GETQUOTA, xdr_getquota_args, (caddr_t)&args, - xdr_getquota_rslt, (caddr_t)&gqr, timeout); - if (clnt_stat == RPC_SUCCESS) - DEBUG(9,("nfs_quotas: rpccall_success\n")); - }; - - - /* - * quotastat returns 0 if the rpc call fails, 1 if quotas exist, 2 if there is - * no quota set, and 3 if no permission to get the quota. If 0 or 3 return - * something sensible. - */ - - if (quotastat == 1) { - DEBUG(9,("nfs_quotas: Good quota data\n")); - D.dqb_bsoftlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bsoftlimit; - D.dqb_bhardlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bhardlimit; - D.dqb_curblocks = gqr.getquota_rslt_u.gqr_rquota.rq_curblocks; - } - - if (quotastat == 0 || quotastat == 3) { - D.dqb_bsoftlimit = 1; - D.dqb_curblocks = 1; - DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", quotastat )); - } - - if (quotastat == 2) { - DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", quotastat )); - auth_destroy(clnt->cl_auth); - clnt_destroy(clnt); - free(cutstr); - return(False); - } - - DEBUG(10,("nfs_quotas: Let`s look at D a bit closer... status \"%i\" bsize \"%i\" active? \"%i\" \ -bhard \"%i\" bsoft \"%i\" curb \"%i\" \n", - quotastat, - gqr.getquota_rslt_u.gqr_rquota.rq_bsize, - gqr.getquota_rslt_u.gqr_rquota.rq_active, - gqr.getquota_rslt_u.gqr_rquota.rq_bhardlimit, - gqr.getquota_rslt_u.gqr_rquota.rq_bsoftlimit, - gqr.getquota_rslt_u.gqr_rquota.rq_curblocks)); - - *bsize = gqr.getquota_rslt_u.gqr_rquota.rq_bsize; - *dsize = D.dqb_bsoftlimit; - - if (D.dqb_curblocks == D.dqb_curblocks == 1) - *bsize = 512; - - if (D.dqb_curblocks > D.dqb_bsoftlimit) { - *dfree = 0; - *dsize = D.dqb_curblocks; - } else - *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; - - auth_destroy(clnt->cl_auth); - clnt_destroy(clnt); - - DEBUG(5,("nfs_quotas: For path \"%s\" returning bsize %.0f, dfree %.0f, dsize \ -%.0f\n",args.gqa_pathp,(double)*bsize,(double)*dfree,(double)*dsize)); - - free(cutstr); - DEBUG(10,("nfs_quotas: End of nfs_quotas\n" )); - return(True); -} -#endif - /**************************************************************************** try to get the disk space from disk quotas (SunOS & Solaris2 version) Quota code by Peter Urbanec (amiga@cse.unsw.edu.au). @@ -417,154 +257,147 @@ Quota code by Peter Urbanec (amiga@cse.unsw.edu.au). BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { - uid_t euser_id; - int ret; - struct dqblk D; + uid_t euser_id; + int ret; + struct dqblk D; #if defined(SUNOS5) - struct quotctl command; - int file; - static struct mnttab mnt; - static pstring name; - pstring devopt; + struct quotctl command; + int file; + static struct mnttab mnt; + static pstring name; + pstring devopt; #else /* SunOS4 */ - struct mntent *mnt; - static pstring name; + struct mntent *mnt; + static pstring name; #endif - FILE *fd; - SMB_STRUCT_STAT sbuf; - SMB_DEV_T devno ; - static SMB_DEV_T devno_cached = 0 ; - static int found ; + FILE *fd; + SMB_STRUCT_STAT sbuf; + SMB_DEV_T devno ; + static SMB_DEV_T devno_cached = 0 ; + static int found ; - euser_id = geteuid(); + euser_id = geteuid(); - if ( sys_stat(path,&sbuf) == -1 ) - return(False) ; + if ( sys_stat(path,&sbuf) == -1 ) + return(False) ; - devno = sbuf.st_dev ; - DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", path,devno)); - if ( devno != devno_cached ) { - devno_cached = devno ; + devno = sbuf.st_dev ; + DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", path,devno)); + if ( devno != devno_cached ) { + devno_cached = devno ; #if defined(SUNOS5) - if ((fd = sys_fopen(MNTTAB, "r")) == NULL) - return(False) ; + if ((fd = sys_fopen(MNTTAB, "r")) == NULL) + return(False) ; - found = False ; - slprintf(devopt, sizeof(devopt) - 1, "dev=%x", devno); - while (getmntent(fd, &mnt) == 0) { - if( !hasmntopt(&mnt, devopt) ) - continue; - - DEBUG(5,("disk_quotas: testing \"%s\" %s\n", mnt.mnt_mountp,devopt)); - - /* quotas are only on vxfs, UFS or NFS */ - if ( strcmp( mnt.mnt_fstype, MNTTYPE_UFS ) == 0 || - strcmp( mnt.mnt_fstype, "nfs" ) == 0 ) || - strcmp( mnt.mnt_fstype, "vxfs" ) == 0 ) { - found = True ; - break; - } - } + found = False ; + slprintf(devopt, sizeof(devopt) - 1, "dev=%x", devno); + while (getmntent(fd, &mnt) == 0) { + if( !hasmntopt(&mnt, devopt) ) + continue; + + DEBUG(5,("disk_quotas: testing \"%s\" %s\n", mnt.mnt_mountp,devopt)); + + /* quotas are only on vxfs, UFS or NFS, but nfs is not supported here */ + if ( strcmp( mnt.mnt_fstype, MNTTYPE_UFS ) == 0 || + strcmp( mnt.mnt_fstype, "vxfs" ) == 0 ) + { + found = True ; + break ; + } + } - pstrcpy(name,mnt.mnt_mountp) ; - pstrcat(name,"/quotas") ; - fclose(fd) ; + pstrcpy(name,mnt.mnt_mountp) ; + pstrcat(name,"/quotas") ; + fclose(fd) ; #else /* SunOS4 */ - if ((fd = setmntent(MOUNTED, "r")) == NULL) - return(False) ; + if ((fd = setmntent(MOUNTED, "r")) == NULL) + return(False) ; - found = False ; - while ((mnt = getmntent(fd)) != NULL) { - if ( sys_stat(mnt->mnt_dir,&sbuf) == -1 ) - continue ; - DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt->mnt_dir,sbuf.st_dev)); - if (sbuf.st_dev == devno) { - found = True ; - break; - } - } + found = False ; + while ((mnt = getmntent(fd)) != NULL) { + if ( sys_stat(mnt->mnt_dir,&sbuf) == -1 ) + continue ; + DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", + mnt->mnt_dir,sbuf.st_dev)); + if (sbuf.st_dev == devno) { + found = True ; + break ; + } + } - pstrcpy(name,mnt->mnt_fsname) ; - endmntent(fd) ; + pstrcpy(name,mnt->mnt_fsname) ; + endmntent(fd) ; #endif - } + + } - if ( ! found ) - return(False) ; + if ( ! found ) + return(False) ; - save_re_uid(); - set_effective_uid(0); + save_re_uid(); + set_effective_uid(0); #if defined(SUNOS5) - if ( strcmp( mnt.mnt_fstype, "nfs" ) == 0) { - BOOL retval; - DEBUG(5,("disk_quotas: looking for mountpath (NFS) \"%s\"\n", mnt.mnt_special)); - retval = nfs_quotas(mnt.mnt_special, euser_id, bsize, dfree, dsize); - restore_re_uid(); - return retval; - } - - DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); - if((file=sys_open(name, O_RDONLY,0))<0) { - restore_re_uid(); - return(False); - } - command.op = Q_GETQUOTA; - command.uid = euser_id; - command.addr = (caddr_t) &D; - ret = ioctl(file, Q_QUOTACTL, &command); - close(file); + DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); + if((file=sys_open(name, O_RDONLY,0))<0) { + restore_re_uid(); + return(False); + } + command.op = Q_GETQUOTA; + command.uid = euser_id; + command.addr = (caddr_t) &D; + ret = ioctl(file, Q_QUOTACTL, &command); + close(file); #else - DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name)); - ret = quotactl(Q_GETQUOTA, name, euser_id, &D); + DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name)); + ret = quotactl(Q_GETQUOTA, name, euser_id, &D); #endif - restore_re_uid(); + restore_re_uid(); - if (ret < 0) { - DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); + if (ret < 0) { + DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); #if defined(SUNOS5) && defined(VXFS_QUOTA) - /* If normal quotactl() fails, try vxfs private calls */ - set_effective_uid(euser_id); - DEBUG(5,("disk_quotas: mount type \"%s\"\n", mnt.mnt_fstype)); - if ( 0 == strcmp ( mnt.mnt_fstype, "vxfs" )) { - BOOL retval; - retval = disk_quotas_vxfs(name, path, bsize, dfree, dsize); - return(retval); - } + /* If normal quotactl() fails, try vxfs private calls */ + set_effective_uid(euser_id); + DEBUG(5,("disk_quotas: mount type \"%s\"\n", mnt.mnt_fstype)); + if ( 0 == strcmp ( mnt.mnt_fstype, "vxfs" )) { + ret = disk_quotas_vxfs(name, path, bsize, dfree, dsize); + return(ret); + } #else - return(False); + return(False); #endif - } + } - /* If softlimit is zero, set it equal to hardlimit. - */ + /* If softlimit is zero, set it equal to hardlimit. + */ - if (D.dqb_bsoftlimit==0) - D.dqb_bsoftlimit = D.dqb_bhardlimit; - - /* Use softlimit to determine disk space. A user exceeding the quota is told - * that there's no space left. Writes might actually work for a bit if the - * hardlimit is set higher than softlimit. Effectively the disk becomes - * made of rubber latex and begins to expand to accommodate the user :-) - */ - - if (D.dqb_bsoftlimit==0) - return(False); - *bsize = DEV_BSIZE; - *dsize = D.dqb_bsoftlimit; - - if (D.dqb_curblocks > D.dqb_bsoftlimit) { - *dfree = 0; - *dsize = D.dqb_curblocks; - } else - *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + if (D.dqb_bsoftlimit==0) + D.dqb_bsoftlimit = D.dqb_bhardlimit; + + /* Use softlimit to determine disk space. A user exceeding the quota is told + * that there's no space left. Writes might actually work for a bit if the + * hardlimit is set higher than softlimit. Effectively the disk becomes + * made of rubber latex and begins to expand to accommodate the user :-) + */ + + if (D.dqb_bsoftlimit==0) + return(False); + *bsize = DEV_BSIZE; + *dsize = D.dqb_bsoftlimit; + + if (D.dqb_curblocks > D.dqb_bsoftlimit) { + *dfree = 0; + *dsize = D.dqb_curblocks; + } else + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; - DEBUG(5,("disk_quotas for path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n", - path,(double)*bsize,(double)*dfree,(double)*dsize)); + DEBUG(5,("disk_quotas for path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n", + path,(double)*bsize,(double)*dfree,(double)*dsize)); - return(True); + return(True); } -- cgit From f439f72ceec665dbd1eae367eb5d7302d8a3338d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 1 Apr 2001 19:00:43 +0000 Subject: Integrated solaris nfs quota code from Alan Romeril Jeremy (This used to be commit 181d41572ceb17dc765d3c0f1a05934e35f56a61) --- source3/smbd/quotas.c | 387 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 275 insertions(+), 112 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 7808d269f9..75e27f356a 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -250,6 +250,162 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U #include #endif +#if defined(SUNOS5) + +/**************************************************************************** + Allows querying of remote hosts for quotas on NFS mounted shares. + Supports normal NFS and AMD mounts. + Alan Romeril July 2K. +****************************************************************************/ + +#include +#include +#include +#include +#include + +static int quotastat; + +static int xdr_getquota_args(XDR *xdrsp, struct getquota_args *args) +{ + if (!xdr_string(xdrsp, &args->gqa_pathp, RQ_PATHLEN )) + return(0); + if (!xdr_int(xdrsp, &args->gqa_uid)) + return(0); + return (1); +} + +static int xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) +{ + gqr_status status; + union { + rquota gqr_rquota; + } getquota_rslt_u; + + if (!xdr_int(xdrsp, "astat)) { + DEBUG(6,("nfs_quotas: Status bad or zero\n")); + return 0; + } + if (!xdr_int32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsize)) { + DEBUG(6,("nfs_quotas: Block size bad or zero\n")); + return 0; + } + if (!xdr_bool(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_active)) { + DEBUG(6,("nfs_quotas: Active bad or zero\n")); + return 0; + } + if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bhardlimit)) { + DEBUG(6,("nfs_quotas: Hardlimit bad or zero\n")); + return 0; + } + if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsoftlimit)) { + DEBUG(6,("nfs_quotas: Softlimit bad or zero\n")); + return 0; + } + if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_curblocks)) { + DEBUG(6,("nfs_quotas: Currentblocks bad or zero\n")); + return 0; + } + return (1); +} + +/* Restricted to SUNOS5 for the moment, I haven`t access to others to test. */ +static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +{ + uid_t uid = euser_id; + struct dqblk D; + char *mnttype = nfspath; + CLIENT *clnt; + struct getquota_rslt gqr; + struct getquota_args args; + char *cutstr, *pathname, *host, *testpath; + int len; + static struct timeval timeout = {2,0}; + enum clnt_stat clnt_stat; + + len=strcspn(mnttype, ":"); + pathname=strstr(mnttype, ":"); + cutstr = (char *) malloc(sizeof(char) * len ); + if (!cutstr) + return False; + + host = strncat(cutstr,mnttype, sizeof(char) * len ); + DEBUG(5,("nfs_quotas: looking for mount on \"%s\"\n", cutstr)); + DEBUG(5,("nfs_quotas: of path \"%s\"\n", mnttype)); + testpath=strchr(mnttype, ':'); + args.gqa_pathp = testpath+1; + args.gqa_uid = uid; + + DEBUG(5,("nfs_quotas: Asking for host \"%s\" rpcprog \"%i\" rpcvers \"%i\" network \"%s\"\n", host, RQUOTAPROG, RQUOTAVERS, "udp")); + + if ((clnt = clnt_create(host, RQUOTAPROG, RQUOTAVERS, "udp")) != NULL) { + clnt->cl_auth = authunix_create_default(); + DEBUG(9,("nfs_quotas: auth_success\n")); + + clnt_stat=clnt_call(clnt, RQUOTAPROC_GETQUOTA, xdr_getquota_args, (caddr_t)&args, xdr_getquota_rslt, (caddr_t)&gqr, timeout); + if (clnt_stat == RPC_SUCCESS) + DEBUG(9,("nfs_quotas: rpccall_success\n")); + }; + + + /* + * quotastat returns 0 if the rpc call fails, 1 if quotas exist, 2 if there is + * no quota set, and 3 if no permission to get the quota. If 0 or 3 return + * something sensible. + */ + + if (quotastat == 1) { + DEBUG(9,("nfs_quotas: Good quota data\n")); + D.dqb_bsoftlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bsoftlimit; + D.dqb_bhardlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bhardlimit; + D.dqb_curblocks = gqr.getquota_rslt_u.gqr_rquota.rq_curblocks; + } + + if (quotastat == 0 || quotastat == 3) { + D.dqb_bsoftlimit = 1; + D.dqb_curblocks = 1; + DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", quotastat )); + } + + if (quotastat == 2) { + DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", quotastat )); + auth_destroy(clnt->cl_auth); + clnt_destroy(clnt); + free(cutstr); + return(False); + } + + DEBUG(10,("nfs_quotas: Let`s look at D a bit closer... status \"%i\" bsize \"%i\" active? \"%i\" bhard \"%i\" bsoft \"%i\" curb \"%i\" \n", + quotastat, + gqr.getquota_rslt_u.gqr_rquota.rq_bsize, + gqr.getquota_rslt_u.gqr_rquota.rq_active, + gqr.getquota_rslt_u.gqr_rquota.rq_bhardlimit, + gqr.getquota_rslt_u.gqr_rquota.rq_bsoftlimit, + gqr.getquota_rslt_u.gqr_rquota.rq_curblocks)); + + *bsize = gqr.getquota_rslt_u.gqr_rquota.rq_bsize; + *dsize = D.dqb_bsoftlimit; + + if (D.dqb_curblocks == D.dqb_curblocks == 1) + *bsize = 512; + + if (D.dqb_curblocks > D.dqb_bsoftlimit) { + *dfree = 0; + *dsize = D.dqb_curblocks; + } else + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + + auth_destroy(clnt->cl_auth); + clnt_destroy(clnt); + + DEBUG(5,("nfs_quotas: For path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n",args.gqa_pathp,(double)*bsize,(double)*dfree,(double)*dsize)); + + free(cutstr); + DEBUG(10,("nfs_quotas: End of nfs_quotas\n" )); + return(True); +} +#endif + /**************************************************************************** try to get the disk space from disk quotas (SunOS & Solaris2 version) Quota code by Peter Urbanec (amiga@cse.unsw.edu.au). @@ -257,147 +413,154 @@ Quota code by Peter Urbanec (amiga@cse.unsw.edu.au). BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { - uid_t euser_id; - int ret; - struct dqblk D; + uid_t euser_id; + int ret; + struct dqblk D; #if defined(SUNOS5) - struct quotctl command; - int file; - static struct mnttab mnt; - static pstring name; - pstring devopt; + struct quotctl command; + int file; + static struct mnttab mnt; + static pstring name; + pstring devopt; #else /* SunOS4 */ - struct mntent *mnt; - static pstring name; + struct mntent *mnt; + static pstring name; #endif - FILE *fd; - SMB_STRUCT_STAT sbuf; - SMB_DEV_T devno ; - static SMB_DEV_T devno_cached = 0 ; - static int found ; + FILE *fd; + SMB_STRUCT_STAT sbuf; + SMB_DEV_T devno ; + static SMB_DEV_T devno_cached = 0 ; + static int found ; - euser_id = geteuid(); + euser_id = geteuid(); - if ( sys_stat(path,&sbuf) == -1 ) - return(False) ; + if ( sys_stat(path,&sbuf) == -1 ) + return(False) ; - devno = sbuf.st_dev ; - DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", path,devno)); - if ( devno != devno_cached ) { - devno_cached = devno ; + devno = sbuf.st_dev ; + DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", path,devno)); + if ( devno != devno_cached ) { + devno_cached = devno ; #if defined(SUNOS5) - if ((fd = sys_fopen(MNTTAB, "r")) == NULL) - return(False) ; + if ((fd = sys_fopen(MNTTAB, "r")) == NULL) + return(False) ; - found = False ; - slprintf(devopt, sizeof(devopt) - 1, "dev=%x", devno); - while (getmntent(fd, &mnt) == 0) { - if( !hasmntopt(&mnt, devopt) ) - continue; - - DEBUG(5,("disk_quotas: testing \"%s\" %s\n", mnt.mnt_mountp,devopt)); - - /* quotas are only on vxfs, UFS or NFS, but nfs is not supported here */ - if ( strcmp( mnt.mnt_fstype, MNTTYPE_UFS ) == 0 || - strcmp( mnt.mnt_fstype, "vxfs" ) == 0 ) - { - found = True ; - break ; - } - } + found = False ; + slprintf(devopt, sizeof(devopt) - 1, "dev=%x", devno); + while (getmntent(fd, &mnt) == 0) { + if( !hasmntopt(&mnt, devopt) ) + continue; + + DEBUG(5,("disk_quotas: testing \"%s\" %s\n", mnt.mnt_mountp,devopt)); + + /* quotas are only on vxfs, UFS or NFS */ + if ( strcmp( mnt.mnt_fstype, MNTTYPE_UFS ) == 0 || + strcmp( mnt.mnt_fstype, "nfs" ) == 0 || + strcmp( mnt.mnt_fstype, "vxfs" ) == 0 ) { + found = True ; + break; + } + } - pstrcpy(name,mnt.mnt_mountp) ; - pstrcat(name,"/quotas") ; - fclose(fd) ; + pstrcpy(name,mnt.mnt_mountp) ; + pstrcat(name,"/quotas") ; + fclose(fd) ; #else /* SunOS4 */ - if ((fd = setmntent(MOUNTED, "r")) == NULL) - return(False) ; + if ((fd = setmntent(MOUNTED, "r")) == NULL) + return(False) ; - found = False ; - while ((mnt = getmntent(fd)) != NULL) { - if ( sys_stat(mnt->mnt_dir,&sbuf) == -1 ) - continue ; - DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", - mnt->mnt_dir,sbuf.st_dev)); - if (sbuf.st_dev == devno) { - found = True ; - break ; - } - } + found = False ; + while ((mnt = getmntent(fd)) != NULL) { + if ( sys_stat(mnt->mnt_dir,&sbuf) == -1 ) + continue ; + DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt->mnt_dir,sbuf.st_dev)); + if (sbuf.st_dev == devno) { + found = True ; + break; + } + } - pstrcpy(name,mnt->mnt_fsname) ; - endmntent(fd) ; + pstrcpy(name,mnt->mnt_fsname) ; + endmntent(fd) ; #endif - - } + } - if ( ! found ) - return(False) ; + if ( ! found ) + return(False) ; - save_re_uid(); - set_effective_uid(0); + save_re_uid(); + set_effective_uid(0); #if defined(SUNOS5) - DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); - if((file=sys_open(name, O_RDONLY,0))<0) { - restore_re_uid(); - return(False); - } - command.op = Q_GETQUOTA; - command.uid = euser_id; - command.addr = (caddr_t) &D; - ret = ioctl(file, Q_QUOTACTL, &command); - close(file); + if ( strcmp( mnt.mnt_fstype, "nfs" ) == 0) { + BOOL retval; + DEBUG(5,("disk_quotas: looking for mountpath (NFS) \"%s\"\n", mnt.mnt_special)); + retval = nfs_quotas(mnt.mnt_special, euser_id, bsize, dfree, dsize); + restore_re_uid(); + return retval; + } + + DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); + if((file=sys_open(name, O_RDONLY,0))<0) { + restore_re_uid(); + return(False); + } + command.op = Q_GETQUOTA; + command.uid = euser_id; + command.addr = (caddr_t) &D; + ret = ioctl(file, Q_QUOTACTL, &command); + close(file); #else - DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name)); - ret = quotactl(Q_GETQUOTA, name, euser_id, &D); + DEBUG(5,("disk_quotas: trying quotactl on device \"%s\"\n", name)); + ret = quotactl(Q_GETQUOTA, name, euser_id, &D); #endif - restore_re_uid(); + restore_re_uid(); - if (ret < 0) { - DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); + if (ret < 0) { + DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); #if defined(SUNOS5) && defined(VXFS_QUOTA) - /* If normal quotactl() fails, try vxfs private calls */ - set_effective_uid(euser_id); - DEBUG(5,("disk_quotas: mount type \"%s\"\n", mnt.mnt_fstype)); - if ( 0 == strcmp ( mnt.mnt_fstype, "vxfs" )) { - ret = disk_quotas_vxfs(name, path, bsize, dfree, dsize); - return(ret); - } + /* If normal quotactl() fails, try vxfs private calls */ + set_effective_uid(euser_id); + DEBUG(5,("disk_quotas: mount type \"%s\"\n", mnt.mnt_fstype)); + if ( 0 == strcmp ( mnt.mnt_fstype, "vxfs" )) { + BOOL retval; + retval = disk_quotas_vxfs(name, path, bsize, dfree, dsize); + return(retval); + } #else - return(False); + return(False); #endif - } + } - /* If softlimit is zero, set it equal to hardlimit. - */ + /* If softlimit is zero, set it equal to hardlimit. + */ - if (D.dqb_bsoftlimit==0) - D.dqb_bsoftlimit = D.dqb_bhardlimit; - - /* Use softlimit to determine disk space. A user exceeding the quota is told - * that there's no space left. Writes might actually work for a bit if the - * hardlimit is set higher than softlimit. Effectively the disk becomes - * made of rubber latex and begins to expand to accommodate the user :-) - */ - - if (D.dqb_bsoftlimit==0) - return(False); - *bsize = DEV_BSIZE; - *dsize = D.dqb_bsoftlimit; - - if (D.dqb_curblocks > D.dqb_bsoftlimit) { - *dfree = 0; - *dsize = D.dqb_curblocks; - } else - *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + if (D.dqb_bsoftlimit==0) + D.dqb_bsoftlimit = D.dqb_bhardlimit; + + /* Use softlimit to determine disk space. A user exceeding the quota is told + * that there's no space left. Writes might actually work for a bit if the + * hardlimit is set higher than softlimit. Effectively the disk becomes + * made of rubber latex and begins to expand to accommodate the user :-) + */ + + if (D.dqb_bsoftlimit==0) + return(False); + *bsize = DEV_BSIZE; + *dsize = D.dqb_bsoftlimit; + + if (D.dqb_curblocks > D.dqb_bsoftlimit) { + *dfree = 0; + *dsize = D.dqb_curblocks; + } else + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; - DEBUG(5,("disk_quotas for path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n", - path,(double)*bsize,(double)*dfree,(double)*dsize)); + DEBUG(5,("disk_quotas for path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n", + path,(double)*bsize,(double)*dfree,(double)*dsize)); - return(True); + return(True); } -- cgit From 5d609165969c5b06aed581b1a21d7b7b0dca9430 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 5 Apr 2001 20:46:15 +0000 Subject: Fix from "Romeril, Alan" to get his NFS quota code to work on Solaris 2.6. Jeremy. (This used to be commit bd2fe239db24b8b3fa6a906542af2e238f435331) --- source3/smbd/quotas.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 75e27f356a..ccb5534641 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -278,15 +278,15 @@ static int xdr_getquota_args(XDR *xdrsp, struct getquota_args *args) static int xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) { gqr_status status; - union { + union { rquota gqr_rquota; } getquota_rslt_u; - + if (!xdr_int(xdrsp, "astat)) { DEBUG(6,("nfs_quotas: Status bad or zero\n")); return 0; } - if (!xdr_int32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsize)) { + if (!xdr_int(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsize)) { DEBUG(6,("nfs_quotas: Block size bad or zero\n")); return 0; } @@ -294,15 +294,15 @@ static int xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) DEBUG(6,("nfs_quotas: Active bad or zero\n")); return 0; } - if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bhardlimit)) { + if (!xdr_int(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bhardlimit)) { DEBUG(6,("nfs_quotas: Hardlimit bad or zero\n")); return 0; } - if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsoftlimit)) { + if (!xdr_int(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsoftlimit)) { DEBUG(6,("nfs_quotas: Softlimit bad or zero\n")); return 0; } - if (!xdr_uint32_t(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_curblocks)) { + if (!xdr_int(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_curblocks)) { DEBUG(6,("nfs_quotas: Currentblocks bad or zero\n")); return 0; } -- cgit From 8f88c7cf4e2029be8b38ee9052dc12e90efcc8d7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Apr 2001 19:56:15 +0000 Subject: Fixes for problems in NFS server code from Michael Gerdts . Jeremy. (This used to be commit 2fd5e0bf141807d31f6f1a817d271548d0ccfadc) --- source3/smbd/quotas.c | 64 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 23 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index ccb5534641..81da013cec 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -322,6 +322,9 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B int len; static struct timeval timeout = {2,0}; enum clnt_stat clnt_stat; + BOOL ret = True; + + *bsize = *dfree = *dsize = (SMB_BIG_UINT)0; len=strcspn(mnttype, ":"); pathname=strstr(mnttype, ":"); @@ -338,15 +341,21 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B DEBUG(5,("nfs_quotas: Asking for host \"%s\" rpcprog \"%i\" rpcvers \"%i\" network \"%s\"\n", host, RQUOTAPROG, RQUOTAVERS, "udp")); - if ((clnt = clnt_create(host, RQUOTAPROG, RQUOTAVERS, "udp")) != NULL) { - clnt->cl_auth = authunix_create_default(); - DEBUG(9,("nfs_quotas: auth_success\n")); + if ((clnt = clnt_create(host, RQUOTAPROG, RQUOTAVERS, "udp")) == NULL) { + ret = False; + goto out; + } - clnt_stat=clnt_call(clnt, RQUOTAPROC_GETQUOTA, xdr_getquota_args, (caddr_t)&args, xdr_getquota_rslt, (caddr_t)&gqr, timeout); - if (clnt_stat == RPC_SUCCESS) - DEBUG(9,("nfs_quotas: rpccall_success\n")); - }; + clnt->cl_auth = authunix_create_default(); + DEBUG(9,("nfs_quotas: auth_success\n")); + clnt_stat=clnt_call(clnt, RQUOTAPROC_GETQUOTA, xdr_getquota_args, (caddr_t)&args, xdr_getquota_rslt, (caddr_t)&gqr, timeout); + + if (clnt_stat != RPC_SUCCESS) { + DEBUG(9,("nfs_quotas: clnt_call fail\n")); + ret = False; + goto out; + } /* * quotastat returns 0 if the rpc call fails, 1 if quotas exist, 2 if there is @@ -354,26 +363,30 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B * something sensible. */ - if (quotastat == 1) { + switch ( quotastat ) { + case 0: + DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", quotastat )); + ret = False; + goto out; + + case 1: DEBUG(9,("nfs_quotas: Good quota data\n")); D.dqb_bsoftlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bsoftlimit; D.dqb_bhardlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bhardlimit; D.dqb_curblocks = gqr.getquota_rslt_u.gqr_rquota.rq_curblocks; - } + break; - if (quotastat == 0 || quotastat == 3) { + case 2: + case 3: D.dqb_bsoftlimit = 1; D.dqb_curblocks = 1; - DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", quotastat )); - } + DEBUG(9,("nfs_quotas: Remote Quotas returned \"%i\" \n", quotastat )); + break; - if (quotastat == 2) { - DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", quotastat )); - auth_destroy(clnt->cl_auth); - clnt_destroy(clnt); - free(cutstr); - return(False); - } + default: + DEBUG(9,("nfs_quotas: Remote Quotas Questionable! Error \"%i\" \n", quotastat )); + break; + } DEBUG(10,("nfs_quotas: Let`s look at D a bit closer... status \"%i\" bsize \"%i\" active? \"%i\" bhard \"%i\" bsoft \"%i\" curb \"%i\" \n", quotastat, @@ -395,14 +408,19 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B } else *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; - auth_destroy(clnt->cl_auth); - clnt_destroy(clnt); + out: + + if (clnt) { + if (clnt->cl_auth) + auth_destroy(clnt->cl_auth); + clnt_destroy(clnt); + } DEBUG(5,("nfs_quotas: For path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n",args.gqa_pathp,(double)*bsize,(double)*dfree,(double)*dsize)); - free(cutstr); + safe_free(cutstr); DEBUG(10,("nfs_quotas: End of nfs_quotas\n" )); - return(True); + return ret; } #endif -- cgit From c11887e3257c8dfe650f5004106a43a891ab4b31 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Apr 2001 22:17:10 +0000 Subject: More debug %d -> %u issues. Jeremy. (This used to be commit 6fcb600dcd23c61d1a7d2ce8c2b7b2eea2e58623) --- source3/smbd/quotas.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 81da013cec..caf3997ba8 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -277,11 +277,6 @@ static int xdr_getquota_args(XDR *xdrsp, struct getquota_args *args) static int xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) { - gqr_status status; - union { - rquota gqr_rquota; - } getquota_rslt_u; - if (!xdr_int(xdrsp, "astat)) { DEBUG(6,("nfs_quotas: Status bad or zero\n")); return 0; @@ -456,7 +451,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U return(False) ; devno = sbuf.st_dev ; - DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", path,devno)); + DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", path,(unsigned int)devno)); if ( devno != devno_cached ) { devno_cached = devno ; #if defined(SUNOS5) @@ -464,7 +459,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U return(False) ; found = False ; - slprintf(devopt, sizeof(devopt) - 1, "dev=%x", devno); + slprintf(devopt, sizeof(devopt) - 1, "dev=%x", (unsigned int)devno); while (getmntent(fd, &mnt) == 0) { if( !hasmntopt(&mnt, devopt) ) continue; @@ -491,7 +486,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U while ((mnt = getmntent(fd)) != NULL) { if ( sys_stat(mnt->mnt_dir,&sbuf) == -1 ) continue ; - DEBUG(5,("disk_quotas: testing \"%s\" devno=%o\n", mnt->mnt_dir,sbuf.st_dev)); + DEBUG(5,("disk_quotas: testing \"%s\" devno=%x\n", mnt->mnt_dir,(unsigned int)sbuf.st_dev)); if (sbuf.st_dev == devno) { found = True ; break; -- cgit From 527e824293ee934ca5da0ef5424efe5ab7757248 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:36:09 +0000 Subject: strchr and strrchr are macros when compiling with optimisation in gcc, so we can't redefine them. damn. (This used to be commit c41fc06376d1a2b83690612304e85010b5e5f3cf) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index caf3997ba8..5d82756f24 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -330,7 +330,7 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B host = strncat(cutstr,mnttype, sizeof(char) * len ); DEBUG(5,("nfs_quotas: looking for mount on \"%s\"\n", cutstr)); DEBUG(5,("nfs_quotas: of path \"%s\"\n", mnttype)); - testpath=strchr(mnttype, ':'); + testpath=strchr_m(mnttype, ':'); args.gqa_pathp = testpath+1; args.gqa_uid = uid; -- cgit From 61b2794968faa35dc91edce17e9b91e5366c3514 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 11:25:41 +0000 Subject: move to SAFE_FREE() (This used to be commit a95943fde0ad89ae3f2deca2f7ba9cb5ab612b74) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 5d82756f24..3ef04b0692 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -413,7 +413,7 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B DEBUG(5,("nfs_quotas: For path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n",args.gqa_pathp,(double)*bsize,(double)*dfree,(double)*dsize)); - safe_free(cutstr); + SAFE_FREE(cutstr); DEBUG(10,("nfs_quotas: End of nfs_quotas\n" )); return ret; } -- cgit From d76dfbb879dc49cb03742f6ed184eb5ef5b75002 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 21 Sep 2001 22:06:03 +0000 Subject: Attempt to make quotas work with RH7.1, and with other Linuxen... This is *HARD*, dammit ! Jeremy. (This used to be commit 59a4684201fb72989698db5ac8169bd8880bd9a7) --- source3/smbd/quotas.c | 193 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 125 insertions(+), 68 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 3ef04b0692..cf21fd7043 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -45,12 +45,72 @@ BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_B #include #include -#include + +/* + * This shouldn't be neccessary - it should be /usr/include/sys/quota.h + * Unfortunately, RH7.1 ships with a different quota system using struct mem_dqblk + * rather than the struct dqblk defined in /usr/include/sys/quota.h. + * This means we must include linux/quota.h to have a hope of working on + * RH7.1 systems. And it also means this breaks if the kernel is upgraded + * to a Linus 2.4.x (where x > the minor number shipped with RH7.1) until + * Linus synchronises with the AC patches. Sometimes I *hate* Linux :-). JRA. + */ + +#include #include #include -_syscall4(int, quotactl, int, cmd, const char *, special, int, id, caddr_t, addr); + +#define LINUX_QUOTAS_2 + +typedef struct _LINUX_SMB_DISK_QUOTA { + SMB_BIG_UINT bsize; + SMB_BIG_UINT hardlimit; /* In bsize units. */ + SMB_BIG_UINT softlimit; /* In bsize units. */ + SMB_BIG_UINT curblocks; /* In bsize units. */ + SMB_BIG_UINT ihardlimit; /* inode hard limit. */ + SMB_BIG_UINT isoftlimit; /* inode soft limit. */ + SMB_BIG_UINT curinodes; /* Current used inodes. */ +} LINUX_SMB_DISK_QUOTA; + +/**************************************************************************** + Abstract out the old and new Linux quota get calls. +****************************************************************************/ + +static int get_smb_linux_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QUOTA *dp) +{ + int ret; +#ifdef LINUX_QUOTAS_1 + struct dqblk D; + ZERO_STRUCT(D); + dp->bsize = (SMB_BIG_UINT)1024; +#else /* LINUX_QUOTAS_2 */ + struct mem_dqblk D; + ZERO_STRUCT(D); +#ifndef QUOTABLOCK_SIZE +#define QUOTABLOCK_SIZE 1024 +#endif + dp->bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE; +#endif + + if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D))) + return -1; + + dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit; + dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit; + dp->ihardlimit = (SMB_BIG_UINT)D.dqb_ihardlimit; + dp->isoftlimit = (SMB_BIG_UINT)D.dqb_isoftlimit; + dp->curinodes = (SMB_BIG_UINT)D.dqb_curinodes; + +#ifdef LINUX_QUOTAS_1 + dp->curblocks = (SMB_BIG_UINT)D.dqb_curblocks; +#else /* LINUX_QUOTAS_2 */ + dp->curblocks = ((SMB_BIG_UINT)D.dqb_curspace)/ dp->bsize; +#endif + + return 0; +} /**************************************************************************** try to get the disk space from disk quotas (LINUX version) @@ -58,81 +118,78 @@ try to get the disk space from disk quotas (LINUX version) BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { - int r; - struct dqblk D; - SMB_STRUCT_STAT S; - FILE *fp; - struct mntent *mnt; - SMB_DEV_T devno; - int found; - uid_t euser_id; + int r; + SMB_STRUCT_STAT S; + FILE *fp; + LINUX_SMB_DISK_QUOTA D; + struct mntent *mnt; + SMB_DEV_T devno; + int found; + uid_t euser_id; - euser_id = geteuid(); + euser_id = geteuid(); - /* find the block device file */ + /* find the block device file */ - if ( sys_stat(path, &S) == -1 ) { - return(False) ; - } + if ( sys_stat(path, &S) == -1 ) + return(False) ; - devno = S.st_dev ; + devno = S.st_dev ; - fp = setmntent(MOUNTED,"r"); - found = False ; + fp = setmntent(MOUNTED,"r"); + found = False ; - while ((mnt = getmntent(fp))) { - if ( sys_stat(mnt->mnt_dir,&S) == -1 ) - continue ; - if (S.st_dev == devno) { - found = True ; - break ; - } - } - endmntent(fp) ; + while ((mnt = getmntent(fp))) { + if ( sys_stat(mnt->mnt_dir,&S) == -1 ) + continue ; + + if (S.st_dev == devno) { + found = True ; + break; + } + } + + endmntent(fp) ; - if (!found) { - return(False); - } + if (!found) + return(False); - save_re_uid(); - set_effective_uid(0); - r=quotactl(QCMD(Q_GETQUOTA,USRQUOTA), mnt->mnt_fsname, euser_id, (caddr_t)&D); - restore_re_uid(); + save_re_uid(); + set_effective_uid(0); + r=get_smb_linux_quota(mnt->mnt_fsname, euser_id, &D); + restore_re_uid(); - /* Use softlimit to determine disk space, except when it has been exceeded */ - *bsize = 1024; - if (r) - { - if (errno == EDQUOT) - { - *dfree =0; - *dsize =D.dqb_curblocks; - return (True); - } - else return(False); - } - /* Use softlimit to determine disk space, except when it has been exceeded */ - if ( - (D.dqb_bsoftlimit && D.dqb_curblocks>=D.dqb_bsoftlimit) || - (D.dqb_bhardlimit && D.dqb_curblocks>=D.dqb_bhardlimit) || - (D.dqb_isoftlimit && D.dqb_curinodes>=D.dqb_isoftlimit) || - (D.dqb_ihardlimit && D.dqb_curinodes>=D.dqb_ihardlimit) - ) - { - *dfree = 0; - *dsize = D.dqb_curblocks; - } - else if (D.dqb_bsoftlimit==0 && D.dqb_bhardlimit==0) - { - return(False); - } - else { - if (D.dqb_bsoftlimit == 0) - D.dqb_bsoftlimit = D.dqb_bhardlimit; - *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; - *dsize = D.dqb_bsoftlimit; - } - return (True); + /* Use softlimit to determine disk space, except when it has been exceeded */ + *bsize = D.bsize; + if (r == -1) { + if (errno == EDQUOT) { + *dfree =0; + *dsize =D.curblocks; + return (True); + } else { + return(False); + } + } + + /* Use softlimit to determine disk space, except when it has been exceeded */ + if ( + (D.softlimit && D.curblocks >= D.softlimit) || + (D.hardlimit && D.curblocks >= D.hardlimit) || + (D.isoftlimit && D.curinodes >= D.isoftlimit) || + (D.ihardlimit && D.curinodes>=D.ihardlimit) + ) { + *dfree = 0; + *dsize = D.curblocks; + } else if (D.softlimit==0 && D.hardlimit==0) { + return(False); + } else { + if (D.softlimit == 0) + D.softlimit = D.hardlimit; + *dfree = D.softlimit - D.curblocks; + *dsize = D.softlimit; + } + + return (True); } #elif defined(CRAY) -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/smbd/quotas.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index cf21fd7043..76d1124aea 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -28,8 +28,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - #if defined(VXFS_QUOTA) /* -- cgit From f8e2baf39eb864481dd48f61404136b325cd73c2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2001 23:34:24 +0000 Subject: Added NT_USER_TOKEN into server_info to fix extra groups problem. Got "medieval on our ass" about const warnings (as many as I could :-). Jeremy. (This used to be commit ee5e7ca547eff016818ba5c43b8ea0c9fa69b808) --- source3/smbd/quotas.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 76d1124aea..96670a985d 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -114,7 +114,7 @@ static int get_smb_linux_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QUOTA try to get the disk space from disk quotas (LINUX version) ****************************************************************************/ -BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { int r; SMB_STRUCT_STAT S; @@ -199,7 +199,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U try to get the disk space from disk quotas (CRAY VERSION) ****************************************************************************/ -BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { struct mntent *mnt; FILE *fd; @@ -479,7 +479,7 @@ try to get the disk space from disk quotas (SunOS & Solaris2 version) Quota code by Peter Urbanec (amiga@cse.unsw.edu.au). ****************************************************************************/ -BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t euser_id; int ret; @@ -639,7 +639,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U try to get the disk space from disk quotas - OSF1 version ****************************************************************************/ -BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { int r, save_errno; struct dqblk D; @@ -705,7 +705,7 @@ try to get the disk space from disk quotas (IRIX 6.2 version) #include #include -BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t euser_id; int r; @@ -843,7 +843,7 @@ BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_U try to get the disk space from disk quotas - default version ****************************************************************************/ -BOOL disk_quotas(char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { int r; struct dqblk D; -- cgit From a9750b20061ed0862754459120043f341a1b8f50 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Nov 2001 21:50:02 +0000 Subject: XFS quota patch for Linux. Jeremy. (This used to be commit ce099faf6ce07e14bd9610960bd09f56c5bee864) --- source3/smbd/quotas.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 96670a985d..73391e6c0d 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -55,6 +55,9 @@ BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_B */ #include +#ifdef HAVE_LINUX_XQM_H +#include +#endif #include #include @@ -72,11 +75,36 @@ typedef struct _LINUX_SMB_DISK_QUOTA { SMB_BIG_UINT curinodes; /* Current used inodes. */ } LINUX_SMB_DISK_QUOTA; +/**************************************************************************** + Abstract out the XFS Quota Manager quota get call. +****************************************************************************/ + +static int get_smb_linux_xfs_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QUOTA *dp) +{ + int ret = -1; +#ifdef HAVE_LINUX_XQM_H + struct fs_disk_quota D; + ZERO_STRUCT(D); + + if ((ret = quotactl(QCMD(Q_XGETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D))) + return ret; + + dp->bsize = (SMB_BIG_UINT)512; + dp->softlimit = (SMB_BIG_UINT)D.d_blk_softlimit; + dp->hardlimit = (SMB_BIG_UINT)D.d_blk_hardlimit; + dp->ihardlimit = (SMB_BIG_UINT)D.d_ino_hardlimit; + dp->isoftlimit = (SMB_BIG_UINT)D.d_ino_softlimit; + dp->curinodes = (SMB_BIG_UINT)D.d_icount; + dp->curblocks = (SMB_BIG_UINT)D.d_bcount; +#endif + return ret; +} + /**************************************************************************** Abstract out the old and new Linux quota get calls. ****************************************************************************/ -static int get_smb_linux_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QUOTA *dp) +static int get_smb_linux_vfs_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QUOTA *dp) { int ret; #ifdef LINUX_QUOTAS_1 @@ -154,7 +182,10 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB save_re_uid(); set_effective_uid(0); - r=get_smb_linux_quota(mnt->mnt_fsname, euser_id, &D); + if (strcmp(mnt->mnt_type, "xfs") == 0) + r=get_smb_linux_xfs_quota(mnt->mnt_fsname, euser_id, &D); + else + r=get_smb_linux_vfs_quota(mnt->mnt_fsname, euser_id, &D); restore_re_uid(); /* Use softlimit to determine disk space, except when it has been exceeded */ -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/smbd/quotas.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 73391e6c0d..39cb8f2432 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. support for quotas Copyright (C) Andrew Tridgell 1992-1998 -- cgit From 7cfe3919f3703eb5aad838b34ceba472865cf081 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 13 Nov 2002 21:54:31 +0000 Subject: small patch to makesure we fallback to if doesn't exist (e.g. in SuSE 8.1) (by Metze) (This used to be commit da8794afe8ca8f454937f06d1c43cc5d844b6037) --- source3/smbd/quotas.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 39cb8f2432..90fd4bbdac 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -56,6 +56,11 @@ BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_B #include #ifdef HAVE_LINUX_XQM_H #include +#else +#ifdef HAVE_XFS_XQM_H +#include +#define HAVE_LINUX_XQM_H +#endif #endif #include -- cgit From db56e6f8f0520547dc9cedcf76120fe404f20a16 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 28 Jan 2003 02:15:11 +0000 Subject: performance patch from HP-UX folks (cant remember who) (This used to be commit d6c22e693efee88c17f1f0f6c861e7101b3fec99) --- source3/smbd/quotas.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 90fd4bbdac..9d3bfe2d64 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -886,10 +886,21 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB #if !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) char dev_disk[256]; SMB_STRUCT_STAT S; + /* find the block device file */ - if ((sys_stat(path, &S)<0) || - (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 0)<0)) return (False); -#endif + +#ifdef HPUX + /* Need to set the cache flag to 1 for HPUX. Seems + * to have a significant performance boost when + * lstat calls on /dev access this function. + */ + if ((sys_stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 1)<0)) +#else + if ((sys_stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 0)<0)) + return (False); +#endif /* ifdef HPUX */ + +#endif /* !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) */ euser_id = geteuid(); -- cgit From 71708c9c077704f7aeadd2abf2b543f4dbec1b40 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Mar 2003 18:10:27 +0000 Subject: Fix up zero termination. Spotted by Sebastian Krahmer . Jeremy. (This used to be commit 289e2e25b91da20ac02b90e5a9d6de3619ad308d) --- source3/smbd/quotas.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 9d3bfe2d64..c2f001423e 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -413,10 +413,11 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B len=strcspn(mnttype, ":"); pathname=strstr(mnttype, ":"); - cutstr = (char *) malloc(sizeof(char) * len ); + cutstr = (char *) malloc(len+1); if (!cutstr) return False; + memset(cutstr, '\0', len+1); host = strncat(cutstr,mnttype, sizeof(char) * len ); DEBUG(5,("nfs_quotas: looking for mount on \"%s\"\n", cutstr)); DEBUG(5,("nfs_quotas: of path \"%s\"\n", mnttype)); -- cgit From bac83636a5993dbcd1c0beefd628044771603523 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 1 May 2003 11:02:54 +0000 Subject: Fix disk quotas support on HP/UX (patch by David Nixon) (This used to be commit a2c315dea6910e3f83ba2e9bad4312cf35f608da) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index c2f001423e..5b843bd09a 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -898,8 +898,8 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB if ((sys_stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 1)<0)) #else if ((sys_stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 0)<0)) - return (False); #endif /* ifdef HPUX */ + return (False); #endif /* !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) */ -- cgit From e8573c8fa928602fd979d5ac45c692e7464f0aad Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Mon, 12 May 2003 01:20:17 +0000 Subject: Add NT quota support. Patch from Stefan (metze) Metzemacher 1. Allows to change quota settings for shared mount points from Win2K and WinXP from Explorer properties tab 2. Disabled by default and when requested, will be probed and enabled only on Linux where it works 3. Was tested for approx. two weeks now on Linux by two independent QA teams, have not found any bugs so far Documentation to follow (This used to be commit 4bf022ce9e45be85609426762ba2644ac2031326) --- source3/smbd/quotas.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 5b843bd09a..0163120ee5 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -27,6 +27,10 @@ #include "includes.h" +#ifndef HAVE_SYS_QUOTAS + +#ifdef WITH_QUOTAS + #if defined(VXFS_QUOTA) /* @@ -1112,3 +1116,108 @@ BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_B #endif /* SUNOS5 || ... */ #endif /* VXFS_QUOTA */ + +#else /* WITH_QUOTAS */ + +BOOL disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize) +{ + (*bsize) = 512; /* This value should be ignored */ + + /* And just to be sure we set some values that hopefully */ + /* will be larger that any possible real-world value */ + (*dfree) = (SMB_BIG_UINT)-1; + (*dsize) = (SMB_BIG_UINT)-1; + + /* As we have select not to use quotas, allways fail */ + return False; +} +#endif /* WITH_QUOTAS */ + +#else /* HAVE_SYS_QUOTAS */ +/* wrapper to the new sys_quota interface + this file should be removed later + */ +BOOL disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize) +{ + int r; + SMB_DISK_QUOTA D; + unid_t id; + + id.uid = geteuid(); + + r=sys_get_quota(path, SMB_USER_QUOTA_TYPE, id, &D); + + /* Use softlimit to determine disk space, except when it has been exceeded */ + *bsize = D.bsize; + if (r == -1) { + if (errno == EDQUOT) { + *dfree =0; + *dsize =D.curblocks; + return (True); + } else { + goto try_group_quota; + } + } + + /* Use softlimit to determine disk space, except when it has been exceeded */ + if ( + (D.softlimit && D.curblocks >= D.softlimit) || + (D.hardlimit && D.curblocks >= D.hardlimit) || + (D.isoftlimit && D.curinodes >= D.isoftlimit) || + (D.ihardlimit && D.curinodes>=D.ihardlimit) + ) { + *dfree = 0; + *dsize = D.curblocks; + } else if (D.softlimit==0 && D.hardlimit==0) { + goto try_group_quota; + } else { + if (D.softlimit == 0) + D.softlimit = D.hardlimit; + *dfree = D.softlimit - D.curblocks; + *dsize = D.softlimit; + } + + return True; + +try_group_quota: +#ifdef HAVE_GROUP_QUOTA + id.gid = getegid(); + + r=sys_get_quota(path, SMB_GROUP_QUOTA_TYPE, id, &D); + + /* Use softlimit to determine disk space, except when it has been exceeded */ + *bsize = D.bsize; + if (r == -1) { + if (errno == EDQUOT) { + *dfree =0; + *dsize =D.curblocks; + return (True); + } else { + return False; + } + } + + /* Use softlimit to determine disk space, except when it has been exceeded */ + if ( + (D.softlimit && D.curblocks >= D.softlimit) || + (D.hardlimit && D.curblocks >= D.hardlimit) || + (D.isoftlimit && D.curinodes >= D.isoftlimit) || + (D.ihardlimit && D.curinodes>=D.ihardlimit) + ) { + *dfree = 0; + *dsize = D.curblocks; + } else if (D.softlimit==0 && D.hardlimit==0) { + return False; + } else { + if (D.softlimit == 0) + D.softlimit = D.hardlimit; + *dfree = D.softlimit - D.curblocks; + *dsize = D.softlimit; + } + + return (True); +#else /* HAVE_GROUP_QUOTA */ + return False; +#endif /* HAVE_GROUP_QUOTA */ +} +#endif /* HAVE_SYS_QUOTAS */ -- cgit From 2c01eef4d7ea9ed57ea5f68a0e75559e101fd26f Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Wed, 14 May 2003 14:38:11 +0000 Subject: Evolve quotas configure check more. Patch from Stefan (metze) Metzemacher. Now we are defaulting to --with-quotas=no but anyway trying to test them in configure. This is done to get information about as much quota API variations as possible -- when --with-quotas=no this does not affect build but provides us with more detailed information on build farm. (This used to be commit 3786695c72e6ff6a52a527382ac77142e236971b) --- source3/smbd/quotas.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 0163120ee5..91c952aa90 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -29,6 +29,11 @@ #ifndef HAVE_SYS_QUOTAS +/* just a quick hack because sysquotas.h is included before linux/quota.h */ +#ifdef QUOTABLOCK_SIZE +#undef QUOTABLOCK_SIZE +#endif + #ifdef WITH_QUOTAS #if defined(VXFS_QUOTA) -- cgit From 2d41ca7198a5a490c45a08953d16df86f36724de Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 19 Nov 2003 02:19:34 +0000 Subject: Group quotas patch from "Heinreichsberger, Helmut" Jeremy. (This used to be commit 06c9e9163010a1035f448f76c4084228dc95334f) --- source3/smbd/quotas.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 91c952aa90..46f688a219 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -94,23 +94,30 @@ typedef struct _LINUX_SMB_DISK_QUOTA { static int get_smb_linux_xfs_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QUOTA *dp) { - int ret = -1; + int ret = -1; #ifdef HAVE_LINUX_XQM_H - struct fs_disk_quota D; - ZERO_STRUCT(D); - - if ((ret = quotactl(QCMD(Q_XGETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D))) - return ret; - - dp->bsize = (SMB_BIG_UINT)512; - dp->softlimit = (SMB_BIG_UINT)D.d_blk_softlimit; - dp->hardlimit = (SMB_BIG_UINT)D.d_blk_hardlimit; - dp->ihardlimit = (SMB_BIG_UINT)D.d_ino_hardlimit; - dp->isoftlimit = (SMB_BIG_UINT)D.d_ino_softlimit; - dp->curinodes = (SMB_BIG_UINT)D.d_icount; - dp->curblocks = (SMB_BIG_UINT)D.d_bcount; + struct fs_disk_quota D; + + ZERO_STRUCT(D); + + ret = quotactl(QCMD(Q_XGETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D); + + /* As XFS has group quotas, if getting the user quota fails, try getting the group instead. */ + if (ret) { + ret = quotactl(QCMD(Q_XGETQUOTA,GRPQUOTA), path, getegid(), (caddr_t)&D); + if (ret) + return ret; + } + + dp->bsize = (SMB_BIG_UINT)512; + dp->softlimit = (SMB_BIG_UINT)D.d_blk_softlimit; + dp->hardlimit = (SMB_BIG_UINT)D.d_blk_hardlimit; + dp->ihardlimit = (SMB_BIG_UINT)D.d_ino_hardlimit; + dp->isoftlimit = (SMB_BIG_UINT)D.d_ino_softlimit; + dp->curinodes = (SMB_BIG_UINT)D.d_icount; + dp->curblocks = (SMB_BIG_UINT)D.d_bcount; #endif - return ret; + return ret; } /**************************************************************************** @@ -119,7 +126,7 @@ static int get_smb_linux_xfs_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QU static int get_smb_linux_vfs_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QUOTA *dp) { - int ret; + int ret = 0; #ifdef LINUX_QUOTAS_1 struct dqblk D; ZERO_STRUCT(D); @@ -133,8 +140,14 @@ static int get_smb_linux_vfs_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QU dp->bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE; #endif - if ((ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D))) - return -1; + ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D); + + /* Linux can have group quotas, if getting the user quota fails, try getting the group instead. */ + if (ret) { + ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), path, getegid(), (caddr_t)&D); + if (ret) + return ret; + } dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit; dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit; @@ -148,7 +161,7 @@ static int get_smb_linux_vfs_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QU dp->curblocks = ((SMB_BIG_UINT)D.dqb_curspace)/ dp->bsize; #endif - return 0; + return ret; } /**************************************************************************** -- cgit From 31876a8478fc16dc7ac62ca835714098398f56e4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 5 Jan 2004 19:36:02 +0000 Subject: Patch from Stefan (metze) Metzmacher to revert to 2.2.x quota methods. :-). "here's a patch which ports the samba 2.2 samba_linux_quota.h stuff to 3_0. This is needed because of so many broken quota files outthere. Please, test this with old, new kernels (strucr dqblk, struct mem_dqblk, and struct if_dqblk) , quota.user, aquota.user formats what is when a user is over soft quota and over hard quotas..." Jeremy. (This used to be commit 4350aa6ce6cfdaf71cdcfd2aebcdc9560fa7efcf) --- source3/smbd/quotas.c | 159 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 96 insertions(+), 63 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 46f688a219..19f225e973 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -50,33 +50,16 @@ BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_B #ifdef LINUX #include -#include +#include /* * This shouldn't be neccessary - it should be /usr/include/sys/quota.h - * Unfortunately, RH7.1 ships with a different quota system using struct mem_dqblk - * rather than the struct dqblk defined in /usr/include/sys/quota.h. - * This means we must include linux/quota.h to have a hope of working on - * RH7.1 systems. And it also means this breaks if the kernel is upgraded - * to a Linus 2.4.x (where x > the minor number shipped with RH7.1) until - * Linus synchronises with the AC patches. Sometimes I *hate* Linux :-). JRA. + * So we include all the files has *should* be in the system into a large, + * grungy samba_linux_quoatas.h Sometimes I *hate* Linux :-). JRA. */ -#include -#ifdef HAVE_LINUX_XQM_H -#include -#else -#ifdef HAVE_XFS_XQM_H -#include -#define HAVE_LINUX_XQM_H -#endif -#endif - -#include -#include - - -#define LINUX_QUOTAS_2 +#include "samba_linux_quota.h" +#include "samba_xfs_quota.h" typedef struct _LINUX_SMB_DISK_QUOTA { SMB_BIG_UINT bsize; @@ -92,22 +75,20 @@ typedef struct _LINUX_SMB_DISK_QUOTA { Abstract out the XFS Quota Manager quota get call. ****************************************************************************/ -static int get_smb_linux_xfs_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QUOTA *dp) +static int get_smb_linux_xfs_quota(char *path, uid_t euser_id, gid_t egrp_id, LINUX_SMB_DISK_QUOTA *dp) { - int ret = -1; -#ifdef HAVE_LINUX_XQM_H struct fs_disk_quota D; + int ret; ZERO_STRUCT(D); - ret = quotactl(QCMD(Q_XGETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D); + ret = quotactl(QCMD(Q_XGETQUOTA,XFS_USER_QUOTA), path, euser_id, (caddr_t)&D); - /* As XFS has group quotas, if getting the user quota fails, try getting the group instead. */ - if (ret) { - ret = quotactl(QCMD(Q_XGETQUOTA,GRPQUOTA), path, getegid(), (caddr_t)&D); - if (ret) - return ret; - } + if (ret) + ret = quotactl(QCMD(Q_XGETQUOTA,XFS_GROUP_QUOTA), path, egrp_id, (caddr_t)&D); + + if (ret) + return ret; dp->bsize = (SMB_BIG_UINT)512; dp->softlimit = (SMB_BIG_UINT)D.d_blk_softlimit; @@ -116,7 +97,7 @@ static int get_smb_linux_xfs_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QU dp->isoftlimit = (SMB_BIG_UINT)D.d_ino_softlimit; dp->curinodes = (SMB_BIG_UINT)D.d_icount; dp->curblocks = (SMB_BIG_UINT)D.d_bcount; -#endif + return ret; } @@ -124,48 +105,90 @@ static int get_smb_linux_xfs_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QU Abstract out the old and new Linux quota get calls. ****************************************************************************/ -static int get_smb_linux_vfs_quota(char *path, uid_t euser_id, LINUX_SMB_DISK_QUOTA *dp) +static int get_smb_linux_v1_quota(char *path, uid_t euser_id, gid_t egrp_id, LINUX_SMB_DISK_QUOTA *dp) { - int ret = 0; -#ifdef LINUX_QUOTAS_1 - struct dqblk D; + struct v1_kern_dqblk D; + int ret; + ZERO_STRUCT(D); - dp->bsize = (SMB_BIG_UINT)1024; -#else /* LINUX_QUOTAS_2 */ - struct mem_dqblk D; + + ret = quotactl(QCMD(Q_V1_GETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D); + + if (ret && errno != EDQUOT) + ret = quotactl(QCMD(Q_V1_GETQUOTA,GRPQUOTA), path, egrp_id, (caddr_t)&D); + + if (ret && errno != EDQUOT) + return ret; + + dp->bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE; + dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit; + dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit; + dp->ihardlimit = (SMB_BIG_UINT)D.dqb_ihardlimit; + dp->isoftlimit = (SMB_BIG_UINT)D.dqb_isoftlimit; + dp->curinodes = (SMB_BIG_UINT)D.dqb_curinodes; + dp->curblocks = (SMB_BIG_UINT)D.dqb_curblocks; + + return ret; +} + +static int get_smb_linux_v2_quota(char *path, uid_t euser_id, gid_t egrp_id, LINUX_SMB_DISK_QUOTA *dp) +{ + struct v2_kern_dqblk D; + int ret; + ZERO_STRUCT(D); -#ifndef QUOTABLOCK_SIZE -#define QUOTABLOCK_SIZE 1024 -#endif + + ret = quotactl(QCMD(Q_V2_GETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D); + + if (ret && errno != EDQUOT) + ret = quotactl(QCMD(Q_V2_GETQUOTA,GRPQUOTA), path, egrp_id, (caddr_t)&D); + + if (ret && errno != EDQUOT) + return ret; + dp->bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE; -#endif + dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit; + dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit; + dp->ihardlimit = (SMB_BIG_UINT)D.dqb_ihardlimit; + dp->isoftlimit = (SMB_BIG_UINT)D.dqb_isoftlimit; + dp->curinodes = (SMB_BIG_UINT)D.dqb_curinodes; + dp->curblocks = ((SMB_BIG_UINT)D.dqb_curspace) / dp->bsize; + + return ret; +} + +/**************************************************************************** + Brand-new generic quota interface. +****************************************************************************/ + +static int get_smb_linux_gen_quota(char *path, uid_t euser_id, gid_t egrp_id, LINUX_SMB_DISK_QUOTA *dp) +{ + struct if_dqblk D; + int ret; + + ZERO_STRUCT(D); ret = quotactl(QCMD(Q_GETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D); - /* Linux can have group quotas, if getting the user quota fails, try getting the group instead. */ - if (ret) { - ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), path, getegid(), (caddr_t)&D); - if (ret) - return ret; - } + if (ret && errno != EDQUOT) + ret = quotactl(QCMD(Q_GETQUOTA,GRPQUOTA), path, egrp_id, (caddr_t)&D); + if (ret && errno != EDQUOT) + return ret; + + dp->bsize = (SMB_BIG_UINT)QUOTABLOCK_SIZE; dp->softlimit = (SMB_BIG_UINT)D.dqb_bsoftlimit; dp->hardlimit = (SMB_BIG_UINT)D.dqb_bhardlimit; dp->ihardlimit = (SMB_BIG_UINT)D.dqb_ihardlimit; dp->isoftlimit = (SMB_BIG_UINT)D.dqb_isoftlimit; dp->curinodes = (SMB_BIG_UINT)D.dqb_curinodes; - -#ifdef LINUX_QUOTAS_1 - dp->curblocks = (SMB_BIG_UINT)D.dqb_curblocks; -#else /* LINUX_QUOTAS_2 */ - dp->curblocks = ((SMB_BIG_UINT)D.dqb_curspace)/ dp->bsize; -#endif + dp->curblocks = ((SMB_BIG_UINT)D.dqb_curspace) / dp->bsize; return ret; } /**************************************************************************** -try to get the disk space from disk quotas (LINUX version) + Try to get the disk space from disk quotas (LINUX version). ****************************************************************************/ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) @@ -178,9 +201,11 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB SMB_DEV_T devno; int found; uid_t euser_id; + gid_t egrp_id; euser_id = geteuid(); - + egrp_id = getegid(); + /* find the block device file */ if ( sys_stat(path, &S) == -1 ) @@ -208,10 +233,18 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB save_re_uid(); set_effective_uid(0); - if (strcmp(mnt->mnt_type, "xfs") == 0) - r=get_smb_linux_xfs_quota(mnt->mnt_fsname, euser_id, &D); - else - r=get_smb_linux_vfs_quota(mnt->mnt_fsname, euser_id, &D); + + if (strcmp(mnt->mnt_type, "xfs")==0) { + r=get_smb_linux_xfs_quota(mnt->mnt_fsname, euser_id, egrp_id, &D); + } else { + r=get_smb_linux_gen_quota(mnt->mnt_fsname, euser_id, egrp_id, &D); + if (r == -1 && errno != EDQUOT) { + r=get_smb_linux_v2_quota(mnt->mnt_fsname, euser_id, egrp_id, &D); + if (r == -1 && errno != EDQUOT) + r=get_smb_linux_v1_quota(mnt->mnt_fsname, euser_id, egrp_id, &D); + } + } + restore_re_uid(); /* Use softlimit to determine disk space, except when it has been exceeded */ @@ -920,8 +953,8 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB if ((sys_stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 1)<0)) #else if ((sys_stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 0)<0)) -#endif /* ifdef HPUX */ return (False); +#endif /* ifdef HPUX */ #endif /* !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) */ -- cgit From 9343c89cb4a1b9f47c38d00b12f3e9058d15b18d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 15 Jan 2004 08:49:30 +0000 Subject: * Fix XFS quotas: XFS_USER_QUOTA -> USRQUOTA XFS_GROUP_QUOTA -> GRPQUOTA * Fix disk_free calculation with group quotas. * Add debug class 'quota' and a lot of DEBUG()'s to the quota code. metze (This used to be commit e9e5e2036f13ff847aa3ef52e8be657bef7d5774) --- source3/smbd/quotas.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 19f225e973..c0b2db6173 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -27,6 +27,9 @@ #include "includes.h" +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_QUOTA + #ifndef HAVE_SYS_QUOTAS /* just a quick hack because sysquotas.h is included before linux/quota.h */ @@ -82,10 +85,10 @@ static int get_smb_linux_xfs_quota(char *path, uid_t euser_id, gid_t egrp_id, LI ZERO_STRUCT(D); - ret = quotactl(QCMD(Q_XGETQUOTA,XFS_USER_QUOTA), path, euser_id, (caddr_t)&D); + ret = quotactl(QCMD(Q_XGETQUOTA,USRQUOTA), path, euser_id, (caddr_t)&D); if (ret) - ret = quotactl(QCMD(Q_XGETQUOTA,XFS_GROUP_QUOTA), path, egrp_id, (caddr_t)&D); + ret = quotactl(QCMD(Q_XGETQUOTA,GRPQUOTA), path, egrp_id, (caddr_t)&D); if (ret) return ret; @@ -1195,7 +1198,8 @@ BOOL disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BI unid_t id; id.uid = geteuid(); - + + ZERO_STRUCT(D); r=sys_get_quota(path, SMB_USER_QUOTA_TYPE, id, &D); /* Use softlimit to determine disk space, except when it has been exceeded */ @@ -1231,9 +1235,9 @@ BOOL disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BI return True; try_group_quota: -#ifdef HAVE_GROUP_QUOTA id.gid = getegid(); - + + ZERO_STRUCT(D); r=sys_get_quota(path, SMB_GROUP_QUOTA_TYPE, id, &D); /* Use softlimit to determine disk space, except when it has been exceeded */ @@ -1267,8 +1271,5 @@ try_group_quota: } return (True); -#else /* HAVE_GROUP_QUOTA */ - return False; -#endif /* HAVE_GROUP_QUOTA */ } #endif /* HAVE_SYS_QUOTAS */ -- cgit From 9073c95b97386ad2a3d1f90bc41b735f4a53ed3d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 16 Mar 2004 19:06:03 +0000 Subject: BUG 979 -- fix quota display on AIX; patch from Heinrich.Mislik@univie.ac.at (Heinrich Mislik) (This used to be commit 760b63496ccc908c76ea5d3ed474cbbca268ad61) --- source3/smbd/quotas.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index c0b2db6173..e439c1e571 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -994,7 +994,11 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB #elif defined(AIX) /* AIX has both USER and GROUP quotas: Get the USER quota (ohnielse@fysik.dtu.dk) */ + save_re_uid(); + if (set_re_uid() != 0) + return False; r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D); + restore_re_uid(); #else /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); #endif /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ -- cgit From 7b4151e173323e6ebc05a7ccc1671ab88f4e1660 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sat, 3 Jul 2004 23:53:36 +0000 Subject: r1333: NFS Quota support from Dan Peterson. (This used to be commit 609828444d9126d8a6e8ff43e4b3c19079a9eb56) --- source3/smbd/quotas.c | 204 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 203 insertions(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index e439c1e571..3c4d4319f6 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -933,6 +933,176 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB #include #endif +#if defined(__FreeBSD__) + +#include +#include +#include +#include +#include + +static int quotastat; + +static int my_xdr_getquota_args(XDR *xdrsp, struct getquota_args *args) +{ + if (!xdr_string(xdrsp, &args->gqa_pathp, RQ_PATHLEN )) + return(0); + if (!xdr_int(xdrsp, &args->gqa_uid)) + return(0); + return (1); +} + +static int my_xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) +{ + if (!xdr_int(xdrsp, "astat)) { + DEBUG(6,("nfs_quotas: Status bad or zero\n")); + return 0; + } + if (!xdr_int(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsize)) { + DEBUG(6,("nfs_quotas: Block size bad or zero\n")); + return 0; + } + if (!xdr_bool(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_active)) { + DEBUG(6,("nfs_quotas: Active bad or zero\n")); + return 0; + } + if (!xdr_int(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bhardlimit)) { + DEBUG(6,("nfs_quotas: Hardlimit bad or zero\n")); + return 0; + } + if (!xdr_int(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_bsoftlimit)) { + DEBUG(6,("nfs_quotas: Softlimit bad or zero\n")); + return 0; + } + if (!xdr_int(xdrsp, &gqr->getquota_rslt_u.gqr_rquota.rq_curblocks)) { + DEBUG(6,("nfs_quotas: Currentblocks bad or zero\n")); + return 0; + } + return (1); +} + +/* Works on FreeBSD, too. :-) */ +static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +{ + uid_t uid = euser_id; + struct dqblk D; + char *mnttype = nfspath; + CLIENT *clnt; + struct getquota_rslt gqr; + struct getquota_args args; + char *cutstr, *pathname, *host, *testpath; + int len; + static struct timeval timeout = {2,0}; + enum clnt_stat clnt_stat; + BOOL ret = True; + + *bsize = *dfree = *dsize = (SMB_BIG_UINT)0; + + len=strcspn(mnttype, ":"); + pathname=strstr(mnttype, ":"); + cutstr = (char *) malloc(len+1); + if (!cutstr) + return False; + + memset(cutstr, '\0', len+1); + host = strncat(cutstr,mnttype, sizeof(char) * len ); + DEBUG(5,("nfs_quotas: looking for mount on \"%s\"\n", cutstr)); + DEBUG(5,("nfs_quotas: of path \"%s\"\n", mnttype)); + testpath=strchr_m(mnttype, ':'); + args.gqa_pathp = testpath+1; + args.gqa_uid = uid; + + DEBUG(5,("nfs_quotas: Asking for host \"%s\" rpcprog \"%i\" rpcvers \"%i\" network \"%s\"\n", host, RQUOTAPROG, RQUOTAVERS, "udp")); + + if ((clnt = clnt_create(host, RQUOTAPROG, RQUOTAVERS, "udp")) == NULL) { + ret = False; + goto out; + } + + clnt->cl_auth = authunix_create_default(); + DEBUG(9,("nfs_quotas: auth_success\n")); + + clnt_stat=clnt_call(clnt, RQUOTAPROC_GETQUOTA, (const xdrproc_t) my_xdr_getquota_args, (caddr_t)&args, (const xdrproc_t) my_xdr_getquota_rslt, (caddr_t)&gqr, timeout); + + if (clnt_stat != RPC_SUCCESS) { + DEBUG(9,("nfs_quotas: clnt_call fail\n")); + ret = False; + goto out; + } + + /* + * quotastat returns 0 if the rpc call fails, 1 if quotas exist, 2 if there is + * no quota set, and 3 if no permission to get the quota. If 0 or 3 return + * something sensible. + */ + + switch ( quotastat ) { + case 0: + DEBUG(9,("nfs_quotas: Remote Quotas Failed! Error \"%i\" \n", quotastat )); + ret = False; + goto out; + + case 1: + DEBUG(9,("nfs_quotas: Good quota data\n")); + D.dqb_bsoftlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bsoftlimit; + D.dqb_bhardlimit = gqr.getquota_rslt_u.gqr_rquota.rq_bhardlimit; + D.dqb_curblocks = gqr.getquota_rslt_u.gqr_rquota.rq_curblocks; + break; + + case 2: + case 3: + D.dqb_bsoftlimit = 1; + D.dqb_curblocks = 1; + DEBUG(9,("nfs_quotas: Remote Quotas returned \"%i\" \n", quotastat )); + break; + + default: + DEBUG(9,("nfs_quotas: Remote Quotas Questionable! Error \"%i\" \n", quotastat )); + break; + } + + DEBUG(10,("nfs_quotas: Let`s look at D a bit closer... status \"%i\" bsize \"%i\" active? \"%i\" bhard \"%i\" bsoft \"%i\" curb \"%i\" \n", + quotastat, + gqr.getquota_rslt_u.gqr_rquota.rq_bsize, + gqr.getquota_rslt_u.gqr_rquota.rq_active, + gqr.getquota_rslt_u.gqr_rquota.rq_bhardlimit, + gqr.getquota_rslt_u.gqr_rquota.rq_bsoftlimit, + gqr.getquota_rslt_u.gqr_rquota.rq_curblocks)); + + if (D.dqb_bsoftlimit == 0) + D.dqb_bsoftlimit = D.dqb_bhardlimit; + if (D.dqb_bsoftlimit == 0) + return False; + + *bsize = gqr.getquota_rslt_u.gqr_rquota.rq_bsize; + *dsize = D.dqb_bsoftlimit; + + if (D.dqb_curblocks == D.dqb_curblocks == 1) + *bsize = DEV_BSIZE; + + if (D.dqb_curblocks > D.dqb_bsoftlimit) { + *dfree = 0; + *dsize = D.dqb_curblocks; + } else + *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; + + out: + + if (clnt) { + if (clnt->cl_auth) + auth_destroy(clnt->cl_auth); + clnt_destroy(clnt); + } + + DEBUG(5,("nfs_quotas: For path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n",args.gqa_pathp,(double)*bsize,(double)*dfree,(double)*dsize)); + + SAFE_FREE(cutstr); + DEBUG(10,("nfs_quotas: End of nfs_quotas\n" )); + return ret; +} + +#endif + /**************************************************************************** try to get the disk space from disk quotas - default version ****************************************************************************/ @@ -976,10 +1146,42 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB { /* FreeBSD patches from Marty Moll */ gid_t egrp_id; - +#if defined(__FreeBSD__) + SMB_DEV_T devno; + struct statfs *mnts; + SMB_STRUCT_STAT st; + int mntsize, i; + + if (sys_stat(path,&st) < 0) + return False; + devno = st.st_dev; + + mntsize = getmntinfo(&mnts,MNT_NOWAIT); + if (mntsize <= 0) + return False; + + for (i = 0; i < mntsize; i++) { + if (sys_stat(mnts[i].f_mntonname,&st) < 0) + return False; + if (st.st_dev == devno) + break; + } + if (i == mntsize) + return False; +#endif + save_re_uid(); set_effective_uid(0); +#if defined(__FreeBSD__) + if (strcmp(mnts[i].f_fstypename,"nfs") == 0) { + BOOL retval; + retval = nfs_quotas(mnts[i].f_mntfromname,euser_id,bsize,dfree,dsize); + restore_re_uid(); + return retval; + } +#endif + egrp_id = getegid(); r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D); -- cgit From ad94eabdc643c2f980bd664231d1ec6216a215cd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 21 Dec 2004 01:04:11 +0000 Subject: r4301: One more *alloc -> SMB_MALLOC (not compiled by default). Jeremy. (This used to be commit 235a0c1698db48583a6860a3a9fca9f261544365) --- source3/smbd/quotas.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 3c4d4319f6..a96f50ad02 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -471,7 +471,7 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B len=strcspn(mnttype, ":"); pathname=strstr(mnttype, ":"); - cutstr = (char *) malloc(len+1); + cutstr = (char *) SMB_MALLOC(len+1); if (!cutstr) return False; @@ -1000,7 +1000,7 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B len=strcspn(mnttype, ":"); pathname=strstr(mnttype, ":"); - cutstr = (char *) malloc(len+1); + cutstr = (char *) SMB_MALLOC(len+1); if (!cutstr) return False; -- cgit From 6c6e231f15c100f1f3449f2656257e120b1071af Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 1 Feb 2005 18:14:15 +0000 Subject: r5157: BUG 2266: conditionally include rpc/nettype.h to work around missing header onf FreeBSD4 (This used to be commit 314da604735696da4cf350f35d84592356e31861) --- source3/smbd/quotas.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index a96f50ad02..1117461bc2 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -938,7 +938,9 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB #include #include #include +#ifdef HAVE_RPC_NETTYPE_H #include +#endif #include static int quotastat; -- cgit From cf99ec82969f6d3c553472028bd9aa2112ef35d4 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 22 Mar 2005 17:31:23 +0000 Subject: r5958: BUG 1843: patch from james peach to fix quotas (with no soft limits) on IRIX (This used to be commit aeb3cea54ea2e050aef38e38fd8519510a14a184) --- source3/smbd/quotas.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 1117461bc2..1a73fdf222 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -882,8 +882,17 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB restore_re_uid(); if (r==-1) + { + DEBUG(5, ("quotactl for uid=%u: %s", euser_id, strerror(errno))); return(False); + } + /* No quota for this user. */ + if (F.d_blk_softlimit==0 && F.d_blk_hardlimit==0) + { + return(False); + } + /* Use softlimit to determine disk space, except when it has been exceeded */ if ( (F.d_blk_softlimit && F.d_bcount>=F.d_blk_softlimit) || @@ -895,14 +904,10 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB *dfree = 0; *dsize = F.d_bcount; } - else if (F.d_blk_softlimit==0 && F.d_blk_hardlimit==0) - { - return(False); - } else { *dfree = (F.d_blk_softlimit - F.d_bcount); - *dsize = F.d_blk_softlimit; + *dsize = F.d_blk_softlimit ? F.d_blk_softlimit : F.d_blk_hardlimit; } } -- cgit From dba540214ad42ed2fb520d6b831aaa36fcc0c848 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 10 May 2005 15:42:32 +0000 Subject: r6712: BUG 2362: fix quota support on DragonFly (Joerg Sonnenberger ) (This used to be commit 0644a2abf646be35b345665558ca173004beedde) --- source3/smbd/quotas.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 1a73fdf222..008f212c2c 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -923,7 +923,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB #else -#if defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) #include #include #elif AIX @@ -933,12 +933,12 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB #define dqb_curfiles dqb_curinodes #define dqb_fhardlimit dqb_ihardlimit #define dqb_fsoftlimit dqb_isoftlimit -#else /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ +#else /* !__FreeBSD__ && !AIX && !__OpenBSD__ && !__DragonFly__ */ #include #include #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__DragonFly__) #include #include @@ -1119,7 +1119,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB int r; struct dqblk D; uid_t euser_id; -#if !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) +#if !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) && !defined(__DragonFly__) char dev_disk[256]; SMB_STRUCT_STAT S; @@ -1136,7 +1136,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB return (False); #endif /* ifdef HPUX */ -#endif /* !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) */ +#endif /* !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) && !defined(__DragonFly__) */ euser_id = geteuid(); @@ -1149,11 +1149,11 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB restore_re_uid(); #else -#if defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) { /* FreeBSD patches from Marty Moll */ gid_t egrp_id; -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__DragonFly__) SMB_DEV_T devno; struct statfs *mnts; SMB_STRUCT_STAT st; @@ -1180,7 +1180,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB save_re_uid(); set_effective_uid(0); -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__DragonFly__) if (strcmp(mnts[i].f_fstypename,"nfs") == 0) { BOOL retval; retval = nfs_quotas(mnts[i].f_mntfromname,euser_id,bsize,dfree,dsize); @@ -1208,17 +1208,17 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB return False; r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D); restore_re_uid(); -#else /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ +#else /* !__FreeBSD__ && !AIX && !__OpenBSD__ && !__DragonFly__ */ r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); -#endif /* !__FreeBSD__ && !AIX && !__OpenBSD__ */ +#endif /* !__FreeBSD__ && !AIX && !__OpenBSD__ && !__DragonFly__ */ #endif /* HPUX */ /* Use softlimit to determine disk space, except when it has been exceeded */ -#if defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) *bsize = DEV_BSIZE; -#else /* !__FreeBSD__ && !__OpenBSD__ */ +#else /* !__FreeBSD__ && !__OpenBSD__ && !__DragonFly__ */ *bsize = 1024; -#endif /*!__FreeBSD__ && !__OpenBSD__ */ +#endif /*!__FreeBSD__ && !__OpenBSD__ && !__DragonFly__ */ if (r) { @@ -1241,7 +1241,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB return(False); /* Use softlimit to determine disk space, except when it has been exceeded */ if ((D.dqb_curblocks>D.dqb_bsoftlimit) -#if !defined(__FreeBSD__) && !defined(__OpenBSD__) +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__) ||((D.dqb_curfiles>D.dqb_fsoftlimit) && (D.dqb_fsoftlimit != 0)) #endif ) { -- cgit From 9e1cf0d51cd7487fff809dc3756fdac0c1efd9b3 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 11 Oct 2005 14:46:40 +0000 Subject: r10901: BUG 3145: Fix build issue regarding quota support on Solaris (This used to be commit b7de9a6c6963e7d3bb1a05ed15600dd50a8f4a08) --- source3/smbd/quotas.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 008f212c2c..8cb94bca3d 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -414,7 +414,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB static int quotastat; -static int xdr_getquota_args(XDR *xdrsp, struct getquota_args *args) +static int my_xdr_getquota_args(XDR *xdrsp, struct getquota_args *args) { if (!xdr_string(xdrsp, &args->gqa_pathp, RQ_PATHLEN )) return(0); @@ -423,7 +423,7 @@ static int xdr_getquota_args(XDR *xdrsp, struct getquota_args *args) return (1); } -static int xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) +static int my_xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) { if (!xdr_int(xdrsp, "astat)) { DEBUG(6,("nfs_quotas: Status bad or zero\n")); @@ -493,7 +493,7 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B clnt->cl_auth = authunix_create_default(); DEBUG(9,("nfs_quotas: auth_success\n")); - clnt_stat=clnt_call(clnt, RQUOTAPROC_GETQUOTA, xdr_getquota_args, (caddr_t)&args, xdr_getquota_rslt, (caddr_t)&gqr, timeout); + clnt_stat=clnt_call(clnt, RQUOTAPROC_GETQUOTA, my_xdr_getquota_args, (caddr_t)&args, my_xdr_getquota_rslt, (caddr_t)&gqr, timeout); if (clnt_stat != RPC_SUCCESS) { DEBUG(9,("nfs_quotas: clnt_call fail\n")); -- cgit From f6a46f3329683217ec5c71b8a5bf9b8322df023f Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Mon, 5 Dec 2005 16:51:19 +0000 Subject: r12076: Ensure setmntent() returns with != NULL in the disk_quotas() Linux version. The IRIX 6.2 version is still without this check as I'm not sure if setmntent() is implemented in the same way. (This used to be commit 519ed7ca0ecffbc341c7516758a678af59f98586) --- source3/smbd/quotas.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 8cb94bca3d..de31376d6c 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -216,7 +216,9 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB devno = S.st_dev ; - fp = setmntent(MOUNTED,"r"); + if ((fp = setmntent(MOUNTED,"r")) == NULL) + return(False) ; + found = False ; while ((mnt = getmntent(fp))) { -- cgit From bd08ae25dccff147547cda7575e2171abeb2195f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 25 Dec 2005 10:41:34 +0000 Subject: r12477: Remove a gcc -O6 warning (This used to be commit dd39a37f8e6ab7dad46b180959636f5e402c136d) --- source3/smbd/quotas.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index de31376d6c..d6ba7bc2d5 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -206,6 +206,8 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB uid_t euser_id; gid_t egrp_id; + ZERO_STRUCT(D); + euser_id = geteuid(); egrp_id = getegid(); -- cgit From 981350a03c14ca526b703925c65d61b70b1f38cb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 28 Jul 2006 23:16:52 +0000 Subject: r17296: Replace the understandable parts of the quota code with become_root_uid_only()/unbecome_root_uid_only() pairs. This code needs working on..... Jeremy. (This used to be commit 0661d4e26614180636bc57de0c48adf8b9ce7a21) --- source3/smbd/quotas.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index d6ba7bc2d5..35bb94bcef 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -238,8 +238,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB if (!found) return(False); - save_re_uid(); - set_effective_uid(0); + become_root_uid_only(); if (strcmp(mnt->mnt_type, "xfs")==0) { r=get_smb_linux_xfs_quota(mnt->mnt_fsname, euser_id, egrp_id, &D); @@ -252,7 +251,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB } } - restore_re_uid(); + unbecome_root_uid_only(); /* Use softlimit to determine disk space, except when it has been exceeded */ *bsize = D.bsize; @@ -654,21 +653,20 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB if ( ! found ) return(False) ; - save_re_uid(); - set_effective_uid(0); + become_root_uid_only(); #if defined(SUNOS5) if ( strcmp( mnt.mnt_fstype, "nfs" ) == 0) { BOOL retval; DEBUG(5,("disk_quotas: looking for mountpath (NFS) \"%s\"\n", mnt.mnt_special)); retval = nfs_quotas(mnt.mnt_special, euser_id, bsize, dfree, dsize); - restore_re_uid(); + unbecome_root_uid_only(); return retval; } DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); if((file=sys_open(name, O_RDONLY,0))<0) { - restore_re_uid(); + unbecome_root_uid_only(); return(False); } command.op = Q_GETQUOTA; @@ -681,7 +679,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB ret = quotactl(Q_GETQUOTA, name, euser_id, &D); #endif - restore_re_uid(); + unbecome_root_uid_only(); if (ret < 0) { DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); @@ -841,8 +839,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB } euser_id=geteuid(); - save_re_uid(); - set_effective_uid(0); + become_root_uid_only(); /* Use softlimit to determine disk space, except when it has been exceeded */ @@ -852,7 +849,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB { r=quotactl (Q_GETQUOTA, mnt->mnt_fsname, euser_id, (caddr_t) &D); - restore_re_uid(); + unbecome_root_uid_only(); if (r==-1) return(False); @@ -883,7 +880,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB { r=quotactl (Q_XGETQUOTA, mnt->mnt_fsname, euser_id, (caddr_t) &F); - restore_re_uid(); + unbecome_root_uid_only(); if (r==-1) { @@ -917,7 +914,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB } else { - restore_re_uid(); + unbecome_root_uid_only(); return(False); } @@ -1181,14 +1178,13 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB return False; #endif - save_re_uid(); - set_effective_uid(0); + become_root_uid_only(); #if defined(__FreeBSD__) || defined(__DragonFly__) if (strcmp(mnts[i].f_fstypename,"nfs") == 0) { BOOL retval; retval = nfs_quotas(mnts[i].f_mntfromname,euser_id,bsize,dfree,dsize); - restore_re_uid(); + unbecome_root_uid_only(); return retval; } #endif @@ -1202,7 +1198,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB r= quotactl(path,QCMD(Q_GETQUOTA,GRPQUOTA),egrp_id,(char *) &D); } - restore_re_uid(); + unbecome_root_uid_only(); } #elif defined(AIX) /* AIX has both USER and GROUP quotas: -- cgit From 0c72a09e7d9f3ce06befe76b102cb6361d9382a4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Oct 2006 05:22:36 +0000 Subject: r19260: Fix for bug #3524 from tiamat@komi.mts.ru - Solaris quotas. Jeremy. (This used to be commit ac510a90f3adf72b64a8e2a764b0500dcd223b3f) --- source3/smbd/quotas.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 35bb94bcef..bb88957731 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -586,7 +586,6 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB int file; static struct mnttab mnt; static pstring name; - pstring devopt; #else /* SunOS4 */ struct mntent *mnt; static pstring name; @@ -603,7 +602,8 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB return(False) ; devno = sbuf.st_dev ; - DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", path,(unsigned int)devno)); + DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", + path, (unsigned int)devno)); if ( devno != devno_cached ) { devno_cached = devno ; #if defined(SUNOS5) @@ -611,17 +611,19 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB return(False) ; found = False ; - slprintf(devopt, sizeof(devopt) - 1, "dev=%x", (unsigned int)devno); + while (getmntent(fd, &mnt) == 0) { - if( !hasmntopt(&mnt, devopt) ) + if (sys_stat(mnt.mnt_mountp, &sbuf) == -1) continue; - DEBUG(5,("disk_quotas: testing \"%s\" %s\n", mnt.mnt_mountp,devopt)); + DEBUG(5,("disk_quotas: testing \"%s\" devno=%x\n", + mnt.mnt_mountp, (unsigned int)devno)); /* quotas are only on vxfs, UFS or NFS */ - if ( strcmp( mnt.mnt_fstype, MNTTYPE_UFS ) == 0 || + if ( (sbuf.st_dev == devno) && ( + strcmp( mnt.mnt_fstype, MNTTYPE_UFS ) == 0 || strcmp( mnt.mnt_fstype, "nfs" ) == 0 || - strcmp( mnt.mnt_fstype, "vxfs" ) == 0 ) { + strcmp( mnt.mnt_fstype, "vxfs" ) == 0 )) { found = True ; break; } -- cgit From 9b807d4f87d80e542bf8209d4ea4b6c09a953470 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Apr 2007 17:10:52 +0000 Subject: r22060: Fix for AIX quotas from Heinrich Mislik . Jeremy. (This used to be commit 8d95cdf8c0a46abc6b5cbcec3fd8bf246d49ee4b) --- source3/smbd/quotas.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index bb88957731..0492130950 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -936,6 +936,10 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB #define dqb_curfiles dqb_curinodes #define dqb_fhardlimit dqb_ihardlimit #define dqb_fsoftlimit dqb_isoftlimit +#ifdef _AIXVERSION_530 +#include +#include +#endif /* AIX 5.3 */ #else /* !__FreeBSD__ && !AIX && !__OpenBSD__ && !__DragonFly__ */ #include #include @@ -1205,11 +1209,37 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB #elif defined(AIX) /* AIX has both USER and GROUP quotas: Get the USER quota (ohnielse@fysik.dtu.dk) */ +#ifdef _AIXVERSION_530 + { + struct statfs statbuf; + quota64_t user_quota; + if (statfs(path,&statbuf) != 0) + return False; + if(statbuf.f_vfstype == MNT_J2) + { + /* For some reason we need to be root for jfs2 */ + become_root_uid_only(); + r = quotactl(path,QCMD(Q_J2GETQUOTA,USRQUOTA),euser_id,(char *) &user_quota); + unbecome_root_uid_only(); + /* Copy results to old struct to let the following code work as before */ + D.dqb_curblocks = user_quota.bused; + D.dqb_bsoftlimit = user_quota.bsoft; + D.dqb_bhardlimit = user_quota.bhard; + } + else if(statbuf.f_vfstype == MNT_JFS) + { +#endif /* AIX 5.3 */ save_re_uid(); if (set_re_uid() != 0) return False; r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D); restore_re_uid(); +#ifdef _AIXVERSION_530 + } + else + r = 1; /* Fail for other FS-types */ + } +#endif /* AIX 5.3 */ #else /* !__FreeBSD__ && !AIX && !__OpenBSD__ && !__DragonFly__ */ r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D); #endif /* !__FreeBSD__ && !AIX && !__OpenBSD__ && !__DragonFly__ */ -- cgit From bc45c82904e268327bfbf72cd3f35699ae6e7397 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 5 Apr 2007 23:56:10 +0000 Subject: r22096: become_root_uid_only() is unneeded - it's only used in messages.c. Refactor to use become_root() instead and make it local to messages.c Jeremy. (This used to be commit f3ffb3f98472b69b476b702dfe5c0575b32da018) --- source3/smbd/quotas.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 0492130950..ddfcb8e0f8 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -238,7 +238,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB if (!found) return(False); - become_root_uid_only(); + become_root(); if (strcmp(mnt->mnt_type, "xfs")==0) { r=get_smb_linux_xfs_quota(mnt->mnt_fsname, euser_id, egrp_id, &D); @@ -251,7 +251,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB } } - unbecome_root_uid_only(); + unbecome_root(); /* Use softlimit to determine disk space, except when it has been exceeded */ *bsize = D.bsize; @@ -655,20 +655,20 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB if ( ! found ) return(False) ; - become_root_uid_only(); + become_root(); #if defined(SUNOS5) if ( strcmp( mnt.mnt_fstype, "nfs" ) == 0) { BOOL retval; DEBUG(5,("disk_quotas: looking for mountpath (NFS) \"%s\"\n", mnt.mnt_special)); retval = nfs_quotas(mnt.mnt_special, euser_id, bsize, dfree, dsize); - unbecome_root_uid_only(); + unbecome(); return retval; } DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); if((file=sys_open(name, O_RDONLY,0))<0) { - unbecome_root_uid_only(); + unbecome_root(); return(False); } command.op = Q_GETQUOTA; @@ -681,7 +681,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB ret = quotactl(Q_GETQUOTA, name, euser_id, &D); #endif - unbecome_root_uid_only(); + unbecome_root(); if (ret < 0) { DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); @@ -841,7 +841,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB } euser_id=geteuid(); - become_root_uid_only(); + become_root(); /* Use softlimit to determine disk space, except when it has been exceeded */ @@ -851,7 +851,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB { r=quotactl (Q_GETQUOTA, mnt->mnt_fsname, euser_id, (caddr_t) &D); - unbecome_root_uid_only(); + unbecome_root(); if (r==-1) return(False); @@ -882,7 +882,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB { r=quotactl (Q_XGETQUOTA, mnt->mnt_fsname, euser_id, (caddr_t) &F); - unbecome_root_uid_only(); + unbecome_root(); if (r==-1) { @@ -916,7 +916,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB } else { - unbecome_root_uid_only(); + unbecome_root(); return(False); } @@ -1184,13 +1184,13 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB return False; #endif - become_root_uid_only(); + become_root(); #if defined(__FreeBSD__) || defined(__DragonFly__) if (strcmp(mnts[i].f_fstypename,"nfs") == 0) { BOOL retval; retval = nfs_quotas(mnts[i].f_mntfromname,euser_id,bsize,dfree,dsize); - unbecome_root_uid_only(); + unbecome_root(); return retval; } #endif @@ -1204,7 +1204,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB r= quotactl(path,QCMD(Q_GETQUOTA,GRPQUOTA),egrp_id,(char *) &D); } - unbecome_root_uid_only(); + unbecome_root(); } #elif defined(AIX) /* AIX has both USER and GROUP quotas: @@ -1218,9 +1218,9 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB if(statbuf.f_vfstype == MNT_J2) { /* For some reason we need to be root for jfs2 */ - become_root_uid_only(); + become_root(); r = quotactl(path,QCMD(Q_J2GETQUOTA,USRQUOTA),euser_id,(char *) &user_quota); - unbecome_root_uid_only(); + unbecome_root(); /* Copy results to old struct to let the following code work as before */ D.dqb_curblocks = user_quota.bused; D.dqb_bsoftlimit = user_quota.bsoft; -- cgit From 1790c67780af0bcc4bc1df3f015fa6fcb7e55f95 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 10 Apr 2007 15:41:23 +0000 Subject: r22149: BUG 4500: patch from Jorge Santos to fix compile bug ni quotas.c (typo calling unbecome_root()). (This used to be commit 22d550d62b5834e2c5155550756d3462a1bd6561) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index ddfcb8e0f8..feb28e2c74 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -662,7 +662,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB BOOL retval; DEBUG(5,("disk_quotas: looking for mountpath (NFS) \"%s\"\n", mnt.mnt_special)); retval = nfs_quotas(mnt.mnt_special, euser_id, bsize, dfree, dsize); - unbecome(); + unbecome_root(); return retval; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/smbd/quotas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index feb28e2c74..19c103f2ba 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/smbd/quotas.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 19c103f2ba..271f3b5d96 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ -- cgit From ef591178d08089494f45ab49870a7aaa4f12bed1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 01:15:57 +0000 Subject: r23786: Use linux/dqblk_xfs.h rather than a private copy of this header in the Samba3 tree. This is neater, plus it avoids the need to get legal approval from SGI to use their GPLv2-only code under GPLv3. If/when SGI legal sort things out, we could consider adding back this header for very old systems where linux/dqblk_xfs.h is not available. (This used to be commit cb435543f84955be75368a3294bc6b627414d876) --- source3/smbd/quotas.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 271f3b5d96..1f30acef33 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -61,7 +61,6 @@ BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_B */ #include "samba_linux_quota.h" -#include "samba_xfs_quota.h" typedef struct _LINUX_SMB_DISK_QUOTA { SMB_BIG_UINT bsize; @@ -73,6 +72,10 @@ typedef struct _LINUX_SMB_DISK_QUOTA { SMB_BIG_UINT curinodes; /* Current used inodes. */ } LINUX_SMB_DISK_QUOTA; + +#ifdef HAVE_LINUX_DQBLK_XFS_H +#include + /**************************************************************************** Abstract out the XFS Quota Manager quota get call. ****************************************************************************/ @@ -102,6 +105,15 @@ static int get_smb_linux_xfs_quota(char *path, uid_t euser_id, gid_t egrp_id, LI return ret; } +#else +static int get_smb_linux_xfs_quota(char *path, uid_t euser_id, gid_t egrp_id, LINUX_SMB_DISK_QUOTA *dp) +{ + DEBUG(0,("XFS quota support not available\n")); + errno = ENOSYS; + return -1; +} +#endif + /**************************************************************************** Abstract out the old and new Linux quota get calls. -- cgit From fb7ee0804c9d4e91a14c03651fc4907115d594e7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 24 Sep 2007 21:43:54 +0000 Subject: r25311: Patch from Heinrich Mislik to fix AIX quotas. Heinrich, I trust you on that, I don't even have compiled this :-) Volker (This used to be commit a8312a1d7b7e3ad00265279dd0640261beaa287d) --- source3/smbd/quotas.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index 1f30acef33..cb31763a9f 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -1236,6 +1236,9 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB D.dqb_curblocks = user_quota.bused; D.dqb_bsoftlimit = user_quota.bsoft; D.dqb_bhardlimit = user_quota.bhard; + D.dqb_curfiles = user_quota.iused; + D.dqb_fsoftlimit = user_quota.isoft; + D.dqb_fhardlimit = user_quota.ihard; } else if(statbuf.f_vfstype == MNT_JFS) { -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/smbd/quotas.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index cb31763a9f..ac6ad9d470 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -45,7 +45,7 @@ * Declare here, define at end: reduces likely "include" interaction problems. * David Lee */ -BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize); +bool disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize); #endif /* VXFS_QUOTA */ @@ -205,7 +205,7 @@ static int get_smb_linux_gen_quota(char *path, uid_t euser_id, gid_t egrp_id, LI Try to get the disk space from disk quotas (LINUX version). ****************************************************************************/ -BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { int r; SMB_STRUCT_STAT S; @@ -306,7 +306,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB try to get the disk space from disk quotas (CRAY VERSION) ****************************************************************************/ -BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { struct mntent *mnt; FILE *fd; @@ -467,7 +467,7 @@ static int my_xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) } /* Restricted to SUNOS5 for the moment, I haven`t access to others to test. */ -static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +static bool nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t uid = euser_id; struct dqblk D; @@ -479,7 +479,7 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B int len; static struct timeval timeout = {2,0}; enum clnt_stat clnt_stat; - BOOL ret = True; + bool ret = True; *bsize = *dfree = *dsize = (SMB_BIG_UINT)0; @@ -587,7 +587,7 @@ try to get the disk space from disk quotas (SunOS & Solaris2 version) Quota code by Peter Urbanec (amiga@cse.unsw.edu.au). ****************************************************************************/ -BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t euser_id; int ret; @@ -670,7 +670,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB #if defined(SUNOS5) if ( strcmp( mnt.mnt_fstype, "nfs" ) == 0) { - BOOL retval; + bool retval; DEBUG(5,("disk_quotas: looking for mountpath (NFS) \"%s\"\n", mnt.mnt_special)); retval = nfs_quotas(mnt.mnt_special, euser_id, bsize, dfree, dsize); unbecome_root(); @@ -702,7 +702,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB set_effective_uid(euser_id); DEBUG(5,("disk_quotas: mount type \"%s\"\n", mnt.mnt_fstype)); if ( 0 == strcmp ( mnt.mnt_fstype, "vxfs" )) { - BOOL retval; + bool retval; retval = disk_quotas_vxfs(name, path, bsize, dfree, dsize); return(retval); } @@ -748,7 +748,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB try to get the disk space from disk quotas - OSF1 version ****************************************************************************/ -BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { int r, save_errno; struct dqblk D; @@ -814,7 +814,7 @@ try to get the disk space from disk quotas (IRIX 6.2 version) #include #include -BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t euser_id; int r; @@ -1007,7 +1007,7 @@ static int my_xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) } /* Works on FreeBSD, too. :-) */ -static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +static bool nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t uid = euser_id; struct dqblk D; @@ -1019,7 +1019,7 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B int len; static struct timeval timeout = {2,0}; enum clnt_stat clnt_stat; - BOOL ret = True; + bool ret = True; *bsize = *dfree = *dsize = (SMB_BIG_UINT)0; @@ -1132,7 +1132,7 @@ static BOOL nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B try to get the disk space from disk quotas - default version ****************************************************************************/ -BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { int r; struct dqblk D; @@ -1199,7 +1199,7 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB #if defined(__FreeBSD__) || defined(__DragonFly__) if (strcmp(mnts[i].f_fstypename,"nfs") == 0) { - BOOL retval; + bool retval; retval = nfs_quotas(mnts[i].f_mntfromname,euser_id,bsize,dfree,dsize); unbecome_root(); return retval; @@ -1351,7 +1351,7 @@ Hints for porting: #include #include -BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +bool disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t user_id, euser_id; int ret; @@ -1432,7 +1432,7 @@ BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_B #else /* WITH_QUOTAS */ -BOOL disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize) +bool disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize) { (*bsize) = 512; /* This value should be ignored */ @@ -1450,7 +1450,7 @@ BOOL disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BI /* wrapper to the new sys_quota interface this file should be removed later */ -BOOL disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize) +bool disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize) { int r; SMB_DISK_QUOTA D; -- cgit From 052efa9a33d7a9a3b9ae9b038f6b3943c85c4bfc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 13 Nov 2007 12:51:31 -0800 Subject: Remove last pstring from smbd/*.c Jeremy. (This used to be commit f1680bada913af4eaf5c0d686983018d6c8b3e5f) --- source3/smbd/quotas.c | 365 +++++++++++++++++++++++++------------------------- 1 file changed, 185 insertions(+), 180 deletions(-) (limited to 'source3/smbd/quotas.c') diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index ac6ad9d470..f47e89bd22 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -45,7 +45,7 @@ * Declare here, define at end: reduces likely "include" interaction problems. * David Lee */ -bool disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize); +bool disk_quotas_vxfs(const char *name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize); #endif /* VXFS_QUOTA */ @@ -223,17 +223,17 @@ bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB egrp_id = getegid(); /* find the block device file */ - + if ( sys_stat(path, &S) == -1 ) return(False) ; devno = S.st_dev ; - + if ((fp = setmntent(MOUNTED,"r")) == NULL) return(False) ; found = False ; - + while ((mnt = getmntent(fp))) { if ( sys_stat(mnt->mnt_dir,&S) == -1 ) continue ; @@ -245,7 +245,7 @@ bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB } endmntent(fp) ; - + if (!found) return(False); @@ -308,94 +308,81 @@ try to get the disk space from disk quotas (CRAY VERSION) bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { - struct mntent *mnt; - FILE *fd; - SMB_STRUCT_STAT sbuf; - SMB_DEV_T devno ; - static SMB_DEV_T devno_cached = 0 ; - static pstring name; - struct q_request request ; - struct qf_header header ; - static int quota_default = 0 ; - int found ; - - if ( sys_stat(path,&sbuf) == -1 ) - return(False) ; - - devno = sbuf.st_dev ; - - if ( devno != devno_cached ) { - - devno_cached = devno ; - - if ((fd = setmntent(KMTAB)) == NULL) - return(False) ; - - found = False ; - - while ((mnt = getmntent(fd)) != NULL) { - - if ( sys_stat(mnt->mnt_dir,&sbuf) == -1 ) - continue ; - - if (sbuf.st_dev == devno) { - - found = True ; - break ; - - } - - } - - pstrcpy(name,mnt->mnt_dir) ; - endmntent(fd) ; - - if ( ! found ) - return(False) ; - } - - request.qf_magic = QF_MAGIC ; - request.qf_entry.id = geteuid() ; - - if (quotactl(name, Q_GETQUOTA, &request) == -1) - return(False) ; - - if ( ! request.user ) - return(False) ; - - if ( request.qf_entry.user_q.f_quota == QFV_DEFAULT ) { - - if ( ! quota_default ) { - - if ( quotactl(name, Q_GETHEADER, &header) == -1 ) - return(False) ; - else - quota_default = header.user_h.def_fq ; - } - - *dfree = quota_default ; - - }else if ( request.qf_entry.user_q.f_quota == QFV_PREVENT ) { - - *dfree = 0 ; - - }else{ - - *dfree = request.qf_entry.user_q.f_quota ; - - } - - *dsize = request.qf_entry.user_q.f_use ; - - if ( *dfree < *dsize ) - *dfree = 0 ; - else - *dfree -= *dsize ; - - *bsize = 4096 ; /* Cray blocksize */ - - return(True) ; - + struct mntent *mnt; + FILE *fd; + SMB_STRUCT_STAT sbuf; + SMB_DEV_T devno ; + struct q_request request ; + struct qf_header header ; + int quota_default = 0 ; + bool found = false; + + if (sys_stat(path,&sbuf) == -1) { + return false; + } + + devno = sbuf.st_dev ; + + if ((fd = setmntent(KMTAB)) == NULL) { + return false; + } + + while ((mnt = getmntent(fd)) != NULL) { + if (sys_stat(mnt->mnt_dir,&sbuf) == -1) { + continue; + } + if (sbuf.st_dev == devno) { + found = frue ; + break; + } + } + + name = talloc_strdup(talloc_tos(), mnt->mnt_dir); + endmntent(fd); + if (!found) { + return false; + } + + if (!name) { + return false; + } + + request.qf_magic = QF_MAGIC ; + request.qf_entry.id = geteuid() ; + + if (quotactl(name, Q_GETQUOTA, &request) == -1) { + return false; + } + + if (!request.user) { + return False; + } + + if (request.qf_entry.user_q.f_quota == QFV_DEFAULT) { + if (!quota_default) { + if (quotactl(name, Q_GETHEADER, &header) == -1) { + return false; + } else { + quota_default = header.user_h.def_fq; + } + } + *dfree = quota_default; + } else if (request.qf_entry.user_q.f_quota == QFV_PREVENT) { + *dfree = 0; + } else { + *dfree = request.qf_entry.user_q.f_quota; + } + + *dsize = request.qf_entry.user_q.f_use; + + if (*dfree < *dsize) { + *dfree = 0; + } else { + *dfree -= *dsize; + } + + *bsize = 4096 ; /* Cray blocksize */ + return true; } @@ -466,7 +453,7 @@ static int my_xdr_getquota_rslt(XDR *xdrsp, struct getquota_rslt *gqr) return (1); } -/* Restricted to SUNOS5 for the moment, I haven`t access to others to test. */ +/* Restricted to SUNOS5 for the moment, I haven`t access to others to test. */ static bool nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t uid = euser_id; @@ -515,11 +502,11 @@ static bool nfs_quotas(char *nfspath, uid_t euser_id, SMB_BIG_UINT *bsize, SMB_B goto out; } - /* + /* * quotastat returns 0 if the rpc call fails, 1 if quotas exist, 2 if there is * no quota set, and 3 if no permission to get the quota. If 0 or 3 return * something sensible. - */ + */ switch ( quotastat ) { case 0: @@ -587,7 +574,10 @@ try to get the disk space from disk quotas (SunOS & Solaris2 version) Quota code by Peter Urbanec (amiga@cse.unsw.edu.au). ****************************************************************************/ -bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +bool disk_quotas(const char *path, + SMB_BIG_UINT *bsize, + SMB_BIG_UINT *dfree, + SMB_BIG_UINT *dsize) { uid_t euser_id; int ret; @@ -595,84 +585,90 @@ bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB #if defined(SUNOS5) struct quotctl command; int file; - static struct mnttab mnt; - static pstring name; + struct mnttab mnt; #else /* SunOS4 */ struct mntent *mnt; - static pstring name; #endif + char *name = NULL; FILE *fd; SMB_STRUCT_STAT sbuf; - SMB_DEV_T devno ; - static SMB_DEV_T devno_cached = 0 ; - static int found ; + SMB_DEV_T devno; + bool found = false; euser_id = geteuid(); - - if ( sys_stat(path,&sbuf) == -1 ) - return(False) ; - + + if (sys_stat(path,&sbuf) == -1) { + return false; + } + devno = sbuf.st_dev ; DEBUG(5,("disk_quotas: looking for path \"%s\" devno=%x\n", path, (unsigned int)devno)); - if ( devno != devno_cached ) { - devno_cached = devno ; #if defined(SUNOS5) - if ((fd = sys_fopen(MNTTAB, "r")) == NULL) - return(False) ; - - found = False ; - - while (getmntent(fd, &mnt) == 0) { - if (sys_stat(mnt.mnt_mountp, &sbuf) == -1) - continue; - - DEBUG(5,("disk_quotas: testing \"%s\" devno=%x\n", - mnt.mnt_mountp, (unsigned int)devno)); - - /* quotas are only on vxfs, UFS or NFS */ - if ( (sbuf.st_dev == devno) && ( - strcmp( mnt.mnt_fstype, MNTTYPE_UFS ) == 0 || - strcmp( mnt.mnt_fstype, "nfs" ) == 0 || - strcmp( mnt.mnt_fstype, "vxfs" ) == 0 )) { - found = True ; - break; - } + if ((fd = sys_fopen(MNTTAB, "r")) == NULL) { + return false; + } + + while (getmntent(fd, &mnt) == 0) { + if (sys_stat(mnt.mnt_mountp, &sbuf) == -1) { + continue; } - - pstrcpy(name,mnt.mnt_mountp) ; - pstrcat(name,"/quotas") ; - fclose(fd) ; -#else /* SunOS4 */ - if ((fd = setmntent(MOUNTED, "r")) == NULL) - return(False) ; - - found = False ; - while ((mnt = getmntent(fd)) != NULL) { - if ( sys_stat(mnt->mnt_dir,&sbuf) == -1 ) - continue ; - DEBUG(5,("disk_quotas: testing \"%s\" devno=%x\n", mnt->mnt_dir,(unsigned int)sbuf.st_dev)); - if (sbuf.st_dev == devno) { - found = True ; + + DEBUG(5,("disk_quotas: testing \"%s\" devno=%x\n", + mnt.mnt_mountp, (unsigned int)devno)); + + /* quotas are only on vxfs, UFS or NFS */ + if ((sbuf.st_dev == devno) && ( + strcmp( mnt.mnt_fstype, MNTTYPE_UFS ) == 0 || + strcmp( mnt.mnt_fstype, "nfs" ) == 0 || + strcmp( mnt.mnt_fstype, "vxfs" ) == 0 )) { + found = true; + name = talloc_asprintf(talloc_tos(), + "%s/quotas", + mnt.mnt_mountp); break; - } } - - pstrcpy(name,mnt->mnt_fsname) ; - endmntent(fd) ; -#endif } - if ( ! found ) - return(False) ; + fclose(fd); +#else /* SunOS4 */ + if ((fd = setmntent(MOUNTED, "r")) == NULL) { + return false; + } + + while ((mnt = getmntent(fd)) != NULL) { + if (sys_stat(mnt->mnt_dir,&sbuf) == -1) { + continue; + } + DEBUG(5,("disk_quotas: testing \"%s\" devno=%x\n", + mnt->mnt_dir, + (unsigned int)sbuf.st_dev)); + if (sbuf.st_dev == devno) { + found = true; + name = talloc_strdup(talloc_tos(), + mnt->mnt_fsname); + break; + } + } + endmntent(fd); +#endif + if (!found) { + return false; + } + + if (!name) { + return false; + } become_root(); #if defined(SUNOS5) - if ( strcmp( mnt.mnt_fstype, "nfs" ) == 0) { + if (strcmp(mnt.mnt_fstype, "nfs") == 0) { bool retval; - DEBUG(5,("disk_quotas: looking for mountpath (NFS) \"%s\"\n", mnt.mnt_special)); - retval = nfs_quotas(mnt.mnt_special, euser_id, bsize, dfree, dsize); + DEBUG(5,("disk_quotas: looking for mountpath (NFS) \"%s\"\n", + mnt.mnt_special)); + retval = nfs_quotas(mnt.mnt_special, + euser_id, bsize, dfree, dsize); unbecome_root(); return retval; } @@ -680,7 +676,7 @@ bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB DEBUG(5,("disk_quotas: looking for quotas file \"%s\"\n", name)); if((file=sys_open(name, O_RDONLY,0))<0) { unbecome_root(); - return(False); + return false; } command.op = Q_GETQUOTA; command.uid = euser_id; @@ -695,7 +691,8 @@ bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB unbecome_root(); if (ret < 0) { - DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", strerror(errno) )); + DEBUG(5,("disk_quotas ioctl (Solaris) failed. Error = %s\n", + strerror(errno) )); #if defined(SUNOS5) && defined(VXFS_QUOTA) /* If normal quotactl() fails, try vxfs private calls */ @@ -703,24 +700,27 @@ bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB DEBUG(5,("disk_quotas: mount type \"%s\"\n", mnt.mnt_fstype)); if ( 0 == strcmp ( mnt.mnt_fstype, "vxfs" )) { bool retval; - retval = disk_quotas_vxfs(name, path, bsize, dfree, dsize); - return(retval); + retval = disk_quotas_vxfs(name, path, + bsize, dfree, dsize); + return retval; } #else - return(False); + return false; #endif } /* If softlimit is zero, set it equal to hardlimit. */ - - if (D.dqb_bsoftlimit==0) + + if (D.dqb_bsoftlimit==0) { D.dqb_bsoftlimit = D.dqb_bhardlimit; + } - /* Use softlimit to determine disk space. A user exceeding the quota is told - * that there's no space left. Writes might actually work for a bit if the - * hardlimit is set higher than softlimit. Effectively the disk becomes - * made of rubber latex and begins to expand to accommodate the user :-) + /* Use softlimit to determine disk space. A user exceeding the quota + * is told that there's no space left. Writes might actually work for + * a bit if the hardlimit is set higher than softlimit. Effectively + * the disk becomes made of rubber latex and begins to expand to + * accommodate the user :-) */ if (D.dqb_bsoftlimit==0) @@ -731,13 +731,15 @@ bool disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB if (D.dqb_curblocks > D.dqb_bsoftlimit) { *dfree = 0; *dsize = D.dqb_curblocks; - } else + } else { *dfree = D.dqb_bsoftlimit - D.dqb_curblocks; - - DEBUG(5,("disk_quotas for path \"%s\" returning bsize %.0f, dfree %.0f, dsize %.0f\n", + } + + DEBUG(5,("disk_quotas for path \"%s\" returning " + "bsize %.0f, dfree %.0f, dsize %.0f\n", path,(double)*bsize,(double)*dfree,(double)*dsize)); - return(True); + return true; } @@ -1351,14 +1353,14 @@ Hints for porting: #include #include -bool disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +bool disk_quotas_vxfs(const char *name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { uid_t user_id, euser_id; int ret; struct vx_dqblk D; struct vx_quotctl quotabuf; struct vx_genioctl genbuf; - pstring qfname; + char *qfname; int file; /* @@ -1367,7 +1369,10 @@ bool disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_B * it might be easier to examine and adjust it here. * Fortunately, VxFS seems not to mind at present. */ - pstrcpy(qfname, name) ; + qfname = talloc_strdup(talloc_tos(), name); + if (!qfname) { + return false; + } /* pstrcat(qfname, "/quotas") ; */ /* possibly examine and adjust "name" */ euser_id = geteuid(); @@ -1434,20 +1439,20 @@ bool disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_B bool disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize) { - (*bsize) = 512; /* This value should be ignored */ + (*bsize) = 512; /* This value should be ignored */ - /* And just to be sure we set some values that hopefully */ - /* will be larger that any possible real-world value */ - (*dfree) = (SMB_BIG_UINT)-1; - (*dsize) = (SMB_BIG_UINT)-1; + /* And just to be sure we set some values that hopefully */ + /* will be larger that any possible real-world value */ + (*dfree) = (SMB_BIG_UINT)-1; + (*dsize) = (SMB_BIG_UINT)-1; - /* As we have select not to use quotas, allways fail */ - return False; + /* As we have select not to use quotas, allways fail */ + return false; } #endif /* WITH_QUOTAS */ #else /* HAVE_SYS_QUOTAS */ -/* wrapper to the new sys_quota interface +/* wrapper to the new sys_quota interface this file should be removed later */ bool disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize) -- cgit