diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-20 17:48:59 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-20 17:48:59 +0000 |
commit | a34f1ed737e79e494904706e59f4e7fbb49e32b3 (patch) | |
tree | 9c84f928e785775d99163b7de5c29e6f85a0fc8c | |
parent | 1e8034e61432cb3bd4bde1d7a13e809543a1e239 (diff) | |
download | busybox-w32-a34f1ed737e79e494904706e59f4e7fbb49e32b3.tar.gz busybox-w32-a34f1ed737e79e494904706e59f4e7fbb49e32b3.tar.bz2 busybox-w32-a34f1ed737e79e494904706e59f4e7fbb49e32b3.zip |
dnsd,sestatus: use libbb to parse config file (by Vladimir)
function old new delta
dnsd_main 1544 1487 -57
-rw-r--r-- | networking/dnsd.c | 92 | ||||
-rw-r--r-- | selinux/sestatus.c | 26 |
2 files changed, 38 insertions, 80 deletions
diff --git a/networking/dnsd.c b/networking/dnsd.c index 8512f0ceb..0047a8445 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c | |||
@@ -102,74 +102,46 @@ static void undot(uint8_t * rip) | |||
102 | } | 102 | } |
103 | 103 | ||
104 | /* | 104 | /* |
105 | * Read one line of hostname/IP from file | ||
106 | * Returns 0 for each valid entry read, -1 at EOF | ||
107 | * Assumes all host names are lower case only | ||
108 | * Hostnames with more than one label are not handled correctly. | ||
109 | * Presently the dot is copied into name without | ||
110 | * converting to a length/string substring for that label. | ||
111 | */ | ||
112 | static int getfileentry(FILE *fp, struct dns_entry *s) | ||
113 | { | ||
114 | unsigned int a,b,c,d; | ||
115 | char *line, *r, *name; | ||
116 | |||
117 | restart: | ||
118 | line = r = xmalloc_fgets(fp); | ||
119 | if (!r) | ||
120 | return -1; | ||
121 | while (*r == ' ' || *r == '\t') { | ||
122 | r++; | ||
123 | if (!*r || *r == '#' || *r == '\n') { | ||
124 | free(line); | ||
125 | goto restart; /* skipping empty/blank and commented lines */ | ||
126 | } | ||
127 | } | ||
128 | name = r; | ||
129 | while (*r != ' ' && *r != '\t') | ||
130 | r++; | ||
131 | *r++ = '\0'; | ||
132 | if (sscanf(r, ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4) { | ||
133 | free(line); | ||
134 | goto restart; /* skipping wrong lines */ | ||
135 | } | ||
136 | |||
137 | sprintf(s->ip, ".%u.%u.%u.%u"+1, a, b, c, d); | ||
138 | sprintf(s->rip, ".%u.%u.%u.%u", d, c, b, a); | ||
139 | undot((uint8_t*)s->rip); | ||
140 | convname(s->name, (uint8_t*)name); | ||
141 | |||
142 | if (OPT_verbose) | ||
143 | fprintf(stderr, "\tname:%s, ip:%s\n", &(s->name[1]),s->ip); | ||
144 | |||
145 | free(line); | ||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | /* | ||
150 | * Read hostname/IP records from file | 105 | * Read hostname/IP records from file |
151 | */ | 106 | */ |
152 | static void dnsentryinit(void) | 107 | static void dnsentryinit(void) |
153 | { | 108 | { |
154 | FILE *fp; | 109 | parser_t *parser; |
155 | struct dns_entry *m, *prev; | 110 | struct dns_entry *m, *prev; |
156 | 111 | ||
157 | prev = dnsentry = NULL; | 112 | prev = dnsentry = NULL; |
158 | fp = xfopen(fileconf, "r"); | 113 | parser = config_open(fileconf); |
159 | 114 | if (parser) { | |
160 | while (1) { | 115 | char *token[2]; |
161 | m = xzalloc(sizeof(*m)); | 116 | while (config_read(parser, token, 2, 0, "# \t", 0)) { |
162 | /*m->next = NULL;*/ | 117 | unsigned int a,b,c,d; |
163 | if (getfileentry(fp, m)) | 118 | /* |
164 | break; | 119 | * Assumes all host names are lower case only |
165 | 120 | * Hostnames with more than one label are not handled correctly. | |
166 | if (prev == NULL) | 121 | * Presently the dot is copied into name without |
167 | dnsentry = m; | 122 | * converting to a length/string substring for that label. |
168 | else | 123 | */ |
169 | prev->next = m; | 124 | if (!token[1] || sscanf(token[1], ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4) |
170 | prev = m; | 125 | continue; |
126 | |||
127 | m = xzalloc(sizeof(*m)); | ||
128 | /*m->next = NULL;*/ | ||
129 | sprintf(m->ip, ".%u.%u.%u.%u"+1, a, b, c, d); | ||
130 | sprintf(m->rip, ".%u.%u.%u.%u", d, c, b, a); | ||
131 | undot((uint8_t*)m->rip); | ||
132 | convname(m->name, (uint8_t*)token[0]); | ||
133 | |||
134 | if (OPT_verbose) | ||
135 | fprintf(stderr, "\tname:%s, ip:%s\n", &(m->name[1]), m->ip); | ||
136 | |||
137 | if (prev == NULL) | ||
138 | dnsentry = m; | ||
139 | else | ||
140 | prev->next = m; | ||
141 | prev = m; | ||
142 | } | ||
143 | config_close(parser); | ||
171 | } | 144 | } |
172 | fclose(fp); | ||
173 | } | 145 | } |
174 | 146 | ||
175 | /* | 147 | /* |
diff --git a/selinux/sestatus.c b/selinux/sestatus.c index 3b027eeb2..1351600c8 100644 --- a/selinux/sestatus.c +++ b/selinux/sestatus.c | |||
@@ -47,31 +47,17 @@ static void display_boolean(void) | |||
47 | 47 | ||
48 | static void read_config(char **pc, int npc, char **fc, int nfc) | 48 | static void read_config(char **pc, int npc, char **fc, int nfc) |
49 | { | 49 | { |
50 | char buf[256]; | 50 | char *buf; |
51 | FILE *fp; | 51 | parser_t *parser; |
52 | int pc_ofs = 0, fc_ofs = 0, section = -1; | 52 | int pc_ofs = 0, fc_ofs = 0, section = -1; |
53 | 53 | ||
54 | pc[0] = fc[0] = NULL; | 54 | pc[0] = fc[0] = NULL; |
55 | 55 | ||
56 | fp = fopen("/etc/sestatus.conf", "rb"); | 56 | parser = config_open("/etc/sestatus.conf"); |
57 | if (fp == NULL) | 57 | if (!parser) |
58 | return; | 58 | return; |
59 | 59 | ||
60 | while (fgets(buf, sizeof(buf), fp) != NULL) { | 60 | while (config_read(parser, &buf, 1, 1, "# \t", PARSE_LAST_IS_GREEDY)) { |
61 | int i, c; | ||
62 | |||
63 | /* kills comments */ | ||
64 | for (i = 0; (c = buf[i]) != '\0'; i++) { | ||
65 | if (c == '#') { | ||
66 | buf[i] = '\0'; | ||
67 | break; | ||
68 | } | ||
69 | } | ||
70 | trim(buf); | ||
71 | |||
72 | if (buf[0] == '\0') | ||
73 | continue; | ||
74 | |||
75 | if (strcmp(buf, "[process]") == 0) { | 61 | if (strcmp(buf, "[process]") == 0) { |
76 | section = 1; | 62 | section = 1; |
77 | } else if (strcmp(buf, "[files]") == 0) { | 63 | } else if (strcmp(buf, "[files]") == 0) { |
@@ -86,7 +72,7 @@ static void read_config(char **pc, int npc, char **fc, int nfc) | |||
86 | } | 72 | } |
87 | } | 73 | } |
88 | } | 74 | } |
89 | fclose(fp); | 75 | config_close(parser); |
90 | } | 76 | } |
91 | 77 | ||
92 | static void display_verbose(void) | 78 | static void display_verbose(void) |