Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 154497
Collapse All | Expand All

(-)NetworkManager/trunk/src/backends/NetworkManagerGentoo.c (-123 / +413 lines)
Lines 1-2 Link Here
1
1
/* NetworkManager -- Network link manager
2
/* NetworkManager -- Network link manager
2
 *
3
 *
Lines 250-257 Link Here
250
 */
251
 */
251
void nm_system_restart_mdns_responder (void)
252
void nm_system_restart_mdns_responder (void)
252
{
253
{	
253
	nm_spawn_process("/etc/init.d/mDNSResponder stop");
254
	/* Check if the daemon was already running - do not start a new instance */
254
	nm_spawn_process("/etc/init.d/mDNSResponder zap");
255
	/* Howl */
255
	nm_spawn_process("/etc/init.d/mDNSResponder start");
256
	if (g_file_test("/var/run/mDNSResponder.pid", G_FILE_TEST_EXISTS))
257
	{
258
		nm_info("Restarting mDNSResponder");
259
		nm_spawn_process("/etc/init.d/mDNSResponder stop");
260
		nm_spawn_process("/etc/init.d/mDNSResponder zap");
261
		nm_spawn_process("/etc/init.d/mDNSResponder start");
262
	}
263
	/* Apple's mDNSResponder */
264
	if (g_file_test("/var/run/mDNSResponderPosix.pid", G_FILE_TEST_EXISTS))
265
	{
266
		nm_info("Restarting mDNSResponderPosix");
267
		nm_spawn_process("/etc/init.d/mDNSResponderPosix restart");
268
	}
269
#if 0
270
	/* Avahi should handle this all by itself, thank-you-very-much */
271
	/* Avahi */
272
	if (g_file_test("/var/run/avahi-daemon/pid", G_FILE_TEST_EXISTS))
273
	{
274
		nm_info("Restarting the Avahi Daemon");
275
		nm_spawn_process("/etc/init.d/avahi-daemon restart");
276
	}
277
#endif
256
}
278
}
257
279
Lines 266-270 Link Here
266
{
288
{
267
	char *buf;
289
	char *buf;
268
	char *addr;
269
	struct ether_addr hw_addr;
290
	struct ether_addr hw_addr;
270
	unsigned char eui[8];
291
	unsigned char eui[8];
Lines 289-298 Link Here
289
}
310
}
290
311
312
/*
313
*   GentooReadConfig
314
*   
315
*   Most of this comes from the arch backend, no need to re-invent.
316
*   Read platform dependant config file and fill hash with relevant info
317
*/
318
static GHashTable * GentooReadConfig(const char* dev)
319
{
320
	GHashTable *ifs;
321
	shvarFile	*file;
322
	int len, hits, i = 0;
323
	guint32 maskval;
324
	gchar buf[16], *value, *cidrprefix, *gateway;
325
	gchar *config_str, *iface_str, *route_str, *mtu_str, *dnsserver_str, *dnssearch_str;	/* Lookup keys */
326
	gchar **conf, **config = NULL, **routes = NULL;
327
	struct in_addr mask;
328
	
329
	file = svNewFile(SYSCONFDIR"/conf.d/net");
330
	if (!file)
331
		return NULL;
332
	
333
	ifs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
334
	if (ifs == NULL)
335
	{
336
		nm_debug("Unable to create g_hash_table.");
337
		svCloseFile(file);
338
		return NULL;
339
	}
340
	
341
	/* Keys we will use for lookups later */
342
	config_str = g_strdup_printf("config_%s", dev);
343
	iface_str = g_strdup_printf("iface_%s", dev);
344
	route_str = g_strdup_printf("routes_%s", dev);
345
	mtu_str = g_strdup_printf("mtu_%s", dev);
346
	dnsserver_str = g_strdup_printf("dns_servers_%s", dev);
347
	dnssearch_str = g_strdup_printf("dns_search_%s", dev);
348
	
349
	
350
	if ((config = svGetArray(file, iface_str)))
351
	{
352
		/* This isn't tested, (or supported, really) so hopefully it works */
353
		nm_info("You are using a deprecated configuration syntax for %s.", dev);
354
		nm_info("You are advised to read /etc/conf.d/net.example and upgrade it accordingly.");
355
		value = svGetValue(file, "gateway");
356
		if ((value) && (gateway = strstr(value, dev)) && strtok(gateway, "/"))
357
		{
358
			/* Is it possible to specify multiple gateways using this variable? */
359
			gateway = strtok(NULL, "/");
360
			routes = g_renew(char*, routes, 2);
361
			routes[0] = g_strdup_printf("default via %s", gateway);
362
			routes[1] = NULL;
363
			g_free(value);
364
		}
365
	}
366
	else
367
	{
368
		config = svGetArray(file, config_str);
369
		routes = svGetArray(file, route_str);
370
	}
371
	
372
	
373
	if ((config) && g_ascii_strcasecmp(config[0], "dhcp"))
374
	{
375
		nm_debug("Found %s in %s.", config_str, SYSCONFDIR"/conf.d/net");
376
	
377
		if (!g_ascii_strcasecmp(config[0], "null"))
378
		{
379
			nm_debug("Config disables device %s.", dev);
380
			g_hash_table_insert(ifs, g_strdup("disabled"), g_strdup("true"));
381
		}
382
		else
383
		{
384
			/* TODO: Handle "noop". */
385
			conf = g_strsplit(config[0], " ", 0);
386
			hits = g_strv_length(conf);
387
			
388
			strtok(conf[0], "/");
389
			if ((cidrprefix = strtok(NULL, "/")))
390
			{
391
				maskval = 0xffffffff;
392
				maskval <<= (32 - atoi(cidrprefix));
393
				mask.s_addr = htonl(maskval);
394
				g_hash_table_insert(ifs, g_strdup("netmask"), g_strdup(inet_ntoa(mask)));
395
			}
396
			
397
			
398
			if ((hits > 0) && inet_aton(conf[0], &mask))
399
			{
400
				g_hash_table_insert(ifs, g_strdup(dev), g_strdup(conf[i++]));
401
				while ((hits -= 2) > 0)
402
				{
403
					g_hash_table_insert(ifs, g_strdup(conf[i]), g_strdup(conf[i+1]));
404
					i += 2;
405
				}
406
			}
407
			else
408
			{
409
				nm_debug("Unhandled configuration. Switching to DHCP.");
410
				nm_debug("\t%s = %s", config_str, config[0]);
411
				g_hash_table_insert(ifs, g_strdup("dhcp"), g_strdup("true"));
412
			}
413
			g_strfreev(conf);
414
		}
415
	}
416
	else
417
	{
418
		nm_debug("Enabling DHCP for device %s.", dev);
419
		g_hash_table_insert(ifs, g_strdup("dhcp"), g_strdup("true"));
420
	}
421
	
422
	g_strfreev(config);
423
	
424
	if (routes)
425
	{
426
		nm_debug("Found %s in config.", route_str);
427
		
428
		len = g_strv_length(routes);
429
		for (i = 0; i < len; i++)
430
		{
431
			if (!sscanf(routes[i], "default via %[0-9.:]", buf))
432
				continue;
433
434
			g_hash_table_insert(ifs,g_strdup("gateway"),g_strdup( (char*) buf));
435
		}
436
	}
437
	
438
	g_strfreev(routes);
439
	
440
	if ((value = svGetValue(file, mtu_str)))
441
	{
442
		nm_debug("Found %s in config.", mtu_str);
443
		g_hash_table_insert(ifs, g_strdup("mtu"), g_strdup(value));
444
	}
445
	
446
	g_free(value);
447
	
448
	if (!(value = svGetValue(file, dnsserver_str)))
449
	{
450
		value = svGetValue(file, "dns_servers");
451
	}
452
	if (value)
453
	{
454
		nm_debug("Found DNS nameservers in config.");
455
		g_hash_table_insert(ifs, g_strdup("nameservers"), g_strdup(value));
456
	}
457
	
458
	g_free(value);
459
	
460
	if (!(value = svGetValue(file, dnssearch_str)))
461
	{
462
		value = svGetValue(file, "dns_search");
463
	}
464
	if (value)
465
	{
466
		nm_debug("Found DNS search in config.");
467
		g_hash_table_insert(ifs, g_strdup("dnssearch"), g_strdup(value));
468
	}
469
470
	g_free(value);
471
	svCloseFile(file);
472
	
473
	if ((file = svNewFile(SYSCONFDIR"/conf.d/hostname")))
474
	{	
475
		if ((value = svGetValue(file, "HOSTNAME")) && (strlen(value) > 0))
476
		{
477
			nm_debug("Found hostname.");
478
			g_hash_table_insert(ifs, g_strdup("hostname"), g_strdup(value));
479
		}
480
		
481
		g_free(value);
482
		svCloseFile(file);
483
	}
484
485
		
486
	g_free(config_str);
487
	g_free(iface_str);
488
	g_free(route_str);
489
	g_free(mtu_str);
490
	g_free(dnsserver_str);
491
	g_free(dnssearch_str);
492
	
493
	return ifs;
494
}
495
291
typedef struct GentooSystemConfigData
496
typedef struct GentooSystemConfigData
292
{
497
{
293
	NMIP4Config *	config;
498
	NMIP4Config *	config;
294
	gboolean		use_dhcp;
499
	gboolean		use_dhcp;
500
	gboolean		system_disabled;
501
	guint32		mtu;
295
} GentooSystemConfigData;
502
} GentooSystemConfigData;
296
297
503
298
/*
504
/*
Lines 304-436 Link Here
304
 *
510
 *
305
 */
