summaryrefslogtreecommitdiffstats
path: root/mpss-daemon.patch
blob: 09bfbfe8ff4c7ca03b7cb17fd4949da9b47eda81 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
diff -ur mpss-daemon-3.8.6.orig/libmpssconfig/genfs.c mpss-daemon-3.8.6/libmpssconfig/genfs.c
--- mpss-daemon-3.8.6.orig/libmpssconfig/genfs.c	2021-01-21 01:46:48.337522089 +0100
+++ mpss-daemon-3.8.6/libmpssconfig/genfs.c	2021-01-21 04:05:30.895228099 +0100
@@ -481,6 +481,8 @@
 	struct dirent *file;
 	DIR *dp;
 
+    printf("handle_common %s\n", dir);
+
 	switch (type) {
 	case SRCTYPE_DIR:
 		mpssut_filename(menv, NULL, comname, PATH_MAX, "%s", dir);
@@ -1682,10 +1684,10 @@
 
 	pid = fork();
 	if (pid == 0) {
-		ifargv[0] = "/bin/gzip";
+		ifargv[0] = "/run/current-system/sw/bin/gzip";
 		ifargv[1] = name;
 		ifargv[2] = NULL;
-		execve("/bin/gzip", ifargv, NULL);
+		execve("/run/current-system/sw/bin/gzip", ifargv, NULL);
 	}
 
 	waitpid(pid, &status, 0);
@@ -1699,11 +1701,11 @@
 
 	pid = fork();
 	if (pid == 0) {
-		ifargv[0] = "/bin/gzip";
+		ifargv[0] = "/run/current-system/sw/bin/gzip";
 		ifargv[1] = "-d";
 		ifargv[2] = name;
 		ifargv[3] = NULL;
-		execve("/bin/gzip", ifargv, NULL);
+		execve("/run/current-system/sw/bin/gzip", ifargv, NULL);
 	}
 
 	waitpid(pid, NULL, 0);
@@ -1724,7 +1726,7 @@
 
 		fclose(stdout);
 		fclose(stderr);
-		ifargv[0] = "/bin/cpio";
+		ifargv[0] = "/run/current-system/sw/bin/cpio";
 		ifargv[1] = "-i";
 		ifargv[2] = "-F";
 		ifargv[3] = cfile;
@@ -1734,7 +1736,7 @@
 		} else {
 			ifargv[4] = NULL;
 		}
-		execve("/bin/cpio", ifargv, NULL);
+		execve("/run/current-system/sw/bin/cpio", ifargv, NULL);
 	}
 
 	if (waitpid(pid, &status, 0) < 0)
diff -ur mpss-daemon-3.8.6.orig/libmpssconfig/micenv.c mpss-daemon-3.8.6/libmpssconfig/micenv.c
--- mpss-daemon-3.8.6.orig/libmpssconfig/micenv.c	2021-01-21 01:46:48.338522081 +0100
+++ mpss-daemon-3.8.6/libmpssconfig/micenv.c	2021-01-21 02:27:02.788081574 +0100
@@ -106,6 +106,8 @@
 			menv->dist = DISTRIB_SUSE;
 		else if (!strcasecmp(dist, "ubuntu"))
 			menv->dist = DISTRIB_UBUNTU;
