Пример #1
0
/* For debugging, mainly.
   We print the tree with the head node unnumbered
   and the root node called level 0.
   In Knuth algorithms where we have p[k] when
   k is zero k refers to the head node.   Handy
   as then the root node is not special at all.
   But here it just looks better as shown, perhaps.

   The ordering here is so that if you turned an output
   page with the left side at the top
   then the tree sort of just shows up nicely in
   what most think of as a normal way.
*/
static void
tdump_inner(struct ts_entry *t,
    char *(keyprint)(const void *),
    const char *descr, int level)
{
    char * keyv = "";
    if(!t) {
        return;
    }
    tdump_inner(t->rlink,keyprint,"right",level+1);

    printlevel(level);
    if(t->keyptr) {
        keyv = keyprint(t->keyptr);
    }
    printf("0x%08lx <keyptr 0x%08lx> <%s %s> <bal %3d> <l 0x%08lx> <r 0x%08lx> %s\n",
        (unsigned long)t,
        (unsigned long)t->keyptr,
        t->keyptr?"key ":"null",
        keyv,
        t->balance,
        (unsigned long)t->llink,(unsigned long)t->rlink,
        descr);
    tdump_inner(t->llink,keyprint,"left ",level+1);
}
Пример #2
0
void draw_top_menu(WINDOW *local_win, const char *title, int key_n,
        const char **keys, int cmd_n, const char **cmds)
{
    int pos = 2, i = 0;

    vrmr_fatal_if(key_n != cmd_n);

    werase(local_win);

    /* draw the box and the title */
    wattron(local_win, vccnf.color_bgd);
    box(local_win, 0, 0);
    menunameprint(local_win, title);
    wattroff(local_win, vccnf.color_bgd);

    for (i = 0; i < key_n; i++) {
        pos = keyprint(local_win, 1, pos, keys[i], cmds[i]);
        if (pos <= 0)
            break;
    }

    setup_topmenu(local_win);
    update_panels();
    doupdate();
}
Пример #3
0
static int
key_print_wrapper(struct sshkey *hostkey, struct ssh *ssh)
{
	con *c;

	if ((c = ssh_get_app_data(ssh)) != NULL)
		keyprint(c, hostkey);
	/* always abort key exchange */
	return -1;
}
Пример #4
0
static void print_entry(struct ts_entry *t,const char *descr,
                        char *(* keyprint)(const void *),
                        unsigned long hashpos,
                        unsigned long chainpos)
{
    char *v = 0;
    if(!t->entryused) {
        return;
    }
    v = keyprint(t->keyptr);
    printf(
        "[%4lu.%02lu] 0x%08x <keyptr 0x%08x> <key %s> %s\n",
        hashpos,chainpos,
        (unsigned)t,
        (unsigned)t->keyptr,
        v,
        descr);
}
Пример #5
0
static void
conread(int s)
{
	con *c = &fdcon[s];
	size_t n;

	if (c->c_status == CS_CON) {
		congreet(s);
		return;
	}
	n = atomicio(read, s, c->c_data + c->c_off, c->c_len - c->c_off);
	if (n == 0) {
		error("read (%s): %s", c->c_name, strerror(errno));
		confree(s);
		return;
	}
	c->c_off += n;

	if (c->c_off == c->c_len)
		switch (c->c_status) {
		case CS_SIZE:
			c->c_plen = htonl(c->c_plen);
			c->c_len = c->c_plen + 8 - (c->c_plen & 7);
			c->c_off = 0;
			c->c_data = xmalloc(c->c_len);
			c->c_status = CS_KEYS;
			break;
#ifdef WITH_SSH1
		case CS_KEYS:
			keyprint(c, keygrab_ssh1(c));
			confree(s);
			return;
#endif
		default:
			fatal("conread: invalid status %d", c->c_status);
			break;
		}

	contouch(s);
}
Пример #6
0
/* For debugging. This prints the nodes with the parent (in each case)
   in between the children.  So it is a tree with root at the left. */
static void
dumptree_inner(const struct ts_entry *t,
    char *(* keyprint)(const void *),
    const char *descr, int level)
{
    char *v = "";
    if(!t) {
        return;
    }
    dumptree_inner(t->rlink,keyprint,"left ",level+1);
    if(t->keyptr) {
        v = keyprint(t->keyptr);
    }
    printlevel(level);
    printf("0x%08x <keyptr 0x%08x> <%s %s> <l 0x%08x> <r 0x%08x> %s\n",
        (unsigned)t,
        (unsigned)t->keyptr,
        t->keyptr?"key ":"null",
        v,
        (unsigned)t->llink,(unsigned)t->rlink,
        descr);
    dumptree_inner(t->llink,keyprint,"right",level+1);
}
Пример #7
0
static void
congreet(int s)
{
    int n = 0, remote_major = 0, remote_minor = 0;
    char buf[256], *cp;
    char remote_version[sizeof buf];
    size_t bufsiz;
    con *c = &fdcon[s];

    for (;;) {
        memset(buf, '\0', sizeof(buf));
        bufsiz = sizeof(buf);
        cp = buf;
        while (bufsiz-- &&
                (n = atomicio(read, s, cp, 1)) == 1 && *cp != '\n') {
            if (*cp == '\r')
                *cp = '\n';
            cp++;
        }
        if (n != 1 || strncmp(buf, "SSH-", 4) == 0)
            break;
    }
    if (n == 0) {
        switch (errno) {
        case EPIPE:
            error("%s: Connection closed by remote host", c->c_name);
            break;
        case ECONNREFUSED:
            break;
        default:
            error("read (%s): %s", c->c_name, strerror(errno));
            break;
        }
        conrecycle(s);
        return;
    }
    if (*cp != '\n' && *cp != '\r') {
        error("%s: bad greeting", c->c_name);
        confree(s);
        return;
    }
    *cp = '\0';
    if (sscanf(buf, "SSH-%d.%d-%[^\n]\n",
               &remote_major, &remote_minor, remote_version) == 3)
        compat_datafellows(remote_version);
    else
        datafellows = 0;
    if (c->c_keytype != KT_RSA1) {
        if (!ssh2_capable(remote_major, remote_minor)) {
            debug("%s doesn't support ssh2", c->c_name);
            confree(s);
            return;
        }
    } else if (remote_major != 1) {
        debug("%s doesn't support ssh1", c->c_name);
        confree(s);
        return;
    }
    fprintf(stderr, "# %s %s\n", c->c_name, chop(buf));
    n = snprintf(buf, sizeof buf, "SSH-%d.%d-OpenSSH-keyscan\r\n",
                 c->c_keytype == KT_RSA1? PROTOCOL_MAJOR_1 : PROTOCOL_MAJOR_2,
                 c->c_keytype == KT_RSA1? PROTOCOL_MINOR_1 : PROTOCOL_MINOR_2);
    if (n < 0 || (size_t)n >= sizeof(buf)) {
        error("snprintf: buffer too small");
        confree(s);
        return;
    }
    if (atomicio(vwrite, s, buf, n) != (size_t)n) {
        error("write (%s): %s", c->c_name, strerror(errno));
        confree(s);
        return;
    }
    if (c->c_keytype != KT_RSA1) {
        keyprint(c, keygrab_ssh2(c));
        confree(s);
        return;
    }
    c->c_status = CS_SIZE;
    contouch(s);
}