29 lines
549 B
C
29 lines
549 B
C
#ifndef _PW_CHECK_H
|
|
#define _PW_CHECK_H
|
|
|
|
#include <pwd.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
int pw_check(const char *prog_name, const struct passwd *pw, const char *pass) {
|
|
if (pw->pw_passwd[0] == '\0' && pass[0] == '\0')
|
|
return 0;
|
|
|
|
if (pw->pw_passwd[0] == '!' || pw->pw_passwd[0] == '*') {
|
|
if (prog_name != NULL)
|
|
fprintf(stderr, "%s: Access denied\n", prog_name);
|
|
|
|
return 1;
|
|
}
|
|
|
|
if (!strcmp(pass, pw->pw_passwd))
|
|
return 0;
|
|
|
|
if (prog_name != NULL)
|
|
fprintf(stderr, "%s: Incorrect password\n", prog_name);
|
|
|
|
return 1;
|
|
}
|
|
|
|
#endif
|