Commit 1a00f9cd authored by Ben Avison's avatar Ben Avison
Browse files

Modernise build structure

* Change capitalisation of CMHG file to match several #includes of the
  derived header file
* Use generic specifiers for include paths and warning suppression options
* Change to `CUSTOMRES=no` so `CModule` provides a no-op `resources` rule
  on our behalf
* Add `.gitignore`
* Enable GitLab CI
* Fix issues identified by CI, including:
  - Tabs-after-spaces
  - Buffer overflows in Auth_LMOWFv2(), LLC_AttachDriver()
  - Dead code: SMBTime(), Auth_NTv2ChallengeResponse(), Func_ReadDir(),
    Transact_getpointer(), Transact_addroutepath()
parent 1c0801eb
Pipeline #1787 passed with stages
in 4 minutes and 49 seconds
/aif/
/aof/
/gpa/
/h/LanMan_MH
/i/
/linked/
/Makefile.d
/o/
/objs/
/od/
/rm/
variables:
WHITESPACE_WHITELIST: "./doc/cifs-v1-spec-01"
include:
- project: 'Support/CI'
file: '/OmniLanManFS.yml'
......@@ -19,14 +19,14 @@ COMPONENT = LanManFS
OBJS = Xlate Transact Stats SMB RPC Printers Omni NetBIOS NBIP \
NameCache Logon LLC LanMan CoreFn buflib Attr \
Interface Auth md5c md4c
CINCLUDES = -ITCPIPLibs:,C:
CINCLUDES = ${TCPIPINC}
HDRS =
CMHGFILE = Lanman_MH
CMHGFILE = LanMan_MH
CMHGDEPENDS = LanMan LLC Logon NBIP Omni
LIBS = ${NET4LIBS} ${ASMUTILS}
RES_PATH = ThirdParty.OmniClient
CDEFINES = -DCOMPAT_INET4 -DLONGNAMES ${OPTIONS}
CFLAGS = -Wp
CFLAGS = ${C_NOWARN_NON_ANSI_INCLUDES}
CDFLAGS = -DDEBUG -DDEBUGLIB -DTRACE -Dprintf=module_printf
ROMCDEFINES = -DROM
CMHGDEFINES = ${OPTIONS}
......@@ -34,7 +34,7 @@ ifeq ("${CMDHELP}","None")
CMHGDEFINES += -DNO_INTERNATIONAL_HELP
endif
# Carry our own ThirdParty resources, don't put them in the Messages module
CUSTOMRES = custom
CUSTOMRES = no
RESDIR = ${MERGEDRDIR}
OBJS += ${RES_OBJ}
INSTRES_FILES = ROM.Sprites
......
......@@ -225,14 +225,14 @@ static int GetEntryPos ( char *name )
static int SearchFileForEntry ( int FH, char *name )
{
uint len;
int pos;
AttrCacheStart = 0;
AttrAllInCache = false;
while(1)
{
len = 0;
uint len = 0;
int pos;
SMB_Read ( FH, AttrCacheStart*ATTR_REC_SIZE,
CACHE_SIZE * ATTR_REC_SIZE,
(BYTE *)AttrCache, &len );
......
......@@ -153,12 +153,12 @@ void Auth_LMOWFv2( const char *password, size_t pass_size,
unsigned char digestout[16] )
{
size_t max_size = user_size;
if (dom_size > max_size) max_size = dom_size;
unsigned short ustr[max_size + 1]; /* 1 added because 0 size causes crash */
Auth_NTOWFv1( password, pass_size, digestout );
if (dom_size > max_size) max_size = dom_size;
HMAC_MD5_CTX ctx;
HMAC_MD5Init( &ctx, digestout, 16 );
......@@ -198,6 +198,8 @@ void Auth_LMv2ChallengeResponse( unsigned char lmowfv2digest[16],
HMAC_MD5Final( responseout, &ctx );
}
#ifdef AUTHTEST
static unsigned long long SMBTime( void )
{
unsigned long long tm = time( NULL );
......@@ -282,8 +284,6 @@ void Auth_NTv2ChallengeResponse( unsigned char ntowfv2digest[16],
HMAC_MD5Final( responseout, &ctx );
}
#ifdef AUTHTEST
#define MDPrint(digest) PrintHex((digest),16)
static void PrintHex( void *d, size_t len )
......
......@@ -182,6 +182,7 @@ static err_t Dir_CallbackFn ( BYTE *entry, int format, bool *taken, void *pw )
/* ----------------- */
#ifdef LONGNAMES
static err_t Func_ReadDir1 ( int reason, char *path_name, char *buffer,
int n_names, int dir_offset, int buflen, int *pOutNread,
int *pOutNextOffset )
......@@ -233,7 +234,8 @@ static err_t Func_ReadDir1 ( int reason, char *path_name, char *buffer,
return res;
}
#endif
#else // not LONGNAMES
/* ----------------- */
......@@ -339,8 +341,11 @@ static err_t Func_ReadDir ( int reason, char *path_name, char *buffer,
return res;
}
#endif
/* Func ============================================================= */
// cppcheck-suppress unusedFunction
_kernel_oserror *fsentry_func ( int *R )
{
err_t err;
......@@ -503,6 +508,7 @@ static err_t FileGetAttribs ( char *filename, DOS_ATTRIBS *pda,
/* ------------------- */
// cppcheck-suppress unusedFunction
_kernel_oserror *fsentry_file( int *R )
{
err_t err;
......@@ -778,6 +784,7 @@ static int NewHandle(void)
/* Open =================================================== */
// cppcheck-suppress unusedFunction
_kernel_oserror *fsentry_open( int *R )
{
err_t err;
......@@ -863,6 +870,7 @@ _kernel_oserror *fsentry_open( int *R )
/* GetBytes =================================================== */
// cppcheck-suppress unusedFunction
_kernel_oserror *fsentry_getbytes( int *R )
{
int fid = R[1]-1;
......@@ -880,6 +888,7 @@ _kernel_oserror *fsentry_getbytes( int *R )
/* PutBytes =================================================== */
// cppcheck-suppress unusedFunction
_kernel_oserror *fsentry_putbytes( int *R )
{
int fid = R[1]-1;
......@@ -896,6 +905,7 @@ _kernel_oserror *fsentry_putbytes( int *R )
/* GBPB =================================================== */
// cppcheck-suppress unusedFunction
_kernel_oserror *fsentry_gbpb( int *R )
{
(void)R;
......@@ -904,6 +914,7 @@ _kernel_oserror *fsentry_gbpb( int *R )
/* Close =================================================== */
// cppcheck-suppress unusedFunction
_kernel_oserror *fsentry_close( int *R )
{
err_t err;
......@@ -935,13 +946,13 @@ _kernel_oserror *fsentry_close( int *R )
static err_t WriteZeros ( int FH, uint offset, uint len )
{
uint tmp;
err_t res=OK;
memset ( DOSnamebuf, 0, NAMEBUF_LEN );
while ( len > 0 )
{
uint tmp;
#if 0
tmp = min(NAMEBUF_LEN, len);
res = SMB_Write ( FH, offset, tmp, (BYTE *)DOSnamebuf, NULL );
......@@ -970,11 +981,11 @@ static err_t WriteZeros ( int FH, uint offset, uint len )
/* --------------------- */
// cppcheck-suppress unusedFunction
_kernel_oserror *fsentry_args( int *R )
{
err_t err=OK;
int fid = R[1]-1;
uint tmp;
debug1("FS_args(%d)\n", R[0]);
......@@ -1001,10 +1012,13 @@ _kernel_oserror *fsentry_args( int *R )
break;
case FSEntry_Args_Reason_ReadSizeAllocatedToFile:
{
uint tmp;
err = SMB_GetLength ( FileTbl[fid].SMB_FH, &tmp );
if ( err == OK )
R[2] = tmp;
break;
}
case FSEntry_Args_Reason_FlushFileBuffer:
err = SMB_Flush ( FileTbl[fid].SMB_FH );
......
......@@ -120,6 +120,7 @@ typedef struct
static bool CallbackSet = false;
// cppcheck-suppress unusedFunction
int LLC_CallbackFn_handler(_kernel_swi_regs *r, void *pw)
{
(void) r;
......@@ -273,6 +274,7 @@ restart:
interrupting anything until the callback is complete.
*/
// cppcheck-suppress unusedFunction
int TickerFn_handler ( _kernel_swi_regs *R, void *pw )
{
struct Timer *pT;
......@@ -419,6 +421,7 @@ static bool TxSend ( NETADDR *dest, BUFCHAIN pB, bool DeleteAfterUse )
manually).
*/
// cppcheck-suppress unusedFunction
int ReceiveFn_handler ( _kernel_swi_regs *R, void *pw )
{
struct mbuf *pData = (struct mbuf *) R->r[1];
......@@ -498,7 +501,7 @@ err_t LLC_AttachDriver( char *name, const NETADDR *Multi_Addr )
int filter_flags = FILTER_NO_UNSAFE | FILTER_CLAIM;
if ( name == NULL ||
sscanf( name, "%[^0123456789]%d", dname, &Net_DriverUnitNo) != 2 )
sscanf( name, "%19[^0123456789]%d", dname, &Net_DriverUnitNo) != 2 )
return EDRIVERNAME;
debug2(" Using driver '%s' unit #%d\n", dname, Net_DriverUnitNo );
......
......@@ -62,7 +62,7 @@
extern void *Resources(void);
#define DEFAULT_ETHER_TYPE "_default_"
#define DEFAULT_ETHER_TYPE "_default_"
typedef void (*pfnShutdown)(void);
typedef void (*pfnTransportInit)(void);
......@@ -138,7 +138,7 @@ err_t MsgSetOSError (_kernel_oserror *err)
/* ------------------ */
_kernel_oserror *MsgError(int which)
_kernel_oserror *MsgError(unsigned int which)
{
struct {
int errnum;
......@@ -185,7 +185,7 @@ static void WrCMOS ( int addr, unsigned int data )
static void SetFSName(char *buf_in)
{
int i, t;
int i;
WrCMOS(CMOS_FSSTAT, 0);
WrCMOS(CMOS_FSERVER1, buf_in[0]);
......@@ -194,7 +194,7 @@ static void SetFSName(char *buf_in)
for (i=1; i < FSERVER_LEN; i++)
{
/* NAS 11/Feb/97 */
t = buf_in[i];
int t = buf_in[i];
if (t <= 0x20 || t > 0x7F) t = 0;
WrCMOS ( CMOS_FSERVER+i-1, t);
if (t == 0) break;
......@@ -205,8 +205,6 @@ static void SetFSName(char *buf_in)
static void GetFSName ( char *buf_out )
{
int i;
if (!_kernel_getenv("Inet$ServerName", buf_out, CMOS_FSERVER)) {
return;
}
......@@ -214,6 +212,7 @@ static void GetFSName ( char *buf_out )
if ( RdCMOS ( CMOS_FSSTAT ) == 0 )
{
/* NAS 11/Feb/97 */
int i;
*buf_out++ = RdCMOS ( CMOS_FSERVER1 );
for ( i=1; i < FSERVER_LEN; i++ )
*buf_out++ = RdCMOS ( CMOS_FSERVER+i-1 );
......@@ -263,6 +262,7 @@ static void LM_GracefulClosedown(void)
LM_Vars.initialised = LMInitState_PreInit;
}
// cppcheck-suppress unusedFunction
_kernel_oserror * LM_Finalise (int fatal, int podule, void *pw)
{
debug0("Finalise\n");
......@@ -548,7 +548,7 @@ static void SetDefaultVars ( void )
#ifdef NO_NETBEUI
LanMan_InitTransport(NB_NBIP_Setup);
#else
LanMan_InitTransport(RdCMOS ( CMOS_NB_TYPE ) & NBTYPE_IP_BIT ?
LanMan_InitTransport((RdCMOS ( CMOS_NB_TYPE ) & NBTYPE_IP_BIT) ?
NB_NBIP_Setup : NB_NetBEUI_Setup);
#endif
}
......@@ -613,10 +613,11 @@ static _kernel_oserror *Cmd_LMNameMode ( const char *args )
int flags[6];
char type;
int mode;
// cppcheck-suppress unusedStructMember
char spare[3]; /* required for sizeof(a) to work with readargs */
} parsed;
_kernel_oserror *e;
e = _swix(OS_ReadArgs, _INR(0,3),
"/e,preservecase/s,lowercase/s,firstcaps/s,includehidden/s,excludehidden/s",
args, &parsed, sizeof(parsed));
......@@ -639,7 +640,7 @@ static _kernel_oserror *Cmd_LMNameMode ( const char *args )
switch (LM_Vars.namemode & NM_MODE)
{
default: /* Preserve case */
token = "NMMode0";
token = "NMMode0";
break;
case NM_LOWERCASE: token = "NMMode1";
break;
......@@ -671,7 +672,7 @@ static _kernel_oserror *Cmd_LMNameMode ( const char *args )
mode = (flags >> 2) & NM_MODE;
break;
}
switch (flags & 0x30)
{
case 0x10: /* IncludeHidden */
......@@ -685,13 +686,13 @@ static _kernel_oserror *Cmd_LMNameMode ( const char *args )
if (mode == -1 && hidden == -1)
return MsgError(EBADPARAM);
if (mode != -1)
{
LM_Vars.namemode &= ~NM_MODE;
LM_Vars.namemode |= mode;
}
if (hidden != -1)
{
LM_Vars.namemode &= ~NM_HIDDEN;
......@@ -706,7 +707,6 @@ static _kernel_oserror *Cmd_LMNameMode ( const char *args )
static _kernel_oserror *Cmd_LMServer ( const char *args )
{
char *argv[MAX_ARGS];
int i;
if ( GetArgs( args, argv, MAX_ARGS ) < 1 )
return MsgError ( EBADPARAM );
......@@ -717,6 +717,7 @@ static _kernel_oserror *Cmd_LMServer ( const char *args )
}
else
{
int i;
for ( i=1; i < MAX_ARGS && argv[i] != NULL; i++ )
Omni_AddInfo ( OAI_DISK, argv[0], argv[i], NULL );
}
......@@ -730,7 +731,6 @@ static _kernel_oserror *Cmd_LMServer ( const char *args )
static _kernel_oserror *Cmd_LMPrinters ( const char *args )
{
char *argv[MAX_ARGS];
int i;
if ( GetArgs( args, argv, MAX_ARGS ) < 1 )
return MsgError ( EBADPARAM );
......@@ -741,6 +741,7 @@ static _kernel_oserror *Cmd_LMPrinters ( const char *args )
}
else
{
int i;
for ( i=1; i < MAX_ARGS && argv[i] != NULL; i++ )
Omni_AddInfo ( OAI_PRINTER, argv[0], argv[i], NULL );
}
......@@ -905,6 +906,7 @@ static CommandFnPtr Cmd_Dispatch[] =
/* --------------------- */
// cppcheck-suppress unusedFunction
_kernel_oserror *LM_Command ( const char *args, int argc, int cmd_no, void *pw )
{
(void) pw;
......@@ -921,6 +923,7 @@ static void LM_check_driver_status(_kernel_swi_regs *r);
static void LM_check_internet_status(_kernel_swi_regs *r);
static void LM_check_protocol_status(_kernel_swi_regs *r);
// cppcheck-suppress unusedFunction
void LM_Service ( int service_number, _kernel_swi_regs *r, void *pw )
{
(void) pw;
......@@ -962,6 +965,7 @@ void LM_Service ( int service_number, _kernel_swi_regs *r, void *pw )
/* SWI handler ------------------------------------------ */
// cppcheck-suppress unusedFunction
_kernel_oserror *LM_Swi( int swi_ofs, _kernel_swi_regs *r, void *pw )
{
(void) pw; /* Not used */
......@@ -1070,8 +1074,6 @@ void LM_Boot(void)
{
int tries=1;
int tmp;
err_t res;
char *serv_name;
char fs_name [ FSERVER_LEN+1 ];
if (LM_Vars.initialised < LMInitState_FullyInited) {
......@@ -1091,7 +1093,8 @@ void LM_Boot(void)
/* Ready to go... */
for (;;) {
serv_name = RPC_GetDomainController(fs_name);
err_t res;
char *serv_name = RPC_GetDomainController(fs_name);
if ( serv_name == NULL )
serv_name = fs_name;
......@@ -1138,6 +1141,7 @@ void LM_Boot(void)
*
*/
// cppcheck-suppress unusedFunction
_kernel_oserror *LM_Initialise(const char *cmd_tail, int pod_base, void *pw)
{
_kernel_oserror *err;
......@@ -1301,17 +1305,17 @@ static void LM_check_driver_status(_kernel_swi_regs *r)
char if_name[16];
Dib *dib = (Dib *) (r->r[0]);
sprintf(if_name, "%-.8s%d", dib->dib_name, dib->dib_unit);
sprintf(if_name, "%-.8s%u", dib->dib_name, dib->dib_unit);
#ifdef TRACE
printf ("Service_DCIDriverStatus called (interface %s%d is %sing)\n"
" Driver supports DCI version %d.%02d\n",
dib->dib_name, dib->dib_unit, r->r[2] ? "dy" : "start",
r->r[3] / 100, r->r[3] % 100
" Driver supports DCI version %d.%02d\n",
dib->dib_name, dib->dib_unit, r->r[2] ? "dy" : "start",
r->r[3] / 100, r->r[3] % 100
);
printf ("We are looking for driver `%s' - got `%s'\n", LM_Vars.drivername,
if_name);
if_name);
#endif
if ((strcmp(LM_Vars.drivername, DEFAULT_ETHER_TYPE) == 0) &&
......@@ -1330,7 +1334,7 @@ static void LM_check_driver_status(_kernel_swi_regs *r)
debug0("Ding! This was our interface\n");
if (r->r[2] == DCIDRIVER_STARTING) {
/*if (LM_Vars.initialised == LMInitState_FullyInited)*/ {
LM_GracefulClosedown();
LM_GracefulClosedown();
}
LM_init_phase_2();
}
......@@ -1418,9 +1422,9 @@ static void LM_check_internet_status(_kernel_swi_regs *r)
#endif
else {
/* Were we actually waiting for the driver to appear */
if (LM_Vars.initialised != LMInitState_PreInit &&
if (LM_Vars.initialised != LMInitState_PreInit &&
LM_Vars.initialised != LMInitState_Boot) return;
/* Was it the right reason code? */
/* Was it the right reason code? */
if (r->r[0] != InternetStatus_InterfaceUpDown) return;
/* Was it the right interface? */
if (stricmp(LM_Vars.drivername, cp) != 0) return;
......@@ -1497,6 +1501,7 @@ int module_printf(const char *str, ...)
* that happening.
*/
// cppcheck-suppress unusedFunction
_kernel_oserror *callback_handler(_kernel_swi_regs *r, void *pw)
{
(void) r;
......
......@@ -113,7 +113,7 @@ typedef struct
int nbflags; /* Group status & node type */
uint TTL_StartTime; /* Time at which a valid 'time to live' was
received */
received */
uint TTL_Interval; /* Time to live, in centiseconds */
struct in_addr IPaddress; /* IP address of this name */
......@@ -515,7 +515,7 @@ static BYTE *PutShort ( BYTE *ptr, uint v )
static BYTE *PutNetname ( BYTE *ptr, NETNAME *pNN )
{
/* Put NetBIOS name in a compressed ASCII-coded representation */
int i,c;
int i;
BYTE *p;
p = pNN->b; /* Pointer to first part of name */
......@@ -524,7 +524,7 @@ static BYTE *PutNetname ( BYTE *ptr, NETNAME *pNN )
for (i=0; i<16; i++)
{
c = *p++;
int c = *p++;
*ptr++ = 'A' + ((c >> 4) & 0xF);
*ptr++ = 'A' + (c & 0xF);
}
......@@ -665,13 +665,11 @@ static void SendStatusRequest ( struct sockaddr *pDst, NAME_ENTRY *pNE )
static bool ValidateName( BYTE *src, BYTE *buf_start, BYTE *buf_end )
{
int c, loopy_count;
loopy_count = 0;
int loopy_count = 0;
while( src >= buf_start && src < buf_end && loopy_count++ < 100 )
{
c = *src;
int c = *src;
if ( c == 0 ) /* Reached the end without incident */
return true;
......@@ -880,11 +878,10 @@ static void NameFindRequest ( struct NBNS_packet *pNBP,
struct NBNS_resource_record *pNBRR )
{
NAME_ENTRY *pNE = pNBRR->pName;
BYTE *p;
if ( pNE->status == LCL_NAME_OK )
{
p = CreateNBNSheader ( DatagramBuf, NAME_FIND_REPLY, pNBP->trn_id );
BYTE *p = CreateNBNSheader ( DatagramBuf, NAME_FIND_REPLY, pNBP->trn_id );
p = PutNetname ( p, &(pNE->nn) );
p = PutLong (p, INET_NAME_TAG );
p = PutResourceInfo(p, pNE, FIND_TTL);
......@@ -1201,6 +1198,7 @@ static bool CallbackSet = false;
/* ---------------- */
// cppcheck-suppress unusedFunction
int EventFn_handler ( _kernel_swi_regs *R, void *pw )
{
(void) pw;
......@@ -1229,16 +1227,15 @@ static void RemoveCallbacks(void)
static int NBIP_CallbackFn_handler(void)
{
fd_set read_set;
struct timeval tv;
int len, flen;
struct sockaddr sa;
CallbackSet = false;
while (NBNS_Socket != INVALID_SOCKET) /* Do as many packets as we can */
{
fd_set read_set;
struct timeval tv;
int len, flen;
struct sockaddr sa;
tv.tv_sec=0;
tv.tv_usec=0;
......@@ -1261,6 +1258,7 @@ static int NBIP_CallbackFn_handler(void)
return 1;
}
// cppcheck-suppress unusedFunction
int NBIP_CallbackFn_handler_ctrl(_kernel_swi_regs *r, void *pw)
{
(void) r;
......@@ -1283,7 +1281,6 @@ int NBIP_CallbackFn_handler_ctrl(_kernel_swi_regs *r, void *pw)
static NAME_ENTRY *FindRemoteName ( NETNAME *pnn )
{
int i;
uint tstart;
char plain_name[NAME_LIMIT];
NAME_ENTRY *pNE;
struct hostent *pHE;
......@@ -1317,6 +1314,8 @@ static NAME_ENTRY *FindRemoteName ( NETNAME *pnn )
for ( i=3; i>=0; i-- )
{
uint tstart;
if ( i > 0 ) /* Send 3 broadcasts */
{
debug0("Broadcast find request\n");
......@@ -1395,7 +1394,6 @@ EXPORT err_t _NB_AddLocalName ( nametype_t nt, char *name, hNAME *phName )
NAME_ENTRY *pNE;
NETNAME netname;
int i;
uint tstart;
debug1("Add name '%s'\n", name );
......@@ -1416,6 +1414,8 @@ EXPORT err_t _NB_AddLocalName ( nametype_t nt, char *name, hNAME *phName )
for ( i=3; i >= 0; i-- ) /* 3 opportunities to complain */
{
uint tstart;
if ( i > 0 ) /* Broadcast 3 times */
{
SendRegisterRequest ( NBNS_Broadcast, pNE );
......@@ -1455,8 +1455,6 @@ EXPORT err_t _NB_AddLocalName ( nametype_t nt, char *name, hNAME *phName )
EXPORT err_t _NB_RemoveLocalName ( hNAME hName )
{
NAME_ENTRY *pNE;
int i;
uint tstart;
pNE = ValidatehName(hName);
if ( pNE == NULL )
......@@ -1466,8 +1464,12 @@ EXPORT err_t _NB_RemoveLocalName ( hNAME hName )
if ( pNE->status != LCL_IN_CONFLICT )
{
int i;
for ( i=0; i<3; i++ )
{
uint tstart;
SendReleaseRequest ( NBNS_Broadcast, pNE );
tstart = NB_GetTime();
do
......@@ -1842,12 +1844,11 @@ EXPORT err_t _NB_SendBlockData ( hSESSION hS, BYTE *where, uint datalen )
{
NBIP_SESSION *pNS;
BYTE hdr[4];
err_t res;
struct iovec iov[2];
while ( datalen > 0x10000 ) /* Max 64K in one go */
{
res = _NB_SendBlockData ( hS, where, 0x10000 );
err_t res = _NB_SendBlockData ( hS, where, 0x10000 );
if ( res != OK )
return res;
where += 0x10000;
......
......@@ -120,9 +120,9 @@ void NameCache_Init(void)
{