Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C90 with no extensions #26

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -179,6 +179,8 @@ IF(BUILD_LIBRARY)
SET_PROPERTY(TARGET ntlmclient PROPERTY POSITION_INDEPENDENT_CODE 1)

ADD_LIBRARY(ntlmclient_shared SHARED $<TARGET_OBJECTS:ntlmclient>)
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})
Expand Down
6 changes: 3 additions & 3 deletions src/crypt_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
38 changes: 19 additions & 19 deletions src/ntlm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/unicode_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/unicode_iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ntlmclient.h"
#include "unicode.h"
#include "ntlm.h"
#include "util.h"
#include "compat.h"

typedef enum {
Expand All @@ -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,
Expand Down
56 changes: 29 additions & 27 deletions src/utf8.h
Original file line number Diff line number Diff line change
@@ -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 <http://unlicense.org/>
/*
* 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 <http://unlicense.org/>
*/

#ifndef SHEREDOM_UTF8_H_INCLUDED
#define SHEREDOM_UTF8_H_INCLUDED
Expand Down
8 changes: 8 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
#include <stddef.h>
#include <stdint.h>

#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);

Expand Down
8 changes: 4 additions & 4 deletions tests/inputs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down