added --optionsfrom capability
This commit is contained in:
@@ -20,15 +20,17 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <library.h>
|
|
||||||
#include <utils/debug.h>
|
|
||||||
#include <pt_tls.h>
|
#include <pt_tls.h>
|
||||||
#include <pt_tls_client.h>
|
#include <pt_tls_client.h>
|
||||||
#include <tnc/tnc.h>
|
#include <tnc/tnc.h>
|
||||||
#include <tls.h>
|
#include <tls.h>
|
||||||
|
|
||||||
|
#include <library.h>
|
||||||
|
#include <utils/debug.h>
|
||||||
#include <credentials/sets/mem_cred.h>
|
#include <credentials/sets/mem_cred.h>
|
||||||
|
#include <utils/optionsfrom.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print usage information
|
* Print usage information
|
||||||
@@ -38,6 +40,7 @@ static void usage(FILE *out, char *cmd)
|
|||||||
fprintf(out, "usage:\n");
|
fprintf(out, "usage:\n");
|
||||||
fprintf(out, " %s --connect <address> [--port <port>] [--cert <file>]+\n", cmd);
|
fprintf(out, " %s --connect <address> [--port <port>] [--cert <file>]+\n", cmd);
|
||||||
fprintf(out, " [--client <client-id>] [--secret <password>]\n");
|
fprintf(out, " [--client <client-id>] [--secret <password>]\n");
|
||||||
|
fprintf(out, " [--optionsfrom <filename>]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,7 +123,7 @@ static bool load_key(char *filename)
|
|||||||
/**
|
/**
|
||||||
* Debug level
|
* Debug level
|
||||||
*/
|
*/
|
||||||
static level_t pt_tls_level = 2;
|
static level_t pt_tls_level = 1;
|
||||||
|
|
||||||
static void dbg_pt_tls(debug_t group, level_t level, char *fmt, ...)
|
static void dbg_pt_tls(debug_t group, level_t level, char *fmt, ...)
|
||||||
{
|
{
|
||||||
@@ -135,6 +138,11 @@ static void dbg_pt_tls(debug_t group, level_t level, char *fmt, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles --optionsfrom arguments
|
||||||
|
*/
|
||||||
|
options_t *options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanup
|
* Cleanup
|
||||||
*/
|
*/
|
||||||
@@ -143,6 +151,7 @@ static void cleanup()
|
|||||||
lib->processor->cancel(lib->processor);
|
lib->processor->cancel(lib->processor);
|
||||||
lib->credmgr->remove_set(lib->credmgr, &creds->set);
|
lib->credmgr->remove_set(lib->credmgr, &creds->set);
|
||||||
creds->destroy(creds);
|
creds->destroy(creds);
|
||||||
|
options->destroy(options);
|
||||||
libtnccs_deinit();
|
libtnccs_deinit();
|
||||||
library_deinit();
|
library_deinit();
|
||||||
}
|
}
|
||||||
@@ -156,6 +165,7 @@ static void init()
|
|||||||
libtnccs_init();
|
libtnccs_init();
|
||||||
|
|
||||||
dbg = dbg_pt_tls;
|
dbg = dbg_pt_tls;
|
||||||
|
options = options_create();
|
||||||
|
|
||||||
if (!lib->plugins->load(lib->plugins,
|
if (!lib->plugins->load(lib->plugins,
|
||||||
lib->settings->get_str(lib->settings, "pt-tls-client.load", PLUGINS)))
|
lib->settings->get_str(lib->settings, "pt-tls-client.load", PLUGINS)))
|
||||||
@@ -187,6 +197,7 @@ int main(int argc, char *argv[])
|
|||||||
{"cert", required_argument, NULL, 'x' },
|
{"cert", required_argument, NULL, 'x' },
|
||||||
{"key", required_argument, NULL, 'k' },
|
{"key", required_argument, NULL, 'k' },
|
||||||
{"debug", required_argument, NULL, 'd' },
|
{"debug", required_argument, NULL, 'd' },
|
||||||
|
{"optionsfrom", required_argument, NULL, '+' },
|
||||||
{0,0,0,0 }
|
{0,0,0,0 }
|
||||||
};
|
};
|
||||||
switch (getopt_long(argc, argv, "", long_opts, NULL))
|
switch (getopt_long(argc, argv, "", long_opts, NULL))
|
||||||
@@ -228,6 +239,12 @@ int main(int argc, char *argv[])
|
|||||||
case 'd':
|
case 'd':
|
||||||
pt_tls_level = atoi(optarg);
|
pt_tls_level = atoi(optarg);
|
||||||
continue;
|
continue;
|
||||||
|
case '+': /* --optionsfrom <filename> */
|
||||||
|
if (!options->from(options, optarg, &argc, &argv, optind))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
default:
|
default:
|
||||||
usage(stderr, argv[0]);
|
usage(stderr, argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user