Bvm 18
asked on
crypt() api returning NULL
Hi all,
In C,
crypt(userpassword, etc-password) always returning NULL in other application.
In my simple test application, working fine.
What could be the reason? How to fix this?
Thanks,
Bvm
In C,
crypt(userpassword, etc-password) always returning NULL in other application.
In my simple test application, working fine.
What could be the reason? How to fix this?
Thanks,
Bvm
Provide your entire source file + build command sequence.
https://serverfault.com/qu estions/33 0069/how-t o-create-a n-sha-512- hashed-pas sword-for- shadow provides... what looks to be... a working example of calling crypt() correctly.
Have you confirmed the data being passed into crypt is actually valid? Check errno as this is set when crypt fails. It will tell you why.
ASKER
Arguments to crypt() function is correct. crypt() api returning NULL. In which cases, it would return NULL.
How to get the errno if crypt returns NULL
How to get the errno if crypt returns NULL
http://man7.org/linux/man-pages/man3/errno.3.html
"The <errno.h> header file defines the integer variable errno, which is set by system calls and some library functions in the event of an error to indicate what went wrong."
"The <errno.h> header file defines the integer variable errno, which is set by system calls and some library functions in the event of an error to indicate what went wrong."
You really want to print the textual representation of errno
#include <stdio.h>
#include <errno.h>
...
perror("crypt")
...
or, fancier but more informative
#include <stdio.h>
#include <errno.h>
#include <string.h>
...
fprintf(stderr, "%s. key=\"%s\", salt=\"%s\" (crypt)\n", strerror(errno), key, salt);
...
Substitute the variable names you use for key and salt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.