From e05714ddc9a8041eaf5c2d172c9467e23b235f5b Mon Sep 17 00:00:00 2001 From: Alexander Naumov Date: Tue, 10 Oct 2023 19:55:43 +0200 Subject: [PATCH] build fix for not glibc systems (shadow.h) --- src/socket.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/socket.c b/src/socket.c index 9c5b8b9..5709a24 100644 --- a/src/socket.c +++ b/src/socket.c @@ -47,9 +47,13 @@ #include #if ENABLE_PAM -#include + #include #else -#include + #ifdef _PWD_H_ + #include + #else + #include + #endif /* PWD_H */ #endif #include "screen.h" @@ -1203,13 +1207,27 @@ 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"); @@ -1217,11 +1235,13 @@ static bool CheckPassword(const char *password) { 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 */