/*
 * Copyright (c) 1996-2007, OpenFWTK Development Group
 * All rights reserved. See LICENSE.
 */

#include <string.h>
#include "firewall.h"
#include "fwfunc.h"
#include "gp_list.h"

int end_gp_list(const Group gp[], int index)
{
    if(gp[index].name[0] == '\0')       
      return 1;
    return 0;
}    

int check_gwiz(const Group act_gp[], const Group gp[])
{
  int act_gp_num;
  for(act_gp_num=0; act_gp_num < AUTH_GNUM; act_gp_num++)
  {
    if(end_gp_list(act_gp,act_gp_num))       
      break;
      
    if((act_gp[act_gp_num].flgs & AUTHFLG_GWIZ) && (strcmplist(act_gp[act_gp_num].name, gp) != -1))
      return 1;
      
  }
  return 0;
}

int strcmplist(const char * str, const Group gp[])
{
  int gp_num;
  for(gp_num=0; gp_num < AUTH_GNUM; gp_num++)
  {
    if(end_gp_list(gp,gp_num))       
      break;
    if(strcmp(str, gp[gp_num].name) == 0)
      return gp_num;
  }
  return -1;
}

int nacasematchlist(const char * str, const Group gp[])
{
  int gp_num;
  for(gp_num=0; gp_num < AUTH_GNUM; gp_num++)
  {
    if(end_gp_list(gp,gp_num))       
      break;
    if(nacasematch((char*) str, (char*) gp[gp_num].name) == 1)
      return 1;
  }
  return 0;
}

