whitelist: Read multiple commands until client closes connection
authorMartin Willi <martin@revosec.ch>
Tue, 29 Oct 2013 13:11:41 +0000 (14:11 +0100)
committerMartin Willi <martin@revosec.ch>
Tue, 29 Oct 2013 13:22:52 +0000 (14:22 +0100)
This restores the same behavior we had before e11c02c8, and fixes the whitelist
add/remove-from command.

src/libcharon/plugins/whitelist/whitelist_control.c

index e97885c..996f263 100644 (file)
@@ -99,38 +99,36 @@ static bool on_accept(private_whitelist_control_t *this, stream_t *stream)
        identification_t *id;
        whitelist_msg_t msg;
 
-       if (!stream->read_all(stream, &msg, sizeof(msg)))
+       while (stream->read_all(stream, &msg, sizeof(msg)))
        {
-               return FALSE;
-       }
-
-       msg.id[sizeof(msg.id) - 1] = 0;
-       id = identification_create_from_string(msg.id);
-       switch (ntohl(msg.type))
-       {
-               case WHITELIST_ADD:
-                       this->listener->add(this->listener, id);
-                       break;
-               case WHITELIST_REMOVE:
-                       this->listener->remove(this->listener, id);
-                       break;
-               case WHITELIST_LIST:
-                       list(this, stream, id);
-                       break;
-               case WHITELIST_FLUSH:
-                       this->listener->flush(this->listener, id);
-                       break;
-               case WHITELIST_ENABLE:
-                       this->listener->set_active(this->listener, TRUE);
-                       break;
-               case WHITELIST_DISABLE:
-                       this->listener->set_active(this->listener, FALSE);
-                       break;
-               default:
-                       DBG1(DBG_CFG, "received unknown whitelist command");
-                       break;
+               msg.id[sizeof(msg.id) - 1] = 0;
+               id = identification_create_from_string(msg.id);
+               switch (ntohl(msg.type))
+               {
+                       case WHITELIST_ADD:
+                               this->listener->add(this->listener, id);
+                               break;
+                       case WHITELIST_REMOVE:
+                               this->listener->remove(this->listener, id);
+                               break;
+                       case WHITELIST_LIST:
+                               list(this, stream, id);
+                               break;
+                       case WHITELIST_FLUSH:
+                               this->listener->flush(this->listener, id);
+                               break;
+                       case WHITELIST_ENABLE:
+                               this->listener->set_active(this->listener, TRUE);
+                               break;
+                       case WHITELIST_DISABLE:
+                               this->listener->set_active(this->listener, FALSE);
+                               break;
+                       default:
+                               DBG1(DBG_CFG, "received unknown whitelist command");
+                               break;
+               }
+               id->destroy(id);
        }
-       id->destroy(id);
 
        return FALSE;
 }