mike-jumper commented on a change in pull request #243: GUACAMOLE-249: Migrate 
to FreeRDP 2.x
URL: https://github.com/apache/guacamole-server/pull/243#discussion_r364951731
 
 

 ##########
 File path: src/protocols/rdp/plugins/channels.c
 ##########
 @@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "plugins/channels.h"
+
+#include <freerdp/channels/channels.h>
+#include <freerdp/freerdp.h>
+#include <freerdp/addin.h>
+#include <winpr/wtypes.h>
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+
+int guac_rdp_wrapped_entry_ex_count = 0;
+
+int guac_rdp_wrapped_entry_count = 0;
+
+PVIRTUALCHANNELENTRYEX guac_rdp_wrapped_entry_ex[GUAC_RDP_MAX_CHANNELS] = { 
NULL };
+
+PVIRTUALCHANNELENTRY guac_rdp_wrapped_entry[GUAC_RDP_MAX_CHANNELS] = { NULL };
+
+PVIRTUALCHANNELENTRYEX guac_rdp_plugin_wrap_entry_ex(PVIRTUALCHANNELENTRYEX 
entry_ex) {
+
+    /* Do not wrap if there is insufficient space to store the wrapped
+     * function */
+    if (guac_rdp_wrapped_entry_ex_count == GUAC_RDP_MAX_CHANNELS)
+        return entry_ex;
+
+    /* Generate wrapped version of provided entry point */
+    PVIRTUALCHANNELENTRYEX wrapper = 
guac_rdp_entry_ex_wrappers[guac_rdp_wrapped_entry_ex_count];
+    guac_rdp_wrapped_entry_ex[guac_rdp_wrapped_entry_ex_count] = entry_ex;
+    guac_rdp_wrapped_entry_ex_count++;
+
+    return wrapper;
+
+}
+
+PVIRTUALCHANNELENTRY guac_rdp_plugin_wrap_entry(PVIRTUALCHANNELENTRY entry) {
+
+    /* Do not wrap if there is insufficient space to store the wrapped
+     * function */
+    if (guac_rdp_wrapped_entry_count == GUAC_RDP_MAX_CHANNELS)
 
 Review comment:
   > No warning or anything if wrapping fails?
   
   To log a message using the normal logging subsystem exposed by libguac, we 
would need access to the `guac_client`, however the `guac_client` is 
unavailable at this level as the calling function 
(`guac_freerdp_channels_load_plugin()`) was meant to be a drop-in replacement 
for part of the FreeRDP API (`freerdp_channels_load_plugin()`) and none of the 
parameters received by these functions have a path for reaching the 
`guac_client`.
   
   We could work around this by:
   
   * *Not* having this function be a true drop-in replacement. There is 
arguably little utility to having the function be a drop-in replacement now 
that the code has been migrated. Passing different arguments (perhaps 
`rdpContext`) would allow access to the associated `guac_client`.
   * Using FreeRDP's logging subsystem (part of libwinpr). That subsystem is 
rerouted early on in the connection process such that all messages logged from 
FreeRDP actually get logged to the `guac_client` at the debug level.
   
   > What are the consequences if this happens?
   
   Generally, it shouldn't - there is an upper bound on the maximum number of 
static channels that can be loaded. This upper bound is set by RDP itself and 
by FreeRDP, and the `GUAC_RDP_MAX_CHANNELS` constant is set to a value that is 
intended to be well above this limit. While we can't verify this at runtime, 
there is a compile-time check that will fail the build if the constant is set 
incorrectly:
   
   
https://github.com/apache/guacamole-server/blob/55959b54564cd7ce8800225ed8d3741345eb90a2/src/protocols/rdp/plugins/channels.h#L39-L42
   
   The plugin would fail to load due to there not being a slot available to 
hold the plugin.
   
   Setting that aside, though, let's assume something strange is going on and 
the plugin does successfully load after the limit is reached:
   
   The first attempt to load a plugin X would succeed, as prior instances of X 
had their entry points wrapped and FreeRDP sees this load attempt as unique. 
After this point, further attempts to load copies of X would fail due to its 
entry point already being present, and FreeRDP would refuse to load the plugin.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to