View difference between Paste ID: bMpbLskH and V42rqXDz
SHOW: | | - or go back to the newest paste.
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);
22+
23-
+		strcpy(mtmp, "This is definetely a pipe!");
23+
24-
+		st.st_size = 20;*/
24+
25
-	if (pam_modutil_read(fd, mtmp, st.st_size) != st.st_size)
26
-	    break;
27
+		/* While there is data left in the pipe, read
28
+		 * by increments of 100 characters - realloc'ing when neccessary */
29
+		do {
30
+			mtmp = realloc(mtmp, (fifo_motdcap += 100));
31
+			fifo_readres = read(fd, &mtmp[fifo_imotd], 100);
32
+			fifo_imotd += fifo_readres;
33
+		} while (fifo_readres);
34
+
35
+		st.st_size = fifo_imotd + 1;
36
+
37
+	} else {
38
+		/* fill in message buffer with contents of motd */
39
+		if (!st.st_size || st.st_size > 0x10000)
40
+		    break;
41
+
42
+		if (!(mtmp = malloc(st.st_size+1)))
43
+		    break;
44
+
45
+		if (pam_modutil_read(fd, mtmp, st.st_size) != st.st_size)
46
+		    break;
47
+	}
48
 
49
 	if (mtmp[st.st_size-1] == '\n')
50
 	    mtmp[st.st_size-1] = '\0';