Operating System - HP-UX
1850431 Members
2368 Online
104054 Solutions
New Discussion

How can I set users parameter by compiled file

 
SOLVED
Go to solution
choijg
Occasional Advisor

How can I set users parameter by compiled file

HP-UX 11.X
L-Class

I need to set user parameter by compiled file.
Because user do not know what parameter was set
or which file is setted, so i tried to compile
putenv fuction.



#include
#include

void main(int argc, char *argv[])
{
putenv("USERPASS=/tmp/dir01");
system("export USERPASS");
system("echo $USERPASS");
}

when i put this compiled exec module in
user .profile user cannot login

How do i set the user parameter by compiled file.

Thanks everyone. ^^;
5 REPLIES 5
Mark Grant
Honored Contributor
Solution

Re: How can I set users parameter by compiled file

Seems an odd request to me but I'm sure you have good reason.

putenv should work but there is no need to do the system(export) because you have already put the thing in the environment (and as you run the export in a different shell anyway, the only reason it does anything at all is because you already exported it with putenv()) .


When you run the program try calling it with a preceding "." as in ". ./program". Because otherwise you are putting things in the environment of the program, not your running shell.
Never preceed any demonstration with anything more predictive than "watch this"
R. Allan Hicks
Trusted Contributor

Re: How can I set users parameter by compiled file

If the parameter is not secret, then put it in the .profile so that when the user logs in it is in his environment.

export USERPASS=/tmp/dir01

Then the getenv will recover it.

-or-

wrap a script around your program

#!/bin/ksh

export USERPASS=/tmp/dir01

myProgram

They run the script which sets the environment and myProgram recovers the environment variable.
"Only he who attempts the absurd is capable of achieving the impossible
A. Clay Stephenson
Acclaimed Contributor

Re: How can I set users parameter by compiled file

The problem is that this is a child process. Any changes you make to the child's environment are not going to be seen by the parent process. This is fundamental to UNIX design. If your .profile exec'ed this program then it could do a putenv() and then spawn a new shell that would have your environment variable defined.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: How can I set users parameter by compiled file

The "." (dot) command will not work in this case. The dot command will only excute shell commands not an executable.
If it ain't broke, I can fix that.
choijg
Occasional Advisor

Re: How can I set users parameter by compiled file

Thanks everyone

I found the crypt function is Good solution
in this situation.

I set the all user environment variable and
connection password in the shell program
and encode the script. ^_^;

When i need the environment variable, I run cript ...(key?) < clear >cypher

cript will be a good solution

Thanks everyone
thanks for good answer.
Good luck to everyone.