util  Diff

Differences From Artifact [804d360053]:

To Artifact [3eda0dfc74]:


   250    250   			}
   251    251   		++j;}}
   252    252   
   253    253   		if (found) {
   254    254   			/* compare and update IPs if necessary */
   255         -			bool goodIPs [ips -> sz]; _zero(goodIPs);
          255  +
          256  +			size_t wgIPc = 0;
          257  +			{ wg_allowedip* a; wg_for_each_allowedip(found, a) ++wgIPc; };
          258  +			bool goodIPs [wgIPc]; _zero(goodIPs);
   256    259   			/* extant IPs that are not marked good by the
   257    260   			 * end of the following loop must be deleted
   258    261   			 * from memory */
   259    262   			size_t goodIPc = 0;
   260    263   			for (size_t j = 0; j < ips -> sz; ++j) {
................................................................................
   271    274   						++goodIPc; goodIPs[l] = true;
   272    275   						foundIP = true;
   273    276   					}
   274    277   				++l;}
   275    278   				
   276         -				if(!foundIP) {
          279  +				if(foundIP == false) {
   277    280   					/* this IP hasn't been loaded into the
   278    281   					 * kernel yet; upload it now */
   279    282   					_infof("inserting IP PG%zu %s", j, inetstr);
   280         -					// is this necessary? FIXME
   281         -					/* found -> flags |= WGPEER_REPLACE_ALLOWEDIPS; */
          283  +					found -> flags |= WGPEER_REPLACE_ALLOWEDIPS;
   282    284   					wg_allowedip* nip = wgd_peer_new_allowedip(found);
   283    285   					memcpy(nip, &aip, sizeof aip);
   284    286   					dirty = true;
   285    287   				}
   286    288   			}
   287    289   
   288         -			if(goodIPc < ips -> sz) {
          290  +			if(goodIPc < wgIPc) {
   289    291   				size_t l = 0;
   290    292   				wg_allowedip* wgip;
   291    293   				wg_for_each_allowedip(found, wgip) {
   292    294   					char inetstr[256];
   293    295   					dumpAllowedIP(inetstr, wgip);
................................................................................
   444    446   		char* susr = getenv("SUDO_USER");
   445    447   		if(suid) seteuid(atoi(suid));
   446    448   		if(susr) setenv("USER",getenv("SUDO_USER"), 1);
   447    449   	}
   448    450   
   449         -	PGconn* db = PQconnectdb("dbname=domain");
          451  +	char* connstr = getenv("wgsync_conn");
          452  +	if(connstr == null) _fatal("no connection string supplied");
          453  +	PGconn* db = PQconnectdb(connstr);
   450    454   	if(PQstatus(db) != CONNECTION_OK) 
   451    455   		_fatal(PQerrorMessage(db));
   452    456   
   453    457   	PGresult* q_get_hosts = PQprepare(db, "get_hosts",
   454    458   		"select h.ref, array_remove(array_agg(wgv4::inet)"