calling UNIX commands C/C++

hi Guys,

I am planning to write a program which can be able to execute scripts/commands which needs a user to be root.

Note: we are not interested to use sudoers option.

.e.g. The requirement can be explaind as:

A normal UNIX system user cannot execute above command(veritas cluster summary command) root previleages are required for its executions. so facilitating normal users (who donot know root passwords) to execute above command we can adopt a program. The program knows root password and should internally execute the above command.
A sample program could be like below. I need to know how and where to provide root password.

Any suggestions.


#include"stdlib.h"
void main()
{

string root_passwd= "mypassword123";
system("/opt/VRTS/bin/hastatus -sum");

}

Thanks and Regards
@ asteroid

Why exactly isn't sudo an option? (Just asking to make sure you describe the right problem before we give the wrong answer)

As for your program: it doesn't need to know the root password, it only has to have the SUID bit set (like sudo or su). If you meant to call su from your program, you'll have the same problem as others who posted about entering the root password from a shell script: probably not possible, as both su and sudo always try to read from the tty, not stdin.

@pludi Thx for the reply. Please extend some more help to solve my problem.

well, Sudu is not an option because this utility is not available on the machines and more over we are willing to install it either.

As for your program: it doesn't need to know the root password, it only has to have the SUID bit set (like sudo or su).

So, how can i adopt SUID by setting the Bit. any help

If you meant to call su from your program, you'll have the same problem as others who posted about entering the root password from a shell script: 

probably not possible, as both su and sudo always try to read from the tty, not stdin.

so it mean, i cannot su - root in my program as it will tend to read from tty.

chmod u+s file
also man chmod

That is correct

If, and only if, you do not need to invoke more that 2-3 programs with as root, without the ability for the user to change anything about the command line, your approach might be ok. Anything more will probably be unmaintainable quickly and/or introduce possible security risks. So unless you only need a wrapper for 2-3 (at max) pre-defined commands that do not accept any user interaction I'd advise to install sudo.