#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/pm_getname.h>
#include <rsbac/error.h>


int main(int argc, char ** argv)
{
  int res = 0;
  int i;
  char tmp1[80];
  enum rsbac_pm_function_type_t function;
  union rsbac_pm_function_param_t param;
  rsbac_pm_tkt_id_t ticket=0;
  struct rsbac_pm_purpose_list_item_t * pp_list_p;
  struct rsbac_pm_purpose_list_item_t * pp_list_tmp_p;

  void use(int exit_code)
      {
        char name[80];
        char pars[160];
        char * key = (void *) 0;

        printf("%s (RSBAC %s)\n***\n", argv[0], VERSION);
        printf("Use: %s call args\n", argv[0]);
        printf("call = one of the following calls, args = call dependent\n");
        for (i=0;i<18;i++)
          {
            get_pm_function_type_name(name,i);
            get_pm_function_param(pars,i);
            printf("%s \t%s\n",name,pars);
          }
        printf("-- press return --");
        scanf("%c", key);
        for (i=18;i<PF_none;i++)
          {
            get_pm_function_type_name(name,i);
            get_pm_function_param(pars,i);
            printf("%s \t%s\n",name,pars);
          }
        exit(exit_code);
      }

  void use_ct(int exit_code)
      {
        char name[80];
        char pars[160];
        char * key = (void *) 0;

        printf("%s (RSBAC %s)\n***\n", argv[0], VERSION);
        printf("Use: %s create_ticket ticket-nr valid-secs call args\n", argv[0]);
        printf("call = one of the following calls, args = call dependent\n");
        for (i=0;i<15;i++)
          {
            get_pm_tkt_function_type_name(name,i);
            get_pm_tkt_function_param(pars,i);
            printf("%s \t%s\n",name,pars);
          }
        printf("-- press return --");
        scanf("%c", key);
        for (i=15;i<PTF_none;i++)
          {
            get_pm_tkt_function_type_name(name,i);
            get_pm_tkt_function_param(pars,i);
            printf("%s \t%s\n",name,pars);
          }
        exit(exit_code);
      }

  
  if (argc >= 2)
    {
      function = get_pm_function_type_nr(argv[1]);
      if(function == PF_none)
        {
          printf("\n%s: invalid pm function %s!\n\n", argv[0], argv[1]);
          use(1);
        }
      printf("%s: requesting pm-call %s (No. %i)\n", argv[0],argv[1],function);
      
      switch(function)
        {
          case PF_add_na:
            if(argc < 7)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.add_na.task = strtol(argv[3],0,0);
            if(!strcmp(argv[4],"IPC"))
              param.add_na.class = RSBAC_PM_IPC_OBJECT_CLASS_ID;
            else
              if(!strcmp(argv[4],"DEV"))
                param.add_na.class = RSBAC_PM_DEV_OBJECT_CLASS_ID;
              else
                if(!strcmp(argv[4],"NIL"))
                  param.add_na.class = 0;
                else
                  param.add_na.class = strtol(argv[4],0,0);
            param.add_na.tp = strtol(argv[5],0,0);
            param.add_na.accesses = strtol(argv[6],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_delete_na:
            if(argc < 7)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.delete_na.task = strtol(argv[3],0,0);
            if(!strcmp(argv[4],"IPC"))
              param.add_na.class = RSBAC_PM_IPC_OBJECT_CLASS_ID;
            else
              if(!strcmp(argv[4],"DEV"))
                param.add_na.class = RSBAC_PM_DEV_OBJECT_CLASS_ID;
              else
                if(!strcmp(argv[4],"NIL"))
                  param.add_na.class = 0;
                else
                  param.add_na.class = strtol(argv[4],0,0);
            param.delete_na.tp = strtol(argv[5],0,0);
            param.delete_na.accesses = strtol(argv[6],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_add_task:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.add_task.id = strtol(argv[3],0,0);
            param.add_task.purpose = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_delete_task:
            if(argc < 4)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.delete_task.id = strtol(argv[3],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_add_object_class:
            if(argc < 4)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.add_object_class.id = strtol(argv[3],0,0);
            if(argc > 4)
              {
                /* creating list of purposes */
                if(!(pp_list_p = (struct rsbac_pm_purpose_list_item_t *)
                       malloc(sizeof(*pp_list_p)) ))
                  {
                    printf("%s: Could not allocate list memory!", argv[0]);
                    exit(1);
                  }
  
                param.add_object_class.pp_list_p = pp_list_p;
                pp_list_p->id = strtol(argv[4],0,0);
                for(i=5;i<argc;i++)
                  {
                    if(!(pp_list_tmp_p = (struct rsbac_pm_purpose_list_item_t *)
                           malloc(sizeof(*pp_list_tmp_p)) ))
                      {
                        printf("%s: Could not allocate list memory!", argv[0]);
                      }
                    pp_list_tmp_p->id = strtol(argv[i],0,0);
                    pp_list_p->next = pp_list_tmp_p;
                    pp_list_p = pp_list_tmp_p;
                  }
                pp_list_p->next = NULL;
              }
            else
              param.add_object_class.pp_list_p = NULL;
            res = rsbac_pm(function, &param, ticket);
            if(argc > 4)
              {
                /* clean up */
                pp_list_p = param.add_object_class.pp_list_p;
                while(pp_list_p)
                  {
                    pp_list_tmp_p = pp_list_p->next;
                    free(pp_list_p);
                    pp_list_p = pp_list_tmp_p;
                  }
              }
            /* ready */
            break;
            
          case PF_delete_object_class:
            if(argc < 4)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.delete_object_class.id = strtol(argv[3],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_add_authorized_tp:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.add_authorized_tp.task = strtol(argv[3],0,0);
            param.add_authorized_tp.tp = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_delete_authorized_tp:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.delete_authorized_tp.task = strtol(argv[3],0,0);
            param.delete_authorized_tp.tp = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_add_consent:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.add_consent.filename = argv[3];
            param.add_consent.purpose = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_delete_consent:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.delete_consent.filename = argv[3];
            param.delete_consent.purpose = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_add_purpose:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.add_purpose.id = strtol(argv[3],0,0);
            param.add_purpose.def_class = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_delete_purpose:
            if(argc < 4)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.delete_purpose.id = strtol(argv[3],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_add_responsible_user:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.add_responsible_user.user = strtol(argv[3],0,0);
            param.add_responsible_user.task = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_delete_responsible_user:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.delete_responsible_user.user = strtol(argv[3],0,0);
            param.delete_responsible_user.task = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_delete_user_aci:
            if(argc < 4)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.delete_user_aci.id = strtol(argv[3],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_set_role:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.set_role.user = strtol(argv[3],0,0);
            if((param.set_role.role = get_pm_role_nr(argv[4])) == PR_none)
              param.set_role.role = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_set_object_class:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.set_object_class.filename = argv[3];
            param.set_object_class.class = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_switch_pm:
            if(argc < 4)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.switch_pm.value = strtol(argv[3],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_set_device_object_type:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.set_device_object_type.filename = argv[3];
            if((param.set_device_object_type.object_type = get_pm_object_type_nr(argv[4])) == PO_none)
              param.set_device_object_type.object_type = strtol(argv[4],0,0);
            param.set_device_object_type.class = RSBAC_PM_DEV_OBJECT_CLASS_ID;
            if(argc > 5)
              {
                if(!strcmp(argv[5],"IPC"))
                  param.set_device_object_type.class = RSBAC_PM_IPC_OBJECT_CLASS_ID;
                else
                  if(!strcmp(argv[5],"DEV"))
                    param.set_device_object_type.class = RSBAC_PM_DEV_OBJECT_CLASS_ID;
                  else
                    if(!strcmp(argv[5],"NIL"))
                      param.set_device_object_type.class = 0;
                    else
                      param.set_device_object_type.class = strtol(argv[5],0,0);
              }
            res = rsbac_pm(function, &param, ticket);
            break;
            
/********/

          case PF_add_authorized_task:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.add_authorized_task.user = strtol(argv[3],0,0);
            param.add_authorized_task.task = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_delete_authorized_task:
            if(argc < 5)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = strtol(argv[2],0,0);
            param.delete_authorized_task.user = strtol(argv[3],0,0);
            param.delete_authorized_task.task = strtol(argv[4],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
/********/

          case PF_write_list:
            if(argc < 4)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            param.write_list.filename = argv[2];
            if((param.write_list.list = get_pm_all_list_nr(argv[3])) == PA_none)
              param.write_list.list = strtol(argv[3],0,0);
            res = rsbac_pm(function, &param, 0);
            break;

/********/
            
          case PF_create_tp:
            if(argc < 3)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = 0;
            param.create_tp.id = strtol(argv[2],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_delete_tp:
            if(argc < 3)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = 0;
            param.delete_tp.id = strtol(argv[2],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
          case PF_set_tp:
            if(argc < 4)
              {
                printf("Too few arguments: argc is %i", argc);
                use(1);
              }
            ticket = 0;
            param.set_tp.filename = argv[2];
            param.set_tp.tp = strtol(argv[3],0,0);
            res = rsbac_pm(function, &param, ticket);
            break;
            
/********/

          case PF_create_ticket:
            if(argc < 6)
              {
                printf("\nToo few arguments: argc is %i\n", argc);
                use_ct(1);
              }
            param.create_ticket.id = strtol(argv[2],0,0);
            param.create_ticket.valid_for = strtol(argv[3],0,0);
            param.create_ticket.function_type = get_pm_tkt_function_type_nr(argv[4]);
            switch(param.create_ticket.function_type)
              {
                case PF_add_na:
                  if(argc < 9)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.add_na.task
                   = strtol(argv[5],0,0);
                  if(!strcmp(argv[6],"IPC"))
                    param.create_ticket.function_param.add_na.class
                     = RSBAC_PM_IPC_OBJECT_CLASS_ID;
                  else
                    if(!strcmp(argv[6],"DEV"))
                      param.create_ticket.function_param.add_na.class
                       = RSBAC_PM_DEV_OBJECT_CLASS_ID;
                    else
                      if(!strcmp(argv[6],"NIL"))
                        param.create_ticket.function_param.add_na.class
                         = 0;
                      else
                        param.create_ticket.function_param.add_na.class
                         = strtol(argv[6],0,0);
                  param.create_ticket.function_param.add_na.tp
                   = strtol(argv[7],0,0);
                  param.create_ticket.function_param.add_na.accesses
                   = strtol(argv[8],0,0);
                  break;

                case PF_delete_na:
                  if(argc < 9)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.delete_na.task
                   = strtol(argv[5],0,0);
                  if(!strcmp(argv[6],"IPC"))
                    param.create_ticket.function_param.delete_na.class
                     = RSBAC_PM_IPC_OBJECT_CLASS_ID;
                  else
                    if(!strcmp(argv[6],"DEV"))
                      param.create_ticket.function_param.delete_na.class
                       = RSBAC_PM_DEV_OBJECT_CLASS_ID;
                    else
                      if(!strcmp(argv[6],"NIL"))
                        param.create_ticket.function_param.delete_na.class
                         = 0;
                      else
                        param.create_ticket.function_param.delete_na.class
                         = strtol(argv[6],0,0);
                  param.create_ticket.function_param.delete_na.tp
                   = strtol(argv[7],0,0);
                  param.create_ticket.function_param.delete_na.accesses
                   = strtol(argv[8],0,0);
                  break;

                case PF_add_task:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.add_task.id
                   = strtol(argv[5],0,0);
                  param.create_ticket.function_param.add_task.purpose
                   = strtol(argv[6],0,0);
                  break;

                case PF_delete_task:
                  if(argc < 6)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.delete_task.id
                   = strtol(argv[5],0,0);
                  break;

                case PF_add_object_class:
                  if(argc < 6)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.add_object_class.id
                   = strtol(argv[5],0,0);
                  if(argc > 6)
                    {
                      /* creating list of purposes */
                      if(!(pp_list_p = (struct rsbac_pm_purpose_list_item_t *)
                             malloc(sizeof(*pp_list_p)) ))
                        {
                          printf("%s: Could not allocate list memory!", argv[0]);
                          exit(1);
                        }

                      param.create_ticket.function_param.add_object_class.pp_list_p = pp_list_p;
                      pp_list_p->id = strtol(argv[6],0,0);
                      for(i=7;i<argc;i++)
                        {
                          if(!(pp_list_tmp_p = (struct rsbac_pm_purpose_list_item_t *)
                                 malloc(sizeof(*pp_list_tmp_p)) ))
                            {
                              printf("%s: Could not allocate list memory!", argv[0]);
                            }
                          pp_list_tmp_p->id = strtol(argv[i],0,0);
                          pp_list_p->next = pp_list_tmp_p;
                          pp_list_p = pp_list_tmp_p;
                        }
                      pp_list_p->next = NULL;
                    }
                  else
                    param.create_ticket.function_param.add_object_class.pp_list_p = NULL;
                  /* calling sys_rsbac_pm */
                  res = rsbac_pm(function, &param, ticket);
                  if(argc > 6)
                    {
                      /* clean up */
                      pp_list_p = param.create_ticket.function_param.add_object_class.pp_list_p;
                      while(pp_list_p)
                        {
                          pp_list_tmp_p = pp_list_p->next;
                          free(pp_list_p);
                          pp_list_p = pp_list_tmp_p;
                        }
                    }
                  break;

                case PF_delete_object_class:
                  if(argc < 6)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.delete_object_class.id
                   = strtol(argv[5],0,0);
                  break;

                case PF_add_authorized_tp:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.add_authorized_tp.task
                   = strtol(argv[5],0,0);
                  param.create_ticket.function_param.add_authorized_tp.tp
                   = strtol(argv[6],0,0);
                  break;

                case PF_delete_authorized_tp:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.delete_authorized_tp.task
                   = strtol(argv[5],0,0);
                  param.create_ticket.function_param.delete_authorized_tp.tp
                   = strtol(argv[6],0,0);
                  break;

                case PF_add_consent:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.add_consent.filename
                   = argv[5];
                  param.create_ticket.function_param.add_consent.purpose
                   = strtol(argv[6],0,0);
                  break;

                case PF_delete_consent:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.delete_consent.filename
                   = argv[5];
                  param.create_ticket.function_param.delete_consent.purpose
                   = strtol(argv[6],0,0);
                  break;

                case PF_add_purpose:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.add_purpose.id
                   = strtol(argv[5],0,0);
                  param.create_ticket.function_param.add_purpose.def_class
                   = strtol(argv[6],0,0);
                  break;

                case PF_delete_purpose:
                  if(argc < 6)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.delete_purpose.id
                   = strtol(argv[5],0,0);
                  break;

                case PF_add_responsible_user:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.add_responsible_user.user
                   = strtol(argv[5],0,0);
                  param.create_ticket.function_param.add_responsible_user.task
                   = strtol(argv[6],0,0);
                  break;

                case PF_delete_responsible_user:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.delete_responsible_user.user
                   = strtol(argv[5],0,0);
                  param.create_ticket.function_param.delete_responsible_user.task
                   = strtol(argv[6],0,0);
                  break;

                case PF_delete_user_aci:
                  if(argc < 6)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.delete_user_aci.id
                   = strtol(argv[5],0,0);
                  break;

                case PF_set_role:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.set_role.user
                   = strtol(argv[5],0,0);
                  if((param.create_ticket.function_param.set_role.role
                      = get_pm_role_nr(argv[6])) == PR_none)
                    param.create_ticket.function_param.set_role.role
                        = strtol(argv[6],0,0);
                  break;

                case PF_set_object_class:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.set_object_class.filename
                   = argv[5];
                  param.create_ticket.function_param.set_object_class.class
                   = strtol(argv[6],0,0);
                  break;

                case PF_switch_pm:
                  if(argc < 6)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.switch_pm.value
                   = strtol(argv[5],0,0);
                  break;

                case PF_set_device_object_type:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.set_device_object_type.filename
                   = argv[5];
                  if((param.create_ticket.function_param.set_device_object_type.object_type = get_pm_object_type_nr(argv[6])) == PO_none)
                    param.create_ticket.function_param.set_device_object_type.object_type = strtol(argv[6],0,0);
                  param.create_ticket.function_param.set_device_object_type.class
                    = RSBAC_PM_DEV_OBJECT_CLASS_ID;
                  if(argc > 7)
                    {
                      if(!strcmp(argv[7],"IPC"))
                        param.create_ticket.function_param.set_device_object_type.class
                          = RSBAC_PM_IPC_OBJECT_CLASS_ID;
                      else
                        if(!strcmp(argv[7],"DEV"))
                          param.create_ticket.function_param.set_device_object_type.class
                            = RSBAC_PM_DEV_OBJECT_CLASS_ID;
                        else
                          if(!strcmp(argv[7],"NIL"))
                            param.create_ticket.function_param.set_device_object_type.class
                              = 0;
                          else
                            param.create_ticket.function_param.set_device_object_type.class
                              = strtol(argv[7],0,0);
                    }
                  break;

                /**********/

                case PF_add_authorized_task:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.add_authorized_task.user
                   = strtol(argv[5],0,0);
                  param.create_ticket.function_param.add_authorized_task.task
                   = strtol(argv[6],0,0);
                  break;

                case PF_delete_authorized_task:
                  if(argc < 7)
                    {
                      printf("Too few arguments: argc is %i", argc);
                      use_ct(1);
                    }
                  param.create_ticket.function_param.delete_authorized_task.user
                   = strtol(argv[5],0,0);
                  param.create_ticket.function_param.delete_authorized_task.task
                   = strtol(argv[6],0,0);
                  break;

                default:
                  use_ct(1);
              }
            if(param.create_ticket.function_type != PF_add_object_class)
              res = rsbac_pm(function, &param, ticket);
            break;
            
          default:
              use(1);
        }
      if(res)
        {
          if((res > -RSBAC_EPERM) || (res < -RSBAC_EDECISIONMISMATCH))
            printf("%s: error: %s\n", argv[0], strerror(-res));
          else
            {
              get_error_name(tmp1,res);
              printf("%s: error: %s\n", argv[0], tmp1);
            }
        }
    }
  else
    {
      use(0);
    }
    
  return (res);
}

