r12693: Move core data structures out of smb.h into core.h
[jelmer/samba4-debian.git] / source / librpc / rpc / dcerpc.h
index 65566878e3a0d1ddd3177de67ba8e2fb7cb5ace1..4129fb25d884801ad5cfd9ed2702722ff9441eae 100644 (file)
@@ -1,9 +1,10 @@
 /* 
    Unix SMB/CIFS implementation.
-   DCERPC interface structures
+
+   DCERPC client side interface structures
 
    Copyright (C) Tim Potter 2003
-   Copyright (C) Andrew Tridgell 2003
+   Copyright (C) Andrew Tridgell 2003-2005
    
    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
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#ifndef __DCERPC_H__
+#define __DCERPC_H__
+
+#include <nt_status.h>
+
+enum dcerpc_transport_t {
+       NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC, NCACN_VNS_SPP, 
+       NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM, NCADG_UNIX_DGRAM,
+       NCACN_HTTP, NCADG_IPX, NCACN_SPX };
+
 /*
-  see http://www.opengroup.org/onlinepubs/9629399/chap12.htm for details
-  of these structures
+  this defines a generic security context for signed/sealed dcerpc pipes.
+*/
+struct dcerpc_connection;
+struct dcerpc_security {
+       struct dcerpc_auth *auth_info;
+       struct gensec_security *generic_state;
+
+       /* get the session key */
+       NTSTATUS (*session_key)(struct dcerpc_connection *, DATA_BLOB *);
+};
 
-  note that the structure definitions here don't include some of the
-  fields that are wire-artifacts. Those are put on the wire by the
-  marshalling/unmarshalling routines in decrpc.c
+/*
+  this holds the information that is not specific to a particular rpc context_id
 */
+struct dcerpc_connection {
+       uint32_t call_id;
+       uint32_t srv_max_xmit_frag;
+       uint32_t srv_max_recv_frag;
+       uint32_t flags;
+       struct dcerpc_security security_state;
+       const char *binding_string;
+       struct event_context *event_ctx;
+
+       struct dcerpc_transport {
+               enum dcerpc_transport_t transport;
+               void *private;
+
+               NTSTATUS (*shutdown_pipe)(struct dcerpc_connection *);
+
+               const char *(*peer_name)(struct dcerpc_connection *);
+
+               /* send a request to the server */
+               NTSTATUS (*send_request)(struct dcerpc_connection *, DATA_BLOB *, BOOL trigger_read);
+
+               /* send a read request to the server */
+               NTSTATUS (*send_read)(struct dcerpc_connection *);
+
+               /* a callback to the dcerpc code when a full fragment
+                  has been received */
+               void (*recv_data)(struct dcerpc_connection *, DATA_BLOB *, NTSTATUS status);
+       } transport;
+
+       /* Requests that have been sent, waiting for a reply */
+       struct rpc_request *pending;
 
+       /* Sync requests waiting to be shipped */
+       struct rpc_request *request_queue;
+
+       /* private pointer for pending binds */
+       void *bind_private;
+
+       /* private pointer for pending alter context requests */
+       void *alter_private;
+
+       /* the next context_id to be assigned */
+       uint32_t next_context_id;
+};
+
+/*
+  this encapsulates a full dcerpc client side pipe 
+*/
 struct dcerpc_pipe {
-       TALLOC_CTX *mem_ctx;
-       uint16 fnum;
-       int reference_count;
-       uint32 call_id;
-       uint32 srv_max_xmit_frag;
-       uint32 srv_max_recv_frag;
-       struct cli_tree *tree;
-       unsigned flags;
+       uint32_t context_id;
+
+       struct dcerpc_syntax_id syntax;
+       struct dcerpc_syntax_id transfer_syntax;
+
+       struct dcerpc_connection *conn;
+
+       /* the last fault code from a DCERPC fault */
+       uint32_t last_fault_code;
+
+       /* timeout for individual rpc requests, in seconds */
+       uint32_t request_timeout;
 };
 
-/* dcerpc packet types */
-#define DCERPC_PKT_REQUEST   0
-#define DCERPC_PKT_RESPONSE  2
-#define DCERPC_PKT_BIND     11
-#define DCERPC_PKT_BIND_ACK 12
-#define DCERPC_PKT_BIND_NAK 13
+/* default timeout for all rpc requests, in seconds */
+#define DCERPC_REQUEST_TIMEOUT 60
 
-/* hdr.pfc_flags */
-#define DCERPC_PFC_FLAG_FIRST   0x01
-#define DCERPC_PFC_FLAG_LAST    0x02
-#define DCERPC_PFC_FLAG_NOCALL  0x20
 
 /* dcerpc pipe flags */
-#define DCERPC_DEBUG_PRINT_IN  1
-#define DCERPC_DEBUG_PRINT_OUT 2
+#define DCERPC_DEBUG_PRINT_IN          (1<<0)
+#define DCERPC_DEBUG_PRINT_OUT         (1<<1)
 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
 
-#define DCERPC_DEBUG_VALIDATE_IN  4
-#define DCERPC_DEBUG_VALIDATE_OUT 8
+#define DCERPC_DEBUG_VALIDATE_IN       (1<<2)
+#define DCERPC_DEBUG_VALIDATE_OUT      (1<<3)
 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
 
+#define DCERPC_CONNECT                 (1<<4)
+#define DCERPC_SIGN                    (1<<5)
+#define DCERPC_SEAL                    (1<<6)
+
+#define DCERPC_PUSH_BIGENDIAN          (1<<7)
+#define DCERPC_PULL_BIGENDIAN          (1<<8)
+
+#define DCERPC_SCHANNEL                (1<<9)
+
+/* use a 128 bit session key */
+#define DCERPC_SCHANNEL_128            (1<<12)
+
+/* check incoming pad bytes */
+#define DCERPC_DEBUG_PAD_CHECK         (1<<13)
+
+/* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
+#define DCERPC_NDR_REF_ALLOC           (1<<14)
+
+#define DCERPC_AUTH_OPTIONS    (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5)
+
+/* enable spnego auth */
+#define DCERPC_AUTH_SPNEGO             (1<<15)
+
+/* enable krb5 auth */
+#define DCERPC_AUTH_KRB5               (1<<16)
+
+#define DCERPC_SMB2                    (1<<17)
+
+/*
+  this is used to find pointers to calls
+*/
+struct dcerpc_interface_call {
+       const char *name;
+       size_t struct_size;
+       ndr_push_flags_fn_t ndr_push;
+       ndr_pull_flags_fn_t ndr_pull;
+       ndr_print_function_t ndr_print;
+       BOOL async;
+};
+
+struct dcerpc_endpoint_list {
+       uint32_t count;
+       const char * const *names;
+};
+
+struct dcerpc_authservice_list {
+       uint32_t count;
+       const char * const *names;
+};
+
+struct dcerpc_interface_table {
+       const char *name;
+       struct GUID uuid;
+       uint32_t if_version;
+       const char *helpstring;
+       uint32_t num_calls;
+       const struct dcerpc_interface_call *calls;
+       const struct dcerpc_endpoint_list *endpoints;
+       const struct dcerpc_authservice_list *authservices;
+};
+
+struct dcerpc_interface_list {
+       struct dcerpc_interface_list *prev, *next;
+       const struct dcerpc_interface_table *table;
+};
+
+/* this describes a binding to a particular transport/pipe */
+struct dcerpc_binding {
+       enum dcerpc_transport_t transport;
+       struct GUID object;
+       uint16_t object_version;
+       const char *host;
+       const char *endpoint;
+       const char **options;
+       uint32_t flags;
+};
+
+
+struct dcerpc_pipe_connect {
+       struct dcerpc_pipe *pipe;
+       struct dcerpc_binding *binding;
+       const char *pipe_name;
+       const struct dcerpc_interface_table *interface;
+       struct cli_credentials *creds;
+};
+
+
+enum rpc_request_state {
+       RPC_REQUEST_PENDING,
+       RPC_REQUEST_DONE
+};
+
 /*
-  all dcerpc packets use this structure. 
+  handle for an async dcerpc request
 */
-struct dcerpc_packet {
-       /* all requests and responses contain a dcerpc header */
-       struct dcerpc_hdr {
-               uint8 rpc_vers;         /* RPC version */
-               uint8 rpc_vers_minor;   /* Minor version */
-               uint8 ptype;            /* Packet type */
-               uint8 pfc_flags;        /* Fragmentation flags */
-               uint8 drep[4];          /* NDR data representation */
-               uint16 frag_length;     /* Total length of fragment */
-               uint16 auth_length;     /* authenticator length */
-               uint32 call_id;         /* Call identifier */
-       } hdr;
-
-       union {
-               struct dcerpc_bind {
-                       uint16 max_xmit_frag;
-                       uint16 max_recv_frag;
-                       uint32 assoc_group_id;
-                       uint8 num_contexts;
-                       struct {
-                               uint16 context_id;
-                               uint8 num_transfer_syntaxes;
-                               struct dcerpc_syntax_id {
-                                       const char *uuid_str;
-                                       uint32 if_version;
-                               } abstract_syntax;
-                               const struct dcerpc_syntax_id *transfer_syntaxes;
-                       } *ctx_list;
-                       DATA_BLOB auth_verifier;
-               } bind;
-
-               struct dcerpc_request {
-                       uint32 alloc_hint;
-                       uint16 context_id;
-                       uint16 opnum;
-                       DATA_BLOB stub_data;
-                       DATA_BLOB auth_verifier;
-               } request;
-       } in;
-
-       union {
-               struct dcerpc_bind_ack {
-                       uint16 max_xmit_frag;
-                       uint16 max_recv_frag;
-                       uint32 assoc_group_id;
-                       const char *secondary_address;
-                       uint8 num_results;
-                       struct {
-                               uint16 result;
-                               uint16 reason;
-                               struct dcerpc_syntax_id syntax;
-                       } *ctx_list;
-                       DATA_BLOB auth_verifier;
-               } bind_ack;
-
-               struct dcerpc_bind_nak {
-                       uint16 reject_reason;
-                       uint32 num_versions;
-                       uint32 *versions;
-               } bind_nak;
-
-               struct dcerpc_response {
-                       uint32 alloc_hint;
-                       uint16 context_id;
-                       uint8 cancel_count;
-                       DATA_BLOB stub_data;
-                       DATA_BLOB auth_verifier;                
-               } response;
-       } out;
+struct rpc_request {
+       struct rpc_request *next, *prev;
+       struct dcerpc_pipe *p;
+       NTSTATUS status;
+       uint32_t call_id;
+       enum rpc_request_state state;
+       DATA_BLOB payload;
+       uint32_t flags;
+       uint32_t fault_code;
+
+       const struct GUID *object;
+       uint16_t opnum;
+       DATA_BLOB request_data;
+       BOOL async_call;
+
+       /* use by the ndr level async recv call */
+       struct {
+               const struct dcerpc_interface_table *table;
+               uint32_t opnum;
+               void *struct_ptr;
+               TALLOC_CTX *mem_ctx;
+       } ndr;
+
+       struct {
+               void (*callback)(struct rpc_request *);
+               void *private;
+       } async;
 };
 
+#include "librpc/rpc/dcerpc_proto.h"
+
+#endif /* __DCERPC_H__ */