r22472: Commit the start of the DRSUAPI pull replication service.
[jelmer/samba4-debian.git] / source / 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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20    
21 */
22
23 #ifndef _DSDB_REPL_DREPL_SERVICE_H_
24 #define _DSDB_REPL_DREPL_SERVICE_H_
25
26 #include "librpc/gen_ndr/ndr_drsuapi_c.h"
27
28 struct dreplsrv_service;
29 struct dreplsrv_partition;
30
31 struct dreplsrv_drsuapi_connection {
32         /*
33          * this pipe pointer is also the indicator
34          * for a valid connection
35          */
36         struct dcerpc_pipe *pipe;
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 reference to the source_dsa and its outgoing connection */
74         struct dreplsrv_out_connection *conn;
75 };
76
77 struct dreplsrv_partition {
78         struct dreplsrv_partition *prev, *next;
79
80         struct dreplsrv_service *service;
81
82         /* the dn of the partition */
83         struct ldb_dn *dn;
84         struct drsuapi_DsReplicaObjectIdentifier nc;
85
86         /* 
87          * uptodate vector needs to be updated before and after each DsGetNCChanges() call
88          *
89          * - before: we need to use our own invocationId together with our highestCommitedUsn
90          * - after: we need to merge in the remote uptodatevector, to avoid reading it again
91          */
92         struct replUpToDateVectorCtr2 uptodatevector;
93         struct drsuapi_DsReplicaCursorCtrEx uptodatevector_ex;
94
95         /*
96          * a linked list of all source dsa's we replicate from
97          */
98         struct dreplsrv_partition_source_dsa *sources;
99 };
100
101 struct dreplsrv_out_operation {
102         struct dreplsrv_out_operation *prev, *next;
103
104         struct dreplsrv_service *service;
105
106         struct dreplsrv_partition_source_dsa *source_dsa;
107
108         struct composite_context *creq;
109 };
110
111 struct dreplsrv_service {
112         /* the whole drepl service is in one task */
113         struct task_server *task;
114
115         /* the time the service was started */
116         struct timeval startup_time;
117
118         /* 
119          * system session info
120          * with machine account credentials
121          */
122         struct auth_session_info *system_session_info;
123
124         /*
125          * a connection to the local samdb
126          */
127         struct ldb_context *samdb;
128
129         /* the guid of our NTDS Settings object, which never changes! */
130         struct GUID ntds_guid;
131         /*
132          * the struct holds the values used for outgoing DsBind() calls,
133          * so that we need to set them up only once
134          */
135         struct drsuapi_DsBindInfo28 bind_info28;
136
137         /* some stuff for periodic processing */
138         struct {
139                 /*
140                  * the interval between to periodic runs
141                  */
142                 uint32_t interval;
143
144                 /*
145                  * the timestamp for the next event,
146                  * this is the timstamp passed to event_add_timed()
147                  */
148                 struct timeval next_event;
149
150                 /* here we have a reference to the timed event the schedules the periodic stuff */
151                 struct timed_event *te;
152         } periodic;
153
154         /*
155          * the list of partitions we need to replicate
156          */
157         struct dreplsrv_partition *partitions;
158
159         /*
160          * the list of cached connections
161          */
162         struct dreplsrv_out_connection *connections;
163
164         struct {        
165                 /* the pointer to the current active operation */
166                 struct dreplsrv_out_operation *current;
167
168                 /* the list of pending operations */
169                 struct dreplsrv_out_operation *pending;
170         } ops;
171 };
172
173 #include "dsdb/repl/drepl_out_helpers.h"
174 #include "dsdb/repl/drepl_service_proto.h"
175
176 #endif /* _DSDB_REPL_DREPL_SERVICE_H_ */