cifs: redefine NUM_SUBAUTH constant from 5 to 15
[pandora-kernel.git] / fs / cifs / cifsacl.c
index d35579a..dd8d3df 100644 (file)
@@ -210,7 +210,7 @@ sid_to_str(struct cifs_sid *sidptr, char *sidstr)
        sprintf(strptr, "-%d", sidptr->revision);
        strptr = sidstr + strlen(sidstr);
 
-       for (i = 0; i < 6; ++i) {
+       for (i = 0; i < NUM_AUTHS; ++i) {
                if (sidptr->authority[i]) {
                        sprintf(strptr, "-%d", sidptr->authority[i]);
                        strptr = sidstr + strlen(sidstr);
@@ -224,11 +224,67 @@ sid_to_str(struct cifs_sid *sidptr, char *sidstr)
        }
 }
 
+/*
+ * if the two SIDs (roughly equivalent to a UUID for a user or group) are
+ * the same returns zero, if they do not match returns non-zero.
+ */
+static int
+compare_sids(const struct cifs_sid *ctsid, const struct cifs_sid *cwsid)
+{
+       int i;
+       int num_subauth, num_sat, num_saw;
+
+       if ((!ctsid) || (!cwsid))
+               return 1;
+
+       /* compare the revision */
+       if (ctsid->revision != cwsid->revision) {
+               if (ctsid->revision > cwsid->revision)
+                       return 1;
+               else
+                       return -1;
+       }
+
+       /* compare all of the six auth values */
+       for (i = 0; i < NUM_AUTHS; ++i) {
+               if (ctsid->authority[i] != cwsid->authority[i]) {
+                       if (ctsid->authority[i] > cwsid->authority[i])
+                               return 1;
+                       else
+                               return -1;
+               }
+       }
+
+       /* compare all of the subauth values if any */
+       num_sat = ctsid->num_subauth;
+       num_saw = cwsid->num_subauth;
+       num_subauth = num_sat < num_saw ? num_sat : num_saw;
+       if (num_subauth) {
+               for (i = 0; i < num_subauth; ++i) {
+                       if (ctsid->sub_auth[i] != cwsid->sub_auth[i]) {
+                               if (le32_to_cpu(ctsid->sub_auth[i]) >
+                                       le32_to_cpu(cwsid->sub_auth[i]))
+                                       return 1;
+                               else
+                                       return -1;
+                       }
+               }
+       }
+
+       return 0; /* sids compare/match */
+}
+
 static void
 cifs_copy_sid(struct cifs_sid *dst, const struct cifs_sid *src)
 {
-       memcpy(dst, src, sizeof(*dst));
-       dst->num_subauth = min_t(u8, src->num_subauth, NUM_SUBAUTHS);
+       int i;
+
+       dst->revision = src->revision;
+       dst->num_subauth = min_t(u8, src->num_subauth, SID_MAX_SUB_AUTHORITIES);
+       for (i = 0; i < NUM_AUTHS; ++i)
+               dst->authority[i] = src->authority[i];
+       for (i = 0; i < dst->num_subauth; ++i)
+               dst->sub_auth[i] = src->sub_auth[i];
 }
 
 static void
@@ -327,7 +383,7 @@ id_to_sid(unsigned long cid, uint sidtype, struct cifs_sid *ssid)
                if (!npsidid)
                        return -ENOMEM;
 
-               npsidid->sidstr = kmalloc(SIDLEN, GFP_KERNEL);
+               npsidid->sidstr = kmalloc(SID_STRING_MAX, GFP_KERNEL);
                if (!npsidid->sidstr) {
                        kfree(npsidid);
                        return -ENOMEM;
@@ -377,7 +433,7 @@ id_to_sid(unsigned long cid, uint sidtype, struct cifs_sid *ssid)
                if (IS_ERR(sidkey)) {
                        rc = -EINVAL;
                        cFYI(1, "%s: Can't map and id to a SID", __func__);
-               } else if (sidkey->datalen < sizeof(struct cifs_sid)) {
+               } else if (sidkey->datalen < CIFS_SID_BASE_SIZE) {
                        rc = -EIO;
                        cFYI(1, "%s: Downcall contained malformed key "
                                "(datalen=%hu)", __func__, sidkey->datalen);
@@ -444,7 +500,7 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid,
                if (!npsidid)
                        return -ENOMEM;
 
-               npsidid->sidstr = kmalloc(SIDLEN, GFP_KERNEL);
+               npsidid->sidstr = kmalloc(SID_STRING_MAX, GFP_KERNEL);
                if (!npsidid->sidstr) {
                        kfree(npsidid);
                        return -ENOMEM;
@@ -630,54 +686,6 @@ cifs_destroy_idmaptrees(void)
        spin_unlock(&gidsidlock);
 }
 
-/* if the two SIDs (roughly equivalent to a UUID for a user or group) are
-   the same returns 1, if they do not match returns 0 */
-int compare_sids(const struct cifs_sid *ctsid, const struct cifs_sid *cwsid)
-{
-       int i;
-       int num_subauth, num_sat, num_saw;
-
-       if ((!ctsid) || (!cwsid))
-               return 1;
-
-       /* compare the revision */
-       if (ctsid->revision != cwsid->revision) {
-               if (ctsid->revision > cwsid->revision)
-                       return 1;
-               else
-                       return -1;
-       }
-
-       /* compare all of the six auth values */
-       for (i = 0; i < 6; ++i) {
-               if (ctsid->authority[i] != cwsid->authority[i]) {
-                       if (ctsid->authority[i] > cwsid->authority[i])
-                               return 1;
-                       else
-                               return -1;
-               }
-       }
-
-       /* compare all of the subauth values if any */
-       num_sat = ctsid->num_subauth;
-       num_saw = cwsid->num_subauth;
-       num_subauth = num_sat < num_saw ? num_sat : num_saw;
-       if (num_subauth) {
-               for (i = 0; i < num_subauth; ++i) {
-                       if (ctsid->sub_auth[i] != cwsid->sub_auth[i]) {
-                               if (le32_to_cpu(ctsid->sub_auth[i]) >
-                                       le32_to_cpu(cwsid->sub_auth[i]))
-                                       return 1;
-                               else
-                                       return -1;
-                       }
-               }
-       }
-
-       return 0; /* sids compare/match */
-}
-
-
 /* copy ntsd, owner sid, and group sid from a security descriptor to another */
 static void copy_sec_desc(const struct cifs_ntsd *pntsd,
                                struct cifs_ntsd *pnntsd, __u32 sidsoffset)
@@ -811,7 +819,7 @@ static __u16 fill_ace_for_sid(struct cifs_ace *pntace,
 
        pntace->sid.revision = psid->revision;
        pntace->sid.num_subauth = psid->num_subauth;
-       for (i = 0; i < 6; i++)
+       for (i = 0; i < NUM_AUTHS; i++)
                pntace->sid.authority[i] = psid->authority[i];
        for (i = 0; i < psid->num_subauth; i++)
                pntace->sid.sub_auth[i] = psid->sub_auth[i];