in reply to Re: passwords with special characters are trying to kill me... no seriously!
in thread passwords with special characters are trying to kill me... no seriously!
my $set_password = '/usr/bin/ssh ' . $master_host . " 'echo \Q$new_pas +sword\E | /usr/bin/passwd --stdin \Q$username\E'";
Unfortunately, that won't work if the password contains, for example, a single quote.
my $master_host = 'localhost'; my $username = 'foo'; my $new_password = 'a\'b$c"d|e'; print "pwd: ",$new_password; my $set_password = '/usr/bin/ssh ' . $master_host . " 'echo \Q$new_pas +sword\E | /usr/bin/passwd --stdin \Q$username\E'"; print "cmd: ",$set_password; system $set_password; __END__ pwd: a'b$c"d|e cmd: /usr/bin/ssh localhost 'echo a\'b\$c\"d\|e | /usr/bin/passwd --st +din foo' sh: Syntax error: Unterminated quoted string
In other words, a simple quotemeta (\Q) is not the appropriate tool to quote arbitrary strings for the shell. You'd have to use more sophisticated techniques.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: passwords with special characters are trying to kill me... no seriously!
by ikegami (Patriarch) on Feb 04, 2011 at 17:55 UTC |
In Section
Seekers of Perl Wisdom