#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <sys/types.h>
#include <rsbac/types.h>
#include <rsbac/getname.h>
#include <rsbac/syscalls.h>
#include <rsbac/error.h>

int main(int argc, char ** argv)
{
  int res = 0;
  char tmp1[80];
  int i;
  union rsbac_attribute_value_t value;
  union rsbac_target_id_t tid;
  struct passwd * user_info_p;
  
  if (argc > 1)
    {
      printf("%s: %i users\n\n", argv[0], argc - 1);
      for (i=1;i < (argc);i++)
        {
          value.dummy = -1;
              if(   (!(user_info_p = getpwnam(argv[i])))
                 && (!(user_info_p = getpwuid(strtol(argv[i],0,0)))) )
                {
                  fprintf(stderr, "Invalid user %s!\n\n", argv[i]);
                  continue;
                }
              printf("Processing user %s (uid %i)\n",
                     user_info_p->pw_name, user_info_p->pw_uid);
              tid.user = user_info_p->pw_uid;

          res = rsbac_remove_target(T_USER, &tid);
          if(res)
            {
              if((res > -RSBAC_EPERM) || (res < -RSBAC_EDECISIONMISMATCH))
                fprintf(stderr, "%s: error: %s\n", argv[0], strerror(-res));
              else
                {
                  get_error_name(tmp1,res);
                  fprintf(stderr, "%s: error: %s\n", argv[0], tmp1);
                }
            }
          else
            printf("Returned value: %i\n",value.dummy);
        }
    }
  else
    {
      printf("%s (RSBAC %s)\n***\n", argv[0], VERSION);
      printf("Use: %s user(s)\n\n", argv[0]);  
    }
    
  return (res);
}
