Skip to content

Commit a027efb

Browse files
authored
Merge pull request libgit2#5658 from libgit2/ethomson/ntlm_htonll
ntlm: update ntlm dependency for htonll
2 parents 7f4fa17 + d79bb15 commit a027efb

File tree

5 files changed

+23
-42
lines changed

5 files changed

+23
-42
lines changed

deps/ntlmclient/compat.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,6 @@
2121
# include <stdbool.h>
2222
#endif
2323

24-
#if defined(_WIN32) || defined(__APPLE__)
25-
/* winsock and macOS > 10.9 have htonll already */
26-
#elif defined(__linux__)
27-
/* See man page endian(3) */
28-
# include <endian.h>
29-
# define htonll htobe64
30-
#elif defined(__NetBSD__) || defined(__OpenBSD__)
31-
/* See man page htobe64(3) */
32-
# include <endian.h>
33-
# define htonll htobe64
34-
#elif defined(__FreeBSD__)
35-
/* See man page bwaps64(9) */
36-
# include <sys/endian.h>
37-
# define htonll htobe64
38-
#elif defined(sun) || defined(__sun)
39-
/* See man page byteorder(3SOCKET) */
40-
# include <sys/types.h>
41-
# include <netinet/in.h>
42-
# include <inttypes.h>
43-
44-
# if !defined(htonll)
45-
# if defined(_BIG_ENDIAN)
46-
# define htonll(x) (x)
47-
# else
48-
# define htonll(x) ((((uint64_t)htonl(x)) << 32) + htonl((uint64_t)(x) >> 32))
49-
# endif
50-
# endif
51-
#elif defined(__HAIKU__)
52-
# include <ByteOrder.h>
53-
# define htonll B_HOST_TO_BENDIAN_INT64
54-
#else
55-
# error "Please implement htonll for your platform"
56-
#endif
57-
5824
#ifndef MIN
5925
# define MIN(x, y) (((x) < (y)) ? (x) : (y))
6026
#endif

deps/ntlmclient/crypt_openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static inline void HMAC_CTX_free(HMAC_CTX *ctx)
7171
static inline int HMAC_CTX_reset(HMAC_CTX *ctx)
7272
{
7373
HMAC_CTX_cleanup(ctx);
74-
memzero(ctx, sizeof(HMAC_CTX));
74+
ntlm_memzero(ctx, sizeof(HMAC_CTX));
7575
return 1;
7676
}
7777

deps/ntlmclient/ntlm.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ int ntlm_client_set_hostname(
132132
static void free_credentials(ntlm_client *ntlm)
133133
{
134134
if (ntlm->password)
135-
memzero(ntlm->password, strlen(ntlm->password));
135+
ntlm_memzero(ntlm->password, strlen(ntlm->password));
136136

137137
if (ntlm->password_utf16)
138-
memzero(ntlm->password_utf16, ntlm->password_utf16_len);
138+
ntlm_memzero(ntlm->password_utf16, ntlm->password_utf16_len);
139139

140140
free(ntlm->username);
141141
free(ntlm->username_upper);
@@ -1125,7 +1125,7 @@ static bool generate_lm2_response(ntlm_client *ntlm,
11251125
size_t lm2_len = 16;
11261126
uint64_t local_nonce;
11271127

1128-
local_nonce = htonll(ntlm->nonce);
1128+
local_nonce = ntlm_htonll(ntlm->nonce);
11291129

11301130
if (!ntlm_hmac_ctx_reset(ntlm->hmac_ctx) ||
11311131
!ntlm_hmac_md5_init(ntlm->hmac_ctx,
@@ -1197,8 +1197,8 @@ static bool generate_ntlm2_response(ntlm_client *ntlm)
11971197

11981198
/* the blob's integer values are in network byte order */
11991199
signature = htonl(0x01010000);
1200-
timestamp = htonll(ntlm->timestamp);
1201-
nonce = htonll(ntlm->nonce);
1200+
timestamp = ntlm_htonll(ntlm->timestamp);
1201+
nonce = ntlm_htonll(ntlm->nonce);
12021202

12031203
/* construct the blob */
12041204
memcpy(&blob[0], &signature, 4);

deps/ntlmclient/util.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,28 @@
88

99
#include <stdlib.h>
1010
#include <stdint.h>
11+
#include <arpa/inet.h>
1112

1213
#include "compat.h"
1314
#include "util.h"
1415

15-
void memzero(void *data, size_t size)
16+
void ntlm_memzero(void *data, size_t size)
1617
{
1718
volatile uint8_t *scan = (volatile uint8_t *)data;
1819

1920
while (size--)
2021
*scan++ = 0x0;
2122
}
23+
24+
uint64_t ntlm_htonll(uint64_t value)
25+
{
26+
static union {
27+
uint32_t i;
28+
char c[8];
29+
} test = { 0x01020304 };
30+
31+
if (test.c[0] == 0x01)
32+
return value;
33+
else
34+
return ((uint64_t)htonl(value) << 32) | htonl((uint64_t)value >> 32);
35+
}

deps/ntlmclient/util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef PRIVATE_UTIL_H__
1010
#define PRIVATE_UTIL_H__
1111

12-
extern void memzero(void *data, size_t size);
12+
extern void ntlm_memzero(void *data, size_t size);
13+
extern uint64_t ntlm_htonll(uint64_t value);
1314

1415
#endif /* PRIVATE_UTIL_H__ */

0 commit comments

Comments
 (0)