monit-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[monit-dev] [monit] r298 committed - Fix rsync protocol test:...


From: monit
Subject: [monit-dev] [monit] r298 committed - Fix rsync protocol test:...
Date: Tue, 05 Oct 2010 21:42:04 +0000

Revision: 298
Author: martin2812
Date: Tue Oct  5 14:35:39 2010
Log: Fix rsync protocol test:

1.) send the full greeting back to the server (including minor version) ... originally rsync server returned error as the greeting sent by
    monit was missing minor version

2.) process full server response (listing + exit) so we won't close the connection too early (on first listing line) and won't
   send TCP RST back to server when rest of response is received


http://code.google.com/p/monit/source/detail?r=298

Modified:
 /trunk/CHANGES.txt
 /trunk/protocols/rsync.c

=======================================
--- /trunk/CHANGES.txt  Fri Oct  1 07:28:43 2010
+++ /trunk/CHANGES.txt  Tue Oct  5 14:35:39 2010
@@ -21,6 +21,9 @@
perform ping, monit will skip the icmp test and log message (in debug
        mode only).

+* rsync protocol test:
+     - bug #31249: send full version to rsync server
+


 Version 5.2.1
=======================================
--- /trunk/protocols/rsync.c    Fri Jan  8 03:20:43 2010
+++ /trunk/protocols/rsync.c    Tue Oct  5 14:35:39 2010
@@ -47,58 +47,63 @@
 /**
* Check the server for greeting "@RSYNCD: XX, then send this greeting back
  *  to server, send command '#list' to get a listing of modules.
- *
+ *
  *  @author Igor Homyakov <address@hidden>
  *
  *  @file
  */
 int check_rsync(Socket_T s) {
-
-  char  buf[STRLEN];
-  char  msg[STRLEN];
-  int   rc, version;
+  char  buf[64];
+  char  header[10];
+  char  result[64];
+  int   rc, version_major, version_minor;
   char  *rsyncd = "@RSYNCD:";
-
+  char  *rsyncd_exit = "@RSYNCD: EXIT";
+
   ASSERT(s);
-
-  if(!socket_readln(s, buf, sizeof(buf))) {
+
+  /* Read and check the greeting */
+  if (!socket_readln(s, buf, sizeof(buf))) {
     LogError("RSYNC: did not see server greeting  -- %s\n", STRERROR);
     return FALSE;
   }
-
   Util_chomp(buf);
-
-  rc = sscanf(buf, "%255s %d", msg, &version);
-  if ((rc == EOF) || (rc == 0)) {
-     LogError("RSYNC: server greeting parse error %s\n", buf);
+  rc = sscanf(buf, "%10s %d.%d", header, &version_major, &version_minor);
+  if ((rc == EOF) || (rc != 3)) {
+    LogError("RSYNC: server greeting parse error %s\n", buf);
     return FALSE;
   }
-
-  if(strncasecmp(msg, rsyncd, strlen(rsyncd)) != 0) {
-    LogError("RSYNC: server sent \"%s\" rather than greeting\n", buf);
+  if (strncasecmp(header, rsyncd, strlen(rsyncd)) != 0) {
+    LogError("RSYNC: server sent unexpected greeting -- %s\n", buf);
     return FALSE;
   }

-  if(snprintf(buf, sizeof(buf), "%s %d\n", rsyncd, version) < 0) {
-    LogError("RSYNC: string copy error -- %s\n", STRERROR);
+  /* Send back the greeting */
+  if (socket_print(s, "%s\n", buf) <= 0) {
+    LogError("RSYNC: identification string send failed -- %s\n", STRERROR);
     return FALSE;
-  }
-
-  if(socket_write(s, buf, strlen(buf)) <= 0) {
- LogError("RSYNC: error sending identification string -- %s\n", STRERROR);
-     return FALSE;
   }

-  if(socket_print(s, "#list\n") < 0) {
- LogError("RSYNC: error sending writing #list command -- %s\n", STRERROR);
+  /* Send #list command */
+  if (socket_print(s, "#list\n") < 0) {
+    LogError("RSYNC: #list command failed -- %s\n", STRERROR);
     return FALSE;
   }

-  if(!socket_readln(s, buf, sizeof(buf))) {
-    LogError("RSYNC: did not see server answer  -- %s\n", STRERROR);
+ /* Read response: discard list output and check that we've received successful exit */
+  do {
+    if (! socket_readln(s, buf, sizeof(buf))) {
+      LogError("RSYNC: error receiving data -- %s\n", STRERROR);
+      return FALSE;
+    }
+    Util_chomp(buf);
+  } while (strncasecmp(buf, rsyncd, strlen(rsyncd)));
+  if (strncasecmp(buf, rsyncd_exit, strlen(rsyncd_exit)) != 0) {
+    LogError("RSYNC: server sent unexpected response -- %s\n", buf);
     return FALSE;
   }
-
+
   return TRUE;
-
-}
+
+}
+



reply via email to

[Prev in Thread] Current Thread [Next in Thread]