/* Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup Copyright (C) Andrew Tridgell 1992-1998 Copyright (C) John H Terpstra 1996-1998 Copyright (C) Luke Kenneth Casson Leighton 1996-1998 Copyright (C) Paul Ashton 1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef _SMB_H #define _SMB_H #define BUFFER_SIZE (0xFFFF) #define SAFETY_MARGIN 1024 #define NMB_PORT 137 #define DGRAM_PORT 138 #define SMB_PORT 139 #define False (0) #define True (1) #define BOOLSTR(b) ((b) ? "Yes" : "No") #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0) #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0) #define IS_BITS_SET_ALL(var,bit) (((var)&(bit))==(bit)) #define IS_BITS_SET_SOME(var,bit) (((var)&(bit))!=0) #define IS_BITS_CLR_ALL(var,bit) (((var)&(~(bit)))==0) #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2))) typedef int BOOL; /* limiting size of ipc replies */ #define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024)) #define SIZEOFWORD 2 #ifndef DEF_CREATE_MASK #define DEF_CREATE_MASK (0755) #endif /* how long to wait for secondary SMB packets (milli-seconds) */ #define SMB_SECONDARY_WAIT (60*1000) /* -------------------------------------------------------------------------- ** * Debugging code. See also debug.c */ /* mkproto.awk has trouble with ifdef'd function definitions (it ignores * the #ifdef directive and will read both definitions, thus creating two * diffferent prototype declarations), so we must do these by hand. */ /* I know the __attribute__ stuff is ugly, but it does ensure we get the arguemnts to DEBUG() right. We have got them wrong too often in the past */ #ifdef HAVE_STDARG_H int Debug1( char *, ... ) #ifdef __GNUC__ __attribute__ ((format (printf, 1, 2))) #endif ; BOOL dbgtext( char *, ... ) #ifdef __GNUC__ __attribute__ ((format (printf, 1, 2))) #endif ; #else int Debug1(); BOOL dbgtext(); #endif /* If we have these macros, we can add additional info to the header. */ #ifdef HAVE_FILE_MACRO #define FILE_MACRO (__FILE__) #else #define FILE_MACRO ("") #endif #ifdef HAVE_FUNCTION_MACRO #define FUNCTION_MACRO (__FUNCTION__) #else #define FUNCTION_MACRO ("") #endif /* Debugging macros. * DEBUGLVL() - If level is <= the system-wide DEBUGLEVEL then generate a * header using the default macros for file, line, and * function name. * Returns True if the debug level was <= DEBUGLEVEL. * Example usage: * if( DEBUGLVL( 2 ) ) * dbgtext( "Some text.\n" ); * DEGUG() - Good old DEBUG(). Each call to DEBUG() will generate a new * header *unless* the previous debug output was unterminated * (i.e., no '\n'). See debug.c:dbghdr() for more info. * Example usage: * DEBUG( 2, ("Some text.\n") ); * DEBUGADD() - If level <= DEBUGLEVEL, then the text is appended to the * current message (i.e., no header). * Usage: * DEBUGADD( 2, ("Some additional text.\n") ); */ #define DEBUGLVL( level ) \ ( (DEBUGLEVEL >= (level)) \ && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) ) #if 0 #define DEBUG( level, body ) \ ( ( DEBUGLEVEL >= (level) \ && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) ) \ ? (void)(dbgtext body) : (void)0 ) #define DEBUGADD( level, body ) \ ( (DEBUGLEVEL >= (level)) ? (void)(dbgtext body) : (void)0 ) #else #define DEBUG( level, body ) \ (void)( (DEBUGLEVEL >= (level)) \ && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \ && (dbgtext body) ) #define DEBUGADD( level, body ) \ (void)( (DEBUGLEVEL >= (level)) && (dbgtext body) ) #endif /* End Debugging code section. * -------------------------------------------------------------------------- ** */ /* this defines the error codes that receive_smb can put in smb_read_error */ #define READ_TIMEOUT 1 #define READ_EOF 2 #define READ_ERROR 3 #define DIR_STRUCT_SIZE 43 /* these define all the command types recognised by the server - there are lots of gaps so probably there are some rare commands that are not implemented */ #define pSETDIR '\377' /* these define the attribute byte as seen by DOS */ #define aRONLY (1L<<0) #define aHIDDEN (1L<<1) #define aSYSTEM (1L<<2) #define aVOLID (1L<<3) #define aDIR (1L<<4) #define aARCH (1L<<5) /* for readability... */ #define IS_DOS_READONLY(test_mode) (((test_mode) & aRONLY) != 0) #define IS_DOS_DIR(test_mode) (((test_mode) & aDIR) != 0) #define IS_DOS_ARCHIVE(test_mode) (((test_mode) & aARCH) != 0) #define IS_DOS_SYSTEM(test_mode) (((test_mode) & aSYSTEM) != 0) #define IS_DOS_HIDDEN(test_mode) (((test_mode) & aHIDDEN) != 0) /* deny modes */ #define DENY_DOS 0 #define DENY_ALL 1 #define DENY_WRITE 2 #define DENY_READ 3 #define DENY_NONE 4 #define DENY_FCB 7 /* open modes */ #define DOS_OPEN_RDONLY 0 #define DOS_OPEN_WRONLY 1 #define DOS_OPEN_RDWR 2 #define DOS_OPEN_FCB 0xF /* define shifts and masks for share and open modes. */ #define OPEN_MODE_MASK 0xF #define SHARE_MODE_SHIFT 4 #define SHARE_MODE_MASK 0x7 #define GET_OPEN_MODE(x) ((x) & OPEN_MODE_MASK) #define SET_OPEN_MODE(x) ((x) & OPEN_MODE_MASK) #define GET_DENY_MODE(x) (((x)>>SHARE_MODE_SHIFT) & SHARE_MODE_MASK) #define SET_DENY_MODE(x) ((x)<