From e07f257cff7a2d81abed5a5f1bbf79ab48912ccf Mon Sep 17 00:00:00 2001 From: Wolfywolfy Date: Wed, 22 Nov 2023 15:25:09 -0300 Subject: [PATCH] Add c89 comments --- include/asprintf.h | 8 ++++---- lib/alloc.c | 4 ++-- lib/dcerpc.c | 4 ++-- lib/errors.c | 14 +++++++++----- lib/init.c | 8 ++++---- lib/libsmb2.c | 6 +++--- lib/ntlmssp.c | 9 +++++---- lib/sha384-512.c | 20 ++++++++++---------- lib/smb2-cmd-query-directory.c | 2 +- lib/smb2-cmd-read.c | 2 +- lib/smb2-cmd-write.c | 2 +- lib/smb3-seal.c | 2 +- lib/socket.c | 24 ++++++++++++++---------- 13 files changed, 57 insertions(+), 48 deletions(-) diff --git a/include/asprintf.h b/include/asprintf.h index 88c83cc0..8c4d804a 100644 --- a/include/asprintf.h +++ b/include/asprintf.h @@ -18,7 +18,7 @@ static inline int _vscprintf_so(const char * format, va_list pargs) { va_end(argcopy); return retval; } -#endif // _vscprintf +#endif /* _vscprintf */ #ifndef vasprintf static inline int vasprintf(char **strp, const char *fmt, va_list ap) { @@ -31,7 +31,7 @@ static inline int vasprintf(char **strp, const char *fmt, va_list ap) { *strp = str; return r; } -#endif // vasprintf +#endif /* vasprintf */ #ifndef asprintf static inline int asprintf(char *strp[], const char *fmt, ...) { @@ -41,6 +41,6 @@ static inline int asprintf(char *strp[], const char *fmt, ...) { va_end(ap); return r; } -#endif // asprintf +#endif /* asprintf */ -#endif // ! _ASPRINTF_H_ +#endif /* ! _ASPRINTF_H_ */ diff --git a/lib/alloc.c b/lib/alloc.c index 3a7741b5..fcff45f8 100644 --- a/lib/alloc.c +++ b/lib/alloc.c @@ -104,7 +104,7 @@ smb2_alloc_data(struct smb2_context *smb2, void *memctx, size_t size) const char* __mptr = memctx; hdr = (struct smb2_alloc_header*)((char *)__mptr - offsetof(struct smb2_alloc_header, buf)); } -#endif // !_MSC_VER +#endif /* !_MSC_VER */ ptr->next = hdr->mem; hdr->mem = ptr; @@ -129,7 +129,7 @@ smb2_free_data(struct smb2_context *smb2, void *ptr) const char* __mptr = ptr; hdr = (struct smb2_alloc_header*)((char *)__mptr - offsetof(struct smb2_alloc_header, buf)); } -#endif // !_MSC_VER +#endif /* !_MSC_VER */ while ((ent = hdr->mem)) { hdr->mem = ent->next; diff --git a/lib/dcerpc.c b/lib/dcerpc.c index df7b8bbb..f2c8fd93 100644 --- a/lib/dcerpc.c +++ b/lib/dcerpc.c @@ -1299,8 +1299,8 @@ dcerpc_decode_response(struct dcerpc_context *ctx, #else const char* __mptr = rsp; struct dcerpc_pdu *pdu = (struct dcerpc_pdu*)((char *)__mptr - offsetof(struct dcerpc_pdu, rsp)); -#endif // !_MSC_VER - +#endif /* !_MSC_VER */ + if (offset < 0) { return offset; } diff --git a/lib/errors.c b/lib/errors.c index 497f40e0..1ff4c02e 100644 --- a/lib/errors.c +++ b/lib/errors.c @@ -1159,13 +1159,17 @@ int nterror_to_errno(uint32_t status) { case SMB2_STATUS_CONNECTION_ABORTED: case SMB2_STATUS_NETWORK_NAME_DELETED: case SMB2_STATUS_INVALID_NETWORK_RESPONSE: - // We return this errno with the intention that caller can - // retry when any of these are received. + /* + ** We return this errno with the intention that caller can + ** retry when any of these are received. + */ return ENETRESET; case SMB2_STATUS_PATH_NOT_COVERED: - // We do not have an errno which can be an equivalent of this - // NT_STATUS code. To handle this, return a code which will not - // be used as we are operating over a network. + /* + ** We do not have an errno which can be an equivalent of this + ** NT_STATUS code. To handle this, return a code which will not + ** be used as we are operating over a network. + */ return ENOEXEC; case SMB2_STATUS_IO_TIMEOUT: return ETIMEDOUT; diff --git a/lib/init.c b/lib/init.c index a0c05cde..77b43e80 100644 --- a/lib/init.c +++ b/lib/init.c @@ -72,7 +72,7 @@ #define srandom srand #define random rand #define getpid GetCurrentProcessId -#endif // _MSC_VER +#endif /* _MSC_VER */ #ifdef ESP_PLATFORM #include @@ -84,11 +84,11 @@ #ifdef __ANDROID__ #include -// getlogin_r() was added in API 28 +/* getlogin_r() was added in API 28 */ #if __ANDROID_API__ < 28 #define getlogin_r(a,b) ENXIO #endif -#endif // __ANDROID__ +#endif /* __ANDROID__ */ static int smb2_parse_args(struct smb2_context *smb2, const char *args) @@ -483,7 +483,7 @@ static void smb2_set_password_from_file(struct smb2_context *smb2) int finished; #ifdef _MSC_UWP -// GetEnvironmentVariable is not available for UWP up to 10.0.16299 SDK +/* GetEnvironmentVariable is not available for UWP up to 10.0.16299 SDK */ #if defined(NTDDI_WIN10_RS3) && (NTDDI_VERSION >= NTDDI_WIN10_RS3) uint32_t name_len = GetEnvironmentVariableA("NTLM_USER_FILE", NULL, 0); if (name_len > 0) { diff --git a/lib/libsmb2.c b/lib/libsmb2.c index e5a2054a..e4ea0e43 100644 --- a/lib/libsmb2.c +++ b/lib/libsmb2.c @@ -118,15 +118,15 @@ static const char SMBAppKey[] = "SMBAppKey"; #ifndef O_ACCMODE #define O_ACCMODE (O_RDWR|O_WRONLY|O_RDONLY) -#endif // !O_ACCMODE +#endif /* !O_ACCMODE */ #ifndef O_SYNC #ifndef O_DSYNC #define O_DSYNC 040000 -#endif // !O_DSYNC +#endif /* !O_DSYNC */ #define __O_SYNC 020000000 #define O_SYNC (__O_SYNC|O_DSYNC) -#endif // !O_SYNC +#endif /* !O_SYNC */ const smb2_file_id compound_file_id = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, diff --git a/lib/ntlmssp.c b/lib/ntlmssp.c index 39c20ce9..c8a16628 100644 --- a/lib/ntlmssp.c +++ b/lib/ntlmssp.c @@ -179,9 +179,9 @@ ntlm_negotiate_message(struct smb2_context *smb2, struct auth_data *auth_data) u32 = NTLMSSP_NEGOTIATE_128| NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY| - //NTLMSSP_NEGOTIATE_ALWAYS_SIGN| + /* NTLMSSP_NEGOTIATE_ALWAYS_SIGN| */ NTLMSSP_NEGOTIATE_SEAL| - //NTLMSSP_NEGOTIATE_SIGN| + /* NTLMSSP_NEGOTIATE_SIGN| */ NTLMSSP_REQUEST_TARGET|NTLMSSP_NEGOTIATE_OEM| NTLMSSP_NEGOTIATE_UNICODE; u32 = htole32(u32); @@ -533,8 +533,9 @@ encode_ntlm_auth(struct smb2_context *smb2, time_t ti, /* negotiate flags */ u32 = NTLMSSP_NEGOTIATE_128| NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY| - //NTLMSSP_NEGOTIATE_ALWAYS_SIGN| - //NTLMSSP_NEGOTIATE_SIGN| + /* NTLMSSP_NEGOTIATE_ALWAYS_SIGN| + NTLMSSP_NEGOTIATE_SIGN| + */ NTLMSSP_REQUEST_TARGET|NTLMSSP_NEGOTIATE_OEM| NTLMSSP_NEGOTIATE_UNICODE; if (anonymous) diff --git a/lib/sha384-512.c b/lib/sha384-512.c index 3af5596d..92f5ef88 100644 --- a/lib/sha384-512.c +++ b/lib/sha384-512.c @@ -114,7 +114,7 @@ /* * Add the 4word value in word2 to word1. */ -//static uint32_t ADDTO4_temp, ADDTO4_temp2; +/* static uint32_t ADDTO4_temp, ADDTO4_temp2; */ #define SHA512_ADDTO4(word1, word2) ( \ ADDTO4_temp = (word1)[3], \ (word1)[3] += (word2)[3], \ @@ -127,7 +127,7 @@ /* * Add the 2word value in word2 to word1. */ -//static uint32_t ADDTO2_temp; +/* static uint32_t ADDTO2_temp; */ #define SHA512_ADDTO2(word1, word2) ( \ ADDTO2_temp = (word1)[1], \ (word1)[1] += (word2)[1], \ @@ -136,7 +136,7 @@ /* * SHA rotate ((word >> bits) | (word << (64-bits))) */ -//static uint32_t ROTR_temp1[2], ROTR_temp2[2]; +/* static uint32_t ROTR_temp1[2], ROTR_temp2[2]; */ #define SHA512_ROTR(bits, word, ret) ( \ SHA512_SHR((bits), (word), ROTR_temp1), \ SHA512_SHL(64-(bits), (word), ROTR_temp2), \ @@ -146,7 +146,7 @@ * Define the SHA SIGMA and sigma macros * SHA512_ROTR(28,word) ^ SHA512_ROTR(34,word) ^ SHA512_ROTR(39,word) */ -//static uint32_t SIGMA0_temp1[2], SIGMA0_temp2[2], SIGMA0_temp3[2], SIGMA0_temp4[2]; +/* static uint32_t SIGMA0_temp1[2], SIGMA0_temp2[2], SIGMA0_temp3[2], SIGMA0_temp4[2]; */ #define SHA512_SIGMA0(word, ret) ( \ SHA512_ROTR(28, (word), SIGMA0_temp1), \ SHA512_ROTR(34, (word), SIGMA0_temp2), \ @@ -157,7 +157,7 @@ /* * SHA512_ROTR(14,word) ^ SHA512_ROTR(18,word) ^ SHA512_ROTR(41,word) */ -//static uint32_t SIGMA1_temp1[2], SIGMA1_temp2[2], SIGMA1_temp3[2], SIGMA1_temp4[2]; +/* static uint32_t SIGMA1_temp1[2], SIGMA1_temp2[2], SIGMA1_temp3[2], SIGMA1_temp4[2]; */ #define SHA512_SIGMA1(word, ret) ( \ SHA512_ROTR(14, (word), SIGMA1_temp1), \ SHA512_ROTR(18, (word), SIGMA1_temp2), \ @@ -168,7 +168,7 @@ /* * (SHA512_ROTR( 1,word) ^ SHA512_ROTR( 8,word) ^ SHA512_SHR( 7,word)) */ -//static uint32_t sigma0_temp1[2], sigma0_temp2[2], sigma0_temp3[2], sigma0_temp4[2]; +/* static uint32_t sigma0_temp1[2], sigma0_temp2[2], sigma0_temp3[2], sigma0_temp4[2]; */ #define SHA512_sigma0(word, ret) ( \ SHA512_ROTR( 1, (word), sigma0_temp1), \ SHA512_ROTR( 8, (word), sigma0_temp2), \ @@ -179,7 +179,7 @@ /* * (SHA512_ROTR(19,word) ^ SHA512_ROTR(61,word) ^ SHA512_SHR( 6,word)) */ -//static uint32_t sigma1_temp1[2], sigma1_temp2[2], sigma1_temp3[2], sigma1_temp4[2]; +/* static uint32_t sigma1_temp1[2], sigma1_temp2[2], sigma1_temp3[2], sigma1_temp4[2]; */ #define SHA512_sigma1(word, ret) ( \ SHA512_ROTR(19, (word), sigma1_temp1), \ SHA512_ROTR(61, (word), sigma1_temp2), \ @@ -195,7 +195,7 @@ * These definitions are the ones used in FIPS-180-2, section 4.1.3 * Ch(x,y,z) ((x & y) ^ (~x & z)) */ -//static uint32_t Ch_temp1[2], Ch_temp2[2], Ch_temp3[2]; +/* static uint32_t Ch_temp1[2], Ch_temp2[2], Ch_temp3[2]; */ #define SHA_Ch(x, y, z, ret) ( \ SHA512_AND(x, y, Ch_temp1), \ SHA512_TILDA(x, Ch_temp2), \ @@ -204,7 +204,7 @@ /* * Maj(x,y,z) (((x)&(y)) ^ ((x)&(z)) ^ ((y)&(z))) */ -//static uint32_t Maj_temp1[2], Maj_temp2[2], Maj_temp3[2], Maj_temp4[2]; +/* static uint32_t Maj_temp1[2], Maj_temp2[2], Maj_temp3[2], Maj_temp4[2]; */ #define SHA_Maj(x, y, z, ret) ( \ SHA512_AND(x, y, Maj_temp1), \ SHA512_AND(x, z, Maj_temp2), \ @@ -235,7 +235,7 @@ /* * add "length" to the length */ -//static uint32_t addTemp[4] = { 0, 0, 0, 0 }; +/* static uint32_t addTemp[4] = { 0, 0, 0, 0 }; */ #define SHA384_512AddLength(context, length) ( \ addTemp[3] = (length), SHA512_ADDTO4((context)->Length, addTemp), \ diff --git a/lib/smb2-cmd-query-directory.c b/lib/smb2-cmd-query-directory.c index b5296730..8d21bb62 100644 --- a/lib/smb2-cmd-query-directory.c +++ b/lib/smb2-cmd-query-directory.c @@ -174,7 +174,7 @@ smb2_cmd_query_directory_async(struct smb2_context *smb2, /* Adjust credit charge for large payloads */ if (smb2->supports_multi_credit) { pdu->header.credit_charge = - (req->output_buffer_length - 1) / 65536 + 1; // 3.1.5.2 of [MS-SMB2] + (req->output_buffer_length - 1) / 65536 + 1; /* 3.1.5.2 of [MS-SMB2] */ } return pdu; diff --git a/lib/smb2-cmd-read.c b/lib/smb2-cmd-read.c index c31b5a73..dd6935bb 100644 --- a/lib/smb2-cmd-read.c +++ b/lib/smb2-cmd-read.c @@ -125,7 +125,7 @@ smb2_cmd_read_async(struct smb2_context *smb2, /* Adjust credit charge for large payloads */ if (smb2->supports_multi_credit) { - pdu->header.credit_charge = (req->length - 1) / 65536 + 1; // 3.1.5.2 of [MS-SMB2] + pdu->header.credit_charge = (req->length - 1) / 65536 + 1; /* 3.1.5.2 of [MS-SMB2] */ } return pdu; diff --git a/lib/smb2-cmd-write.c b/lib/smb2-cmd-write.c index 68112e81..1ac52f70 100644 --- a/lib/smb2-cmd-write.c +++ b/lib/smb2-cmd-write.c @@ -114,7 +114,7 @@ smb2_cmd_write_async(struct smb2_context *smb2, /* Adjust credit charge for large payloads */ if (smb2->supports_multi_credit) { - pdu->header.credit_charge = (req->length - 1) / 65536 + 1; // 3.1.5.2 of [MS-SMB2] + pdu->header.credit_charge = (req->length - 1) / 65536 + 1; /* 3.1.5.2 of [MS-SMB2] */ } return pdu; diff --git a/lib/smb3-seal.c b/lib/smb3-seal.c index be6ae9ac..1dd70549 100644 --- a/lib/smb3-seal.c +++ b/lib/smb3-seal.c @@ -59,7 +59,7 @@ #ifdef _MSC_VER #define random rand -#endif // _MSC_VER +#endif /* _MSC_VER */ #include diff --git a/lib/socket.c b/lib/socket.c index 8defc039..1578de15 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -963,28 +963,32 @@ static void interleave_addrinfo(struct addrinfo *base) struct addrinfo **next = &base->ai_next; while (*next) { struct addrinfo *cur = *next; - // Iterate forward until we find an entry of a different family. + /* Iterate forward until we find an entry of a different family. */ if (cur->ai_family == base->ai_family) { next = &cur->ai_next; continue; } if (cur == base->ai_next) { - // If the first one following base is of a different family, just - // move base forward one step and continue. + /* + ** If the first one following base is of a different family, just + ** move base forward one step and continue. + */ base = cur; next = &base->ai_next; continue; } - // Unchain cur from the rest of the list from its current spot. + /* Unchain cur from the rest of the list from its current spot. */ *next = cur->ai_next; - // Hook in cur directly after base. + /* Hook in cur directly after base. */ cur->ai_next = base->ai_next; base->ai_next = cur; - // Restart with a new base. We know that before moving the cur element, - // everything between the previous base and cur had the same family, - // different from cur->ai_family. Therefore, we can keep next pointing - // where it was, and continue from there with base at the one after - // cur. + /* + ** Restart with a new base. We know that before moving the cur element, + ** everything between the previous base and cur had the same family, + ** different from cur->ai_family. Therefore, we can keep next pointing + ** where it was, and continue from there with base at the one after + ** cur. + */ base = cur->ai_next; } }