infer fixes, clang build fixes, initial build on OSX

pull/435/head
Jacob Barthelmeh 2022-08-05 12:05:07 -06:00
parent f51375802b
commit 8f3cdc8230
5 changed files with 44 additions and 14 deletions

View File

@ -49,10 +49,14 @@
#ifndef _WIN32 #ifndef _WIN32
#include <sys/types.h> #include <sys/types.h>
#include <pwd.h> #include <pwd.h>
#include <shadow.h>
#include <errno.h> #include <errno.h>
#endif #endif
#if !defined(_WIN32) && !(defined(__OSX__) || defined(__APPLE__))
#include <shadow.h>
#define HAVE_SHADOW
#endif
struct WOLFSSHD_AUTH { struct WOLFSSHD_AUTH {
CallbackCheckUser CheckUserCb; CallbackCheckUser CheckUserCb;
CallbackCheckPassword CheckPasswordCb; CallbackCheckPassword CheckPasswordCb;
@ -289,7 +293,9 @@ static int CheckPasswordUnix(const char* usr, const byte* pw, word32 pwSz)
int ret = WS_SUCCESS; int ret = WS_SUCCESS;
char* pwStr = NULL; char* pwStr = NULL;
struct passwd* pwInfo; struct passwd* pwInfo;
#ifdef HAVE_SHADOW
struct spwd* shadowInfo; struct spwd* shadowInfo;
#endif
/* The hash of the user's password stored on the system. */ /* The hash of the user's password stored on the system. */
char* storedHash; char* storedHash;
char* storedHashCpy = NULL; char* storedHashCpy = NULL;
@ -318,6 +324,7 @@ static int CheckPasswordUnix(const char* usr, const byte* pw, word32 pwSz)
} }
if (ret == WS_SUCCESS) { if (ret == WS_SUCCESS) {
#ifdef HAVE_SHADOW
if (pwInfo->pw_passwd[0] == 'x') { if (pwInfo->pw_passwd[0] == 'x') {
#ifdef WOLFSSH_HAVE_LIBCRYPT #ifdef WOLFSSH_HAVE_LIBCRYPT
shadowInfo = getspnam((const char*)usr); shadowInfo = getspnam((const char*)usr);
@ -336,7 +343,9 @@ static int CheckPasswordUnix(const char* usr, const byte* pw, word32 pwSz)
storedHash = shadowInfo->sp_pwdp; storedHash = shadowInfo->sp_pwdp;
} }
} }
else { else
#endif
{
storedHash = pwInfo->pw_passwd; storedHash = pwInfo->pw_passwd;
} }
} }

View File

@ -275,11 +275,11 @@ static int HandleLoginGraceTime(WOLFSSHD_CONFIG* conf, const char* value)
} }
if (ret == WS_SUCCESS) { if (ret == WS_SUCCESS) {
num = GetConfigInt(value, XSTRLEN(value), 1, conf->heap); num = GetConfigInt(value, (int)XSTRLEN(value), 1, conf->heap);
if (num < 0) { if (num < 0) {
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Issue getting login grace " wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Issue getting login grace "
"time"); "time");
ret = num; ret = (int)num;
} }
else { else {
conf->loginTimer = num; conf->loginTimer = num;
@ -376,7 +376,7 @@ static int HandleProtocol(WOLFSSHD_CONFIG* conf, const char* value)
} }
if (ret == WS_SUCCESS) { if (ret == WS_SUCCESS) {
portInt = GetConfigInt(value, WSTRLEN(value), 0, conf->heap); portInt = GetConfigInt(value, (int)WSTRLEN(value), 0, conf->heap);
if (portInt <= 0) { if (portInt <= 0) {
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Invalid protocol number: %s.", wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Invalid protocol number: %s.",
value); value);
@ -405,7 +405,7 @@ static int HandlePort(WOLFSSHD_CONFIG* conf, const char* value)
} }
if (ret == WS_SUCCESS) { if (ret == WS_SUCCESS) {
portInt = GetConfigInt(value, WSTRLEN(value), 0, conf->heap); portInt = GetConfigInt(value, (int)WSTRLEN(value), 0, conf->heap);
if (portInt <= 0) { if (portInt <= 0) {
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Invalid port number: %s.", wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Invalid port number: %s.",
value); value);
@ -528,7 +528,7 @@ WOLFSSHD_STATIC int ParseConfigLine(WOLFSSHD_CONFIG* conf, const char* l,
int lSz) int lSz)
{ {
int ret = WS_BAD_ARGUMENT; int ret = WS_BAD_ARGUMENT;
int sz; int sz = 0;
char tmp[MAX_FILENAME_SZ]; char tmp[MAX_FILENAME_SZ];
int idx; int idx;
const CONFIG_OPTION* found = NULL; const CONFIG_OPTION* found = NULL;
@ -646,7 +646,7 @@ int wolfSSHD_ConfigSetAuthKeysFile(WOLFSSHD_CONFIG* conf, const char* file)
if (file != NULL) { if (file != NULL) {
ret = CreateString(&conf->authKeysFile, file, ret = CreateString(&conf->authKeysFile, file,
WSTRLEN(file), conf->heap); (int)WSTRLEN(file), conf->heap);
} }
} }
@ -691,7 +691,7 @@ int wolfSSHD_ConfigSetHostKeyFile(WOLFSSHD_CONFIG* conf, const char* file)
if (file != NULL) { if (file != NULL) {
ret = CreateString(&conf->hostKeyFile, file, ret = CreateString(&conf->hostKeyFile, file,
WSTRLEN(file), conf->heap); (int)WSTRLEN(file), conf->heap);
} }
} }

