- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Changing user's password programmatically
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2001 11:42 PM
07-01-2001 11:42 PM
I'm trying to write small C code to change the user's password automatically using getpwent(3C), crypt(3C) and then putpwent(3C) ... actually "Clay" has guided me to use these function calls sometime back..
now i have a question, The "salt" value in crypt function "second argument", on which base i choose this value?
Thanks
Ahmed
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2001 12:04 AM
07-02-2001 12:04 AM
SolutionThe salt is a two caracters word which is a
crypt argument. You can use random to
calcultate each letter.
This salt is use to be a key for crypt function
After crypt a password you can see that salt
is on the two first signs of the passwd 13
caracters.
HTH
Herv?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2001 12:17 AM
07-02-2001 12:17 AM
Re: Changing user's password programmatically
So it is up to me to choose the "salt" value, great...
i have tried this and i got the 13 characters output, which starts with "My_2_Salt_Characters".. then i replaced the password entry for one account with the new password... when i tried to login i had login incorrect.
Is there anything missing of the procedure i described: -
1- getpwnam
2- crypt
3- putpwent
thanks,
Ahmed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2001 12:41 AM
07-02-2001 12:41 AM
Re: Changing user's password programmatically
I try that :
1) getpwnam
2) crypt new passwd with a salt
3) putpwent
4) try to login : works well !!!
Look at this small piece of code :
---- CUT HERE -----
#include
#include
main ()
{
struct passwd * my_pwstr;
char * new_pwd;
/* You need to open you passwd file for update */
FILE *pwfile = fopen ("/etc/passwd","r+");
my_pwstr = getpwnam ("cg");
printf ("\nEncrypted passwd : %s\n",my_pwstr ->pw_passwd);
new_pwd = crypt ("azerty","q2"); /* new pwd is "azerty" and salt is "q2" */
printf ("New encrypted passwd : %s\n",new_pwd);
strcpy (my_pwstr->pw_passwd, new_pwd);
putpwent (my_pwstr,pwfile);
fclose (pwfile);
}
----- CUT HERE ------
I made no control on file opening and other error
but it works well. You just need to add a
function to calculate your salt.
Good luck
Herv?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2001 12:50 AM
07-02-2001 12:50 AM
Re: Changing user's password programmatically
Ahmed
I just see something : Clay and, now, I help
you... don't forget to assign points to our
reply if we help you.
An information : I don't know where you get new
password. Don't forget that you can't take
passwd field gave by getpwnam : it is encrypted
You need to use a new one not encrypted.
Herv?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2001 01:07 AM
07-02-2001 01:07 AM
Re: Changing user's password programmatically
my code is almost typical of what you did the difference is that i'm getting the username and the new password from the command line.
it is not only the problem that i can't login but the user home directory got corrupted after i apply the crypt call this in case the old password is NULL "means that no characters between the two':' in /etc/passwd!!!
i'm attaching my code as well...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2001 01:08 AM
07-02-2001 01:08 AM
Re: Changing user's password programmatically
Thanks, again
Ahmed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2001 01:19 AM
07-02-2001 01:19 AM
Re: Changing user's password programmatically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2001 01:40 AM
07-02-2001 01:40 AM
Re: Changing user's password programmatically
When the password has less than 13 characters value the amount of memory allocated will be less than 13 characters so unpredicted results will occure,
To solve this we need to malloc or realloc 13 characters of memory and return the pointer to pw_passwd..
It works fine now...
Thanks and i will assign the points right now..
Ahmed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2001 01:48 AM
07-02-2001 01:48 AM
Re: Changing user's password programmatically
It seems to work well now but have a look to
your passwd file : when you use putpwent you
add a new line on passwd file.
The problem is that if you have two lines the
first is read and not the others and it seems
that the first is the old one.
I made modification in your program (using grep
in the system call) to delete all "user" lines
when copying /etc/passwd to /tmp/passwd.
I join the file...
Bye
Herv?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2001 02:03 AM
07-02-2001 02:03 AM
Re: Changing user's password programmatically
Another information :
return of crypt () is ALWAYS 13 caracters
you can crypt 1 to 8 caracters and the result
is 2 + 11 caracters (salt + encrypted form).
So you have exactly 13 caracters in pw_passwd.
Herv?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2001 03:13 AM
07-02-2001 03:13 AM
Re: Changing user's password programmatically
Yea, actually my program is not in the final state ... i know i have to remove the old entry before updating by the new one .. also i need to check for the /etc/passwd file after updating to check whether there is errors or not ....
thank you again for ur help :-)
Ahmed