Guest User

pam_kwalletd.c patch

a guest
Feb 19th, 2020
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.39 KB | None | 0 0
  1. --- pam_kwallet_old.c   2020-02-19 23:03:03.952797869 +0100
  2. +++ pam_kwallet.c   2020-02-19 22:47:03.689180218 +0100
  3. @@ -360,6 +360,7 @@
  4.  
  5.  static void execute_kwallet(pam_handle_t *pamh, struct passwd *userInfo, int toWalletPipe[2], char *fullSocket)
  6.  {
  7. +    syslog(LOG_DEBUG, "%s: Function execute_kwallet...\n", logPrefix);
  8.      //In the child pam_syslog does not work, using syslog directly
  9.      //keep stderr open so socket doesn't returns us that fd
  10.      int x = 3;
  11. @@ -375,47 +376,26 @@
  12.  
  13.      //Change to the user in case we are not it yet
  14.      if (drop_privileges(userInfo) < 0) {
  15. -        syslog(LOG_ERR, "%s: could not set gid/uid/euid/egit for kwalletd", logPrefix);
  16. +        syslog(LOG_ERR, "%s: could not set gid/uid/euid/egit for kwalletd\n", logPrefix);
  17.          free(fullSocket);
  18.          goto cleanup;
  19.      }
  20. -
  21. -    int envSocket;
  22. -    if ((envSocket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
  23. -        syslog(LOG_ERR, "%s: couldn't create socket", logPrefix);
  24. -        free(fullSocket);
  25. +    //Create a named pipe
  26. +    syslog(LOG_DEBUG, "%s: Creating named pipe...\n", logPrefix);
  27. +    if(access(fullSocket, F_OK) != -1 && remove(fullSocket) == -1) {
  28. +        syslog(LOG_DEBUG, "%s: couldn't remove previous file: %s\n", logPrefix, fullSocket);
  29.          goto cleanup;
  30.      }
  31. -
  32. -    struct sockaddr_un local;
  33. -    local.sun_family = AF_UNIX;
  34. -
  35. -    if (strlen(fullSocket) > sizeof(local.sun_path)) {
  36. -        syslog(LOG_ERR, "%s: socket path %s too long to open",
  37. -                   logPrefix, fullSocket);
  38. -        free(fullSocket);
  39. -        goto cleanup;
  40. -    }
  41. -    strcpy(local.sun_path, fullSocket);
  42. -    free(fullSocket);
  43. -    fullSocket = NULL;
  44. -    unlink(local.sun_path);//Just in case it exists from a previous login
  45. -
  46. -    syslog(LOG_DEBUG, "%s: final socket path: %s", logPrefix, local.sun_path);
  47. -
  48. -    size_t len = strlen(local.sun_path) + sizeof(local.sun_family);
  49. -    if (bind(envSocket, (struct sockaddr *)&local, len) == -1) {
  50. -        syslog(LOG_INFO, "%s-kwalletd: Couldn't bind to local file\n", logPrefix);
  51. +    if(mkfifo(fullSocket, 0755) == -1) {
  52. +        syslog(LOG_DEBUG, "%s: couldn't create named pipe: %s\n", logPrefix, fullSocket);
  53.          goto cleanup;
  54.      }
  55.  
  56. -    if (listen(envSocket, 5) == -1) {
  57. -        syslog(LOG_INFO, "%s-kwalletd: Couldn't listen in socket\n", logPrefix);
  58. -        goto cleanup;
  59. -    }
  60. +    syslog(LOG_DEBUG, "%s: final named pipe path: %s\n", logPrefix, fullSocket);
  61. +
  62.      //finally close stderr
  63.      close(2);
  64. -
  65. +    
  66.      // Fork twice to daemonize kwallet
  67.      setsid();
  68.      pid_t pid = fork();
  69. @@ -430,12 +410,12 @@
  70.      //TODO use a pam argument for full path kwalletd
  71.      char pipeInt[4];
  72.      sprintf(pipeInt, "%d", toWalletPipe[0]);
  73. -    char sockIn[4];
  74. -    sprintf(sockIn, "%d", envSocket);
  75.  
  76. -    char *args[] = {strdup(kwalletd), "--pam-login", pipeInt, sockIn, NULL, NULL};
  77. +    syslog(LOG_DEBUG, "%s: hash pipe: %d; env pipe path: %s\n", logPrefix, toWalletPipe[0], fullSocket);
  78. +    syslog(LOG_DEBUG, "%s: Starting kwalletd...\n", logPrefix);
  79. +    char *args[] = {strdup(kwalletd), "--pam-login", pipeInt, fullSocket, NULL, NULL};
  80.      execve(args[0], args, pam_getenvlist(pamh));
  81. -    syslog(LOG_ERR, "%s: could not execute kwalletd from %s", logPrefix, kwalletd);
  82. +    syslog(LOG_ERR, "%s: could not execute kwalletd from %s\n", logPrefix, kwalletd);
  83.  
  84.  cleanup:
  85.      exit(EXIT_FAILURE);
Advertisement
Add Comment
Please, Sign In to add comment