server_access_control.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  3. #include <ua_server.h>
  4. #include <ua_config_default.h>
  5. #include <ua_plugin_access_control.h>
  6. #include <ua_log_stdout.h>
  7. #include <signal.h>
  8. static UA_Boolean
  9. allowAddNode(UA_Server *server, UA_AccessControl *ac,
  10. const UA_NodeId *sessionId, void *sessionContext,
  11. const UA_AddNodesItem *item) {
  12. printf("Called allowAddNode\n");
  13. return UA_TRUE;
  14. }
  15. static UA_Boolean
  16. allowAddReference(UA_Server *server, UA_AccessControl *ac,
  17. const UA_NodeId *sessionId, void *sessionContext,
  18. const UA_AddReferencesItem *item) {
  19. printf("Called allowAddReference\n");
  20. return UA_TRUE;
  21. }
  22. static UA_Boolean
  23. allowDeleteNode(UA_Server *server, UA_AccessControl *ac,
  24. const UA_NodeId *sessionId, void *sessionContext,
  25. const UA_DeleteNodesItem *item) {
  26. printf("Called allowDeleteNode\n");
  27. return UA_FALSE; // Do not allow deletion from client
  28. }
  29. static UA_Boolean
  30. allowDeleteReference(UA_Server *server, UA_AccessControl *ac,
  31. const UA_NodeId *sessionId, void *sessionContext,
  32. const UA_DeleteReferencesItem *item) {
  33. printf("Called allowDeleteReference\n");
  34. return UA_TRUE;
  35. }
  36. UA_Boolean running = true;
  37. static void stopHandler(int sign) {
  38. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  39. running = false;
  40. }
  41. int main(void) {
  42. signal(SIGINT, stopHandler);
  43. signal(SIGTERM, stopHandler);
  44. UA_ServerConfig *config = UA_ServerConfig_new_default();
  45. // Set accessControl functions for nodeManagement
  46. config->accessControl.allowAddNode = allowAddNode;
  47. config->accessControl.allowAddReference = allowAddReference;
  48. config->accessControl.allowDeleteNode = allowDeleteNode;
  49. config->accessControl.allowDeleteReference = allowDeleteReference;
  50. UA_Server *server = UA_Server_new(config);
  51. UA_StatusCode retval = UA_Server_run(server, &running);
  52. UA_Server_delete(server);
  53. UA_ServerConfig_delete(config);
  54. return (int)retval;
  55. }