From patchwork Sat Nov 3 12:50:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1692351 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 E925BDFB7B for ; Sat, 3 Nov 2012 12:51:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932397Ab2KCMvB (ORCPT ); Sat, 3 Nov 2012 08:51:01 -0400 Received: from mail-yh0-f46.google.com ([209.85.213.46]:44234 "EHLO mail-yh0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932383Ab2KCMvB (ORCPT ); Sat, 3 Nov 2012 08:51:01 -0400 Received: by mail-yh0-f46.google.com with SMTP id m54so749191yhm.19 for ; Sat, 03 Nov 2012 05:51:00 -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=Is6Sd7igXtuoPVSJvl4BlWQ3t3koT+rYvQhaqQeIC/4=; b=GNG9hR2YRheD2Ao2F+I6CCOILKKeRpCkevyjd0TE8rI888TIdbk6pKksfeJp+WXPHT BOGLzHY54dIvjpfyqj9MD0MzUbsJzS5jO5hYquIN5CMd5Y5fEedStJKBdc29yD5JxdUb zhxMuYaW4B9NehzhMpjmCGtQBxqWoscT0jmdkic6Mq+lq4Txc2ZVC2pxvUTFjYt0hZ/u x7sJV/QfpibpX90ASPr0sCXn9kqndIcdJOjyT5TM3+8zLZb0wVTyLrPmrd2Gi0sRfsHW MQy3zaKVY3R2DLM1waXzGsHIjkbQEnHalgOsRLvTulbrFgwXWcoelcj+oqBdjrwNPJU2 rVEw== Received: by 10.236.77.229 with SMTP id d65mr4217930yhe.124.1351947060422; Sat, 03 Nov 2012 05:51:00 -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.58 (version=SSLv3 cipher=OTHER); Sat, 03 Nov 2012 05:50:59 -0700 (PDT) From: Jeff Layton To: linux-cifs@vger.kernel.org Cc: shirishpargaonkar@gmail.com Subject: [PATCH 13/17] setcifsacl: fix verify_ace_sid Date: Sat, 3 Nov 2012 08:50:30 -0400 Message-Id: <1351947034-18876-14-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: ALoCoQmFNVJauLAxdMskF76+dcCT1okg5aTKnnMHewW7A/stgM9J6YW7H37Aq0TOiqL4InkPMLqE Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org The current method of trying to convert a name to a password struct and then back to a SID is just weird. It also doesn't seem to work correctly. Instead, look for a '\\' in the string. If there isn't one then try to convert it directly to a SID. If there is a '\\' or the direct-to-SID conversion didn't work, then use wbcLookupName to do the conversion directly to a SID instead. Also, fix the error handling. These routines return a wbcErr, so we should use their macros to check whether it worked or not. Signed-off-by: Jeff Layton --- setcifsacl.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/setcifsacl.c b/setcifsacl.c index 54d8cbc..9f748c1 100644 --- a/setcifsacl.c +++ b/setcifsacl.c @@ -396,30 +396,30 @@ build_fetched_aces_ret: static int verify_ace_sid(char *sidstr, struct cifs_sid *sid) { - int rc, i; - char *lstr; - struct passwd *winpswdptr; - - lstr = strstr(sidstr, "\\"); /* everything before | */ - if (lstr) - ++lstr; - else - lstr = sidstr; - - /* Check if it is a (raw) SID (string) */ - rc = wbcStringToSid(lstr, (struct wbcDomainSid *)sid); - if (!rc) - goto fix_endianness; - - /* Check if it a name (string) which can be resolved to a SID*/ - rc = wbcGetpwnam(lstr, &winpswdptr); - if (rc) { - printf("%s: Invalid user name: %s\n", __func__, sidstr); - return rc; - } - rc = wbcUidToSid(winpswdptr->pw_uid, (struct wbcDomainSid *)sid); - if (rc) { - printf("%s: Invalid user: %s\n", __func__, sidstr); + int i; + wbcErr rc; + char *name, *domain; + enum wbcSidType type; + + name = strchr(sidstr, '\\'); + if (!name) { + /* might be a raw string representation of SID */ + rc = wbcStringToSid(sidstr, (struct wbcDomainSid *)sid); + if (WBC_ERROR_IS_OK(rc)) + goto fix_endianness; + + domain = ""; + name = sidstr; + } else { + domain = sidstr; + *name = '\0'; + ++name; + } + + rc = wbcLookupName(domain, name, (struct wbcDomainSid *)sid, &type); + if (!WBC_ERROR_IS_OK(rc)) { + printf("%s: Error converting %s\\%s to SID: %s\n", + __func__, domain, name, wbcErrorString(rc)); return rc; }