fixed
This commit is contained in:
parent
7a048f8787
commit
f8dd7660ae
143 changed files with 74 additions and 248 deletions
|
@ -1,58 +0,0 @@
|
|||
#ifndef _PW_CHECK_H
|
||||
#define _PW_CHECK_H
|
||||
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.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)
|
||||
fprintf(stderr, "%s: Access denied\n", prog_name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *cpass = enc_password(prog_name, pass, NULL);
|
||||
if (cpass == NULL)
|
||||
return 1;
|
||||
|
||||
if (!strcmp(pw->pw_passwd, cpass))
|
||||
return 0;
|
||||
|
||||
if (prog_name != NULL)
|
||||
fprintf(stderr, "%s: Incorrect password\n", prog_name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue