summaryrefslogtreecommitdiff
path: root/hostfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'hostfile.c')
-rw-r--r--hostfile.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/hostfile.c b/hostfile.c
index 29efe5656..e1c2429bd 100644
--- a/hostfile.c
+++ b/hostfile.c
@@ -14,7 +14,7 @@
14 */ 14 */
15 15
16#include "includes.h" 16#include "includes.h"
17RCSID("$OpenBSD: hostfile.c,v 1.16 2000/04/14 10:30:31 markus Exp $"); 17RCSID("$OpenBSD: hostfile.c,v 1.17 2000/04/26 20:56:29 markus Exp $");
18 18
19#include "packet.h" 19#include "packet.h"
20#include "match.h" 20#include "match.h"
@@ -39,13 +39,8 @@ hostfile_read_key(char **cpp, unsigned int *bitsp, Key *ret)
39 for (cp = *cpp; *cp == ' ' || *cp == '\t'; cp++) 39 for (cp = *cpp; *cp == ' ' || *cp == '\t'; cp++)
40 ; 40 ;
41 41
42 /* Get number of bits. */ 42 bits = key_read(ret, &cp);
43 if (*cp < '0' || *cp > '9') 43 if (bits == 0)
44 return 0; /* Bad bit count... */
45 for (bits = 0; *cp >= '0' && *cp <= '9'; cp++)
46 bits = 10 * bits + *cp - '0';
47
48 if (!key_read(ret, bits, &cp))
49 return 0; 44 return 0;
50 45
51 /* Skip trailing whitespace. */ 46 /* Skip trailing whitespace. */
@@ -182,24 +177,18 @@ add_host_to_hostfile(const char *filename, const char *host, Key *key)
182{ 177{
183 FILE *f; 178 FILE *f;
184 int success = 0; 179 int success = 0;
185
186 if (key == NULL) 180 if (key == NULL)
187 return 1; 181 return 1; /* XXX ? */
188
189 /* Open the file for appending. */
190 f = fopen(filename, "a"); 182 f = fopen(filename, "a");
191 if (!f) 183 if (!f)
192 return 0; 184 return 0;
193
194 fprintf(f, "%s ", host); 185 fprintf(f, "%s ", host);
195 if (key_write(key, f)) { 186 if (key_write(key, f)) {
196 fprintf(f, "\n");
197 success = 1; 187 success = 1;
198 } else { 188 } else {
199 error("add_host_to_hostfile: saving key failed"); 189 error("add_host_to_hostfile: saving key in %s failed", filename);
200 } 190 }
201 191 fprintf(f, "\n");
202 /* Close the file. */
203 fclose(f); 192 fclose(f);
204 return success; 193 return success;
205} 194}