Witam
W trakcie kompilacji poniższego programu za pomocą gcc pojawiają się dwa ostrzeżenia
checkpass.c: In function ‘main’:
checkpass.c:31: warning: cast to pointer from integer of different size
checkpass.c:36: warning: cast to pointer from integer of different size
Niestety jestem początkującym i nie bardzo wiem, jak sobie z tym poradzić. Wiem tylko tyle, że w we wspomnianych linijkach musiałem popełnić jakiś bląd, ponieważ program po kompilacji wyświetla komunikat blędu: segmetation fault.
Kod php:
/*
* getpw* no longer returns an encrypted password.
*
* Compile with: gcc checkpass.c -o checkpass
* Run with: ./checkpass
*/
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
const char *user = NULL;
struct passwd *pwd;
/* Set the username if it was supplied on the command
,* line. Bail out if we don 't end up with a username.
*/
if (argc == 2)
user = argv[1];
if(!user)
{
fprintf(stderr, "Usage: checkpass <username>\n");
exit(1);
}
/* Fetch to password entry. */
if (pwd = getpwnam(user))
{
char *password = (char *) getpass("Enter your password:");
/* Encrypt the password using the encrypted passsword as salt.
* See crypt(3) for complete details.
*/
char *crypted = (char *) crypt(password, pwd->pw_passwd);
/* Are the two encrypted passwords identical? */
if (strcmp(pwd->pw_passwd, crypted) == 0)
printf("Success.\n");
else
{
printf("Bad password: %s != %s\n", pwd->pw_passwd, crypted);
return 1;
}
}
else
{
fprintf(stderr, "Could not find password for %s.\n", user);
return 1;
}
return 0;
}