[SOLVED]encfs and input password from script using kdialog

This forum is dedicated to basic help and support :

Ask here your questions about basic installation and usage of Mageia. For example you may post here all your questions about getting Mageia isos and installing it, configuring your printer, using your word processor etc.

Try to ask your questions in the right sub-forum with as much details as you can gather. the more precise the question will be, the more likely you are to get a useful answer

[SOLVED]encfs and input password from script using kdialog

Postby mackowiakp » Mar 22nd, '15, 10:37

I create small script to mount encfs filesystem. just like this:

Code: Select all
#!/bin/bash
kdialog --password "Wprowadź hasło do SSH lub ENTER żeby rozłączyć:" >  /home/maciek/Pobrane/pass-1
sudo encfs -S --public /home/maciek/dir/.dir_c /home/maciek/dir_v < /home/maciek/Pobrane/pass-1
status=$?
if test $status -eq 0
then
cat /dev/null > /home/maciek/Pobrane/pass-1
<command_A>
kdialog --passivepopup "Zamontowano SSH" 5
exit
else
cat /dev/null > /home/maciek/Pobrane/pass-1
<command_B>
kdialog --passivepopup "Rozłączono SSH lub błędne hasło" 5
fi


Previously I used zenity instead kdialog but kdialog looks more nice for me.
It works OK, when running from terminal as ordinary user or as root. Than I create shortcut on my KDE desktop to run that script. And I have to use option "Run in terminal" in shortcut definition because in other case "encfs" does not mount filesys, because of wrong password. But the password was entered correctly. What I im doing wrong so script works properly only started from "konsole" terminal in KDE?
Last edited by mackowiakp on Mar 22nd, '15, 15:46, edited 1 time in total.
Linux is like wigwam. No Windows, no Gates but Apache inside

WARNING ! The administrator has the right to refuse to install WINDOWS, invoking the conscience clause
mackowiakp
 
Posts: 660
Joined: May 23rd, '13, 07:32
Location: Gdynia, Poland

Re: encfs and input password from script using kdialog

Postby doktor5000 » Mar 22nd, '15, 12:37

When you don't run it inside a terminal you will have no tty associated, and hence sudo will fail to run encfs.
And the default from /etc/sudoers is that sudo requires a tty:
grep requiretty /etc/sudoers wrote:Defaults requiretty

Check http://unix.stackexchange.com/questions ... a-password

Apart from that, you should definitely redo that script. It's bad practice to use a file when you can use a variable instead,
just image your box crashes during the script run after you entered the password - it will be put in plaintext in a file.

I'd try this way, after the password query the script will output the associated tty, just compare the difference when run from a terminal and run from your shortcut, if not run in a terminal.

Code: Select all
#!/bin/bash
# empty password var for safety
pass=

pass=$(kdialog --password "Wprowadź hasło do SSH lub ENTER żeby rozłączyć:")
kdialog --passivepopup "$(tty)"
echo $pass | sudo encfs -S --public $HOME/dir/.dir_c $HOME/dir_v
if [[ $? -eq 0 ]];
then
  unset $pass
  command_A
  kdialog --passivepopup "Zamontowano SSH" 5
exit
else
  unset $pass
  command_B
  kdialog --passivepopup "Rozłączono SSH lub błędne hasło" 5
fi
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18059
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: encfs and input password from script using kdialog

Postby mackowiakp » Mar 22nd, '15, 13:24

I agree with You that passing passwords via file is not correct situation. But I try a lot of different solution to workaround TTY problem.
Now I correct my script and comment "Defaults requiretty" entry in /etc/sudoers. Now it works OK from desktop shortcut !

As I understand, it is not dangerous for system security?
Linux is like wigwam. No Windows, no Gates but Apache inside

WARNING ! The administrator has the right to refuse to install WINDOWS, invoking the conscience clause
mackowiakp
 
Posts: 660
Joined: May 23rd, '13, 07:32
Location: Gdynia, Poland


Return to Basic support

Who is online

Users browsing this forum: No registered users and 1 guest