s3-net: add net_scan_dc function.
authorGünther Deschner <gd@samba.org>
Tue, 11 Nov 2008 17:59:57 +0000 (18:59 +0100)
committerGünther Deschner <gd@samba.org>
Tue, 18 Nov 2008 15:00:52 +0000 (16:00 +0100)
Guenther

source3/utils/net_proto.h
source3/utils/net_util.c

index ee4388f1577980c826b6c99cccfd1f8c567645d4..128f88b0d3cb3d4a32fd6519cee8957cc81c5964 100644 (file)
@@ -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,
index a9b2bbe621f0df2fd7c2b2616d469adfe36a9a01..590a916522fd18f5801d82ac7c9424d8284da8c0 100644 (file)
@@ -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;
+}