shellmatta_auth.dox 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. @page shellmatta_auth Shellmatta Authentication
  3. The shellmatta comes with a simple authentication mechanism.
  4. It can be used to hide certain (or all) commands from users without
  5. permission.
  6. Ther permissions can be set per command.
  7. To enable the shellmatta auth module you have to include the file
  8. shellmatta_auth.c into your build and set the define
  9. ``SHELLMATTA_AUTHENTICATION``.
  10. Unfortunately the structure of each command has to be altered to include
  11. the additional information required by the auth module.
  12. Please add another NULL to the initializers of every command of type
  13. #shellmatta_cmd_t.
  14. shellmatta_cmd_t exampleCmd = { "example",
  15. "e",
  16. "example command",
  17. "example [options]\n"
  18. "\t-v, --version - print the version of the command",
  19. exampleCmdFct,
  20. NULL,
  21. NULL};
  22. After initializing the shellmatta instance you have to setup users with
  23. username and password:
  24. shellmatta_auth_user_t userList[] = {
  25. {1, "shimatta", "12345678"},
  26. {2, "not_shimatta", "87654321"}
  27. };
  28. Every command can get a permission matrix - the perm lists can be reused for
  29. multiple users with the same permissions.
  30. uint32_t exampleCmdPerms[] = {1};
  31. shellmatta_auth_perm_t permList[] = {
  32. {"adoSome2", exampleCmdPerms, sizeof(exampleCmdPerms)/sizeof(exampleCmdPerms[0])}
  33. };
  34. Now call the #shellmatta_auth_init method and pass the user and permissions
  35. lists.
  36. It is possible to register optional callbacks for a custom password check
  37. and a log function which is called on every authentication event.
  38. shellmatta_auth_init(handle, userList, 2, permList, 2, false, NULL, NULL);
  39. @section shellmatta_auth_custom_login Custom login
  40. By default the shellmatta uses plain text passwords.
  41. This of course is not state of the art and usually highly insecure.
  42. As most of the fancy password hashing systems are platform dependant none of
  43. those is included to keep up the compatibility with as many platforms as
  44. possible (sacrificing security).
  45. To overcome this limitation you can register your own function to check the
  46. credentials.
  47. Just implement a function of type #shellmatta_auth_check_t and pass it to
  48. the #shellmatta_auth_init method during initialization.
  49. shellmatta_retCode_t custom_auth_check(const uint32_t userId, const char* password) {
  50. /‌/ Check if the passed userID matches the passed password.
  51. if (password_matches()) {
  52. return userId;
  53. }
  54. return 0;
  55. }
  56. */