Author: gd
Date: 2006-05-04 12:37:13 +0000 (Thu, 04 May 2006)
New Revision: 15428

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=15428

Log:
Add "smbcontrol winbind onlinestatus" for debugging purpose.

Guenther

Modified:
   branches/SAMBA_3_0/source/include/messages.h
   branches/SAMBA_3_0/source/nsswitch/winbindd.c
   branches/SAMBA_3_0/source/nsswitch/winbindd_cache.c
   branches/SAMBA_3_0/source/nsswitch/winbindd_dual.c
   branches/SAMBA_3_0/source/utils/smbcontrol.c
   trunk/source/include/messages.h
   trunk/source/nsswitch/winbindd.c
   trunk/source/nsswitch/winbindd_cache.c
   trunk/source/nsswitch/winbindd_dual.c
   trunk/source/utils/smbcontrol.c


Changeset:
Modified: branches/SAMBA_3_0/source/include/messages.h
===================================================================
--- branches/SAMBA_3_0/source/include/messages.h        2006-05-04 11:01:10 UTC 
(rev 15427)
+++ branches/SAMBA_3_0/source/include/messages.h        2006-05-04 12:37:13 UTC 
(rev 15428)
@@ -76,6 +76,7 @@
 #define MSG_WINBIND_FORGET_STATE 4002
 #define MSG_WINBIND_ONLINE       4003
 #define MSG_WINBIND_OFFLINE      4004
+#define MSG_WINBIND_ONLINESTATUS 4005
 
 /* Flags to classify messages - used in message_send_all() */
 /* Sender will filter by flag. */

Modified: branches/SAMBA_3_0/source/nsswitch/winbindd.c
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/winbindd.c       2006-05-04 11:01:10 UTC 
(rev 15427)
+++ branches/SAMBA_3_0/source/nsswitch/winbindd.c       2006-05-04 12:37:13 UTC 
(rev 15428)
@@ -1035,6 +1035,7 @@
        /* Handle online/offline messages. */
        message_register(MSG_WINBIND_OFFLINE,winbind_msg_offline);
        message_register(MSG_WINBIND_ONLINE,winbind_msg_online);
+       message_register(MSG_WINBIND_ONLINESTATUS,winbind_msg_onlinestatus);
 
        poptFreeContext(pc);
 

Modified: branches/SAMBA_3_0/source/nsswitch/winbindd_cache.c
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/winbindd_cache.c 2006-05-04 11:01:10 UTC 
(rev 15427)
+++ branches/SAMBA_3_0/source/nsswitch/winbindd_cache.c 2006-05-04 12:37:13 UTC 
(rev 15428)
@@ -2357,6 +2357,11 @@
        tdb_delete_bystring(wcache->tdb, "WINBINDD_OFFLINE");
 }
 
+BOOL get_global_winbindd_state_online(void)
+{
+       return global_winbindd_offline_state;
+}
+
 /* the cache backend methods are exposed via this structure */
 struct winbindd_methods cache_methods = {
        True,

Modified: branches/SAMBA_3_0/source/nsswitch/winbindd_dual.c
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/winbindd_dual.c  2006-05-04 11:01:10 UTC 
(rev 15427)
+++ branches/SAMBA_3_0/source/nsswitch/winbindd_dual.c  2006-05-04 12:37:13 UTC 
(rev 15428)
@@ -496,6 +496,26 @@
        }
 }
 
+/* Forward the online/offline messages to our children. */
+void winbind_msg_onlinestatus(int msg_type, struct process_id src, void *buf, 
size_t len)
+{
+       struct winbindd_child *child;
+
+       DEBUG(10,("winbind_msg_onlinestatus: got onlinestatus message.\n"));
+
+       for (child = children; child != NULL; child = child->next) {
+               if (child->domain && child->domain->primary) {
+                       DEBUG(10,("winbind_msg_onlinestatus: "
+                                 "sending message to pid %u of primary 
domain.\n",
+                                 (unsigned int)child->pid));
+                       message_send_pid(pid_to_procid(child->pid), 
+                                        MSG_WINBIND_ONLINESTATUS, buf, len, 
False);
+                       break;
+               }
+       }
+}
+
+
 static void account_lockout_policy_handler(struct timed_event *te,
                                           const struct timeval *now,
                                           void *private_data)
