2 Unix SMB/CIFS Implementation.
3 KCC service periodic handling
5 Copyright (C) Andrew Tridgell 2009
6 based on repl service code
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 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "lib/events/events.h"
25 #include "dsdb/samdb/samdb.h"
26 #include "auth/auth.h"
27 #include "samba/service.h"
28 #include "lib/messaging/irpc.h"
29 #include "dsdb/kcc/kcc_connection.h"
30 #include "dsdb/kcc/kcc_service.h"
31 #include <ldb_errors.h>
32 #include "../lib/util/dlinklist.h"
33 #include "librpc/gen_ndr/ndr_misc.h"
34 #include "librpc/gen_ndr/ndr_drsuapi.h"
35 #include "librpc/gen_ndr/ndr_drsblobs.h"
36 #include "librpc/gen_ndr/ndr_irpc_c.h"
37 #include "param/param.h"
38 #include "dsdb/common/util.h"
41 * see if two repsFromToBlob blobs are for the same source DSA
43 static bool kccsrv_same_source_dsa(struct repsFromToBlob
*r1
, struct repsFromToBlob
*r2
)
45 return GUID_equal(&r1
->ctr
.ctr1
.source_dsa_obj_guid
,
46 &r2
->ctr
.ctr1
.source_dsa_obj_guid
);
50 * see if a repsFromToBlob is in a list
52 static bool reps_in_list(struct repsFromToBlob
*r
, struct repsFromToBlob
*reps
, uint32_t count
)
55 for (i
=0; i
<count
; i
++) {
56 if (kccsrv_same_source_dsa(r
, &reps
[i
])) {
64 make sure we only add repsFrom entries for DCs who are masters for
67 static bool check_MasterNC(struct kccsrv_service
*service
, struct dsdb_ldb_dn_list_node
*p
, struct repsFromToBlob
*r
,
68 struct ldb_result
*res
)
70 struct repsFromTo1
*r1
= &r
->ctr
.ctr1
;
71 struct GUID invocation_id
= r1
->source_dsa_invocation_id
;
75 /* we are expecting only version 1 */
76 SMB_ASSERT(r
->version
== 1);
78 tmp_ctx
= talloc_new(p
);
83 for (i
=0; i
<res
->count
; i
++) {
84 struct ldb_message
*msg
= res
->msgs
[i
];
85 struct ldb_message_element
*el
;
88 struct GUID id2
= samdb_result_guid(msg
, "invocationID");
89 if (GUID_all_zero(&id2
) ||
90 !GUID_equal(&invocation_id
, &id2
)) {
94 el
= ldb_msg_find_element(msg
, "msDS-hasMasterNCs");
95 if (!el
|| el
->num_values
== 0) {
96 el
= ldb_msg_find_element(msg
, "hasMasterNCs");
97 if (!el
|| el
->num_values
== 0) {
101 for (j
=0; j
<el
->num_values
; j
++) {
102 dn
= ldb_dn_from_ldb_val(tmp_ctx
, service
->samdb
, &el
->values
[j
]);
103 if (!ldb_dn_validate(dn
)) {
107 if (ldb_dn_compare(dn
, p
->dn
) == 0) {
108 DEBUG(5,("%s %s match on %s in %s\n",
109 r1
->other_info
->dns_name
,
111 ldb_dn_get_linearized(dn
),
112 ldb_dn_get_linearized(msg
->dn
)));
113 talloc_free(tmp_ctx
);
119 talloc_free(tmp_ctx
);
123 struct kccsrv_notify_drepl_server_state
{
124 struct dreplsrv_refresh r
;
127 static void kccsrv_notify_drepl_server_done(struct tevent_req
*subreq
);
130 * Force dreplsrv to update its state as topology is changed
132 static void kccsrv_notify_drepl_server(struct kccsrv_service
*s
,
135 struct kccsrv_notify_drepl_server_state
*state
;
136 struct dcerpc_binding_handle
*irpc_handle
;
137 struct tevent_req
*subreq
;
139 state
= talloc_zero(s
, struct kccsrv_notify_drepl_server_state
);
144 irpc_handle
= irpc_binding_handle_by_name(state
, s
->task
->msg_ctx
,
145 "dreplsrv", &ndr_table_irpc
);
146 if (irpc_handle
== NULL
) {
147 /* dreplsrv is not running yet */
152 subreq
= dcerpc_dreplsrv_refresh_r_send(state
, s
->task
->event_ctx
,
153 irpc_handle
, &state
->r
);
154 if (subreq
== NULL
) {
158 tevent_req_set_callback(subreq
, kccsrv_notify_drepl_server_done
, state
);
161 static void kccsrv_notify_drepl_server_done(struct tevent_req
*subreq
)
163 struct kccsrv_notify_drepl_server_state
*state
=
164 tevent_req_callback_data(subreq
,
165 struct kccsrv_notify_drepl_server_state
);
167 dcerpc_dreplsrv_refresh_r_recv(subreq
, state
);
170 /* we don't care about errors */
174 uint32_t kccsrv_replica_flags(struct kccsrv_service
*s
)
177 return DRSUAPI_DRS_INIT_SYNC
|
178 DRSUAPI_DRS_PER_SYNC
|
179 DRSUAPI_DRS_ADD_REF
|
180 DRSUAPI_DRS_SPECIAL_SECRET_PROCESSING
|
181 DRSUAPI_DRS_NONGC_RO_REP
;
183 return DRSUAPI_DRS_INIT_SYNC
|
184 DRSUAPI_DRS_PER_SYNC
|
185 DRSUAPI_DRS_ADD_REF
|
186 DRSUAPI_DRS_WRIT_REP
;
190 * add any missing repsFrom structures to our partitions
192 NTSTATUS
kccsrv_add_repsFrom(struct kccsrv_service
*s
, TALLOC_CTX
*mem_ctx
,
193 struct repsFromToBlob
*reps
, uint32_t count
,
194 struct ldb_result
*res
)
196 struct dsdb_ldb_dn_list_node
*p
;
197 bool notify_dreplsrv
= false;
198 uint32_t replica_flags
= kccsrv_replica_flags(s
);
200 /* update the repsFrom on all partitions */
201 for (p
=s
->partitions
; p
; p
=p
->next
) {
202 struct repsFromToBlob
*our_reps
;
206 bool modified
= false;
208 werr
= dsdb_loadreps(s
->samdb
, mem_ctx
, p
->dn
, "repsFrom", &our_reps
, &our_count
);
209 if (!W_ERROR_IS_OK(werr
)) {
210 DEBUG(0,(__location__
": Failed to load repsFrom from %s - %s\n",
211 ldb_dn_get_linearized(p
->dn
), ldb_errstring(s
->samdb
)));
212 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
215 /* see if the entry already exists */
216 for (i
=0; i
<count
; i
++) {
217 for (j
=0; j
<our_count
; j
++) {
218 if (kccsrv_same_source_dsa(&reps
[i
], &our_reps
[j
])) {
219 /* we already have this one -
220 check the replica_flags are right */
221 if (replica_flags
!= our_reps
[j
].ctr
.ctr1
.replica_flags
) {
222 /* we need to update the old one with
225 our_reps
[j
].ctr
.ctr1
.replica_flags
= replica_flags
;
231 if (j
== our_count
) {
232 /* we don't have the new one - add it
235 if (res
&& !check_MasterNC(s
, p
, &reps
[i
], res
)) {
236 /* its not a master, we don't
237 want to pull from it */
240 /* we need to add it to our repsFrom */
241 our_reps
= talloc_realloc(mem_ctx
, our_reps
, struct repsFromToBlob
, our_count
+1);
242 NT_STATUS_HAVE_NO_MEMORY(our_reps
);
243 our_reps
[our_count
] = reps
[i
];
244 our_reps
[our_count
].ctr
.ctr1
.replica_flags
= replica_flags
;
247 DEBUG(4,(__location__
": Added repsFrom for %s\n",
248 reps
[i
].ctr
.ctr1
.other_info
->dns_name
));
252 /* remove any stale ones */
253 for (i
=0; i
<our_count
; i
++) {
254 if (!reps_in_list(&our_reps
[i
], reps
, count
) ||
255 (res
&& !check_MasterNC(s
, p
, &our_reps
[i
], res
))) {
256 DEBUG(4,(__location__
": Removed repsFrom for %s\n",
257 our_reps
[i
].ctr
.ctr1
.other_info
->dns_name
));
258 memmove(&our_reps
[i
], &our_reps
[i
+1], (our_count
-(i
+1))*sizeof(our_reps
[0]));
266 werr
= dsdb_savereps(s
->samdb
, mem_ctx
, p
->dn
, "repsFrom", our_reps
, our_count
);
267 if (!W_ERROR_IS_OK(werr
)) {
268 DEBUG(0,(__location__
": Failed to save repsFrom to %s - %s\n",
269 ldb_dn_get_linearized(p
->dn
), ldb_errstring(s
->samdb
)));
270 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
272 /* dreplsrv should refresh its state */
273 notify_dreplsrv
= true;
276 /* remove stale repsTo entries */
278 werr
= dsdb_loadreps(s
->samdb
, mem_ctx
, p
->dn
, "repsTo", &our_reps
, &our_count
);
279 if (!W_ERROR_IS_OK(werr
)) {
280 DEBUG(0,(__location__
": Failed to load repsTo from %s - %s\n",
281 ldb_dn_get_linearized(p
->dn
), ldb_errstring(s
->samdb
)));
282 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
285 /* remove any stale ones */
286 for (i
=0; i
<our_count
; i
++) {
287 if (!reps_in_list(&our_reps
[i
], reps
, count
)) {
288 DEBUG(4,(__location__
": Removed repsTo for %s\n",
289 our_reps
[i
].ctr
.ctr1
.other_info
->dns_name
));
290 memmove(&our_reps
[i
], &our_reps
[i
+1], (our_count
-(i
+1))*sizeof(our_reps
[0]));
298 werr
= dsdb_savereps(s
->samdb
, mem_ctx
, p
->dn
, "repsTo", our_reps
, our_count
);
299 if (!W_ERROR_IS_OK(werr
)) {
300 DEBUG(0,(__location__
": Failed to save repsTo to %s - %s\n",
301 ldb_dn_get_linearized(p
->dn
), ldb_errstring(s
->samdb
)));
302 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
304 /* dreplsrv should refresh its state */
305 notify_dreplsrv
= true;
309 /* notify dreplsrv toplogy has changed */
310 if (notify_dreplsrv
) {
311 kccsrv_notify_drepl_server(s
, mem_ctx
);
320 form a unique list of DNs from a search result and a given set of attributes
322 static int kccsrv_dn_list(struct ldb_context
*ldb
, struct ldb_result
*res
,
325 struct ldb_dn
***dn_list
, int *dn_count
)
328 struct ldb_dn
**nc_list
= NULL
;
331 nc_list
= talloc_array(mem_ctx
, struct ldb_dn
*, 0);
332 if (nc_list
== NULL
) {
333 return LDB_ERR_OPERATIONS_ERROR
;
336 /* gather up a list of all NCs in this forest */
337 for (i
=0; i
<res
->count
; i
++) {
338 struct ldb_message
*msg
= res
->msgs
[i
];
340 for (j
=0; attrs
[j
]; j
++) {
341 struct ldb_message_element
*el
;
344 el
= ldb_msg_find_element(msg
, attrs
[j
]);
345 if (el
== NULL
) continue;
346 for (k
=0; k
<el
->num_values
; k
++) {
348 dn
= ldb_dn_from_ldb_val(nc_list
, ldb
, &el
->values
[k
]);
351 for (l
=0; l
<nc_count
; l
++) {
352 if (ldb_dn_compare(nc_list
[l
], dn
) == 0) break;
354 if (l
< nc_count
) continue;
355 nc_list
= talloc_realloc(mem_ctx
, nc_list
, struct ldb_dn
*, nc_count
+1);
356 if (nc_list
== NULL
) {
357 return LDB_ERR_OPERATIONS_ERROR
;
359 nc_list
[nc_count
] = dn
;
366 (*dn_list
) = nc_list
;
367 (*dn_count
) = nc_count
;
373 look for any additional global catalog partitions that we should be
374 replicating (by looking for msDS-HasDomainNCs), and add them to our
375 hasPartialReplicaNCs NTDS attribute
377 static int kccsrv_gc_update(struct kccsrv_service
*s
, struct ldb_result
*res
)
380 struct ldb_dn
**nc_list
= NULL
;
382 struct ldb_dn
**our_nc_list
= NULL
;
383 int our_nc_count
= 0;
384 const char *attrs1
[] = { "msDS-hasMasterNCs", "hasMasterNCs", "msDS-HasDomainNCs", NULL
};
385 const char *attrs2
[] = { "msDS-hasMasterNCs", "hasMasterNCs", "msDS-HasDomainNCs", "hasPartialReplicaNCs", NULL
};
387 TALLOC_CTX
*tmp_ctx
= talloc_new(res
);
388 struct ldb_result
*res2
;
389 struct ldb_message
*msg
;
391 /* get a complete list of NCs for the forest */
392 ret
= kccsrv_dn_list(s
->samdb
, res
, tmp_ctx
, attrs1
, &nc_list
, &nc_count
);
393 if (ret
!= LDB_SUCCESS
) {
394 DEBUG(1,("Failed to get NC list for GC update - %s\n", ldb_errstring(s
->samdb
)));
395 talloc_free(tmp_ctx
);
399 /* get a list of what NCs we are already replicating */
400 ret
= dsdb_search_dn(s
->samdb
, tmp_ctx
, &res2
, samdb_ntds_settings_dn(s
->samdb
, tmp_ctx
), attrs2
, 0);
401 if (ret
!= LDB_SUCCESS
) {
402 DEBUG(1,("Failed to get our NC list attributes for GC update - %s\n", ldb_errstring(s
->samdb
)));
403 talloc_free(tmp_ctx
);
407 ret
= kccsrv_dn_list(s
->samdb
, res2
, tmp_ctx
, attrs2
, &our_nc_list
, &our_nc_count
);
408 if (ret
!= LDB_SUCCESS
) {
409 DEBUG(1,("Failed to get our NC list for GC update - %s\n", ldb_errstring(s
->samdb
)));
410 talloc_free(tmp_ctx
);
414 msg
= ldb_msg_new(tmp_ctx
);
416 talloc_free(tmp_ctx
);
417 return LDB_ERR_OPERATIONS_ERROR
;
419 msg
->dn
= res2
->msgs
[0]->dn
;
421 /* see if we are missing any */
422 for (i
=0; i
<nc_count
; i
++) {
424 for (j
=0; j
<our_nc_count
; j
++) {
425 if (ldb_dn_compare(nc_list
[i
], our_nc_list
[j
]) == 0) break;
427 if (j
== our_nc_count
) {
429 ret
= ldb_msg_add_string(msg
, "hasPartialReplicaNCs",
430 ldb_dn_get_extended_linearized(msg
, nc_list
[i
], 1));
431 if (ret
!= LDB_SUCCESS
) {
432 talloc_free(tmp_ctx
);
439 if (msg
->num_elements
== 0) {
441 talloc_free(tmp_ctx
);
446 DEBUG(5, ("%d partial replica should be added but we are RODC so we skip\n", msg
->num_elements
));
447 talloc_free(tmp_ctx
);
451 msg
->elements
[0].flags
= LDB_FLAG_MOD_ADD
;
453 ret
= dsdb_modify(s
->samdb
, msg
, 0);
454 if (ret
!= LDB_SUCCESS
) {
455 DEBUG(0,("Failed to add hasPartialReplicaNCs - %s\n",
456 ldb_errstring(s
->samdb
)));
459 talloc_free(tmp_ctx
);
465 this is the core of our initial simple KCC
466 We just add a repsFrom entry for all DCs we find that have nTDSDSA
467 objects, except for ourselves
469 NTSTATUS
kccsrv_simple_update(struct kccsrv_service
*s
, TALLOC_CTX
*mem_ctx
)
471 struct ldb_result
*res
;
474 const char *attrs
[] = { "objectGUID", "invocationID", "msDS-hasMasterNCs", "hasMasterNCs", "msDS-HasDomainNCs", NULL
};
475 struct repsFromToBlob
*reps
= NULL
;
477 struct kcc_connection_list
*ntds_conn
, *dsa_conn
;
479 ret
= dsdb_search(s
->samdb
, mem_ctx
, &res
, s
->config_dn
, LDB_SCOPE_SUBTREE
,
480 attrs
, DSDB_SEARCH_SHOW_EXTENDED_DN
, "objectClass=nTDSDSA");
481 if (ret
!= LDB_SUCCESS
) {
482 DEBUG(0,(__location__
": Failed nTDSDSA search - %s\n", ldb_errstring(s
->samdb
)));
483 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
486 if (samdb_is_gc(s
->samdb
)) {
487 kccsrv_gc_update(s
, res
);
490 /* get the current list of connections */
491 ntds_conn
= kccsrv_find_connections(s
, mem_ctx
);
493 dsa_conn
= talloc_zero(mem_ctx
, struct kcc_connection_list
);
495 for (i
=0; i
<res
->count
; i
++) {
496 struct repsFromTo1
*r1
;
497 struct GUID ntds_guid
, invocation_id
;
499 ntds_guid
= samdb_result_guid(res
->msgs
[i
], "objectGUID");
500 if (GUID_equal(&ntds_guid
, &s
->ntds_guid
)) {
501 /* don't replicate with ourselves */
505 invocation_id
= samdb_result_guid(res
->msgs
[i
], "invocationID");
507 reps
= talloc_realloc(mem_ctx
, reps
, struct repsFromToBlob
, count
+1);
508 NT_STATUS_HAVE_NO_MEMORY(reps
);
510 ZERO_STRUCT(reps
[count
]);
511 reps
[count
].version
= 1;
512 r1
= &reps
[count
].ctr
.ctr1
;
514 r1
->other_info
= talloc_zero(reps
, struct repsFromTo1OtherInfo
);
515 r1
->other_info
->dns_name
= samdb_ntds_msdcs_dns_name(s
->samdb
, reps
, &ntds_guid
);
516 r1
->source_dsa_obj_guid
= ntds_guid
;
517 r1
->source_dsa_invocation_id
= invocation_id
;
518 r1
->replica_flags
= kccsrv_replica_flags(s
);
519 memset(r1
->schedule
, 0x11, sizeof(r1
->schedule
));
521 dsa_conn
->servers
= talloc_realloc(dsa_conn
, dsa_conn
->servers
,
522 struct kcc_connection
,
523 dsa_conn
->count
+ 1);
524 NT_STATUS_HAVE_NO_MEMORY(dsa_conn
->servers
);
525 dsa_conn
->servers
[dsa_conn
->count
].dsa_guid
= r1
->source_dsa_obj_guid
;
531 kccsrv_apply_connections(s
, ntds_conn
, dsa_conn
);
533 return kccsrv_add_repsFrom(s
, mem_ctx
, reps
, count
, res
);
537 static void kccsrv_periodic_run(struct kccsrv_service
*service
);
539 static void kccsrv_periodic_handler_te(struct tevent_context
*ev
, struct tevent_timer
*te
,
540 struct timeval t
, void *ptr
)
542 struct kccsrv_service
*service
= talloc_get_type(ptr
, struct kccsrv_service
);
545 service
->periodic
.te
= NULL
;
547 kccsrv_periodic_run(service
);
549 status
= kccsrv_periodic_schedule(service
, service
->periodic
.interval
);
550 if (!W_ERROR_IS_OK(status
)) {
551 task_server_terminate(service
->task
, win_errstr(status
), true);
556 WERROR
kccsrv_periodic_schedule(struct kccsrv_service
*service
, uint32_t next_interval
)
559 struct tevent_timer
*new_te
;
560 struct timeval next_time
;
562 /* prevent looping */
563 if (next_interval
== 0) next_interval
= 1;
565 next_time
= timeval_current_ofs(next_interval
, 50);
567 if (service
->periodic
.te
) {
569 * if the timestamp of the new event is higher,
570 * as current next we don't need to reschedule
572 if (timeval_compare(&next_time
, &service
->periodic
.next_event
) > 0) {
577 /* reset the next scheduled timestamp */
578 service
->periodic
.next_event
= next_time
;
580 new_te
= tevent_add_timer(service
->task
->event_ctx
, service
,
581 service
->periodic
.next_event
,
582 kccsrv_periodic_handler_te
, service
);
583 W_ERROR_HAVE_NO_MEMORY(new_te
);
585 tmp_mem
= talloc_new(service
);
586 DEBUG(4,("kccsrv_periodic_schedule(%u) %sscheduled for: %s\n",
588 (service
->periodic
.te
?"re":""),
589 nt_time_string(tmp_mem
, timeval_to_nttime(&next_time
))));
590 talloc_free(tmp_mem
);
592 talloc_free(service
->periodic
.te
);
593 service
->periodic
.te
= new_te
;
599 * Check to see if any dns entries need scavenging. This only occurs if aging
600 * is enabled in general ("zone scavenging" lpcfg) and on the zone
601 * (zone->fAging is true).
603 static NTSTATUS
kccsrv_dns_zone_scavenging(
604 struct kccsrv_service
*s
,
608 time_t current_time
= time(NULL
);
609 time_t dns_scavenge_interval
;
611 char *error_string
= NULL
;
614 * Only perform zone scavenging if it's been enabled.
615 * (it still might be disabled on all zones).
617 if (!lpcfg_dns_zone_scavenging(s
->task
->lp_ctx
)) {
618 DBG_INFO("DNS scavenging not enabled\n");
622 dns_scavenge_interval
= lpcfg_parm_int(s
->task
->lp_ctx
,
625 "scavenging_interval",
627 if ((current_time
- s
->last_dns_scavenge
) > dns_scavenge_interval
) {
628 s
->last_dns_scavenge
= current_time
;
629 status
= dns_tombstone_records(mem_ctx
, s
->samdb
,
631 if (!NT_STATUS_IS_OK(status
)) {
632 const char *err
= NULL
;
633 if (error_string
!= NULL
) {
636 err
= nt_errstr(status
);
638 DBG_ERR("DNS record scavenging process failed: %s\n",
643 DBG_INFO("Successfully tombstoned stale DNS records\n");
647 * check to see if any dns tombstones should be deleted. This is not optional
648 * ([MS-DNSP] "DsTombstoneInterval") -- stale tombstones are useless clutter.
650 * Windows does it daily at 2am; we do it roughly daily at an uncontrolled
653 static NTSTATUS
kccsrv_dns_zone_tombstone_deletion(struct kccsrv_service
*s
,
656 time_t current_time
= time(NULL
);
658 char *error_string
= NULL
;
659 time_t dns_collection_interval
=
660 lpcfg_parm_int(s
->task
->lp_ctx
,
663 "tombstone_collection_interval",
666 if ((current_time
- s
->last_dns_tombstone_collection
) >
667 dns_collection_interval
) {
668 s
->last_dns_tombstone_collection
= current_time
;
669 status
= dns_delete_tombstones(mem_ctx
, s
->samdb
,
671 if (!NT_STATUS_IS_OK(status
)) {
672 const char *err
= NULL
;
673 if (error_string
!= NULL
) {
676 err
= nt_errstr(status
);
678 DBG_ERR("DNS tombstone deletion failed: %s\n", err
);
682 DBG_INFO("Successfully deleted DNS tombstones\n");
687 check to see if any deleted objects need scavenging
689 static NTSTATUS
kccsrv_check_deleted(struct kccsrv_service
*s
, TALLOC_CTX
*mem_ctx
)
691 time_t current_time
= time(NULL
);
692 time_t interval
= lpcfg_parm_int(
693 s
->task
->lp_ctx
, NULL
, "kccsrv", "check_deleted_interval", 86400);
694 uint32_t tombstoneLifetime
;
696 unsigned int num_objects_removed
= 0;
697 unsigned int num_links_removed
= 0;
699 char *error_string
= NULL
;
701 if (current_time
- s
->last_deleted_check
< interval
) {
705 ret
= dsdb_tombstone_lifetime(s
->samdb
, &tombstoneLifetime
);
706 if (ret
!= LDB_SUCCESS
) {
707 DEBUG(1,(__location__
": Failed to get tombstone lifetime\n"));
708 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
711 s
->last_deleted_check
= current_time
;
713 status
= dsdb_garbage_collect_tombstones(mem_ctx
, s
->samdb
,
715 current_time
, tombstoneLifetime
,
716 &num_objects_removed
,
720 if (NT_STATUS_IS_OK(status
)) {
721 DEBUG(5, ("garbage_collect_tombstones: Removed %u tombstone objects "
722 "and %u tombstone links successfully\n",
723 num_objects_removed
, num_links_removed
));
725 DEBUG(2, ("garbage_collect_tombstones: Failure removing tombstone "
726 "objects and links after removing %u tombstone objects "
727 "and %u tombstone links successfully: %s\n",
728 num_objects_removed
, num_links_removed
,
729 error_string
? error_string
: nt_errstr(status
)));
734 static void kccsrv_periodic_run(struct kccsrv_service
*service
)
739 DEBUG(4,("kccsrv_periodic_run(): update\n"));
741 mem_ctx
= talloc_new(service
);
743 if (service
->samba_kcc_code
)
744 status
= kccsrv_samba_kcc(service
);
746 status
= kccsrv_simple_update(service
, mem_ctx
);
747 if (!NT_STATUS_IS_OK(status
))
748 DEBUG(0,("kccsrv_simple_update failed - %s\n",
752 status
= kccsrv_check_deleted(service
, mem_ctx
);
753 if (!NT_STATUS_IS_OK(status
)) {
754 DEBUG(0,("kccsrv_check_deleted failed - %s\n", nt_errstr(status
)));
756 status
= kccsrv_dns_zone_scavenging(service
, mem_ctx
);
757 if (!NT_STATUS_IS_OK(status
)) {
758 DBG_ERR("kccsrv_dns_zone_aging failed - %s\n",
761 status
= kccsrv_dns_zone_tombstone_deletion(service
, mem_ctx
);
762 if (!NT_STATUS_IS_OK(status
)) {
763 DBG_ERR("kccsrv_dns_zone_tombstone_scavenging failed - %s\n",
766 talloc_free(mem_ctx
);
769 /* Called when samba_kcc script has finished
771 static void samba_kcc_done(struct tevent_req
*subreq
)
773 struct kccsrv_service
*service
=
774 tevent_req_callback_data(subreq
, struct kccsrv_service
);
778 service
->periodic
.subreq
= NULL
;
780 rc
= samba_runcmd_recv(subreq
, &sys_errno
);
784 service
->periodic
.status
=
785 map_nt_error_from_unix_common(sys_errno
);
787 service
->periodic
.status
= NT_STATUS_OK
;
789 if (!NT_STATUS_IS_OK(service
->periodic
.status
))
790 DEBUG(0,(__location__
": Failed samba_kcc - %s\n",
791 nt_errstr(service
->periodic
.status
)));
793 DEBUG(3,("Completed samba_kcc OK\n"));
796 /* Invocation of the samba_kcc python script for replication
797 * topology generation.
799 NTSTATUS
kccsrv_samba_kcc(struct kccsrv_service
*service
)
801 NTSTATUS status
= NT_STATUS_OK
;
802 const char * const *samba_kcc_command
=
803 lpcfg_samba_kcc_command(service
->task
->lp_ctx
);
805 /* kill any existing child */
806 TALLOC_FREE(service
->periodic
.subreq
);
808 DEBUG(2, ("Calling samba_kcc script\n"));
809 service
->periodic
.subreq
= samba_runcmd_send(service
,
810 service
->task
->event_ctx
,
811 timeval_current_ofs(40, 0),
812 2, 0, samba_kcc_command
, NULL
);
814 if (service
->periodic
.subreq
== NULL
) {
815 status
= NT_STATUS_NO_MEMORY
;
818 tevent_req_set_callback(service
->periodic
.subreq
,
819 samba_kcc_done
, service
);
822 if (!NT_STATUS_IS_OK(status
))
823 DEBUG(0,(__location__
": failed - %s\n", nt_errstr(status
)));