+		else if (!strcasecmp(dist, "nixos"))
+			menv->dist = DISTRIB_NIXOS;
 		else
 			return (SETENV_FUNC_DIST << 16) | SETENV_CMDLINE_DIST;
 	} else if ((dist = getenv("MPSS_DIST")) != NULL) {
@@ -117,6 +119,8 @@
 			menv->dist = DISTRIB_SUSE;
 		else if (!strcasecmp(dist, "ubuntu"))
 			menv->dist = DISTRIB_UBUNTU;
+		else if (!strcasecmp(dist, "nixos"))
+			menv->dist = DISTRIB_NIXOS;
 		else
 			return (SETENV_FUNC_DIST << 16) | SETENV_ENV_DIST;
 	} else {
@@ -126,12 +130,15 @@
 			menv->dist = DISTRIB_SUSE;
 		else if ((stat(UBUNTU_NETWORK_DIR, &sbuf) == 0) && S_ISDIR(sbuf.st_mode))
 			menv->dist = DISTRIB_UBUNTU;
+		else if ((stat(NIXOS_RUN_DIR, &sbuf) == 0) && S_ISDIR(sbuf.st_mode))
+			menv->dist = DISTRIB_NIXOS;
 		else
 			return (SETENV_FUNC_DIST << 16) | SETENV_PROBE_DIST;
 	}
 
 	switch(menv->dist) {
 	case DISTRIB_REDHAT:
+	case DISTRIB_NIXOS:
 	case DISTRIB_SUSE:
 		menv->lockfile = LSB_LOCK_FILENAME;
 		break;
diff -ur mpss-daemon-3.8.6.orig/libmpssconfig/mpssconfig.h mpss-daemon-3.8.6/libmpssconfig/mpssconfig.h
--- mpss-daemon-3.8.6.orig/libmpssconfig/mpssconfig.h	2021-01-21 01:46:48.338522081 +0100
+++ mpss-daemon-3.8.6/libmpssconfig/mpssconfig.h	2021-01-21 02:10:37.013513734 +0100
@@ -218,6 +218,7 @@
 #define REDHAT_NETWORK_DIR "/etc/sysconfig/network-scripts"
 #define SUSE_NETWORK_DIR "/etc/sysconfig/network"
 #define UBUNTU_NETWORK_DIR "/etc/network"
+#define NIXOS_RUN_DIR "/var/run/nixos"
 
 /**
  * Mic family
@@ -239,6 +240,7 @@
 #define DISTRIB_REDHAT	1
 #define DISTRIB_SUSE	2
 #define DISTRIB_UBUNTU	3
+#define DISTRIB_NIXOS   4
 	char	*home;
 	char	*confdir;
 	char	*destdir;
diff -ur mpss-daemon-3.8.6.orig/libmpssconfig/verify_bzimage.c mpss-daemon-3.8.6/libmpssconfig/verify_bzimage.c
--- mpss-daemon-3.8.6.orig/libmpssconfig/verify_bzimage.c	2021-01-21 01:46:48.338522081 +0100
+++ mpss-daemon-3.8.6/libmpssconfig/verify_bzimage.c	2021-01-21 03:00:35.816162608 +0100
@@ -173,17 +173,18 @@
 do_gunzip(char *name)
 {
 	pid_t pid;
-	char *ifargv[4];
+	char *ifargv[5];
 
 	pid = fork();
 	if (pid == 0) {
 		fclose(stdout);
 		fclose(stderr);
-		ifargv[0] = "/bin/gzip";
-		ifargv[1] = "-d";
-		ifargv[2] = name;
-		ifargv[3] = NULL;
-		execve("/bin/gzip", ifargv, NULL);
+		ifargv[0] = "/usr/bin/env";
+        ifargv[1] = "gzip";
+		ifargv[2] = "-d";
+		ifargv[3] = name;
+		ifargv[4] = NULL;
+		execve("/usr/bin/env", ifargv, NULL);
 	}
 
 	waitpid(pid, NULL, 0);
diff -ur mpss-daemon-3.8.6.orig/micctrl/init.c mpss-daemon-3.8.6/micctrl/init.c
--- mpss-daemon-3.8.6.orig/micctrl/init.c	2021-01-21 01:46:48.338522081 +0100
+++ mpss-daemon-3.8.6/micctrl/init.c	2021-01-21 01:52:24.195846483 +0100
@@ -1016,7 +1016,7 @@
 		}
 
 		fprintf(fp, defconf, mpssenv.vardir, DEF_SHUTDOWN_TIMEOUT, DEF_CRASHDUMP_DIR, DEF_CRASHDUMP_LIMITGB);
-		fprintf(fp, kncextracmd);
+		fprintf(fp, "%s", kncextracmd);
 		fclose(fp);
 		display(PFS, "%s: Created %s\n", mic->name, filename);
 	} else {
diff -ur mpss-daemon-3.8.6.orig/micctrl/network.c mpss-daemon-3.8.6/micctrl/network.c
--- mpss-daemon-3.8.6.orig/micctrl/network.c	2021-01-21 01:46:48.338522081 +0100
+++ mpss-daemon-3.8.6/micctrl/network.c	2021-01-21 02:38:42.021016226 +0100
@@ -101,6 +101,13 @@
 void ubuntu_unattach_hostbridge(char *name, char *bridge);
 void ubuntu_remove_bridges(void);
 
+void nixos_net_remove(char *name, char *bridge, int modhost);
+void nixos_br_remove(struct mbridge *br);
+void nixos_attach_hostbridge(char *name, char *bridge, char *mac, char *mtu, int saveresolv);
+void nixos_host_addif(char *name, char *ip, char *netbits, char *mtu, char *mac);
+void nixos_unattach_hostbridge(char *name, char *bridge);
+void nixos_remove_bridges(void);
+
 struct netinfo {
 	char *netdir;
 	char *defnetdir;
@@ -141,7 +148,15 @@
 		ubuntu_br_remove,
 		ubuntu_attach_hostbridge,
 		ubuntu_host_addif,
-		ubuntu_remove_bridges}
+		ubuntu_remove_bridges},
+	  { "/tmp/notreally",
+		"/tmp/notreally",
+		"/tmp/yeahstillno",
+		nixos_net_remove,
+		nixos_br_remove,
+		nixos_attach_hostbridge,
+		nixos_host_addif,
+		nixos_remove_bridges}
 	};
 
 #define MIC_DEFAULT_BIG_MTU	"64512";
@@ -995,7 +1010,7 @@
 		(mic->config.rootdev.type == ROOT_TYPE_PFS)) {
 		mpssut_filename(&mpssenv, NULL, oname, PATH_MAX, "%s/etc/ssh/%s",
 			      strchr(mic->config.rootdev.target, ':') + 1, name);
-		if ((fd = open(oname, O_WRONLY|O_CREAT) & 0777) < 0) {
+		if (fd = open(oname, O_WRONLY|O_CREAT, 0755) < 0) {
 			display(PERROR, "%s: Could not open %s\n", mic->name, oname);
 			free(buffer);
 			return 0;
@@ -2571,6 +2586,37 @@
 }
 
 void
+nixos_net_remove(char *name, char *bridge, int modhost)
+{
+    printf("STUB: nixos_net_remove(%s, %s, %d)\n", name, bridge, modhost);
+}
+
+void
+nixos_br_remove(struct mbridge *br)
+{
+    printf("STUB: nixos_br_remove(%p)\n", br);
+}
+
+void
+nixos_attach_hostbridge(char *name, char *bridge, char *mac, char *mtu, int saveresolv)
+{
+    printf("STUB: nixos_attach_hostbridge(%s, %s, %s, %s, %d)\n", name, bridge, mac, mtu, saveresolv);
+}
+
+void
+nixos_host_addif(char *name, char *ip, char *netbits, char *mtu, char *mac)
+{
+    printf("STUB: nixos_host_addif(%s, %s, %s, %s, _)\n", name, ip, netbits, mtu, mac);
+}
+
+void
+nixos_remove_bridges(void)
+{
+    printf("STUB: nixos_remove_bridges()\n");
+	// TODO
+}
+
+void
 common_host_addif(char *name, char *ip, char *netbits, char *mtu, char *mac)
 {
 	char filename[PATH_MAX];
diff -ur mpss-daemon-3.8.6.orig/micctrl/user.c mpss-daemon-3.8.6/micctrl/user.c
--- mpss-daemon-3.8.6.orig/micctrl/user.c	2021-01-21 01:46:48.338522081 +0100
+++ mpss-daemon-3.8.6/micctrl/user.c	2021-01-21 03:36:40.330342110 +0100
@@ -2344,14 +2344,18 @@
 
 	if ((hpwfp = fopen("/etc/passwd", "r")) == NULL)
 		return;
+    printf("opened /etc/passwd\n");
 
 	while (fgets(line, PWBUF_SIZE, hpwfp)) {
 		user = line;
+        printf("line: %s\n", user);
 		if (parse_pwfile(user, &pw, &uid, &gid, &name, &home, &app))
 			continue;
+        printf("parsed pwfile\n");
 
 		if ((uid < get_min_uid()) || (uid == 65534))
 			continue;
+        printf("uid okay\n");
 
 		while (ulist) {
 			if (!strcmp(ulist->user, user)) {
@@ -2858,7 +2862,7 @@
 	if (pid == 0) {
 		fclose(stdout);
 		fclose(stderr);
-		ifargv[0] = "/usr/bin/ssh-keygen";
+		ifargv[0] = "/run/current-system/sw/bin/ssh-keygen";
 		ifargv[1] = "-q";
 		ifargv[2] = "-t";
 		ifargv[3] = type;
@@ -2869,7 +2873,7 @@
 		ifargv[8] = "-N";
 		ifargv[9] = "";
 		ifargv[10] = NULL;
-		execve("/usr/bin/ssh-keygen", ifargv, NULL);
+		execve("/run/current-system/sw/bin/ssh-keygen", ifargv, NULL);
 		exit(errno);
 	}
 
@@ -2885,9 +2889,9 @@
 	char *name;
 	char *type;
 	int optional;
-} hkeys[] = {{"ssh_host_key", "rsa1", FALSE},
+} hkeys[] = {/*{"ssh_host_key", "rsa1", FALSE},*/
 	     {"ssh_host_rsa_key", "rsa", FALSE},
-	     {"ssh_host_dsa_key", "dsa", FALSE},
+	     /*{"ssh_host_dsa_key", "dsa", FALSE},*/
 	     {"ssh_host_ecdsa_key", "ecdsa", TRUE},
 	     {NULL, NULL}};
 
