From patchwork Fri Jan 21 21:43:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirish Pargaonkar X-Patchwork-Id: 496801 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p0LLjNIP028135 for ; Fri, 21 Jan 2011 21:45:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753630Ab1AUVpW (ORCPT ); Fri, 21 Jan 2011 16:45:22 -0500 Received: from mail-iy0-f174.google.com ([209.85.210.174]:48276 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753573Ab1AUVpW (ORCPT ); Fri, 21 Jan 2011 16:45:22 -0500 Received: by iyj18 with SMTP id 18so2123221iyj.19 for ; Fri, 21 Jan 2011 13:45:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=Gtf2GbCjXyiR/U3oe9I2L/KPBgI/MjUaRjNdyMEcDsI=; b=O76S6yvQhWZVzxJTWYTQdcU5JLBAns2ZdikKpj8q/6GFTzam1LJbjO8ee+qttp3zd4 PuqJs7Flm8EvFsXeub2vHa5IPs3igjsX4zDfbtewypXRe1HjrMjoSq5mSSUKkk6FXZla 5hNYkLpM/dJYiF7n7jVcWntBV0wipfLw85YSQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=yEveEYPPMLPs+Zs+mVb81I4cFKkUXDxV3pvlt2tnNxsv8/7Pi+Yan20yVqeJu2IPqP z4FbQskZ4W39SRYXAsFqIuivlSXPTalCRqHlZR+yBn77qszmathTcmCwbMbm0dJ0tmQU eyxcqQgOIBCKMwSVLBn66pK9EwTbJ6wnIfvz4= Received: by 10.42.172.67 with SMTP id m3mr1488304icz.95.1295646321873; Fri, 21 Jan 2011 13:45:21 -0800 (PST) Received: from localhost ([32.97.110.58]) by mx.google.com with ESMTPS id gy41sm8163382ibb.23.2011.01.21.13.45.21 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 21 Jan 2011 13:45:21 -0800 (PST) From: shirishpargaonkar@gmail.com To: jlayton@redhat.com Cc: linux-cifs@vger.kernel.org, Shirish Pargaonkar Subject: [PATCH] cifs-utils: handle cifs_acl type of key to map a SID to either an uid or gid and return it [try #3] Date: Fri, 21 Jan 2011 15:43:44 -0600 Message-Id: <1295646224-21781-1-git-send-email-shirishpargaonkar@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 (demeter1.kernel.org [140.211.167.41]); Fri, 21 Jan 2011 21:45:44 +0000 (UTC) diff --git a/Makefile.am b/Makefile.am index 67a0190..c9018ae 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,7 +11,7 @@ man_MANS = mount.cifs.8 if CONFIG_CIFSUPCALL sbin_PROGRAMS = cifs.upcall cifs_upcall_SOURCES = cifs.upcall.c data_blob.c asn1.c spnego.c util.c -cifs_upcall_LDADD = -ltalloc -lkeyutils $(KRB5_LDADD) +cifs_upcall_LDADD = -ltalloc -lwbclient -lkeyutils $(KRB5_LDADD) man_MANS += cifs.upcall.8 # diff --git a/cifs.upcall.c b/cifs.upcall.c index 479517c..7563137 100644 --- a/cifs.upcall.c +++ b/cifs.upcall.c @@ -45,6 +45,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include #include "util.h" #include "replace.h" @@ -695,6 +702,66 @@ static int cifs_resolver(const key_serial_t key, const char *key_descr) return 0; } +static int +cifs_sid_resolver(const key_serial_t key, const char *key_descr) +{ + int i; + uid_t uid = 0; + gid_t gid = 0;; + wbcErr rc; + const char *keyend = key_descr; + struct wbcDomainSid sid; + + /* skip next 4 ';' delimiters to get to description */ + for (i = 1; i <= 4; ++i) { + keyend = index(keyend + 1, ';'); + if (!keyend) { + syslog(LOG_ERR, "invalid key description: %s", + key_descr); + return 1; + } + } + keyend++; + + if (strncmp(keyend, "os", 2) == 0) { + keyend = index(keyend + 1, ':'); + keyend++; + rc = wbcStringToSid(keyend, &sid); + if (!rc) { + rc = wbcSidToUid(&sid, &uid); + if (!rc) { + rc = keyctl_instantiate(key, &uid, + sizeof(uid_t), 0); + if (rc) + syslog(LOG_ERR, "%s: key inst: %s", + __func__, strerror(errno)); + } else + syslog(LOG_DEBUG, "OwnerSID to uid: %s, rc: %d", + keyend, rc); + } else + syslog(LOG_DEBUG, "O strtosid: %s, rc: %d", keyend, rc); + } else if (strncmp(keyend, "gs", 2) == 0) { + keyend = index(keyend + 1, ':'); + keyend++; + rc = wbcStringToSid(keyend, &sid); + if (!rc) { + rc = wbcSidToGid(&sid, &gid); + if (!rc) { + rc = keyctl_instantiate(key, &gid, + sizeof(gid_t), 0); + if (rc) + syslog(LOG_ERR, "%s: key inst: %s", + __func__, strerror(errno)); + } else + syslog(LOG_DEBUG, "GroupSID to gid: %s, rc: %d", + keyend, rc); + } else + syslog(LOG_DEBUG, "O strtosid: %s, rc: %d", keyend, rc); + } else + syslog(LOG_DEBUG, "Invalid SID"); + return 0; +} + /* * Older kernels sent IPv6 addresses without colons. Well, at least * they're fixed-length strings. Convert these addresses to have colon @@ -833,6 +900,12 @@ int main(const int argc, char *const argv[]) goto out; } + if ((strncmp(buf, "cifs.cifs_idmap", sizeof("cifs.cifs_idmap") - 1) + == 0)) { + rc = cifs_sid_resolver(key, buf); + goto out; + } + have = decode_key_description(buf, &arg); SAFE_FREE(buf); if ((have & DKD_MUSTHAVE_SET) != DKD_MUSTHAVE_SET) {