511
 */
306
void *nm_system_device_get_system_config (NMDevice *dev, NMData *app_data)
512
void* nm_system_device_get_system_config (NMDevice * dev, NMData *app_data)
307
{
513
{
308
	char		*cfg_file_path = NULL;
514
	GHashTable* ifh;
309
	FILE		*file = NULL;
515
	gpointer val;
310
	char		 buffer[100];
516
	gchar **strarr;
311
	char		 confline[100], dhcpline[100], ipline[100];
517
	GentooSystemConfigData*   sys_data = NULL;
312
	int		 ipa, ipb, ipc, ipd;
518
	int len, i;
313
 	int		 nNext =  0, bNext = 0, count = 0;
519
314
	char		*confToken;
520
	g_return_val_if_fail(dev != NULL, NULL);
315
	gboolean	 data_good = FALSE;
521
	
316
	gboolean	 use_dhcp = TRUE;
522
	sys_data = g_malloc0(sizeof (GentooSystemConfigData));
317
	GentooSystemConfigData *sys_data = NULL;
318
	guint32	 ip4_address = 0;
319
	guint32	 ip4_netmask = 0;
320
	guint32	 ip4_gateway = 0;
321
	guint32	 ip4_broadcast = 0;
322
323
	g_return_val_if_fail (dev != NULL, NULL);
324
325
	sys_data = g_malloc0 (sizeof (GentooSystemConfigData));
326
    sys_data->config = nm_device_get_ip4_config(dev);
327
	/* We use DHCP on an interface unless told not to */
328
	sys_data->use_dhcp = TRUE;
523
	sys_data->use_dhcp = TRUE;
329
	nm_device_set_use_dhcp (dev, TRUE);
524
	sys_data->system_disabled = FALSE;
330
//	nm_ip4_config_set_address (sys_data->config, 0);
525
	sys_data->mtu = 0;
331
//	nm_ip4_config_set_gateway (sys_data->config, 0);
526
	sys_data->config=NULL;
332
//	nm_ip4_config_set_netmask (sys_data->config, 0);
527
333
528
	ifh = GentooReadConfig(nm_device_get_iface(dev));
334
	/* Gentoo systems store this information in
529
	if (ifh == NULL)
335
	 * /etc/conf.d/net, this is for all interfaces.
530
	{
336
	 */
531
		g_free(sys_data);
337
338
	cfg_file_path = g_strdup_printf ("/etc/conf.d/net");
339
	if (!cfg_file_path)
340
		return NULL;
532
		return NULL;
341
533
	}
342
	if (!(file = fopen (cfg_file_path, "r")))
534
	
343
	{
535
	val = g_hash_table_lookup(ifh, "disabled");
344
		g_free (cfg_file_path);
536
	if (val)
345
		return NULL;
537
	{
346
	}
538
		if (!strcasecmp (val, "true"))
347
 	sprintf(confline, "iface_%s", nm_device_get_iface (dev));
539
		{
348
 	sprintf(dhcpline, "iface_%s=\"dhcp\"", nm_device_get_iface (dev));
540
			nm_info ("System configuration disables device %s", nm_device_get_iface (dev));
349
	while (fgets (buffer, 499, file) && !feof (file))
541
			sys_data->system_disabled = TRUE;
350
	{
542
		}
351
		/* Kock off newline if any */
543
	}
352
		g_strstrip (buffer);
544
	
353
545
	val = g_hash_table_lookup(ifh, "mtu");
354
		if (strncmp (buffer, confline, strlen(confline)) == 0)
546
	if (val)
547
	{
548
		guint32 mtu;
549
		
550
		mtu = strtoul(val, NULL, 10);
551
		if (mtu > 500 && mtu < INT_MAX)
552
		{
553
			nm_debug("System configuration specifies a MTU of %i for device %s", mtu, nm_device_get_iface(dev));
554
			sys_data->mtu = mtu;
555
		}
556
	}
557
	val = g_hash_table_lookup(ifh, "hostname");
558
	if (val)
559
	{
560
		nm_ip4_config_set_hostname(sys_data->config, val);
561
	}
562
	
563
	val = g_hash_table_lookup(ifh, nm_device_get_iface(dev));
564
	if (val && !g_hash_table_lookup(ifh, "dhcp"))
565
	{
566
		/* This device does not use DHCP */
567
568
		sys_data->use_dhcp=FALSE;
569
		sys_data->config = nm_ip4_config_new();
570
571
		nm_ip4_config_set_address (sys_data->config, inet_addr (val));
572
573
		val = g_hash_table_lookup(ifh, "gateway");
574
		if (val)
575
			nm_ip4_config_set_gateway (sys_data->config, inet_addr (val));
576
		else
577
		{
578
			nm_info ("Network configuration for device '%s' does not specify a gateway but is "
579
				 "statically configured (non-DHCP).", nm_device_get_iface (dev));
580
		}
581
582
		val = g_hash_table_lookup(ifh, "netmask");
583
		if (val)
584
			nm_ip4_config_set_netmask (sys_data->config, inet_addr (val));
585
		else
586
		{
587
			guint32 addr = nm_ip4_config_get_address (sys_data->config);
588
589
			/* Make a default netmask if we have an IP address */
590
			if (((ntohl (addr) & 0xFF000000) >> 24) <= 127)
591
				nm_ip4_config_set_netmask (sys_data->config, htonl (0xFF000000));
592
			else if (((ntohl (addr) & 0xFF000000) >> 24) <= 191)
593
				nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFF0000));
594
			else
595
				nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFFFF00));
