util  Check-in [987a1aac03]

Overview
Comment:fixes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 987a1aac0368eb1ba1468de2f03194f903aa18fd47000fd3f004d7eb319d339b
User & Date: lexi on 2022-11-01 20:05:09
Other Links: manifest | tags
Context
2022-12-26
13:31
add termcolors, update parvan and compose check-in: 54874eb3eb user: lexi tags: trunk
2022-11-01
20:05
fixes check-in: 987a1aac03 user: lexi tags: trunk
19:10
fully functional?? check-in: 700efc70e2 user: lexi tags: trunk
Changes

Modified wgsync/src/wgsync.c from [804d360053] to [3eda0dfc74].

248
249
250
251
252
253
254



255
256
257
258
259
260
261
262
...
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
...
442
443
444
445
446
447
448


449
450
451
452
453
454
455
456
				found = p;
				break;
			}
		++j;}}

		if (found) {
			/* compare and update IPs if necessary */



			bool goodIPs [ips -> sz]; _zero(goodIPs);
			/* extant IPs that are not marked good by the
			 * end of the following loop must be deleted
			 * from memory */
			size_t goodIPc = 0;
			for (size_t j = 0; j < ips -> sz; ++j) {
				char inetstr[256];
				wg_allowedip aip = inet_to_allowedip(ips -> elts[j].data);
................................................................................
				wg_for_each_allowedip(found, wgip) {
					if (compare_allowedip(&aip, wgip)) {
						++goodIPc; goodIPs[l] = true;
						foundIP = true;
					}
				++l;}
				
				if(!foundIP) {
					/* this IP hasn't been loaded into the
					 * kernel yet; upload it now */
					_infof("inserting IP PG%zu %s", j, inetstr);
					// is this necessary? FIXME
					/* found -> flags |= WGPEER_REPLACE_ALLOWEDIPS; */
					wg_allowedip* nip = wgd_peer_new_allowedip(found);
					memcpy(nip, &aip, sizeof aip);
					dirty = true;
				}
			}

			if(goodIPc < ips -> sz) {
				size_t l = 0;
				wg_allowedip* wgip;
				wg_for_each_allowedip(found, wgip) {
					char inetstr[256];
					dumpAllowedIP(inetstr, wgip);
					_dbgf("IP WG%zu :: %s", l, inetstr);
					if(l<goodIPc && !goodIPs[l]) {
................................................................................
	if(geteuid() == 0) {
		char* suid = getenv("SUDO_UID");
		char* susr = getenv("SUDO_USER");
		if(suid) seteuid(atoi(suid));
		if(susr) setenv("USER",getenv("SUDO_USER"), 1);
	}



	PGconn* db = PQconnectdb("dbname=domain");
	if(PQstatus(db) != CONNECTION_OK) 
		_fatal(PQerrorMessage(db));

	PGresult* q_get_hosts = PQprepare(db, "get_hosts",
		"select h.ref, array_remove(array_agg(wgv4::inet)"
		                        "|| array_agg(wgv6::inet), null)"
			"from ns, hostref h "







>
>
>
|







 







|



<
|






|







 







>
>
|







248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
...
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
...
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
				found = p;
				break;
			}
		++j;}}

		if (found) {
			/* compare and update IPs if necessary */

			size_t wgIPc = 0;
			{ wg_allowedip* a; wg_for_each_allowedip(found, a) ++wgIPc; };
			bool goodIPs [wgIPc]; _zero(goodIPs);
			/* extant IPs that are not marked good by the
			 * end of the following loop must be deleted
			 * from memory */
			size_t goodIPc = 0;
			for (size_t j = 0; j < ips -> sz; ++j) {
				char inetstr[256];
				wg_allowedip aip = inet_to_allowedip(ips -> elts[j].data);
................................................................................
				wg_for_each_allowedip(found, wgip) {
					if (compare_allowedip(&aip, wgip)) {
						++goodIPc; goodIPs[l] = true;
						foundIP = true;
					}
				++l;}
				
				if(foundIP == false) {
					/* this IP hasn't been loaded into the
					 * kernel yet; upload it now */
					_infof("inserting IP PG%zu %s", j, inetstr);

					found -> flags |= WGPEER_REPLACE_ALLOWEDIPS;
					wg_allowedip* nip = wgd_peer_new_allowedip(found);
					memcpy(nip, &aip, sizeof aip);
					dirty = true;
				}
			}

			if(goodIPc < wgIPc) {
				size_t l = 0;
				wg_allowedip* wgip;
				wg_for_each_allowedip(found, wgip) {
					char inetstr[256];
					dumpAllowedIP(inetstr, wgip);
					_dbgf("IP WG%zu :: %s", l, inetstr);
					if(l<goodIPc && !goodIPs[l]) {
................................................................................
	if(geteuid() == 0) {
		char* suid = getenv("SUDO_UID");
		char* susr = getenv("SUDO_USER");
		if(suid) seteuid(atoi(suid));
		if(susr) setenv("USER",getenv("SUDO_USER"), 1);
	}

	char* connstr = getenv("wgsync_conn");
	if(connstr == null) _fatal("no connection string supplied");
	PGconn* db = PQconnectdb(connstr);
	if(PQstatus(db) != CONNECTION_OK) 
		_fatal(PQerrorMessage(db));

	PGresult* q_get_hosts = PQprepare(db, "get_hosts",
		"select h.ref, array_remove(array_agg(wgv4::inet)"
		                        "|| array_agg(wgv6::inet), null)"
			"from ns, hostref h "