libwbclient: add wbcInterfaceDetails()
authorStefan Metzmacher <metze@samba.org>
Fri, 28 Mar 2008 15:52:18 +0000 (16:52 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 1 Apr 2008 16:30:10 +0000 (18:30 +0200)
metze
(This used to be commit fee3806326b9ba214e35868271e6481c0c8b9c4b)

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

index ff3cec8689d9568a083cb1fe4d4d2ceaf49b0891..7bdae9154406ad21d29551031e7e55848f7f23a2 100644 (file)
@@ -44,6 +44,81 @@ wbcErr wbcPing(void)
        return wbcRequestResponse(WINBINDD_PING, &request, &response);
 }
 
+wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details)
+{
+       wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+       struct wbcInterfaceDetails *info;
+       struct wbcDomainInfo *domain = NULL;
+       struct winbindd_request request;
+       struct winbindd_response response;
+
+       /* Initialize request */
+
+       ZERO_STRUCT(request);
+       ZERO_STRUCT(response);
+
+       info = talloc(NULL, struct wbcInterfaceDetails);
+       BAIL_ON_PTR_ERROR(info, wbc_status);
+
+       /* first the interface version */
+       wbc_status = wbcRequestResponse(WINBINDD_INTERFACE_VERSION, NULL, &response);
+       BAIL_ON_WBC_ERROR(wbc_status);
+       info->interface_version = response.data.interface_version;
+
+       /* then the samba version and the winbind separator */
+       wbc_status = wbcRequestResponse(WINBINDD_INFO, NULL, &response);
+       BAIL_ON_WBC_ERROR(wbc_status);
+
+       info->winbind_version = talloc_strdup(info,
+                                             response.data.info.samba_version);
+       BAIL_ON_PTR_ERROR(info->winbind_version, wbc_status);
+       info->winbind_separator = response.data.info.winbind_separator;
+
+       /* then the local netbios name */
+       wbc_status = wbcRequestResponse(WINBINDD_NETBIOS_NAME, NULL, &response);
+       BAIL_ON_WBC_ERROR(wbc_status);
+
+       info->netbios_name = talloc_strdup(info,
+                                          response.data.netbios_name);
+       BAIL_ON_PTR_ERROR(info->netbios_name, wbc_status);
+
+       /* then the local workgroup name */
+       wbc_status = wbcRequestResponse(WINBINDD_DOMAIN_NAME, NULL, &response);
+       BAIL_ON_WBC_ERROR(wbc_status);
+
+       info->netbios_domain = talloc_strdup(info,
+                                       response.data.domain_name);
+       BAIL_ON_PTR_ERROR(info->netbios_domain, wbc_status);
+
+       wbc_status = wbcDomainInfo(info->netbios_domain, &domain);
+       if (wbc_status == WBC_ERR_DOMAIN_NOT_FOUND) {
+               /* maybe it's a standalone server */
+               domain = NULL;
+               wbc_status = WBC_ERR_SUCCESS;
+       } else {
+               BAIL_ON_WBC_ERROR(wbc_status);
+       }
+
+       if (domain) {
+               info->dns_domain = talloc_strdup(info,
+                                                domain->dns_name);
+               wbcFreeMemory(domain);
+               BAIL_ON_PTR_ERROR(info->dns_domain, wbc_status);
+       } else {
+               info->dns_domain = NULL;
+       }
+
+       *_details = info;
+       info = NULL;
+
+       wbc_status = WBC_ERR_SUCCESS;
+
+done:
+       talloc_free(info);
+       return wbc_status;
+}
+
+
 /** @brief Lookup the current status of a trusted domain
  *
  * @param domain      Domain to query
index e5047af9f7fda4b48322d888c621df28f9a8656c..4a9a3b2809860be902fb08a3482863c4c891d55a 100644 (file)
@@ -51,6 +51,19 @@ typedef enum _wbcErrType wbcErr;
 
 const char *wbcErrorString(wbcErr error);
 
+/**
+ *  @brief Some useful details about the running winbindd
+ *
+ **/
+struct wbcInterfaceDetails {
+       uint32_t interface_version;
+       const char *winbind_version;
+       char winbind_separator;
+       const char *netbios_name;
+       const char *netbios_domain;
+       const char *dns_domain;
+};
+
 /*
  * Data types used by the Winbind Client API
  */
@@ -277,6 +290,8 @@ wbcErr wbcStringToSid(const char *sid_string,
 
 wbcErr wbcPing(void);
 
+wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details);
+
 /*
  * Name/SID conversion
  */