Created
May 27, 2011 06:00
-
-
Save gyuchang/994726 to your computer and use it in GitHub Desktop.
chkpasswd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| #include <unistd.h> | |
| #include <crypt.h> | |
| #include <stdio.h> | |
| #include <shadow.h> | |
| int main (int argc, char *argv[]) { | |
| char *plain_passwd; | |
| char *crypt_passwd; | |
| char *username; | |
| struct spwd *shadow; | |
| if (argc != 2) { | |
| exit(-1); | |
| } | |
| username = argv[1]; | |
| plain_passwd = getpass("password:"); | |
| if ((shadow = getspnam(username)) == NULL) { | |
| exit(-1); | |
| } | |
| crypt_passwd = shadow->sp_pwdp; | |
| exit(strcmp(crypt(plain_passwd, crypt_passwd), crypt_passwd)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| all: chkpasswd.c | |
| gcc -o chkpasswd -l crypt chkpasswd.c | |
| install: all | |
| install -s -m 4755 chkpasswd /usr/local/bin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment