summaryrefslogtreecommitdiff
blob: 216336f3494176a84003457ad0d269e0b311a70b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Author: Robin H. Johnson <robbat2@gentoo.org>
Original-Date: 2006-08-09
Forward-Port-Date: 2007-12-06

This patch allows a CVS server to deny usage of specific commands, based on
input in the environment.

Just set the CVS_BLOCK_REQUESTS env var with all of the commands you want,
seperated by spaces. Eg:
CVS_BLOCK_REQUESTS="Gzip-stream gzip-file-contents"
would block ALL usage of compression.

Please see the array 'struct request requests[]' in src/server.c for a full
list of commands.

Please note that if you block any commands marked as RQ_ESSENTIAL, CVS clients
may fail! (This includes 'ci'!).

See the companion cvs-custom.c for a wrapper that can enforce the environment variable for pserver setups.

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>

diff -Nuar cvs-1.12.13.1.orig/src/server.c cvs-1.12.13.1/src/server.c
--- cvs-1.12.13.1.orig/src/server.c	2006-06-21 11:55:21.000000000 -0700
+++ cvs-1.12.13.1/src/server.c	2007-12-06 16:25:38.109309990 -0800
@@ -6244,6 +6244,49 @@
 /*
  * This server request is not ignored by the secondary.
  */
+
+/* Hack by Robin H. Johnson <robbat2@gentoo.org>.
+ * Allow the server ENV to specify what request types are to be ignored.
+ */
+
+static char blocked_requests[BUFSIZ] = " ";
+
+static void build_blocked_requests() {
+	char *tmp = getenv("CVS_BLOCK_REQUESTS");
+
+	if (tmp != NULL && strlen(tmp) > 0) {
+		// move to our custom buffer
+		strncat(blocked_requests, tmp, sizeof(blocked_requests)-strlen(blocked_requests));
+		//add a space on the end as well for searching
+		strncat(blocked_requests, " ", sizeof(blocked_requests)-strlen(blocked_requests));
+	}
+
+	// now blocked_requests contains the list of every request that we do not
+	// want to serve
+}
+
+// returns 0 if we should serve this request
+// use as if(checker(FOO)) continue;
+static int serve_valid_requests_checker(char *reqname) {
+	char needle[BUFSIZ] = " ";
+	char *tmp;
+
+	if(!blocked_requests || strlen(blocked_requests) < 2)
+		return 0;
+
+	// we want to look for ' 'reqname' '
+	snprintf(needle, sizeof(needle), " %s ", reqname);
+
+	// now do the search
+	tmp = strstr(blocked_requests, needle);
+
+	if (tmp != NULL)
+		return 1;
+
+	return 0;
+	
+}
+
 static void
 serve_valid_requests (char *arg)
 {
@@ -6262,11 +6305,15 @@
        )
 	return;
 
+    build_blocked_requests();
+
     buf_output0 (buf_to_net, "Valid-requests");
     for (rq = requests; rq->name != NULL; rq++)
     {
 	if (rq->func != NULL)
 	{
+		if(serve_valid_requests_checker(rq->name)) 
+			continue;
 	    buf_append_char (buf_to_net, ' ');
 	    buf_output0 (buf_to_net, rq->name);
 	}
@@ -6706,6 +6753,9 @@
 		     * "co".
 		     */
 		    continue;
+		// Ignore commands that we are supposed to ignore.
+		if(serve_valid_requests_checker(rq->name))
+			continue;
 
 		if (!(rq->flags & RQ_ROOTLESS)
 		    && current_parsed_root == NULL)