Browse Source

Use capsicum on FreeBSD

Causal Agent 1 month ago
parent
commit
715f2cdf2f
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
1 changed files with 22 additions and 3 deletions
  1. 22
    3
      play.c

+ 22
- 3
play.c View File

@@ -25,6 +25,10 @@
25 25
 #include <sysexits.h>
26 26
 #include <time.h>
27 27
 
28
+#ifdef __FreeBSD__
29
+#include <sys/capsicum.h>
30
+#endif
31
+
28 32
 typedef unsigned uint;
29 33
 
30 34
 uint play2048(void);
@@ -152,10 +156,25 @@ static void draw(size_t new) {
152 156
 }
153 157
 
154 158
 int main(void) {
155
-	struct Score new = { .date = time(NULL) };
156
-	new.score = play2048();
157
-
159
+	curse();
158 160
 	FILE *file = scoresOpen("2048.scores");
161
+
162
+#ifdef __FreeBSD__
163
+	int error = cap_enter();
164
+	if (error) err(EX_OSERR, "cap_enter");
165
+
166
+	cap_rights_t rights;
167
+	cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_SEEK, CAP_FLOCK);
168
+
169
+	error = cap_rights_limit(fileno(file), &rights);
170
+	if (error) err(EX_OSERR, "cap_rights_limit");
171
+#endif
172
+
173
+	struct Score new = {
174
+		.date = time(NULL),
175
+		.score = play2048(),
176
+	};
177
+
159 178
 	scoresRead(file);
160 179
 	size_t index = scoresInsert(new);
161 180
 

Loading…
Cancel
Save