Guest User

pam_motd FIFO patch

a guest
Jun 2nd, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. --- modules/pam_motd/pam_motd.c 2011-06-21 11:04:56.000000000 +0200
  2. +++ modules/pam_motd/pam_motd.c-patched 2012-06-02 22:09:34.000000000 +0200
  3. @@ -82,16 +82,43 @@
  4.  
  5. while ((fd = open(motd_path, O_RDONLY, 0)) >= 0) {
  6. struct stat st;
  7. + if(fstat(fd, &st) == -1) break;
  8.  
  9. - /* fill in message buffer with contents of motd */
  10. - if ((fstat(fd, &st) < 0) || !st.st_size || st.st_size > 0x10000)
  11. - break;
  12. + /* Fira Hack patch to make him read FIFOs aswell
  13. + * This is not safe and could use a bunch of additional checks */
  14. + if (S_ISFIFO(st.st_mode)) {
  15. +
  16. + int fifo_imotd = 0;
  17. + int fifo_motdcap = 100;
  18. + int fifo_readres = 0;
  19.  
  20. - if (!(mtmp = malloc(st.st_size+1)))
  21. - break;
  22. + /*mtmp = malloc(100);
  23. + strcpy(mtmp, "This is definetely a pipe!");
  24. + st.st_size = 20;*/
  25. +
  26. + mtmp = malloc(fifo_motdcap);
  27.  
  28. - if (pam_modutil_read(fd, mtmp, st.st_size) != st.st_size)
  29. - break;
  30. + /* While there is data left in the pipe, read
  31. + * by increments of 100 characters - realloc'ing when neccessary */
  32. + do {
  33. + mtmp = realloc(mtmp, (fifo_motdcap += 100));
  34. + fifo_readres = read(fd, &mtmp[fifo_imotd], 100);
  35. + fifo_imotd += fifo_readres;
  36. + } while (fifo_readres);
  37. +
  38. + st.st_size = fifo_imotd + 1;
  39. +
  40. + } else {
  41. + /* fill in message buffer with contents of motd */
  42. + if (!st.st_size || st.st_size > 0x10000)
  43. + break;
  44. +
  45. + if (!(mtmp = malloc(st.st_size+1)))
  46. + break;
  47. +
  48. + if (pam_modutil_read(fd, mtmp, st.st_size) != st.st_size)
  49. + break;
  50. + }
  51.  
  52. if (mtmp[st.st_size-1] == '\n')
  53. mtmp[st.st_size-1] = '\0';
Advertisement
Add Comment
Please, Sign In to add comment