예제 #1
0
파일: parse.c 프로젝트: ltworf/xinetd
/*
 * Get a service entry. Steps:
 *
 *      1. Parse entry attributes
 *      2. Determine service id
 *      3. Insert entry in table
 */
static void get_service_entry( int fd,
                               pset_h sconfs,
                               const char *name,
                               struct service_config *defaults )
{
    struct service_config   *scp ;
    const char              *func = "get_service_entry" ;

    scp = sc_alloc( name ) ;
    if ( scp == NULL )
    {
        skip_entry( fd ) ;
        return ;
    }

    /* Now fill in default attributes if given. */
    if ( SC_SPECIFIED( defaults, A_LOG_ON_SUCCESS ) &&
            ! SC_IS_PRESENT( scp, A_LOG_ON_SUCCESS) )
        fill_attribute( A_LOG_ON_SUCCESS, scp, defaults ) ;
    if ( SC_SPECIFIED( defaults, A_LOG_ON_FAILURE ) &&
            ! SC_IS_PRESENT( scp, A_LOG_ON_FAILURE ) )
        fill_attribute( A_LOG_ON_FAILURE, scp, defaults ) ;
    if ( SC_SPECIFIED( defaults, A_ONLY_FROM ) &&
            ! SC_IS_PRESENT( scp, A_ONLY_FROM ) )
        fill_attribute( A_ONLY_FROM, scp, defaults ) ;
    if ( SC_SPECIFIED( defaults, A_NO_ACCESS ) &&
            ! SC_IS_PRESENT( scp, A_NO_ACCESS ) )
        fill_attribute( A_NO_ACCESS, scp, defaults ) ;
    if ( SC_SPECIFIED( defaults, A_PASSENV ) &&
            ! SC_IS_PRESENT( scp, A_PASSENV ) )
        fill_attribute( A_PASSENV, scp, defaults ) ;
    if ( SC_SPECIFIED( defaults, A_ACCESS_TIMES ) &&
            ! SC_IS_PRESENT( scp, A_ACCESS_TIMES ) )
        fill_attribute( A_ACCESS_TIMES, scp, defaults ) ;
    if ( SC_SPECIFIED( defaults, A_BANNER ) &&
            ! SC_IS_PRESENT( scp, A_BANNER ) )
        fill_attribute( A_BANNER, scp, defaults ) ;
    if ( SC_SPECIFIED( defaults, A_BANNER_SUCCESS ) &&
            ! SC_IS_PRESENT( scp, A_BANNER_SUCCESS ) )
        fill_attribute( A_BANNER_SUCCESS, scp, defaults ) ;
    if ( SC_SPECIFIED( defaults, A_BANNER_FAIL ) &&
            ! SC_IS_PRESENT( scp, A_BANNER_FAIL ) )
        fill_attribute( A_BANNER_FAIL, scp, defaults ) ;

    if ( parse_entry( SERVICE_ENTRY, fd, scp ) == FAILED )
    {
        sc_free( scp ) ;
        skip_entry( fd ) ;
        return ;
    }

    /*
     * If no service id was specified, set it equal to the service name
     */
    if ( ! SC_SPECIFIED( scp, A_ID ) ) {
        if ( (SC_ID(scp) = new_string( SC_NAME(scp) )) )
            SC_PRESENT( scp, A_ID ) ;
        else
        {
            out_of_memory( func ) ;
            sc_free( scp ) ;
            return ;
        }
    }

    if ( ! (pset_add( sconfs, scp )) )
    {
        out_of_memory( func ) ;
        sc_free( scp ) ;
        return ;
    }

}
예제 #2
0
/* Stores in unicode_attributes[] the entire contents of the UnicodeData.txt
   file.  */
static void
fill_attributes (const char *unicodedata_filename)
{
  unsigned int i, j;
  FILE *stream;
  char field0[FIELDLEN];
  char field1[FIELDLEN];
  char field2[FIELDLEN];
  char field3[FIELDLEN];
  char field4[FIELDLEN];
  char field5[FIELDLEN];
  char field6[FIELDLEN];
  char field7[FIELDLEN];
  char field8[FIELDLEN];
  char field9[FIELDLEN];
  char field10[FIELDLEN];
  char field11[FIELDLEN];
  char field12[FIELDLEN];
  char field13[FIELDLEN];
  char field14[FIELDLEN];
  int lineno = 0;

  for (i = 0; i < 0x110000; i++)
    unicode_attributes[i].name = NULL;

  stream = fopen (unicodedata_filename, "r");
  if (stream == NULL)
    {
      fprintf (stderr, "error during fopen of '%s'\n", unicodedata_filename);
      exit (1);
    }

  for (;;)
    {
      int n;

      lineno++;
      n = getfield (stream, field0, ';');
      n += getfield (stream, field1, ';');
      n += getfield (stream, field2, ';');
      n += getfield (stream, field3, ';');
      n += getfield (stream, field4, ';');
      n += getfield (stream, field5, ';');
      n += getfield (stream, field6, ';');
      n += getfield (stream, field7, ';');
      n += getfield (stream, field8, ';');
      n += getfield (stream, field9, ';');
      n += getfield (stream, field10, ';');
      n += getfield (stream, field11, ';');
      n += getfield (stream, field12, ';');
      n += getfield (stream, field13, ';');
      n += getfield (stream, field14, '\n');
      if (n == 0)
	break;
      if (n != 15)
	{
	  fprintf (stderr, "short line in'%s':%d\n",
		   unicodedata_filename, lineno);
	  exit (1);
	}
      i = strtoul (field0, NULL, 16);
      if (field1[0] == '<'
	  && strlen (field1) >= 9
	  && !strcmp (field1 + strlen(field1) - 8, ", First>"))
	{
	  /* Deal with a range. */
	  lineno++;
	  n = getfield (stream, field0, ';');
	  n += getfield (stream, field1, ';');
	  n += getfield (stream, field2, ';');
	  n += getfield (stream, field3, ';');
	  n += getfield (stream, field4, ';');
	  n += getfield (stream, field5, ';');
	  n += getfield (stream, field6, ';');
	  n += getfield (stream, field7, ';');
	  n += getfield (stream, field8, ';');
	  n += getfield (stream, field9, ';');
	  n += getfield (stream, field10, ';');
	  n += getfield (stream, field11, ';');
	  n += getfield (stream, field12, ';');
	  n += getfield (stream, field13, ';');
	  n += getfield (stream, field14, '\n');
	  if (n != 15)
	    {
	      fprintf (stderr, "missing end range in '%s':%d\n",
		       unicodedata_filename, lineno);
	      exit (1);
	    }
	  if (!(field1[0] == '<'
		&& strlen (field1) >= 8
		&& !strcmp (field1 + strlen (field1) - 7, ", Last>")))
	    {
	      fprintf (stderr, "missing end range in '%s':%d\n",
		       unicodedata_filename, lineno);
	      exit (1);
	    }
	  field1[strlen (field1) - 7] = '\0';
	  j = strtoul (field0, NULL, 16);
	  for (; i <= j; i++)
	    fill_attribute (i, field1+1, field2, field3, field4, field5,
			       field6, field7, field8, field9, field10,
			       field11, field12, field13, field14);
	}
      else
	{
	  /* Single character line */
	  fill_attribute (i, field1, field2, field3, field4, field5,
			     field6, field7, field8, field9, field10,
			     field11, field12, field13, field14);
	}
    }
  if (ferror (stream) || fclose (stream))
    {
      fprintf (stderr, "error reading from '%s'\n", unicodedata_filename);
      exit (1);
    }
}