From b8fee9d863054e18e5103fa197acbf58129db09d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 11 Nov 2008 18:59:57 +0100 Subject: s3-net: add net_scan_dc function. Guenther --- source3/utils/net_proto.h | 4 ++++ source3/utils/net_util.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'source3') diff --git a/source3/utils/net_proto.h b/source3/utils/net_proto.h index ee4388f157..128f88b0d3 100644 --- a/source3/utils/net_proto.h +++ b/source3/utils/net_proto.h @@ -473,6 +473,10 @@ void net_display_usage_from_functable(struct functable *table); const char *net_share_type_str(int num_type); +NTSTATUS net_scan_dc(struct net_context *c, + struct cli_state *cli, + struct net_dc_info *dc_info); + /* The following definitions come from utils/netlookup.c */ NTSTATUS net_lookup_name_from_sid(struct net_context *c, diff --git a/source3/utils/net_util.c b/source3/utils/net_util.c index a9b2bbe621..590a916522 100644 --- a/source3/utils/net_util.c +++ b/source3/utils/net_util.c @@ -607,3 +607,41 @@ const char *net_share_type_str(int num_type) default: return "Unknown"; } } + +NTSTATUS net_scan_dc(struct net_context *c, + struct cli_state *cli, + struct net_dc_info *dc_info) +{ + TALLOC_CTX *mem_ctx = talloc_tos(); + struct rpc_pipe_client *dssetup_pipe = NULL; + union dssetup_DsRoleInfo info; + NTSTATUS status; + + ZERO_STRUCTP(dc_info); + + status = cli_rpc_pipe_open_noauth(cli, &ndr_table_dssetup.syntax_id, + &dssetup_pipe); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + status = rpccli_dssetup_DsRoleGetPrimaryDomainInformation(dssetup_pipe, mem_ctx, + DS_ROLE_BASIC_INFORMATION, + &info, + NULL); + TALLOC_FREE(dssetup_pipe); + + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + dc_info->is_dc = (info.basic.role & (DS_ROLE_PRIMARY_DC|DS_ROLE_BACKUP_DC)); + dc_info->is_pdc = (info.basic.role & DS_ROLE_PRIMARY_DC); + dc_info->is_ad = (info.basic.flags & DS_ROLE_PRIMARY_DS_RUNNING); + dc_info->is_mixed_mode = (info.basic.flags & DS_ROLE_PRIMARY_DS_MIXED_MODE); + dc_info->netbios_domain_name = talloc_strdup(mem_ctx, info.basic.domain); + dc_info->dns_domain_name = talloc_strdup(mem_ctx, info.basic.dns_domain); + dc_info->forest_name = talloc_strdup(mem_ctx, info.basic.forest); + + return NT_STATUS_OK; +} -- cgit