diff --git a/apps/wolfsshd/auth.c b/apps/wolfsshd/auth.c index 2205680e..26918f9a 100644 --- a/apps/wolfsshd/auth.c +++ b/apps/wolfsshd/auth.c @@ -49,10 +49,14 @@ #ifndef _WIN32 #include #include -#include #include #endif +#if !defined(_WIN32) && !(defined(__OSX__) || defined(__APPLE__)) +#include +#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; } } diff --git a/apps/wolfsshd/configuration.c b/apps/wolfsshd/configuration.c index 181fdb86..73be8063 100644 --- a/apps/wolfsshd/configuration.c +++ b/apps/wolfsshd/configuration.c @@ -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); } } diff --git a/apps/wolfsshd/test/test_configuration.c b/apps/wolfsshd/test/test_configuration.c index c671803c..4b1fe5b7 100644 --- a/apps/wolfsshd/test/test_configuration.c +++ b/apps/wolfsshd/test/test_configuration.c @@ -3,12 +3,26 @@ #include #include -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)) { diff --git a/apps/wolfsshd/wolfsshd.c b/apps/wolfsshd/wolfsshd.c index 21daeebf..8a21c3e5 100644 --- a/apps/wolfsshd/wolfsshd.c +++ b/apps/wolfsshd/wolfsshd.c @@ -376,10 +376,14 @@ 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) { - wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Failure to raise permissions for auth"); + wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Failure to raise permissions for auth"); return WS_FATAL_ERROR; } @@ -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); diff --git a/configure.ac b/configure.ac index 200ba7ff..7b11c829 100644 --- a/configure.ac +++ b/configure.ac @@ -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";