]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/hfs/hfs_quota.c
xnu-792.25.20.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_quota.c
index 1354664f740b8a61c23d4036dadce14e6e312e43..5a1a459c4afd0b1915f27df9b11924e25dddcf47 100644 (file)
@@ -1,29 +1,23 @@
 /*
  * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * @APPLE_LICENSE_HEADER_START@
  * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. The rights granted to you under the License
- * may not be used to create, or enable the creation or redistribution of,
- * unlawful or unlicensed copies of an Apple operating system, or to
- * circumvent, violate, or enable the circumvention or violation of, any
- * terms of an Apple operating system software license agreement.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License").  You may not use this file except in compliance with the
+ * License.  Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
  * 
- * Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
  * 
- * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ * @APPLE_LICENSE_HEADER_END@
  */
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -169,7 +163,11 @@ hfs_chkdq(cp, change, cred, flags)
                return (0);
        }
        p = current_proc();
-       if (cred == NOCRED)
+       /*
+        * This use of proc_ucred() is safe because kernproc credential never
+        * changes.
+        */
+       if (!IS_VALID_CRED(cred))
                cred = proc_ucred(kernproc);
        if (suser(cred, NULL) || proc_forcequota(p)) {
                for (i = 0; i < MAXQUOTAS; i++) {
@@ -310,7 +308,11 @@ hfs_chkiq(cp, change, cred, flags)
                return (0);
        }
        p = current_proc();
-       if (cred == NOCRED)
+       /*
+        * This use of proc_ucred() is safe because kernproc credential never
+        * changes.
+        */
+       if (!IS_VALID_CRED(cred))
                cred = proc_ucred(kernproc);
        if (suser(cred, NULL) || proc_forcequota(p)) {
                for (i = 0; i < MAXQUOTAS; i++) {
@@ -501,8 +503,8 @@ hfs_quotaon(p, mp, type, fnamep)
        if (error) {
                (void) vnode_close(vp, FREAD|FWRITE, NULL);
 
-               kauth_cred_rele(qfp->qf_cred);
-               qfp->qf_cred = NOCRED;
+               if (IS_VALID_CRED(qfp->qf_cred))
+                       kauth_cred_unref(&qfp->qf_cred);
                qfp->qf_vp = NULLVP;
                goto out;
        }
@@ -569,7 +571,6 @@ hfs_quotaoff(__unused struct proc *p, struct mount *mp, register int type)
        struct hfsmount *hfsmp = VFSTOHFS(mp);
        struct quotafile *qfp;
        int error;
-       kauth_cred_t cred;
        struct hfs_quotaoff_cargs args;
 
        qfp = &hfsmp->hfs_qfiles[type];
@@ -604,11 +605,9 @@ hfs_quotaoff(__unused struct proc *p, struct mount *mp, register int type)
        error = vnode_close(qvp, FREAD|FWRITE, NULL);
 
        qfp->qf_vp = NULLVP;
-       cred = qfp->qf_cred;
-       if (cred != NOCRED) {
-               qfp->qf_cred = NOCRED;
-               kauth_cred_rele(cred);
-       }
+
+       if (IS_VALID_CRED(qfp->qf_cred))
+               kauth_cred_unref(&qfp->qf_cred);
        for (type = 0; type < MAXQUOTAS; type++)
                if (hfsmp->hfs_qfiles[type].qf_vp != NULLVP)
                        break;