diff options
author | Bob Gilligan <gilligan@vyatta.com> | 2008-02-26 16:52:11 -0800 |
---|---|---|
committer | Bob Gilligan <gilligan@vyatta.com> | 2008-02-26 16:52:11 -0800 |
commit | f9ee85510c958f07191cdbb7c3f57f2cf226a6d3 (patch) | |
tree | 47f55dc322dcaa83f3bdb2fd5caa2388e8ff4b8b | |
parent | 79eb089b0d3463823f0a1fba1376842e3eb8aa47 (diff) | |
parent | af75cfaa93b1ac933bb8b5ecec64fcc0c269a013 (diff) | |
download | vyatta-cfg-f9ee85510c958f07191cdbb7c3f57f2cf226a6d3.tar.gz vyatta-cfg-f9ee85510c958f07191cdbb7c3f57f2cf226a6d3.zip |
Merge branch 'glendale' of git:/git/vyatta-cfg into glendale
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | debian/vyatta-cfg.postinst.in | 2 | ||||
-rw-r--r-- | etc/bash_completion.d/20vyatta-cfg | 4 | ||||
-rwxr-xr-x | etc/init.d/vyatta-ofr | 2 | ||||
-rw-r--r-- | etc/shell/level/users/allowed-op | 14 | ||||
-rwxr-xr-x | scripts/vyatta-cfg-cmd-wrapper | 65 | ||||
-rwxr-xr-x | scripts/vyatta-config-loader.pl | 43 | ||||
-rwxr-xr-x | scripts/xorp_tmpl_tool | 162 | ||||
-rw-r--r-- | src/cli_new.c | 3 |
9 files changed, 119 insertions, 178 deletions
diff --git a/Makefile.am b/Makefile.am index 9e55aa1..5d41b2d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,7 +31,7 @@ src_my_delete_SOURCES = src/delete.c src_my_set_SOURCES = src/set.c src_check_tmpl_SOURCES = src/check_tmpl.c -sbin_SCRIPTS = scripts/xorp_tmpl_tool +sbin_SCRIPTS = scripts/vyatta-cfg-cmd-wrapper sbin_SCRIPTS += scripts/vyatta-validate-type.pl sbin_SCRIPTS += scripts/vyatta-find-type.pl sbin_SCRIPTS += scripts/vyatta-config-loader.pl diff --git a/debian/vyatta-cfg.postinst.in b/debian/vyatta-cfg.postinst.in index 3fce13b..556b1a9 100644 --- a/debian/vyatta-cfg.postinst.in +++ b/debian/vyatta-cfg.postinst.in @@ -4,7 +4,7 @@ prefix=@prefix@ sysconfdir=@sysconfdir@ mkdir -m 0775 -p $sysconfdir/config $prefix/config -chgrp quaggavty $sysconfdir/config $prefix/config +chgrp vyattacfg $sysconfdir/config $prefix/config update-rc.d vyatta-ofr defaults 90 >/dev/null # do we want to start vyatta-ofr here in postinst? diff --git a/etc/bash_completion.d/20vyatta-cfg b/etc/bash_completion.d/20vyatta-cfg index 7d0b633..5966e18 100644 --- a/etc/bash_completion.d/20vyatta-cfg +++ b/etc/bash_completion.d/20vyatta-cfg @@ -61,7 +61,7 @@ show () save () { - eval "sudo sg quaggavty \ + eval "sudo sg vyattacfg \ \"umask 0002 ; ${vyatta_sbindir}/vyatta-save-config.pl $@\"" } @@ -968,7 +968,7 @@ vyatta_config_complete () eval $restore_shopts } -DEF_GROUP=quaggavty +DEF_GROUP=vyattacfg make_vyatta_config_dir () { sudo mkdir -m 0775 -p $1 diff --git a/etc/init.d/vyatta-ofr b/etc/init.d/vyatta-ofr index 32eb554..89914c4 100755 --- a/etc/init.d/vyatta-ofr +++ b/etc/init.d/vyatta-ofr @@ -55,7 +55,7 @@ else subinit+=( rtrmgr ) GROUP=xorp else - GROUP=quaggavty + GROUP=vyattacfg fi fi diff --git a/etc/shell/level/users/allowed-op b/etc/shell/level/users/allowed-op index c2c2482..498d120 100644 --- a/etc/shell/level/users/allowed-op +++ b/etc/shell/level/users/allowed-op @@ -1,6 +1,14 @@ -show -terminal +clear +debug exit -telnet +init-floppy +no ping +reboot +set +show +telnet +terminal traceroute +undebug +vpn diff --git a/scripts/vyatta-cfg-cmd-wrapper b/scripts/vyatta-cfg-cmd-wrapper new file mode 100755 index 0000000..4a42105 --- /dev/null +++ b/scripts/vyatta-cfg-cmd-wrapper @@ -0,0 +1,65 @@ +#!/bin/bash + +if grep -q union=aufs /proc/cmdline || grep -q aufs /proc/filesystems ; then + export UNIONFS=aufs +else + export UNIONFS=unionfs +fi + +UMASK_SAVE=`umask` +umask 0002 + +export VYATTA_EDIT_LEVEL=/; +export VYATTA_TEMPLATE_LEVEL=/; +export VYATTA_ACTIVE_CONFIGURATION_DIR=/opt/vyatta/config/active; + +export VYATTA_CHANGES_ONLY_DIR=/opt/vyatta/config/tmp/changes_only_$PPID; +export VYATTA_TEMP_CONFIG_DIR=/opt/vyatta/config/tmp/new_config_$PPID; +export VYATTA_CONFIG_TMP=/opt/vyatta/config/tmp/tmp_$PPID; + +RET_STATUS=0 + +case "$1" in + begin) + # set up the environment/directories + mkdir -p $VYATTA_ACTIVE_CONFIGURATION_DIR + mkdir -p $VYATTA_CHANGES_ONLY_DIR + if [ ! -d $VYATTA_TEMP_CONFIG_DIR ]; then + mkdir -p $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} + fi + mkdir -p $VYATTA_CONFIG_TMP + ;; + end) + # tear down the environment/directories + sudo umount ${VYATTA_TEMP_CONFIG_DIR} + rm -rf ${VYATTA_CHANGES_ONLY_DIR} + rm -rf ${VYATTA_CONFIG_TMP} + rm -rf ${VYATTA_TEMP_CONFIG_DIR} + ;; + cleanup) + sudo umount ${VYATTA_TEMP_CONFIG_DIR} + rm -rf $VYATTA_CHANGES_ONLY_DIR/* $VYATTA_CHANGES_ONLY_DIR/.modified + sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:${VYATTA_ACTIVE_CONFIGURATION_DIR}=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR} + ;; + set) + /opt/vyatta/sbin/my_set "${@:2}" + RET_STATUS=$? + ;; + delete) + /opt/vyatta/sbin/my_delete "${@:2}" + RET_STATUS=$? + ;; + commit) + /opt/vyatta/sbin/my_commit + RET_STATUS=$? + ;; + *) + echo "Invalid command \"$1\" for vyatta-cfg-cmd-wrapper" + RET_STATUS=1 + ;; +esac + +umask ${UMASK_SAVE} +exit $RET_STATUS + diff --git a/scripts/vyatta-config-loader.pl b/scripts/vyatta-config-loader.pl index 4c05b80..035d2af 100755 --- a/scripts/vyatta-config-loader.pl +++ b/scripts/vyatta-config-loader.pl @@ -8,16 +8,40 @@ use VyattaConfigLoad; umask 0002; +if (!open(OLDOUT, ">&STDOUT") || !open(OLDERR, ">&STDERR") + || !open(STDOUT, ">/var/log/config-boot.log") + || !open(STDERR, ">&STDOUT")) { + print STDERR "Cannot dup STDOUT/STDERR: $!\n"; + exit 1; +} + +sub restore_fds { + open(STDOUT, ">&OLDOUT"); + open(STDERR, ">&OLDERR"); +} + # get a list of all config statement in the startup config file # (sorted by rank). my @all_nodes = VyattaConfigLoad::getStartupConfigStatements($ARGV[0]); if (scalar(@all_nodes) == 0) { # no config statements + restore_fds(); exit 1; } my $cur_rank = ${$all_nodes[0]}[1]; -my $commit_cmd = '/opt/vyatta/sbin/xorp_tmpl_tool commit'; -my $cleanup_cmd = '/opt/vyatta/sbin/xorp_tmpl_tool cleanup'; + +# set up the config environment +my $CWRAPPER = '/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper'; +system("$CWRAPPER begin"); +if ($? >> 8) { + print OLDOUT "Cannot set up configuration environment\n"; + print STDOUT "Cannot set up configuration environment\n"; + restore_fds(); + exit 1; +} + +my $commit_cmd = "$CWRAPPER commit"; +my $cleanup_cmd = "$CWRAPPER cleanup"; my $ret = 0; # higher-ranked statements committed before lower-ranked. foreach (@all_nodes) { @@ -26,28 +50,33 @@ foreach (@all_nodes) { # commit all nodes with the same rank together. $ret = system("$commit_cmd"); if ($ret >> 8) { - print STDERR "Commit failed at rank $cur_rank\n"; + print OLDOUT "Commit failed at rank $cur_rank\n"; + print STDOUT "Commit failed at rank $cur_rank\n"; system("$cleanup_cmd"); # continue after cleanup (or should we abort?) } $cur_rank = $rank; } - my $cmd = '/opt/vyatta/sbin/xorp_tmpl_tool set ' . (join ' ', @$path_ref); + my $cmd = "$CWRAPPER set " . (join ' ', @$path_ref); $ret = system("$cmd"); if ($ret >> 8) { $cmd =~ s/^.*?set /set /; - print STDERR "[[$cmd]] failed\n"; + print OLDOUT "[[$cmd]] failed\n"; + print STDOUT "[[$cmd]] failed\n"; # continue after set failure (or should we abort?) } } $ret = system("$commit_cmd"); if ($ret >> 8) { - print STDERR "Commit failed at rank $cur_rank\n"; + print OLDOUT "Commit failed at rank $cur_rank\n"; + print STDOUT "Commit failed at rank $cur_rank\n"; system("$cleanup_cmd"); # exit normally after cleanup (or should we exit with error?) } # really clean up -system('/opt/vyatta/sbin/xorp_tmpl_tool end_loading'); +system("$CWRAPPER end"); +restore_fds(); exit 0; + diff --git a/scripts/xorp_tmpl_tool b/scripts/xorp_tmpl_tool deleted file mode 100755 index 014a53b..0000000 --- a/scripts/xorp_tmpl_tool +++ /dev/null @@ -1,162 +0,0 @@ -#!/bin/bash - -if grep -q union=aufs /proc/cmdline || grep -q aufs /proc/filesystems ; then - export UNIONFS=aufs -else - export UNIONFS=unionfs -fi - -UMASK_SAVE_G=`umask` -umask 0111 -XORPLOGFILE=/tmp/xorp_tmpl_tool.log -touch ${XORPLOGFILE} - -umask 0002 - -#need to pass in value to change... as part of set command... -## cli ENV_EDIT_LEVEL -export VYATTA_EDIT_LEVEL=/; -## cli ENV_TEMPLATE_LEVEL -export VYATTA_TEMPLATE_LEVEL=/; - -## cli ENV_A_DIR -export VYATTA_ACTIVE_CONFIGURATION_DIR=/opt/vyatta/config/active; -mkdir -p $VYATTA_ACTIVE_CONFIGURATION_DIR - -#now need to grab the parent pid. -## XXX eventually, we will use each session's bash shell pid for this. -## however, for now, to interact with XORP we will rely on a global lock -## instead of separate config dirs. -#export VTID=$PPID -export VTID=XORP - -# lock for XORP -export XORP_LOCK="/opt/vyatta/config/active/.xorp.lck" - -## cli ENV_C_DIR -export VYATTA_CHANGES_ONLY_DIR=/opt/vyatta/config/tmp/changes_only_$VTID; -mkdir -p $VYATTA_CHANGES_ONLY_DIR - -## cli ENV_M_DIR -export VYATTA_TEMP_CONFIG_DIR=/opt/vyatta/config/tmp/new_config_$VTID; -if [ ! -d $VYATTA_TEMP_CONFIG_DIR ] -then - mkdir -p $VYATTA_TEMP_CONFIG_DIR - sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR} -fi - -## cli ENV_TMP_DIR -export VYATTA_CONFIG_TMP=/opt/vyatta/config/tmp/tmp_$VTID; -mkdir -p $VYATTA_CONFIG_TMP - -RET_STATUS=0 -#this needs to be the array string of commands, something like $[*] or whatever - -echo "Command: ${@}" | grep -v -i password >> ${XORPLOGFILE} - -#echo "ConfigDirectories BEFORE ========>>>>>>" >> ${XORPLOGFILE} -#find /opt/vyatta/config -name "*" -print | grep interface >> ${XORPLOGFILE} -#echo "<=========ConfigDirectories BEFORE" >> ${XORPLOGFILE} - -## for tracing command-line XRL calls. -## 1 => info level -## 2 => warning level -#export CL_XRLTRACE=2 - -UMASK_SAVE=`umask` -umask 0111 -MYCMDERRLOGFILE=/tmp/my_cmd_err_${RANDOM}.log -rm -rf ${MYCMDERRLOGFILE} -umask ${UMASK_SAVE} - -case "$1" in - set) - /opt/vyatta/sbin/my_set "${@:2}" >>${XORPLOGFILE} 2>>${MYCMDERRLOGFILE} - RET_STATUS=$? - if [ $RET_STATUS != 0 ]; then - rm -rf $XORP_LOCK >&/dev/null - fi - ;; - delete) - /opt/vyatta/sbin/my_delete "${@:2}" >>${XORPLOGFILE} 2>>${MYCMDERRLOGFILE} - RET_STATUS=$? - if [ $RET_STATUS != 0 ]; then - rm -rf $XORP_LOCK >&/dev/null - fi - ;; - commit) - /opt/vyatta/sbin/my_commit >>${XORPLOGFILE} 2>>${MYCMDERRLOGFILE} - RET_STATUS=$? - rm -rf $XORP_LOCK >&/dev/null - ;; - test) - "${@:2}" - RET_STATUS=$? - ;; - cleanup) - - LOCKTRYCOUNTER=0 - LOCKTRYSTATUS=-1 - - while [[ ${LOCKTRYCOUNTER} -lt 60 && ${LOCKTRYSTATUS} -ne 0 ]] ; do - - if mkdir $XORP_LOCK >&/dev/null ; then - LOCKTRYSTATUS=0 - else - LOCKTRYCOUNTER=`expr ${LOCKTRYCOUNTER} + 1` - sleep 1; - fi - done - - if [ ${LOCKTRYCOUNTER} -ge 60 ] ; then - echo "Cannot unlock configuration" >> ${MYCMDERRLOGFILE} - rm -rf ${XORP_LOCK} - mkdir $XORP_LOCK >&/dev/null - fi - - sudo umount ${VYATTA_TEMP_CONFIG_DIR} - sudo rm -rf $VYATTA_CHANGES_ONLY_DIR/* $VYATTA_CHANGES_ONLY_DIR/.modified - sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR} - RET_STATUS=0 - ;; - end_loading) - sudo umount ${VYATTA_TEMP_CONFIG_DIR} - sudo rm -rf ${VYATTA_CHANGES_ONLY_DIR} - sudo rm -rf ${VYATTA_CONFIG_TMP} - sudo rm -rf ${VYATTA_TEMP_CONFIG_DIR} - RET_STATUS=0 - ;; - rtrmgr_indirect_cleanup) - # do nothing now that we handle XORP interaction differently. - RET_STATUS=0 - ;; - *) - rm -rf ${MYCMDERRLOGFILE} - exit 1 - ;; -esac - -if [ -f ${MYCMDERRLOGFILE} ] ; then - - echo -n "STDERR:" >>${XORPLOGFILE} - cat ${MYCMDERRLOGFILE} >>${XORPLOGFILE} - echo "end of STDERR" >>${XORPLOGFILE} - - cat ${MYCMDERRLOGFILE} 1>&2 - - rm -rf ${MYCMDERRLOGFILE} - -fi - -#echo "ConfigDirectories AFTER ========>>>>>>" >> ${XORPLOGFILE} -#find /opt/vyatta/config -name "*" -print | grep interface >> ${XORPLOGFILE} -#echo "<=========ConfigDirectories AFTER" >> ${XORPLOGFILE} - -echo "ret=${RET_STATUS}" >> ${XORPLOGFILE} -umask ${UMASK_SAVE_G} -exit $RET_STATUS - -# Local Variables: -# mode: shell-script -# sh-indentation: 4 -# End: diff --git a/src/cli_new.c b/src/cli_new.c index 353babd..1ecbe83 100644 --- a/src/cli_new.c +++ b/src/cli_new.c @@ -745,11 +745,12 @@ int char2val(vtw_def *def, char *value, valstruct *valp) if (!token) return 0; if (token != EOL) { + fprintf(out_stream, "\"%s\" is not a valid value\n", value); print_msg("Badly formed value in %s\n", m_path.path + m_path.print_offset); if (token == VALUE) my_free(get_cli_value_ptr()->val); - return 0; + return -1; } } return 0; |