@license BSD 2-clause License
*/
#include "util.h"
+#include <sys/ioctl.h>
#include <unistd.h>
#include <pwd.h>
+#include <grp.h>
#include <shadow.h>
-#include <sys/ioctl.h>
#define ENV_PATH "/bin"
}
static struct passwd* check_pass(const char* user, char* pass) {
- struct spwd* spw;
+ struct spwd* spw = NULL;
/* get the passwd entry */
struct passwd* pwentry = getpwnam(user);
if (!pwentry || errno)
}
/* Handle blank pass or blank pass entry */
if ((pwentry->pw_passwd[0] == '\0') || (pass[0] == '\0')) {
- warn("incorrect password\n");
+ warn("blank passwords are not allowed\n");
return NULL;
}
/* Get the shadow entry */
errno = 0;
spw = getspnam(pwentry->pw_name);
if (!spw || errno)
- die("could not retrieve shadow entry for %s", user);
+ die("could not retrieve shadow entry for %s: %s", pwentry->pw_name, errnostr());
if (spw->sp_pwdp[0] == '!' || spw->sp_pwdp[0] == '*') {
warn("access denied\n");
return NULL;
}
+
}
/* Check the password */
- char* cryptpass = crypt(pass, spw->sp_pwdp);
- if (strcmp(cryptpass, spw->sp_pwdp) != 0) {
+ char* refpass = (spw ? spw->sp_pwdp : pwentry->pw_passwd);
+ char* cryptpass = crypt(pass, refpass);
+ if (strcmp(cryptpass, refpass) != 0) {
warn("incorrect password");
return NULL;
}