You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.3KB

  1. #define _GNU_SOURCE
  2. #include <stdio.h>
  3. #include <linux/limits.h>
  4. #include "pamela.h"
  5. #include <syslog.h>
  6. PAM_EXTERN
  7. int pam_sm_open_session(pam_handle_t *pamh, int flags,
  8. int argc, const char **argv) {
  9. char const *user;
  10. int pam_error;
  11. // get user name
  12. if ((pam_error = pam_get_user(pamh, &user, NULL)) != PAM_SUCCESS) {
  13. fprintf(stderr, "%sn", pam_strerror(pamh, pam_error));
  14. syslog(LOG_USER | LOG_ERR, "Error pam_get_user()\n");
  15. return pam_error;
  16. }
  17. // open / create volume
  18. char *cmd_open;
  19. if (!asprintf(&cmd_open, "su -l root -c \"pamela_manager open %s\"", user, user)) {
  20. syslog(LOG_USER | LOG_ERR, "Error asprintf()\n");
  21. // log error
  22. return PAM_ABORT;
  23. }
  24. if (system(cmd_open) != 0) {
  25. free(cmd_open);
  26. syslog(LOG_USER | LOG_ERR, "Error during the pamela_manager script\n");
  27. return PAM_ABORT;
  28. }
  29. free(cmd_open);
  30. return PAM_SUCCESS;
  31. }
  32. PAM_EXTERN
  33. int pam_sm_close_session(pam_handle_t *pamh, int flags,
  34. int argc, const char *argv[]) {
  35. syslog(LOG_USER | LOG_ERR, "close()\n");
  36. char const *user;
  37. int pam_error;
  38. // get user name
  39. if ((pam_error = pam_get_user(pamh, &user, NULL)) != PAM_SUCCESS) {
  40. fprintf(stderr, "%sn", pam_strerror(pamh, pam_error));
  41. syslog(LOG_USER | LOG_ERR, "Error pam_get_user()\n");
  42. return pam_error;
  43. }
  44. // open / create volume
  45. char *cmd_open;
  46. if (!asprintf(&cmd_open, "su -l root -c \"pamela_manager close %s\"", user, user)) {
  47. // log error
  48. return PAM_ABORT;
  49. }
  50. if (system(cmd_open) != 0) {
  51. free(cmd_open);
  52. syslog(LOG_USER | LOG_ERR, "Error during the pamela_manager script\n");
  53. return PAM_ABORT;
  54. }
  55. free(cmd_open);
  56. return PAM_SUCCESS;
  57. }
  58. /*
  59. PAM_EXTERN
  60. int pam_sm_authenticate(pam_handle_t *pamh, int flags,
  61. int argc, const char *argv[])
  62. {
  63. syslog(LOG_USER | LOG_ERR, "authenticate()\n");
  64. (void)pamh;
  65. (void)flags;
  66. (void)argc;
  67. (void)argv;
  68. return (PAM_SUCCESS);
  69. }
  70. PAM_EXTERN
  71. int pam_sm_setcred(pam_handle_t *pamh, int flags,
  72. int argc, const char *argv[])
  73. {
  74. syslog(LOG_USER | LOG_ERR, "setcred()\n");
  75. (void)pamh;
  76. (void)flags;
  77. (void)argc;
  78. (void)argv;
  79. return (PAM_SUCCESS);
  80. }
  81. PAM_EXTERN
  82. int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
  83. int argc, const char *argv[])
  84. {
  85. syslog(LOG_USER | LOG_ERR, "acct_mgmt()\n");
  86. (void)pamh;
  87. (void)flags;
  88. (void)argc;
  89. (void)argv;
  90. return (PAM_SUCCESS);
  91. }
  92. */