s4-repl: add partial attribute set to getncchanges calls for RODCs
[metze/samba/wip.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
57 struct dreplsrv_partition_source_dsa {
58         struct dreplsrv_partition_source_dsa *prev, *next;
59
60         struct dreplsrv_partition *partition;
61
62         /*
63          * the cached repsFrom value for this source dsa
64          *
65          * it needs to be updated after each DsGetNCChanges() call
66          * to the source dsa
67          *
68          * repsFrom1 == &_repsFromBlob.ctr.ctr1
69          */
70         struct repsFromToBlob _repsFromBlob;
71         struct repsFromTo1 *repsFrom1;
72
73         /* the last uSN when we sent a notify */
74         uint64_t notify_uSN;
75         
76         /* the reference to the source_dsa and its outgoing connection */
77         struct dreplsrv_out_connection *conn;
78 };
79
80 struct dreplsrv_partition {
81         struct dreplsrv_partition *prev, *next;
82
83         struct dreplsrv_service *service;
84
85         /* the dn of the partition */
86         struct ldb_dn *dn;
87         struct drsuapi_DsReplicaObjectIdentifier nc;
88
89         /* 
90          * uptodate vector needs to be updated before and after each DsGetNCChanges() call
91          *
92          * - before: we need to use our own invocationId together with our highestCommitedUsn
93          * - after: we need to merge in the remote uptodatevector, to avoid reading it again
94          */
95         struct replUpToDateVectorCtr2 uptodatevector;
96         struct drsuapi_DsReplicaCursorCtrEx uptodatevector_ex;
97
98         /*
99          * a linked list of all source dsa's we replicate from
100          */
101         struct dreplsrv_partition_source_dsa *sources;
102
103         bool incoming_only;
104 };
105
106 typedef void (*dreplsrv_extended_callback_t)(struct dreplsrv_service *,
107                                              WERROR,
108                                              enum drsuapi_DsExtendedError,
109                                              void *cb_data);
110
111 struct dreplsrv_out_operation {
112         struct dreplsrv_out_operation *prev, *next;
113
114         struct dreplsrv_service *service;
115
116         struct dreplsrv_partition_source_dsa *source_dsa;
117
118         enum drsuapi_DsExtendedOperation extended_op;
119         uint64_t fsmo_info;
120         enum drsuapi_DsExtendedError extended_ret;
121         dreplsrv_extended_callback_t callback;
122         void *cb_data;
123 };
124
125 struct dreplsrv_notify_operation {
126         struct dreplsrv_notify_operation *prev, *next;
127
128         struct dreplsrv_service *service;
129         uint64_t uSN;
130
131         struct dreplsrv_partition_source_dsa *source_dsa;
132         bool is_urgent;
133 };
134
135 struct dreplsrv_service {
136         /* the whole drepl service is in one task */
137         struct task_server *task;
138
139         /* the time the service was started */
140         struct timeval startup_time;
141
142         /* 
143          * system session info
144          * with machine account credentials
145          */
146         struct auth_session_info *system_session_info;
147
148         /*
149          * a connection to the local samdb
150          */
151         struct ldb_context *samdb;
152
153         /* the guid of our NTDS Settings object, which never changes! */
154         struct GUID ntds_guid;
155         /*
156          * the struct holds the values used for outgoing DsBind() calls,
157          * so that we need to set them up only once
158          */
159         struct drsuapi_DsBindInfo28 bind_info28;
160
161         /* some stuff for periodic processing */
162         struct {
163                 /*
164                  * the interval between to periodic runs
165                  */
166                 uint32_t interval;
167
168                 /*
169                  * the timestamp for the next event,
170                  * this is the timstamp passed to event_add_timed()
171                  */
172                 struct timeval next_event;
173
174                 /* here we have a reference to the timed event the schedules the periodic stuff */
175                 struct tevent_timer *te;
176         } periodic;
177
178         /* some stuff for notify processing */
179         struct {
180                 /*
181                  * the interval between notify runs
182                  */
183                 uint32_t interval;
184
185                 /*
186                  * the timestamp for the next event,
187                  * this is the timstamp passed to event_add_timed()
188                  */
189                 struct timeval next_event;
190
191                 /* here we have a reference to the timed event the schedules the notifies */
192                 struct tevent_timer *te;
193         } notify;
194
195         /*
196          * the list of partitions we need to replicate
197          */
198         struct dreplsrv_partition *partitions;
199
200         /*
201          * the list of cached connections
202          */
203         struct dreplsrv_out_connection *connections;
204
205         struct {        
206                 /* the pointer to the current active operation */
207                 struct dreplsrv_out_operation *current;
208
209                 /* the list of pending operations */
210                 struct dreplsrv_out_operation *pending;
211
212                 /* the list of pending notify operations */
213                 struct dreplsrv_notify_operation *notifies;
214
215                 /* an active notify operation */
216                 struct dreplsrv_notify_operation *n_current;
217         } ops;
218
219         bool rid_alloc_in_progress;
220
221         bool syncall_workaround;
222
223         bool am_rodc;
224 };
225
226 #include "dsdb/repl/drepl_out_helpers.h"
227 #include "dsdb/repl/drepl_service_proto.h"
228
229 #endif /* _DSDB_REPL_DREPL_SERVICE_H_ */