]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/quota.c
Replace relevant direct seteuid() calls with calls to (un)become_root()
[netatalk.git] / etc / afpd / quota.c
index 5887c6d60da1f853bb1eb0c2cda1e5f01d267992..6903a21610ab421bbd3560569ae0e3cb30131d45 100644 (file)
@@ -25,6 +25,7 @@
 #include <atalk/logger.h>
 #include <atalk/afp.h>
 #include <atalk/compat.h>
+#include <atalk/unix.h>
 
 #include "auth.h"
 #include "volume.h"
@@ -34,8 +35,8 @@
 #include <quota/quota.h>
 
 static int
-getfreespace(struct vol *vol, VolSpace *bfree, VolSpace *btotal,
-    uid_t uid, const char *classq)
+getfreespace(const AFPObj *obj, struct vol *vol, VolSpace *bfree, VolSpace *btotal,
+            uid_t uid, const char *classq)
 {
        int retq;
        struct ufs_quota_entry ufsq[QUOTA_NLIMITS];
@@ -47,16 +48,15 @@ getfreespace(struct vol *vol, VolSpace *bfree, VolSpace *btotal,
                return -1;
        }
 
-       if ( seteuid( getuid() ) != 0 )  {
-               LOG(log_info, logtype_afpd, "seteuid(): %s",
-                   strerror(errno));
-               return -1;
-       }
-       if ((retq = getfsquota(vol->v_path, ufsq, uid, classq)) < 0) {
+    become_root();
+
+       if ((retq = getfsquota(obj, vol, ufsq, uid, classq)) < 0) {
                LOG(log_info, logtype_afpd, "getfsquota(%s, %s): %s",
                    vol->v_path, classq, strerror(errno));
        }
-        seteuid( uid );
+
+    unbecome_root();
+
        if (retq < 1)
                return retq;
 
@@ -78,19 +78,19 @@ getfreespace(struct vol *vol, VolSpace *bfree, VolSpace *btotal,
        return 1;
 }
 
-int uquota_getvolspace( struct vol *vol, VolSpace *bfree, VolSpace *btotal, const u_int32_t bsize)
+int uquota_getvolspace(const AFPObj *obj, struct vol *vol, VolSpace *bfree, VolSpace *btotal, const u_int32_t bsize)
 {
        int uretq, gretq;
        VolSpace ubfree, ubtotal;
        VolSpace gbfree, gbtotal;
 
-       uretq = getfreespace(vol, &ubfree, &ubtotal,
-           uuid, QUOTADICT_CLASS_USER);
+       uretq = getfreespace(obj, vol, &ubfree, &ubtotal,
+                            uuid, QUOTADICT_CLASS_USER);
        LOG(log_info, logtype_afpd, "getfsquota(%s): %d %d",
            vol->v_path, (int)ubfree, (int)ubtotal);
-       if (ngroups >= 1) {
+       if (obj->ngroups >= 1) {
                gretq = getfreespace(vol, &ubfree, &ubtotal,
-                   groups[0], QUOTADICT_CLASS_GROUP);
+                   obj->groups[0], QUOTADICT_CLASS_GROUP);
        } else
                gretq = -1;
        if (uretq < 1 && gretq < 1) { /* no quota for this fs */
@@ -501,7 +501,7 @@ special(char *file, int *nfs)
 #endif /* __svr4__ */
 
 
-static int getfsquota(struct vol *vol, const int uid, struct dqblk *dq)
+static int getfsquota(const AFPObj *obj, struct vol *vol, const int uid, struct dqblk *dq)
 
 {
        struct dqblk dqg;
@@ -541,29 +541,19 @@ static int getfsquota(struct vol *vol, const int uid, struct dqblk *dq)
 #endif /* TRU64 */
 
 #ifdef BSD4_4
-    if ( seteuid( getuid() ) == 0 ) {
+    become_root();
         if ( quotactl( vol->v_path, QCMD(Q_GETQUOTA,USRQUOTA),
                        uid, (char *)dq ) != 0 ) {
             /* try group quotas */
-            if (ngroups >= 1) {
+            if (obj->ngroups >= 1) {
                 if ( quotactl(vol->v_path, QCMD(Q_GETQUOTA, GRPQUOTA),
-                              groups[0], (char *) &dqg) != 0 ) {
-                    seteuid( uid );
+                              obj->groups[0], (char *) &dqg) != 0 ) {
+                    unbecome_root();
                     return( AFPERR_PARAM );
                 }
             }
         }
-        seteuid( uid );
-    }
-
-#elif defined(TRU64)
-    if ( seteuid( getuid() ) == 0 ) {
-        if ( quotactl( vol->v_path, QCMD(Q_GETQUOTA, USRQUOTA),
-                       uid, (char *)dq ) != 0 ) {
-            seteuid( uid );
-            return ( AFPERR_PARAM );
-        }
-        seteuid( uid );
+        unbecome_root();
     }
 
 #else /* BSD4_4 */
@@ -690,11 +680,11 @@ static int getquota(const AFPObj *obj, struct vol *vol, struct dqblk *dq, const
            return getnfsquota(vol, uuid, bsize, dq);
     } else
        /* local filesystem */
-       return getfsquota(vol, uuid, dq);
+      return getfsquota(obj, vol, obj->uid, dq);
           
 #else /* TRU64 */
     return vol->v_nfs ? getnfsquota(vol, obj->uid, bsize, dq) :
-           getfsquota(vol, obj->uid, dq);
+      getfsquota(obj, vol, obj->uid, dq);
 #endif /* TRU64 */
 }