Пример #1
0
/***************************************************************
 Load
 ***************************************************************/
static obj_ptr _load_imp(cptr file, obj_ptr env)
{
    port_ptr p;
    obj_ptr  o = NIL;

    p = port_open_input_file(file);
    while (!port_eof(p))
    {
        o = obj_read(p);
        if (ERRORP(o)) break;
        o = obj_eval(o, env);
        if (ERRORP(o)) break;
        port_skip_while(p, isspace);
    }

    if (ERRORP(o))
        error_add_file_info(o, port_name(p), port_line(p));

    port_close(p);
    return o;
}
Пример #2
0
/* Control the process of parsing the conf file and intializing
 * the 'ci' struct with relevant values.  We are interested in 
 * the following values:
 *
 * config value name    default
 * -----------------    -------
 * irrd_port            43
 * irrd_host            localhost
 * super_passwd         NULL ie, no super password accepted unless it is configured
 * submission_log_dir   'irr_directory' irrd.conf value if present
 *                      log_dir == NULL means no logging
 * irr_directory        DEF_DBCACHE see irr_defs.h
 * pgp_dir              NULL ie, user's ~/.pgp is assumed
 * db_admin             email for new maintainer requests
 * reply_from		email to use as reply from address.
 * 'ci' (sources struc) empty list
 *
 * Function assumes 'ci' has bee set to all 0's.  Command line options
 * override the irrd.conf options so if a value is set then the corresponding
 * irrd.conf value will be ignored.
 *
 * Result:
 *   1 if irrd.conf file was opened successfully
 *   -1 otherwise
 *   intialize the 'ci' struct
 */
int parse_irrd_conf_file (char *config_fname, trace_t *tr) {
  FILE *fin;
  char buf[MAXLINE+1], *p, *q, *s, *irr_dir = NULL;
  char val[MAXLINE+1];
  int len, offset;
  config_info_t temp_ci = {0};
  src_t sstart;
  source_t *obj;
  regmatch_t rm[9];
  regex_t re_accept, re_auth, re_rpstrust;

  /* rpsdist <db> accept <host> */
  char *accept = "^[ \t]*(([[:graph:]]+)[ \t]+)?accept[ \t]+([[:graph:]]+)[ \t]*\n?$";
  
  /* rpsdist_database <db> authoritative <pgppass> */
  char *auth =  "^[ \t]*([[:graph:]]+)[ \t]+authoritative[ \t]+"
    "((\"(.+)\")|([^\" \t\n]+))[ \t]*\n?$";

  /* rpsdist_database <db> trusted <host> <port> */
  char *rpstrust = "^[ \t]*([[:graph:]]+)[ \t]+trusted[ \t]+"
    "([[:graph:]]+)[ \t]+([[:digit:]]+)[ \t]*\n?$";

  /* compile our regex's */
  regcomp (&re_accept,   accept,   REG_EXTENDED|REG_ICASE);
  regcomp (&re_auth,     auth,     REG_EXTENDED|REG_ICASE);
  regcomp (&re_rpstrust, rpstrust, REG_EXTENDED|REG_ICASE);

  /* load the defaults */
  sstart.first = sstart.last = NULL;
  temp_ci.irrd_port = 43;
  temp_ci.irrd_host = strdup ("localhost");
  temp_ci.log_dir = NULL;  /* default is 'irr_directory' value */
  temp_ci.db_dir  = strdup (DEF_DBCACHE);
  temp_ci.pgp_dir = NULL;
  temp_ci.db_admin = NULL; /* email addr to send maintainer req's */
  temp_ci.reply_from = NULL; /* email addr to use for From:/Reply-To: */
  temp_ci.footer_msg = NULL; /* footer text */
  if (ci.footer_msg != NULL) {
    if (ci.footer_msg[0] != (char ) '"') {
      strcpy (buf, "\"");
      strcat (buf, ci.footer_msg);
      strcat (buf, "\"");
      s = get_footer_msg (buf);
    }
    else
      s = get_footer_msg (ci.footer_msg);
    free (ci.footer_msg);
    ci.footer_msg = strdup (s);
  }
  
  /* load the default config file name */
  if (config_fname == NULL)
    config_fname = "/etc/irrd.conf";
  
  /* open the config file */
  if ((fin = fopen (config_fname, "r")) == NULL) {
    fprintf (stderr, "Error opening IRRd conf file \"%s\": %s\n",
             config_fname, strerror(errno));
    return -1;
  }
  
  /* pick off the value of relavent fields */
  while (fgets (buf, MAXLINE, fin) != NULL) {
    p = q = buf;
    if (find_conf_token (&p, &q) > 0) {
      len = (int) (q - p);
      if (len > 5 && !strncmp (p, "irr_database", len)) {
	/* authoritative */
	db_line (q, &sstart);
      }
      else if (len > 15 && !strncmp (p, "rpsdist_database", len)) {
	db_line (q, &sstart);
	
	/* rpsdist trusted */
	if (regexec (&re_rpstrust, q, 8, rm, 0) == 0) {
	  /* DB name */
	  *(q + rm[1].rm_eo) = '\0';
	  if ((obj = find_src_object (&sstart, q + rm[1].rm_so)) != NULL) {
	    obj->rpsdist_flag = 1;
	    obj->rpsdist_trusted = 1;
	    
	    /* host */
	    *(q + rm[2].rm_eo) = '\0';
	    obj->rpsdist_host = strdup (q + rm[2].rm_so);
	    
	    /* port */
	    *(q + rm[3].rm_eo) = '\0';
	    obj->rpsdist_port = strdup (q + rm[3].rm_so);
	  }
	}

	/* authoritative and pgppass */
	else if (regexec (&re_auth, q, 9, rm, 0) == 0) {
	  /* DB name */
	  *(q + rm[1].rm_eo) = '\0';
	  if ((obj = find_src_object (&sstart, q + rm[1].rm_so)) != NULL) {
	    obj->rpsdist_flag = 1;
	    obj->rpsdist_auth = 1;
	    offset = 5;
	    if (rm[4].rm_so != -1)
	      offset = 4;
	    *(q + rm[offset].rm_eo) = '\0';
	    strcpy (val, (char *) (q + rm[offset].rm_so));
	    obj->rpsdist_pgppass = strdup (val);
	  }
	}
      }

      if (regexec (&re_accept, q, 4, rm, 0) == 0) {
	/* optional DB name(2), address (3) */
	*(q + rm[3].rm_eo) = '\0';
	if( rm[2].rm_so != -1 ){
	  *(q + rm[2].rm_eo) = '\0';
	  add_acl((q + rm[3].rm_so), (q + rm[2].rm_so), &ci.acls);	    
	}
	else
	  add_acl((q + rm[3].rm_so), NULL, &ci.acls);
      }
      else if (len > 4 && !strncmp (p, "irr_port", len))
	temp_ci.irrd_port = port_line (q, &temp_ci.irrd_port);
      else if (len > 4 && !strncmp (p, "irr_host", len))
	temp_ci.irrd_host = char_line (q, temp_ci.irrd_host);
      else if (len > 3 && !strncmp (p, "override_cryptpw", len))
	temp_ci.super_passwd = char_line (q, temp_ci.super_passwd);
      else if (len > 4 && !strncmp (p, "pgp_dir", len))
	temp_ci.pgp_dir = char_line (q, temp_ci.pgp_dir);
      else if (len > 5 && !strncmp (p, "irr_directory", len))
	irr_dir = char_line (q, irr_dir);
      else if (len > 3 && !strncmp (p, "db_admin", len))
	temp_ci.db_admin = char_line (q, temp_ci.db_admin);
      else if (len > 5 && !strncmp (p, "reply_from", len))
	temp_ci.reply_from = char_line (q, temp_ci.reply_from);
      else if (len > 4  && !strncmp (p, "debug", len)) 
	config_trace_local (tr, q);
      else if (len > 10 && ci.footer_msg == NULL &&
	       !strncmp (p, "response_footer", len))
	temp_ci.footer_msg = myconcat_nospace (temp_ci.footer_msg, get_footer_msg (q));
      else if (len > 10 && ci.notify_header_msg == NULL &&
	       !strncmp (p, "response_notify_header", len))
	temp_ci.notify_header_msg =
	  myconcat_nospace (temp_ci.replace_msg, get_footer_msg (q));
      else if (len > 10 && ci.replace_msg == NULL &&
	       !strncmp (p, "response_replace", len))
	temp_ci.replace_msg =
	  myconcat_nospace (temp_ci.replace_msg, get_footer_msg (q));
      else if (len > 10 && ci.forward_header_msg == NULL &&
	       !strncmp (p, "response_forward_header", len))
	temp_ci.forward_header_msg = 
	  myconcat_nospace (temp_ci.forward_header_msg, get_footer_msg (q));
      else if (len > 5 && !strncmp (p, "irr_database", len)) {

      }
    }
  }

  /* If the user has specified command line options,
   * then use those instead of the irrd.conf options
   */
  if (ci.srcs == NULL)
    ci.srcs = sstart.first;

  if (ci.irrd_port == 0)
    ci.irrd_port = temp_ci.irrd_port;

  if (ci.irrd_host == NULL)
   ci.irrd_host = temp_ci.irrd_host;
  else
    free_mem (temp_ci.irrd_host);

  if (ci.super_passwd == NULL)
    ci.super_passwd = temp_ci.super_passwd;
  else
    free_mem (temp_ci.super_passwd);

  if (ci.footer_msg == NULL) {
    if (temp_ci.footer_msg != NULL) {
        ci.footer_msg = strdup (temp_ci.footer_msg);
  	free_mem (temp_ci.footer_msg);
    }
  } 

  if (ci.notify_header_msg == NULL) {
    if (temp_ci.notify_header_msg != NULL) {
        ci.notify_header_msg = strdup (temp_ci.notify_header_msg);
  	free_mem (temp_ci.notify_header_msg);
    }
  } 

  if (ci.replace_msg == NULL) {
    if (temp_ci.replace_msg != NULL) {
        ci.replace_msg = strdup (temp_ci.replace_msg);
  	free_mem (temp_ci.replace_msg);
    }
  } 

  if (ci.forward_header_msg == NULL) {
    if (temp_ci.forward_header_msg != NULL) {
        ci.forward_header_msg = strdup (temp_ci.forward_header_msg);
  	free_mem (temp_ci.forward_header_msg);
    }
  } 

  /* need the db cache directory for rps_dist communication */
  if (irr_dir != NULL)
    ci.db_dir = strdup (irr_dir);

  /* see if the cache dir exists.  we do not need
   * it except for default ack and trans logs
   * and pgp dir */
  if ((s = dir_chks (ci.db_dir, 0)) != NULL) {
    ci.db_dir = NULL;
    trace (NORM, tr, "irr_dir set to NULL:%s\n", s);
    free (s);
  }
    
  /* pgp directory processing, used by RPS-DIST */
  if (ci.pgp_dir == NULL) {
    if (temp_ci.pgp_dir == NULL) {
      ci.pgp_dir = make_pgpname (irr_dir);
    }
    else
      ci.pgp_dir = temp_ci.pgp_dir;
  }
  else
    free_mem (temp_ci.pgp_dir);

  /* see if the pgp dir exists. */
  if ((s = dir_chks (ci.pgp_dir, 0)) != NULL) {
    ci.pgp_dir = NULL;
    trace (NORM, tr, "pgp_dir set to NULL:%s\n", s);
    free (s);
  }

  /* what the hey, we only leak a little memory */
  if (ci.log_dir == NULL) {
    if (temp_ci.log_dir == NULL)
      ci.log_dir = irr_dir;
    else
      ci.log_dir = temp_ci.log_dir;
  }
  else {
    free_mem (irr_dir);
    free_mem (temp_ci.log_dir);
  }

  /* see if the log dir exists. */
  if ((s = dir_chks (ci.log_dir, 0)) != NULL) {
    ci.log_dir = NULL;
    trace (NORM, tr, "log_dir set to NULL:%s\n", s);
    free (s);
  }

  if (ci.db_admin == NULL)
    ci.db_admin = temp_ci.db_admin;
  else
    free_mem (temp_ci.db_admin);

  if (ci.reply_from == NULL)
    ci.reply_from = temp_ci.reply_from;
  else
    free_mem (temp_ci.reply_from);

  fclose  (fin);
  regfree (&re_accept);
  regfree (&re_auth);
  regfree (&re_rpstrust);

  return 1;
}