Clean up a long-standing bug in the scripting code. You could set variables,

but you couldn't call functions!  Now you can do both.
Guard against whitespace pollution in variable names.
This commit is contained in:
Jordan K. Hubbard 1997-01-16 10:24:09 +00:00
parent 1d0847d38d
commit 37c16c5340
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=21764
9 changed files with 132 additions and 81 deletions

View file

@ -37,6 +37,8 @@
#include "sysinstall.h"
#include <ctype.h>
static int _shutdown(dialogMenuItem *unused);
static struct _word {
char *name;
int (*handler)(dialogMenuItem *self);
@ -85,6 +87,7 @@ static struct _word {
{ "optionsEditor", optionsEditor },
{ "addGroup", userAddGroup },
{ "addUser", userAddUser },
{ "shutdown", _shutdown },
{ NULL, NULL },
};
@ -104,6 +107,13 @@ call_possible_resword(char *name, dialogMenuItem *value, int *status)
return rval;
}
/* Just convenience */
static int _shutdown(dialogMenuItem *unused)
{
systemShutdown(0);
return DITEM_FAILURE;
}
/* For a given string, call it or spit out an undefined command diagnostic */
int
dispatchCommand(char *str)
@ -115,16 +125,22 @@ dispatchCommand(char *str)
msgConfirm("Null or zero-length string passed to dispatchCommand");
return DITEM_FAILURE;
}
/* If it's got a newline, trim it */
if ((cp = index(str, '\n')) != NULL)
*cp = '\0';
/* A command might be a pathname if it's encoded in argv[0], as we also support */
if (index(str, '=')) {
variable_set(str);
return DITEM_SUCCESS;
i = DITEM_SUCCESS;
}
else if ((cp = index(str, '/')) != NULL)
str = cp + 1;
if (!call_possible_resword(str, NULL, &i)) {
msgConfirm("No such command: %s", str);
return DITEM_FAILURE;
else {
if ((cp = index(str, '/')) != NULL)
str = cp + 1;
if (!call_possible_resword(str, NULL, &i)) {
msgConfirm("No such command: %s", str);
i = DITEM_FAILURE;
}
}
return i;
}

View file

