Click here to Skip to main content
15,894,405 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Question!file trickiness Pin
mike74114-Jan-24 1:45
mike74114-Jan-24 1:45 
AnswerRe: !file trickiness Pin
Maximilien4-Jan-24 2:12
Maximilien4-Jan-24 2:12 
GeneralRe: !file trickiness Pin
mike74114-Jan-24 2:41
mike74114-Jan-24 2:41 
Questionoutputting Δέλτα Pin
mike74112-Jan-24 16:34
mike74112-Jan-24 16:34 
AnswerRe: outputting Δέλτα Pin
Dave Kreskowiak2-Jan-24 17:56
mveDave Kreskowiak2-Jan-24 17:56 
Questionsizeof not working Pin
mike74111-Jan-24 1:31
mike74111-Jan-24 1:31 
AnswerRe: sizeof not working Pin
Richard MacCutchan1-Jan-24 2:28
mveRichard MacCutchan1-Jan-24 2:28 
AnswerRe: sizeof not working Pin
jeron12-Jan-24 5:38
jeron12-Jan-24 5:38 
GeneralRe: sizeof not working Pin
jschell2-Jan-24 6:34
jschell2-Jan-24 6:34 
GeneralRe: sizeof not working Pin
jeron12-Jan-24 7:11
jeron12-Jan-24 7:11 
QuestionPlease - explain the C++ code / function Pin
Salvatore Terress28-Dec-23 6:09
Salvatore Terress28-Dec-23 6:09 
AnswerRe: Please - explain the C++ code / function Pin
Graham Breach28-Dec-23 8:59
Graham Breach28-Dec-23 8:59 
GeneralRe: Please - explain the C++ code / function Pin
Salvatore Terress29-Dec-23 2:56
Salvatore Terress29-Dec-23 2:56 
GeneralRe: Please - explain the C++ code / function Pin
Graham Breach29-Dec-23 3:50
Graham Breach29-Dec-23 3:50 
GeneralMessage Closed Pin
31-Dec-23 8:49
Salvatore Terress31-Dec-23 8:49 
GeneralRe: How to pass xterm -e option as variable? Pin
k505431-Dec-23 17:35
mvek505431-Dec-23 17:35 
GeneralRe: How to pass xterm -e option as variable? Pin
jschell1-Jan-24 2:07
jschell1-Jan-24 2:07 
GeneralMessage Closed Pin
1-Jan-24 9:51
Salvatore Terress1-Jan-24 9:51 
GeneralRe: How to pass xterm -e option as variable? Pin
k50541-Jan-24 13:09
mvek50541-Jan-24 13:09 
You can tell sudo to allow certain users the ability to run a given command without having to prompt for a password. For example you might add a file foo to the /etc/sudoers.d directory
# allow user "joe" to use command /usr/sbin/foobar
joe ALL(ALL) NOPASSWD:/usr/sbin/foobar

# allow users in group foo to use command /usr/sbin/frobnicate
%foo ALL(ALL) NOPASSWD:/usr/sbin/frobnicate
Google for sudoers to see what other options you have for the sudoers file.

But you should be aware that any time a user process "needs" sudo access, its something of a smell. That is it should be considered a signal that there may be something fundamentally wrong with the approach to solving the problem. If your app definitely, absolutely, no-question-about-it needs to elevate its permissions to perform some tasks, I would be inclined to write a program that only does that one thing, and use setuid/setgid with appropriate setuid/setgid permissions e.g.
Bash
$ ls /usr/local/bin/foo
---s--x--x 1 root root 12345 Jan 1 08:00 /usr/local/bin/foo
and the code for foo would do something like
C++
std::string build_cmd_str(int argc, char argv)
{
   std::string cmd{"/usr/local/bin/foo"};
   / build up rest of command string here */
   if(bad_things_happened) {
      cmd.erase();
   }
   return cmd;
}

main(int argc, char *argv[])
{

   // create a command string<br />
   std::string cmd{build_cmd_str(argc, argv)}; 

   if(cmd.length() == 0) {
      // send diagnostic to cerr, maybe? 
      return -1;
   } else {
      setuid(0);  // set actual uid to root 
      FILE *p = pipe(cmd.c_str(), "r");
      // process output
      // send to stdout as needed
      pclose(p);
   }

   return 0;
}
This can be as simple or complex as you need, but should only execute one system command. Ideally, if you only need to run something as perhaps the database administrator, the helper program would have setuid as the dba, not root.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown

GeneralRe: How to pass xterm -e option as variable? Pin
jschell2-Jan-24 6:14
jschell2-Jan-24 6:14 
GeneralRe: How to pass xterm -e option as variable? Pin
Richard MacCutchan1-Jan-24 22:13
mveRichard MacCutchan1-Jan-24 22:13 
GeneralRe: How to pass xterm -e option as variable? Pin
jschell2-Jan-24 6:26
jschell2-Jan-24 6:26 
AnswerRe: Please - explain the C++ code / function Pin
Richard MacCutchan28-Dec-23 22:02
mveRichard MacCutchan28-Dec-23 22:02 
AnswerRe: Please - explain the C++ code / function Pin
jschell29-Dec-23 5:16
jschell29-Dec-23 5:16 
AnswerRe: Please - explain the C++ code / function Pin
jeron112-Jan-24 5:04
jeron112-Jan-24 5:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.