summaryrefslogtreecommitdiffstats
path: root/usr.sbin/sade
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1997-06-11 08:41:10 +0000
committerjkh <jkh@FreeBSD.org>1997-06-11 08:41:10 +0000
commita0c781a8d7594a444c97cf2c8723cfe0aeca0074 (patch)
tree5273673eaf48d6bc752aeac28f9543ffe1ffb478 /usr.sbin/sade
parent5cfc21982c7428b1a96901cd5f74a59832f8bb94 (diff)
downloadFreeBSD-src-a0c781a8d7594a444c97cf2c8723cfe0aeca0074.zip
FreeBSD-src-a0c781a8d7594a444c97cf2c8723cfe0aeca0074.tar.gz
YAMF22 - Bugs Of Evil in variable handling and rc.conf editing.
PR#: 3218 [partial]
Diffstat (limited to 'usr.sbin/sade')
-rw-r--r--usr.sbin/sade/config.c58
-rw-r--r--usr.sbin/sade/variable.c21
2 files changed, 42 insertions, 37 deletions
diff --git a/usr.sbin/sade/config.c b/usr.sbin/sade/config.c
index 50a874d..314deab 100644
--- a/usr.sbin/sade/config.c
+++ b/usr.sbin/sade/config.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: config.c,v 1.97 1997/05/30 01:03:07 jkh Exp $
+ * $Id: config.c,v 1.51.2.52 1997/06/11 08:39:26 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -305,7 +305,7 @@ void
configEnvironmentRC_conf(char *config)
{
char *lines[MAX_LINES], *cp, *cp2;
- int i, j, nlines;
+ int i, nlines;
nlines = readConfig(config, lines, MAX_LINES);
if (nlines == -1)
@@ -318,19 +318,21 @@ configEnvironmentRC_conf(char *config)
continue;
}
*cp++ = '\0';
- (void)string_prune(lines[i]);
- cp = string_skipwhite(string_prune(cp));
- if ((cp2 = index(cp, '"')) || (cp2 = index(cp, '\047'))) /* Eliminate leading quote if it's quoted */
+ /* Find quotes */
+ if ((cp2 = index(cp, '"')) || (cp2 = index(cp, '\047'))) {
cp = cp2 + 1;
- j = strlen(cp) - 1;
- if (cp2 && cp[j] == *cp2) /* And trailing one */
- cp[j] = '\0';
- if (strlen(cp))
- variable_set2(lines[i], cp);
+ cp2 = index(cp, *cp2);
+ }
+ /* If valid quotes, use it */
+ if (cp2) {
+ *cp2 = '\0';
+ if (strlen(cp))
+ variable_set2(lines[i], cp);
+ }
free(lines[i]);
}
}
-
+
/* Load the environment from a resolv.conf file */
void
configEnvironmentResolv(char *config)
@@ -345,10 +347,10 @@ configEnvironmentResolv(char *config)
Boolean name_set = FALSE;
if (!strncmp(lines[i], "domain", 6))
- variable_set2(VAR_DOMAINNAME, string_skipwhite(lines[i] + 6));
+ variable_set2(VAR_DOMAINNAME, string_skipwhite(string_prune(lines[i] + 6)));
else if (!strncmp(lines[i], "nameserver", 10) && !name_set) {
/* Only take the first nameserver setting - we're lame */
- variable_set2(VAR_NAMESERVER, string_skipwhite(lines[i] + 10));
+ variable_set2(VAR_NAMESERVER, string_skipwhite(string_prune(lines[i] + 10)));
name_set = TRUE;
}
free(lines[i]);
@@ -373,35 +375,36 @@ configRC_conf(char *config)
FILE *fp;
char *lines[MAX_LINES], *cp;
Variable *v;
- int i, nlines;
+ int i, nlines, len;
nlines = readConfig(config, lines, MAX_LINES);
- if (nlines == -1) {
- msgConfirm("Unable to open %s file! This is bad!", config);
+ if (nlines == -1)
return;
- }
/* Now do variable substitutions */
for (v = VarHead; v; v = v->next) {
- char line[512];
-
for (i = 0; i < nlines; i++) {
/* Skip the comments & non-variable settings */
if (lines[i][0] == '#' || !(cp = index(lines[i], '=')))
continue;
- sstrncpy(line, lines[i], cp - lines[i]);
- if (!strcmp(line, v->name)) {
- char *cp3, *comment = NULL;
+ len = strlen(v->name);
+ if (!strncmp(lines[i], v->name, cp - lines[i]) && (cp - lines[i]) == len) {
+ char *cp2, *comment = NULL;
/* If trailing comment, try and preserve it */
- if ((cp3 = index(lines[i], '#')) != NULL) {
- comment = alloca(strlen(cp3) + 1);
- strcpy(comment, cp3);
+ if ((index(lines[i], '#')) != NULL) {
+ /* Find quotes */
+ if ((cp2 = index(cp, '"')) || (cp2 = index(cp, '\047')))
+ cp2 = index(cp2 + 1, *cp2);
+ if (cp2 && strlen(cp2 + 1)) {
+ comment = alloca(strlen(cp2));
+ strcpy(comment, cp2 + 1);
+ }
}
free(lines[i]);
lines[i] = (char *)malloc(strlen(v->name) + strlen(v->value) + (comment ? strlen(comment) : 0) + 10);
if (comment)
- sprintf(lines[i], "%s=\"%s\"\t\t%s", v->name, v->value, comment);
+ sprintf(lines[i], "%s=\"%s\"%s", v->name, v->value, comment);
else
sprintf(lines[i], "%s=\"%s\"\n", v->name, v->value);
}
@@ -430,6 +433,9 @@ configRC_conf(char *config)
char iname[255], toadd[512];
int k, addit = TRUE;
+ if (!strncmp(devp[j]->name, "ppp", 3) || !strncmp(devp[j]->name, "tun", 3))
+ continue;
+
snprintf(iname, 255, "%s%s", VAR_IFCONFIG, devp[j]->name);
if ((cp = variable_get(iname))) {
snprintf(toadd, sizeof toadd, "%s=\"%s\"\n", iname, cp);
diff --git a/usr.sbin/sade/variable.c b/usr.sbin/sade/variable.c
index 4bd2e78..0c579d6 100644
--- a/usr.sbin/sade/variable.c
+++ b/usr.sbin/sade/variable.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: variable.c,v 1.17 1997/02/22 14:12:38 peter Exp $
+ * $Id: variable.c,v 1.11.2.5 1997/06/11 08:39:27 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -111,16 +111,15 @@ variable_unset(char *var)
Variable *vp;
char name[512], *cp;
- unsetenv(var);
- if ((cp = index(var, '=')) != NULL) {
- sstrncpy(name, cp, cp - var);
- var = string_skipwhite(string_prune(name));
- }
-
+ if ((cp = index(var, '=')) != NULL)
+ sstrncpy(name, var, cp - var);
+ else
+ SAFE_STRCPY(name, var);
+ unsetenv(name);
/* Now search to see if it's in our list, if we have one.. */
if (!VarHead)
return;
- else if (!VarHead->next && !strcmp(VarHead->name, var)) {
+ else if (!VarHead->next && !strcmp(VarHead->name, name)) {
safe_free(VarHead->name);
safe_free(VarHead->value);
free(VarHead);
@@ -128,12 +127,12 @@ variable_unset(char *var)
}
else {
for (vp = VarHead; vp; vp = vp->next) {
- if (!strcmp(vp->name, var)) {
+ if (!strcmp(vp->name, name)) {
Variable *save = vp->next;
+ safe_free(vp->name);
+ safe_free(vp->value);
*vp = *save;
- safe_free(save->name);
- safe_free(save->value);
safe_free(save);
break;
}
OpenPOWER on IntegriCloud