@@ -582,6 +602,60 @@
        }
 }
 
+static const char *collect_onlinestatus(TALLOC_CTX *mem_ctx)
+{
+       struct winbindd_domain *domain;
+       char *buf = NULL;
+
+       if ((buf = talloc_asprintf(mem_ctx, "global:%s ", 
+                                  get_global_winbindd_state_online() ? 
+                                  "Offline":"Online")) == NULL) {
+               return NULL;
+       }
+
+       for (domain = domain_list(); domain; domain = domain->next) {
+               if ((buf = talloc_asprintf_append(buf, "%s:%s ", 
+                                                 domain->name, 
+                                                 domain->online ?
+                                                 "Online":"Offline")) == NULL) 
{
+                       return NULL;
+               }
+       }
+
+       buf = talloc_asprintf_append(buf, "\n");
+
+       DEBUG(5,("collect_onlinestatus: %s\n", buf));
+
+       return buf;
+}
+
+static void child_msg_onlinestatus(int msg_type, struct process_id src, void 
*buf, size_t len)
+{
+       TALLOC_CTX *mem_ctx;
+       const char *message;
+       struct process_id *sender;
+       
+       DEBUG(5,("winbind_msg_onlinestatus received.\n"));
+
+       if (!buf) {
+               return;
+       }
+
+       sender = (struct process_id *)buf;
+
+       mem_ctx = talloc_init("winbind_msg_onlinestatus");
+       if (mem_ctx == NULL) {
+               return;
+       }
+       
+       message = collect_onlinestatus(mem_ctx);
+
+       message_send_pid(*sender, MSG_WINBIND_ONLINESTATUS, 
+                        message, strlen(message) + 1, True);
+
+       talloc_destroy(mem_ctx);
+}
+
 static BOOL fork_domain_child(struct winbindd_child *child)
 {
        int fdpair[2];
@@ -646,6 +720,7 @@
        message_deregister(MSG_SHUTDOWN);
        message_deregister(MSG_WINBIND_OFFLINE);
        message_deregister(MSG_WINBIND_ONLINE);
+       message_deregister(MSG_WINBIND_ONLINESTATUS);
 
        /* The child is ok with online/offline messages now. */
        message_unblock();
@@ -667,6 +742,7 @@
        /* Handle online/offline messages. */
        message_register(MSG_WINBIND_OFFLINE,child_msg_offline);
        message_register(MSG_WINBIND_ONLINE,child_msg_online);
+       message_register(MSG_WINBIND_ONLINESTATUS,child_msg_onlinestatus);
 
        while (1) {
 

Modified: branches/SAMBA_3_0/source/utils/smbcontrol.c
===================================================================
--- branches/SAMBA_3_0/source/utils/smbcontrol.c        2006-05-04 11:01:10 UTC 
(rev 15427)
+++ branches/SAMBA_3_0/source/utils/smbcontrol.c        2006-05-04 12:37:13 UTC 
(rev 15428)
@@ -909,6 +909,36 @@
        return ret;
 }
 
+static BOOL do_winbind_onlinestatus(const struct process_id pid,
+                                   const int argc, const char **argv)
+{
+       struct process_id myid;
+
+       myid = pid_to_procid(sys_getpid());
+
+       if (argc != 1) {
+               fprintf(stderr, "Usage: smbcontrol winbindd onlinestatus\n");
+               return False;
+       }
+
+       message_register(MSG_WINBIND_ONLINESTATUS, print_pid_string_cb);
+
+       if (!send_message(pid, MSG_WINBIND_ONLINESTATUS, &myid, sizeof(myid), 
False))
+               return False;
+
+       wait_replies(procid_to_pid(&pid) == 0);
+
+       /* No replies were received within the timeout period */
+
+       if (num_replies == 0)
+               printf("No replies received\n");
+
+       message_deregister(MSG_WINBIND_ONLINESTATUS);
+
+       return num_replies;
+}
+
+
 static BOOL do_reload_config(const struct process_id pid,
                             const int argc, const char **argv)
 {
@@ -999,6 +1029,7 @@
        { "nodestatus", do_nodestatus, "Ask nmbd to do a node status request"},
        { "online", do_winbind_online, "Ask winbind to go into online state"},
        { "offline", do_winbind_offline, "Ask winbind to go into offline 
state"},
+       { "onlinestatus", do_winbind_onlinestatus, "Request winbind online 
status"},
        { "noop", do_noop, "Do nothing" },
        { NULL }
 };

Modified: trunk/source/include/messages.h
===================================================================
--- trunk/source/include/messages.h     2006-05-04 11:01:10 UTC (rev 15427)
+++ trunk/source/include/messages.h     2006-05-04 12:37:13 UTC (rev 15428)
@@ -76,6 +76,7 @@
 #define MSG_WINBIND_FORGET_STATE 4002
 #define MSG_WINBIND_ONLINE       4003
 #define MSG_WINBIND_OFFLINE      4004
+#define MSG_WINBIND_ONLINESTATUS 4005
 
 /* Flags to classify messages - used in message_send_all() */
 /* Sender will filter by flag. */

Modified: trunk/source/nsswitch/winbindd.c
===================================================================
--- trunk/source/nsswitch/winbindd.c    2006-05-04 11:01:10 UTC (rev 15427)
+++ trunk/source/nsswitch/winbindd.c    2006-05-04 12:37:13 UTC (rev 15428)
@@ -1036,6 +1036,7 @@
        /* Handle online/offline messages. */
        message_register(MSG_WINBIND_OFFLINE,winbind_msg_offline);
        message_register(MSG_WINBIND_ONLINE,winbind_msg_online);
+       message_register(MSG_WINBIND_ONLINESTATUS,winbind_msg_onlinestatus);
 
        poptFreeContext(pc);
 

Modified: trunk/source/nsswitch/winbindd_cache.c
===================================================================
--- trunk/source/nsswitch/winbindd_cache.c      2006-05-04 11:01:10 UTC (rev 
15427)
+++ trunk/source/nsswitch/winbindd_cache.c      2006-05-04 12:37:13 UTC (rev 
15428)
@@ -2479,6 +2479,11 @@
        tdb_delete_bystring(wcache->tdb, "WINBINDD_OFFLINE");
 }
 
+BOOL get_global_winbindd_state_online(void)
+{
+       return global_winbindd_offline_state;
+}
+
 /* the cache backend methods are exposed via this structure */
 struct winbindd_methods cache_methods = {
        True,

Modified: trunk/source/nsswitch/winbindd_dual.c
===================================================================
--- trunk/source/nsswitch/winbindd_dual.c       2006-05-04 11:01:10 UTC (rev 
15427)
+++ trunk/source/nsswitch/winbindd_dual.c       2006-05-04 12:37:13 UTC (rev 
15428)
@@ -497,6 +497,26 @@
        }
 }
 
+/* Forward the online/offline messages to our children. */
+void winbind_msg_onlinestatus(int msg_type, struct process_id src, void *buf, 
size_t len)
+{
+       struct winbindd_child *child;
+
+       DEBUG(10,("winbind_msg_onlinestatus: got onlinestatus message.\n"));
+
+       for (child = children; child != NULL; child = child->next) {
+               if (child->domain && child->domain->primary) {
+                       DEBUG(10,("winbind_msg_onlinestatus: "
+                                 "sending message to pid %u of primary 
domain.\n",
+                                 (unsigned int)child->pid));
+                       message_send_pid(pid_to_procid(child->pid), 
+                                        MSG_WINBIND_ONLINESTATUS, buf, len, 
False);
+                       break;
+               }
+       }
+}
+
+
 static void account_lockout_policy_handler(struct timed_event *te,
                                           const struct timeval *now,
                                           void *private_data)
@@ -583,6 +603,60 @@
        }
 }
 
