[Frugalware-darcs] setup-current: netconfig: sanility checks in parseconfig()

VMiklos vmiklos at frugalware.org
Thu Mar 16 18:09:23 CET 2006


[netconfig: sanility checks in parseconfig()
VMiklos <vmiklos at frugalware.org>**20060117203214] {
hunk ./src/config/Makefile 1
-CFLAGS ?= -Wall -march=i686 -O2 -pipe
+CFLAGS ?= -g -Wall -march=i686 -O2 -pipe
hunk ./src/config/netconfig.c 43
+char *strtrim(char *str)
+{
+	char *ptr = str;
+
+	while(isspace(*ptr))
+		ptr++;
+	if(ptr != str)
+		memmove(str, ptr, (strlen(ptr) + 1));
+	ptr = (char *)(str + (strlen(str) - 1));
+	while(isspace(*ptr))
+		ptr--;
+	*++ptr = '\0';
+	return str;
+}
+
hunk ./src/config/netconfig.c 61
+	char line[PATH_MAX+1];
+	int n=0;
+	char *ptr = NULL;
+	char *var = NULL;
+	char interface[256] = "";
+	profile_t *profile;
+
+	profile = (profile_t*)malloc(sizeof(profile_t));
+	if(profile==NULL)
+		return(NULL);
+	memset(profile, 0, sizeof(profile_t));
hunk ./src/config/netconfig.c 73
-	fp = fopen(fn, "r");
+	ptr = g_strdup_printf("/etc/sysconfig/network/%s", fn);
+	fp = fopen(ptr, "r");
+	free(ptr);
hunk ./src/config/netconfig.c 77
+	{
+		printf("No such profile!\n");
hunk ./src/config/netconfig.c 80
+	}
+
+	while(fgets(line, PATH_MAX, fp))
+	{
+		n++;
+		strtrim(line);
+		if(strlen(line) == 0 || line[0] == '#')
+			continue;
+		printf("new line: %s\n", line);
+		if(line[0] == '[' && line[strlen(line)-1] == ']')
+		{
+			// new interface
+			ptr = line;
+			ptr++;
+			strncpy(interface, ptr, min(255, strlen(ptr)-1));
+			interface[min(255, strlen(ptr)-1)] = '\0';
+			if(!strlen(interface))
+			{
+				fprintf(stderr, "profile: line %d: bad interface name\n", n);
+				return(NULL);
+			}
+		}
+		line[0] = '\0';
+	}
hunk ./src/config/netconfig.c 155
-		init_dialog(input, dialog_state.output);
+		printf("no profile to load\n");
+		/*init_dialog(input, dialog_state.output);
hunk ./src/config/netconfig.c 158
-		end_dialog();
+		end_dialog();*/
}


More information about the Frugalware-darcs mailing list