summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Layton <jlayton@samba.org>2012-11-07 10:19:16 -0500
committerJeff Layton <jlayton@samba.org>2012-11-07 10:19:16 -0500
commit47400ee5dcdda7e7b77b536f4befb5c04c1c5144 (patch)
tree3fb8c61dd6ed4566c1f0d858ac08a92051e2ee71
parent78a2a8b9c6b5ce040122f87e6000636ca8574544 (diff)
downloadcifs-utils-47400ee5dcdda7e7b77b536f4befb5c04c1c5144.tar.gz
cifs-utils-47400ee5dcdda7e7b77b536f4befb5c04c1c5144.tar.bz2
cifs-utils-47400ee5dcdda7e7b77b536f4befb5c04c1c5144.zip
cifs.idmap: fix endianness on SIDs before sending to kernel
Winbind keeps wbcDomainSids in host-endian format. They must be converted to little-endian before we can ship them off to the kernel. Signed-off-by: Jeff Layton <jlayton@samba.org>
-rw-r--r--cifs.idmap.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/cifs.idmap.c b/cifs.idmap.c
index d2ccbb1..4109ca0 100644
--- a/cifs.idmap.c
+++ b/cifs.idmap.c
@@ -42,6 +42,8 @@
#include <limits.h>
#include <wbclient.h>
+#include "cifsacl.h"
+
static const char *prog = "cifs.idmap";
static const struct option long_options[] = {
@@ -99,6 +101,19 @@ str_to_uint(const char *src, unsigned int *dst)
return 0;
}
+/*
+ * Winbind keeps wbcDomainSid fields in host-endian. So, we must convert it
+ * to little endian since the kernel will expect that.
+ */
+static void
+convert_sid_endianness(struct cifs_sid *sid)
+{
+ int i;
+
+ for (i = 0; i < sid->num_subauth; i++)
+ sid->sub_auth[i] = htole32(sid->sub_auth[i]);
+}
+
static int
cifs_idmap(const key_serial_t key, const char *key_descr)
{
@@ -173,7 +188,9 @@ cifs_idmap(const key_serial_t key, const char *key_descr)
rc = wbcUidToSid(uid, &sid);
if (rc)
syslog(LOG_DEBUG, "uid %u to SID error: %d", uid, rc);
- if (!rc) { /* SID has been mapped to a uid */
+ if (!rc) {
+ /* SID has been mapped to a uid */
+ convert_sid_endianness((struct cifs_sid *)&sid);
rc = keyctl_instantiate(key, &sid,
sizeof(struct wbcDomainSid), 0);
if (rc)
@@ -197,7 +214,9 @@ cifs_idmap(const key_serial_t key, const char *key_descr)
rc = wbcGidToSid(gid, &sid);
if (rc)
syslog(LOG_DEBUG, "gid %u to SID error: %d", gid, rc);
- if (!rc) { /* SID has been mapped to a gid */
+ if (!rc) {
+ /* SID has been mapped to a gid */
+ convert_sid_endianness((struct cifs_sid *)&sid);
rc = keyctl_instantiate(key, &sid,
sizeof(struct wbcDomainSid), 0);
if (rc)