From patchwork Tue Aug 9 19:31:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirish Pargaonkar X-Patchwork-Id: 1050752 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 p79JNGgC030985 for ; Tue, 9 Aug 2011 19:25:16 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750773Ab1HITZQ (ORCPT ); Tue, 9 Aug 2011 15:25:16 -0400 Received: from mail-gx0-f174.google.com ([209.85.161.174]:51583 "EHLO mail-gx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750722Ab1HITZQ (ORCPT ); Tue, 9 Aug 2011 15:25:16 -0400 Received: by gxk21 with SMTP id 21so230265gxk.19 for ; Tue, 09 Aug 2011 12:25:15 -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=YpzQcUb6VZ4LvG/Z617TR95cjVs/RSyoIdBRFZiigg1TAtiWLLdq8JeMwMDWmvct+9 TLnZPSmoWHzXqnRejnu+VivDhqjKhh1MKojCnrFm+fw1A825pPOnGoU8Fp3XDKfMNSlc gRzjctPjrbY09BtBjrTaAUp3dqJRkMvkFLwew= Received: by 10.236.180.1 with SMTP id i1mr3721381yhm.134.1312917915218; Tue, 09 Aug 2011 12:25:15 -0700 (PDT) Received: from localhost ([32.97.110.58]) by mx.google.com with ESMTPS id f48sm255442yhh.14.2011.08.09.12.25.13 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 09 Aug 2011 12:25:14 -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 #4) Date: Tue, 9 Aug 2011 14:31:00 -0500 Message-Id: <1312918260-23780-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 19:25:17 +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: