server_access_control.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "open62541.h"
  4. #include <signal.h>
  5. static UA_Boolean
  6. allowAddNode(UA_Server *server, UA_AccessControl *ac,
  7. const UA_NodeId *sessionId, void *sessionContext,
  8. const UA_AddNodesItem *item) {
  9. printf("Called allowAddNode\n");
  10. return UA_TRUE;
  11. }
  12. static UA_Boolean
  13. allowAddReference(UA_Server *server, UA_AccessControl *ac,
  14. const UA_NodeId *sessionId, void *sessionContext,
  15. const UA_AddReferencesItem *item) {
  16. printf("Called allowAddReference\n");
  17. return UA_TRUE;
  18. }
  19. static UA_Boolean
  20. allowDeleteNode(UA_Server *server, UA_AccessControl *ac,
  21. const UA_NodeId *sessionId, void *sessionContext,
  22. const UA_DeleteNodesItem *item) {
  23. printf("Called allowDeleteNode\n");
  24. return UA_FALSE; // Do not allow deletion from client
  25. }
  26. static UA_Boolean
  27. allowDeleteReference(UA_Server *server, UA_AccessControl *ac,
  28. const UA_NodeId *sessionId, void *sessionContext,
  29. const UA_DeleteReferencesItem *item) {
  30. printf("Called allowDeleteReference\n");
  31. return UA_TRUE;
  32. }
  33. UA_Boolean running = true;
  34. static void stopHandler(int sign) {
  35. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  36. running = false;
  37. }
  38. int main(void) {
  39. signal(SIGINT, stopHandler);
  40. signal(SIGTERM, stopHandler);
  41. UA_ServerConfig *config = UA_ServerConfig_new_default();
  42. // Set accessControl functions for nodeManagement
  43. config->accessControl.allowAddNode = allowAddNode;
  44. config->accessControl.allowAddReference = allowAddReference;
  45. config->accessControl.allowDeleteNode = allowDeleteNode;
  46. config->accessControl.allowDeleteReference = allowDeleteReference;
  47. UA_Server *server = UA_Server_new(config);
  48. UA_StatusCode retval = UA_Server_run(server, &running);
  49. UA_Server_delete(server);
  50. UA_ServerConfig_delete(config);
  51. return (int)retval;
  52. }