commit - 50f036824c2c9c860754f608c478c909642bdab1
commit + eb722b5028dcd686244ecbca2ff4bfb0a29a6c68
blob - 5e8a17493f800dd8c5af5c9850a5bfbcd2655d9d
blob + 065cde90fd716f1acebd322bf4634a731e031b5a
--- fs.c
+++ fs.c
static void mkdirs(const char*, mode_t);
static void xdg_init(void);
static void load_last_session(void);
+static void load_certs(void);
static struct imsgev *iev_ui;
static FILE *session;
{
switch (imsg->hdr.type) {
case IMSG_INIT:
+ load_certs();
load_last_session();
break;
return ap == &tmp[3] && *line == '\0';
}
-int
-load_certs(struct ohash *h)
+static void
+load_certs(void)
{
char *tmp[3], *line = NULL;
const char *errstr;
size_t lineno = 0, linesize = 0;
ssize_t linelen;
FILE *f;
- struct tofu_entry *e;
+ struct tofu_entry e;
if ((f = fopen(known_hosts_file, "r")) == NULL)
- return 0;
+ return;
while ((linelen = getline(&line, &linesize, f)) != -1) {
- if ((e = calloc(1, sizeof(*e))) == NULL)
- abort();
-
lineno++;
- if (parse_khost_line(line, tmp)) {
- strlcpy(e->domain, tmp[0], sizeof(e->domain));
- strlcpy(e->hash, tmp[1], sizeof(e->hash));
+ memset(&e, 0, sizeof(e));
+ if (parse_khost_line(line, tmp)) {
+ strlcpy(e.domain, tmp[0], sizeof(e.domain));
+ strlcpy(e.hash, tmp[1], sizeof(e.hash));
- e->verified = strtonum(tmp[2], 0, 1, &errstr);
+ e.verified = strtonum(tmp[2], 0, 1, &errstr);
if (errstr != NULL)
errx(1, "%s:%zu verification for %s is %s: %s",
known_hosts_file, lineno,
- e->domain, errstr, tmp[2]);
- tofu_add(h, e);
+ e.domain, errstr, tmp[2]);
+
+ fs_send_ui(IMSG_TOFU, 0, -1, &e, sizeof(e));
} else {
warnx("%s:%zu invalid entry",
known_hosts_file, lineno);
- free(e);
}
}
free(line);
- return ferror(f);
+ fclose(f);
+ return;
}
blob - 5e48fbdecfc07b88e66e1a9d8d9e1db284fa8ffd
blob + 7f07e22acf62c3676335e7e4fc7795b4ac8f2fa8
--- fs.h
+++ fs.h
int fs_main(void);
int last_time_crashed(void);
int lock_session(void);
-int load_certs(struct ohash *);
#endif
blob - 0d06700ce88a704696aab7f7a764ba1ac8ff670b
blob + 9c81b8fbd2cbbad08aa49c3f9bdd02cc73516ecf
--- telescope.c
+++ telescope.c
static void handle_imsg_file_opened(struct imsg *, size_t);
static void handle_imsg_buf(struct imsg *, size_t);
static void handle_imsg_eof(struct imsg *, size_t);
+static void handle_imsg_tofu(struct imsg *, size_t);
static void handle_imsg_bookmark_ok(struct imsg *, size_t);
static void handle_imsg_save_cert_ok(struct imsg *, size_t);
static void handle_imsg_update_cert_ok(struct imsg *, size_t);
[IMSG_GOT_META] = handle_imsg_got_meta,
[IMSG_BUF] = handle_imsg_buf,
[IMSG_EOF] = handle_imsg_eof,
+ [IMSG_TOFU] = handle_imsg_tofu,
[IMSG_BOOKMARK_OK] = handle_imsg_bookmark_ok,
[IMSG_SAVE_CERT_OK] = handle_imsg_save_cert_ok,
[IMSG_UPDATE_CERT_OK] = handle_imsg_update_cert_ok,
}
static void
+handle_imsg_tofu(struct imsg *imsg, size_t datalen)
+{
+ struct tofu_entry *e;
+
+ if (operating)
+ die();
+
+ if ((e = calloc(1, sizeof(*e))) == NULL)
+ die();
+
+ if (datalen != sizeof(*e))
+ die();
+ memcpy(e, imsg->data, sizeof(*e));
+ if (e->domain[sizeof(e->domain)-1] != '\0' ||
+ e->hash[sizeof(e->hash)-1] != '\0')
+ die();
+ tofu_add(&certs, e);
+}
+
+static void
handle_imsg_bookmark_ok(struct imsg *imsg, size_t datalen)
{
int res;
setproctitle("ui");
- /* initialize tofu & load certificates */
+ /* initialize tofu store */
tofu_init(&certs, 5, offsetof(struct tofu_entry, domain));
- load_certs(&certs);
event_init();
blob - 1755f633562bf7c0c8bfeeea22085afc9ce45b1c
blob + 1cb51617e81908a9f7c4f87713bf8de8bc19c253
--- telescope.h
+++ telescope.h
/* ui <-> fs */
IMSG_INIT,
+ IMSG_TOFU,
IMSG_BOOKMARK_PAGE,
IMSG_BOOKMARK_OK,
IMSG_SAVE_CERT,