- Allow to specify value as const pointers.
- Make optional string values always an empty string.
This commit is contained in:
parent
b7d28b2e0b
commit
a478ea7490
@ -55,15 +55,12 @@ uint32_t lib_version = G_LIB_VERSION;
|
||||
uint32_t version = G_ELI_VERSION;
|
||||
|
||||
#define GELI_BACKUP_DIR "/var/backups/"
|
||||
#define GELI_ENC_ALGO "aes"
|
||||
|
||||
static char aalgo[] = "none";
|
||||
static char ealgo[] = "aes";
|
||||
static intmax_t keylen = 0;
|
||||
static intmax_t keyno = -1;
|
||||
static intmax_t iterations = -1;
|
||||
static intmax_t sectorsize = 0;
|
||||
static char keyfile[] = "", newkeyfile[] = "";
|
||||
static char backupfile[] = "";
|
||||
|
||||
static void eli_main(struct gctl_req *req, unsigned flags);
|
||||
static void eli_init(struct gctl_req *req);
|
||||
@ -101,12 +98,12 @@ static int eli_backup_create(struct gctl_req *req, const char *prov,
|
||||
struct g_command class_commands[] = {
|
||||
{ "init", G_FLAG_VERBOSE, eli_main,
|
||||
{
|
||||
{ 'a', "aalgo", aalgo, G_TYPE_STRING },
|
||||
{ 'a', "aalgo", "", G_TYPE_STRING },
|
||||
{ 'b', "boot", NULL, G_TYPE_BOOL },
|
||||
{ 'B', "backupfile", backupfile, G_TYPE_STRING },
|
||||
{ 'e', "ealgo", ealgo, G_TYPE_STRING },
|
||||
{ 'B', "backupfile", "", G_TYPE_STRING },
|
||||
{ 'e', "ealgo", GELI_ENC_ALGO, G_TYPE_STRING },
|
||||
{ 'i', "iterations", &iterations, G_TYPE_NUMBER },
|
||||
{ 'K', "newkeyfile", newkeyfile, G_TYPE_STRING },
|
||||
{ 'K', "newkeyfile", "", G_TYPE_STRING },
|
||||
{ 'l', "keylen", &keylen, G_TYPE_NUMBER },
|
||||
{ 'P', "nonewpassphrase", NULL, G_TYPE_BOOL },
|
||||
{ 's', "sectorsize", §orsize, G_TYPE_NUMBER },
|
||||
@ -116,12 +113,12 @@ struct g_command class_commands[] = {
|
||||
},
|
||||
{ "label", G_FLAG_VERBOSE, eli_main,
|
||||
{
|
||||
{ 'a', "aalgo", aalgo, G_TYPE_STRING },
|
||||
{ 'a', "aalgo", "", G_TYPE_STRING },
|
||||
{ 'b', "boot", NULL, G_TYPE_BOOL },
|
||||
{ 'B', "backupfile", backupfile, G_TYPE_STRING },
|
||||
{ 'e', "ealgo", ealgo, G_TYPE_STRING },
|
||||
{ 'B', "backupfile", "", G_TYPE_STRING },
|
||||
{ 'e', "ealgo", GELI_ENC_ALGO, G_TYPE_STRING },
|
||||
{ 'i', "iterations", &iterations, G_TYPE_NUMBER },
|
||||
{ 'K', "newkeyfile", newkeyfile, G_TYPE_STRING },
|
||||
{ 'K', "newkeyfile", "", G_TYPE_STRING },
|
||||
{ 'l', "keylen", &keylen, G_TYPE_NUMBER },
|
||||
{ 'P', "nonewpassphrase", NULL, G_TYPE_BOOL },
|
||||
{ 's', "sectorsize", §orsize, G_TYPE_NUMBER },
|
||||
@ -132,7 +129,7 @@ struct g_command class_commands[] = {
|
||||
{ "attach", G_FLAG_VERBOSE | G_FLAG_LOADKLD, eli_main,
|
||||
{
|
||||
{ 'd', "detach", NULL, G_TYPE_BOOL },
|
||||
{ 'k', "keyfile", keyfile, G_TYPE_STRING },
|
||||
{ 'k', "keyfile", "", G_TYPE_STRING },
|
||||
{ 'p', "nopassphrase", NULL, G_TYPE_BOOL },
|
||||
{ 'r', "readonly", NULL, G_TYPE_BOOL },
|
||||
G_OPT_SENTINEL
|
||||
@ -157,9 +154,9 @@ struct g_command class_commands[] = {
|
||||
},
|
||||
{ "onetime", G_FLAG_VERBOSE | G_FLAG_LOADKLD, NULL,
|
||||
{
|
||||
{ 'a', "aalgo", aalgo, G_TYPE_STRING },
|
||||
{ 'a', "aalgo", "", G_TYPE_STRING },
|
||||
{ 'd', "detach", NULL, G_TYPE_BOOL },
|
||||
{ 'e', "ealgo", ealgo, G_TYPE_STRING },
|
||||
{ 'e', "ealgo", GELI_ENC_ALGO, G_TYPE_STRING },
|
||||
{ 'l', "keylen", &keylen, G_TYPE_NUMBER },
|
||||
{ 's', "sectorsize", §orsize, G_TYPE_NUMBER },
|
||||
G_OPT_SENTINEL
|
||||
@ -177,8 +174,8 @@ struct g_command class_commands[] = {
|
||||
{ "setkey", G_FLAG_VERBOSE, eli_main,
|
||||
{
|
||||
{ 'i', "iterations", &iterations, G_TYPE_NUMBER },
|
||||
{ 'k', "keyfile", keyfile, G_TYPE_STRING },
|
||||
{ 'K', "newkeyfile", newkeyfile, G_TYPE_STRING },
|
||||
{ 'k', "keyfile", "", G_TYPE_STRING },
|
||||
{ 'K', "newkeyfile", "", G_TYPE_STRING },
|
||||
{ 'n', "keyno", &keyno, G_TYPE_NUMBER },
|
||||
{ 'p', "nopassphrase", NULL, G_TYPE_BOOL },
|
||||
{ 'P', "nonewpassphrase", NULL, G_TYPE_BOOL },
|
||||
@ -551,7 +548,7 @@ eli_init(struct gctl_req *req)
|
||||
md.md_flags |= G_ELI_FLAG_BOOT;
|
||||
md.md_ealgo = CRYPTO_ALGORITHM_MIN - 1;
|
||||
str = gctl_get_ascii(req, "aalgo");
|
||||
if (strcmp(str, "none") != 0) {
|
||||
if (*str != '\0') {
|
||||
md.md_aalgo = g_eli_str2aalgo(str);
|
||||
if (md.md_aalgo >= CRYPTO_ALGORITHM_MIN &&
|
||||
md.md_aalgo <= CRYPTO_ALGORITHM_MAX) {
|
||||
|
@ -44,7 +44,8 @@ __FBSDID("$FreeBSD$");
|
||||
uint32_t lib_version = G_LIB_VERSION;
|
||||
uint32_t version = G_MIRROR_VERSION;
|
||||
|
||||
static char label_balance[] = "load", configure_balance[] = "none";
|
||||
#define GMIRROR_BALANCE "load"
|
||||
|
||||
static intmax_t label_slice = 4096, configure_slice = -1;
|
||||
static intmax_t insert_priority = 0, configure_priority = -1;
|
||||
|
||||
@ -64,7 +65,7 @@ struct g_command class_commands[] = {
|
||||
{ "configure", G_FLAG_VERBOSE, NULL,
|
||||
{
|
||||
{ 'a', "autosync", NULL, G_TYPE_BOOL },
|
||||
{ 'b', "balance", configure_balance, G_TYPE_STRING },
|
||||
{ 'b', "balance", "", G_TYPE_STRING },
|
||||
{ 'd', "dynamic", NULL, G_TYPE_BOOL },
|
||||
{ 'f', "failsync", NULL, G_TYPE_BOOL },
|
||||
{ 'F', "nofailsync", NULL, G_TYPE_BOOL },
|
||||
@ -88,7 +89,7 @@ struct g_command class_commands[] = {
|
||||
},
|
||||
{ "label", G_FLAG_VERBOSE, mirror_main,
|
||||
{
|
||||
{ 'b', "balance", label_balance, G_TYPE_STRING },
|
||||
{ 'b', "balance", GMIRROR_BALANCE, G_TYPE_STRING },
|
||||
{ 'F', "nofailsync", NULL, G_TYPE_BOOL },
|
||||
{ 'h', "hardcode", NULL, G_TYPE_BOOL },
|
||||
{ 'n', "noautosync", NULL, G_TYPE_BOOL },
|
||||
|
@ -59,7 +59,6 @@ uint32_t PUBSYM(lib_version) = G_LIB_VERSION;
|
||||
uint32_t PUBSYM(version) = 0;
|
||||
|
||||
static char autofill[] = "*";
|
||||
static char optional[] = "";
|
||||
static char flags[] = "C";
|
||||
|
||||
static char sstart[32];
|
||||
@ -91,16 +90,16 @@ struct g_command PUBSYM(class_commands)[] = {
|
||||
{ 'b', "start", autofill, G_TYPE_STRING },
|
||||
{ 's', "size", autofill, G_TYPE_STRING },
|
||||
{ 't', "type", NULL, G_TYPE_STRING },
|
||||
{ 'i', index_param, optional, G_TYPE_ASCNUM },
|
||||
{ 'l', "label", optional, G_TYPE_STRING },
|
||||
{ 'i', index_param, "", G_TYPE_ASCNUM },
|
||||
{ 'l', "label", "", G_TYPE_STRING },
|
||||
{ 'f', "flags", flags, G_TYPE_STRING },
|
||||
G_OPT_SENTINEL },
|
||||
"geom", NULL
|
||||
},
|
||||
{ "bootcode", 0, gpart_bootcode, {
|
||||
{ 'b', bootcode_param, optional, G_TYPE_STRING },
|
||||
{ 'p', partcode_param, optional, G_TYPE_STRING },
|
||||
{ 'i', index_param, optional, G_TYPE_ASCNUM },
|
||||
{ 'b', bootcode_param, "", G_TYPE_STRING },
|
||||
{ 'p', partcode_param, "", G_TYPE_STRING },
|
||||
{ 'i', index_param, "", G_TYPE_ASCNUM },
|
||||
{ 'f', "flags", flags, G_TYPE_STRING },
|
||||
G_OPT_SENTINEL },
|
||||
"geom", NULL
|
||||
@ -108,7 +107,7 @@ struct g_command PUBSYM(class_commands)[] = {
|
||||
{ "commit", 0, gpart_issue, G_NULL_OPTS, "geom", NULL },
|
||||
{ "create", 0, gpart_issue, {
|
||||
{ 's', "scheme", NULL, G_TYPE_STRING },
|
||||
{ 'n', "entries", optional, G_TYPE_ASCNUM },
|
||||
{ 'n', "entries", "", G_TYPE_ASCNUM },
|
||||
{ 'f', "flags", flags, G_TYPE_STRING },
|
||||
G_OPT_SENTINEL },
|
||||
"provider", NULL
|
||||
@ -125,8 +124,8 @@ struct g_command PUBSYM(class_commands)[] = {
|
||||
"geom", NULL },
|
||||
{ "modify", 0, gpart_issue, {
|
||||
{ 'i', index_param, NULL, G_TYPE_ASCNUM },
|
||||
{ 'l', "label", optional, G_TYPE_STRING },
|
||||
{ 't', "type", optional, G_TYPE_STRING },
|
||||
{ 'l', "label", "", G_TYPE_STRING },
|
||||
{ 't', "type", "", G_TYPE_STRING },
|
||||
{ 'f', "flags", flags, G_TYPE_STRING },
|
||||
G_OPT_SENTINEL },
|
||||
"geom", NULL
|
||||
|
@ -54,7 +54,7 @@ uint32_t version = G_SCHED_VERSION;
|
||||
* storage for parameters used by this geom class.
|
||||
* Right now only the scheduler name is used.
|
||||
*/
|
||||
static char algo[] = "rr"; /* default scheduler */
|
||||
#define GSCHED_ALGO "rr" /* default scheduler */
|
||||
|
||||
/*
|
||||
* Adapt to differences in geom library.
|
||||
@ -76,7 +76,7 @@ gcmd_createinsert(struct gctl_req *req, unsigned flags __unused)
|
||||
if (gctl_has_param(req, "algo"))
|
||||
reqalgo = gctl_get_ascii(req, "algo");
|
||||
else
|
||||
reqalgo = algo;
|
||||
reqalgo = GSCHED_ALGO;
|
||||
|
||||
snprintf(name, sizeof(name), "gsched_%s", reqalgo);
|
||||
/*
|
||||
@ -91,21 +91,21 @@ gcmd_createinsert(struct gctl_req *req, unsigned flags __unused)
|
||||
struct g_command class_commands[] = {
|
||||
{ "create", G_FLAG_VERBOSE | G_FLAG_LOADKLD, gcmd_createinsert,
|
||||
{
|
||||
{ 'a', "algo", algo, G_TYPE_STRING },
|
||||
{ 'a', "algo", GSCHED_ALGO, G_TYPE_STRING },
|
||||
G_OPT_SENTINEL
|
||||
},
|
||||
G_ARGNAME "[-v] [-a algorithm_name] dev ..."
|
||||
},
|
||||
{ "insert", G_FLAG_VERBOSE | G_FLAG_LOADKLD, gcmd_createinsert,
|
||||
{
|
||||
{ 'a', "algo", algo, G_TYPE_STRING },
|
||||
{ 'a', "algo", GSCHED_ALGO, G_TYPE_STRING },
|
||||
G_OPT_SENTINEL
|
||||
},
|
||||
G_ARGNAME "[-v] [-a algorithm_name] dev ..."
|
||||
},
|
||||
{ "configure", G_FLAG_VERBOSE, NULL,
|
||||
{
|
||||
{ 'a', "algo", algo, G_TYPE_STRING },
|
||||
{ 'a', "algo", GSCHED_ALGO, G_TYPE_STRING },
|
||||
G_OPT_SENTINEL
|
||||
},
|
||||
G_ARGNAME "[-v] [-a algorithm_name] prov ..."
|
||||
|
@ -236,8 +236,8 @@ find_option(struct g_command *cmd, char ch)
|
||||
static void
|
||||
set_option(struct gctl_req *req, struct g_option *opt, const char *val)
|
||||
{
|
||||
char *s;
|
||||
uint64_t number;
|
||||
void *ptr;
|
||||
|
||||
if (G_OPT_TYPE(opt) == G_TYPE_NUMBER ||
|
||||
G_OPT_TYPE(opt) == G_TYPE_ASCNUM) {
|
||||
@ -245,27 +245,29 @@ set_option(struct gctl_req *req, struct g_option *opt, const char *val)
|
||||
err(EXIT_FAILURE, "Invalid value for '%c' argument.",
|
||||
opt->go_char);
|
||||
}
|
||||
if (G_OPT_TYPE(opt) == G_TYPE_NUMBER)
|
||||
opt->go_val = malloc(sizeof(intmax_t));
|
||||
else {
|
||||
asprintf(&s, "%jd", number);
|
||||
opt->go_val = s;
|
||||
}
|
||||
if (opt->go_val == NULL)
|
||||
errx(EXIT_FAILURE, "No memory.");
|
||||
if (G_OPT_TYPE(opt) == G_TYPE_NUMBER) {
|
||||
*(intmax_t *)opt->go_val = number;
|
||||
ptr = malloc(sizeof(intmax_t));
|
||||
if (ptr == NULL)
|
||||
errx(EXIT_FAILURE, "No memory.");
|
||||
*(intmax_t *)ptr = number;
|
||||
opt->go_val = ptr;
|
||||
gctl_ro_param(req, opt->go_name, sizeof(intmax_t),
|
||||
opt->go_val);
|
||||
} else
|
||||
} else {
|
||||
asprintf((void *)(&ptr), "%jd", number);
|
||||
if (ptr == NULL)
|
||||
errx(EXIT_FAILURE, "No memory.");
|
||||
opt->go_val = ptr;
|
||||
gctl_ro_param(req, opt->go_name, -1, opt->go_val);
|
||||
}
|
||||
} else if (G_OPT_TYPE(opt) == G_TYPE_STRING) {
|
||||
gctl_ro_param(req, opt->go_name, -1, val);
|
||||
} else if (G_OPT_TYPE(opt) == G_TYPE_BOOL) {
|
||||
opt->go_val = malloc(sizeof(int));
|
||||
if (opt->go_val == NULL)
|
||||
ptr = malloc(sizeof(int));
|
||||
if (ptr == NULL)
|
||||
errx(EXIT_FAILURE, "No memory.");
|
||||
*(int *)opt->go_val = *val - '0';
|
||||
*(int *)ptr = *val - '0';
|
||||
opt->go_val = ptr;
|
||||
gctl_ro_param(req, opt->go_name, sizeof(int), opt->go_val);
|
||||
} else {
|
||||
assert(!"Invalid type");
|
||||
@ -354,7 +356,7 @@ parse_arguments(struct g_command *cmd, struct gctl_req *req, int *argc,
|
||||
G_OPT_TYPE(opt) == G_TYPE_ASCNUM) {
|
||||
if (cmd->gc_argname == NULL ||
|
||||
opt->go_val == NULL ||
|
||||
*(char *)opt->go_val != '\0')
|
||||
*(const char *)opt->go_val != '\0')
|
||||
gctl_ro_param(req, opt->go_name,
|
||||
-1, opt->go_val);
|
||||
} else {
|
||||
|
@ -54,7 +54,7 @@
|
||||
struct g_option {
|
||||
char go_char;
|
||||
const char *go_name;
|
||||
void *go_val;
|
||||
const void *go_val;
|
||||
unsigned go_type;
|
||||
};
|
||||
|
||||
|
@ -269,7 +269,7 @@ g_eli_ctl_onetime(struct gctl_req *req, struct g_class *mp)
|
||||
gctl_error(req, "No '%s' argument.", "aalgo");
|
||||
return;
|
||||
}
|
||||
if (strcmp(name, "none") != 0) {
|
||||
if (*name != '\0') {
|
||||
md.md_aalgo = g_eli_str2aalgo(name);
|
||||
if (md.md_aalgo >= CRYPTO_ALGORITHM_MIN &&
|
||||
md.md_aalgo <= CRYPTO_ALGORITHM_MAX) {
|
||||
|
@ -192,7 +192,7 @@ g_mirror_ctl_configure(struct gctl_req *req, struct g_class *mp)
|
||||
gctl_error(req, "No such device: %s.", name);
|
||||
return;
|
||||
}
|
||||
if (strcmp(balancep, "none") == 0)
|
||||
if (*balancep == '\0')
|
||||
balance = sc->sc_balance;
|
||||
else {
|
||||
if (balance_id(balancep) == -1) {
|
||||
@ -215,7 +215,7 @@ g_mirror_ctl_configure(struct gctl_req *req, struct g_class *mp)
|
||||
/* Enforce usage() of -p not allowing any other options. */
|
||||
if (do_priority && (*autosync || *noautosync || *failsync ||
|
||||
*nofailsync || *hardcode || *dynamic || *slicep != -1 ||
|
||||
strcmp(balancep, "none") != 0)) {
|
||||
*balancep != '\0')) {
|
||||
sx_xunlock(&sc->sc_lock);
|
||||
gctl_error(req, "only -p accepted when setting priority");
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user