summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbalocca <rbalocca@vyatta.com>2008-07-09 12:22:04 -0700
committerrbalocca <rbalocca@vyatta.com>2008-07-09 12:22:04 -0700
commita1561f2b43a221651f1b370296a205be772c2ff6 (patch)
tree20f719fd409d57fb93c67d6a6c0be37d9598b02a
parent7db066e99a5e9c3b41ce30d19b9781b1a8df8d44 (diff)
parent42d6c942800e2273b77ea92371ffdcb3f183163f (diff)
downloadvyatta-cfg-a1561f2b43a221651f1b370296a205be772c2ff6.tar.gz
vyatta-cfg-a1561f2b43a221651f1b370296a205be772c2ff6.zip
Merge branch 'hollywood'
-rwxr-xr-xetc/bash_completion.d/20vyatta-cfg13
-rwxr-xr-xetc/init.d/vyatta-ofr6
-rwxr-xr-xscripts/VyattaConfig.pm4
-rwxr-xr-xscripts/VyattaConfigLoad.pm19
-rwxr-xr-xscripts/VyattaConfigOutput.pm6
-rwxr-xr-xscripts/vyatta-load-config.pl34
-rw-r--r--src/cli_new.c61
-rw-r--r--src/cli_objects.c2
-rw-r--r--src/cli_val.h2
-rw-r--r--src/delete.c4
10 files changed, 125 insertions, 26 deletions
diff --git a/etc/bash_completion.d/20vyatta-cfg b/etc/bash_completion.d/20vyatta-cfg
index f1d100e..3b523bd 100755
--- a/etc/bash_completion.d/20vyatta-cfg
+++ b/etc/bash_completion.d/20vyatta-cfg
@@ -75,9 +75,10 @@ discard ()
changes=0
fi
- sudo umount ${VYATTA_TEMP_CONFIG_DIR};
- sudo rm -fr ${VYATTA_CHANGES_ONLY_DIR};
- sudo mkdir -p ${VYATTA_CHANGES_ONLY_DIR};
+ sudo umount $VYATTA_TEMP_CONFIG_DIR
+ sudo rm -fr $VYATTA_CHANGES_ONLY_DIR $VYATTA_TEMP_CONFIG_DIR
+ make_vyatta_config_dir $VYATTA_CHANGES_ONLY_DIR
+ make_vyatta_config_dir $VYATTA_TEMP_CONFIG_DIR
sudo mount -t unionfs -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:${VYATTA_ACTIVE_CONFIGURATION_DIR}=ro unionfs ${VYATTA_TEMP_CONFIG_DIR};
if (( changes )); then
@@ -813,22 +814,26 @@ vyatta_config_complete ()
if (( ${#COMP_WORDS[@]} < 2 )); then
declare -a hitems=( "commit" \
+ "copy" \
"delete" \
- "discard" \
+ "discard" \
"edit" \
"exit" \
"load" \
+ "rename" \
"run" \
"save" \
"set" \
"show" )
declare -a hstrs=( \
"Commit the current set of changes" \
+ "Copy a configuration element" \
"Delete a configuration element" \
"Discard uncommitted changes" \
"Edit a sub-element" \
"Exit from this configuration level" \
"Load configuration from a file" \
+ "Rename a configuration element" \
"Run an operational-mode command" \
"Save configuration to a file" \
"Set the value of a parameter or create a new element" \
diff --git a/etc/init.d/vyatta-ofr b/etc/init.d/vyatta-ofr
index 104903e..92acf45 100755
--- a/etc/init.d/vyatta-ofr
+++ b/etc/init.d/vyatta-ofr
@@ -118,6 +118,12 @@ start ()
done
load_bootfile
chmod g-w,o-w /
+
+ ( [ -s /boot/grub/menu.lst ] &&
+ upgrade-from-grub-legacy &&
+ rm -f /boot/grub/menu.lst*
+ ) || true
+
log_end_msg $?
}
diff --git a/scripts/VyattaConfig.pm b/scripts/VyattaConfig.pm
index 3c4b51f..1c0eaf3 100755
--- a/scripts/VyattaConfig.pm
+++ b/scripts/VyattaConfig.pm
@@ -130,7 +130,9 @@ sub listOrigNodes {
$tmp =~ s/\n//g;
$tmp =~ s/%2F/\//g;
#print "DEBUG VyattaConfig->listNodes(): node = $tmp\n";
- push @nodes_modified, $tmp;
+ if ($tmp ne 'def') {
+ push @nodes_modified, $tmp;
+ }
}
return @nodes_modified;
diff --git a/scripts/VyattaConfigLoad.pm b/scripts/VyattaConfigLoad.pm
index f1339c3..c8563bb 100755
--- a/scripts/VyattaConfigLoad.pm
+++ b/scripts/VyattaConfigLoad.pm
@@ -56,7 +56,8 @@ my %regex_rank = (
'interfaces ethernet \S* vrrp' => 500,
'interfaces ethernet \S* vif \S* vrrp' => 500,
'protocols bgp \d+ parameters' => 810,
- 'protocols bgp \d+ neighbor \S*[^\d.]\S*' => 800,
+ 'protocols bgp \d+ neighbor \d+\.\d+\.\d+\.\d+' => 800,
+ 'protocols bgp \d+ neighbor \w+' => 801,
);
my @all_nodes = ();
@@ -296,9 +297,6 @@ sub findDeletedNodes {
$active_cfg->setLevel(join ' ', @active_path);
my @active_nodes = $active_cfg->listOrigNodes();
foreach (@active_nodes) {
- if ($_ eq 'def') {
- next;
- }
if ($_ eq 'node.val') {
findDeletedValues($new_ref, \@active_path);
next;
@@ -396,8 +394,19 @@ sub getConfigDiff {
# everything together anyway.
@delete_list = sort { ${$a}[1] <=> ${$b}[1] } @delete_list;
@set_list = sort { ${$b}[1] <=> ${$a}[1] } @set_list;
+
+ # need to filter out deletions of nodes with default values
+ my @new_delete_list = ();
+ foreach my $del (@delete_list) {
+ my @comps = map { s/^'(.*)'$/$1/; $_; } @{${$del}[0]};
+ my ($is_multi, $is_text, $default) = $active_cfg->parseTmpl(\@comps);
+ if (!defined($default)) {
+ push @new_delete_list, $del;
+ }
+ }
+
my %diff = (
- 'delete' => \@delete_list,
+ 'delete' => \@new_delete_list,
'set' => \@set_list,
);
return %diff;
diff --git a/scripts/VyattaConfigOutput.pm b/scripts/VyattaConfigOutput.pm
index 5358c21..ab7068f 100755
--- a/scripts/VyattaConfigOutput.pm
+++ b/scripts/VyattaConfigOutput.pm
@@ -138,7 +138,7 @@ sub displayValues {
my @cnames = sort keys %cnodes;
if (defined($simple_show)) {
- if (!$cnodes{'def'} || $show_all) {
+ if ($show_all) {
if ($is_password && $hide_password) {
$oval = $HIDE_PASSWORD;
}
@@ -159,7 +159,7 @@ sub displayValues {
$diff = '>';
}
}
- if (!$cnodes{'def'} || $show_all) {
+ if ($show_all) {
if ($is_password && $hide_password) {
$value = $HIDE_PASSWORD;
}
@@ -194,8 +194,6 @@ sub displayDeletedOrigChildren {
if ($cnames[0] eq 'node.val') {
displayValues([ @cur_path, $child ], $prefix, $child,
$dont_show_as_deleted);
- } elsif ($cnames[0] eq 'def') {
- #ignore
} elsif (scalar($#cnames) >= 0) {
if ($is_tag) {
@cnames = sort versioncmp @cnames;
diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl
index 29d4dec..ee4a9c4 100755
--- a/scripts/vyatta-load-config.pl
+++ b/scripts/vyatta-load-config.pl
@@ -23,6 +23,9 @@
use strict;
use lib "/opt/vyatta/share/perl5/";
+use POSIX;
+use IO::Prompt;
+use Sys::Syslog qw(:standard :macros);
use VyattaConfigLoad;
my $etcdir = $ENV{vyatta_sysconfdir};
@@ -42,6 +45,7 @@ my $proto;
if (defined($ARGV[0])) {
$load_file = $ARGV[0];
}
+my $orig_load_file = $load_file;
if ($load_file =~ /^[^\/]\w+:\//) {
if ($load_file =~ /^(\w+):\/\/\w/) {
@@ -107,20 +111,36 @@ if ($mode eq 'local') {
}
$load_file = $url_tmp_file;
}
+
+my $xorp_cfg = 0;
+my $valid_cfg = 0;
while (<CFG>) {
if (/\/\*XORP Configuration File, v1.0\*\//) {
- print "Warning: Loading a pre-Glendale configuration.\n";
- print "Do you want to continue? [no] ";
- my $resp = <STDIN>;
- if (!($resp =~ /^yes$/i)) {
- print "Configuration not loaded\n";
- exit 1;
- }
+ $xorp_cfg = 1;
+ last;
+ } elsif (/vyatta-config-version/) {
+ $valid_cfg = 1;
last;
}
}
+if ($xorp_cfg or ! $valid_cfg) {
+ if ($xorp_cfg) {
+ print "Warning: Loading a pre-Glendale configuration.\n";
+ } else {
+ print "Warning: file does NOT appear to be a valid config file.\n";
+ }
+ if (!prompt("Do you want to continue? ", -tty, -Yes, -default=>'no')) {
+ print "Configuration not loaded\n";
+ exit 1;
+ }
+}
close CFG;
+# log it
+openlog($0, "", LOG_USER);
+my $login = getlogin() || getpwuid($<) || "unknown";
+syslog("warning", "Load config [$orig_load_file] by $login");
+
# do config migration
system("$sbindir/vyatta_config_migrate.pl $load_file");
diff --git a/src/cli_new.c b/src/cli_new.c
index 26cc719..0b50ccb 100644
--- a/src/cli_new.c
+++ b/src/cli_new.c
@@ -1774,7 +1774,35 @@ void push_path(vtw_path *path, char *segm)
}else
*pp = *cp;
*pp = 0;
+ path->path_len += len;
+ if (path->path_lev == path->path_ends_alloc){
+ path->path_ends_alloc += ENDS_ALLOC;
+ path->path_ends = (int *)my_realloc(path->path_ends,
+ sizeof(int *)*path->path_ends_alloc, "puhs_path 2");
+ }
+ path->path_ends[path->path_lev++] = path->path_len;
+ // push_path_no_escape();
+}
+/**
+ * Version of above that doesn't escape value before stuffing.
+ *
+ **/
+void push_path_no_escape(vtw_path *path, char *segm)
+{
+ int len;
+ char *cp;
+ char *pp;
+
+ for(cp=segm, len=0;*cp;++cp, ++len);
+ warrant_path(path, len + 1);
+ path->path_buf[path->path_len] = '/';
+ path->path_buf[++path->path_len] = 0;
+ for(pp=path->path_buf + path->path_len,cp=segm;
+ *cp;++cp, ++pp) {
+ *pp = *cp;
+ }
+ *pp = 0;
path->path_len += len;
if (path->path_lev == path->path_ends_alloc){
path->path_ends_alloc += ENDS_ALLOC;
@@ -1926,24 +1954,51 @@ void subtract_values(char **lhs, const char *rhs)
if (lhs == NULL || *lhs == NULL || **lhs == '\0' || rhs == NULL || *rhs == '\0')
return;
+ /* calculate number of rhs entries */
+ rhs_copy = strdup(rhs);
+ line = strtok(rhs_copy, "\n\r");
+ while (line != NULL && *line != '\0') {
+ rhs_cnt++;
+ line = strtok(NULL, "\n\r");
+ }
+
+ /* strtok destroys the string. dup again. */
+ free(rhs_copy);
rhs_copy = strdup(rhs);
- length = strlen(rhs) / 2;
+
+ /* allocate enough space for all old entries (to be subtracted) */
+ length = rhs_cnt * sizeof(char *);
head = ptr = my_malloc(length, "subtract_values list1");
memset(head, 0, length);
+ /* parse the entries and put them in head[] */
line = strtok(rhs_copy, "\n\r");
while (line != NULL && *line != '\0') {
*ptr = line;
ptr++;
- rhs_cnt++;
line = strtok(NULL, "\n\r");
}
- length = strlen(*lhs) / 2;
+ /* calculate number of lhs entries */
+ {
+ char *lhs_copy = strdup(*lhs);
+ line = strtok(lhs_copy, "\n\r");
+ while (line != NULL && *line != '\0') {
+ lhs_cnt++;
+ line = strtok(NULL, "\n\r");
+ }
+ free(lhs_copy);
+ }
+
+ /* allocate enough space for all new entries */
+ length = lhs_cnt * sizeof(char *);
new_head = new_ptr = my_malloc(length, "subtract_values list2");
memset(new_head, 0, length);
+ /* reset length and lhs_cnt. they are now used for the "new" array (i.e.,
+ * after subtraction). */
length = 0;
+ lhs_cnt = 0;
line = strtok(*lhs, "\n\r");
while (line != NULL && *line != '\0') {
for (i = 0; i < rhs_cnt; i++) {
diff --git a/src/cli_objects.c b/src/cli_objects.c
index 8f0f6fe..8685c6a 100644
--- a/src/cli_objects.c
+++ b/src/cli_objects.c
@@ -243,7 +243,7 @@ void init_edit()
slashp = strchr(scanp, '/');
if (slashp)
*slashp = 0;
- push_path(&m_path, scanp);
+ push_path_no_escape(&m_path, scanp);
if (slashp) {
*slashp = '/';
scanp = slashp+1;
diff --git a/src/cli_val.h b/src/cli_val.h
index 520fa8e..c9d59a6 100644
--- a/src/cli_val.h
+++ b/src/cli_val.h
@@ -153,6 +153,7 @@ extern void cli_val_done(void);
extern void init_path(vtw_path *path, const char *root);
extern void pop_path(vtw_path *path);
extern void push_path(vtw_path *path, char *segm);
+extern void push_path_no_escape(vtw_path *path, char *segm);
extern void free_def(vtw_def *defp);
extern void free_sorted(vtw_sorted *sortp);
extern void *my_malloc(size_t size, const char *name);
@@ -214,6 +215,7 @@ extern int get_config_lock();
extern int out_fd;
extern FILE *out_stream;
+extern FILE *err_stream;
extern int initialize_output();
diff --git a/src/delete.c b/src/delete.c
index 9bdb3ed..bb2c987 100644
--- a/src/delete.c
+++ b/src/delete.c
@@ -291,8 +291,10 @@ int main(int argc, char **argv)
if (status != VTWERR_OK)
bye("Corrupted old value ---- \n%s\n-----\n", cp);
res = val_cmp(&new_value, &old_value, IN_COND);
- if (!res)
+ if (!res) {
+ fprintf(out_stream, "%s is not a configured value\n", new_value.val);
bye("Not in multivalue");
+ }
touch();
if (old_value.cnt) {
push_path(&m_path, VAL_NAME);