2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
SMB parameters and setup
Copyright ( C ) Andrew Tridgell 1992 - 1998
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1998
Copyright ( C ) Jeremy Allison 1998
Copyright ( C ) James Myers 2003 < myersjj @ samba . org >
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 0213 9 , USA .
*/
2004-08-04 13:23:35 +00:00
# ifndef _SMBCLI_CONTEXT_H
# define _SMBCLI_CONTEXT_H
2003-08-13 01:53:07 +00:00
2004-08-04 13:23:35 +00:00
struct smbcli_tree ; /* forward declare */
struct smbcli_request ; /* forward declare */
struct smbcli_session ; /* forward declare */
struct smbcli_transport ; /* forward declare */
2003-08-13 01:53:07 +00:00
/* context that will be and has been negotiated between the client and server */
2004-08-04 13:23:35 +00:00
struct smbcli_negotiate {
2003-08-13 01:53:07 +00:00
/*
* negotiated maximum transmit size - this is given to us by the server
*/
2004-07-05 23:28:49 +00:00
uint32_t max_xmit ;
2003-08-13 01:53:07 +00:00
/* maximum number of requests that can be multiplexed */
2004-05-25 17:24:24 +00:00
uint16_t max_mux ;
2003-08-13 01:53:07 +00:00
/* the negotiatiated protocol */
enum protocol_types protocol ;
2004-07-05 23:28:49 +00:00
uint8_t sec_mode ; /* security mode returned by negprot */
uint8_t key_len ;
DATA_BLOB server_guid ; /* server_guid */
2003-08-13 01:53:07 +00:00
DATA_BLOB secblob ; /* cryptkey or negTokenInit blob */
2004-05-25 16:24:13 +00:00
uint32_t sesskey ;
2003-08-13 01:53:07 +00:00
2004-08-11 18:05:30 +00:00
struct smb_signing_context sign_info ;
2003-08-13 01:53:07 +00:00
/* capabilities that the server reported */
2004-05-25 16:24:13 +00:00
uint32_t capabilities ;
2003-08-13 01:53:07 +00:00
2004-08-03 05:44:48 +00:00
int server_zone ;
2003-08-13 01:53:07 +00:00
time_t server_time ;
2004-06-01 08:12:45 +00:00
uint_t readbraw_supported : 1 ;
uint_t writebraw_supported : 1 ;
2003-08-13 01:53:07 +00:00
2004-08-24 10:07:49 +00:00
char * server_domain ;
2003-08-13 01:53:07 +00:00
} ;
/* this is the context for a SMB socket associated with the socket itself */
2004-08-04 13:23:35 +00:00
struct smbcli_socket {
2003-08-13 01:53:07 +00:00
struct in_addr dest_ip ;
2004-07-13 05:14:59 +00:00
/* dest hostname (which may or may not be a DNS name) */
char * hostname ;
2003-08-13 01:53:07 +00:00
/* the port used */
int port ;
/* the open file descriptor */
int fd ;
/* a count of the number of packets we have received. We
* actually only care about zero / non - zero at this stage */
2004-06-01 10:12:52 +00:00
uint_t pkt_count ;
2003-08-13 01:53:07 +00:00
/* the network address of the client */
char * client_addr ;
/* timeout for socket operations in milliseconds. */
int timeout ;
} ;
/*
this structure allows applications to control the behaviour of the
client library
*/
2004-08-04 13:23:35 +00:00
struct smbcli_options {
2004-06-01 08:12:45 +00:00
uint_t use_oplocks : 1 ;
uint_t use_level2_oplocks : 1 ;
uint_t use_spnego : 1 ;
2003-08-13 01:53:07 +00:00
} ;
/* this is the context for the client transport layer */
2004-08-04 13:23:35 +00:00
struct smbcli_transport {
2003-08-13 01:53:07 +00:00
/* socket level info */
2004-08-04 13:23:35 +00:00
struct smbcli_socket * socket ;
2003-08-13 01:53:07 +00:00
/* the next mid to be allocated - needed for signing and
request matching */
2004-05-25 17:24:24 +00:00
uint16_t next_mid ;
2003-08-13 01:53:07 +00:00
/* negotiated protocol information */
2004-08-04 13:23:35 +00:00
struct smbcli_negotiate negotiate ;
2003-08-13 01:53:07 +00:00
/* options to control the behaviour of the client code */
2004-08-04 13:23:35 +00:00
struct smbcli_options options ;
2003-08-13 01:53:07 +00:00
/* is a readbraw pending? we need to handle that case
specially on receiving packets */
2004-06-01 08:12:45 +00:00
uint_t readbraw_pending : 1 ;
2003-08-13 01:53:07 +00:00
/* an idle function - if this is defined then it will be
2004-07-23 06:40:49 +00:00
called once every period seconds while we are waiting
2003-08-13 01:53:07 +00:00
for a packet */
struct {
2004-08-04 13:23:35 +00:00
void ( * func ) ( struct smbcli_transport * , void * ) ;
2003-08-13 01:53:07 +00:00
void * private ;
uint_t period ;
} idle ;
/* the error fields from the last message */
struct {
enum { ETYPE_NONE , ETYPE_DOS , ETYPE_NT , ETYPE_SOCKET , ETYPE_NBT } etype ;
union {
struct {
2004-05-25 17:50:17 +00:00
uint8_t eclass ;
2004-05-25 17:24:24 +00:00
uint16_t ecode ;
2003-08-13 01:53:07 +00:00
} dos ;
NTSTATUS nt_status ;
2004-07-23 06:40:49 +00:00
enum { SOCKET_READ_TIMEOUT ,
SOCKET_READ_EOF ,
SOCKET_READ_ERROR ,
SOCKET_WRITE_ERROR ,
SOCKET_READ_BAD_SIG } socket_error ;
2004-06-01 10:12:52 +00:00
uint_t nbt_error ;
2003-08-13 01:53:07 +00:00
} e ;
} error ;
struct {
/* a oplock break request handler */
2004-08-04 13:23:35 +00:00
BOOL ( * handler ) ( struct smbcli_transport * transport ,
2004-05-25 17:50:17 +00:00
uint16_t tid , uint16_t fnum , uint8_t level , void * private ) ;
2003-08-13 01:53:07 +00:00
/* private data passed to the oplock handler */
void * private ;
} oplock ;
2004-07-23 06:40:49 +00:00
/* a list of async requests that are pending for send on this connection */
2004-08-04 13:23:35 +00:00
struct smbcli_request * pending_send ;
2004-07-23 06:40:49 +00:00
/* a list of async requests that are pending for receive on this connection */
2004-08-04 13:23:35 +00:00
struct smbcli_request * pending_recv ;
2003-11-17 03:38:13 +00:00
/* remember the called name - some sub-protocols require us to
know the server name */
struct nmb_name called ;
2004-07-23 06:40:49 +00:00
/* a buffer for partially received SMB packets. */
struct {
uint8_t header [ NBT_HDR_SIZE ] ;
size_t req_size ;
size_t received ;
uint8_t * buffer ;
} recv_buffer ;
/* the event handle for waiting for socket IO */
struct {
struct event_context * ctx ;
struct fd_event * fde ;
struct timed_event * te ;
} event ;
2003-08-13 01:53:07 +00:00
} ;
/* this is the context for the user */
/* this is the context for the session layer */
2004-08-04 13:23:35 +00:00
struct smbcli_session {
2003-08-13 01:53:07 +00:00
/* transport layer info */
2004-08-04 13:23:35 +00:00
struct smbcli_transport * transport ;
2003-08-13 01:53:07 +00:00
/* after a session setup the server provides us with
a vuid identifying the security context */
2004-05-25 17:24:24 +00:00
uint16_t vuid ;
2003-08-13 01:53:07 +00:00
/* default pid for this session */
2004-05-25 16:24:13 +00:00
uint32_t pid ;
2004-05-09 12:42:18 +00:00
DATA_BLOB user_session_key ;
2004-07-05 23:28:49 +00:00
/* the spnego context if we use extented security */
struct gensec_security * gensec ;
2003-08-13 01:53:07 +00:00
} ;
/*
2004-08-04 13:23:35 +00:00
smbcli_tree context : internal state for a tree connection .
2003-08-13 01:53:07 +00:00
*/
2004-08-04 13:23:35 +00:00
struct smbcli_tree {
2003-08-13 01:53:07 +00:00
/* session layer info */
2004-08-04 13:23:35 +00:00
struct smbcli_session * session ;
2003-08-13 01:53:07 +00:00
2004-05-25 17:24:24 +00:00
uint16_t tid ; /* tree id, aka cnum */
2003-08-13 01:53:07 +00:00
char * device ;
char * fs_type ;
} ;
2004-07-16 02:54:57 +00:00
2004-07-23 06:40:49 +00:00
/*
a client request moves between the following 4 states .
*/
2004-08-04 13:23:35 +00:00
enum smbcli_request_state { SMBCLI_REQUEST_INIT , /* we are creating the request */
SMBCLI_REQUEST_SEND , /* the request is in the outgoing socket Q */
SMBCLI_REQUEST_RECV , /* we are waiting for a matching reply */
SMBCLI_REQUEST_DONE , /* the request is finished */
SMBCLI_REQUEST_ERROR } ; /* a packet or transport level error has occurred */
2004-07-23 06:40:49 +00:00
2003-08-13 01:53:07 +00:00
/* the context for a single SMB request. This is passed to any request-context
* functions ( similar to context . h , the server version ) .
* This will allow requests to be multi - threaded . */
2004-08-04 13:23:35 +00:00
struct smbcli_request {
2003-08-13 01:53:07 +00:00
/* allow a request to be part of a list of requests */
2004-08-04 13:23:35 +00:00
struct smbcli_request * next , * prev ;
2003-08-13 01:53:07 +00:00
2004-07-23 06:40:49 +00:00
/* each request is in one of 4 possible states */
2004-08-04 13:23:35 +00:00
enum smbcli_request_state state ;
2004-07-23 06:40:49 +00:00
2003-08-13 01:53:07 +00:00
/* a request always has a transport context, nearly always has
a session context and usually has a tree context */
2004-08-04 13:23:35 +00:00
struct smbcli_transport * transport ;
struct smbcli_session * session ;
struct smbcli_tree * tree ;
2003-08-13 01:53:07 +00:00
/* the flags2 from the SMB request, in raw form (host byte
order ) . Used to parse strings */
2004-05-25 17:24:24 +00:00
uint16_t flags2 ;
2003-08-13 01:53:07 +00:00
/* the NT status for this request. Set by packet receive code
or code detecting error . */
NTSTATUS status ;
/* the sequence number of this packet - used for signing */
2004-06-01 10:12:52 +00:00
uint_t seq_num ;
2003-08-13 01:53:07 +00:00
/* set if this is a one-way request, meaning we are not
expecting a reply from the server . */
2004-06-01 08:12:45 +00:00
uint_t one_way_request : 1 ;
2003-08-13 01:53:07 +00:00
2004-08-03 06:52:06 +00:00
/* set this when the request should only increment the signing
counter by one */
uint_t sign_single_increment : 1 ;
2003-08-13 01:53:07 +00:00
/* the mid of this packet - used to match replies */
2004-05-25 17:24:24 +00:00
uint16_t mid ;
2003-08-13 01:53:07 +00:00
2004-07-16 02:54:57 +00:00
struct request_buffer in ;
struct request_buffer out ;
2003-08-13 01:53:07 +00:00
/* information on what to do with a reply when it is received
asyncronously . If this is not setup when a reply is received then
the reply is discarded
The private pointer is private to the caller of the client
library ( the application ) , not private to the library
*/
struct {
2004-08-04 13:23:35 +00:00
void ( * fn ) ( struct smbcli_request * ) ;
2003-08-13 01:53:07 +00:00
void * private ;
} async ;
} ;
/*
2004-08-04 13:23:35 +00:00
smbcli_state : internal state used in libcli library for single - threaded callers ,
2003-08-13 01:53:07 +00:00
i . e . a single session on a single socket .
*/
2004-08-04 13:23:35 +00:00
struct smbcli_state {
struct smbcli_transport * transport ;
struct smbcli_session * session ;
struct smbcli_tree * tree ;
2003-08-13 01:53:07 +00:00
struct substitute_context substitute ;
} ;
/* useful way of catching wct errors with file and line number */
2004-08-04 13:23:35 +00:00
# define SMBCLI_CHECK_MIN_WCT(req, wcount) if ((req)->in.wct < (wcount)) { \
2003-08-13 01:53:07 +00:00
DEBUG ( 1 , ( " Unexpected WCT %d at %s(%d) - expected min %d \n " , ( req ) - > in . wct , __FILE__ , __LINE__ , wcount ) ) ; \
req - > status = NT_STATUS_INVALID_PARAMETER ; \
goto failed ; \
}
2004-08-04 13:23:35 +00:00
# define SMBCLI_CHECK_WCT(req, wcount) if ((req)->in.wct != (wcount)) { \
2003-08-13 01:53:07 +00:00
DEBUG ( 1 , ( " Unexpected WCT %d at %s(%d) - expected %d \n " , ( req ) - > in . wct , __FILE__ , __LINE__ , wcount ) ) ; \
req - > status = NT_STATUS_INVALID_PARAMETER ; \
goto failed ; \
}
2004-08-04 13:23:35 +00:00
# endif /* _SMBCLI_CONTEXT_H */