+static const char *collect_onlinestatus(TALLOC_CTX *mem_ctx)
+{
+       struct winbindd_domain *domain;
+       char *buf = NULL;
+
+       if ((buf = talloc_asprintf(mem_ctx, "global:%s ", 
+                                  get_global_winbindd_state_online() ? 
+                                  "Offline":"Online")) == NULL) {
+               return NULL;
+       }
+
+       for (domain = domain_list(); domain; domain = domain->next) {
+               if ((buf = talloc_asprintf_append(buf, "%s:%s ", 
+                                                 domain->name, 
+                                                 domain->online ?
+                                                 "Online":"Offline")) == NULL) 
{
+                       return NULL;
+               }
+       }
+
+       buf = talloc_asprintf_append(buf, "\n");
+
+       DEBUG(5,("collect_onlinestatus: %s\n", buf));
+
+       return buf;
+}
+
+static void child_msg_onlinestatus(int msg_type, struct process_id src, void 
*buf, size_t len)
+{
+       TALLOC_CTX *mem_ctx;
+       const char *message;
+       struct process_id *sender;
+       
+       DEBUG(5,("winbind_msg_onlinestatus received.\n"));
+
+       if (!buf) {
+               return;
+       }
+
+       sender = (struct process_id *)buf;
+
+       mem_ctx = talloc_init("winbind_msg_onlinestatus");
+       if (mem_ctx == NULL) {
+               return;
+       }
+       
+       message = collect_onlinestatus(mem_ctx);
+
+       message_send_pid(*sender, MSG_WINBIND_ONLINESTATUS, 
+                        message, strlen(message) + 1, True);
+
+       talloc_destroy(mem_ctx);
+}
+
 static BOOL fork_domain_child(struct winbindd_child *child)
 {
        int fdpair[2];
@@ -647,6 +721,7 @@
        message_deregister(MSG_SHUTDOWN);
        message_deregister(MSG_WINBIND_OFFLINE);
        message_deregister(MSG_WINBIND_ONLINE);
+       message_deregister(MSG_WINBIND_ONLINESTATUS);
 
        /* The child is ok with online/offline messages now. */
        message_unblock();
@@ -668,6 +743,7 @@
        /* Handle online/offline messages. */
        message_register(MSG_WINBIND_OFFLINE,child_msg_offline);
        message_register(MSG_WINBIND_ONLINE,child_msg_online);
+       message_register(MSG_WINBIND_ONLINESTATUS,child_msg_onlinestatus);
 
        while (1) {
 

Modified: trunk/source/utils/smbcontrol.c
===================================================================
--- trunk/source/utils/smbcontrol.c     2006-05-04 11:01:10 UTC (rev 15427)
+++ trunk/source/utils/smbcontrol.c     2006-05-04 12:37:13 UTC (rev 15428)
@@ -909,6 +909,36 @@
        return ret;
 }
 
+static BOOL do_winbind_onlinestatus(const struct process_id pid,
+                                   const int argc, const char **argv)
+{
+       struct process_id myid;
+
+       myid = pid_to_procid(sys_getpid());
+
+       if (argc != 1) {
+               fprintf(stderr, "Usage: smbcontrol winbindd onlinestatus\n");
+               return False;
+       }
+
+       message_register(MSG_WINBIND_ONLINESTATUS, print_pid_string_cb);
+
+       if (!send_message(pid, MSG_WINBIND_ONLINESTATUS, &myid, sizeof(myid), 
False))
+               return False;
+
+       wait_replies(procid_to_pid(&pid) == 0);
+
+       /* No replies were received within the timeout period */
+
+       if (num_replies == 0)
+               printf("No replies received\n");
+
+       message_deregister(MSG_WINBIND_ONLINESTATUS);
+
+       return num_replies;
+}
+
+
 static BOOL do_reload_config(const struct process_id pid,
                             const int argc, const char **argv)
 {
@@ -999,6 +1029,7 @@
        { "nodestatus", do_nodestatus, "Ask nmbd to do a node status request"},
        { "online", do_winbind_online, "Ask winbind to go into online state"},
        { "offline", do_winbind_offline, "Ask winbind to go into offline 
state"},
+       { "onlinestatus", do_winbind_onlinestatus, "Request winbind online 
status"},
        { "noop", do_noop, "Do nothing" },
        { NULL }
 };

Reply via email to