PowerDNS / pdns

PowerDNS Authoritative, PowerDNS Recursor, dnsdist
https://www.powerdns.com/
GNU General Public License v2.0
3.72k stars 913 forks source link

'pdnsutil edit-zone' doesn't work in RHEL #12338

Closed v1shnya closed 1 year ago

v1shnya commented 1 year ago

Short description

'pdnsutil edit-zone' doesn't work in RHEL

Environment

Steps to reproduce

[/home/dev]$ EDITOR='/usr/bin/vi'
[/home/dev]$ export EDITOR
[/home/dev]$ echo $EDITOR
/usr/bin/vi
[/home/dev]$ sudo pdnsutil edit-zone test.com
Dec 19 11:01:13 godbc Connection successful
Dec 19 11:01:14 godbc Connection successful
sh: editor: command not found
Error: Editing file with: 'editor /tmp/pdnsutil-WkU2Nl', perhaps set EDITOR variable: Operation now in progress

Other information

I belive that the problem is related to the CHAR* to STRING assignment in the code. See it started from the line https://github.com/PowerDNS/pdns/blob/master/pdns/pdnsutil.cc#L1188

  string editor="editor";
  if(auto e=getenv("EDITOR")) // <3
    editor=e;

Function char* getenv (const char* name) returns CHAR* that can't be just assigned to STRING. Need to use type conversion editor=str(e);

omoerbeek commented 1 year ago

It is also very possible that the environment provided by sudo does not provide EDITOR.

v1shnya commented 1 year ago
[/home/dev]$ EDITOR='/usr/bin/vi'
[/home/dev]$ echo $EDITOR
/usr/bin/vi
[/home/dev]$ sudo  echo $EDITOR
/usr/bin/vi

using sudoI still can see EDITOR variable

v1shnya commented 1 year ago

Was wrong, assignment editor=e is correct. By the way, the same issue is also seen on Ubuntu - can't specify EDITOR envvar.

So, for me it looks like the problem is in the if(auto e=getenv("EDITOR")) statement

pieterlexis-tomtom commented 1 year ago

this works for me (on Arch):

sudo -E EDITOR=vim pdnsutil edit-zone $ZONE

Does this (with your favorite editor) work on RHEL?

Habbie commented 1 year ago

[/home/dev]$ sudo echo $EDITOR

this expands $EDITOR before invoking sudo

omoerbeek commented 1 year ago

Try sudo sh -c "echo PATH=\$PATH EDITOR=\$EDITOR"

v1shnya commented 1 year ago
[/home/dev]$ sudo sh -c "echo PATH=\$PATH EDITOR=\$EDITOR"
PATH=/sbin:/bin:/usr/sbin:/usr/bin EDITOR=

Yes, sudo -E EDITOR=vim pdnsutil edit-zone test.com works! Thank you! and point taken, will read about sudo invocation ;)