getcifsacl: fix endianness before handing off SID to winbind
authorJeff Layton <jlayton@samba.org>
Wed, 7 Nov 2012 15:19:18 +0000 (10:19 -0500)
committerJeff Layton <jlayton@samba.org>
Wed, 7 Nov 2012 15:19:18 +0000 (10:19 -0500)
winbind expects SIDs to be expressed in host-endian. Convert them
from little-endian before asking winbind to convert them to names.

Also use the WBC_ERROR_IS_OK() macro to check the return code.

Signed-off-by: Jeff Layton <jlayton@samba.org>
getcifsacl.c

index 083705cd4545e635b0689decd9b362e5b2bdf34c..f7e6d4f7dc6f627931a0286e3db677ae52bb5f50 100644 (file)
@@ -171,6 +171,19 @@ print_ace_type(uint8_t acetype, int raw)
        }
 }
 
+/*
+ * Winbind keeps wbcDomainSid fields in host-endian. So, we must convert from
+ * little endian here so that winbind will understand correctly.
+ */
+static void
+convert_sid_endianness(struct wbcDomainSid *sid)
+{
+       int i;
+
+       for (i = 0; i < sid->num_subauth; i++)
+               sid->sub_auth[i] = le32toh(sid->sub_auths[i]);
+}
+
 static void
 print_sid(struct wbcDomainSid *sidptr, int raw)
 {
@@ -182,11 +195,13 @@ print_sid(struct wbcDomainSid *sidptr, int raw)
        char *sidname = NULL;
        enum wbcSidType sntype;
 
+       convert_sid_endianness(sidptr);
+
        if (raw)
                goto print_sid_raw;
 
        rc = wbcLookupSid(sidptr, &domain_name, &sidname, &sntype);
-       if (!rc) {
+       if (WBC_ERROR_IS_OK(rc)) {
                printf("%s", domain_name);
                if (strlen(domain_name))
                        printf("%c", '\\');
@@ -202,7 +217,7 @@ print_sid_raw:
                if (sidptr->id_auth[i])
                        printf("-%d", sidptr->id_auth[i]);
        for (i = 0; i < num_auths; i++)
-               printf("-%u", le32toh(sidptr->sub_auths[i]));
+               printf("-%u", sidptr->sub_auths[i]);
 }
 
 static void