1

I have developed an application in Linux using C language which has command line interface. It is completely an independent application. Now I am making a GUI interface for it also in C using gtk library. In CLI, before a certain operation, my CLI application waits for a password (just like they do it in useradd command line utility in linux). For this purpose I will create a window with password field asking for password in GUI.

My question is that how will I transfer the password from GUI to the application that is waiting for password in CLI? Can I redirect the password taken from GUI to the stdin of CLI process?

Also please let me know if my approach is correct or what are the standard ways of doing it?

Any help would be appreciated.

awatan
  • 1,182
  • 15
  • 33
  • You can either pipe in the input (if the CLI application is expecting input that way) or you can put in the parameters as command line arguments. –  Feb 20 '13 at 16:32
  • I dont want to take password as an argument to command line parameters as it may be compromise security. – awatan Feb 20 '13 at 16:35
  • 2
    You could always pass in a salted hash of the password. Also, an unencrypted password sent as a command line argument is just as much of a security vulnerability as an unencrypted password piped into a CLI app. –  Feb 20 '13 at 16:35

1 Answers1

0

Sure you can. I don't know much about GTK, but you can simply use popen, that is for sure. For bidirectional communication take a look at Can popen() make bidirectional pipes like pipe() + fork()?

Community
  • 1
  • 1
João Fernandes
  • 1,101
  • 5
  • 11
  • Thanks. I have read manpage of popen(). Correct me if I am wrong in my understanding: I will invoke my CLI application as a shell command from popen and give "w" as argument in its 'type' parameter and then write the password to this write pipe. – awatan Feb 20 '13 at 16:47
  • That is correct. However, thinking more clearly about your use case, I think you may need bidirectional communication at some point, for whatever reason. If that is the case, take a look at http://stackoverflow.com/questions/3884103/can-popen-make-bidirectional-pipes-like-pipe-fork – João Fernandes Feb 20 '13 at 16:51
  • I think you are correct. I may need bidirectional communication in this case. – awatan Feb 20 '13 at 17:10