📄 wrepl_apply_records.c
字号:
/* Unix SMB/CIFS implementation. WINS Replication server Copyright (C) Stefan Metzmacher 2005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.*/#include "includes.h"#include "smbd/service_task.h"#include "lib/messaging/irpc.h"#include "librpc/gen_ndr/ndr_irpc.h"#include "librpc/gen_ndr/ndr_winsrepl.h"#include "wrepl_server/wrepl_server.h"#include "nbt_server/wins/winsdb.h"#include "libcli/wrepl/winsrepl.h"#include "system/time.h"#include "librpc/gen_ndr/ndr_nbt.h"enum _R_ACTION { R_INVALID, R_DO_REPLACE, R_NOT_REPLACE, R_DO_PROPAGATE, R_DO_CHALLENGE, R_DO_RELEASE_DEMAND, R_DO_SGROUP_MERGE};static const char *_R_ACTION_enum_string(enum _R_ACTION action){ switch (action) { case R_INVALID: return "INVALID"; case R_DO_REPLACE: return "REPLACE"; case R_NOT_REPLACE: return "NOT_REPLACE"; case R_DO_PROPAGATE: return "PROPAGATE"; case R_DO_CHALLENGE: return "CHALLEGNE"; case R_DO_RELEASE_DEMAND: return "RELEASE_DEMAND"; case R_DO_SGROUP_MERGE: return "SGROUP_MERGE"; } return "enum _R_ACTION unknown";}#define R_IS_ACTIVE(r) ((r)->state == WREPL_STATE_ACTIVE)#if 0 /* unused */#define R_IS_RELEASED(r) ((r)->state == WREPL_STATE_RELEASED)#endif#define R_IS_TOMBSTONE(r) ((r)->state == WREPL_STATE_TOMBSTONE)#define R_IS_UNIQUE(r) ((r)->type == WREPL_TYPE_UNIQUE)#define R_IS_GROUP(r) ((r)->type == WREPL_TYPE_GROUP)#define R_IS_SGROUP(r) ((r)->type == WREPL_TYPE_SGROUP)#if 0 /* unused */#define R_IS_MHOMED(r) ((r)->type == WREPL_TYPE_MHOMED)#endif/* blindly overwrite records from the same owner in all cases */static enum _R_ACTION replace_same_owner(struct winsdb_record *r1, struct wrepl_name *r2){ /* REPLACE */ return R_DO_REPLACE;}static bool r_1_is_subset_of_2_address_list(struct winsdb_record *r1, struct wrepl_name *r2, bool check_owners){ uint32_t i,j; size_t len = winsdb_addr_list_length(r1->addresses); for (i=0; i < len; i++) { bool found = false; for (j=0; j < r2->num_addresses; j++) { if (strcmp(r1->addresses[i]->address, r2->addresses[j].address) != 0) { continue; } if (check_owners && strcmp(r1->addresses[i]->wins_owner, r2->addresses[j].owner) != 0) { return false; } found = true; break; } if (!found) return false; } return true;}static bool r_1_is_superset_of_2_address_list(struct winsdb_record *r1, struct wrepl_name *r2, bool check_owners){ uint32_t i,j; size_t len = winsdb_addr_list_length(r1->addresses); for (i=0; i < r2->num_addresses; i++) { bool found = false; for (j=0; j < len; j++) { if (strcmp(r2->addresses[i].address, r1->addresses[j]->address) != 0) { continue; } if (check_owners && strcmp(r2->addresses[i].owner, r1->addresses[j]->wins_owner) != 0) { return false; } found = true; break; } if (!found) return false; } return true;}static bool r_1_is_same_as_2_address_list(struct winsdb_record *r1, struct wrepl_name *r2, bool check_owners){ size_t len = winsdb_addr_list_length(r1->addresses); if (len != r2->num_addresses) { return false; } return r_1_is_superset_of_2_address_list(r1, r2, check_owners);}static bool r_contains_addrs_from_owner(struct winsdb_record *r1, const char *owner){ uint32_t i; size_t len = winsdb_addr_list_length(r1->addresses); for (i=0; i < len; i++) { if (strcmp(r1->addresses[i]->wins_owner, owner) == 0) { return true; } } return false;}/*UNIQUE,ACTIVE vs. UNIQUE,ACTIVE with different ip(s) => REPLACEUNIQUE,ACTIVE vs. UNIQUE,TOMBSTONE with different ip(s) => NOT REPLACEUNIQUE,RELEASED vs. UNIQUE,ACTIVE with different ip(s) => REPLACEUNIQUE,RELEASED vs. UNIQUE,TOMBSTONE with different ip(s) => REPLACEUNIQUE,TOMBSTONE vs. UNIQUE,ACTIVE with different ip(s) => REPLACEUNIQUE,TOMBSTONE vs. UNIQUE,TOMBSTONE with different ip(s) => REPLACEUNIQUE,ACTIVE vs. GROUP,ACTIVE with different ip(s) => REPLACEUNIQUE,ACTIVE vs. GROUP,TOMBSTONE with same ip(s) => NOT REPLACEUNIQUE,RELEASED vs. GROUP,ACTIVE with different ip(s) => REPLACEUNIQUE,RELEASED vs. GROUP,TOMBSTONE with different ip(s) => REPLACEUNIQUE,TOMBSTONE vs. GROUP,ACTIVE with different ip(s) => REPLACEUNIQUE,TOMBSTONE vs. GROUP,TOMBSTONE with different ip(s) => REPLACEUNIQUE,ACTIVE vs. SGROUP,ACTIVE with same ip(s) => NOT REPLACEUNIQUE,ACTIVE vs. SGROUP,TOMBSTONE with same ip(s) => NOT REPLACEUNIQUE,RELEASED vs. SGROUP,ACTIVE with different ip(s) => REPLACEUNIQUE,RELEASED vs. SGROUP,TOMBSTONE with different ip(s) => REPLACEUNIQUE,TOMBSTONE vs. SGROUP,ACTIVE with different ip(s) => REPLACEUNIQUE,TOMBSTONE vs. SGROUP,TOMBSTONE with different ip(s) => REPLACEUNIQUE,ACTIVE vs. MHOMED,ACTIVE with different ip(s) => REPLACEUNIQUE,ACTIVE vs. MHOMED,TOMBSTONE with same ip(s) => NOT REPLACEUNIQUE,RELEASED vs. MHOMED,ACTIVE with different ip(s) => REPLACEUNIQUE,RELEASED vs. MHOMED,TOMBSTONE with different ip(s) => REPLACEUNIQUE,TOMBSTONE vs. MHOMED,ACTIVE with different ip(s) => REPLACEUNIQUE,TOMBSTONE vs. MHOMED,TOMBSTONE with different ip(s) => REPLACE*/static enum _R_ACTION replace_unique_replica_vs_X_replica(struct winsdb_record *r1, struct wrepl_name *r2){ if (!R_IS_ACTIVE(r1)) { /* REPLACE */ return R_DO_REPLACE; } if (!R_IS_SGROUP(r2) && R_IS_ACTIVE(r2)) { /* REPLACE */ return R_DO_REPLACE; } /* NOT REPLACE */ return R_NOT_REPLACE;}/*GROUP,ACTIVE vs. UNIQUE,ACTIVE with same ip(s) => NOT REPLACEGROUP,ACTIVE vs. UNIQUE,TOMBSTONE with same ip(s) => NOT REPLACEGROUP,RELEASED vs. UNIQUE,ACTIVE with same ip(s) => NOT REPLACEGROUP,RELEASED vs. UNIQUE,TOMBSTONE with same ip(s) => NOT REPLACEGROUP,TOMBSTONE vs. UNIQUE,ACTIVE with same ip(s) => NOT REPLACEGROUP,TOMBSTONE vs. UNIQUE,TOMBSTONE with same ip(s) => NOT REPLACEGROUP,ACTIVE vs. GROUP,ACTIVE with same ip(s) => NOT REPLACEGROUP,ACTIVE vs. GROUP,TOMBSTONE with same ip(s) => NOT REPLACEGROUP,RELEASED vs. GROUP,ACTIVE with different ip(s) => REPLACEGROUP,RELEASED vs. GROUP,TOMBSTONE with different ip(s) => REPLACEGROUP,TOMBSTONE vs. GROUP,ACTIVE with different ip(s) => REPLACEGROUP,TOMBSTONE vs. GROUP,TOMBSTONE with different ip(s) => REPLACEGROUP,ACTIVE vs. SGROUP,ACTIVE with same ip(s) => NOT REPLACEGROUP,ACTIVE vs. SGROUP,TOMBSTONE with same ip(s) => NOT REPLACEGROUP,RELEASED vs. SGROUP,ACTIVE with different ip(s) => REPLACEGROUP,RELEASED vs. SGROUP,TOMBSTONE with same ip(s) => NOT REPLACEGROUP,TOMBSTONE vs. SGROUP,ACTIVE with different ip(s) => REPLACEGROUP,TOMBSTONE vs. SGROUP,TOMBSTONE with different ip(s) => REPLACEGROUP,ACTIVE vs. MHOMED,ACTIVE with same ip(s) => NOT REPLACEGROUP,ACTIVE vs. MHOMED,TOMBSTONE with same ip(s) => NOT REPLACEGROUP,RELEASED vs. MHOMED,ACTIVE with same ip(s) => NOT REPLACEGROUP,RELEASED vs. MHOMED,TOMBSTONE with same ip(s) => NOT REPLACEGROUP,TOMBSTONE vs. MHOMED,ACTIVE with different ip(s) => REPLACEGROUP,TOMBSTONE vs. MHOMED,TOMBSTONE with different ip(s) => REPLACE*/static enum _R_ACTION replace_group_replica_vs_X_replica(struct winsdb_record *r1, struct wrepl_name *r2){ if (!R_IS_ACTIVE(r1) && R_IS_GROUP(r2)) { /* REPLACE */ return R_DO_REPLACE; } if (R_IS_TOMBSTONE(r1) && !R_IS_UNIQUE(r2)) { /* REPLACE */ return R_DO_REPLACE; } /* NOT REPLACE */ return R_NOT_REPLACE;}/*SGROUP,ACTIVE vs. UNIQUE,ACTIVE with same ip(s) => NOT REPLACESGROUP,ACTIVE vs. UNIQUE,TOMBSTONE with same ip(s) => NOT REPLACESGROUP,RELEASED vs. UNIQUE,ACTIVE with different ip(s) => REPLACESGROUP,RELEASED vs. UNIQUE,TOMBSTONE with different ip(s) => REPLACESGROUP,TOMBSTONE vs. UNIQUE,ACTIVE with different ip(s) => REPLACESGROUP,TOMBSTONE vs. UNIQUE,TOMBSTONE with different ip(s) => REPLACESGROUP,ACTIVE vs. GROUP,ACTIVE with same ip(s) => NOT REPLACESGROUP,ACTIVE vs. GROUP,TOMBSTONE with same ip(s) => NOT REPLACESGROUP,RELEASED vs. GROUP,ACTIVE with different ip(s) => REPLACESGROUP,RELEASED vs. GROUP,TOMBSTONE with different ip(s) => REPLACESGROUP,TOMBSTONE vs. GROUP,ACTIVE with different ip(s) => REPLACESGROUP,TOMBSTONE vs. GROUP,TOMBSTONE with different ip(s) => REPLACESGROUP,RELEASED vs. SGROUP,ACTIVE with different ip(s) => REPLACESGROUP,RELEASED vs. SGROUP,TOMBSTONE with different ip(s) => REPLACESGROUP,TOMBSTONE vs. SGROUP,ACTIVE with different ip(s) => REPLACESGROUP,TOMBSTONE vs. SGROUP,TOMBSTONE with different ip(s) => REPLACESGROUP,ACTIVE vs. MHOMED,ACTIVE with same ip(s) => NOT REPLACESGROUP,ACTIVE vs. MHOMED,TOMBSTONE with same ip(s) => NOT REPLACESGROUP,RELEASED vs. MHOMED,ACTIVE with different ip(s) => REPLACESGROUP,RELEASED vs. MHOMED,TOMBSTONE with different ip(s) => REPLACESGROUP,TOMBSTONE vs. MHOMED,ACTIVE with different ip(s) => REPLACESGROUP,TOMBSTONE vs. MHOMED,TOMBSTONE with different ip(s) => REPLACESGROUP,ACTIVE vs. SGROUP,ACTIVE A:A_3_4 vs. B:A_3_4 => NOT REPLACESGROUP,ACTIVE vs. SGROUP,ACTIVE A:A_3_4 vs. B:NULL => NOT REPLACESGROUP,ACTIVE vs. SGROUP,ACTIVE A:A_3_4_X_3_4 vs. B:A_3_4 => NOT REPLACESGROUP,ACTIVE vs. SGROUP,ACTIVE A:B_3_4 vs. B:A_3_4 => REPLACESGROUP,ACTIVE vs. SGROUP,ACTIVE A:A_3_4 vs. B:A_3_4_OWNER_B => REPLACESGROUP,ACTIVE vs. SGROUP,ACTIVE A:A_3_4_OWNER_B vs. B:A_3_4 => REPLACESGROUP,ACTIVE vs. SGROUP,ACTIVE A:A_3_4 vs. B:B_3_4 => C:A_3_4_B_3_4 => SGROUP_MERGESGROUP,ACTIVE vs. SGROUP,ACTIVE A:B_3_4_X_3_4 vs. B:A_3_4 => B:A_3_4_X_3_4 => SGROUP_MERGESGROUP,ACTIVE vs. SGROUP,ACTIVE A:X_3_4 vs. B:A_3_4 => C:A_3_4_X_3_4 => SGROUP_MERGESGROUP,ACTIVE vs. SGROUP,ACTIVE A:A_3_4_X_3_4 vs. B:A_3_4_OWNER_B => B:A_3_4_OWNER_B_X_3_4 => SGROUP_MERGESGROUP,ACTIVE vs. SGROUP,ACTIVE A:B_3_4_X_3_4 vs. B:B_3_4_X_1_2 => C:B_3_4_X_1_2_3_4 => SGROUP_MERGESGROUP,ACTIVE vs. SGROUP,ACTIVE A:B_3_4_X_3_4 vs. B:NULL => B:X_3_4 => SGROUP_MERGE this is a bit strange, incoming tombstone replicas always replace old replicas:SGROUP,ACTIVE vs. SGROUP,TOMBSTONE A:B_3_4_X_3_4 vs. B:NULL => B:NULL => REPLACESGROUP,ACTIVE vs. SGROUP,TOMBSTONE A:B_3_4_X_3_4 vs. B:A_3_4 => B:A_3_4 => REPLACESGROUP,ACTIVE vs. SGROUP,TOMBSTONE A:B_3_4_X_3_4 vs. B:B_3_4 => B:B_3_4 => REPLACESGROUP,ACTIVE vs. SGROUP,TOMBSTONE A:B_3_4_X_3_4 vs. B:B_3_4_X_3_4 => B:B_3_4_X_3_4 => REPLACE*/static enum _R_ACTION replace_sgroup_replica_vs_X_replica(struct winsdb_record *r1, struct wrepl_name *r2){ if (!R_IS_ACTIVE(r1)) { /* REPLACE */ return R_DO_REPLACE; } if (!R_IS_SGROUP(r2)) { /* NOT REPLACE */ return R_NOT_REPLACE; } /* * this is strange, but correct * the incoming tombstone replace the current active * record */ if (!R_IS_ACTIVE(r2)) { /* REPLACE */ return R_DO_REPLACE; } if (r2->num_addresses == 0) { if (r_contains_addrs_from_owner(r1, r2->owner)) { /* not handled here: MERGE */ return R_DO_SGROUP_MERGE; } /* NOT REPLACE */ return R_NOT_REPLACE; } if (r_1_is_superset_of_2_address_list(r1, r2, true)) { /* NOT REPLACE */ return R_NOT_REPLACE; } if (r_1_is_same_as_2_address_list(r1, r2, false)) { /* REPLACE */ return R_DO_REPLACE; } /* not handled here: MERGE */ return R_DO_SGROUP_MERGE;}/*MHOMED,ACTIVE vs. UNIQUE,ACTIVE with different ip(s) => REPLACEMHOMED,ACTIVE vs. UNIQUE,TOMBSTONE with same ip(s) => NOT REPLACEMHOMED,RELEASED vs. UNIQUE,ACTIVE with different ip(s) => REPLACEMHOMED,RELEASED vs. UNIQUE,TOMBSTONE with different ip(s) => REPLACEMHOMED,TOMBSTONE vs. UNIQUE,ACTIVE with different ip(s) => REPLACEMHOMED,TOMBSTONE vs. UNIQUE,TOMBSTONE with different ip(s) => REPLACEMHOMED,ACTIVE vs. GROUP,ACTIVE with different ip(s) => REPLACEMHOMED,ACTIVE vs. GROUP,TOMBSTONE with same ip(s) => NOT REPLACEMHOMED,RELEASED vs. GROUP,ACTIVE with different ip(s) => REPLACEMHOMED,RELEASED vs. GROUP,TOMBSTONE with different ip(s) => REPLACEMHOMED,TOMBSTONE vs. GROUP,ACTIVE with different ip(s) => REPLACEMHOMED,TOMBSTONE vs. GROUP,TOMBSTONE with different ip(s) => REPLACEMHOMED,ACTIVE vs. SGROUP,ACTIVE with same ip(s) => NOT REPLACEMHOMED,ACTIVE vs. SGROUP,TOMBSTONE with same ip(s) => NOT REPLACEMHOMED,RELEASED vs. SGROUP,ACTIVE with different ip(s) => REPLACEMHOMED,RELEASED vs. SGROUP,TOMBSTONE with different ip(s) => REPLACEMHOMED,TOMBSTONE vs. SGROUP,ACTIVE with different ip(s) => REPLACEMHOMED,TOMBSTONE vs. SGROUP,TOMBSTONE with different ip(s) => REPLACEMHOMED,ACTIVE vs. MHOMED,ACTIVE with different ip(s) => REPLACEMHOMED,ACTIVE vs. MHOMED,TOMBSTONE with same ip(s) => NOT REPLACEMHOMED,RELEASED vs. MHOMED,ACTIVE with different ip(s) => REPLACEMHOMED,RELEASED vs. MHOMED,TOMBSTONE with different ip(s) => REPLACEMHOMED,TOMBSTONE vs. MHOMED,ACTIVE with different ip(s) => REPLACEMHOMED,TOMBSTONE vs. MHOMED,TOMBSTONE with different ip(s) => REPLACE*/static enum _R_ACTION replace_mhomed_replica_vs_X_replica(struct winsdb_record *r1, struct wrepl_name *r2){ if (!R_IS_ACTIVE(r1)) { /* REPLACE */ return R_DO_REPLACE; } if (!R_IS_SGROUP(r2) && R_IS_ACTIVE(r2)) { /* REPLACE */ return R_DO_REPLACE; } /* NOT REPLACE */ return R_NOT_REPLACE;}/*active:_UA_UA_SI_U<00> => REPLACE_UA_UA_DI_P<00> => NOT REPLACE_UA_UA_DI_O<00> => NOT REPLACE_UA_UA_DI_N<00> => REPLACE_UA_UT_SI_U<00> => NOT REPLACE_UA_UT_DI_U<00> => NOT REPLACE_UA_GA_SI_R<00> => REPLACE_UA_GA_DI_R<00> => REPLACE_UA_GT_SI_U<00> => NOT REPLACE_UA_GT_DI_U<00> => NOT REPLACE_UA_SA_SI_R<00> => REPLACE_UA_SA_DI_R<00> => REPLACE_UA_ST_SI_U<00> => NOT REPLACE_UA_ST_DI_U<00> => NOT REPLACE_UA_MA_SI_U<00> => REPLACE_UA_MA_SP_U<00> => REPLACE_UA_MA_DI_P<00> => NOT REPLACE_UA_MA_DI_O<00> => NOT REPLACE_UA_MA_DI_N<00> => REPLACE_UA_MT_SI_U<00> => NOT REPLACE_UA_MT_DI_U<00> => NOT REPLACETest Replica vs. owned active: some more UNIQUE,MHOMED combinations_UA_UA_DI_A<00> => MHOMED_MERGE_UA_MA_DI_A<00> => MHOMED_MERGEreleased:_UR_UA_SI<00> => REPLACE_UR_UA_DI<00> => REPLACE_UR_UT_SI<00> => REPLACE_UR_UT_DI<00> => REPLACE_UR_GA_SI<00> => REPLACE_UR_GA_DI<00> => REPLACE_UR_GT_SI<00> => REPLACE_UR_GT_DI<00> => REPLACE_UR_SA_SI<00> => REPLACE_UR_SA_DI<00> => REPLACE_UR_ST_SI<00> => REPLACE_UR_ST_DI<00> => REPLACE_UR_MA_SI<00> => REPLACE_UR_MA_DI<00> => REPLACE_UR_MT_SI<00> => REPLACE_UR_MT_DI<00> => REPLACE*/static enum _R_ACTION replace_unique_owned_vs_X_replica(struct winsdb_record *r1, struct wrepl_name *r2){ if (!R_IS_ACTIVE(r1)) { /* REPLACE */ return R_DO_REPLACE; } if (!R_IS_ACTIVE(r2)) { /* NOT REPLACE, and PROPAGATE */ return R_DO_PROPAGATE; } if (R_IS_GROUP(r2) || R_IS_SGROUP(r2)) { /* REPLACE and send a release demand to the old name owner */ return R_DO_RELEASE_DEMAND; } /* * here we only have unique,active,owned vs. * is unique,active,replica or mhomed,active,replica */ if (r_1_is_subset_of_2_address_list(r1, r2, false)) { /* * if r1 has a subset(or same) of the addresses of r2 * <=> * if r2 has a superset(or same) of the addresses of r1 * * then replace the record */ return R_DO_REPLACE; } /* * in any other case, we need to do * a name request to the old name holder * to see if it's still there... */ return R_DO_CHALLENGE;}/*active:_GA_UA_SI_U<00> => NOT REPLACE_GA_UA_DI_U<00> => NOT REPLACE_GA_UT_SI_U<00> => NOT REPLACE_GA_UT_DI_U<00> => NOT REPLACE_GA_GA_SI_U<00> => REPLACE_GA_GA_DI_U<00> => REPLACE_GA_GT_SI_U<00> => NOT REPLACE_GA_GT_DI_U<00> => NOT REPLACE_GA_SA_SI_U<00> => NOT REPLACE_GA_SA_DI_U<00> => NOT REPLACE_GA_ST_SI_U<00> => NOT REPLACE_GA_ST_DI_U<00> => NOT REPLACE_GA_MA_SI_U<00> => NOT REPLACE_GA_MA_DI_U<00> => NOT REPLACE_GA_MT_SI_U<00> => NOT REPLACE_GA_MT_DI_U<00> => NOT REPLACEreleased:_GR_UA_SI<00> => NOT REPLACE_GR_UA_DI<00> => NOT REPLACE_GR_UT_SI<00> => NOT REPLACE_GR_UT_DI<00> => NOT REPLACE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -