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

int main(int argc, char ** argv)
{
  int res = 0;
  int i;
  int request,value;
  char name[80];
  
  if (argc == 3)
    {
      if(!strcmp(argv[1],"ALL"))
        {
          value=strtol(argv[2],0,0);
          printf("%s: switching logging for ALL requests to %i\n",
                 argv[0],value);
          for(i=0;i<R_NONE;i++)
            {
              printf("%s: request %s(%i) to %i\n",
                     argv[0],get_request_name(name,i),i,value);
              res = rsbac_adf_log_switch(i,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);
                    }
                }
            }
        }
      else
        {
          request=get_request_nr(argv[1]);
          if(request == R_NONE)
            return(-RSBAC_EINVALIDREQUEST);
          value=strtol(argv[2],0,0);
          printf("%s: switching logging for request %s(%i) to %i\n", argv[0],argv[1],request,value);
          res = rsbac_adf_log_switch(request,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);
                }
            }
        }
    }
  else
    {
      printf("%s (RSBAC %s)\n***\n", argv[0], VERSION);
      printf("Use: %s request value\n", argv[0]);
      printf("request = request name or ALL, value = [012]\n\n");
      printf("Possible requests are:\n");
      for(i=0;i<R_NONE;i++)
        {
          get_request_name(name,i);
          printf("%s\n",name);
        }
      printf("\n");
    }
    
  return (res);
}

