Linux, Eclipse CDT work as su

I use Eclipse CDT to write an application. The application uses the third part API, which requires running as sudo to open raw sockets, etc.

On the command line, I can run the program somehow like

su ./program 

But in the Eclipse CDT environment this will not work if I press Ctrl + F11 (Run-> Run Last Launched), I think the reason is that my Linux GUI login is not su.

Anyway, can I run as su (with su password) in an Eclipse CDT?

Thanks.

+4
source share
2 answers

Some options you have:

  • Run Eclipse as root. (Not a good idea, IMHO, but the simplest)

  • Temporarily allow the user to use this library. (May be dirty)

  • Create a new launch configuration and create a script to run the executable. (You must enter a password each time).

  • (@ Others, feel free to add more.)

+3
source

You can create a launch configuration in which you use sudo to launch your application. Since sudo does not have access to the terminal, if you run it this way, it requires setting the SUDO_ASKPASS environment SUDO_ASKPASS in your startup configuration. These steps are as follows:

  • Creating a new launch configuration (for completeness):

    • In eclipse, right-click your executable file (i.e. the result of building your application) to open the context menu
    • In the context menu, select Run as → Run configuration ...
    • In the “Startup Configuration” window that appears, right-click the C / C ++ application and click "Create."
  • Change launch configuration

    • On the tab "Basic configuration", replace the "C / C ++ Application" field with
      /usr/bin/sudo .
    • Go to the "Arguments" tab and enter the path to your executable file, for example.
      ./bin/my-executable . Note: the sudo working directory is an eclipse project, so the path should be relative to this.
    • If your executable requires any command line arguments, add them, for example.
      ./bin/my-executable arg1 arg2
  • Adding a path for sudo to request a password.

    • This is the hardest part. Since sudo does not have a terminal (tty) at its disposal when starting from (eclipse) gui, we must provide it with a program that can receive a password for it, that is, program the program. See fooobar.com/questions/30580 / ... for more information.
    • On my system (Ubuntu 15.04), the ssh-askpass-gnome package provides the askpass program, as I found out by running dpkg --get-selections | grep askpass dpkg --get-selections | grep askpass . Since this has not yet given me an executable name, I roughly searched for the search by running
      sudo find -name *askpass* . In any case, if such a utility is not installed, find it using your favorite package manager.
    • Once we have installed and / or placed the askpass program, we can continue to create our launch configuration in eclipse; go to step 2.3
    • In the Run Configuration window, select the Environment tab and click Create.
    • In the dialog that appears, enter SUDO_ASKPASS as the name and the full path to the askpass program as a value, for example. /usr/bin/ssh-askpass .
    • Click Apply to save your changes.
  • Run startup configuration
    • In the Run Configuration window, click Run to launch our executable file using the newly created launch configuration.
    • A pop-up window for entering the sudo password will appear.
    • After successfully entering the password, our executable file will be launched with root privileges.
0
source

Source: https://habr.com/ru/post/1402748/


All Articles