calling UNIX commands C/C++


 
Thread Tools Search this Thread
Top Forums Programming calling UNIX commands C/C++
# 1  
Old 03-11-2009
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:

Quote:
/opt/VRTS/bin/hastatus -sum
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.

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

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

}

Thanks and Regards
@ asteroid
# 2  
Old 03-11-2009
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.
# 3  
Old 03-11-2009
@pludi Thx for the reply. Please extend some more help to solve my problem.

Quote:
Why exactly isn't sudo an option? (Just asking to make sure you describe the right problem before we give the wrong answer)
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.

Code:
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

Code:
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.
# 4  
Old 03-11-2009
Quote:
Originally Posted by Asteroid
[...]So, how can i adopt SUID by setting the Bit. any help[...]
chmod u+s file
also man chmod
Quote:
Originally Posted by Asteroid
[...]so it mean, i cannot su - root in my program as it will tend to read from tty.
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Calling Macros in UNIX command

Hi .. I have created a sql macro, i want to execute this through ksh in putty.ie) sql.ksh will contain the macro query ,once i call this ksh ,the macro should trigger. I am able to write a macro : for ex: create macro macro_name (sel * from db_tablename) execute macro_name. Could... (1 Reply)
Discussion started by: Kalaiselvi66
1 Replies

2. UNIX for Dummies Questions & Answers

Unix Shell Scripting( Calling from Unix to PLSQL)

Hello Experts, I have the following questions to be discussed here at this esteemed discussion forum. I have two Excel sheets which contain Unix Commands llike creating directory the structure/ftp/Copy/Zip etc to basically create an environment. I need help in understanding some of... (1 Reply)
Discussion started by: faizsaadq
1 Replies

3. UNIX for Dummies Questions & Answers

Calling commands with ksh

Hi, I am not able to run below command on linux, it however works on solaris. If anyone knows the reason and a solution for it can you please let me know ? Linux ----- $> ksh 'echo hi' ksh: echo hi: No such file or directory $> which ksh /usr/bin/ksh Solaris ------ $> ksh 'echo... (2 Replies)
Discussion started by: krishnaux
2 Replies

4. Shell Programming and Scripting

calling perl commands in shell

i have four commands 1. perl -MCPAN -e shell 2. o conf prerequisites_policy follow 3. o conf commit 4. exit I am attempting to streamline a bunch of yum commands and cpan installations and want to remove the confirmation portion of the cpan these four commands will do just that. my... (2 Replies)
Discussion started by: murphybr
2 Replies

5. UNIX for Advanced & Expert Users

Oracle (11gr2) calling unix commands (aix)

I have an Oracle database running on AIX, and I have a procedure that is calling OS commands from an oracle (and it's not working anymore)... so, there was an Java stored proc in Oracle CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED COMMON."Host" as import java.io.*; public class Host {... (1 Reply)
Discussion started by: bongo
1 Replies

6. Programming

Calling procedure through Unix Shell

Hi can anyone help me in how to 1) invoke batch profile to run sqlplus on XXXXX server. 2) execute truncate table xtra.xtra_card_email_request using procedure dbadmin.truncate_table . 3) Check the count before and after the job run. (1 Reply)
Discussion started by: jakred
1 Replies

7. Shell Programming and Scripting

Calling GDB commands from Shell

Hi, I have just started off with the shell programming. I need to execute a GDB command from a shell script. I have been trying to get this working from quite sometime but not getting it quite right.I have this specific requirement that i read byte data from a file and write that data to the... (0 Replies)
Discussion started by: jsantosh
0 Replies

8. Shell Programming and Scripting

Perl calling unix system commands

if ( system ("/bin/cat $File1 >> $File2") ) { print("#WARNING RAISED : /bin/cat File1 >> File2 - FAILURE!\n"); } I came across this code, would appreciate if someone can tell me if my understanding is correct? the perl code tell the system to cat file 1 into file 2, if command fails, print... (4 Replies)
Discussion started by: new2ss
4 Replies

9. UNIX for Dummies Questions & Answers

calling Oracle procedure from Unix

Does anyone know how to call an Oracle stored procedure from a Unix script? (1 Reply)
Discussion started by: ssmiths001
1 Replies

10. Programming

calling UNIX script from C/C++

Hi all, Is it possible to call a UNIX script from C/C++ program? If yes, can you please tell me how? Thank you in advance Regards (3 Replies)
Discussion started by: omran
3 Replies
Login or Register to Ask a Question