s3: pass DCE RPC handle type to create_policy_hnd
[samba.git] / source3 / rpc_server / rpc_pipes.h
1 /*
2    Unix SMB/Netbios implementation.
3    RPC Server Headers
4    Copyright (C) Andrew Tridgell 1992-1997
5    Copyright (C) Luke Kenneth Casson Leighton 1996-1997
6    Copyright (C) Paul Ashton 1997
7    Copyright (C) Jeremy Allison 2000-2004
8    Copyright (C) Simo Sorce 2010-2011
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 3 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #ifndef _RPC_PIPES_H_
25 #define _RPC_PIPES_H_
26
27 #include "librpc/rpc/dcerpc.h"
28
29 struct dcesrv_ep_entry_list;
30 struct tsocket_address;
31 struct handle_list;
32 struct pipes_struct;
33
34 struct pipe_rpc_fns {
35
36         struct pipe_rpc_fns *next, *prev;
37
38         /* RPC function table associated with the current rpc_bind (associated by context) */
39
40         uint32_t context_id;
41         struct ndr_syntax_id syntax;
42
43         /*
44          * shall we allow "connect" auth level for this interface ?
45          */
46         bool allow_connect;
47
48         /*
49          * minimal required auth level
50          */
51         enum dcerpc_AuthLevel min_auth_level;
52 };
53
54 /*
55  * DCE/RPC-specific samba-internal-specific handling of data on
56  * NamedPipes.
57  */
58 struct pipes_struct {
59         struct pipes_struct *next, *prev;
60
61         const struct tsocket_address *local_address;
62         const struct tsocket_address *remote_address;
63
64         enum dcerpc_transport_t transport;
65
66         struct auth_session_info *session_info;
67         struct messaging_context *msg_ctx;
68
69         struct dcesrv_ep_entry_list *ep_entries;
70
71         /* linked list of rpc dispatch tables associated 
72            with the open rpc contexts */
73
74         struct pipe_rpc_fns *contexts;
75
76         struct pipe_auth_data auth;
77
78         /*
79          * Set to true when an RPC bind has been done on this pipe.
80          */
81         bool pipe_bound;
82
83         /*
84          * Set the DCERPC_FAULT to return.
85          */
86         int fault_state;
87
88         /*
89          * Set to RPC_BIG_ENDIAN when dealing with big-endian PDU's
90          */
91         bool endian;
92
93         /* This context is used for PDU data and is freed between each pdu.
94                 Don't use for pipe state storage. */
95         TALLOC_CTX *mem_ctx;
96
97         /* handle database to use on this pipe. */
98         struct handle_list *pipe_handles;
99
100         /* call id retrieved from the pdu header */
101         uint32_t call_id;
102
103         /* operation number retrieved from the rpc header */
104         uint16_t opnum;
105
106         /* private data for the interface implementation */
107         void *private_data;
108
109 };
110
111 int make_base_pipes_struct(TALLOC_CTX *mem_ctx,
112                            struct messaging_context *msg_ctx,
113                            const char *pipe_name,
114                            enum dcerpc_transport_t transport,
115                            bool endian,
116                            const struct tsocket_address *remote_address,
117                            const struct tsocket_address *local_address,
118                            struct pipes_struct **_p);
119 bool check_open_pipes(void);
120 int close_internal_rpc_pipe_hnd(struct pipes_struct *p);
121
122 size_t num_pipe_handles(struct pipes_struct *p);
123 bool init_pipe_handles(struct pipes_struct *p, const struct ndr_syntax_id *syntax);
124 bool create_policy_hnd(struct pipes_struct *p,
125                         struct policy_handle *hnd,
126                         uint8_t handle_type,
127                         void *data_ptr);
128 bool find_policy_by_hnd(struct pipes_struct *p, const struct policy_handle *hnd,
129                         void **data_p);
130 bool close_policy_hnd(struct pipes_struct *p, struct policy_handle *hnd);
131 void close_policy_by_pipe(struct pipes_struct *p);
132 bool pipe_access_check(struct pipes_struct *p);
133
134 void *_policy_handle_create(struct pipes_struct *p,
135                         struct policy_handle *hnd,
136                         uint8_t handle_type,
137                         uint32_t access_granted,
138                         size_t data_size,
139                         const char *type,
140                         NTSTATUS *pstatus);
141 #define policy_handle_create(_p, _hnd, _hnd_type, _access, _type, _pstatus) \
142         (_type *)_policy_handle_create((_p), (_hnd), (_hnd_type), (_access), sizeof(_type), #_type, \
143                                        (_pstatus))
144
145 void *_policy_handle_find(struct pipes_struct *p,
146                           const struct policy_handle *hnd,
147                           uint32_t access_required, uint32_t *paccess_granted,
148                           const char *name, const char *location,
149                           NTSTATUS *pstatus);
150 #define policy_handle_find(_p, _hnd, _access_required, _access_granted, _type, _pstatus) \
151         (_type *)_policy_handle_find((_p), (_hnd), (_access_required), \
152                                      (_access_granted), #_type, __location__, (_pstatus))
153
154 #endif /* _RPC_PIPES_H_ */