596
		}
597
598
		val = g_hash_table_lookup(ifh, "broadcast");
599
		if (val)
600
			nm_ip4_config_set_broadcast (sys_data->config, inet_addr (val));
601
		else if ((val = g_hash_table_lookup(ifh, "brd")))
602
			nm_ip4_config_set_broadcast (sys_data->config, inet_addr (val));
603
		else
604
		{
605
			guint32 broadcast = ((nm_ip4_config_get_address (sys_data->config) & nm_ip4_config_get_netmask (sys_data->config))
606
							 | ~nm_ip4_config_get_netmask (sys_data->config));
607
			nm_ip4_config_set_broadcast (sys_data->config, broadcast);
608
		}
609
		
610
		val = g_hash_table_lookup(ifh, "nameservers");
611
		if (val)
612
		{
613
			nm_debug("Using DNS nameservers \"%s\" from config for device %s.", val, nm_device_get_iface(dev));
614
			if ((strarr = g_strsplit(val, " ", 0)))
355
			{
615
			{
356
			/* Make sure this config file is for this device */
616
				len = g_strv_length(strarr);
357
			if (strncmp (&buffer[strlen(confline) - strlen(nm_device_get_iface (dev))], 
617
				for(i = 0; i < len; i++)
358
				nm_device_get_iface (dev), strlen(nm_device_get_iface (dev))) != 0)
359
				{
618
				{
360
				nm_warning ("System config file '%s' does not define device '%s'\n",
619
					guint32 addr = (guint32) (inet_addr (strarr[i]));
361
                                             cfg_file_path, nm_device_get_iface (dev));
620
362
				break;
621
					if (addr != (guint32) -1)
363
			}
622
						nm_ip4_config_add_nameserver(sys_data->config, addr);
364
			else
623
				}
365
				data_good = TRUE;
624
				
366
625
				g_strfreev(strarr);
367
			if (strncmp (buffer, dhcpline, strlen(dhcpline)) == 0)
368
			{
369
				use_dhcp = TRUE;
370
			}
626
			}
371
			else
627
			else
372
			{
628
			{
373
				use_dhcp = FALSE;
629
				guint32 addr = (guint32) (inet_addr (val));
374
				confToken = strtok(&buffer[strlen(confline) + 2], " ");
630
375
				while (count < 3)
631
				if (addr != (guint32) -1)
376
					{
632
					nm_ip4_config_add_nameserver(sys_data->config, addr);
377
					if (nNext == 1 && bNext == 1)
633
			}
378
					{
634
		}
379
						ip4_address = inet_addr (confToken);
635
380
						count++;
636
		val = g_hash_table_lookup(ifh, "dnssearch");
381
						continue;
637
		if (val)
382
					}
638
		{
383
					if (strcmp(confToken, "netmask") == 0)
639
			nm_debug("Using DNS search \"%s\" from config for device %s.", val, nm_device_get_iface(dev));
384
					{
640
			if ((strarr = g_strsplit(val, " ", 0)))
385
						confToken = strtok(NULL, " ");
641
			{
386
						ip4_netmask = inet_addr (confToken);
642
				len = g_strv_length(strarr);
387
						count++;
643
				for(i = 0; i < len; i++)
388
						nNext = 1;
644
				{
389
					}
645
					if (strarr[i])
390
					else if (strcmp(confToken, "broadcast") == 0)
646
						nm_ip4_config_add_domain(sys_data->config, strarr[i]);
391
					{
392
						confToken = strtok(NULL, " ");
393
						count++;
394
						bNext = 1;
395
					}
396
					else
397
					{
398
						ip4_address = inet_addr (confToken);
399
						count++;
400
					}
401
						confToken = strtok(NULL, " ");
402
					}
403
				}
647
				}
648
				
649
				g_strfreev(strarr);
404
			}
650
			}
405
		/* If we aren't using dhcp, then try to get the gateway */
651
			else
406
		if (!use_dhcp)
407
			{
652
			{
408
			sprintf(ipline, "gateway=\"%s/", nm_device_get_iface (dev));
653
				nm_ip4_config_add_domain(sys_data->config, val);
409
			if (strncmp(buffer, ipline, strlen(ipline) - 1) == 0)
654
			}
655
		}
656
		
657
		nm_ip4_config_set_mtu (sys_data->config, sys_data->mtu);
658
659
#if 0
660
		{
661
			int j;
662
			nm_debug ("------ Config (%s)", nm_device_get_iface (dev));
663
			nm_debug ("    ADDR=%d", nm_ip4_config_get_address (sys_data->config));
664
			nm_debug ("    GW  =%d", nm_ip4_config_get_gateway (sys_data->config));
665
			nm_debug ("    NM  =%d", nm_ip4_config_get_netmask (sys_data->config));
666
			nm_debug ("    NSs =%d",nm_ip4_config_get_num_nameservers(sys_data->config));
667
			for (j=0;j<nm_ip4_config_get_num_nameservers(sys_data->config);j++)
410
			{
668
			{
411
				sprintf(ipline, "gateway=\"%s/%%d.%%d.%%d.%%d\"", nm_device_get_iface (dev) );
669
				nm_debug ("    NS =%d",nm_ip4_config_get_nameserver(sys_data->config,j));
412
				sscanf(buffer, ipline, &ipa, &ipb, &ipc, &ipd);
413
				sprintf(ipline, "%d.%d.%d.%d", ipa, ipb, ipc, ipd);
414
				ip4_gateway = inet_addr (ipline);
415
			}
670
			}
416
		}		
671
			nm_debug ("---------------------\n");
417
	}
