From 74f18c6264618187386a5dc8b1152faa8727bf53 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Wed, 18 Feb 2026 22:45:06 +0100 Subject: Extract configureAccessControl() into common The access-control switch block was duplicated in server_lds.c and server_register.c. Move it to a shared helper in common.c with a Doxygen block that consolidates the rationale from both call sites. --- src/common.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c index cf364bb..9401392 100644 --- a/src/common.c +++ b/src/common.c @@ -6,6 +6,7 @@ #include "common.h" #include +#include #include #include @@ -304,6 +305,30 @@ resolveSecurityPolicyUri (const char *shortName) return NULL; } +/* ======================================================================== + * Access Control + * ======================================================================== */ + +UA_StatusCode +configureAccessControl (UA_ServerConfig *config, const AuthConfig *auth) +{ + switch (auth->mode) + { + case AUTH_ANONYMOUS: + return UA_AccessControl_default (config, true, NULL, 0, NULL); + case AUTH_USER: + { + UA_UsernamePasswordLogin logins[1]; + logins[0].username = UA_STRING ((char *)auth->user.username); + logins[0].password = UA_STRING ((char *)auth->user.password); + return UA_AccessControl_default (config, false, NULL, 1, logins); + } + case AUTH_CERT: + return UA_AccessControl_default (config, false, NULL, 0, NULL); + } + return UA_STATUSCODE_BADINTERNALERROR; +} + /* ======================================================================== * Output Formatting * ======================================================================== */ -- cgit v1.2.3