From patchwork Sat Nov 3 12:50:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1692311 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 38CEDDFB7B for ; Sat, 3 Nov 2012 12:50:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932295Ab2KCMuy (ORCPT ); Sat, 3 Nov 2012 08:50:54 -0400 Received: from mail-ye0-f174.google.com ([209.85.213.174]:38739 "EHLO mail-ye0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932075Ab2KCMuy (ORCPT ); Sat, 3 Nov 2012 08:50:54 -0400 Received: by mail-ye0-f174.google.com with SMTP id m12so792835yen.19 for ; Sat, 03 Nov 2012 05:50:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=Ifo0xQ6lWaLdvk0vOf9EozcycHrmR0bTe83e91OLAIc=; b=OODmWF2G8QdU3K5vFqC3bLq1TI6+KT9ZDE98BZ71ERO/Jjn6lS+H4uIcbMjIhAe+Gc kIA5pgzBgt5Pld4DbfMwDc2hFZLp5+je3rQ6M20REbpTJDB1LgYUBwtw1MLRoraSTdSo 6NcICPR4ZJIINr86cn3ex0EwCBDWXTMe5B9YRnzdIs5X0+Ppj2aQQRZtdl7OBPj9UPP3 nmVYZ5H//o9SVAY73NeVora3v9iRpR76PziK/NF6ln0yRYQ0g1TG1gFroIZjI4R230cV H3aKM7FgpfMXG//E4gXDUwWt8PcksBQKXV4VEdMXHXru99Kvq7ymqltjy+OOhA8PjgT1 cavQ== Received: by 10.236.52.198 with SMTP id e46mr4294052yhc.57.1351947054124; Sat, 03 Nov 2012 05:50:54 -0700 (PDT) Received: from salusa.poochiereds.net (cpe-107-015-110-129.nc.res.rr.com. [107.15.110.129]) by mx.google.com with ESMTPS id n13sm11145727ano.20.2012.11.03.05.50.52 (version=SSLv3 cipher=OTHER); Sat, 03 Nov 2012 05:50:53 -0700 (PDT) From: Jeff Layton To: linux-cifs@vger.kernel.org Cc: shirishpargaonkar@gmail.com Subject: [PATCH 09/17] cifs.idmap: fix endianness on SIDs before sending to kernel Date: Sat, 3 Nov 2012 08:50:26 -0400 Message-Id: <1351947034-18876-10-git-send-email-jlayton@samba.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1351947034-18876-1-git-send-email-jlayton@samba.org> References: <1351947034-18876-1-git-send-email-jlayton@samba.org> X-Gm-Message-State: ALoCoQl3TQdLc83E7HoDYQAOflZFuBZgp4Bk72BYsBb2qrR3AQUl/JbPtNmgUjjdpAeSntRXJ2ew Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org 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 --- cifs.idmap.c | 23 +++++++++++++++++++++-- 1 file 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 #include +#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)