Skip to content

Commit

Permalink
build fix for not glibc systems (shadow.h)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-naumov committed Aug 5, 2024
1 parent e6ec507 commit e05714d
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@
#include <signal.h>

#if ENABLE_PAM
#include <security/pam_appl.h>
#include <security/pam_appl.h>
#else
#include <shadow.h>
#ifdef _PWD_H_
#include <pwd.h>
#else
#include <shadow.h>
#endif /* PWD_H */
#endif

#include "screen.h"
Expand Down Expand Up @@ -1203,25 +1207,41 @@ static bool CheckPassword(const char *password) {
static bool CheckPassword(const char *password) {
bool ret = false;
char *passwd = 0;

#ifndef _PWD_H
struct passwd *p;
#else
struct spwd *p;
#endif

gid_t gid = getegid();
uid_t uid = geteuid();

if (seteuid(0) || setegid(0))
Panic(0, "\r\ncan't get root uid/gid\r\n");

#ifndef _PWD_H
p = getpwnam_shadow(ppp->pw_name);
#else
p = getspnam(ppp->pw_name);
#endif
if (p == NULL)
return false;

if (seteuid(uid) || setegid(gid))
Panic(0, "\r\ncan't restore uid/gid\r\n");

if (p == NULL) {
AddStr("\r\ncan't open passwd file\r\n");
return false;
}

#ifndef _PWD_H
passwd = crypt(password, p->pw_passwd);
ret = (strcmp(passwd, p->pw_passwd) == 0);
#else
passwd = crypt(password, p->sp_pwdp);

ret = (strcmp(passwd, p->sp_pwdp) == 0);

#endif
return ret;
}
#endif /* ENABLE_PAM */
Expand Down

0 comments on commit e05714d

Please sign in to comment.