Operating System - HP-UX
1827439 Members
6149 Online
109965 Solutions
New Discussion

problems with programmatically executing usermod/userdel on 11.11

 
SOLVED
Go to solution
kellye bernecker_1
New Member

problems with programmatically executing usermod/userdel on 11.11

Hello everyone,

I am new to this forum, so please forgive me if I make any mistakes.

I am working on an application that performs account manipulation, such as useradd, userdel and the like. This application works great on 11.00, but I have some problems on 11.11 with the shadow password bundle. I am compiling on 11.00, for what it's worth.

I have no problems with the useradd command.

My application is getting an error when trying to execute usermod -g or usermod -s . The error is 15, which according to the man page for usermod indicates :
Cannot modify the entry in the /etc/passwd file.

The command actually does perform the action. When I check the /etc/passwd file, the group/shell has been changed as requested.

My application is also getting an error when trying to execute a userdel . The return code is 17, indicating:
Cannot delete entry from /etc/passwd file.

The entry DOES get deleted from the passwd file, but remains in /etc/shadow.

If I execute these commands from the command line, they work perfectly.

I installed patch PHCO_29269 in the hopes that it would help, but it did not.

I have written a small C program to test with, and have attached the source to this post. To execute it, I compile it as commandTest and type ./commandTest " ", for example, ./commandTest "userdel dummy". It's not a very fancy program, but it helps to illustrate my problem. This code is similar to the code in my application.

I appreciate your time.

Regards,

kellye
9 REPLIES 9
Jeff Schussele
Honored Contributor

Re: problems with programmatically executing usermod/userdel on 11.11

Hi Kellye,

Verify that there is no corruption in the passwd or group files - run
pwck & grpck
and fix any problems reported.
Also verify that you have *all* the pre-enablement as well as required patches for shadow - there were a lot of them IIRC.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
kellye bernecker_1
New Member

Re: problems with programmatically executing usermod/userdel on 11.11

Thanks, Jeff. I'll look into that.

Points forthcoming.

kellye
Sridhar Bhaskarla
Honored Contributor

Re: problems with programmatically executing usermod/userdel on 11.11

Hi Kellye,

Since your program does nothing but running the commands, I guess the problem is with the tcb database itself.

Do you get the same results if you run the command "userdel dummy" instead through the c-program?. If not, then you will need to follow Jeff's suggestions.

I infact compiled your program onto my workstation and ran it. It worked just fine. My workstation is with June 2003 bundles.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Tom Danzig
Honored Contributor

Re: problems with programmatically executing usermod/userdel on 11.11

Also make sure the user you are trying to modify or delete is not logged in. These commands will fail if they are. This is consistant with what you are seeing (useradd works fine).

Just a thought.
kellye bernecker_1
New Member

Re: problems with programmatically executing usermod/userdel on 11.11

Sri,

When I manually run the commands, they work perfectly. The only time I have a problem is when I execute them from my program.

I'm currently investigating which patches I need and which ones I'm missing.

Thanks,

kellye
kellye bernecker_1
New Member

Re: problems with programmatically executing usermod/userdel on 11.11

Tom,

I'm sequentially creating the user, modifying the user then deleting the user (programmatically), so having the user logged in shouldn't be a problem. I'm currently the only person using this particular machine.

Thanks,

kellye
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: problems with programmatically executing usermod/userdel on 11.11

Because this is working from the command line, I suspect that the commands are failing because of your popen() and problems with stderr redirection. I suggest that you use the system() function instead using sprintf to buld up as complex a command as you like and making sure to redirect stdout and stderr to separate temp files.
If it ain't broke, I can fix that.
kellye bernecker_1
New Member

Re: problems with programmatically executing usermod/userdel on 11.11

Clay,

You hit it on the head, when I modified the program to use system() instead of popen(), all of the calls worked.

My question now has to be why would these calls work with popen() on 11.00 and have a problem on 11.11. Is it due to the shadow file somehow?

Thanks!

kellye

A. Clay Stephenson
Acclaimed Contributor

Re: problems with programmatically executing usermod/userdel on 11.11

I doubt that there are fundamental differences in the popen()/pclose() functions in 11.11 but rather that the usermod et al commands are a little different in their use of stderr. I would capture the stdout/stderr files from the system() function and compare them across the OS releases. Handling stderr is something you always have to be aware of in any popen() command.
If it ain't broke, I can fix that.