2014-06-05 07:48:45 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2014-06-30 14:03:41 -04:00
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2014-06-09 05:51:02 -04:00
|
|
|
#include <errno.h>
|
2014-06-05 07:48:45 -04:00
|
|
|
#include <pwd.h>
|
2014-06-09 05:51:02 -04:00
|
|
|
#include <shadow.h>
|
2014-06-05 07:48:45 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-06-09 05:51:02 -04:00
|
|
|
#include <unistd.h>
|
2014-06-30 14:03:41 -04:00
|
|
|
|
2014-06-09 05:51:02 -04:00
|
|
|
#include "../passwd.h"
|
2014-06-05 07:48:45 -04:00
|
|
|
#include "../text.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2014-06-09 07:58:40 -04:00
|
|
|
/* Returns -1 on error, 0 for incorrect password
|
|
|
|
* and 1 if all went OK */
|
2014-06-09 05:51:02 -04:00
|
|
|
int
|
2014-07-13 15:55:46 -04:00
|
|
|
pw_check(const struct passwd *pw, const char *pass)
|
2014-06-09 05:51:02 -04:00
|
|
|
{
|
|
|
|
char *cryptpass, *p;
|
|
|
|
struct spwd *spw;
|
|
|
|
|
|
|
|
p = pw->pw_passwd;
|
2014-06-09 07:58:40 -04:00
|
|
|
if (p[0] == '!' || p[0] == '*') {
|
|
|
|
weprintf("denied\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-06-09 05:51:02 -04:00
|
|
|
|
2014-06-09 08:03:19 -04:00
|
|
|
if (pw->pw_passwd[0] == '\0') {
|
|
|
|
if (pass[0] == '\0')
|
|
|
|
return 1;
|
|
|
|
weprintf("incorrect password\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2014-06-09 05:51:02 -04:00
|
|
|
|
|
|
|
if (pw->pw_passwd[0] == 'x' && pw->pw_passwd[1] == '\0') {
|
|
|
|
errno = 0;
|
|
|
|
spw = getspnam(pw->pw_name);
|
2014-07-09 10:08:09 -04:00
|
|
|
if (!spw) {
|
|
|
|
if (errno)
|
|
|
|
weprintf("getspnam: %s:", pw->pw_name);
|
|
|
|
else
|
|
|
|
weprintf("who are you?\n");
|
2014-06-09 07:58:40 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-09 05:51:02 -04:00
|
|
|
p = spw->sp_pwdp;
|
2014-06-09 07:58:40 -04:00
|
|
|
if (p[0] == '!' || p[0] == '*') {
|
|
|
|
weprintf("denied\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-06-09 05:51:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
cryptpass = crypt(pass, p);
|
2014-06-09 07:58:40 -04:00
|
|
|
if (!cryptpass) {
|
|
|
|
weprintf("crypt:");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (strcmp(cryptpass, p) != 0) {
|
|
|
|
weprintf("incorrect password\n");
|
2014-06-09 05:51:02 -04:00
|
|
|
return 0;
|
2014-06-09 07:58:40 -04:00
|
|
|
}
|
2014-06-09 05:51:02 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-06-10 06:38:45 -04:00
|
|
|
int
|
|
|
|
pw_init(void)
|
|
|
|
{
|
|
|
|
struct rlimit rlim;
|
|
|
|
|
|
|
|
rlim.rlim_cur = 0;
|
|
|
|
rlim.rlim_max = 0;
|
|
|
|
if (setrlimit(RLIMIT_CORE, &rlim) < 0)
|
|
|
|
eprintf("setrlimit:");
|
|
|
|
return 0;
|
|
|
|
}
|