]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/quota.c
Remove NEED_QUOTACTL_WRAPPER cruft. I think that was needed for old Linux
[netatalk.git] / etc / afpd / quota.c
index 714dee7152943e79fe3944afa5044a63a5bda44a..36bf3bc84f24b68ae63330ba6d3e29b71b50eced 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: quota.c,v 1.13 2001-12-10 20:16:54 srittau Exp $
+ * $Id: quota.c,v 1.23 2003-12-15 04:49:56 srittau Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -38,7 +38,7 @@ char *strchr (), *strrchr ();
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif /* HAVE_FCNTL_H */
-#include <syslog.h>
+#include <atalk/logger.h>
 
 #include <atalk/afp.h>
 
@@ -47,12 +47,6 @@ char *strchr (), *strrchr ();
 #include "unix.h"
 
 #ifndef NO_QUOTA_SUPPORT
-#ifdef NEED_QUOTACTL_WRAPPER
-int quotactl(int cmd, const char *special, int id, caddr_t addr)
-{
-    return syscall(__NR_quotactl, cmd, special, id, addr);
-}
-#endif /* NEED_QUOTACTL_WRAPPER */
 
 
 #if defined(HAVE_SYS_MNTTAB_H) || defined(__svr4__)
@@ -115,7 +109,7 @@ int  *nfs;
     static struct fs_data      fsd;
 
     if ( getmnt(0, &fsd, 0, STAT_ONE, file ) < 0 ) {
-        syslog(LOG_INFO, "special: getmnt %s: %m", file );
+        LOG(log_info, logtype_afpd, "special: getmnt %s: %s", file, strerror(errno) );
         return( NULL );
     }
 
@@ -139,8 +133,14 @@ int         *nfs;
         return( NULL );
     }
 
+#ifdef TRU64
+    /* Digital UNIX: The struct sfs contains a field sfs.f_type,
+     * the MOUNT_* constants are defined in <sys/mount.h> */
+    if ((sfs.f_type == MOUNT_NFS)||(sfs.f_type == MOUNT_NFS3))
+#else /* TRU64 */
     /* XXX: make sure this really detects an nfs mounted fs */
     if (strchr(sfs.f_mntfromname, ':'))
+#endif /* TRU64 */
         *nfs = 1;
     return( sfs.f_mntfromname );
 }
@@ -231,15 +231,21 @@ struct dqblk        *dq;
 #endif /* TRU64 */
 
 #ifdef BSD4_4
-    if ( quotactl( vol->v_gvs, QCMD(Q_GETQUOTA,USRQUOTA),
-                   uid, (char *)dq ) != 0 ) {
-        return( AFPERR_PARAM );
+    if ( seteuid( getuid() ) == 0 ) {
+        if ( quotactl( vol->v_path, QCMD(Q_GETQUOTA,USRQUOTA),
+                       uid, (char *)dq ) != 0 ) {
+            /* try group quotas */
+            if (ngroups >= 1) {
+                if ( quotactl(vol->v_path, QCMD(Q_GETQUOTA, GRPQUOTA),
+                              groups[0], (char *) &dqg) != 0 ) {
+                    seteuid( uid );
+                    return( AFPERR_PARAM );
+                }
+            }
+        }
+        seteuid( uid );
     }
 
-    if (ngroups == 1)
-        quotactl(vol->v_gvs, QCMD(Q_GETQUOTA, GRPQUOTA),
-                 groups[0], (char *) &dqg);
-
 #elif defined(TRU64)
     if ( seteuid( getuid() ) == 0 ) {
         if ( quotactl( vol->v_path, QCMD(Q_GETQUOTA, USRQUOTA),
@@ -256,7 +262,7 @@ struct dqblk        *dq;
         return( AFPERR_PARAM );
     }
 
-    if (ngroups == 1)
+    if (ngroups >= 1)
         quotactl(QCMD(Q_GETQUOTA, GRPQUOTA), vol->v_gvs,
                  groups[0], (char *) &dqg);
 #endif  /* BSD4_4 */
@@ -304,13 +310,13 @@ const u_int32_t     bsize;
 
     if ( vol->v_qfd == -1 && vol->v_gvs == NULL) {
         if (( p = mountp( vol->v_path, &vol->v_nfs)) == NULL ) {
-            syslog( LOG_INFO, "getquota: mountp %s fails", vol->v_path );
+            LOG(log_info, logtype_afpd, "getquota: mountp %s fails", vol->v_path );
             return( AFPERR_PARAM );
         }
 
         if (vol->v_nfs) {
             if (( vol->v_gvs = (char *)malloc( strlen( p ) + 1 )) == NULL ) {
-                syslog( LOG_ERR, "getquota: malloc: %m" );
+                LOG(log_error, logtype_afpd, "getquota: malloc: %s", strerror(errno) );
                 return AFPERR_MISC;
             }
             strcpy( vol->v_gvs, p );
@@ -318,7 +324,7 @@ const u_int32_t     bsize;
         } else {
             sprintf( buf, "%s/quotas", p );
             if (( vol->v_qfd = open( buf, O_RDONLY, 0 )) < 0 ) {
-                syslog( LOG_INFO, "open %s: %m", buf );
+                LOG(log_info, logtype_afpd, "open %s: %s", buf, strerror(errno) );
                 return( AFPERR_PARAM );
             }
         }
@@ -327,20 +333,55 @@ const u_int32_t     bsize;
 #else
     if ( vol->v_gvs == NULL ) {
         if (( p = special( vol->v_path, &vol->v_nfs )) == NULL ) {
-            syslog( LOG_INFO, "getquota: special %s fails", vol->v_path );
+            LOG(log_info, logtype_afpd, "getquota: special %s fails", vol->v_path );
             return( AFPERR_PARAM );
         }
 
         if (( vol->v_gvs = (char *)malloc( strlen( p ) + 1 )) == NULL ) {
-            syslog( LOG_ERR, "getquota: malloc: %s", strerror(errno) );
+            LOG(log_error, logtype_afpd, "getquota: malloc: %s", strerror(errno) );
             return AFPERR_MISC;
         }
         strcpy( vol->v_gvs, p );
     }
 #endif
 
+#ifdef TRU64
+    /* Digital UNIX: Two forms of specifying an NFS filesystem are possible,
+       either 'hostname:path' or 'path@hostname' (Ultrix heritage) */
+    if (vol->v_nfs) {
+       char *hostpath;
+       char pathstring[MNAMELEN];
+       /* MNAMELEN ist defined in <sys/mount.h> */
+       int result;
+       
+       if ((hostpath = strchr(vol->v_gvs,'@')) != NULL ) {
+           /* convert 'path@hostname' to 'hostname:path',
+            * call getnfsquota(),
+            * convert 'hostname:path' back to 'path@hostname' */
+           *hostpath = '\0';
+           sprintf(pathstring,"%s:%s",hostpath+1,vol->v_gvs);
+           strcpy(vol->v_gvs,pathstring);
+           
+           result = getnfsquota(vol, uuid, bsize, dq);
+           
+           hostpath = strchr(vol->v_gvs,':');
+           *hostpath = '\0';
+           sprintf(pathstring,"%s@%s",hostpath+1,vol->v_gvs);
+           strcpy(vol->v_gvs,pathstring);
+           
+           return result;
+       }
+       else
+           /* vol->v_gvs is of the form 'hostname:path' */
+           return getnfsquota(vol, uuid, bsize, dq);
+    } else
+       /* local filesystem */
+       return getfsquota(vol, uuid, dq);
+          
+#else /* TRU64 */
     return vol->v_nfs ? getnfsquota(vol, uuid, bsize, dq) :
            getfsquota(vol, uuid, dq);
+#endif /* TRU64 */
 }
 
 static int overquota( dqblk )
@@ -357,10 +398,10 @@ struct dqblk      *dqblk;
     }
 #else /* ultrix */
     if ( gettimeofday( &tv, 0 ) < 0 ) {
-        syslog( LOG_ERR, "overquota: gettimeofday: %s", strerror(errno) );
+        LOG(log_error, logtype_afpd, "overquota: gettimeofday: %s", strerror(errno) );
         return( AFPERR_PARAM );
     }
-    if ( !dqblk->dqb_btimelimit || dqblk->dqb_btimelimit > tv.tv_sec ) {
+    if ( dqblk->dqb_btimelimit && dqblk->dqb_btimelimit > tv.tv_sec ) {
         return( 0 );
     }
 #endif /* ultrix */
@@ -407,9 +448,15 @@ const u_int32_t bsize;
     if (dqblk.dqb_bsoftlimit == 0 && dqblk.dqb_bhardlimit == 0) {
         *btotal = *bfree = ~((VolSpace) 0);
     } else if ( overquota( &dqblk )) {
-        *btotal = tobytes( dqblk.dqb_bhardlimit, bsize );
-        *bfree = tobytes( dqblk.dqb_bhardlimit, bsize ) -
-                 tobytes( dqblk.dqb_curblocks, bsize );
+        if ( tobytes( dqblk.dqb_curblocks, bsize ) > tobytes( dqblk.dqb_bhardlimit, bsize ) ) {
+            *btotal = tobytes( dqblk.dqb_curblocks, bsize );
+            *bfree = 0;
+        }
+        else {
+            *btotal = tobytes( dqblk.dqb_bhardlimit, bsize );
+            *bfree = tobytes( dqblk.dqb_bhardlimit, bsize ) -
+                     tobytes( dqblk.dqb_curblocks, bsize );
+        }
     } else {
         *btotal = tobytes( dqblk.dqb_bsoftlimit, bsize );
         *bfree = tobytes( dqblk.dqb_bsoftlimit, bsize  ) -