From patchwork Tue Dec 7 17:11:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirish Pargaonkar X-Patchwork-Id: 383692 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 oB7HGeBP028873 for ; Tue, 7 Dec 2010 17:16:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752216Ab0LGRQl (ORCPT ); Tue, 7 Dec 2010 12:16:41 -0500 Received: from mail-gy0-f174.google.com ([209.85.160.174]:44641 "EHLO mail-gy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751942Ab0LGRQk (ORCPT ); Tue, 7 Dec 2010 12:16:40 -0500 Received: by mail-gy0-f174.google.com with SMTP id 11so114214gyb.19 for ; Tue, 07 Dec 2010 09:16:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=jG1D2bJzQwsSERZgxRLN6qkVgkuSEqBSNU8dWD5P8iw=; b=nGys82X+qCkL1/BhZfMkU8BxKF0rKe96wxllWU0f/waqqqNtBfEXkLsboRNJFxnpqQ 8M+xtTCg2ahM0/U2ubyG1PpgGTK8rEoZRhzWaps1Vawkb6Y+X+udqjymcbyPwsvaxorW UZ5ghXJjiCLii99u8NIvc8tf77L5c+T3jEPZc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=UOLcp0LWRTfYZ9Go3Wb17NXoHGDRQejzGr8ouhr1kjXmGk6HVwLm4rjD9yXwKhHz8b 3gjl74+/mq0BzcdpwY1fpVh73SPnfshp8kkrflByGoUP3ywzt6hTnu7auWIUXOISWnTq izX61OO5UqGEH72UHSm5i+HwkgKhodDVStcxw= Received: by 10.151.102.21 with SMTP id e21mr2239722ybm.306.1291742200135; Tue, 07 Dec 2010 09:16:40 -0800 (PST) Received: from localhost ([32.97.110.58]) by mx.google.com with ESMTPS id r18sm4128348yba.15.2010.12.07.09.16.39 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 07 Dec 2010 09:16:39 -0800 (PST) From: shirishpargaonkar@gmail.com To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org, dhowells@redhat.com, samba-technical@lists.samba.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 Date: Tue, 7 Dec 2010 11:11:16 -0600 Message-Id: <1291741876-22770-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.3 (demeter1.kernel.org [140.211.167.41]); Tue, 07 Dec 2010 17:16:41 +0000 (UTC) diff --git a/cifs.upcall.c b/cifs.upcall.c index 9b1436e..17ef57e 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" @@ -544,6 +551,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 @@ -679,6 +746,11 @@ int main(const int argc, char *const argv[]) goto out; } + if ((strncmp(buf, "cifs.cifs_acl", sizeof("cifs.cifs_acl") - 1) == 0)) { + rc = cifs_sid_resolver(key, buf); + goto out; + } + memset(&arg, 0, sizeof(arg)); have = decode_key_description(buf, &arg);