Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Repost This is a request for C/C++ code...

Repost This is a request for C/C++ code...

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestionannouncement
4 Posts 3 Posters 32 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #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:

    J K 2 Replies Last reply
    0
    • L Lost User

      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:

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      Googling provides answers

      C++ "sudo" provide password

      1 Reply Last reply
      0
      • L Lost User

        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:

        K Offline
        K Offline
        k5054
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • K k5054

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups