Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754178AbZIXAbM (ORCPT ); Wed, 23 Sep 2009 20:31:12 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754164AbZIXAbJ (ORCPT ); Wed, 23 Sep 2009 20:31:09 -0400 Received: from smtp231.iad.emailsrvr.com ([207.97.245.231]:39153 "EHLO smtp231.iad.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753989AbZIXAaQ (ORCPT ); Wed, 23 Sep 2009 20:30:16 -0400 From: Oren Laadan To: Andrew Morton Cc: Linus Torvalds , containers@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, Serge Hallyn , Ingo Molnar , Pavel Emelyanov , Dan Smith Subject: [PATCH v18 67/80] Expose may_setuid() in user.h and add may_setgid() (v2) Date: Wed, 23 Sep 2009 19:51:47 -0400 Message-Id: <1253749920-18673-68-git-send-email-orenl@librato.com> X-Mailer: git-send-email 1.6.0.4 In-Reply-To: <1253749920-18673-1-git-send-email-orenl@librato.com> References: <1253749920-18673-1-git-send-email-orenl@librato.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1756 Lines: 69 From: Dan Smith Make these helpers available to others. Changes in v2: - Avoid checking the groupinfo in ctx->realcred against the current in may_setgid() Cc: Serge Hallyn Signed-off-by: Dan Smith --- include/linux/user.h | 9 +++++++++ kernel/user.c | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletions(-) diff --git a/include/linux/user.h b/include/linux/user.h index 68daf84..c231e9c 100644 --- a/include/linux/user.h +++ b/include/linux/user.h @@ -1 +1,10 @@ +#ifndef _LINUX_USER_H +#define _LINUX_USER_H + #include +#include + +extern int may_setuid(struct user_namespace *ns, uid_t uid); +extern int may_setgid(gid_t gid); + +#endif diff --git a/kernel/user.c b/kernel/user.c index a535ed6..a78fde7 100644 --- a/kernel/user.c +++ b/kernel/user.c @@ -604,7 +604,7 @@ int checkpoint_user(struct ckpt_ctx *ctx, void *ptr) return do_checkpoint_user(ctx, (struct user_struct *) ptr); } -static int may_setuid(struct user_namespace *ns, uid_t uid) +int may_setuid(struct user_namespace *ns, uid_t uid) { /* * this next check will one day become @@ -631,6 +631,17 @@ static int may_setuid(struct user_namespace *ns, uid_t uid) return 0; } +int may_setgid(gid_t gid) +{ + if (capable(CAP_SETGID)) + return 1; + + if (in_egroup_p(gid)) + return 1; + + return 0; +} + static struct user_struct *do_restore_user(struct ckpt_ctx *ctx) { struct user_struct *u; -- 1.6.0.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/