From patchwork Fri Nov 9 12:04: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: 1720201 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id BA0B23FCDF for ; Fri, 9 Nov 2012 12:04:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753073Ab2KIMEf (ORCPT ); Fri, 9 Nov 2012 07:04:35 -0500 Received: from mail-qa0-f46.google.com ([209.85.216.46]:47557 "EHLO mail-qa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753042Ab2KIMEe (ORCPT ); Fri, 9 Nov 2012 07:04:34 -0500 Received: by mail-qa0-f46.google.com with SMTP id c11so147047qad.19 for ; Fri, 09 Nov 2012 04:04:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=5wKaMInvkAIIGoCh7GNQZarw9l33v0vF/KeRaVt4/Rw=; b=FvDQodM9inE0S+dVMpD47BpQ8Shb24BUpPIzr62gBj5G0Y2DywikqXceGBxkZZQj16 9HBgcqAgs3JjLMEUrDjb/+ZyAbTmnxeKNTGbvWB9I6CWFqGDPUBMEbqnE8/QtWRiY50V HyXigdDHUpYzWazmqYDbCtn/5YgWBpXCX/PWscleIoeEc7zz6irTEDRwFHyK1b/WJGEr duwJa2/euJONlmteni0zoQadnx4YibXOiDh03O96Zpri1Op/tqxLv9Wo5ueXMG+ZbZqq 8uiSzUCyRRPbZhAlwdnDnvwHeIXYZfD2YY/6liBMdxjw5lAqfY/k2M13RHEM6pqkOQKQ g7AQ== Received: by 10.49.75.40 with SMTP id z8mr1512037qev.25.1352462674195; Fri, 09 Nov 2012 04:04:34 -0800 (PST) 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 hw8sm17783546qab.9.2012.11.09.04.04.32 (version=SSLv3 cipher=OTHER); Fri, 09 Nov 2012 04:04:33 -0800 (PST) From: Jeff Layton To: linux-cifs@vger.kernel.org Subject: [PATCH 2/2] setcifsacl: don't freely cast between wbcDomainSid and cifs_sid Date: Fri, 9 Nov 2012 07:04:26 -0500 Message-Id: <1352462666-10910-2-git-send-email-jlayton@samba.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1352462666-10910-1-git-send-email-jlayton@samba.org> References: <1352462666-10910-1-git-send-email-jlayton@samba.org> X-Gm-Message-State: ALoCoQler4KEUy69bXMh0Q2j2xCShyA/U5SqYucgaMVDMbNQ+aJT/6j4V7DUh9oHXC52jZ2lGjBY Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org 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 --- cifs.idmap.c | 6 +++--- setcifsacl.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 14 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..cd46045 100644 --- a/setcifsacl.c +++ b/setcifsacl.c @@ -379,20 +379,38 @@ build_fetched_aces_err: return NULL; } +/* + * 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 *sid) +verify_ace_sid(char *sidstr, struct cifs_sid *csid) { int i; 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 +420,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; }