From e3e034c9c18f88ee8ce9be30b94b3a50920be8fe Mon Sep 17 00:00:00 2001 From: ivanpauno Date: Mon, 23 Sep 2019 14:46:03 -0300 Subject: [PATCH 01/23] Switch to one participant per context. Signed-off-by: ivanpauno --- rmw/CMakeLists.txt | 1 + rmw/include/rmw/init.h | 20 +------ rmw/include/rmw/init_options.h | 27 +-------- rmw/include/rmw/rmw.h | 2 +- ..._security_options.h => security_options.h} | 16 +++--- rmw/include/rmw/types.h | 57 ++++++++++++++++++- ..._security_options.c => security_options.c} | 16 +++--- 7 files changed, 74 insertions(+), 65 deletions(-) rename rmw/include/rmw/{node_security_options.h => security_options.h} (67%) rename rmw/src/{node_security_options.c => security_options.c} (67%) diff --git a/rmw/CMakeLists.txt b/rmw/CMakeLists.txt index 34c638ae..f1b8e07b 100644 --- a/rmw/CMakeLists.txt +++ b/rmw/CMakeLists.txt @@ -35,6 +35,7 @@ set(rmw_sources "src/node_security_options.c" "src/publisher_options.c" "src/sanity_checks.c" + "src/security_options.c" "src/subscription_options.c" "src/topic_endpoint_info_array.c" "src/topic_endpoint_info.c" diff --git a/rmw/include/rmw/init.h b/rmw/include/rmw/init.h index 95fa48a2..2b53c690 100644 --- a/rmw/include/rmw/init.h +++ b/rmw/include/rmw/init.h @@ -22,29 +22,11 @@ extern "C" #include -#include "rmw/init_options.h" #include "rmw/macros.h" #include "rmw/ret_types.h" +#include "rmw/types.h" #include "rmw/visibility_control.h" -/// Implementation defined context structure returned by rmw_init(). -/** - * This should be defined by the rmw implementation. - */ -typedef struct rmw_context_impl_t rmw_context_impl_t; - -/// Initialization context structure which is used to store init specific information. -typedef struct RMW_PUBLIC_TYPE rmw_context_t -{ - /// Locally (process local) unique ID that represents this init/shutdown cycle. - uint64_t instance_id; - /// Implementation identifier, used to ensure two different implementations are not being mixed. - const char * implementation_identifier; - /// Implementation defined context information. - /** May be NULL if there is no implementation defined context information. */ - rmw_context_impl_t * impl; -} rmw_context_t; - /// Return a zero initialized context structure. RMW_PUBLIC RMW_WARN_UNUSED diff --git a/rmw/include/rmw/init_options.h b/rmw/include/rmw/init_options.h index 8d8a64cc..994eef1c 100644 --- a/rmw/include/rmw/init_options.h +++ b/rmw/include/rmw/init_options.h @@ -25,34 +25,9 @@ extern "C" #include "rcutils/allocator.h" #include "rmw/macros.h" #include "rmw/ret_types.h" +#include "rmw/types.h" #include "rmw/visibility_control.h" -/// Implementation defined options structure used during rmw_init(). -/** - * This should be defined by the rmw implementation. - */ -typedef struct rmw_init_options_impl_t rmw_init_options_impl_t; - -/// Options structure used during rmw_init(). -typedef struct RMW_PUBLIC_TYPE rmw_init_options_t -{ - /// Locally (process local) unique ID that represents this init/shutdown cycle. - /** - * This should be set by the caller of `rmw_init()` to a number that is - * unique within this process. - * It is designed to be used with `rcl_init()` and `rcl_get_instance_id()`. - */ - uint64_t instance_id; - /// Implementation identifier, used to ensure two different implementations are not being mixed. - const char * implementation_identifier; - // TODO(wjwwood): replace with rmw_allocator_t when that refactor happens - /// Allocator used during internal allocation of init options, if needed. - rcutils_allocator_t allocator; - /// Implementation defined init options. - /** May be NULL if there are no implementation defined options. */ - rmw_init_options_impl_t * impl; -} rmw_init_options_t; - /// Return a zero initialized init options structure. RMW_PUBLIC RMW_WARN_UNUSED diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index 2fb995f1..36826f9c 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -173,7 +173,7 @@ rmw_create_node( const char * name, const char * namespace_, size_t domain_id, - const rmw_node_security_options_t * security_options, + const rmw_security_options_t * security_options, bool localhost_only); /// Finalize a given node handle, reclaim the resources, and deallocate the node handle. diff --git a/rmw/include/rmw/node_security_options.h b/rmw/include/rmw/security_options.h similarity index 67% rename from rmw/include/rmw/node_security_options.h rename to rmw/include/rmw/security_options.h index fafc5543..ae30f8ad 100644 --- a/rmw/include/rmw/node_security_options.h +++ b/rmw/include/rmw/security_options.h @@ -1,4 +1,4 @@ -// Copyright 2017 Open Source Robotics Foundation, Inc. +// Copyright 2017-2019 Open Source Robotics Foundation, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RMW__NODE_SECURITY_OPTIONS_H_ -#define RMW__NODE_SECURITY_OPTIONS_H_ +#ifndef RMW__SECURITY_OPTIONS_H_ +#define RMW__SECURITY_OPTIONS_H_ #ifdef __cplusplus extern "C" @@ -23,15 +23,15 @@ extern "C" #include "rmw/types.h" RMW_PUBLIC -rmw_node_security_options_t -rmw_get_zero_initialized_node_security_options(); +rmw_security_options_t +rmw_get_zero_initialized_security_options(); RMW_PUBLIC -rmw_node_security_options_t -rmw_get_default_node_security_options(); +rmw_security_options_t +rmw_get_default_security_options(); #ifdef __cplusplus } #endif -#endif // RMW__NODE_SECURITY_OPTIONS_H_ +#endif // RMW__SECURITY_OPTIONS_H_ diff --git a/rmw/include/rmw/types.h b/rmw/include/rmw/types.h index cbbe5dd8..5879b684 100644 --- a/rmw/include/rmw/types.h +++ b/rmw/include/rmw/types.h @@ -27,7 +27,6 @@ extern "C" // map rcutils specific log levels to rmw speicfic type #include -#include "rmw/init.h" #include "rmw/loaned_message_sequence.h" #include "rmw/ret_types.h" #include "rmw/serialized_message.h" @@ -37,6 +36,24 @@ extern "C" // implementation. It may need to be increased in the future. #define RMW_GID_STORAGE_SIZE 24 +/// Implementation defined context structure returned by rmw_init(). +/** + * This should be defined by the rmw implementation. + */ +typedef struct rmw_context_impl_t rmw_context_impl_t; + +/// Initialization context structure which is used to store init specific information. +typedef struct RMW_PUBLIC_TYPE rmw_context_t +{ + /// Locally (process local) unique ID that represents this init/shutdown cycle. + uint64_t instance_id; + /// Implementation identifier, used to ensure two different implementations are not being mixed. + const char * implementation_identifier; + /// Implementation defined context information. + /** May be NULL if there is no implementation defined context information. */ + rmw_context_impl_t * impl; +} rmw_context_t; + typedef struct RMW_PUBLIC_TYPE rmw_node_t { const char * implementation_identifier; @@ -259,11 +276,45 @@ enum RMW_PUBLIC_TYPE rmw_security_enforcement_policy_t RMW_SECURITY_ENFORCEMENT_ENFORCE, }; -typedef struct RMW_PUBLIC_TYPE rmw_node_security_options_t +typedef struct RMW_PUBLIC_TYPE rmw_security_options_t { enum rmw_security_enforcement_policy_t enforce_security; const char * security_root_path; -} rmw_node_security_options_t; +} rmw_security_options_t; + +/// Constant which indicates that the default domain id should be used. +#define RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID SIZE_MAX + +/// Implementation defined options structure used during rmw_init(). +/** + * This should be defined by the rmw implementation. + */ +typedef struct rmw_init_options_impl_t rmw_init_options_impl_t; + +/// Options structure used during rmw_init(). +typedef struct RMW_PUBLIC_TYPE rmw_init_options_t +{ + /// Locally (process local) unique ID that represents this init/shutdown cycle. + /** + * This should be set by the caller of `rmw_init()` to a number that is + * unique within this process. + * It is designed to be used with `rcl_init()` and `rcl_get_instance_id()`. + */ + uint64_t instance_id; + /// Implementation identifier, used to ensure two different implementations are not being mixed. + const char * implementation_identifier; + /// ROS domain id + size_t domain_id; + /// Security options + rmw_security_options_t security_options; + + // TODO(wjwwood): replace with rmw_allocator_t when that refactor happens + /// Allocator used during internal allocation of init options, if needed. + rcutils_allocator_t allocator; + /// Implementation defined init options. + /** May be NULL if there are no implementation defined options. */ + rmw_init_options_impl_t * impl; +} rmw_init_options_t; enum RMW_PUBLIC_TYPE rmw_qos_reliability_policy_t { diff --git a/rmw/src/node_security_options.c b/rmw/src/security_options.c similarity index 67% rename from rmw/src/node_security_options.c rename to rmw/src/security_options.c index 0d7d5bc9..e13766cc 100644 --- a/rmw/src/node_security_options.c +++ b/rmw/src/security_options.c @@ -1,4 +1,4 @@ -// Copyright 2017 Open Source Robotics Foundation, Inc. +// Copyright 2017-2019 Open Source Robotics Foundation, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,19 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "rmw/node_security_options.h" +#include "rmw/security_options.h" -rmw_node_security_options_t -rmw_get_zero_initialized_node_security_options() +rmw_security_options_t +rmw_get_zero_initialized_security_options() { - static rmw_node_security_options_t null_security_options = {0, NULL}; + static rmw_security_options_t null_security_options = {0, NULL}; return null_security_options; } -rmw_node_security_options_t -rmw_get_default_node_security_options() +rmw_security_options_t +rmw_get_default_security_options() { - static rmw_node_security_options_t default_options; + static rmw_security_options_t default_options; default_options.enforce_security = RMW_SECURITY_ENFORCEMENT_PERMISSIVE; default_options.security_root_path = NULL; return default_options; From 2d8f8d6c9e8ab28c2483d4ffc06976c3bcf6dad6 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Tue, 26 Nov 2019 16:21:23 -0300 Subject: [PATCH 02/23] Reorganize headers. Correct get_default_init_options functions Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/init.h | 20 ++++++++- rmw/include/rmw/init_options.h | 35 +++++++++++++++- rmw/include/rmw/security_options.h | 14 ++++++- rmw/include/rmw/types.h | 67 ++---------------------------- rmw/src/init_options.c | 2 + rmw/src/security_options.c | 2 + 6 files changed, 73 insertions(+), 67 deletions(-) diff --git a/rmw/include/rmw/init.h b/rmw/include/rmw/init.h index 2b53c690..95fa48a2 100644 --- a/rmw/include/rmw/init.h +++ b/rmw/include/rmw/init.h @@ -22,11 +22,29 @@ extern "C" #include +#include "rmw/init_options.h" #include "rmw/macros.h" #include "rmw/ret_types.h" -#include "rmw/types.h" #include "rmw/visibility_control.h" +/// Implementation defined context structure returned by rmw_init(). +/** + * This should be defined by the rmw implementation. + */ +typedef struct rmw_context_impl_t rmw_context_impl_t; + +/// Initialization context structure which is used to store init specific information. +typedef struct RMW_PUBLIC_TYPE rmw_context_t +{ + /// Locally (process local) unique ID that represents this init/shutdown cycle. + uint64_t instance_id; + /// Implementation identifier, used to ensure two different implementations are not being mixed. + const char * implementation_identifier; + /// Implementation defined context information. + /** May be NULL if there is no implementation defined context information. */ + rmw_context_impl_t * impl; +} rmw_context_t; + /// Return a zero initialized context structure. RMW_PUBLIC RMW_WARN_UNUSED diff --git a/rmw/include/rmw/init_options.h b/rmw/include/rmw/init_options.h index 994eef1c..e55009e1 100644 --- a/rmw/include/rmw/init_options.h +++ b/rmw/include/rmw/init_options.h @@ -25,9 +25,42 @@ extern "C" #include "rcutils/allocator.h" #include "rmw/macros.h" #include "rmw/ret_types.h" -#include "rmw/types.h" +#include "rmw/security_options.h" #include "rmw/visibility_control.h" +/// Implementation defined options structure used during rmw_init(). +/** + * This should be defined by the rmw implementation. + */ +typedef struct rmw_init_options_impl_t rmw_init_options_impl_t; + +#define RMW_INIT_OPTIONS_DEFAULT_DOMAIN_ID SIZE_MAX + +/// Options structure used during rmw_init(). +typedef struct RMW_PUBLIC_TYPE rmw_init_options_t +{ + /// Locally (process local) unique ID that represents this init/shutdown cycle. + /** + * This should be set by the caller of `rmw_init()` to a number that is + * unique within this process. + * It is designed to be used with `rcl_init()` and `rcl_get_instance_id()`. + */ + uint64_t instance_id; + /// Implementation identifier, used to ensure two different implementations are not being mixed. + const char * implementation_identifier; + /// ROS domain id + size_t domain_id; + /// Security options + rmw_security_options_t security_options; + + // TODO(wjwwood): replace with rmw_allocator_t when that refactor happens + /// Allocator used during internal allocation of init options, if needed. + rcutils_allocator_t allocator; + /// Implementation defined init options. + /** May be NULL if there are no implementation defined options. */ + rmw_init_options_impl_t * impl; +} rmw_init_options_t; + /// Return a zero initialized init options structure. RMW_PUBLIC RMW_WARN_UNUSED diff --git a/rmw/include/rmw/security_options.h b/rmw/include/rmw/security_options.h index ae30f8ad..4bf5d723 100644 --- a/rmw/include/rmw/security_options.h +++ b/rmw/include/rmw/security_options.h @@ -20,7 +20,19 @@ extern "C" { #endif -#include "rmw/types.h" +#include "rmw/visibility_control.h" + +enum RMW_PUBLIC_TYPE rmw_security_enforcement_policy_t +{ + RMW_SECURITY_ENFORCEMENT_PERMISSIVE, + RMW_SECURITY_ENFORCEMENT_ENFORCE, +}; + +typedef struct RMW_PUBLIC_TYPE rmw_security_options_t +{ + enum rmw_security_enforcement_policy_t enforce_security; + const char * security_root_path; +} rmw_security_options_t; RMW_PUBLIC rmw_security_options_t diff --git a/rmw/include/rmw/types.h b/rmw/include/rmw/types.h index 5879b684..e4c76e93 100644 --- a/rmw/include/rmw/types.h +++ b/rmw/include/rmw/types.h @@ -27,8 +27,11 @@ extern "C" // map rcutils specific log levels to rmw speicfic type #include +#include "rmw/init.h" +#include "rmw/init_options.h" #include "rmw/loaned_message_sequence.h" #include "rmw/ret_types.h" +#include "rmw/security_options.h" #include "rmw/serialized_message.h" #include "rmw/visibility_control.h" @@ -36,24 +39,6 @@ extern "C" // implementation. It may need to be increased in the future. #define RMW_GID_STORAGE_SIZE 24 -/// Implementation defined context structure returned by rmw_init(). -/** - * This should be defined by the rmw implementation. - */ -typedef struct rmw_context_impl_t rmw_context_impl_t; - -/// Initialization context structure which is used to store init specific information. -typedef struct RMW_PUBLIC_TYPE rmw_context_t -{ - /// Locally (process local) unique ID that represents this init/shutdown cycle. - uint64_t instance_id; - /// Implementation identifier, used to ensure two different implementations are not being mixed. - const char * implementation_identifier; - /// Implementation defined context information. - /** May be NULL if there is no implementation defined context information. */ - rmw_context_impl_t * impl; -} rmw_context_t; - typedef struct RMW_PUBLIC_TYPE rmw_node_t { const char * implementation_identifier; @@ -270,52 +255,6 @@ typedef struct RMW_PUBLIC_TYPE rmw_time_t uint64_t nsec; } rmw_time_t; -enum RMW_PUBLIC_TYPE rmw_security_enforcement_policy_t -{ - RMW_SECURITY_ENFORCEMENT_PERMISSIVE, - RMW_SECURITY_ENFORCEMENT_ENFORCE, -}; - -typedef struct RMW_PUBLIC_TYPE rmw_security_options_t -{ - enum rmw_security_enforcement_policy_t enforce_security; - const char * security_root_path; -} rmw_security_options_t; - -/// Constant which indicates that the default domain id should be used. -#define RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID SIZE_MAX - -/// Implementation defined options structure used during rmw_init(). -/** - * This should be defined by the rmw implementation. - */ -typedef struct rmw_init_options_impl_t rmw_init_options_impl_t; - -/// Options structure used during rmw_init(). -typedef struct RMW_PUBLIC_TYPE rmw_init_options_t -{ - /// Locally (process local) unique ID that represents this init/shutdown cycle. - /** - * This should be set by the caller of `rmw_init()` to a number that is - * unique within this process. - * It is designed to be used with `rcl_init()` and `rcl_get_instance_id()`. - */ - uint64_t instance_id; - /// Implementation identifier, used to ensure two different implementations are not being mixed. - const char * implementation_identifier; - /// ROS domain id - size_t domain_id; - /// Security options - rmw_security_options_t security_options; - - // TODO(wjwwood): replace with rmw_allocator_t when that refactor happens - /// Allocator used during internal allocation of init options, if needed. - rcutils_allocator_t allocator; - /// Implementation defined init options. - /** May be NULL if there are no implementation defined options. */ - rmw_init_options_impl_t * impl; -} rmw_init_options_t; - enum RMW_PUBLIC_TYPE rmw_qos_reliability_policy_t { RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT, diff --git a/rmw/src/init_options.c b/rmw/src/init_options.c index de7701c2..54364d31 100644 --- a/rmw/src/init_options.c +++ b/rmw/src/init_options.c @@ -28,6 +28,8 @@ rmw_get_zero_initialized_init_options(void) .instance_id = 0, .implementation_identifier = NULL, .impl = NULL, + .domain_id = RMW_INIT_OPTIONS_DEFAULT_DOMAIN_ID, + .security_options = rmw_get_default_security_options(), }; // NOLINT(readability/braces): false positive } diff --git a/rmw/src/security_options.c b/rmw/src/security_options.c index e13766cc..0500de4c 100644 --- a/rmw/src/security_options.c +++ b/rmw/src/security_options.c @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include "rmw/security_options.h" rmw_security_options_t From 1a741a6dab0f779fd26b1c66859affca866ab539 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Fri, 13 Dec 2019 18:05:47 -0300 Subject: [PATCH 03/23] Addressed per review comments Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/domain_id.h | 21 +++++++++++++++++ rmw/include/rmw/init_options.h | 6 +++-- rmw/include/rmw/localhost.h | 38 ++++++++++++++++++++++++++++++ rmw/include/rmw/security_options.h | 4 ++-- rmw/include/rmw/types.h | 2 +- rmw/src/init_options.c | 2 +- 6 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 rmw/include/rmw/domain_id.h create mode 100644 rmw/include/rmw/localhost.h diff --git a/rmw/include/rmw/domain_id.h b/rmw/include/rmw/domain_id.h new file mode 100644 index 00000000..7a5a1c0d --- /dev/null +++ b/rmw/include/rmw/domain_id.h @@ -0,0 +1,21 @@ +// Copyright 2019 Open Source Robotics Foundation, Inc. +// +// Licensed 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. + +#ifndef RMW__DOMAIN_ID_H_ +#define RMW__DOMAIN_ID_H_ + +/// Default domain id. +#define RMW_DEFAULT_DOMAIN_ID SIZE_MAX + +#endif // RMW__DOMAIN_ID_H_ diff --git a/rmw/include/rmw/init_options.h b/rmw/include/rmw/init_options.h index e55009e1..56eb851c 100644 --- a/rmw/include/rmw/init_options.h +++ b/rmw/include/rmw/init_options.h @@ -23,6 +23,8 @@ extern "C" #include #include "rcutils/allocator.h" +#include "rmw/domain_id.h" +#include "rmw/localhost.h" #include "rmw/macros.h" #include "rmw/ret_types.h" #include "rmw/security_options.h" @@ -34,8 +36,6 @@ extern "C" */ typedef struct rmw_init_options_impl_t rmw_init_options_impl_t; -#define RMW_INIT_OPTIONS_DEFAULT_DOMAIN_ID SIZE_MAX - /// Options structure used during rmw_init(). typedef struct RMW_PUBLIC_TYPE rmw_init_options_t { @@ -52,6 +52,8 @@ typedef struct RMW_PUBLIC_TYPE rmw_init_options_t size_t domain_id; /// Security options rmw_security_options_t security_options; + /// Enable localhost only + rmw_localhost_only_t localhost_only; // TODO(wjwwood): replace with rmw_allocator_t when that refactor happens /// Allocator used during internal allocation of init options, if needed. diff --git a/rmw/include/rmw/localhost.h b/rmw/include/rmw/localhost.h new file mode 100644 index 00000000..868643fb --- /dev/null +++ b/rmw/include/rmw/localhost.h @@ -0,0 +1,38 @@ +// Copyright 2019 Open Source Robotics Foundation, Inc. +// +// Licensed 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. + +#ifndef RMW__LOCALHOST_H_ +#define RMW__LOCALHOST_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/// Used to specify if the context can only communicate through localhost. +typedef enum rmw_localhost_only_t +{ + /// Uses ROS_LOCALHOST_ONLY environment variable. + RMW_LOCALHOST_ONLY_DEFAULT = 0, + /// Forces using only localhost. + RMW_LOCALHOST_ONLY_ENABLED = 1, + /// Forces disabling localhost only. + RMW_LOCALHOST_ONLY_DISABLED = 2, +} rmw_localhost_only_t; + +#ifdef __cplusplus +} +#endif + +#endif // RMW__LOCALHOST_H_ diff --git a/rmw/include/rmw/security_options.h b/rmw/include/rmw/security_options.h index 4bf5d723..ba7b2842 100644 --- a/rmw/include/rmw/security_options.h +++ b/rmw/include/rmw/security_options.h @@ -22,11 +22,11 @@ extern "C" #include "rmw/visibility_control.h" -enum RMW_PUBLIC_TYPE rmw_security_enforcement_policy_t +typedef enum RMW_PUBLIC_TYPE rmw_security_enforcement_policy_t { RMW_SECURITY_ENFORCEMENT_PERMISSIVE, RMW_SECURITY_ENFORCEMENT_ENFORCE, -}; +} rmw_security_enforcement_policy_t; typedef struct RMW_PUBLIC_TYPE rmw_security_options_t { diff --git a/rmw/include/rmw/types.h b/rmw/include/rmw/types.h index e4c76e93..840b0cb7 100644 --- a/rmw/include/rmw/types.h +++ b/rmw/include/rmw/types.h @@ -37,7 +37,7 @@ extern "C" // 24 bytes is the most memory needed to represent the GID by any current // implementation. It may need to be increased in the future. -#define RMW_GID_STORAGE_SIZE 24 +#define RMW_GID_STORAGE_SIZE 24u typedef struct RMW_PUBLIC_TYPE rmw_node_t { diff --git a/rmw/src/init_options.c b/rmw/src/init_options.c index 54364d31..4104772a 100644 --- a/rmw/src/init_options.c +++ b/rmw/src/init_options.c @@ -28,7 +28,7 @@ rmw_get_zero_initialized_init_options(void) .instance_id = 0, .implementation_identifier = NULL, .impl = NULL, - .domain_id = RMW_INIT_OPTIONS_DEFAULT_DOMAIN_ID, + .domain_id = RMW_DEFAULT_DOMAIN_ID, .security_options = rmw_get_default_security_options(), }; // NOLINT(readability/braces): false positive } From cd1b326f33c6c0f437a9f46cfacc4870a1221868 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Wed, 18 Dec 2019 16:58:12 -0300 Subject: [PATCH 04/23] Correct rmw_get_zero_initialized_init_options Signed-off-by: Ivan Santiago Paunovic --- rmw/src/init_options.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rmw/src/init_options.c b/rmw/src/init_options.c index 4104772a..54ea8e8c 100644 --- a/rmw/src/init_options.c +++ b/rmw/src/init_options.c @@ -25,10 +25,11 @@ rmw_init_options_t rmw_get_zero_initialized_init_options(void) { return (const rmw_init_options_t) { + .domain_id = RMW_DEFAULT_DOMAIN_ID, + .localhost_only = false, .instance_id = 0, .implementation_identifier = NULL, .impl = NULL, - .domain_id = RMW_DEFAULT_DOMAIN_ID, .security_options = rmw_get_default_security_options(), }; // NOLINT(readability/braces): false positive } From ee0b354a7ada75bbe50507f4ad7ee093dce30c67 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Wed, 22 Jan 2020 13:42:42 -0300 Subject: [PATCH 05/23] Store init options in context Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/init.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rmw/include/rmw/init.h b/rmw/include/rmw/init.h index 95fa48a2..c6788d4f 100644 --- a/rmw/include/rmw/init.h +++ b/rmw/include/rmw/init.h @@ -40,6 +40,8 @@ typedef struct RMW_PUBLIC_TYPE rmw_context_t uint64_t instance_id; /// Implementation identifier, used to ensure two different implementations are not being mixed. const char * implementation_identifier; + /// Options used to initialize the context. + rmw_init_options_t options; /// Implementation defined context information. /** May be NULL if there is no implementation defined context information. */ rmw_context_impl_t * impl; From 52c5a4c1111c8a09e13305aa2288801b38d5293f Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Wed, 22 Jan 2020 13:48:40 -0300 Subject: [PATCH 06/23] Add rmw_security_options_fini and setter for secure_root Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/security_options.h | 30 ++++++++++++++++++++-- rmw/src/security_options.c | 40 +++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/rmw/include/rmw/security_options.h b/rmw/include/rmw/security_options.h index ba7b2842..8a094fbd 100644 --- a/rmw/include/rmw/security_options.h +++ b/rmw/include/rmw/security_options.h @@ -1,4 +1,4 @@ -// Copyright 2017-2019 Open Source Robotics Foundation, Inc. +// Copyright 2020 Open Source Robotics Foundation, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,6 +20,11 @@ extern "C" { #endif +#include + +#include "rcutils/allocator.h" + +#include "rmw/ret_types.h" #include "rmw/visibility_control.h" typedef enum RMW_PUBLIC_TYPE rmw_security_enforcement_policy_t @@ -31,17 +36,38 @@ typedef enum RMW_PUBLIC_TYPE rmw_security_enforcement_policy_t typedef struct RMW_PUBLIC_TYPE rmw_security_options_t { enum rmw_security_enforcement_policy_t enforce_security; - const char * security_root_path; + char * security_root_path; } rmw_security_options_t; +/// Get zero initialized security options. RMW_PUBLIC rmw_security_options_t rmw_get_zero_initialized_security_options(); +/// Get default initialized security options. RMW_PUBLIC rmw_security_options_t rmw_get_default_security_options(); +/// Copy the security_root_path in the security_options using the allocator. +/** + * \param security_root_path path to be copied. + * \param allocator allocator used to store the new string. + * \param security_options security options to be set. + */ +rmw_ret_t +rmw_security_options_set_root_path( + const char * security_root_path, + rcutils_allocator_t * allocator, + rmw_security_options_t * security_options); + +/// Finalize the given security_options. +RMW_PUBLIC +rmw_ret_t +rmw_security_options_fini( + rmw_security_options_t * security_options, + rcutils_allocator_t * allocator); + #ifdef __cplusplus } #endif diff --git a/rmw/src/security_options.c b/rmw/src/security_options.c index 0500de4c..c68f3e92 100644 --- a/rmw/src/security_options.c +++ b/rmw/src/security_options.c @@ -1,4 +1,4 @@ -// Copyright 2017-2019 Open Source Robotics Foundation, Inc. +// Copyright 2020 Open Source Robotics Foundation, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,20 +14,48 @@ #include +#include "rcutils/strdup.h" + #include "rmw/security_options.h" rmw_security_options_t rmw_get_zero_initialized_security_options() { - static rmw_security_options_t null_security_options = {0, NULL}; - return null_security_options; + rmw_security_options_t zero_initialized_options = {0, NULL}; + return zero_initialized_options; } rmw_security_options_t rmw_get_default_security_options() { - static rmw_security_options_t default_options; - default_options.enforce_security = RMW_SECURITY_ENFORCEMENT_PERMISSIVE; - default_options.security_root_path = NULL; + rmw_security_options_t default_options = { + RMW_SECURITY_ENFORCEMENT_PERMISSIVE, + NULL}; return default_options; } + +rmw_ret_t +rmw_security_options_set_root_path( + const char * security_root_path, + rcutils_allocator_t * allocator, + rmw_security_options_t * security_options) +{ + security_options->security_root_path = rcutils_strdup(security_root_path, *allocator); + if (!security_options->security_root_path) { + return RMW_RET_BAD_ALLOC; + } + return RMW_RET_OK; +} + +rmw_ret_t +rmw_security_options_fini( + rmw_security_options_t * security_options, + rcutils_allocator_t * allocator) +{ + if (!allocator) { + return RMW_RET_INVALID_ARGUMENT; + } + allocator->deallocate(security_options->security_root_path, allocator->state); + *security_options = rmw_get_zero_initialized_security_options(); + return RMW_RET_OK; +} From a90c367c005f664e070825337388b378ac0b9a48 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Fri, 24 Jan 2020 10:47:00 -0300 Subject: [PATCH 07/23] Add context name and namespace Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/init_options.h | 4 +++ rmw/include/rmw/security.h | 40 ++++++++++++++++++++++++++++++ rmw/include/rmw/security_options.h | 10 ++++++++ rmw/src/init_options.c | 4 ++- rmw/src/security_options.c | 29 +++++++++++++++++++--- 5 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 rmw/include/rmw/security.h diff --git a/rmw/include/rmw/init_options.h b/rmw/include/rmw/init_options.h index 56eb851c..39527ecc 100644 --- a/rmw/include/rmw/init_options.h +++ b/rmw/include/rmw/init_options.h @@ -54,6 +54,10 @@ typedef struct RMW_PUBLIC_TYPE rmw_init_options_t rmw_security_options_t security_options; /// Enable localhost only rmw_localhost_only_t localhost_only; + /// Context name + char * name; + /// Context namespace_ + char * namespace_; // TODO(wjwwood): replace with rmw_allocator_t when that refactor happens /// Allocator used during internal allocation of init options, if needed. diff --git a/rmw/include/rmw/security.h b/rmw/include/rmw/security.h new file mode 100644 index 00000000..9aefa0a5 --- /dev/null +++ b/rmw/include/rmw/security.h @@ -0,0 +1,40 @@ +// Copyright 2020 Open Source Robotics Foundation, Inc. +// +// Licensed 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. + +#ifndef RMW__SECURITY_H_ +#define RMW__SECURITY_H_ + +#include + +#include "rmw/visibility_control.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/// Indicates if node or context name have to be used in security directory lookup. +/** + * \returns true if node name should be used, or + * \returns false if context name should be used. + */ +RMW_PUBLIC +bool +rmw_use_node_name_in_security_directory_lookup(); + +#ifdef __cplusplus +} +#endif + +#endif // RMW__SECURITY_H_ diff --git a/rmw/include/rmw/security_options.h b/rmw/include/rmw/security_options.h index 8a094fbd..279f6903 100644 --- a/rmw/include/rmw/security_options.h +++ b/rmw/include/rmw/security_options.h @@ -49,11 +49,21 @@ RMW_PUBLIC rmw_security_options_t rmw_get_default_security_options(); +/// Copy the given security options. +RMW_PUBLIC +rmw_ret_t +rmw_security_options_copy( + const rmw_security_options_t * src, + const rcutils_allocator_t * allocator, + rmw_security_options_t * dst); + /// Copy the security_root_path in the security_options using the allocator. /** * \param security_root_path path to be copied. * \param allocator allocator used to store the new string. * \param security_options security options to be set. + * \returns RMW_RET_BAD_ALLOC, or + * \returns RMW_RET_OK */ rmw_ret_t rmw_security_options_set_root_path( diff --git a/rmw/src/init_options.c b/rmw/src/init_options.c index 54ea8e8c..853abc16 100644 --- a/rmw/src/init_options.c +++ b/rmw/src/init_options.c @@ -27,9 +27,11 @@ rmw_get_zero_initialized_init_options(void) return (const rmw_init_options_t) { .domain_id = RMW_DEFAULT_DOMAIN_ID, .localhost_only = false, - .instance_id = 0, .implementation_identifier = NULL, .impl = NULL, + .instance_id = 0, + .name = NULL, + .namespace_ = NULL, .security_options = rmw_get_default_security_options(), }; // NOLINT(readability/braces): false positive } diff --git a/rmw/src/security_options.c b/rmw/src/security_options.c index c68f3e92..7f59cadd 100644 --- a/rmw/src/security_options.c +++ b/rmw/src/security_options.c @@ -16,6 +16,7 @@ #include "rcutils/strdup.h" +#include "rmw/error_handling.h" #include "rmw/security_options.h" rmw_security_options_t @@ -34,14 +35,37 @@ rmw_get_default_security_options() return default_options; } +rmw_ret_t +rmw_security_options_copy( + const rmw_security_options_t * src, + const rcutils_allocator_t * allocator, + rmw_security_options_t * dst) +{ + RMW_CHECK_ARGUMENT_FOR_NULL(src, RMW_RET_INVALID_ARGUMENT); + RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_ARGUMENT_FOR_NULL(dst, RMW_RET_INVALID_ARGUMENT); + *dst = *src; + + dst->security_root_path = rcutils_strdup(src->security_root_path, *allocator); + if (src->security_root_path && !dst->security_root_path) { + RMW_SET_ERROR_MSG("failed to copy security root path"); + return RMW_RET_BAD_ALLOC; + } + return RMW_RET_OK; +} + rmw_ret_t rmw_security_options_set_root_path( const char * security_root_path, rcutils_allocator_t * allocator, rmw_security_options_t * security_options) { + RMW_CHECK_ARGUMENT_FOR_NULL(security_root_path, RMW_RET_INVALID_ARGUMENT); + RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_ARGUMENT_FOR_NULL(security_options, RMW_RET_INVALID_ARGUMENT); security_options->security_root_path = rcutils_strdup(security_root_path, *allocator); if (!security_options->security_root_path) { + RMW_SET_ERROR_MSG("failed to copy security root path"); return RMW_RET_BAD_ALLOC; } return RMW_RET_OK; @@ -52,9 +76,8 @@ rmw_security_options_fini( rmw_security_options_t * security_options, rcutils_allocator_t * allocator) { - if (!allocator) { - return RMW_RET_INVALID_ARGUMENT; - } + RMW_CHECK_ARGUMENT_FOR_NULL(security_options, RMW_RET_INVALID_ARGUMENT); + RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); allocator->deallocate(security_options->security_root_path, allocator->state); *security_options = rmw_get_zero_initialized_security_options(); return RMW_RET_OK; From df2fee1f3c86299019c485ed6f25ee02eb09bab9 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Tue, 28 Jan 2020 12:54:44 -0300 Subject: [PATCH 08/23] Correct rebasing error Signed-off-by: Ivan Santiago Paunovic --- rmw/CMakeLists.txt | 2 +- rmw/src/security_options.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rmw/CMakeLists.txt b/rmw/CMakeLists.txt index f1b8e07b..766fe768 100644 --- a/rmw/CMakeLists.txt +++ b/rmw/CMakeLists.txt @@ -32,7 +32,7 @@ set(rmw_sources "src/init_options.c" "src/loaned_message_sequence.c" "src/names_and_types.c" - "src/node_security_options.c" + "src/security_options.c" "src/publisher_options.c" "src/sanity_checks.c" "src/security_options.c" diff --git a/rmw/src/security_options.c b/rmw/src/security_options.c index 7f59cadd..450a9ff0 100644 --- a/rmw/src/security_options.c +++ b/rmw/src/security_options.c @@ -31,7 +31,8 @@ rmw_get_default_security_options() { rmw_security_options_t default_options = { RMW_SECURITY_ENFORCEMENT_PERMISSIVE, - NULL}; + NULL, + }; return default_options; } From bcffc6e36b8bc69fa7f72dc517634e9617aa91f5 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Tue, 4 Feb 2020 16:17:12 -0300 Subject: [PATCH 09/23] Use const rcutils_allocator_t * Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/security_options.h | 4 ++-- rmw/src/security_options.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rmw/include/rmw/security_options.h b/rmw/include/rmw/security_options.h index 279f6903..3b8885d6 100644 --- a/rmw/include/rmw/security_options.h +++ b/rmw/include/rmw/security_options.h @@ -68,7 +68,7 @@ rmw_security_options_copy( rmw_ret_t rmw_security_options_set_root_path( const char * security_root_path, - rcutils_allocator_t * allocator, + const rcutils_allocator_t * allocator, rmw_security_options_t * security_options); /// Finalize the given security_options. @@ -76,7 +76,7 @@ RMW_PUBLIC rmw_ret_t rmw_security_options_fini( rmw_security_options_t * security_options, - rcutils_allocator_t * allocator); + const rcutils_allocator_t * allocator); #ifdef __cplusplus } diff --git a/rmw/src/security_options.c b/rmw/src/security_options.c index 450a9ff0..c8317240 100644 --- a/rmw/src/security_options.c +++ b/rmw/src/security_options.c @@ -58,7 +58,7 @@ rmw_security_options_copy( rmw_ret_t rmw_security_options_set_root_path( const char * security_root_path, - rcutils_allocator_t * allocator, + const rcutils_allocator_t * allocator, rmw_security_options_t * security_options) { RMW_CHECK_ARGUMENT_FOR_NULL(security_root_path, RMW_RET_INVALID_ARGUMENT); @@ -75,7 +75,7 @@ rmw_security_options_set_root_path( rmw_ret_t rmw_security_options_fini( rmw_security_options_t * security_options, - rcutils_allocator_t * allocator) + const rcutils_allocator_t * allocator) { RMW_CHECK_ARGUMENT_FOR_NULL(security_options, RMW_RET_INVALID_ARGUMENT); RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); From 9dbd91c0c9e248cbda3460caa1598f6badd832f0 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Tue, 4 Feb 2020 16:23:31 -0300 Subject: [PATCH 10/23] Delete duplicated source file from CMakeLists.txt Signed-off-by: Ivan Santiago Paunovic --- rmw/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/rmw/CMakeLists.txt b/rmw/CMakeLists.txt index 766fe768..aebb6a2a 100644 --- a/rmw/CMakeLists.txt +++ b/rmw/CMakeLists.txt @@ -32,7 +32,6 @@ set(rmw_sources "src/init_options.c" "src/loaned_message_sequence.c" "src/names_and_types.c" - "src/security_options.c" "src/publisher_options.c" "src/sanity_checks.c" "src/security_options.c" From ad17a5612cbe5dc2c23f018aff42b6bd1a16dcb8 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Tue, 4 Feb 2020 16:24:33 -0300 Subject: [PATCH 11/23] Improve documentation in security_options.h Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/security_options.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/rmw/include/rmw/security_options.h b/rmw/include/rmw/security_options.h index 3b8885d6..dd3b38d6 100644 --- a/rmw/include/rmw/security_options.h +++ b/rmw/include/rmw/security_options.h @@ -50,6 +50,13 @@ rmw_security_options_t rmw_get_default_security_options(); /// Copy the given security options. +/** + * \param src security options to be copied. + * \param allocator allocator used when copying data to the new security options. + * \param dst security options to be set. + * \returns RMW_RET_BAD_ALLOC, or + * \returns RMW_RET_OK + */ RMW_PUBLIC rmw_ret_t rmw_security_options_copy( @@ -60,7 +67,7 @@ rmw_security_options_copy( /// Copy the security_root_path in the security_options using the allocator. /** * \param security_root_path path to be copied. - * \param allocator allocator used to store the new string. + * \param allocator allocator used to allocate the new path. * \param security_options security options to be set. * \returns RMW_RET_BAD_ALLOC, or * \returns RMW_RET_OK @@ -72,6 +79,12 @@ rmw_security_options_set_root_path( rmw_security_options_t * security_options); /// Finalize the given security_options. +/** + * \param security_options security options to be finalized. + * \param allocator allocator used to deallocate the root path. + * \returns RMW_RET_ERROR, or + * \returns RMW_RET_OK + */ RMW_PUBLIC rmw_ret_t rmw_security_options_fini( From 46bff30407e23bee394029f0f9d5b0fad5e882df Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Mon, 17 Feb 2020 17:02:50 -0300 Subject: [PATCH 12/23] Modify localhost_only default value Signed-off-by: Ivan Santiago Paunovic --- rmw/src/init_options.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rmw/src/init_options.c b/rmw/src/init_options.c index 853abc16..87f787db 100644 --- a/rmw/src/init_options.c +++ b/rmw/src/init_options.c @@ -15,6 +15,7 @@ #include #include "rmw/init_options.h" +#include "rmw/localhost.h" #ifdef __cplusplus extern "C" @@ -26,7 +27,7 @@ rmw_get_zero_initialized_init_options(void) { return (const rmw_init_options_t) { .domain_id = RMW_DEFAULT_DOMAIN_ID, - .localhost_only = false, + .localhost_only = RMW_LOCALHOST_ONLY_DEFAULT, .implementation_identifier = NULL, .impl = NULL, .instance_id = 0, From 9f10c0b972f98bd6599504cb5f1fd22b06b850bd Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Fri, 28 Feb 2020 15:10:59 -0300 Subject: [PATCH 13/23] Address peer review comments Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/security_options.h | 6 ++++-- rmw/src/security_options.c | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rmw/include/rmw/security_options.h b/rmw/include/rmw/security_options.h index dd3b38d6..3fb8b6d1 100644 --- a/rmw/include/rmw/security_options.h +++ b/rmw/include/rmw/security_options.h @@ -64,9 +64,11 @@ rmw_security_options_copy( const rcutils_allocator_t * allocator, rmw_security_options_t * dst); -/// Copy the security_root_path in the security_options using the allocator. +/// Set the security root path for the given security options. /** - * \param security_root_path path to be copied. + * The provided `security_root_path` will be copied into allocated memory. + * + * \param security_root_path path to be set. * \param allocator allocator used to allocate the new path. * \param security_options security options to be set. * \returns RMW_RET_BAD_ALLOC, or diff --git a/rmw/src/security_options.c b/rmw/src/security_options.c index c8317240..de910182 100644 --- a/rmw/src/security_options.c +++ b/rmw/src/security_options.c @@ -64,6 +64,9 @@ rmw_security_options_set_root_path( RMW_CHECK_ARGUMENT_FOR_NULL(security_root_path, RMW_RET_INVALID_ARGUMENT); RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); RMW_CHECK_ARGUMENT_FOR_NULL(security_options, RMW_RET_INVALID_ARGUMENT); + if (security_options->security_root_path) { + allocator->deallocate(security_options->security_root_path, allocator->state); + } security_options->security_root_path = rcutils_strdup(security_root_path, *allocator); if (!security_options->security_root_path) { RMW_SET_ERROR_MSG("failed to copy security root path"); From 73d4f1f258f1fe263136904cb55cf681c07fcdae Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Fri, 28 Feb 2020 15:13:51 -0300 Subject: [PATCH 14/23] Improve error handling in rmw_security_options_set_root_path Signed-off-by: Ivan Santiago Paunovic --- rmw/src/security_options.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rmw/src/security_options.c b/rmw/src/security_options.c index de910182..7e58328a 100644 --- a/rmw/src/security_options.c +++ b/rmw/src/security_options.c @@ -64,14 +64,14 @@ rmw_security_options_set_root_path( RMW_CHECK_ARGUMENT_FOR_NULL(security_root_path, RMW_RET_INVALID_ARGUMENT); RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); RMW_CHECK_ARGUMENT_FOR_NULL(security_options, RMW_RET_INVALID_ARGUMENT); - if (security_options->security_root_path) { - allocator->deallocate(security_options->security_root_path, allocator->state); - } + const char * old_security_root_path = security_options->security_root_path; security_options->security_root_path = rcutils_strdup(security_root_path, *allocator); if (!security_options->security_root_path) { + security_options->security_root_path = old_security_root_path; RMW_SET_ERROR_MSG("failed to copy security root path"); return RMW_RET_BAD_ALLOC; } + allocator->deallocate(old_security_root_path, allocator->state); return RMW_RET_OK; } From 4f74f6e8c50841ff82f6fafdc4b930892cd8b3f2 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Fri, 28 Feb 2020 15:14:51 -0300 Subject: [PATCH 15/23] Delete const qualifier Signed-off-by: Ivan Santiago Paunovic --- rmw/src/security_options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw/src/security_options.c b/rmw/src/security_options.c index 7e58328a..73a54b8a 100644 --- a/rmw/src/security_options.c +++ b/rmw/src/security_options.c @@ -64,7 +64,7 @@ rmw_security_options_set_root_path( RMW_CHECK_ARGUMENT_FOR_NULL(security_root_path, RMW_RET_INVALID_ARGUMENT); RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); RMW_CHECK_ARGUMENT_FOR_NULL(security_options, RMW_RET_INVALID_ARGUMENT); - const char * old_security_root_path = security_options->security_root_path; + char * old_security_root_path = security_options->security_root_path; security_options->security_root_path = rcutils_strdup(security_root_path, *allocator); if (!security_options->security_root_path) { security_options->security_root_path = old_security_root_path; From d6a9a463aa166f6c3a78249e619bbf947f028003 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Thu, 12 Mar 2020 11:34:44 -0300 Subject: [PATCH 16/23] Latest update after discussion about supporting sros2 Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/init_options.h | 2 -- rmw/include/rmw/rmw.h | 19 ++++++++++++++++++- rmw/src/init_options.c | 1 - rmw/src/security_options.c | 4 +++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/rmw/include/rmw/init_options.h b/rmw/include/rmw/init_options.h index 39527ecc..34d53246 100644 --- a/rmw/include/rmw/init_options.h +++ b/rmw/include/rmw/init_options.h @@ -56,8 +56,6 @@ typedef struct RMW_PUBLIC_TYPE rmw_init_options_t rmw_localhost_only_t localhost_only; /// Context name char * name; - /// Context namespace_ - char * namespace_; // TODO(wjwwood): replace with rmw_allocator_t when that refactor happens /// Allocator used during internal allocation of init options, if needed. diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index 36826f9c..36393ef3 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -173,7 +173,6 @@ rmw_create_node( const char * name, const char * namespace_, size_t domain_id, - const rmw_security_options_t * security_options, bool localhost_only); /// Finalize a given node handle, reclaim the resources, and deallocate the node handle. @@ -1044,6 +1043,24 @@ rmw_get_node_names( rcutils_string_array_t * node_names, rcutils_string_array_t * node_namespaces); +/// Return a list of node name and namespaces discovered via a node, with its context names. +/** + * \sa Similar to rmw_get_node_names, but it also provides the context names of each node. + * + * \param[in] node the handle to the node being used to query the ROS graph + * \param[out] node_names a list of discovered node names + * \param[out] node_namespaces a list of discovered node namespaces + * \param[out] context_names list with the context names of the nodes + * \return `RMW_RET_OK` if node the query was made successfully, or + * \return `RMW_RET_ERROR` if an unspecified error occurs. + */ +rmw_ret_t +rmw_get_node_names_with_context_names( + const rmw_node_t * node, + rcutils_string_array_t * node_names, + rcutils_string_array_t * node_namespaces, + rcutils_string_array_t * context_names); + RMW_PUBLIC RMW_WARN_UNUSED rmw_ret_t diff --git a/rmw/src/init_options.c b/rmw/src/init_options.c index 87f787db..427d9251 100644 --- a/rmw/src/init_options.c +++ b/rmw/src/init_options.c @@ -32,7 +32,6 @@ rmw_get_zero_initialized_init_options(void) .impl = NULL, .instance_id = 0, .name = NULL, - .namespace_ = NULL, .security_options = rmw_get_default_security_options(), }; // NOLINT(readability/braces): false positive } diff --git a/rmw/src/security_options.c b/rmw/src/security_options.c index 73a54b8a..1182eea4 100644 --- a/rmw/src/security_options.c +++ b/rmw/src/security_options.c @@ -45,8 +45,10 @@ rmw_security_options_copy( RMW_CHECK_ARGUMENT_FOR_NULL(src, RMW_RET_INVALID_ARGUMENT); RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); RMW_CHECK_ARGUMENT_FOR_NULL(dst, RMW_RET_INVALID_ARGUMENT); - *dst = *src; + allocator->deallocate(dst->security_root_path, allocator->state); + *dst = *src; + dst->security_root_path = NULL; dst->security_root_path = rcutils_strdup(src->security_root_path, *allocator); if (src->security_root_path && !dst->security_root_path) { RMW_SET_ERROR_MSG("failed to copy security root path"); From ea3648cebbb11311308abfc6ccd5787267f804bd Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Fri, 13 Mar 2020 15:09:48 -0300 Subject: [PATCH 17/23] Delete unused function Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/security.h | 40 -------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 rmw/include/rmw/security.h diff --git a/rmw/include/rmw/security.h b/rmw/include/rmw/security.h deleted file mode 100644 index 9aefa0a5..00000000 --- a/rmw/include/rmw/security.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2020 Open Source Robotics Foundation, Inc. -// -// Licensed 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. - -#ifndef RMW__SECURITY_H_ -#define RMW__SECURITY_H_ - -#include - -#include "rmw/visibility_control.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -/// Indicates if node or context name have to be used in security directory lookup. -/** - * \returns true if node name should be used, or - * \returns false if context name should be used. - */ -RMW_PUBLIC -bool -rmw_use_node_name_in_security_directory_lookup(); - -#ifdef __cplusplus -} -#endif - -#endif // RMW__SECURITY_H_ From 27dcc254e9a078dd7361e500f071159a0b32a3ce Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Tue, 17 Mar 2020 10:53:44 -0300 Subject: [PATCH 18/23] Naming: replace context_name with security_context Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/init_options.h | 4 ++-- rmw/include/rmw/rmw.h | 10 +++++----- rmw/src/init_options.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rmw/include/rmw/init_options.h b/rmw/include/rmw/init_options.h index 34d53246..06265357 100644 --- a/rmw/include/rmw/init_options.h +++ b/rmw/include/rmw/init_options.h @@ -54,8 +54,8 @@ typedef struct RMW_PUBLIC_TYPE rmw_init_options_t rmw_security_options_t security_options; /// Enable localhost only rmw_localhost_only_t localhost_only; - /// Context name - char * name; + /// Security context + char * security_context; // TODO(wjwwood): replace with rmw_allocator_t when that refactor happens /// Allocator used during internal allocation of init options, if needed. diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index 36393ef3..e0c94b7a 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -1043,23 +1043,23 @@ rmw_get_node_names( rcutils_string_array_t * node_names, rcutils_string_array_t * node_namespaces); -/// Return a list of node name and namespaces discovered via a node, with its context names. +/// Return a list of node name and namespaces discovered via a node with its security context. /** - * \sa Similar to rmw_get_node_names, but it also provides the context names of each node. + * \sa Similar to rmw_get_node_names, but it also provides the security context name. * * \param[in] node the handle to the node being used to query the ROS graph * \param[out] node_names a list of discovered node names * \param[out] node_namespaces a list of discovered node namespaces - * \param[out] context_names list with the context names of the nodes + * \param[out] security_contexts list of the security context of the nodes * \return `RMW_RET_OK` if node the query was made successfully, or * \return `RMW_RET_ERROR` if an unspecified error occurs. */ rmw_ret_t -rmw_get_node_names_with_context_names( +rmw_get_node_names_with_security_contexts( const rmw_node_t * node, rcutils_string_array_t * node_names, rcutils_string_array_t * node_namespaces, - rcutils_string_array_t * context_names); + rcutils_string_array_t * security_contexts); RMW_PUBLIC RMW_WARN_UNUSED diff --git a/rmw/src/init_options.c b/rmw/src/init_options.c index 427d9251..f8c2ab4a 100644 --- a/rmw/src/init_options.c +++ b/rmw/src/init_options.c @@ -31,7 +31,7 @@ rmw_get_zero_initialized_init_options(void) .implementation_identifier = NULL, .impl = NULL, .instance_id = 0, - .name = NULL, + .security_context = NULL, .security_options = rmw_get_default_security_options(), }; // NOLINT(readability/braces): false positive } From 54e0a68700763c49f14d6ee24ee2f690538d6c28 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Mon, 23 Mar 2020 15:58:05 -0300 Subject: [PATCH 19/23] Fix linkage problem Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/rmw.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index e0c94b7a..e983f35b 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -1054,6 +1054,8 @@ rmw_get_node_names( * \return `RMW_RET_OK` if node the query was made successfully, or * \return `RMW_RET_ERROR` if an unspecified error occurs. */ +RMW_PUBLIC +RMW_WARN_UNUSED rmw_ret_t rmw_get_node_names_with_security_contexts( const rmw_node_t * node, From 49613b2863068092033032ee3e5331c6ca343bb5 Mon Sep 17 00:00:00 2001 From: Ivan S Paunovic Date: Tue, 24 Mar 2020 13:46:46 +0000 Subject: [PATCH 20/23] Fix build problem on Windows Signed-off-by: Ivan S Paunovic --- rmw/include/rmw/localhost.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rmw/include/rmw/localhost.h b/rmw/include/rmw/localhost.h index 868643fb..187a6f32 100644 --- a/rmw/include/rmw/localhost.h +++ b/rmw/include/rmw/localhost.h @@ -15,13 +15,15 @@ #ifndef RMW__LOCALHOST_H_ #define RMW__LOCALHOST_H_ +#include "rmw/visibility_control.h" + #ifdef __cplusplus extern "C" { #endif /// Used to specify if the context can only communicate through localhost. -typedef enum rmw_localhost_only_t +typedef enum RMW_PUBLIC_TYPE rmw_localhost_only_t { /// Uses ROS_LOCALHOST_ONLY environment variable. RMW_LOCALHOST_ONLY_DEFAULT = 0, From 3a2b9ef986f27343b912956a86b62a555c007fb9 Mon Sep 17 00:00:00 2001 From: Ivan S Paunovic Date: Tue, 24 Mar 2020 14:34:48 +0000 Subject: [PATCH 21/23] More windows build errors Signed-off-by: Ivan S Paunovic --- rmw/include/rmw/types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw/include/rmw/types.h b/rmw/include/rmw/types.h index 840b0cb7..8948cbb8 100644 --- a/rmw/include/rmw/types.h +++ b/rmw/include/rmw/types.h @@ -48,7 +48,7 @@ typedef struct RMW_PUBLIC_TYPE rmw_node_t rmw_context_t * context; } rmw_node_t; -typedef enum RMW_PUBLIC_TYPE +typedef enum RMW_PUBLIC_TYPE rmw_endpoint_type_t { RMW_ENDPOINT_INVALID = 0, RMW_ENDPOINT_PUBLISHER, From 474732022d4719b6ffefd59619f1231a07bcdd49 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Thu, 26 Mar 2020 11:51:04 -0300 Subject: [PATCH 22/23] Address peer review comments Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/rmw.h | 2 +- rmw/src/security_options.c | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index e983f35b..979c070c 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -1050,7 +1050,7 @@ rmw_get_node_names( * \param[in] node the handle to the node being used to query the ROS graph * \param[out] node_names a list of discovered node names * \param[out] node_namespaces a list of discovered node namespaces - * \param[out] security_contexts list of the security context of the nodes + * \param[out] security_contexts list of discovered nodes' security context names * \return `RMW_RET_OK` if node the query was made successfully, or * \return `RMW_RET_ERROR` if an unspecified error occurs. */ diff --git a/rmw/src/security_options.c b/rmw/src/security_options.c index 1182eea4..ff69620a 100644 --- a/rmw/src/security_options.c +++ b/rmw/src/security_options.c @@ -46,14 +46,14 @@ rmw_security_options_copy( RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); RMW_CHECK_ARGUMENT_FOR_NULL(dst, RMW_RET_INVALID_ARGUMENT); - allocator->deallocate(dst->security_root_path, allocator->state); - *dst = *src; - dst->security_root_path = NULL; - dst->security_root_path = rcutils_strdup(src->security_root_path, *allocator); - if (src->security_root_path && !dst->security_root_path) { + char * new_root_path = rcutils_strdup(src->security_root_path, *allocator); + if (src->security_root_path && !new_root_path) { RMW_SET_ERROR_MSG("failed to copy security root path"); return RMW_RET_BAD_ALLOC; } + allocator->deallocate(dst->security_root_path, allocator->state); + dst->security_root_path = new_root_path; + dst->enforce_security = src->enforce_security; return RMW_RET_OK; } @@ -66,14 +66,13 @@ rmw_security_options_set_root_path( RMW_CHECK_ARGUMENT_FOR_NULL(security_root_path, RMW_RET_INVALID_ARGUMENT); RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); RMW_CHECK_ARGUMENT_FOR_NULL(security_options, RMW_RET_INVALID_ARGUMENT); - char * old_security_root_path = security_options->security_root_path; - security_options->security_root_path = rcutils_strdup(security_root_path, *allocator); - if (!security_options->security_root_path) { - security_options->security_root_path = old_security_root_path; + char * new_root_path = rcutils_strdup(security_root_path, *allocator); + if (!new_root_path) { RMW_SET_ERROR_MSG("failed to copy security root path"); return RMW_RET_BAD_ALLOC; } - allocator->deallocate(old_security_root_path, allocator->state); + allocator->deallocate(security_options->security_root_path, allocator->state); + security_options->security_root_path = new_root_path; return RMW_RET_OK; } From cbb5fc008f4304a62cf070663e3174c9f7970f9f Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Mon, 30 Mar 2020 09:18:09 -0300 Subject: [PATCH 23/23] Address peer review comment Signed-off-by: Ivan Santiago Paunovic --- rmw/include/rmw/rmw.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index 979c070c..f29e6e1a 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -1045,7 +1045,7 @@ rmw_get_node_names( /// Return a list of node name and namespaces discovered via a node with its security context. /** - * \sa Similar to rmw_get_node_names, but it also provides the security context name. + * Similar to \ref rmw_get_node_names, but it also provides the security context name. * * \param[in] node the handle to the node being used to query the ROS graph * \param[out] node_names a list of discovered node names