@@ -60,7 +60,7 @@ static void usage(void)
char *strget(const char *str, const char *substr)
{
- int len, sublen, retlen;
+ int sublen;
char *substrptr;
/* find the prefix */
@@ -102,16 +102,20 @@ str_to_uint(const char *src, unsigned int *dst)
}
/*
- * Winbind keeps wbcDomainSid fields in host-endian. So, we must convert it
- * to little endian since the kernel will expect that.
+ * Winbind keeps wbcDomainSid fields in host-endian. Copy fields from the
+ * wsid to the csid, while converting the subauthority fields to LE.
*/
static void
-convert_sid_endianness(struct cifs_sid *sid)
+convert_sid(struct cifs_sid *csid, struct wbcDomainSid *wsid)
{
int i;
- for (i = 0; i < sid->num_subauth; i++)
- sid->sub_auth[i] = htole32(sid->sub_auth[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
@@ -189,10 +193,12 @@ cifs_idmap(const key_serial_t key, const char *key_descr)
if (rc)
syslog(LOG_DEBUG, "uid %u to SID error: %d", uid, rc);
if (!rc) {
+ struct cifs_sid csid;
+
/* SID has been mapped to a uid */
- convert_sid_endianness((struct cifs_sid *)&sid);
- rc = keyctl_instantiate(key, &sid,
- sizeof(struct wbcDomainSid), 0);
+ convert_sid(&csid, &sid);
+ rc = keyctl_instantiate(key, &csid,
+ sizeof(struct cifs_sid), 0);
if (rc)
syslog(LOG_ERR, "%s: key inst: %s",
__func__, strerror(errno));
@@ -215,10 +221,12 @@ cifs_idmap(const key_serial_t key, const char *key_descr)
if (rc)
syslog(LOG_DEBUG, "gid %u to SID error: %d", gid, rc);
if (!rc) {
+ struct cifs_sid csid;
+
/* SID has been mapped to a gid */
- convert_sid_endianness((struct cifs_sid *)&sid);
- rc = keyctl_instantiate(key, &sid,
- sizeof(struct wbcDomainSid), 0);
+ convert_sid(&csid, &sid);
+ rc = keyctl_instantiate(key, &csid,
+ sizeof(struct cifs_sid), 0);
if (rc)
syslog(LOG_ERR, "%s: key inst: %s",
__func__, strerror(errno));
Get rid of some unused variables, and fix a strict-aliasing problem by copying the SID data to a new place instead of converting the endianness in-place. Signed-off-by: Jeff Layton <jlayton@samba.org> --- cifs.idmap.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)