View File

@ -3,12 +3,26 @@
#include <wolfssh/ssh.h> #include <wolfssh/ssh.h>
#include <configuration.h> #include <configuration.h>
static void Log(const char* fmt, ...) #ifndef WOLFSSH_DEFAULT_LOG_WIDTH
#define WOLFSSH_DEFAULT_LOG_WIDTH 120
#endif
#undef FMTCHECK
#ifdef __GNUC__
#define FMTCHECK __attribute__((format(printf,1,2)))
#else
#define FMTCHECK
#endif /* __GNUC__ */
void Log(const char *const, ...) FMTCHECK;
void Log(const char *const fmt, ...)
{ {
va_list vlist; va_list vlist;
char msgStr[WOLFSSH_DEFAULT_LOG_WIDTH];
va_start(vlist, fmt); va_start(vlist, fmt);
vfprintf(stderr, fmt, vlist); WVSNPRINTF(msgStr, sizeof(msgStr), fmt, vlist);
va_end(vlist); va_end(vlist);
} }
@ -109,7 +123,7 @@ static int test_ParseConfigLine(void)
Log(" Testing scenario: %s.", vectors[i].desc); Log(" Testing scenario: %s.", vectors[i].desc);
ret = ParseConfigLine(conf, vectors[i].line, ret = ParseConfigLine(conf, vectors[i].line,
WSTRLEN(vectors[i].line)); (int)WSTRLEN(vectors[i].line));
if ((ret == WS_SUCCESS && !vectors[i].shouldFail) || if ((ret == WS_SUCCESS && !vectors[i].shouldFail) ||
(ret != WS_SUCCESS && vectors[i].shouldFail)) { (ret != WS_SUCCESS && vectors[i].shouldFail)) {

View File

@ -376,6 +376,10 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh)
byte channelBuffer[EXAMPLE_BUFFER_SZ]; byte channelBuffer[EXAMPLE_BUFFER_SZ];
userName = wolfSSH_GetUsername(ssh); userName = wolfSSH_GetUsername(ssh);
if (userName == NULL) {
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Failure get user name");
return WS_FATAL_ERROR;
}
/* temporarily elevate permissions to get users information */ /* temporarily elevate permissions to get users information */
if (wolfSSHD_AuthRaisePermissions(conn->auth) != WS_SUCCESS) { if (wolfSSHD_AuthRaisePermissions(conn->auth) != WS_SUCCESS) {
@ -597,7 +601,7 @@ static void* HandleConnection(void* arg)
graceTime = wolfSSHD_AuthGetGraceTime(conn->auth); graceTime = wolfSSHD_AuthGetGraceTime(conn->auth);
if (graceTime > 0) { if (graceTime > 0) {
signal(SIGALRM, alarmCatch); signal(SIGALRM, alarmCatch);
alarm(graceTime); alarm((unsigned int)graceTime);
} }
ret = wolfSSH_accept(ssh); ret = wolfSSH_accept(ssh);

View File

@ -272,6 +272,9 @@ if test "$ENABLED_SSHD" = "yes"; then
LIBS="$LIBS -llogin"], LIBS="$LIBS -llogin"],
[AC_MSG_ERROR(liblogin not found)]) [AC_MSG_ERROR(liblogin not found)])
;; ;;
*darwin*)
AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSH_HAVE_LIBCRYPT"
;;
*) *)
AC_CHECK_LIB([crypt], [crypt], AC_CHECK_LIB([crypt], [crypt],
[AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSH_HAVE_LIBCRYPT"; [AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSH_HAVE_LIBCRYPT";