#!/bin/sh

# This file is part of syscalltrack, a GNU/Linux kernel module and
# user space utilities for logging or modifying any system call    
# invocation.                                                      
#                                                                  
# Copyright (C) 2000-2002 Muli Ben-Yehuda, mulix@actcom.co.il      
# License: GNU General Public License                              

#
# $Id: sct_load,v 1.6 2002/06/15 15:16:14 mulix Exp $
#

# This code is based upon code from the book "Linux Device
# Drivers" by Alessandro Rubini and Jonathan Corbet, published
# by O'Reilly & Associates. 

pre_module="syscall_hijack"
module="sct_rules"
device="sct"
mode="664"

# alternate location to find the modules, if we cant find at ./
# TODO: change to a reasonable default 
release=`uname -r`
mod_location="/lib/modules/${release}/kernel/sct"

# Group: since distributions do it differently, look for wheel or use staff
if grep '^staff:' /etc/group > /dev/null; then
    group="staff"
else
    group="wheel"
fi

# remove stale nodes
rm -f /dev/${device}? 

# invoke insmod with all arguments we got
# and use a pathname, as newer modutils don't look in . by default
if [ -e ./$pre_module.o ] && [ -e ./$module.o ]; then
    /sbin/insmod ./$pre_module.o $* || exit 1
    /sbin/insmod ./$module.o $* || exit 1
else 
    if [ -e ${mod_location}/${pre_module}.o ] &&  [ -e ${mod_location}/${module}.o ]; then
	/sbin/insmod ${mod_location}/$pre_module.o $* || exit 1
	/sbin/insmod ${mod_location}/$module.o $* || exit 1
    else 
	echo 
	echo "sct_load: could not find '${module}.o' and/or '${pre_module}.o'"
	echo "sct_load: looking at: ./:$mod_location"
	echo 
	exit 1
    fi
fi

major=`cat /proc/devices | awk "\\$2==\"$module\" {print \\$1}" | head -1`
echo "major=$major"

mknod /dev/${device}0 c $major 0
mknod /dev/${device}1 c $major 1

ln -sf ${device}0  /dev/${device}_ctrl
ln -sf ${device}1  /dev/${device}_log

# give appropriate group/permissions
chgrp $group /dev/${device}[0-3]
chmod $mode  /dev/${device}[0-3]
