From patchwork Tue Aug 9 17:34:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirish Pargaonkar X-Patchwork-Id: 1050522 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p79HSN1N020261 for ; Tue, 9 Aug 2011 17:28:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753905Ab1HIR2W (ORCPT ); Tue, 9 Aug 2011 13:28:22 -0400 Received: from mail-gx0-f174.google.com ([209.85.161.174]:52128 "EHLO mail-gx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754210Ab1HIR2U (ORCPT ); Tue, 9 Aug 2011 13:28:20 -0400 Received: by gxk21 with SMTP id 21so155324gxk.19 for ; Tue, 09 Aug 2011 10:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=v0L2dfiKxsIiLI1U/W3x5ADKLvL3OMWcdtxJcm4XrrU=; b=fYFvsIWJUrQCK5bzVz0b/qSiLYt9NpKOztDIcF8rqvjv992rnTWsGJAL6JpPqZs4zy fw4KbzqMmYB9kxIs90SKxvh7MjidXyRX2OMYQAG5BEFxxSFn72gYQLuHeFFhhMyJGNc3 5o9B1LqnTfBqlb472N6WHBveskM2X992rS1H8= Received: by 10.236.193.9 with SMTP id j9mr3515340yhn.81.1312910899874; Tue, 09 Aug 2011 10:28:19 -0700 (PDT) Received: from localhost ([32.97.110.58]) by mx.google.com with ESMTPS id z28sm147521yhn.21.2011.08.09.10.28.18 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 09 Aug 2011 10:28:19 -0700 (PDT) From: shirishpargaonkar@gmail.com To: jlayton@samba.org Cc: linux-cifs@vger.kernel.org, Shirish Pargaonkar Subject: [PATCH] cifs-utils: Add uid/gid to SID mapping functions (try #3) Date: Tue, 9 Aug 2011 12:34:05 -0500 Message-Id: <1312911245-22404-1-git-send-email-shirishpargonkar@gmail.com> X-Mailer: git-send-email 1.6.0.2 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 09 Aug 2011 17:28:23 +0000 (UTC) From: Shirish Pargaonkar Add functions to map a uid and gid to a SID. These functions are similar to SID to uid and gid mapping functions. A SID is what is returned to the cifs module. Signed-off-by: Shirish Pargaonkar --- cifs.idmap.c | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-) diff --git a/cifs.idmap.c b/cifs.idmap.c index 56edb58..80802d7 100644 --- a/cifs.idmap.c +++ b/cifs.idmap.c @@ -134,6 +134,43 @@ cifs_idmap(const key_serial_t key, const char *key_descr) goto cifs_idmap_ret; } + sidstr = strget(key_descr, "oi:"); + if (sidstr) { + uid = atoi(sidstr); + syslog(LOG_DEBUG, "SID: %s, uid: %d", sidstr, uid); + rc = wbcUidToSid(uid, &sid); + if (rc) + syslog(LOG_DEBUG, "uid %d to SID error: %d", uid, rc); + if (!rc) { /* SID has been mapped to a uid */ + rc = keyctl_instantiate(key, &sid, + sizeof(struct wbcDomainSid), 0); + if (rc) + syslog(LOG_ERR, "%s: key inst: %s", + __func__, strerror(errno)); + } + + goto cifs_idmap_ret; + } + + sidstr = strget(key_descr, "gi:"); + if (sidstr) { + gid = atoi(sidstr); + syslog(LOG_DEBUG, "SID: %s, gid: %d", sidstr, gid); + rc = wbcGidToSid(gid, &sid); + if (rc) + syslog(LOG_DEBUG, "gid %d to SID error: %d", gid, rc); + if (!rc) { /* SID has been mapped to a gid */ + rc = keyctl_instantiate(key, &sid, + sizeof(struct wbcDomainSid), 0); + if (rc) + syslog(LOG_ERR, "%s: key inst: %s", + __func__, strerror(errno)); + } + + goto cifs_idmap_ret; + } + + syslog(LOG_DEBUG, "Invalid key: %s", key_descr); cifs_idmap_ret: