added RPC flags "padcheck" which enables checking of all received pad
[samba-svnmirror.git] / source / librpc / rpc / dcerpc.h
1 /* 
2    Unix SMB/CIFS implementation.
3    DCERPC interface structures
4
5    Copyright (C) Tim Potter 2003
6    Copyright (C) Andrew Tridgell 2003
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 enum dcerpc_transport_t {NCACN_NP, NCACN_IP_TCP};
24
25 /*
26   this defines a generic security context for signed/sealed dcerpc pipes.
27 */
28 struct dcerpc_pipe;
29 struct dcerpc_security {
30         struct dcerpc_auth *auth_info;
31         struct gensec_security *generic_state;
32 };
33
34 struct dcerpc_pipe {
35         int reference_count;
36         uint32_t call_id;
37         uint32_t srv_max_xmit_frag;
38         uint32_t srv_max_recv_frag;
39         uint_t flags;
40         struct dcerpc_security security_state;
41         const char *binding_string;
42
43         struct dcerpc_syntax_id syntax;
44         struct dcerpc_syntax_id transfer_syntax;
45
46         struct dcerpc_transport {
47                 enum dcerpc_transport_t transport;
48                 void *private;
49
50                 NTSTATUS (*shutdown_pipe)(struct dcerpc_pipe *);
51
52                 const char *(*peer_name)(struct dcerpc_pipe *);
53
54                 /* send a request to the server */
55                 NTSTATUS (*send_request)(struct dcerpc_pipe *, DATA_BLOB *, BOOL trigger_read);
56
57                 /* send a read request to the server */
58                 NTSTATUS (*send_read)(struct dcerpc_pipe *);
59
60                 /* get an event context for the connection */
61                 struct event_context *(*event_context)(struct dcerpc_pipe *);
62
63                 /* a callback to the dcerpc code when a full fragment
64                    has been received */
65                 void (*recv_data)(struct dcerpc_pipe *, DATA_BLOB *, NTSTATUS status);
66         } transport;
67
68         /* the last fault code from a DCERPC fault */
69         uint32_t last_fault_code;
70
71         /* pending requests */
72         struct rpc_request *pending;
73
74         /* private pointer for pending full requests */
75         void *full_request_private;
76 };
77
78 /* dcerpc pipe flags */
79 #define DCERPC_DEBUG_PRINT_IN          (1<<0)
80 #define DCERPC_DEBUG_PRINT_OUT         (1<<1)
81 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
82
83 #define DCERPC_DEBUG_VALIDATE_IN       (1<<2)
84 #define DCERPC_DEBUG_VALIDATE_OUT      (1<<3)
85 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
86
87 #define DCERPC_SIGN                    (1<<4)
88 #define DCERPC_SEAL                    (1<<5)
89
90 #define DCERPC_PUSH_BIGENDIAN          (1<<6)
91 #define DCERPC_PULL_BIGENDIAN          (1<<7)
92
93 #define DCERPC_SCHANNEL_BDC            (1<<8)
94 #define DCERPC_SCHANNEL_WORKSTATION    (1<<9)
95 #define DCERPC_SCHANNEL_DOMAIN         (1<<10)
96 #define DCERPC_SCHANNEL_ANY            (DCERPC_SCHANNEL_BDC| \
97                                         DCERPC_SCHANNEL_DOMAIN| \
98                                         DCERPC_SCHANNEL_WORKSTATION)
99 /* use a 128 bit session key */
100 #define DCERPC_SCHANNEL_128            (1<<11)
101
102 #define DCERPC_AUTH_OPTIONS    (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL_ANY)
103
104 /* check incoming pad bytes */
105 #define DCERPC_DEBUG_PAD_CHECK         (1<<12)
106
107 /*
108   this is used to find pointers to calls
109 */
110 struct dcerpc_interface_call {
111         const char *name;
112         size_t struct_size;
113         NTSTATUS (*ndr_push)(struct ndr_push *, int , void *);
114         NTSTATUS (*ndr_pull)(struct ndr_pull *, int , void *);
115         void (*ndr_print)(struct ndr_print *, const char *, int, void *);       
116 };
117
118 struct dcerpc_endpoint_list {
119         uint32_t count;
120         const char * const *names;
121 };
122
123 struct dcerpc_interface_table {
124         const char *name;
125         const char *uuid;
126         uint32_t if_version;
127         const char *helpstring;
128         uint32_t num_calls;
129         const struct dcerpc_interface_call *calls;
130         const struct dcerpc_endpoint_list *endpoints;
131 };
132
133
134 /* this describes a binding to a particular transport/pipe */
135 struct dcerpc_binding {
136         enum dcerpc_transport_t transport;
137         const char *host;
138         const char **options;
139         uint32_t flags;
140 };
141
142
143 enum rpc_request_state {
144         RPC_REQUEST_PENDING,
145         RPC_REQUEST_DONE
146 };
147
148 /*
149   handle for an async dcerpc request
150 */
151 struct rpc_request {
152         struct rpc_request *next, *prev;
153         struct dcerpc_pipe *p;
154         NTSTATUS status;
155         uint32_t call_id;
156         enum rpc_request_state state;
157         DATA_BLOB payload;
158         uint_t flags;
159         uint32_t fault_code;
160
161         /* use by the ndr level async recv call */
162         struct rpc_request_ndr {
163                 NTSTATUS (*ndr_push)(struct ndr_push *, int, void *);
164                 NTSTATUS (*ndr_pull)(struct ndr_pull *, int, void *);
165                 void *struct_ptr;
166                 size_t struct_size;
167                 TALLOC_CTX *mem_ctx;
168         } ndr;
169 };