#include <stdio.h>
#include <stdlib.h>
#include <linux/kdev_t.h>
#include <rsbac/types.h>
#include <rsbac/syscalls.h>
#include <rsbac/getname.h>
#include <rsbac/error.h>

int main(int argc, char ** argv)
{
  int res = 0;
  int i;
  int module,value;
  char name[80];
  
  if (argc == 3)
    {
      module=get_switch_target_nr(argv[1]);
      if(module == SW_NONE)
        {
          printf("%s: Invalid switch target %s\n", argv[0], argv[1]);
          exit(1);
        }
      value=strtol(argv[2],0,0);
/*      printf("%s: switching Module %s(%i) to %i\n", argv[0],argv[1],module,value);
*/
      res = rsbac_switch(module,value);
      if(res)
        {
          if((res > -RSBAC_EPERM) || (res < -RSBAC_EDECISIONMISMATCH))
            {
              printf("%s: error: %s\n", argv[0], strerror(-res));
            }
          else
            {
              get_error_name(name,res);
              printf("%s: error: %s\n", argv[0], name);
            }
          exit(1);
        }
      exit(0);
    }
  else
    {
      printf("%s (RSBAC %s)\n***\n", argv[0], VERSION);
      printf("Use: %s module value\n", argv[0]);
      printf("module = module name, value = [01]\n\n");
      printf("Possible module names are:\n");
      for (i=0;i<SW_NONE;i++)
        {
          get_switch_target_name(name,i);
          printf("%s\n",name);
        }
    }
  exit(1);
}
