]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Add DsGetDcName call to libnetapi library.
authorGünther Deschner <gd@samba.org>
Tue, 8 Apr 2008 16:43:51 +0000 (18:43 +0200)
committerGünther Deschner <gd@samba.org>
Tue, 8 Apr 2008 17:40:47 +0000 (19:40 +0200)
Guenther

source/lib/netapi/getdc.c
source/lib/netapi/libnetapi.c
source/lib/netapi/libnetapi.h
source/lib/netapi/netapi.h

index f6a666d70da4d9af025afd98a0c571163b1137f2..9ad935efd82e9a92c43d85c0d616033bc03c0e3d 100644 (file)
@@ -133,3 +133,79 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
        return werr;
 
 }
+
+/********************************************************************
+********************************************************************/
+
+WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
+                    struct DsGetDcName *r)
+{
+       NTSTATUS status;
+
+       status = dsgetdcname(ctx,
+                            r->in.domain_name,
+                            r->in.domain_guid,
+                            r->in.site_name,
+                            r->in.flags,
+                            (struct netr_DsRGetDCNameInfo **)r->out.dc_info);
+       if (!NT_STATUS_IS_OK(status)) {
+               libnetapi_set_error_string(ctx,
+                       "failed to find DC: %s",
+                       get_friendly_nt_error_msg(status));
+       }
+
+       return ntstatus_to_werror(status);
+}
+
+/********************************************************************
+********************************************************************/
+
+WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
+                    struct DsGetDcName *r)
+{
+       WERROR werr;
+       NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
+       struct cli_state *cli = NULL;
+       struct rpc_pipe_client *pipe_cli = NULL;
+
+       status = cli_full_connection(&cli, NULL, r->in.server_name,
+                                    NULL, 0,
+                                    "IPC$", "IPC",
+                                    ctx->username,
+                                    ctx->workgroup,
+                                    ctx->password,
+                                    0, Undefined, NULL);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               werr = ntstatus_to_werror(status);
+               goto done;
+       }
+
+       pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON,
+                                           &status);
+       if (!pipe_cli) {
+               werr = ntstatus_to_werror(status);
+               goto done;
+       }
+
+       status = rpccli_netr_DsRGetDCName(pipe_cli,
+                                         ctx,
+                                         r->in.server_name,
+                                         r->in.domain_name,
+                                         r->in.domain_guid,
+                                         NULL,
+                                         r->in.flags,
+                                         (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
+                                         &werr);
+       if (!NT_STATUS_IS_OK(status)) {
+               werr = ntstatus_to_werror(status);
+               goto done;
+       }
+
+ done:
+       if (cli) {
+               cli_shutdown(cli);
+       }
+
+       return werr;
+}
index 9d42b7e97c1a293fd1bde4e37339f509eb482dfe..ed97df21439de804172b837fc96cf33086d4b2c0 100644 (file)
@@ -391,3 +391,53 @@ NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] [unique] */,
        return r.out.result;
 }
 
+/****************************************************************
+ DsGetDcName
+****************************************************************/
+
+NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */,
+                          const char * domain_name /* [in] [ref] */,
+                          struct GUID *domain_guid /* [in] [unique] */,
+                          const char * site_name /* [in] [unique] */,
+                          uint32_t flags /* [in] */,
+                          struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */)
+{
+       struct DsGetDcName r;
+       struct libnetapi_ctx *ctx = NULL;
+       NET_API_STATUS status;
+       WERROR werr;
+
+       status = libnetapi_getctx(&ctx);
+       if (status != 0) {
+               return status;
+       }
+
+       /* In parameters */
+       r.in.server_name = server_name;
+       r.in.domain_name = domain_name;
+       r.in.domain_guid = domain_guid;
+       r.in.site_name = site_name;
+       r.in.flags = flags;
+
+       /* Out parameters */
+       r.out.dc_info = dc_info;
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_IN_DEBUG(DsGetDcName, &r);
+       }
+
+       if (LIBNETAPI_LOCAL_SERVER(server_name)) {
+               werr = DsGetDcName_l(ctx, &r);
+       } else {
+               werr = DsGetDcName_r(ctx, &r);
+       }
+
+       r.out.result = W_ERROR_V(werr);
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_OUT_DEBUG(DsGetDcName, &r);
+       }
+
+       return r.out.result;
+}
+
index a215c84cb3eedc6afa07ac431639f694f84c15c2..99c5295c56835c6a975c6de0d0328240de8bb6a6 100644 (file)
@@ -64,4 +64,14 @@ WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
                         struct NetGetAnyDCName *r);
 WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx,
                         struct NetGetAnyDCName *r);
+NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */,
+                          const char * domain_name /* [in] [ref] */,
+                          struct GUID *domain_guid /* [in] [unique] */,
+                          const char * site_name /* [in] [unique] */,
+                          uint32_t flags /* [in] */,
+                          struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */);
+WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
+                    struct DsGetDcName *r);
+WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
+                    struct DsGetDcName *r);
 #endif /* __LIBNETAPI_LIBNETAPI__ */
index 87126fbacf574c59251437bd6e72c5695d360c21..68f23720ff2c6bef31050a4bdde3cfe3bee12bb0 100644 (file)
@@ -31,6 +31,37 @@ typedef enum {
 /****************************************************************
 ****************************************************************/
 
+#ifndef _HEADER_misc
+
+struct GUID {
+       uint32_t time_low;
+       uint16_t time_mid;
+       uint16_t time_hi_and_version;
+       uint8_t clock_seq[2];
+       uint8_t node[6];
+};
+
+#endif /* _HEADER_misc */
+
+#ifndef _HEADER_libnetapi
+
+struct DOMAIN_CONTROLLER_INFO {
+       const char * domain_controller_name;
+       const char * domain_controller_address;
+       uint32_t domain_controller_address_type;
+       struct GUID domain_guid;
+       const char * domain_name;
+       const char * dns_foreset_name;
+       uint32_t flags;
+       const char * dc_site_name;
+       const char * client_site_name;
+};
+
+#endif /* _HEADER_libnetapi */
+
+/****************************************************************
+****************************************************************/
+
 struct libnetapi_ctx {
        char *debuglevel;
        char *error_string;
@@ -134,4 +165,15 @@ NET_API_STATUS NetGetAnyDCName(const char * server_name /* [in] */,
                               const char * domain_name /* [in] */,
                               uint8_t **buffer /* [out] [ref] */);
 
+
+/****************************************************************
+ DsGetDcName
+****************************************************************/
+
+NET_API_STATUS DsGetDcName(const char * server_name /* [in] [unique] */,
+                          const char * domain_name /* [in] [ref] */,
+                          struct GUID *domain_guid /* [in] [unique] */,
+                          const char * site_name /* [in] [unique] */,
+                          uint32_t flags /* [in] */,
+                          struct DOMAIN_CONTROLLER_INFO **dc_info /* [out] [ref] */);
 #endif