📄 smb.h
字号:
/* 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_Hint Debug1( char *, ... )#ifdef __GNUC__ __attribute__ ((format (printf, 1, 2)))#endif;BOOL dbgtext( char *, ... )#ifdef __GNUC__ __attribute__ ((format (printf, 1, 2)))#endif;#elseint 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 - thereare lots of gaps so probably there are some rare commands that are notimplemented */#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)<<SHARE_MODE_SHIFT)/* Sync on open file (not sure if used anymore... ?) */#define FILE_SYNC_OPENMODE (1<<14)#define GET_FILE_SYNC_OPENMODE(x) (((x) & FILE_SYNC_OPENMODE) ? True : False)/* allow delete on open file mode (used by NT SMB's). */#define ALLOW_SHARE_DELETE (1<<15)#define GET_ALLOW_SHARE_DELETE(x) (((x) & ALLOW_SHARE_DELETE) ? True : False)#define SET_ALLOW_SHARE_DELETE(x) ((x) ? ALLOW_SHARE_DELETE : 0)/* delete on close flag (used by NT SMB's). */#define DELETE_ON_CLOSE_FLAG (1<<16)#define GET_DELETE_ON_CLOSE_FLAG(x) (((x) & DELETE_ON_CLOSE_FLAG) ? True : False)#define SET_DELETE_ON_CLOSE_FLAG(x) ((x) ? DELETE_ON_CLOSE_FLAG : 0)/* open disposition values */#define FILE_EXISTS_FAIL 0#define FILE_EXISTS_OPEN 1#define FILE_EXISTS_TRUNCATE 2/* mask for open disposition. */#define FILE_OPEN_MASK 0x3#define GET_FILE_OPEN_DISPOSITION(x) ((x) & FILE_OPEN_MASK)#define SET_FILE_OPEN_DISPOSITION(x) ((x) & FILE_OPEN_MASK)/* The above can be OR'ed with... */#define FILE_CREATE_IF_NOT_EXIST 0x10#define FILE_FAIL_IF_NOT_EXIST 0#define GET_FILE_CREATE_DISPOSITION(x) ((x) & (FILE_CREATE_IF_NOT_EXIST|FILE_FAIL_IF_NOT_EXIST))/* share types */#define STYPE_DISKTREE 0 /* Disk drive */#define STYPE_PRINTQ 1 /* Spooler queue */#define STYPE_DEVICE 2 /* Serial device */#define STYPE_IPC 3 /* Interprocess communication (IPC) */#define STYPE_HIDDEN 0x80000000 /* share is a hidden one (ends with $) *//* SMB X/Open error codes for the ERRDOS error class */#define ERRbadfunc 1 /* Invalid function (or system call) */#define ERRbadfile 2 /* File not found (pathname error) */#define ERRbadpath 3 /* Directory not found */#define ERRnofids 4 /* Too many open files */#define ERRnoaccess 5 /* Access denied */#define ERRbadfid 6 /* Invalid fid */#define ERRnomem 8 /* Out of memory */#define ERRbadmem 9 /* Invalid memory block address */#define ERRbadenv 10 /* Invalid environment */#define ERRbadaccess 12 /* Invalid open mode */#define ERRbaddata 13 /* Invalid data (only from ioctl call) */#define ERRres 14 /* reserved */#define ERRbaddrive 15 /* Invalid drive */#define ERRremcd 16 /* Attempt to delete current directory */#define ERRdiffdevice 17 /* rename/move across different filesystems */#define ERRnofiles 18 /* no more files found in file search */#define ERRbadshare 32 /* Share mode on file conflict with open mode */#define ERRlock 33 /* Lock request conflicts with existing lock */#define ERRunsup 50 /* Request unsupported, returned by Win 95, RJS 20Jun98 */#define ERRfilexists 80 /* File in operation already exists */#define ERRcannotopen 110 /* Cannot open the file specified */#define ERRunknownlevel 124#define ERRrename 183#define ERRbadpipe 230 /* Named pipe invalid */#define ERRpipebusy 231 /* All instances of pipe are busy */#define ERRpipeclosing 232 /* named pipe close in progress */#define ERRnotconnected 233 /* No process on other end of named pipe */#define ERRmoredata 234 /* More data to be returned */#define ERRbaddirectory 267 /* Invalid directory name in a path. */#define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */#define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not supported */#define ERROR_NOTIFY_ENUM_DIR 1022 /* Buffer too small to return change notify. */#define ERRunknownipc 2142/* here's a special one from observing NT */#define ERRnoipc 66 /* don't support ipc *//* Error codes for the ERRSRV class */#define ERRerror 1 /* Non specific error code */#define ERRbadpw 2 /* Bad password */#define ERRbadtype 3 /* reserved */#define ERRaccess 4 /* No permissions to do the requested operation */#define ERRinvnid 5 /* tid invalid */#define ERRinvnetname 6 /* Invalid servername */#define ERRinvdevice 7 /* Invalid device */#define ERRqfull 49 /* Print queue full */#define ERRqtoobig 50 /* Queued item too big */#define ERRinvpfid 52 /* Invalid print file in smb_fid */#define ERRsmbcmd 64 /* Unrecognised command */#define ERRsrverror 65 /* smb server internal error */#define ERRfilespecs 67 /* fid and pathname invalid combination */#define ERRbadlink 68 /* reserved */#define ERRbadpermits 69 /* Access specified for a file is not valid */#define ERRbadpid 70 /* reserved */#define ERRsetattrmode 71 /* attribute mode invalid */#define ERRpaused 81 /* Message server paused */#define ERRmsgoff 82 /* Not receiving messages */#define ERRnoroom 83 /* No room for message */#define ERRrmuns 87 /* too many remote usernames */#define ERRtimeout 88 /* operation timed out */#define ERRnoresource 89 /* No resources currently available for request. */#define ERRtoomanyuids 90 /* too many userids */#define ERRbaduid 91 /* bad userid */#define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */#define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */#define ERRcontMPX 252 /* resume MPX mode */#define ERRbadPW /* reserved */#define ERRnosupport 0xFFFF#define ERRunknownsmb 22 /* from NT 3.5 response *//* Error codes for the ERRHRD class */#define ERRnowrite 19 /* read only media */#define ERRbadunit 20 /* Unknown device */#define ERRnotready 21 /* Drive not ready */#define ERRbadcmd 22 /* Unknown command */#define ERRdata 23 /* Data (CRC) error */#define ERRbadreq 24 /* Bad request structure length */#define ERRseek 25#define ERRbadmedia 26#define ERRbadsector 27#define ERRnopaper 28#define ERRwrite 29 /* write fault */#define ERRread 30 /* read fault */#define ERRgeneral 31 /* General hardware failure */#define ERRwrongdisk 34#define ERRFCBunavail 35#define ERRsharebufexc 36 /* share buffer exceeded */#define ERRdiskfull 39typedef char pstring[1024];typedef char fstring[128];/* pipe string names */#define PIPE_LANMAN "\\PIPE\\LANMAN"#define PIPE_SRVSVC "\\PIPE\\srvsvc"#define PIPE_SAMR "\\PIPE\\samr"#define PIPE_WINREG "\\PIPE\\winreg"#define PIPE_WKSSVC "\\PIPE\\wkssvc"#define PIPE_NETLOGON "\\PIPE\\NETLOGON"#define PIPE_NTLSA "\\PIPE\\ntlsa"#define PIPE_NTSVCS "\\PIPE\\ntsvcs"#define PIPE_LSASS "\\PIPE\\lsass"#define PIPE_LSARPC "\\PIPE\\lsarpc"/* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */typedef struct nttime_info{ uint32 low; uint32 high;} NTTIME;/* Allowable account control bits */#define ACB_DISABLED 0x0001 /* 1 = User account disabled */#define ACB_HOMDIRREQ 0x0002 /* 1 = Home directory required */#define ACB_PWNOTREQ 0x0004 /* 1 = User password not required */#define ACB_TEMPDUP 0x0008 /* 1 = Temporary duplicate account */#define ACB_NORMAL 0x0010 /* 1 = Normal user account */#define ACB_MNS 0x0020 /* 1 = MNS logon user account */#define ACB_DOMTRUST 0x0040 /* 1 = Interdomain trust account */#define ACB_WSTRUST 0x0080 /* 1 = Workstation trust account */#define ACB_SVRTRUST 0x0100 /* 1 = Server trust account */#define ACB_PWNOEXP 0x0200 /* 1 = User password does not expire */#define ACB_AUTOLOCK 0x0400 /* 1 = Account auto locked */ #define MAX_HOURS_LEN 32struct sam_passwd{ time_t logon_time; /* logon time */ time_t logoff_time; /* logoff time */ time_t kickoff_time; /* kickoff time */ time_t pass_last_set_time; /* password last set time */ time_t pass_can_change_time; /* password can change time */ time_t pass_must_change_time; /* password must change time */ char *smb_name; /* username string */ char *full_name; /* user's full name string */ char *home_dir; /* home directory string */ char *dir_drive; /* home directory drive string */ char *logon_script; /* logon script string */ char *profile_path; /* profile path string */ char *acct_desc ; /* user description string */ char *workstations; /* login from workstations string */ char *unknown_str ; /* don't know what this is, yet. */ char *munged_dial ; /* munged path name and dial-back tel number */ uid_t smb_userid; /* this is actually the unix uid_t */ gid_t smb_grpid; /* this is actually the unix gid_t */ uint32 user_rid; /* Primary User ID */ uint32 group_rid; /* Primary Group ID */ unsigned char *smb_passwd; /* Null if no password */ unsigned char *smb_nt_passwd; /* Null if no password */ uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */ uint32 unknown_3; /* 0x00ff ffff */ uint16 logon_divs; /* 168 - number of hours in a week */ uint32 hours_len; /* normally 21 bytes */ uint8 hours[MAX_HOURS_LEN]; uint32 unknown_5; /* 0x0002 0000 */ uint32 unknown_6; /* 0x0000 04ec */};struct smb_passwd{ uid_t smb_userid; /* this is actually the unix uid_t */ char *smb_name; /* username string */ unsigned char *smb_passwd; /* Null if no password */ unsigned char *smb_nt_passwd; /* Null if no password */ uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */ time_t pass_last_set_time; /* password last set time */};struct sam_disp_info{ uint32 user_rid; /* Primary User ID */ char *smb_name; /* username string */ char *full_name; /* user's full name string */};#define MAXSUBAUTHS 15 /* max sub authorities in a SID *//* DOM_SID - security id */typedef struct sid_info{ uint8 sid_rev_num; /* SID revision number */ uint8 num_auths; /* number of sub-authorities */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -