Page MenuHomeVyOS Platform

Problems when using <path> as completion helper in op-mode
Closed, ResolvedPublicBUG

Description

Using a completion helper in op mode like:

<completionHelp>
  <path>vrf name</path>
</completionHelp>

will generate the following node.def file:

cat /opt/vyatta/share/vyatta-op/templates/show/vrf/node.tag/node.def
help: Show information on specific VRF instance
allowed: /bin/cli-shell-api listActiveNodes vrf name
run: ${vyos_op_scripts_dir}/show_vrf.py -e "$3"

The problem here is a call to /bin/cli-shell-api listNodes vrf name will return: 'bar' 'foo' see the ' quotes. The old node.def implementations got rid if the '' by using shell code like:

allowed:
  local -a bnodes
  local -a nnodes
  eval "bnodes=($(cli-shell-api listActiveNodes protocols bgp))"
  for b in "${bnodes[@]}"; do
    eval "nnodes=($(cli-shell-api listActiveNodes protocols bgp $b neighbor))"
    echo -n "${nnodes[@]}" ' '
  done

Which removes the ' quotes.

This can easily be done using | sed -e "s/'//g"

Question: Why is this of no issue in configuration mode?

Details

Difficulty level
Unknown (require assessment)
Version
1.2.5
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Internal change (not visible to end users)

Event Timeline

Turns out it's because the conf mode "allowed: " is escaped and eval'd when it's passed to the shell: https://github.com/vyos/vyatta-cfg/blob/current/src/cstore/cstore.cpp#L756-L762

However, op mode "allowed:" is a different story altogether . Op mode template "parsing" seems to be done in shell with sed! https://github.com/vyos/vyatta-op/blob/current/functions/interpreter/vyatta-op-run#L45-L64

I couldn't locate where exactly the "allowed:" field is processed yet.

VyOS 1.3-rolling-202007240117

vyos@r1-roll:~$ show vrf 
Possible completions:
  <Enter>       Execute the current command
  bar           Show information on specific VRF instance
  FOO
  LAN

@c-po Can we close it?

A workaround is in place for this

c-po claimed this task.
erkin set Issue type to Internal change (not visible to end users).Aug 31 2021, 5:26 PM