From patchwork Sat Nov 3 12:50:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1692371 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 BC4E1DFB7B for ; Sat, 3 Nov 2012 12:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932413Ab2KCMvE (ORCPT ); Sat, 3 Nov 2012 08:51:04 -0400 Received: from mail-gg0-f174.google.com ([209.85.161.174]:64925 "EHLO mail-gg0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932075Ab2KCMvD (ORCPT ); Sat, 3 Nov 2012 08:51:03 -0400 Received: by mail-gg0-f174.google.com with SMTP id k5so779725ggd.19 for ; Sat, 03 Nov 2012 05:51:03 -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=zJO4L/F8HuX8L1UqvDqO4P3O12Ksr9s7RNr/fJwgKCM=; b=m5MnNPdN39bNYf5rmEzMHUX6dvETs5w/Opb66uNNAMaktDtwcOprQRkCTM7Ni0llXr VpY2kaeeta2rAVNcRyRe8PjCfBB2fY+PTs64EZ65Lwkb5fCE0SG+WXjRALbR7WGRuP3S VnNXolo0XcFV8gJc49d03l+zLxePNNetxrREbG5yxHkWI+ZjS8X8bzHzLW/Y/dwDJkCp 6ayWVBLG2MLjJP/CDD6/Ja+ZWUk3S1zMApdDtzajKsKjjCKJektaR1on6Wk6VSN4agqG Dudg4gSlCzeNlIzsNIZ3Bmo7G0QCWdTzCLNyF5KELateUGZZ1J3X18/DCoNpUyYQUXDf QNKA== Received: by 10.236.77.39 with SMTP id c27mr4326553yhe.102.1351947063394; Sat, 03 Nov 2012 05:51:03 -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.51.01 (version=SSLv3 cipher=OTHER); Sat, 03 Nov 2012 05:51:02 -0700 (PDT) From: Jeff Layton To: linux-cifs@vger.kernel.org Cc: shirishpargaonkar@gmail.com Subject: [PATCH 15/17] getcifsacl: fix endianness before handing off SID to winbind Date: Sat, 3 Nov 2012 08:50:32 -0400 Message-Id: <1351947034-18876-16-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: ALoCoQk1sunFi2FqqPbhz4/0KO5vqsOMxkOGaJwOgcuR6madf1geyVhanK4MtS6XLt9o4h62bEAc Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org winbind expects SIDs to be expressed in host-endian. Convert them from little-endian before asking winbind to convert them to names. Also use the WBC_ERROR_IS_OK() macro to check the return code. Signed-off-by: Jeff Layton --- getcifsacl.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/getcifsacl.c b/getcifsacl.c index 083705c..f7e6d4f 100644 --- a/getcifsacl.c +++ b/getcifsacl.c @@ -171,6 +171,19 @@ print_ace_type(uint8_t acetype, int raw) } } +/* + * Winbind keeps wbcDomainSid fields in host-endian. So, we must convert from + * little endian here so that winbind will understand correctly. + */ +static void +convert_sid_endianness(struct wbcDomainSid *sid) +{ + int i; + + for (i = 0; i < sid->num_subauth; i++) + sid->sub_auth[i] = le32toh(sid->sub_auths[i]); +} + static void print_sid(struct wbcDomainSid *sidptr, int raw) { @@ -182,11 +195,13 @@ print_sid(struct wbcDomainSid *sidptr, int raw) char *sidname = NULL; enum wbcSidType sntype; + convert_sid_endianness(sidptr); + if (raw) goto print_sid_raw; rc = wbcLookupSid(sidptr, &domain_name, &sidname, &sntype); - if (!rc) { + if (WBC_ERROR_IS_OK(rc)) { printf("%s", domain_name); if (strlen(domain_name)) printf("%c", '\\'); @@ -202,7 +217,7 @@ print_sid_raw: if (sidptr->id_auth[i]) printf("-%d", sidptr->id_auth[i]); for (i = 0; i < num_auths; i++) - printf("-%u", le32toh(sidptr->sub_auths[i])); + printf("-%u", sidptr->sub_auths[i]); } static void