From a4d19de2d456ef8b03e8b02998b3f60578b60bf6 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Fri, 18 Oct 2024 14:50:56 +0100 Subject: [PATCH] Use C90 with no extensions --- CMakeLists.txt | 4 +++- src/crypt_openssl.c | 6 ++--- src/ntlm.c | 38 ++++++++++++++--------------- src/unicode_builtin.c | 5 ++-- src/unicode_iconv.c | 3 ++- src/utf8.h | 56 ++++++++++++++++++++++--------------------- src/util.h | 8 +++++++ tests/inputs.c | 8 +++---- 8 files changed, 71 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3486190..b3e3116 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,7 +131,7 @@ ELSE() MESSAGE(FATAL_ERROR "invalid cryptographic support requested: ${CRYPT}") ENDIF() -SET(CMAKE_C_FLAGS "-std=gnu99 -D_DEFAULT_SOURCE") +SET(CMAKE_C_FLAGS "-D_DEFAULT_SOURCE") ENABLE_WARNINGS(all) ENABLE_WARNINGS(extra) @@ -179,6 +179,8 @@ IF(BUILD_LIBRARY) SET_PROPERTY(TARGET ntlmclient PROPERTY POSITION_INDEPENDENT_CODE 1) ADD_LIBRARY(ntlmclient_shared SHARED $) + SET_TARGET_PROPERTIES(ntlmclient_shared PROPERTIES C_STANDARD 90) + SET_TARGET_PROPERTIES(ntlmclient_shared PROPERTIES C_EXTENSIONS OFF) SET_TARGET_PROPERTIES(ntlmclient_shared PROPERTIES OUTPUT_NAME ntlmclient) SET_TARGET_PROPERTIES(ntlmclient_shared PROPERTIES VERSION ${NTLM_VERSION}) SET_TARGET_PROPERTIES(ntlmclient_shared PROPERTIES SOVERSION ${NTLM_SOVERSION}) diff --git a/src/crypt_openssl.c b/src/crypt_openssl.c index c4be129..7d757f6 100644 --- a/src/crypt_openssl.c +++ b/src/crypt_openssl.c @@ -26,18 +26,18 @@ #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(CRYPT_OPENSSL_DYNAMIC) -static inline HMAC_CTX *HMAC_CTX_new(void) +NTLM_INLINE(HMAC_CTX *) HMAC_CTX_new(void) { return calloc(1, sizeof(HMAC_CTX)); } -static inline int HMAC_CTX_reset(HMAC_CTX *ctx) +NTLM_INLINE(int) HMAC_CTX_reset(HMAC_CTX *ctx) { ntlm_memzero(ctx, sizeof(HMAC_CTX)); return 1; } -static inline void HMAC_CTX_free(HMAC_CTX *ctx) +NTLM_INLINE(void) HMAC_CTX_free(HMAC_CTX *ctx) { free(ctx); } diff --git a/src/ntlm.c b/src/ntlm.c index ad4de5d..44421f5 100644 --- a/src/ntlm.c +++ b/src/ntlm.c @@ -43,7 +43,7 @@ static bool supports_unicode(ntlm_client *ntlm) false : true; } -static inline bool increment_size(size_t *out, size_t incr) +NTLM_INLINE(bool) increment_size(size_t *out, size_t incr) { if (SIZE_MAX - *out < incr) { *out = (size_t)-1; @@ -272,7 +272,7 @@ int ntlm_client_set_timestamp(ntlm_client *ntlm, uint64_t timestamp) return 0; } -static inline bool write_buf( +NTLM_INLINE(bool) write_buf( ntlm_client *ntlm, ntlm_buf *out, const unsigned char *buf, @@ -291,7 +291,7 @@ static inline bool write_buf( return true; } -static inline bool write_byte( +NTLM_INLINE(bool) write_byte( ntlm_client *ntlm, ntlm_buf *out, uint8_t value) @@ -305,7 +305,7 @@ static inline bool write_byte( return true; } -static inline bool write_int16( +NTLM_INLINE(bool) write_int16( ntlm_client *ntlm, ntlm_buf *out, uint16_t value) @@ -320,7 +320,7 @@ static inline bool write_int16( return true; } -static inline bool write_int32( +NTLM_INLINE(bool) write_int32( ntlm_client *ntlm, ntlm_buf *out, uint32_t value) @@ -337,7 +337,7 @@ static inline bool write_int32( return true; } -static inline bool write_version( +NTLM_INLINE(bool) write_version( ntlm_client *ntlm, ntlm_buf *out, ntlm_version *version) @@ -348,7 +348,7 @@ static inline bool write_version( write_int32(ntlm, out, version->reserved); } -static inline bool write_bufinfo( +NTLM_INLINE(bool) write_bufinfo( ntlm_client *ntlm, ntlm_buf *out, size_t len, @@ -369,7 +369,7 @@ static inline bool write_bufinfo( write_int32(ntlm, out, (uint32_t)offset); } -static inline bool read_buf( +NTLM_INLINE(bool) read_buf( unsigned char *out, ntlm_client *ntlm, ntlm_buf *message, @@ -386,7 +386,7 @@ static inline bool read_buf( return true; } -static inline bool read_byte( +NTLM_INLINE(bool) read_byte( uint8_t *out, ntlm_client *ntlm, ntlm_buf *message) @@ -400,7 +400,7 @@ static inline bool read_byte( return true; } -static inline bool read_int16( +NTLM_INLINE(bool) read_int16( uint16_t *out, ntlm_client *ntlm, ntlm_buf *message) @@ -418,7 +418,7 @@ static inline bool read_int16( return true; } -static inline bool read_int32( +NTLM_INLINE(bool) read_int32( uint32_t *out, ntlm_client *ntlm, ntlm_buf *message) @@ -438,7 +438,7 @@ static inline bool read_int32( return true; } -static inline bool read_int64( +NTLM_INLINE(bool) read_int64( uint64_t *out, ntlm_client *ntlm, ntlm_buf *message) @@ -462,7 +462,7 @@ static inline bool read_int64( return true; } -static inline bool read_version( +NTLM_INLINE(bool) read_version( ntlm_version *out, ntlm_client *ntlm, ntlm_buf *message) @@ -473,7 +473,7 @@ static inline bool read_version( read_int32(&out->reserved, ntlm, message); } -static inline bool read_bufinfo( +NTLM_INLINE(bool) read_bufinfo( uint16_t *out_len, uint32_t *out_offset, ntlm_client *ntlm, @@ -486,7 +486,7 @@ static inline bool read_bufinfo( read_int32(out_offset, ntlm, message); } -static inline bool read_string_unicode( +NTLM_INLINE(bool) read_string_unicode( char **out, ntlm_client *ntlm, ntlm_buf *message, @@ -504,7 +504,7 @@ static inline bool read_string_unicode( return ret; } -static inline bool read_string_ascii( +NTLM_INLINE(bool) read_string_ascii( char **out, ntlm_client *ntlm, ntlm_buf *message, @@ -526,7 +526,7 @@ static inline bool read_string_ascii( return true; } -static inline bool read_string( +NTLM_INLINE(bool) read_string( char **out, ntlm_client *ntlm, ntlm_buf *message, @@ -539,7 +539,7 @@ static inline bool read_string( return read_string_ascii(out, ntlm, message, string_len); } -static inline bool read_target_info( +NTLM_INLINE(bool) read_target_info( char **server_out, char **domain_out, char **server_dns_out, @@ -965,7 +965,7 @@ static void des_key_from_password( generate_odd_parity(out); } -static inline bool generate_lm_hash( +NTLM_INLINE(bool) generate_lm_hash( ntlm_des_block out[2], ntlm_client *ntlm, const char *password) diff --git a/src/unicode_builtin.c b/src/unicode_builtin.c index 6d398b7..cb98f70 100644 --- a/src/unicode_builtin.c +++ b/src/unicode_builtin.c @@ -12,6 +12,7 @@ #include "ntlm.h" #include "unicode.h" #include "compat.h" +#include "util.h" typedef unsigned int UTF32; /* at least 32 bits */ typedef unsigned short UTF16; /* at least 16 bits */ @@ -180,7 +181,7 @@ static ConversionResult ConvertUTF16toUTF8 ( * definition of UTF-8 goes up to 4-byte sequences. */ -static inline bool isLegalUTF8(const UTF8 *source, int length) { +NTLM_INLINE(bool) isLegalUTF8(const UTF8 *source, int length) { UTF8 a; const UTF8 *srcptr = source+length; switch (length) { @@ -288,7 +289,7 @@ typedef enum { unicode_builtin_utf16_to_8 } unicode_builtin_encoding_direction; -static inline bool unicode_builtin_encoding_convert( +NTLM_INLINE(bool) unicode_builtin_encoding_convert( char **converted, size_t *converted_len, ntlm_client *ntlm, diff --git a/src/unicode_iconv.c b/src/unicode_iconv.c index e14da21..ac53638 100644 --- a/src/unicode_iconv.c +++ b/src/unicode_iconv.c @@ -14,6 +14,7 @@ #include "ntlmclient.h" #include "unicode.h" #include "ntlm.h" +#include "util.h" #include "compat.h" typedef enum { @@ -40,7 +41,7 @@ bool ntlm_unicode_init(ntlm_client *ntlm) return true; } -static inline bool unicode_iconv_encoding_convert( +NTLM_INLINE(bool) unicode_iconv_encoding_convert( char **converted, size_t *converted_len, ntlm_client *ntlm, diff --git a/src/utf8.h b/src/utf8.h index a26ae85..dd0bce8 100644 --- a/src/utf8.h +++ b/src/utf8.h @@ -1,30 +1,32 @@ -// The latest version of this library is available on GitHub; -// https://github.com/sheredom/utf8.h - -// This is free and unencumbered software released into the public domain. -// -// Anyone is free to copy, modify, publish, use, compile, sell, or -// distribute this software, either in source code form or as a compiled -// binary, for any purpose, commercial or non-commercial, and by any -// means. -// -// In jurisdictions that recognize copyright laws, the author or authors -// of this software dedicate any and all copyright interest in the -// software to the public domain. We make this dedication for the benefit -// of the public at large and to the detriment of our heirs and -// successors. We intend this dedication to be an overt act of -// relinquishment in perpetuity of all present and future rights to this -// software under copyright law. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// For more information, please refer to +/* + * The latest version of this library is available on GitHub; + * https://github.com/sheredom/utf8.h + * + * This is free and unencumbered software released into the public domain. + * + * Anyone is free to copy, modify, publish, use, compile, sell, or + * distribute this software, either in source code form or as a compiled + * binary, for any purpose, commercial or non-commercial, and by any + * means. + * + * In jurisdictions that recognize copyright laws, the author or authors + * of this software dedicate any and all copyright interest in the + * software to the public domain. We make this dedication for the benefit + * of the public at large and to the detriment of our heirs and + * successors. We intend this dedication to be an overt act of + * relinquishment in perpetuity of all present and future rights to this + * software under copyright law. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * For more information, please refer to + */ #ifndef SHEREDOM_UTF8_H_INCLUDED #define SHEREDOM_UTF8_H_INCLUDED diff --git a/src/util.h b/src/util.h index 70cf294..48e0169 100644 --- a/src/util.h +++ b/src/util.h @@ -12,6 +12,14 @@ #include #include +#if defined(_MSC_VER) +# define NTLM_INLINE(type) static __inline type +#elif defined(__GNUC__) +# define NTLM_INLINE(type) static __inline__ type +#else +# define NTLM_INLINE(type) static type +#endif + extern void ntlm_memzero(void *data, size_t size); extern uint64_t ntlm_htonll(uint64_t value); diff --git a/tests/inputs.c b/tests/inputs.c index 7178877..3db1367 100644 --- a/tests/inputs.c +++ b/tests/inputs.c @@ -69,15 +69,15 @@ void test_inputs__set_credentials(void) void test_inputs__set_credentials_unicode(void) { - cl_must_pass(ntlm_client_set_credentials(ntlm, "us\u00e9r", "DOMAIN", "pass!")); - cl_assert_equal_s("us\u00e9r", ntlm->username); + cl_must_pass(ntlm_client_set_credentials(ntlm, "us\xc3\xa9r", "DOMAIN", "pass!")); + cl_assert_equal_s("us\xc3\xa9r", ntlm->username); cl_assert_equal_s("DOMAIN", ntlm->userdomain); cl_assert_equal_s("pass!", ntlm->password); - cl_must_pass(ntlm_client_set_credentials(ntlm, "user", "DOMAIN", "p\u00e1ss!")); + cl_must_pass(ntlm_client_set_credentials(ntlm, "user", "DOMAIN", "p\xe1ss!")); cl_assert_equal_s("user", ntlm->username); cl_assert_equal_s("DOMAIN", ntlm->userdomain); - cl_assert_equal_s("p\u00e1ss!", ntlm->password); + cl_assert_equal_s("p\xe1ss!", ntlm->password); } void test_inputs__set_target(void)