Пример #1
0
int
replay_remove (munge_cred_t c)
{
/*  Removes the credential [c] from the replay hash.
 */
    m_msg_t           m = c->msg;
    union replay_key  rkey_st;
    replay_t          rkey = &rkey_st;
    replay_t          r;

    if (!replay_hash) {
        if (conf->got_benchmark)
            return (0);
        errno = EPERM;
        return (-1);
    }
    /*  Compute the cred's "hash key".
     */
    rkey->data.t_expired = (time_t) (m->time0 + m->ttl);
    assert (c->mac_len >= sizeof (rkey->data.mac));
    memcpy (rkey->data.mac, c->mac, sizeof (rkey->data.mac));

    if ((r = hash_remove (replay_hash, rkey))) {
        replay_free (r);
    }
    return (r ? 0 : -1);
}
Пример #2
0
void nes_free(NES *nes)
{
    // disable ndb debugging will make cpu keep running
    ndb_set_debug(&(nes->ndb), NDB_DEBUG_MODE_DISABLE);

    // destroy nes thread
    nes->thread_exit = TRUE;
    pthread_join(nes->thread_id, NULL);

    // free replay
    replay_free(&(nes->replay));

    // free joypad
    joypad_setkey(&(nes->pad), 0, NES_PAD_CONNECT, 0);
    joypad_setkey(&(nes->pad), 1, NES_PAD_CONNECT, 0);
    joypad_free  (&(nes->pad ));

    // free cpu & ppu & apu & mmc
    cpu_free(&(nes->cpu));
    ppu_free(&(nes->ppu));
    apu_free(&(nes->apu));
    mmc_free(&(nes->mmc));
    ndb_free(&(nes->ndb));

    // free cartridge
    cartridge_free(&(nes->cart));

    log_done(); // log done
}
Пример #3
0
int
replay_insert (munge_cred_t c)
{
/*  Inserts the credential [c] into the replay hash.
 *    The credential is identified by the first N bytes of the MAC, where N
 *    is the minimum message digest length used by MUNGE.  Limiting the MAC
 *    length here helps to reduce the replay cache memory requirements.
 *  Returns 0 if the credential is successfully inserted.
 *    Returns 1 if the credential is already present (ie, replay).
 *    Returns -1 on error with errno set.
 */
    m_msg_t   m = c->msg;
    int       e;
    replay_t  r;

    if (!replay_hash) {
        if (conf->got_benchmark)
            return (0);
        errno = EPERM;
        return (-1);
    }
    if (!(r = replay_alloc ())) {
        return (-1);
    }
    r->data.t_expired = (time_t) (m->time0 + m->ttl);
    assert (c->mac_len >= sizeof (r->data.mac));
    memcpy (r->data.mac, c->mac, sizeof (r->data.mac));
    /*
     *  The replay hash key is just the replay struct itself.
     */
    if (hash_insert (replay_hash, r, r) != NULL) {
        return (0);
    }
    e = errno;
    replay_free (r);

    if (e == EEXIST) {
        return (1);
    }
    if (e == EINVAL) {
        log_err (EMUNGE_SNAFU, LOG_ERR,
            "Attempted to insert cred into hash using invalid args");
    }
    return (-1);
}