@ -116,21 +116,19 @@ main(int argc, char **argv)
{
FILE *fp;
Attribs *attrs;
char buf[BUFSIZ];
attrs = alloca(sizeof(Attribs) * MAX_ATTRIBS);
fp = fopen("install.cfg", "r");
if (fp) {
msgNotify("Loading pre-configuration file");
if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) {
int i;
for (i = 0; attrs[i].name; i++)
variable_set2(attrs[i].name, attrs[i].value);
while (fgets(buf, sizeof buf, fp)) {
if (DITEM_STATUS(dispatchCommand(buf)) != DITEM_SUCCESS) {
msgDebug("Command `%s' failed - rest of script aborted.\n", buf);
break;
}
}
fclose(fp);
}
#if defined(LOAD_CONFIG_FILE)
else {
/* If we have a compiled-in startup config file name on
@ -141,19 +139,15 @@ main(int argc, char **argv)
distWanted = (char *)1;
/* Try to open the floppy drive if we can do that first */
if (DITEM_STATUS(mediaSetFloppy(NULL)) != DITEM_FAILURE &&
mediaDevice->init(mediaDevice)) {
int fd;
if (DITEM_STATUS(mediaSetFloppy(NULL)) != DITEM_FAILURE && mediaDevice->init(mediaDevice)) {
fp = mediaDevice->get(mediaDevice, LOAD_CONFIG_FILE, TRUE);
if (fp) {
msgNotify("Loading %s pre-configuration file",
LOAD_CONFIG_FILE);
if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) {
int i;
for (i = 0; attrs[i].name; i++)
variable_set2(attrs[i].name, attrs[i].value);
msgNotify("Loading %s pre-configuration file", LOAD_CONFIG_FILE);
while (fgets(buf, sizeof buf, fp)) {
if (DITEM_STATUS(dispatchCommand(buf)) != DITEM_SUCCESS) {
msgDebug("Command `%s' failed - rest of script aborted.\n", buf);
break;
}
}
fclose(fp);
}

View file

@ -42,6 +42,13 @@ static void
make_variable(char *var, char *value)
{
Variable *vp;
char *cp;
/* Trim leading and trailing whitespace */
var = string_skipwhite(string_prune(var));
if (!var || !*var)
return;
/* Put it in the environment in any case */
setenv(var, value, 1);
@ -80,7 +87,7 @@ variable_set(char *var)
if ((cp = index(tmp, '=')) == NULL)
msgFatal("Invalid variable format: %s", var);
*(cp++) = '\0';
make_variable(tmp, cp);
make_variable(tmp, string_skipwhite(cp));
}
void
@ -108,7 +115,7 @@ variable_unset(char *var)
unsetenv(var);
if ((cp = index(var, '=')) != NULL) {
sstrncpy(name, cp, cp - var);
var = name;
var = string_skipwhite(string_prune(name));
}
/* Now search to see if it's in our list, if we have one.. */

View file

@ -37,6 +37,8 @@
#include "sysinstall.h"
#include <ctype.h>
static int _shutdown(dialogMenuItem *unused);
static struct _word {
char *name;
int (*handler)(dialogMenuItem *self);
@ -85,6 +87,7 @@ static struct _word {
{ "optionsEditor", optionsEditor },
{ "addGroup", userAddGroup },
{ "addUser", userAddUser },
{ "shutdown", _shutdown },
{ NULL, NULL },
};
@ -104,6 +107,13 @@ call_possible_resword(char *name, dialogMenuItem *value, int *status)
return rval;
}
/* Just convenience */
static int _shutdown(dialogMenuItem *unused)
{
systemShutdown(0);
return DITEM_FAILURE;
}
/* For a given string, call it or spit out an undefined command diagnostic */
int
dispatchCommand(char *str)
@ -115,16 +125,22 @@ dispatchCommand(char *str)
msgConfirm("Null or zero-length string passed to dispatchCommand");
return DITEM_FAILURE;
}
/* If it's got a newline, trim it */
if ((cp = index(str, '\n')) != NULL)
*cp = '\0';
/* A command might be a pathname if it's encoded in argv[0], as we also support */
if (index(str, '=')) {
variable_set(str);
return DITEM_SUCCESS;
i = DITEM_SUCCESS;
}
else if ((cp = index(str, '/')) != NULL)
str = cp + 1;
if (!call_possible_resword(str, NULL, &i)) {
msgConfirm("No such command: %s", str);
return DITEM_FAILURE;
else {
if ((cp = index(str, '/')) != NULL)
str = cp + 1;
if (!call_possible_resword(str, NULL, &i)) {
msgConfirm("No such command: %s", str);
i = DITEM_FAILURE;
}
}
return i;
}

View file

@ -116,21 +116,19 @@ main(int argc, char **argv)
{
FILE *fp;
Attribs *attrs;
char buf[BUFSIZ];
attrs = alloca(sizeof(Attribs) * MAX_ATTRIBS);
fp = fopen("install.cfg", "r");
if (fp) {
msgNotify("Loading pre-configuration file");
if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) {
int i;
for (i = 0; attrs[i].name; i++)
variable_set2(attrs[i].name, attrs[i].value);
while (fgets(buf, sizeof buf, fp)) {
if (DITEM_STATUS(dispatchCommand(buf)) != DITEM_SUCCESS) {
msgDebug("Command `%s' failed - rest of script aborted.\n", buf);
break;
}
}
fclose(fp);
}
#if defined(LOAD_CONFIG_FILE)
else {
/* If we have a compiled-in startup config file name on
@ -141,19 +139,15 @@ main(int argc, char **argv)
distWanted = (char *)1;
/* Try to open the floppy drive if we can do that first */
if (DITEM_STATUS(mediaSetFloppy(NULL)) != DITEM_FAILURE &&
mediaDevice->init(mediaDevice)) {
int fd;
if (DITEM_STATUS(mediaSetFloppy(NULL)) != DITEM_FAILURE && mediaDevice->init(mediaDevice)) {
fp = mediaDevice->get(mediaDevice, LOAD_CONFIG_FILE, TRUE);
if (fp) {
msgNotify("Loading %s pre-configuration file",
LOAD_CONFIG_FILE);
if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) {
int i;
for (i = 0; attrs[i].name; i++)
variable_set2(attrs[i].name, attrs[i].value);
msgNotify("Loading %s pre-configuration file", LOAD_CONFIG_FILE);
while (fgets(buf, sizeof buf, fp)) {
if (DITEM_STATUS(dispatchCommand(buf)) != DITEM_SUCCESS) {
msgDebug("Command `%s' failed - rest of script aborted.\n", buf);
break;
}
}
fclose(fp);
}

View file

@ -42,6 +42,13 @@ static void
make_variable(char *var, char *value)
{
Variable *vp;
char *cp;
/* Trim leading and trailing whitespace */
var = string_skipwhite(string_prune(var));
if (!var || !*var)
return;
/* Put it in the environment in any case */
setenv(var, value, 1);
@ -80,7 +87,7 @@ variable_set(char *var)
if ((cp = index(tmp, '=')) == NULL)
msgFatal("Invalid variable format: %s", var);
*(cp++) = '\0';
make_variable(tmp, cp);
make_variable(tmp, string_skipwhite(cp));
}
void
@ -108,7 +115,7 @@ variable_unset(char *var)
unsetenv(var);
if ((cp = index(var, '=')) != NULL) {
sstrncpy(name, cp, cp - var);
var = name;
var = string_skipwhite(string_prune(name));
}
/* Now search to see if it's in our list, if we have one.. */

View file

@ -37,6 +37,8 @@
#include "sysinstall.h"
#include <ctype.h>
static int _shutdown(dialogMenuItem *unused);
static struct _word {
char *name;
int (*handler)(dialogMenuItem *self);
@ -85,6 +87,7 @@ static struct _word {
{ "optionsEditor", optionsEditor },
{ "addGroup", userAddGroup },
{ "addUser", userAddUser },
{ "shutdown", _shutdown },
{ NULL, NULL },
};
@ -104,6 +107,13 @@ call_possible_resword(char *name, dialogMenuItem *value, int *status)
return rval;
}
/* Just convenience */
static int _shutdown(dialogMenuItem *unused)
{
systemShutdown(0);
return DITEM_FAILURE;
}
/* For a given string, call it or spit out an undefined command diagnostic */
int
dispatchCommand(char *str)
@ -115,16 +125,22 @@ dispatchCommand(char *str)
msgConfirm("Null or zero-length string passed to dispatchCommand");
return DITEM_FAILURE;
}
/* If it's got a newline, trim it */
if ((cp = index(str, '\n')) != NULL)
*cp = '\0';
/* A command might be a pathname if it's encoded in argv[0], as we also support */
if (index(str, '=')) {
variable_set(str);
return DITEM_SUCCESS;
i = DITEM_SUCCESS;
}
else if ((cp = index(str, '/')) != NULL)
str = cp + 1;
if (!call_possible_resword(str, NULL, &i)) {
msgConfirm("No such command: %s", str);
return DITEM_FAILURE;
else {
if ((cp = index(str, '/')) != NULL)
str = cp + 1;
if (!call_possible_resword(str, NULL, &i)) {
msgConfirm("No such command: %s", str);
i = DITEM_FAILURE;
}
}
return i;
}

View file

@ -116,21 +116,19 @@ main(int argc, char **argv)
{
FILE *fp;
Attribs *attrs;
char buf[BUFSIZ];
attrs = alloca(sizeof(Attribs) * MAX_ATTRIBS);
fp = fopen("install.cfg", "r");
if (fp) {
msgNotify("Loading pre-configuration file");
if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) {
int i;
for (i = 0; attrs[i].name; i++)
variable_set2(attrs[i].name, attrs[i].value);
while (fgets(buf, sizeof buf, fp)) {
if (DITEM_STATUS(dispatchCommand(buf)) != DITEM_SUCCESS) {
msgDebug("Command `%s' failed - rest of script aborted.\n", buf);
break;
}
}
fclose(fp);
}
#if defined(LOAD_CONFIG_FILE)
else {
/* If we have a compiled-in startup config file name on
@ -141,19 +139,15 @@ main(int argc, char **argv)
distWanted = (char *)1;
/* Try to open the floppy drive if we can do that first */
if (DITEM_STATUS(mediaSetFloppy(NULL)) != DITEM_FAILURE &&
mediaDevice->init(mediaDevice)) {
int fd;
if (DITEM_STATUS(mediaSetFloppy(NULL)) != DITEM_FAILURE && mediaDevice->init(mediaDevice)) {
fp = mediaDevice->get(mediaDevice, LOAD_CONFIG_FILE, TRUE);
if (fp) {
msgNotify("Loading %s pre-configuration file",
LOAD_CONFIG_FILE);
if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) {
int i;
for (i = 0; attrs[i].name; i++)
variable_set2(attrs[i].name, attrs[i].value);
msgNotify("Loading %s pre-configuration file", LOAD_CONFIG_FILE);
while (fgets(buf, sizeof buf, fp)) {
if (DITEM_STATUS(dispatchCommand(buf)) != DITEM_SUCCESS) {
msgDebug("Command `%s' failed - rest of script aborted.\n", buf);
break;
}
}
fclose(fp);
}

View file

@ -42,6 +42,13 @@ static void
make_variable(char *var, char *value)
{
Variable *vp;
char *cp;
/* Trim leading and trailing whitespace */
var = string_skipwhite(string_prune(var));
if (!var || !*var)
return;
/* Put it in the environment in any case */
setenv(var, value, 1);
@ -80,7 +87,7 @@ variable_set(char *var)
if ((cp = index(tmp, '=')) == NULL)
msgFatal("Invalid variable format: %s", var);
*(cp++) = '\0';
make_variable(tmp, cp);
make_variable(tmp, string_skipwhite(cp));
}
void
@ -108,7 +115,7 @@ variable_unset(char *var)
unsetenv(var);
if ((cp = index(var, '=')) != NULL) {
sstrncpy(name, cp, cp - var);
var = name;
var = string_skipwhite(string_prune(name));
}
/* Now search to see if it's in our list, if we have one.. */