1

So my end goal is to run a program on my Beaglebone Black on boot (add it to the init file) that will exec other programs. Those other programs that are being started need sudo privileges to start. From research, I have seen a couple of ways to do this but I don't know which one would be "correct". Could somebody point me in the right direction?

Here is the code I am testing right now to start one of the many programs:

#include <iostream>
#include <unistd.h>

using std::cout;
using std::cin;

int main()
{
   pid_t pid;

   pid = fork();

   if (0 == pid)
   {
      setreuid(geteuid(), getuid());
      execl("/usr/local/bin/osmo-trx", "osmo-trx", "-f", NULL);
      cout << "\n\n***Something went wrong starting osmo-trx***\n\n";
   }
   else if (0 < pid) ;
   else
   {
      cout << "\n\nSomething went wrong...\n\n";
      return -1;
   }

   return 0;
}

I'm having trouble figuring out the correct question. Here are some that I have though they may be way off the path that I should take.

  1. Can I exec a program with sudo privileges? Tried with the uid but no luck.

  2. If I give the debian user root privileges, will I be able to run any program? Tried by editing my visudo and adding debian with no success. Below is the file:

    #
    # This file MUST be edited with the 'visudo' command as root.
    #
    # Please consider adding local content in /etc/sudoers.d/ instead of
    # directly modifying this file.
    #
    # See the man page for details on how to write a sudoers file.
    #
    Defaults        env_reset
    Defaults        mail_badpass
    Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    
    # Host alias specification
    
    # User alias specification
    
    # Cmnd alias specification
    
    # User privilege specification
    root    ALL=(ALL:ALL) ALL
    debian  ALL=(ALL:ALL) ALL
    
    # Allow members of group sudo to execute any command
    %sudo   ALL=(ALL:ALL) ALL
    
    # See sudoers(5) for more information on "#include" directives:
    
    #includedir /etc/sudoers.d
    %admin  ALL=(ALL) ALL</code>
    

    --Note: sorry for the epic indentation but the editor was giving me trouble highlighting my code.--

Please help...

Community
  • 1
  • 1

0 Answers0