Skip to content

Commit

Permalink
Add context name and namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno committed Jan 24, 2020
1 parent c0bd963 commit 8254c7f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
4 changes: 4 additions & 0 deletions rmw/include/rmw/init_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
40 changes: 40 additions & 0 deletions rmw/include/rmw/security.h
Original file line number Diff line number Diff line change
@@ -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 <stdbool.h>

#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_
10 changes: 10 additions & 0 deletions rmw/include/rmw/security_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion rmw/src/init_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
29 changes: 26 additions & 3 deletions rmw/src/security_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "rcutils/strdup.h"

#include "rmw/error_handling.h"
#include "rmw/security_options.h"

rmw_security_options_t
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 8254c7f

Please sign in to comment.