672
		}
418
	fclose (file);
673
#endif
419
	g_free (cfg_file_path);
674
420
 
675
	}
421
	/* If successful, set values on the device */
676
	
422
	if (data_good)
677
	g_hash_table_destroy(ifh);
423
	{
678
424
        nm_warning("data good :-)");
679
425
		nm_device_set_use_dhcp (dev, use_dhcp);
426
		if (ip4_address)
427
            nm_ip4_config_set_address (sys_data->config, ip4_address);
428
		if (ip4_gateway)
429
            nm_ip4_config_set_gateway (sys_data->config, ip4_gateway);
430
		if (ip4_netmask)
431
			nm_ip4_config_set_netmask (sys_data->config, ip4_netmask);
432
		if (ip4_broadcast)
433
			nm_ip4_config_set_broadcast (sys_data->config, ip4_broadcast);
434
	}
435
	return (void *)sys_data;
680
	return (void *)sys_data;
436
}
681
}
Lines 519-522 Link Here
519
gboolean nm_system_device_get_disabled (NMDevice *dev)
764
gboolean nm_system_device_get_disabled (NMDevice *dev)
520
{
765
{
766
	GentooSystemConfigData *sys_data;
767
768
	g_return_val_if_fail (dev != NULL, FALSE);
769
770
	if ((sys_data = nm_device_get_system_config_data (dev)))
771
		return sys_data->system_disabled;
772
521
	return FALSE;
773
	return FALSE;
522
}
774
}
Lines 576-579 Link Here
576
void nm_system_set_hostname (NMIP4Config *config)
828
void nm_system_set_hostname (NMIP4Config *config)
577
{
829
{
830
	char *h_name = NULL;
831
	const char *hostname;
832
833
	g_return_if_fail (config != NULL);
834
835
	hostname = nm_ip4_config_get_hostname (config);
836
	if (!hostname)
837
	{
838
		struct in_addr temp_addr;
839
		struct hostent *host;
840
841
		/* try to get hostname via dns */
842
		temp_addr.s_addr = nm_ip4_config_get_address (config);
843
		host = gethostbyaddr ((char *) &temp_addr, sizeof (temp_addr), AF_INET);
844
		if (host)
845
		{
846
			h_name = g_strdup (host->h_name);
847
			hostname = strtok (h_name, ".");
848
		}
849
		else
850
			nm_warning ("nm_system_set_hostname(): gethostbyaddr failed, h_errno = %d", h_errno);
851
	}
852
853
	if (hostname)
854
	{
855
		nm_info ("Setting hostname to '%s'", hostname);
856
		if (sethostname (hostname, strlen (hostname)) < 0)
857
			nm_warning ("Could not set hostname.");
858
	}
859
860
	g_free (h_name);
578
}
861
}
579
862
Lines 596-599 Link Here
596
guint32 nm_system_get_mtu (NMDevice *dev)
879
guint32 nm_system_get_mtu (NMDevice *dev)
597
{
880
{
881
	GentooSystemConfigData *sys_data;
882
883
	g_return_val_if_fail (dev != NULL, 0);
884
885
	if ((sys_data = nm_device_get_system_config_data (dev)))
886
		return sys_data->mtu;
887
598
	return 0;
888
	return 0;
599
}
889
}
(-)NetworkManager/trunk/src/backends/shvar.c (-1 / +77 lines)
Lines 216-219 Link Here
216
    if (s->parent) value = svGetValue(s->parent, key);
216
    if (s->parent) value = svGetValue(s->parent, key);
217
    return value;
217
    return value;
218
}
219
220
/* Get the array associated with the key, and leave the current pointer
221
 * pointing at the line containing the key.  The char** returned MUST
222
 * be freed by the caller.
223
 */
224
gchar **
225
svGetArray(shvarFile *s, const char *key)
226
{
227
	gchar **values = NULL, **lines, *line, *value;
228
	GList *restore;
229
	int len, strvlen, i, j;
230
231
	g_assert(s);
232
	g_assert(key);
233
234
	/* Attempt to do things the easy way first */
235
	line = svGetValue(s, key);
236
	if (!line)
237
		return NULL;
238
	
239
	restore = s->current;
240
	
241
	g_strstrip(strtok(line, "#"));	/* Remove comments and whitespace */
242
	
243
	if (line[0] != '(')
244
	{
245
		/* This isn't an array, so pretend it's a one item array. */
246
		values = g_renew(char*, values, 2);
247
		values[0] = line;
248
		values[1] = NULL;
249
		return values;
250
	}
251
	
252
	while(!strrchr(line, ')'))
253
	{
254
		s->current = s->current->next;
255
		value = g_strjoin(" ", line, g_strstrip(strtok(s->current->data, "#")), NULL);
256
		g_free(line);
257
		line = value;
258
		value = NULL;
259
	}
260
	
261
	lines = g_strsplit(line, "\"", 0);
262
	
263
	strvlen = g_strv_length(lines);
264
	if (strvlen == 0)
265
	{
266
		/* didn't split, something's wrong */
267
		g_free(line);
268
		return NULL;
269
	}
270
	
271
	j = 0;
272
	for (i = 0; i <= strvlen - 1; i++)
273
	{
274
		value = lines[i];
275
		len = strlen(g_strstrip(value));
276
		if ((value[0] == '(') || (value[0] == ')') || (len == 0))
277
			continue;
278
		
279
		values = g_renew(char*, values, j + 2);
280
		values[j+1] = NULL;
281
		values[j++] = g_strdup(value);
282
	}
283
	
284
	g_free(line);
285
	g_strfreev(lines);
286
	s->current = restore;
287
	
288
	return values;
218
}
289
}
219
290
Lines 393-397 Link Here
393
    g_free(s->fileName);
