summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Layton <jlayton@samba.org>2012-11-09 06:40:14 -0500
committerJeff Layton <jlayton@samba.org>2012-11-09 06:48:23 -0500
commitea0441d56862538b6c72ebbe085f98d9da8e14ea (patch)
treea0958bc0d0123935eeb426c3b91f3242d20e2e0a
parentec80b4feeb2a86b3661e9c710b942196492a9af4 (diff)
downloadcifs-utils-ea0441d56862538b6c72ebbe085f98d9da8e14ea.tar.gz
cifs-utils-ea0441d56862538b6c72ebbe085f98d9da8e14ea.tar.bz2
cifs-utils-ea0441d56862538b6c72ebbe085f98d9da8e14ea.zip
setcifsacl: don't freely cast between wbcDomainSid and cifs_sid
Since they are not necessarily aligned the same and potentially store their fields with different endianness. Copy from the wbcDomainSid to the cifs_sid as appropriate. Also rename the same function in cifs.idmap.c for consistency. Signed-off-by: Jeff Layton <jlayton@samba.org>
-rw-r--r--cifs.idmap.c6
-rw-r--r--setcifsacl.c36
2 files changed, 27 insertions, 15 deletions
diff --git a/cifs.idmap.c b/cifs.idmap.c
index 24bec00..792ea58 100644
--- a/cifs.idmap.c
+++ b/cifs.idmap.c
@@ -106,7 +106,7 @@ str_to_uint(const char *src, unsigned int *dst)
* wsid to the csid, while converting the subauthority fields to LE.
*/
static void
-convert_sid(struct cifs_sid *csid, struct wbcDomainSid *wsid)
+wsid_to_csid(struct cifs_sid *csid, struct wbcDomainSid *wsid)
{
int i;
@@ -196,7 +196,7 @@ cifs_idmap(const key_serial_t key, const char *key_descr)
struct cifs_sid csid;
/* SID has been mapped to a uid */
- convert_sid(&csid, &sid);
+ wsid_to_csid(&csid, &sid);
rc = keyctl_instantiate(key, &csid,
sizeof(struct cifs_sid), 0);
if (rc)
@@ -224,7 +224,7 @@ cifs_idmap(const key_serial_t key, const char *key_descr)
struct cifs_sid csid;
/* SID has been mapped to a gid */
- convert_sid(&csid, &sid);
+ wsid_to_csid(&csid, &sid);
rc = keyctl_instantiate(key, &csid,
sizeof(struct cifs_sid), 0);
if (rc)
diff --git a/setcifsacl.c b/setcifsacl.c
index 30d5905..465f195 100644
--- a/setcifsacl.c
+++ b/setcifsacl.c
@@ -379,20 +379,37 @@ build_fetched_aces_err:
return NULL;
}
-static int
-verify_ace_sid(char *sidstr, struct cifs_sid *sid)
+/*
+ * Winbind keeps wbcDomainSid fields in host-endian. Copy fields from the
+ * wsid to the csid, while converting the subauthority fields to LE.
+ */
+static void
+wsid_to_csid(struct cifs_sid *csid, struct wbcDomainSid *wsid)
{
int i;
+
+ csid->revision = wsid->sid_rev_num;
+ csid->num_subauth = wsid->num_auths;
+ for (i = 0; i < NUM_AUTHS; i++)
+ csid->authority[i] = wsid->id_auth[i];
+ for (i = 0; i < wsid->num_auths; i++)
+ csid->sub_auth[i] = htole32(wsid->sub_auths[i]);
+}
+
+static int
+verify_ace_sid(char *sidstr, struct cifs_sid *csid)
+{
wbcErr rc;
char *name, *domain;
enum wbcSidType type;
+ struct wbcDomainSid wsid;
name = strchr(sidstr, '\\');
if (!name) {
/* might be a raw string representation of SID */
- rc = wbcStringToSid(sidstr, (struct wbcDomainSid *)sid);
+ rc = wbcStringToSid(sidstr, &wsid);
if (WBC_ERROR_IS_OK(rc))
- goto fix_endianness;
+ goto convert_sid;
domain = "";
name = sidstr;
@@ -402,20 +419,15 @@ verify_ace_sid(char *sidstr, struct cifs_sid *sid)
++name;
}
- rc = wbcLookupName(domain, name, (struct wbcDomainSid *)sid, &type);
+ rc = wbcLookupName(domain, name, &wsid, &type);
if (!WBC_ERROR_IS_OK(rc)) {
printf("%s: Error converting %s\\%s to SID: %s\n",
__func__, domain, name, wbcErrorString(rc));
return rc;
}
-fix_endianness:
- /*
- * Winbind keeps wbcDomainSid fields in host-endian. So, we must
- * convert that to little endian since the server will expect that.
- */
- for (i = 0; i < sid->num_subauth; i++)
- sid->sub_auth[i] = htole32(sid->sub_auth[i]);
+convert_sid:
+ wsid_to_csid(csid, &wsid);
return 0;
}