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

View File

@ -275,11 +275,11 @@ static int HandleLoginGraceTime(WOLFSSHD_CONFIG* conf, const char* value)
}
if (ret == WS_SUCCESS) {
num = GetConfigInt(value, XSTRLEN(value), 1, conf->heap);
num = GetConfigInt(value, (int)XSTRLEN(value), 1, conf->heap);
if (num < 0) {
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Issue getting login grace "
"time");
ret = num;
ret = (int)num;
}
else {
conf->loginTimer = num;
@ -376,7 +376,7 @@ static int HandleProtocol(WOLFSSHD_CONFIG* conf, const char* value)
}
if (ret == WS_SUCCESS) {
portInt = GetConfigInt(value, WSTRLEN(value), 0, conf->heap);
portInt = GetConfigInt(value, (int)WSTRLEN(value), 0, conf->heap);
if (portInt <= 0) {
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Invalid protocol number: %s.",
value);
@ -405,7 +405,7 @@ static int HandlePort(WOLFSSHD_CONFIG* conf, const char* value)
}
if (ret == WS_SUCCESS) {
portInt = GetConfigInt(value, WSTRLEN(value), 0, conf->heap);
portInt = GetConfigInt(value, (int)WSTRLEN(value), 0, conf->heap);
if (portInt <= 0) {
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Invalid port number: %s.",
value);
@ -528,7 +528,7 @@ WOLFSSHD_STATIC int ParseConfigLine(WOLFSSHD_CONFIG* conf, const char* l,
int lSz)
{
int ret = WS_BAD_ARGUMENT;
int sz;
int sz = 0;
char tmp[MAX_FILENAME_SZ];
int idx;
const CONFIG_OPTION* found = NULL;
@ -646,7 +646,7 @@ int wolfSSHD_ConfigSetAuthKeysFile(WOLFSSHD_CONFIG* conf, const char* file)
if (file != NULL) {
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) {
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 <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;
char msgStr[WOLFSSH_DEFAULT_LOG_WIDTH];
va_start(vlist, fmt);
vfprintf(stderr, fmt, vlist);
WVSNPRINTF(msgStr, sizeof(msgStr), fmt, vlist);
va_end(vlist);
}
@ -109,7 +123,7 @@ static int test_ParseConfigLine(void)
Log(" Testing scenario: %s.", vectors[i].desc);
ret = ParseConfigLine(conf, vectors[i].line,
WSTRLEN(vectors[i].line));
(int)WSTRLEN(vectors[i].line));
if ((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];
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 */
if (wolfSSHD_AuthRaisePermissions(conn->auth) != WS_SUCCESS) {
@ -597,7 +601,7 @@ static void* HandleConnection(void* arg)
graceTime = wolfSSHD_AuthGetGraceTime(conn->auth);
if (graceTime > 0) {
signal(SIGALRM, alarmCatch);
alarm(graceTime);
alarm((unsigned int)graceTime);
}
ret = wolfSSH_accept(ssh);

View File

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