shellmatta_auth.dox 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. The 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. By enabling the user to be superuser you grant this user access to all
  25. commands without the need of setting a permission list.
  26. shellmatta_auth_user_t userList[] = {
  27. {1, true, "root", "rootpw"},
  28. {2, false, "shimatta", "12345678"},
  29. {3, false, "not_shimatta", "87654321"}
  30. };
  31. Every command can get a permission matrix - the perm lists can be reused for
  32. multiple users with the same permissions.
  33. When no entry is found for a command in the permission list the command
  34. defaults to be public.
  35. It is also possible to use the userID 0 to hide a command when logged in.
  36. uint32_t exampleCmdPerms[] = {2};
  37. shellmatta_auth_perm_t permList[] = {
  38. {"exampleCmd", exampleCmdPerms, sizeof(exampleCmdPerms)/sizeof(exampleCmdPerms[0])}
  39. };
  40. Now call the #shellmatta_auth_init method and pass the user and permissions
  41. lists.
  42. It is possible to register optional callbacks for a custom password check
  43. and a log function which is called on every authentication event.
  44. shellmatta_auth_init(handle, userList, 3, permList, 1, false, NULL, NULL);
  45. @section shellmatta_auth_custom_login Custom login
  46. By default the shellmatta uses plain text passwords.
  47. This of course is not state of the art and usually highly insecure.
  48. As most of the fancy password hashing methods are platform dependant none of
  49. those is included to keep up the compatibility with as many platforms as
  50. possible (sacrificing security).
  51. To overcome this limitation you can register your own function to check the
  52. credentials.
  53. Just implement a function of type #shellmatta_auth_check_t and pass it to
  54. the #shellmatta_auth_init method during initialization.
  55. shellmatta_retCode_t custom_auth_check(const uint32_t userId, const char* password) {
  56. /‌/ Check if the passed userID matches the passed password.
  57. if (password_matches()) {
  58. return SHELLMATTA_OK;
  59. }
  60. return SHELLMATTA_ERROR;
  61. }
  62. */