Changeset View
Changeset View
Standalone View
Standalone View
head/sys/geom/eli/g_eli_ctl.c
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
MALLOC_DECLARE(M_ELI); | MALLOC_DECLARE(M_ELI); | ||||
static void | static void | ||||
g_eli_ctl_attach(struct gctl_req *req, struct g_class *mp) | g_eli_ctl_attach(struct gctl_req *req, struct g_class *mp) | ||||
{ | { | ||||
struct g_eli_metadata md; | struct g_eli_metadata md; | ||||
struct g_provider *pp; | struct g_provider *pp; | ||||
const char *name; | |||||
u_char *key, mkey[G_ELI_DATAIVKEYLEN]; | u_char *key, mkey[G_ELI_DATAIVKEYLEN]; | ||||
int *nargs, *detach, *readonly, *dryrunp; | int *nargs, *detach, *readonly, *dryrunp; | ||||
int keysize, error, nkey, dryrun, dummy; | int keysize, error, nkey, dryrun, dummy; | ||||
intmax_t *valp; | intmax_t *valp; | ||||
g_topology_assert(); | g_topology_assert(); | ||||
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); | nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); | ||||
Show All 40 Lines | if (dryrunp != NULL) | ||||
dryrun = *dryrunp; | dryrun = *dryrunp; | ||||
} | } | ||||
if (*detach && *readonly) { | if (*detach && *readonly) { | ||||
gctl_error(req, "Options -d and -r are mutually exclusive."); | gctl_error(req, "Options -d and -r are mutually exclusive."); | ||||
return; | return; | ||||
} | } | ||||
name = gctl_get_asciiparam(req, "arg0"); | pp = gctl_get_provider(req, "arg0"); | ||||
if (name == NULL) { | if (pp == NULL) | ||||
gctl_error(req, "No 'arg%u' argument.", 0); | |||||
return; | return; | ||||
} | |||||
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) | |||||
name += strlen(_PATH_DEV); | |||||
pp = g_provider_by_name(name); | |||||
if (pp == NULL) { | |||||
gctl_error(req, "Provider %s is invalid.", name); | |||||
return; | |||||
} | |||||
error = g_eli_read_metadata(mp, pp, &md); | error = g_eli_read_metadata(mp, pp, &md); | ||||
if (error != 0) { | if (error != 0) { | ||||
gctl_error(req, "Cannot read metadata from %s (error=%d).", | gctl_error(req, "Cannot read metadata from %s (error=%d).", | ||||
name, error); | pp->name, error); | ||||
return; | return; | ||||
} | } | ||||
if (md.md_keys == 0x00) { | if (md.md_keys == 0x00) { | ||||
explicit_bzero(&md, sizeof(md)); | explicit_bzero(&md, sizeof(md)); | ||||
gctl_error(req, "No valid keys on %s.", pp->name); | gctl_error(req, "No valid keys on %s.", pp->name); | ||||
return; | return; | ||||
} | } | ||||
if (!eli_metadata_crypto_supported(&md)) { | if (!eli_metadata_crypto_supported(&md)) { | ||||
▲ Show 20 Lines • Show All 221 Lines • ▼ Show 20 Lines | g_eli_ctl_onetime(struct gctl_req *req, struct g_class *mp) | ||||
bzero(md.md_salt, sizeof(md.md_salt)); | bzero(md.md_salt, sizeof(md.md_salt)); | ||||
md.md_keys = 0x01; | md.md_keys = 0x01; | ||||
arc4rand(mkey, sizeof(mkey), 0); | arc4rand(mkey, sizeof(mkey), 0); | ||||
/* Not important here. */ | /* Not important here. */ | ||||
bzero(md.md_hash, sizeof(md.md_hash)); | bzero(md.md_hash, sizeof(md.md_hash)); | ||||
name = gctl_get_asciiparam(req, "arg0"); | pp = gctl_get_provider(req, "arg0"); | ||||
if (name == NULL) { | if (pp == NULL) | ||||
gctl_error(req, "No 'arg%u' argument.", 0); | |||||
return; | return; | ||||
} | |||||
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) | |||||
name += strlen(_PATH_DEV); | |||||
pp = g_provider_by_name(name); | |||||
if (pp == NULL) { | |||||
gctl_error(req, "Provider %s is invalid.", name); | |||||
return; | |||||
} | |||||
sectorsize = gctl_get_paraml(req, "sectorsize", sizeof(*sectorsize)); | sectorsize = gctl_get_paraml(req, "sectorsize", sizeof(*sectorsize)); | ||||
if (sectorsize == NULL) { | if (sectorsize == NULL) { | ||||
gctl_error(req, "No '%s' argument.", "sectorsize"); | gctl_error(req, "No '%s' argument.", "sectorsize"); | ||||
return; | return; | ||||
} | } | ||||
if (*sectorsize == 0) | if (*sectorsize == 0) | ||||
md.md_sectorsize = pp->sectorsize; | md.md_sectorsize = pp->sectorsize; | ||||
▲ Show 20 Lines • Show All 842 Lines • Show Last 20 Lines |