wbclient: add wbcLookupDomainControllerEx call.
authorGünther Deschner <gd@samba.org>
Sat, 27 Sep 2008 01:29:01 +0000 (03:29 +0200)
committerGünther Deschner <gd@samba.org>
Thu, 9 Oct 2008 10:48:13 +0000 (12:48 +0200)
Guenther

source3/nsswitch/libwbclient/wbc_util.c
source3/nsswitch/libwbclient/wbclient.h

index 8e01e6e719072e9fd07af9a7b4aad5ec4cd70ed3..5aea8842724bdfe21937b9e3278fdd07db3cb3e2 100644 (file)
@@ -550,3 +550,142 @@ done:
 
        return wbc_status;
 }
+
+static wbcErr wbc_create_domain_controller_info_ex(TALLOC_CTX *mem_ctx,
+                                                  const struct winbindd_response *resp,
+                                                  struct wbcDomainControllerInfoEx **_i)
+{
+       wbcErr wbc_status = WBC_ERR_SUCCESS;
+       struct wbcDomainControllerInfoEx *i;
+       struct wbcGuid guid;
+
+       i = talloc(mem_ctx, struct wbcDomainControllerInfoEx);
+       BAIL_ON_PTR_ERROR(i, wbc_status);
+
+       i->dc_unc = talloc_strdup(i, resp->data.dsgetdcname.dc_unc);
+       BAIL_ON_PTR_ERROR(i->dc_unc, wbc_status);
+
+       i->dc_address = talloc_strdup(i, resp->data.dsgetdcname.dc_address);
+       BAIL_ON_PTR_ERROR(i->dc_address, wbc_status);
+
+       i->dc_address_type = resp->data.dsgetdcname.dc_address_type;
+
+       wbc_status = wbcStringToGuid(resp->data.dsgetdcname.domain_guid, &guid);
+       if (WBC_ERROR_IS_OK(wbc_status)) {
+               i->domain_guid = talloc(i, struct wbcGuid);
+               BAIL_ON_PTR_ERROR(i->domain_guid, wbc_status);
+
+               *i->domain_guid = guid;
+       } else {
+               i->domain_guid = NULL;
+       }
+
+       i->domain_name = talloc_strdup(i, resp->data.dsgetdcname.domain_name);
+       BAIL_ON_PTR_ERROR(i->domain_name, wbc_status);
+
+       if (resp->data.dsgetdcname.forest_name[0] != '\0') {
+               i->forest_name = talloc_strdup(i,
+                       resp->data.dsgetdcname.forest_name);
+               BAIL_ON_PTR_ERROR(i->forest_name, wbc_status);
+       } else {
+               i->forest_name = NULL;
+       }
+
+       i->dc_flags = resp->data.dsgetdcname.dc_flags;
+
+       if (resp->data.dsgetdcname.dc_site_name[0] != '\0') {
+               i->dc_site_name = talloc_strdup(i,
+                       resp->data.dsgetdcname.dc_site_name);
+               BAIL_ON_PTR_ERROR(i->dc_site_name, wbc_status);
+       } else {
+               i->dc_site_name = NULL;
+       }
+
+       if (resp->data.dsgetdcname.client_site_name[0] != '\0') {
+               i->client_site_name = talloc_strdup(i,
+                       resp->data.dsgetdcname.client_site_name);
+               BAIL_ON_PTR_ERROR(i->client_site_name, wbc_status);
+       } else {
+               i->client_site_name = NULL;
+       }
+
+       *_i = i;
+       i = NULL;
+
+done:
+       talloc_free(i);
+       return wbc_status;
+}
+
+/** @brief Get extended domain controller information
+ *
+ * @param domain        Name of the domain to query for a DC
+ * @param guid          Guid of the domain to query for a DC
+ * @param site          Site of the domain to query for a DC
+ * @param flags         Bit flags used to control the domain location query
+ * @param *dc_info      Pointer to the returned extended domain controller information
+ *
+ * @return #wbcErr
+ *
+ **/
+
+wbcErr wbcLookupDomainControllerEx(const char *domain,
+                                  struct wbcGuid *guid,
+                                  const char *site,
+                                  uint32_t flags,
+                                  struct wbcDomainControllerInfoEx **dc_info)
+{
+       wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+       struct winbindd_request request;
+       struct winbindd_response response;
+
+       /* validate input params */
+
+       if (!domain || !dc_info) {
+               wbc_status = WBC_ERR_INVALID_PARAM;
+               BAIL_ON_WBC_ERROR(wbc_status);
+       }
+
+       ZERO_STRUCT(request);
+       ZERO_STRUCT(response);
+
+       request.data.dsgetdcname.flags = flags;
+
+       strncpy(request.data.dsgetdcname.domain_name, domain,
+               sizeof(request.data.dsgetdcname.domain_name)-1);
+
+       if (site) {
+               strncpy(request.data.dsgetdcname.site_name, site,
+                       sizeof(request.data.dsgetdcname.site_name)-1);
+       }
+
+       if (guid) {
+               char *str = NULL;
+
+               wbc_status = wbcGuidToString(guid, &str);
+               BAIL_ON_WBC_ERROR(wbc_status);
+
+               strncpy(request.data.dsgetdcname.domain_guid, str,
+                       sizeof(request.data.dsgetdcname.domain_guid)-1);
+
+               wbcFreeMemory(str);
+       }
+
+       /* Send request */
+
+       wbc_status = wbcRequestResponse(WINBINDD_DSGETDCNAME,
+                                       &request,
+                                       &response);
+       BAIL_ON_WBC_ERROR(wbc_status);
+
+       if (dc_info) {
+               wbc_status = wbc_create_domain_controller_info_ex(NULL,
+                                                                 &response,
+                                                                 dc_info);
+               BAIL_ON_WBC_ERROR(wbc_status);
+       }
+
+       wbc_status = WBC_ERR_SUCCESS;
+done:
+       return wbc_status;
+}
index 48b611561214b4f6b9d4dc1ebc162790f9d9e7c6..327dafdae40360c741f32a88b011df505b4ed5fb 100644 (file)
@@ -392,7 +392,20 @@ struct wbcDomainControllerInfo {
        char *dc_name;
 };
 
-
+/*
+ * DomainControllerInfoEx struct
+ */
+struct wbcDomainControllerInfoEx {
+       const char *dc_unc;
+       const char *dc_address;
+       uint16_t dc_address_type;
+       struct wbcGuid *domain_guid;
+       const char *domain_name;
+       const char *forest_name;
+       uint32_t dc_flags;
+       const char *dc_site_name;
+       const char *client_site_name;
+};
 
 /*
  * Memory Management
@@ -554,6 +567,12 @@ wbcErr wbcLookupDomainController(const char *domain,
                                 uint32_t flags,
                                 struct wbcDomainControllerInfo **dc_info);
 
+wbcErr wbcLookupDomainControllerEx(const char *domain,
+                                  struct wbcGuid *guid,
+                                  const char *site,
+                                  uint32_t flags,
+                                  struct wbcDomainControllerInfoEx **dc_info);
+
 /*
  * Athenticate functions
  */