Hardcoded device names are really bad, and we shouldn't be using them. We don't interpret variables in strings, and it's very invasive to add that functionality, so instead, build the entire cryptsetup command line ahead of time, and pass it as an environment variable to plymouth. This adds two commands, setDeviceEnv and buildEnv. setDeviceEnv stashes a device ("/dev/sda2" or "UUID=blah" or "LABEL=blah") into an environmental variable. buildEnv builds an environmental variable from its command line. --- mkinitrd | 7 ++++- nash/nash.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/mkinitrd b/mkinitrd index 271f0c4..df7a400 100755 --- a/mkinitrd +++ b/mkinitrd @@ -1580,8 +1580,11 @@ emitdmraids emitcrypto() { - emit "echo Setting up disk encryption: $1" - emit "plymouth ask-for-password --command \"cryptsetup luksOpen $1 $2\"" + local luksuuid=$(grep "^$2 " /etc/crypttab | awk '{ print $2 }') + emit "setDeviceEnv LUKSUUID $luksuuid" + emit "echo Setting up disk encryption: \$LUKSUUID" + emit "buildEnv LUKSUUID cryptsetup luksOpen \$LUKSUUID $2" + emit "plymouth ask-for-password --command \$LUKSUUID" } for cryptdev in ${!cryptopart@} ; do diff --git a/nash/nash.c b/nash/nash.c index b951578..5f04846 100644 --- a/nash/nash.c +++ b/nash/nash.c @@ -1451,6 +1451,10 @@ resolveDeviceCommand(char *cmd, char *end) eprintf("resolveDevice: device spec expected\n"); return 1; } + if (cmd < end) { + eprintf("resolveDevice: unexpected arguments\n"); + return 1; + } device = nashGetPathBySpec(_nash_context, spec); if (device) { @@ -1460,6 +1464,76 @@ resolveDeviceCommand(char *cmd, char *end) return 1; } +static int +buildEnvCommand(char *cmd, char *end) +{ + char *name = NULL; + char *arg = NULL; + char *value = NULL; + ssize_t len = 1; + + value = calloc(1, len); + if (!value) { + eprintf("buildEnv: %m\n"); + return 1; + } + + if (!(cmd = getArg(cmd, end, &name))) { + eprintf("buildEnv: environment variable expected\n"); + return 1; + } + + while ((cmd = getArg(cmd, end, &arg))) { + len += strlen(" ") + strlen(arg); + char *oldvalue = value; + value = realloc(oldvalue, len); + if (!value) { + eprintf("buildEnv: %m\n"); + free(oldvalue); + return 1; + } + if (value[0] != '\0') + strcat(value, " "); + strcat(value, arg); + } + if (value[0] == '\0') { + eprintf("buildEnv: value expected\n"); + free(value); + return 1; + } + setenv(name, value, 1); + free(value); + return 0; +} + +static int +setDeviceEnvCommand(char *cmd, char *end) +{ + char *env = NULL; + char *spec = NULL; + char *device = NULL; + + if (!(cmd = getArg(cmd, end, &env))) { + eprintf("setDeviceEnv: environment variable expected\n"); + return 1; + } + if (!(cmd = getArg(cmd, end, &spec))) { + eprintf("setDeviceEnv: device spec expected\n"); + return 1; + } + if (cmd < end) { + eprintf("setDeviceEnv: unexpected arguments\n"); + return 1; + } + + device = nashGetPathBySpec(_nash_context, spec); + if (device) { + setenv(env, device, 1); + return 0; + } + return 1; +} + /* 2.6 magic swsusp stuff */ static int resumeCommand(char * cmd, char * end) @@ -3176,6 +3250,7 @@ setQuietCommand(char * cmd, char * end) static const struct commandHandler handlers[] = { { "access", accessCommand }, + { "buildEnv", buildEnvCommand }, #ifdef DEBUG { "cat", catCommand }, #endif @@ -3214,6 +3289,7 @@ static const struct commandHandler handlers[] = { { "resume", resumeCommand }, { "resolveDevice", resolveDeviceCommand }, { "rmparts", rmpartsCommand }, + { "setDeviceEnv", setDeviceEnvCommand }, { "setquiet", setQuietCommand }, { "setuproot", setuprootCommand }, { "showelfinterp", showElfInterpCommand }, -- 1.6.2.2 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list