diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-18 22:45:06 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-18 22:45:06 +0100 |
| commit | 74f18c6264618187386a5dc8b1152faa8727bf53 (patch) | |
| tree | f3e233f6d79f6f0b8a9758aefb91ff3731793dee /src/common.c | |
| parent | 5f5e172cd2392952162398c85b07e6f6b7e69398 (diff) | |
| download | BobinkCOpcUa-74f18c6264618187386a5dc8b1152faa8727bf53.tar.gz BobinkCOpcUa-74f18c6264618187386a5dc8b1152faa8727bf53.zip | |
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.
Diffstat (limited to 'src/common.c')
| -rw-r--r-- | src/common.c | 25 |
1 files changed, 25 insertions, 0 deletions
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 <open62541/client_config_default.h> +#include <open62541/plugin/accesscontrol_default.h> #include <open62541/plugin/log_stdout.h> #include <open62541/server_config_default.h> @@ -305,6 +306,30 @@ resolveSecurityPolicyUri (const char *shortName) } /* ======================================================================== + * 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 * ======================================================================== */ |
