From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756360AbYFQHzn (ORCPT ); Tue, 17 Jun 2008 03:55:43 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755747AbYFQHxu (ORCPT ); Tue, 17 Jun 2008 03:53:50 -0400 Received: from 74-93-104-97-Washington.hfc.comcastbusiness.net ([74.93.104.97]:43474 "EHLO sunset.davemloft.net" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1756782AbYFQHxp (ORCPT ); Tue, 17 Jun 2008 03:53:45 -0400 Date: Tue, 17 Jun 2008 00:53:45 -0700 (PDT) Message-Id: <20080617.005345.175709521.davem@davemloft.net> To: linville@tuxdriver.com CC: mokuno@sm.sony.co.jp, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/12]: wext: Pull ioctl permission checking out into helper function. From: David Miller X-Mailer: Mew version 5.2 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org wext: Pull ioctl permission checking out into helper function. Signed-off-by: David S. Miller --- net/wireless/wext.c | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-) diff --git a/net/wireless/wext.c b/net/wireless/wext.c index a1cd19a..e96559e 100644 --- a/net/wireless/wext.c +++ b/net/wireless/wext.c @@ -1061,18 +1061,26 @@ static int wireless_process_ioctl(struct net *net, struct ifreq *ifr, unsigned i return -EOPNOTSUPP; } +/* If command is `set a parameter', or `get the encoding parameters', + * check if the user has the right to do it. + */ +static int wext_permission_check(unsigned int cmd) +{ + if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE || cmd == SIOCGIWENCODEEXT) + && !capable(CAP_NET_ADMIN)) + return -EPERM; + + return 0; +} + /* entry point from dev ioctl */ int wext_handle_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd, void __user *arg) { - int ret; + int ret = wext_permission_check(cmd); - /* If command is `set a parameter', or - * `get the encoding parameters', check if - * the user has the right to do it */ - if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE || cmd == SIOCGIWENCODEEXT) - && !capable(CAP_NET_ADMIN)) - return -EPERM; + if (ret) + return ret; dev_load(net, ifr->ifr_name); rtnl_lock(); -- 1.5.5.1.308.g1fbb5