>From 4ead5dcd79b6c37c3cb0a7ac29d273450aa407e0 Mon Sep 17 00:00:00 2001
From: Tim Meier <meier3@llnl.gov>
Date: Fri, 23 May 2008 08:12:07 -0700
Subject: [PATCH] infiniband-diags: terminate perl scripts with error if not authorized

An "auth_check" routine intended for use in scripts that use umad
functions.  Quickly terminates with an error code, if not authorized.

Signed-off-by: Tim Meier <meier3@llnl.gov>
---
 infiniband-diags/scripts/IBswcountlimits.pm |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/infiniband-diags/scripts/IBswcountlimits.pm b/infiniband-diags/scripts/IBswcountlimits.pm
index 9bc356f..da75b25 100755
--- a/infiniband-diags/scripts/IBswcountlimits.pm
+++ b/infiniband-diags/scripts/IBswcountlimits.pm
@@ -85,6 +85,19 @@ $IBswcountlimits::cache_dir       = "/var/cache/infiniband-diags";
 	"This counter can increase due to a valid network event"
 );
 
+# =========================================================================
+#  only authorized if uid is root, or matches umad ownership
+#
+sub auth_check
+{
+	my $file = "/dev/infiniband/umad0";
+	my $uid = (stat $file)[4];
+	my $gid = (stat $file)[5];
+	if (($> != $uid) && ($> != $gid) && ($> != 0)){
+		die "Permission denied\n";
+	}
+}
+
 sub check_counters
 {
 	my $print_action = $_[0];
-- 
1.5.1

