Tuesday, 4 August 2009

Against the wind (part 3)

It turns out the poor man’s gksudo I came up with earlier has issues. It has something to do with how quotes are handed in bash and/or sudo, but I’ve tried everything to figure out what the problem is and have come up with nothing. In short, in a bash script, if you issue

echo $pw | sudo -H -S -b -u root rox "/home/mithat/test me"

it works as expected (assuming $pw is valid). But if you issue:

myCMD="rox "/home/mithat/test me""
echo $pw | sudo -H -S -b -u root $myCMD

it doesn’t, even though $myCMD echoes as rox "/home/mithat/test me". The sudo command seems to become blind to the quotes around the path, even though they appear just fine when echoed. Quoting the error verbatim:

File doesn't exist, or I can't access it: "/home/mithat/test
File doesn't exist, or I can't access it: me"

sudo sees rox just fine, but then it splits arguments at the space in the path even though the path is quotedand it sees the quotes! WTF?

So, here’s a list of things that don’t work reliably, even though they should:

  • gksudo
  • su-to-root
  • handmade GUI sudo wrapper

And here’s a list of things that work reliably:

  • su
  • sudo

It really shouldn’t be like this.