diff -ur mpss-daemon-3.8.6.orig/micctrl/utilfuncs.c mpss-daemon-3.8.6/micctrl/utilfuncs.c
--- mpss-daemon-3.8.6.orig/micctrl/utilfuncs.c	2021-01-21 01:46:48.338522081 +0100
+++ mpss-daemon-3.8.6/micctrl/utilfuncs.c	2021-01-21 01:56:35.453755052 +0100
@@ -238,7 +238,7 @@
 	mpssut_filename(&mpssenv, NULL, permfile, PATH_MAX, "/permfile");
 	tmpname = mpssut_tempnam(permfile);
 
-	if ((fd = open(tmpname, O_RDWR | O_CREAT)) < 0) {
+	if ((fd = open(tmpname, O_RDWR | O_CREAT, 0644)) < 0) {
 		free(tmpname);
 		display(PERROR, "Failed permissions test - cannot determine if %s is secure\n", mpssenv.destdir);
 		exit(errno);
diff -ur mpss-daemon-3.8.6.orig/mpssd/mpssd.c mpss-daemon-3.8.6/mpssd/mpssd.c
--- mpss-daemon-3.8.6.orig/mpssd/mpssd.c	2021-01-21 01:46:48.338522081 +0100
+++ mpss-daemon-3.8.6/mpssd/mpssd.c	2021-01-21 03:52:50.930892803 +0100
@@ -729,10 +729,10 @@
 
 	pid = fork();
 	if (pid == 0) {
-		ifargv[0] = "/bin/gzip";
+		ifargv[0] = "/run/current-system/sw/bin/gzip";
 		ifargv[1] = name;
 		ifargv[2] = NULL;
-		execve("/bin/gzip", ifargv, NULL);
+		execve("/run/current-system/sw/bin/gzip", ifargv, NULL);
 	}
 
 	return pid;
@@ -1418,7 +1418,7 @@
 		len = read(fd, cookie, MPSS_COOKIE_SIZE);
 		close(fd);
 
-		if ((fd = open(cookiename, O_WRONLY|O_CREAT)) < 0) {
+		if ((fd = open(cookiename, O_WRONLY|O_CREAT, 0755)) < 0) {
 			mpsslog(PERROR, "Failed to open %s: %s\n", cookiename, strerror(errno));
 			goto cookie_done;
 		}