464
    g_free(s->fileName);
394
    g_list_free(s->freeList);
465
    g_list_free(s->freeList);
395
    g_list_free(s->lineList); /* implicitly frees s->current */
466
    
467
    if (s->lineList) {
468
	    g_list_foreach(s->lineList, (GFunc) g_free, NULL);
469
	    g_list_free(s->lineList); /* implicitly frees s->current */
470
    }
471
    
396
    g_free(s);
472
    g_free(s);
397
    return 0;
473
    return 0;
(-)NetworkManager/trunk/src/backends/shvar.h (+7 lines)
Lines 66-69 Link Here
66
svGetValue(shvarFile *s, const char *key);
66
svGetValue(shvarFile *s, const char *key);
67
67
68
/* Get the bash array associated with the key, and leave the current pointer
69
 * pointing at the line containing the key.  The gchar** returned MUST
70
 * be freed by the caller.
71
 */
72
gchar **
73
svGetArray(shvarFile *s, const char *key);
74
68
/* return 1 if <key> resolves to any truth value (e.g. "yes", "y", "true")
75
/* return 1 if <key> resolves to any truth value (e.g. "yes", "y", "true")
69
 * return 0 if <key> resolves to any non-truth value (e.g. "no", "n", "false")
76
 * return 0 if <key> resolves to any non-truth value (e.g. "no", "n", "false")

Return to bug 154497