- Allow specifying socket type when adding smbd service
[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 {
24         NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC, NCACN_VNS_SPP, 
25         NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM, NCADG_UNIX_DGRAM };
26
27 /*
28   this defines a generic security context for signed/sealed dcerpc pipes.
29 */
30 struct dcerpc_pipe;
31 struct dcerpc_security {
32         struct dcerpc_auth *auth_info;
33         struct gensec_security *generic_state;
34
35         /* get the session key */
36         NTSTATUS (*session_key)(struct dcerpc_pipe *, DATA_BLOB *);
37 };
38
39 struct dcerpc_pipe {
40         int reference_count;
41         uint32_t call_id;
42         uint32_t srv_max_xmit_frag;
43         uint32_t srv_max_recv_frag;
44         uint_t flags;
45         struct dcerpc_security security_state;
46         const char *binding_string;
47
48         struct dcerpc_syntax_id syntax;
49         struct dcerpc_syntax_id transfer_syntax;
50
51         struct dcerpc_transport {
52                 enum dcerpc_transport_t transport;
53                 void *private;
54
55                 NTSTATUS (*shutdown_pipe)(struct dcerpc_pipe *);
56
57                 const char *(*peer_name)(struct dcerpc_pipe *);
58
59                 /* send a request to the server */
60                 NTSTATUS (*send_request)(struct dcerpc_pipe *, DATA_BLOB *, BOOL trigger_read);
61
62                 /* send a read request to the server */
63                 NTSTATUS (*send_read)(struct dcerpc_pipe *);
64
65                 /* get an event context for the connection */
66                 struct event_context *(*event_context)(struct dcerpc_pipe *);
67
68                 /* a callback to the dcerpc code when a full fragment
69                    has been received */
70                 void (*recv_data)(struct dcerpc_pipe *, DATA_BLOB *, NTSTATUS status);
71
72         } transport;
73
74         /* the last fault code from a DCERPC fault */
75         uint32_t last_fault_code;
76
77         /* pending requests */
78         struct rpc_request *pending;
79
80         /* private pointer for pending full requests */
81         void *full_request_private;
82 };
83
84 /* dcerpc pipe flags */
85 #define DCERPC_DEBUG_PRINT_IN          (1<<0)
86 #define DCERPC_DEBUG_PRINT_OUT         (1<<1)
87 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
88
89 #define DCERPC_DEBUG_VALIDATE_IN       (1<<2)
90 #define DCERPC_DEBUG_VALIDATE_OUT      (1<<3)
91 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
92
93 #define DCERPC_CONNECT                 (1<<4)
94 #define DCERPC_SIGN                    (1<<5)
95 #define DCERPC_SEAL                    (1<<6)
96
97 #define DCERPC_PUSH_BIGENDIAN          (1<<7)
98 #define DCERPC_PULL_BIGENDIAN          (1<<8)
99
100 #define DCERPC_SCHANNEL_BDC            (1<<9)
101 #define DCERPC_SCHANNEL_WORKSTATION    (1<<10)
102 #define DCERPC_SCHANNEL_DOMAIN         (1<<11)
103 #define DCERPC_SCHANNEL_ANY            (DCERPC_SCHANNEL_BDC| \
104                                         DCERPC_SCHANNEL_DOMAIN| \
105                                         DCERPC_SCHANNEL_WORKSTATION)
106 /* use a 128 bit session key */
107 #define DCERPC_SCHANNEL_128            (1<<12)
108
109 #define DCERPC_AUTH_OPTIONS    (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL_ANY)
110
111 /* check incoming pad bytes */
112 #define DCERPC_DEBUG_PAD_CHECK         (1<<13)
113
114 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
115 #define DCERPC_NDR_REF_ALLOC           (1<<14)
116
117 /*
118   this is used to find pointers to calls
119 */
120 struct dcerpc_interface_call {
121         const char *name;
122         size_t struct_size;
123         NTSTATUS (*ndr_push)(struct ndr_push *, int , void *);
124         NTSTATUS (*ndr_pull)(struct ndr_pull *, int , void *);
125         void (*ndr_print)(struct ndr_print *, const char *, int, void *);       
126 };
127
128 struct dcerpc_endpoint_list {
129         uint32_t count;
130         const char * const *names;
131 };
132
133 struct dcerpc_interface_table {
134         const char *name;
135         const char *uuid;
136         uint32_t if_version;
137         const char *helpstring;
138         uint32_t num_calls;
139         const struct dcerpc_interface_call *calls;
140         const struct dcerpc_endpoint_list *endpoints;
141 };
142
143
144 /* this describes a binding to a particular transport/pipe */
145 struct dcerpc_binding {
146         enum dcerpc_transport_t transport;
147         struct GUID object;
148         int object_version;
149         const char *host;
150         const char **options;
151         uint32_t flags;
152 };
153
154
155 enum rpc_request_state {
156         RPC_REQUEST_PENDING,
157         RPC_REQUEST_DONE
158 };
159
160 /*
161   handle for an async dcerpc request
162 */
163 struct rpc_request {
164         struct rpc_request *next, *prev;
165         struct dcerpc_pipe *p;
166         NTSTATUS status;
167         uint32_t call_id;
168         enum rpc_request_state state;
169         DATA_BLOB payload;
170         uint_t flags;
171         uint32_t fault_code;
172
173         /* use by the ndr level async recv call */
174         struct rpc_request_ndr {
175                 NTSTATUS (*ndr_push)(struct ndr_push *, int, void *);
176                 NTSTATUS (*ndr_pull)(struct ndr_pull *, int, void *);
177                 void *struct_ptr;
178                 size_t struct_size;
179                 TALLOC_CTX *mem_ctx;
180         } ndr;
181
182         struct {
183                 void (*callback)(struct rpc_request *);
184                 void *private;
185         } async;
186 };