fixed pw_check, cryptpw
This commit is contained in:
parent
1925d32c40
commit
ff94d81541
5 changed files with 29 additions and 43 deletions
|
@ -5,48 +5,29 @@
|
|||
#include "pw_check.h"
|
||||
#include "config.h"
|
||||
|
||||
void dec_salt(void) {
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof(MU_SALT_ENC) / sizeof(int); i++)
|
||||
MU_SALT_BUF[i] = (char)MU_SALT_ENC[i];
|
||||
|
||||
MU_SALT_BUF[i + 1] = '\0';
|
||||
}
|
||||
|
||||
char *enc_password(const char *prog_name, const char *pass, const char *salt) {
|
||||
if (salt == NULL)
|
||||
dec_salt();
|
||||
|
||||
char *cpass = crypt(pass, (salt == NULL) ? MU_SALT_BUF : salt);
|
||||
if (cpass == NULL) {
|
||||
if (prog_name != NULL)
|
||||
fprintf(stderr, "%s: %s\n", prog_name, strerror(errno));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return cpass;
|
||||
}
|
||||
|
||||
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)
|
||||
if (prog_name)
|
||||
fprintf(stderr, "%s: Access denied\n", prog_name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *cpass = enc_password(prog_name, pass, NULL);
|
||||
if (cpass == NULL)
|
||||
char *cpass = crypt(pass, pw->pw_passwd);
|
||||
if (cpass == NULL) {
|
||||
if (prog_name)
|
||||
fprintf(stderr, "%s: crypt: %s\n", prog_name, strerror(errno));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!strcmp(pw->pw_passwd, cpass))
|
||||
return 0;
|
||||
|
||||
if (prog_name != NULL)
|
||||
if (prog_name)
|
||||
fprintf(stderr, "%s: Incorrect password\n", prog_name);
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -2,8 +2,5 @@
|
|||
#define _PW_CHECK_H
|
||||
#include <pwd.h>
|
||||
|
||||
void dec_salt(void);
|
||||
char *enc_password(const char *prog_name, const char *pass, const char *salt);
|
||||
int pw_check(const char *prog_name, const struct passwd *pw, const char *pass);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue