Ejemplo n.º 1
0
Archivo: era.c Proyecto: kralf/era-libs
int era_init_arg(era_arm_p arm, int argc, char **argv, const char* prefix,
    const char* args) {
  int result;
  can_device_p can_dev = malloc(sizeof(can_device_t));

  if (!(result = can_init_arg(can_dev, argc, argv, 0, args))) {
    era_config_t config;
    if (result = era_config_init_arg(&config, argc, argv, (prefix) ? prefix :
        ERA_ARG_PREFIX, args)) {
      config_print_usage(stdout, argv[0], args, result);
      era_config_print_help(stdout, &era_config_default, ERA_ARG_PREFIX);
      config_print_help(stdout, &can_default_config, CAN_ARG_PREFIX);
    }
    else
      era_init(arm, can_dev, &config);

    era_config_destroy(&config);
  }
  else
    era_config_print_help(stdout, &era_config_default, ERA_ARG_PREFIX);

  return result;
}
Ejemplo n.º 2
0
void config_parse_cli(int argc, char **argv, stud_config *cfg) {
  static int tls = 0, ssl = 0;
  static int client = 0;
  int c, i;
  int test_only = 0;
  char *prog;

  struct option long_options[] = {
#ifndef NO_CONFIG_FILE
    { CFG_CONFIG, 1, NULL, CFG_PARAM_CFGFILE },
    { CFG_CONFIG_DEFAULT, 0, NULL, CFG_PARAM_DEFCFG },
#endif

    { "tls", 0, &tls, 1},
    { "ssl", 0, &ssl, 1},
    { "client", 0, &client, 1},
    { CFG_CIPHERS, 1, NULL, 'c' },
    { CFG_PREFER_SERVER_CIPHERS, 0, NULL, 'O' },
    { CFG_BACKEND, 1, NULL, 'b' },
    { CFG_FRONTEND, 1, NULL, 'f' },
    { CFG_WORKERS, 1, NULL, 'n' },
    { CFG_BACKLOG, 1, NULL, 'B' },
#ifdef USE_SHARED_CACHE
    { CFG_SHARED_CACHE, 1, NULL, 'C' },
    { CFG_SHARED_CACHE_LISTEN, 1, NULL, 'U' },
    { CFG_SHARED_CACHE_PEER, 1, NULL, 'P' },
    { CFG_SHARED_CACHE_MCASTIF, 1, NULL, 'M' },
#endif
    { CFG_KEEPALIVE, 1, NULL, 'k' },
    { CFG_CHROOT, 1, NULL, 'r' },
    { CFG_USER, 1, NULL, 'u' },
    { CFG_GROUP, 1, NULL, 'g' },
    { CFG_QUIET, 0, NULL, 'q' },
    { CFG_SYSLOG, 0, NULL, 's' },
    { CFG_SYSLOG_FACILITY, 1, NULL, CFG_PARAM_SYSLOG_FACILITY },
    { CFG_DAEMON, 0, &cfg->DAEMONIZE, 1 },
    { CFG_WRITE_IP, 0, &cfg->WRITE_IP_OCTET, 1 },
    { CFG_WRITE_PROXY, 0, &cfg->WRITE_PROXY_LINE, 1 },
    { CFG_PROXY_PROXY, 0, &cfg->PROXY_PROXY_LINE, 1 },

    { "test", 0, NULL, 't' },
    { "version", 0, NULL, 'V' },
    { "help", 0, NULL, 'h' },
    { 0, 0, 0, 0 }
  };

  while (1) {
    int option_index = 0;
    c = getopt_long(
      argc, argv,
      "c:e:Ob:f:n:B:C:U:P:M:k:r:u:g:qstVh",
      long_options, &option_index
    );

    if (c == -1)
      break;

    switch (c) {
      case 0:
        break;
#ifndef NO_CONFIG_FILE
      case CFG_PARAM_CFGFILE:
        if (!config_file_parse(optarg, cfg))
          config_die("%s", config_error_get());
        break;
      case CFG_PARAM_DEFCFG:
        config_print_default(stdout, cfg);
        exit(0);
        break;
#endif
      case CFG_PARAM_SYSLOG_FACILITY:
        config_param_validate(CFG_SYSLOG_FACILITY, optarg, cfg, NULL, 0);
        break;
      case 'c':
        config_param_validate(CFG_CIPHERS, optarg, cfg, NULL, 0);
        break;
      case 'e':
        config_param_validate(CFG_SSL_ENGINE, optarg, cfg, NULL, 0);
         break;
      case 'O':
        config_param_validate(CFG_PREFER_SERVER_CIPHERS, CFG_BOOL_ON, cfg, NULL, 0);
        break;
      case 'b':
        config_param_validate(CFG_BACKEND, optarg, cfg, NULL, 0);
        break;
      case 'f':
        config_param_validate(CFG_FRONTEND, optarg, cfg, NULL, 0);
        break;
      case 'n':
        config_param_validate(CFG_WORKERS, optarg, cfg, NULL, 0);
        break;
      case 'B':
        config_param_validate(CFG_BACKLOG, optarg, cfg, NULL, 0);
        break;
#ifdef USE_SHARED_CACHE
      case 'C':
        config_param_validate(CFG_SHARED_CACHE, optarg, cfg, NULL, 0);
        break;
      case 'U':
        config_param_validate(CFG_SHARED_CACHE_LISTEN, optarg, cfg, NULL, 0);
        break;
      case 'P':
        config_param_validate(CFG_SHARED_CACHE_PEER, optarg, cfg, NULL, 0);
        break;
      case 'M':
        config_param_validate(CFG_SHARED_CACHE_MCASTIF, optarg, cfg, NULL, 0);
        break;
#endif
      case 'k':
        config_param_validate(CFG_KEEPALIVE, optarg, cfg, NULL, 0);
        break;
      case 'r':
        config_param_validate(CFG_CHROOT, optarg, cfg, NULL, 0);
        break;
      case 'u':
        config_param_validate(CFG_USER, optarg, cfg, NULL, 0);
        break;
      case 'g':
        config_param_validate(CFG_GROUP, optarg, cfg, NULL, 0);
        break;
      case 'q':
        config_param_validate(CFG_QUIET, CFG_BOOL_ON, cfg, NULL, 0);
        break;
      case 's':
        config_param_validate(CFG_SYSLOG, CFG_BOOL_ON, cfg, NULL, 0);
        break;
      case 't':
        test_only = 1;
        break;
      case 'V':
        printf("%s %s\n", basename(argv[0]), STUD_VERSION);
        exit(0);
        break;
      case 'h':
        config_print_usage(argv[0], cfg);
        exit(0);
        break;

      default:
        config_die("Invalid command line parameters. Run %s --help for instructions.", basename(argv[0]));
    }
  }

  prog = argv[0];

  if (tls && ssl)
    config_die("Options --tls and --ssl are mutually exclusive.");
  else {
    if (ssl)
      cfg->ETYPE = ENC_SSL;
    else if (tls)
      cfg->ETYPE = ENC_TLS;
  }

  if (client) {
      cfg->PMODE = SSL_CLIENT;
  }

  if (cfg->WRITE_IP_OCTET && cfg->WRITE_PROXY_LINE)
    config_die("Options --write-ip and --write-proxy are mutually exclusive.");

  if (cfg->WRITE_PROXY_LINE && cfg->PROXY_PROXY_LINE)
    config_die("Options --write-proxy and --proxy-proxy are mutually exclusive.");

  if (cfg->WRITE_IP_OCTET && cfg->PROXY_PROXY_LINE)
    config_die("Options --write-ip and --proxy-proxy are mutually exclusive.");

  if (cfg->DAEMONIZE) {
    cfg->SYSLOG = 1;
    cfg->QUIET = 1;
  }

#ifdef USE_SHARED_CACHE
  if (cfg->SHCUPD_IP != NULL && ! cfg->SHARED_CACHE)
    config_die("Shared cache update listener is defined, but shared cache is disabled.");
#endif

  // Any arguments left are presumed to be PEM files
  argc -= optind;
  argv += optind;
  for (i = 0; i < argc; i++) {
    config_param_validate(CFG_PEM_FILE, argv[i], cfg, NULL, 0);
  }
    /*
  if (cfg->PMODE == SSL_SERVER && cfg->CERT_FILES == NULL) {
    config_die("No x509 certificate PEM file specified!");
  }
    */
  // was this only a test?
  /*
  if (test_only) {
    fprintf(stderr, "Trying to initialize SSL contexts with your certificates");
    if (!init_openssl()) {
      config_die("Error initializing OpenSSL.");
    }
    printf("%s configuration looks ok.\n", basename(prog));
    exit(0);
  }
  */
}