Mark a domain offline in the wbcDomainInfo structure using the domain_flags.
authorGerald W. Carter <jerry@samba.org>
Tue, 22 Apr 2008 20:29:53 +0000 (15:29 -0500)
committerGerald W. Carter <jerry@samba.org>
Wed, 23 Apr 2008 13:47:50 +0000 (08:47 -0500)
Use the existing domain_flags fiueld in wbcDomainInfo to set a bit if the
domain is marked as offline by Winbind.
(This used to be commit 59cfba2c3d6d4594f08cbe3b7295ab36a7cfb044)

source3/nsswitch/libwbclient/wbc_util.c
source3/nsswitch/libwbclient/wbclient.h
source3/nsswitch/wbinfo.c
source3/winbindd/winbindd_misc.c

index c1b3affc721f79ad9f87cf7abe27ffd734d001a4..3afd8a29d31f026492408a328955e6ac368b77f5 100644 (file)
@@ -373,15 +373,28 @@ static wbcErr process_domain_info_string(TALLOC_CTX *ctx,
 
        /* Outgoing */
        r = s;
-       if (r == NULL) {
+       if ((s = strchr(r, '\\')) == NULL) {
                wbc_status = WBC_ERR_INVALID_RESPONSE;
                BAIL_ON_WBC_ERROR(wbc_status);
        }
+       *s = '\0';
+       s++;
 
        if (strcmp(r, "Yes") == 0) {
                info->trust_flags |= WBC_DOMINFO_TRUST_OUTGOING;                
        }
 
+       /* Online/Offline status */
+
+       r = s;
+       if (r == NULL) {
+               wbc_status = WBC_ERR_INVALID_RESPONSE;
+               BAIL_ON_WBC_ERROR(wbc_status);
+       }
+       if ( strcmp(r, "Offline") == 0) {
+               info->domain_flags |= WBC_DOMINFO_DOMAIN_OFFLINE;
+       }
+
        wbc_status = WBC_ERR_SUCCESS;
 
  done:
index 67fa25691ae347a69aece03d0b0ac754a67edc80..f236c43e11649730ce8565aa0b8601734e43a060 100644 (file)
@@ -139,6 +139,7 @@ struct wbcDomainInfo {
 #define WBC_DOMINFO_DOMAIN_NATIVE     0x00000001
 #define WBC_DOMINFO_DOMAIN_AD         0x00000002
 #define WBC_DOMINFO_DOMAIN_PRIMARY    0x00000004
+#define WBC_DOMINFO_DOMAIN_OFFLINE    0x00000008
 
 /* wbcDomainInfo->trust_flags */
 
index d844e2385e55a3f9e215ed1f0f28a7ab6e749dcc..7bb4abe9b2e557178c938f1697b174c209d1699a 100644 (file)
@@ -419,39 +419,43 @@ static bool wbinfo_list_own_domain(void)
 /* show sequence numbers */
 static bool wbinfo_show_sequence(const char *domain)
 {
-       struct winbindd_request  request;
-       struct winbindd_response response;
-
-       ZERO_STRUCT(response);
-       ZERO_STRUCT(request);
-
-       if ( domain )
-               fstrcpy( request.domain_name, domain );
+       d_printf("This command has been deprecated.  Please use the --online-status option instead.\n");
+       return false;
+}
 
-       /* Send request */
+/* show sequence numbers */
+static bool wbinfo_show_onlinestatus(const char *domain)
+{
+       struct wbcDomainInfo *domain_list = NULL;
+       size_t num_domains;
+       wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+       int i;
 
-       if (winbindd_request_response(WINBINDD_SHOW_SEQUENCE, &request, &response) !=
-           NSS_STATUS_SUCCESS)
+       wbc_status = wbcListTrusts(&domain_list, &num_domains);
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
                return false;
+       }
 
-       /* Display response */
+       for (i=0; i<num_domains; i++) {
+               bool is_offline;
 
-       if (domain) {
-               d_printf("%s : ", domain);
-               if (response.data.sequence_number == (uint32_t)-1) {
-                       d_printf("DISCONNECTED\n");
-               } else {
-                       d_printf("%d\n", response.data.sequence_number);
+               if (domain) {
+                       if (!strequal(domain_list[i].short_name, domain)) {
+                               continue;
+                       }
                }
-       } else if (response.extra_data.data) {
-               char *extra_data = (char *)response.extra_data.data;
-               d_printf("%s", extra_data);
-               SAFE_FREE(response.extra_data.data);
+
+               is_offline = (domain_list[i].domain_flags & WBC_DOMINFO_DOMAIN_OFFLINE);
+               
+               d_printf("%s : %s\n", 
+                        domain_list[i].short_name,
+                        is_offline ? "offline" : "online" );
        }
 
        return true;
 }
 
+
 /* Show domain info */
 
 static bool wbinfo_domain_info(const char *domain)
@@ -1317,7 +1321,8 @@ enum {
        OPT_LIST_OWN_DOMAIN,
        OPT_UID_INFO,
        OPT_GROUP_INFO,
-       OPT_VERBOSE
+       OPT_VERBOSE,
+       OPT_ONLINESTATUS
 };
 
 int main(int argc, char **argv, char **envp)
@@ -1357,6 +1362,7 @@ int main(int argc, char **argv, char **envp)
                { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
                { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
                { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" },
+               { "online-status", 0, POPT_ARG_NONE, 0, OPT_ONLINESTATUS, "Show whether domains are marked as online or offline"},
                { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
                { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" },
                { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" },
@@ -1529,6 +1535,12 @@ int main(int argc, char **argv, char **envp)
                                goto done;
                        }
                        break;
+               case OPT_ONLINESTATUS:
+                       if (!wbinfo_show_onlinestatus(opt_domain_name)) {
+                               d_fprintf(stderr, "Could not show online-status\n");
+                               goto done;
+                       }
+                       break;
                case 'D':
                        if (!wbinfo_domain_info(string_arg)) {
                                d_fprintf(stderr, "Could not get domain info\n");
index bde2eafb53563596fca42a4ed59b3bc7c0057d57..8933cf27945d058dcd58af1807bb72cbaeecb6da 100644 (file)
@@ -173,20 +173,29 @@ void winbindd_list_trusted_domains(struct winbindd_cli_state *state)
        }
 
        for ( i = 0; i < num_domains; i++ ) {
+               struct winbindd_domain *domain;
+               bool is_online = true;          
+
                d = &dom_list[i];
+               domain = find_domain_from_name_noinit(d->domain_name);
+               if (domain) {
+                       is_online = domain->online;
+               }
+
                if ( !extra_data ) {
                        extra_data = talloc_asprintf(state->mem_ctx, 
-                                                    "%s\\%s\\%s\\%s\\%s\\%s\\%s",
+                                                    "%s\\%s\\%s\\%s\\%s\\%s\\%s\\%s",
                                                     d->domain_name,
                                                     d->dns_name ? d->dns_name : d->domain_name,
                                                     sid_string_talloc(state->mem_ctx, &d->sid),
                                                     get_trust_type_string(d),
                                                     trust_is_transitive(d) ? "Yes" : "No",
                                                     trust_is_inbound(d) ? "Yes" : "No",
-                                                    trust_is_outbound(d) ? "Yes" : "No");
+                                                    trust_is_outbound(d) ? "Yes" : "No",
+                                                    is_online ? "Online" : "Offline" );
                } else {
                        extra_data = talloc_asprintf(state->mem_ctx, 
-                                                    "%s\n%s\\%s\\%s\\%s\\%s\\%s\\%s",
+                                                    "%s\n%s\\%s\\%s\\%s\\%s\\%s\\%s\\%s",
                                                     extra_data,
                                                     d->domain_name,
                                                     d->dns_name ? d->dns_name : d->domain_name,
@@ -194,7 +203,8 @@ void winbindd_list_trusted_domains(struct winbindd_cli_state *state)
                                                     get_trust_type_string(d),
                                                     trust_is_transitive(d) ? "Yes" : "No",
                                                     trust_is_inbound(d) ? "Yes" : "No",
-                                                    trust_is_outbound(d) ? "Yes" : "No");
+                                                    trust_is_outbound(d) ? "Yes" : "No",
+                                                    is_online ? "Online" : "Offline" );
                }
        }