#!/usr/bin/perl
########################################################################
#
#
# LOMAC - Low Water-Mark Mandatory Access Control for Linux 
# Copyright (C) 1999 TIS Labs at Network Associates, Inc.
# Copyright (C) 2000 - 2001 NAI Labs
# Copyright (C) 2001 John Thiltges
# Copyright (C) 2002 Networks Associates Technology, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.  This program
# is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.  You should have received a copy of the
# GNU General Public License along with this program; if not, write
# to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
#
# level - a perl script to determine the LOMAC level associated with
#         a specified process or file.  Uses the /dev/lomac pseudo-
#         device to retrieve this information from the LOMAC loadable
#         kernel module (LKM).
#
# Tim Fraser <tfraser@tislabs.com>        : initial implementation
# John Thiltges <jthiltg1@bigred.unl.edu> : adapted to use lomac.pm
#
########################################################################

use lib "/opt/lomac/bin";
use lomac;

my $ret_val;

#
# Step 1 - If the LOMAC LKM is not loaded, exit.
# Step 2 - Verify that "/dev/lomac" exists and is a character special file.
#          with correct device major number

if (linfo("-c")) {
    exit( -1 );
}


#
# Step 3 - Process command-line arguments
#

# Bomb if we didn't get the proper number of arguments
if( $#ARGV != 1 ) {
    die "USAGE: level -p <pid>\n       level -f <pathname>\n";
}

#
# Step 4 - Call level() in lomac.pm to query the LOMAC LKM.
#

$ret_val = level($ARGV[0],$ARGV[1]);

#
# Step 5 - report results.
#

print "$ret_val\n";
exit( $ret_val );
