c454ac618ad2285a678d6f9549841cd01c2e159b
[rusty/samba.git] / source4 / dsdb / repl / drepl_service.h
1 /* 
2    Unix SMB/CIFS mplementation.
3    DSDB replication service
4    
5    Copyright (C) Stefan Metzmacher 2007
6     
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19    
20 */
21
22 #ifndef _DSDB_REPL_DREPL_SERVICE_H_
23 #define _DSDB_REPL_DREPL_SERVICE_H_
24
25 #include "librpc/gen_ndr/ndr_drsuapi_c.h"
26
27 struct dreplsrv_service;
28 struct dreplsrv_partition;
29
30 struct dreplsrv_drsuapi_connection {
31         /*
32          * this pipe pointer is also the indicator
33          * for a valid connection
34          */
35         struct dcerpc_pipe *pipe;
36         struct dcerpc_binding_handle *drsuapi_handle;
37
38         DATA_BLOB gensec_skey;
39         struct drsuapi_DsBindInfo28 remote_info28;
40         struct policy_handle bind_handle;
41 };
42
43 struct dreplsrv_out_connection {
44         struct dreplsrv_out_connection *prev, *next;
45
46         struct dreplsrv_service *service;
47
48         /*
49          * the binding for the outgoing connection
50          */
51         struct dcerpc_binding *binding;
52
53         /* the out going connection to the source dsa */
54         struct dreplsrv_drsuapi_connection *drsuapi;
55
56         /* used to force the GC principal name */
57         const char *principal_name;
58 };
59
60 struct dreplsrv_partition_source_dsa {
61         struct dreplsrv_partition_source_dsa *prev, *next;
62
63         struct dreplsrv_partition *partition;
64
65         /*
66          * the cached repsFrom value for this source dsa
67          *
68          * it needs to be updated after each DsGetNCChanges() call
69          * to the source dsa
70          *
71          * repsFrom1 == &_repsFromBlob.ctr.ctr1
72          */
73         struct repsFromToBlob _repsFromBlob;
74         struct repsFromTo1 *repsFrom1;
75
76         /* the last uSN when we sent a notify */
77         uint64_t notify_uSN;
78         
79         /* the reference to the source_dsa and its outgoing connection */
80         struct dreplsrv_out_connection *conn;
81 };
82
83 struct dreplsrv_partition {
84         struct dreplsrv_partition *prev, *next;
85
86         struct dreplsrv_service *service;
87
88         /* the dn of the partition */
89         struct ldb_dn *dn;
90         struct drsuapi_DsReplicaObjectIdentifier nc;
91
92         /* 
93          * uptodate vector needs to be updated before and after each DsGetNCChanges() call
94          *
95          * - before: we need to use our own invocationId together with our highestCommitedUsn
96          * - after: we need to merge in the remote uptodatevector, to avoid reading it again
97          */
98         struct replUpToDateVectorCtr2 uptodatevector;
99         struct drsuapi_DsReplicaCursorCtrEx uptodatevector_ex;
100
101         /*
102          * a linked list of all source dsa's we replicate from
103          */
104         struct dreplsrv_partition_source_dsa *sources;
105
106         /*
107          * a linked list of all source dsa's we will notify,
108          * that are not also in sources
109          */
110         struct dreplsrv_partition_source_dsa *notifies;
111
112         bool incoming_only;
113 };
114
115 typedef void (*dreplsrv_extended_callback_t)(struct dreplsrv_service *,
116                                              WERROR,
117                                              enum drsuapi_DsExtendedError,
118                                              void *cb_data);
119
120 struct dreplsrv_out_operation {
121         struct dreplsrv_out_operation *prev, *next;
122         time_t schedule_time;
123
124         struct dreplsrv_service *service;
125
126         struct dreplsrv_partition_source_dsa *source_dsa;
127
128         /* replication options - currently used by DsReplicaSync */
129         uint32_t options;
130         enum drsuapi_DsExtendedOperation extended_op;
131         uint64_t fsmo_info;
132         enum drsuapi_DsExtendedError extended_ret;
133         dreplsrv_extended_callback_t callback;
134         void *cb_data;
135 };
136
137 struct dreplsrv_notify_operation {
138         struct dreplsrv_notify_operation *prev, *next;
139         time_t schedule_time;
140
141         struct dreplsrv_service *service;
142         uint64_t uSN;
143
144         struct dreplsrv_partition_source_dsa *source_dsa;
145         bool is_urgent;
146         uint32_t replica_flags;
147 };
148
149 struct dreplsrv_service {
150         /* the whole drepl service is in one task */
151         struct task_server *task;
152
153         /* the time the service was started */
154         struct timeval startup_time;
155
156         /* 
157          * system session info
158          * with machine account credentials
159          */
160         struct auth_session_info *system_session_info;
161
162         /*
163          * a connection to the local samdb
164          */
165         struct ldb_context *samdb;
166
167         /* the guid of our NTDS Settings object, which never changes! */
168         struct GUID ntds_guid;
169         /*
170          * the struct holds the values used for outgoing DsBind() calls,
171          * so that we need to set them up only once
172          */
173         struct drsuapi_DsBindInfo28 bind_info28;
174
175         /* some stuff for periodic processing */
176         struct {
177                 /*
178                  * the interval between to periodic runs
179                  */
180                 uint32_t interval;
181
182                 /*
183                  * the timestamp for the next event,
184                  * this is the timstamp passed to event_add_timed()
185                  */
186                 struct timeval next_event;
187
188                 /* here we have a reference to the timed event the schedules the periodic stuff */
189                 struct tevent_timer *te;
190         } periodic;
191
192         /* some stuff for notify processing */
193         struct {
194                 /*
195                  * the interval between notify runs
196                  */
197                 uint32_t interval;
198
199                 /*
200                  * the timestamp for the next event,
201                  * this is the timstamp passed to event_add_timed()
202                  */
203                 struct timeval next_event;
204
205                 /* here we have a reference to the timed event the schedules the notifies */
206                 struct tevent_timer *te;
207         } notify;
208
209         /*
210          * the list of partitions we need to replicate
211          */
212         struct dreplsrv_partition *partitions;
213
214         /*
215          * the list of cached connections
216          */
217         struct dreplsrv_out_connection *connections;
218
219         struct {        
220                 /* the pointer to the current active operation */
221                 struct dreplsrv_out_operation *current;
222
223                 /* the list of pending operations */
224                 struct dreplsrv_out_operation *pending;
225
226                 /* the list of pending notify operations */
227                 struct dreplsrv_notify_operation *notifies;
228
229                 /* an active notify operation */
230                 struct dreplsrv_notify_operation *n_current;
231         } ops;
232
233         bool rid_alloc_in_progress;
234
235         bool am_rodc;
236 };
237
238 #include "lib/messaging/irpc.h"
239 #include "dsdb/repl/drepl_out_helpers.h"
240 #include "dsdb/repl/drepl_service_proto.h"
241
242 #endif /* _DSDB_REPL_DREPL_SERVICE_H_ */