Skip to content

Commit

Permalink
Merge pull request #294 from Wolf3s/C89
Browse files Browse the repository at this point in the history
Add C89 comments on libsmb2 source
  • Loading branch information
sahlberg authored Nov 26, 2023
2 parents 64c7e0a + e14e3b2 commit 8a40d6c
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 39 deletions.
8 changes: 4 additions & 4 deletions include/asprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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, ...) {
Expand All @@ -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_ */
4 changes: 2 additions & 2 deletions lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/dcerpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 9 additions & 5 deletions lib/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions lib/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
#define srandom srand
#define random rand
#define getpid GetCurrentProcessId
#endif // _MSC_VER
#endif /* _MSC_VER */

#ifdef ESP_PLATFORM
#include <errno.h>
Expand All @@ -84,11 +84,11 @@

#ifdef __ANDROID__
#include <errno.h>
// 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)
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions lib/libsmb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions lib/ntlmssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion lib/sha384-512.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@
/*
* add "length" to the length
*/

#define SHA384_512AddLength(context, length) ( \
addTemp[3] = (length), SHA512_ADDTO4((context)->Length, addTemp), \
(context)->Corrupted = (((context)->Length[3] == 0) && \
Expand Down
2 changes: 1 addition & 1 deletion lib/smb2-cmd-query-directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/smb2-cmd-read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/smb2-cmd-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/smb3-seal.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

#ifdef _MSC_VER
#define random rand
#endif // _MSC_VER
#endif /* _MSC_VER */

#include <stdio.h>

Expand Down
24 changes: 14 additions & 10 deletions lib/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 8a40d6c

Please sign in to comment.