Repost This is a request for C/C++ code...
-
UPDATE ( just to share ) here is working as expected C++ code
system(" echo q | sudo -S hcitool cc --role=c 98:D3:31:F8:29:33");
and here is the result:
[sudo] password for nov25-1: Can't create connection: Input/output error
what is interesting "echo" hides the passed password the challenge - how to hide [sudo] password for nov25-1:
-
UPDATE ( just to share ) here is working as expected C++ code
system(" echo q | sudo -S hcitool cc --role=c 98:D3:31:F8:29:33");
and here is the result:
[sudo] password for nov25-1: Can't create connection: Input/output error
what is interesting "echo" hides the passed password the challenge - how to hide [sudo] password for nov25-1:
-
UPDATE ( just to share ) here is working as expected C++ code
system(" echo q | sudo -S hcitool cc --role=c 98:D3:31:F8:29:33");
and here is the result:
[sudo] password for nov25-1: Can't create connection: Input/output error
what is interesting "echo" hides the passed password the challenge - how to hide [sudo] password for nov25-1:
Try using a [Here Document](https://tldp.org/LDP/abs/html/here-docs.html) :
[k5054@localhost]$ sudo ps
[sudo] password for k5054:
sudo: no password was provided
sudo: a password is required
[k5054@localhost]$ cat example.cpp
#include #include #include int main()
{
std::string userPass{"myPassword"};
std::string command{"sudo -S ps -lf 2>/dev/null <<_EOF\n" + userPass + "\n_EOF"};
FILE *pipe = popen(command.c_str(), "r");
char *line = NULL;
size_t len = 0;
ssize_t rlen;
while( (rlen = getline(&line, &len, pipe)) > 0) {
line[--rlen] = '\0'; // trim trailing newline
std::cout << line << '\n';
}pclose(pipe); free(line);
}
[k5054@localhost]$ make example
g++ -Wall -Wextra -ggdb example.cpp -o example
[k5054@localhost]$ ./example
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
1 S root 4030 4029 0 80 0 - 4799 do_pol 11:49 pts/2 00:00:00 sudo -S ps -lf
4 R root 4031 4030 0 80 0 - 3502 - 11:49 pts/2 00:00:00 ps -lf
[k5054@localhost]$You should be able to modify that for use with QProcess. Note that if you don't redirect stderr to /dev/null, the SSH password prompt goes to wherever stderr is pointing to.
"A little song, a little dance, a little seltzer down your pants" Chuckles the clown
-
Try using a [Here Document](https://tldp.org/LDP/abs/html/here-docs.html) :
[k5054@localhost]$ sudo ps
[sudo] password for k5054:
sudo: no password was provided
sudo: a password is required
[k5054@localhost]$ cat example.cpp
#include #include #include int main()
{
std::string userPass{"myPassword"};
std::string command{"sudo -S ps -lf 2>/dev/null <<_EOF\n" + userPass + "\n_EOF"};
FILE *pipe = popen(command.c_str(), "r");
char *line = NULL;
size_t len = 0;
ssize_t rlen;
while( (rlen = getline(&line, &len, pipe)) > 0) {
line[--rlen] = '\0'; // trim trailing newline
std::cout << line << '\n';
}pclose(pipe); free(line);
}
[k5054@localhost]$ make example
g++ -Wall -Wextra -ggdb example.cpp -o example
[k5054@localhost]$ ./example
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
1 S root 4030 4029 0 80 0 - 4799 do_pol 11:49 pts/2 00:00:00 sudo -S ps -lf
4 R root 4031 4030 0 80 0 - 3502 - 11:49 pts/2 00:00:00 ps -lf
[k5054@localhost]$You should be able to modify that for use with QProcess. Note that if you don't redirect stderr to /dev/null, the SSH password prompt goes to wherever stderr is pointing to.
"A little song, a little dance, a little seltzer down your pants" Chuckles the clown
Thanks, as I suspected "stdin" and file "pipe" are what I failed to put into THE equation. Unfortunately all these " well meaning " but superficial, distracting from subject , AKA not answering questions , commentaries about security did not help... SOLVED 10-4