Esempio n. 1
0
static DBMeta *DBMetaNewDirect(const char *dbfilename)
{
    char hbuf[256];
    DBMeta *dbmeta = xcalloc(1, sizeof(*dbmeta));

    char *p = realpath(dbfilename, dbmeta->dbpath);
    if (p  == NULL ||
        -1 == (dbmeta->fd = open(dbmeta->dbpath, O_RDONLY)))
    {
        Log(LOG_LEVEL_ERR, "Failure opening file '%s' (%s: %s)",
            (p == NULL) ? dbfilename : dbmeta->dbpath,
            (p == NULL) ? "realpath" : "open",
            GetErrorStr());

        free(dbmeta);
        return NULL;
    }

    if (256 != read(dbmeta->fd, hbuf, 256))
    {
        Log(LOG_LEVEL_ERR, "Failure reading from database '%s'. (read: %s)",
                dbmeta->dbpath, GetErrorStr());
        close(dbmeta->fd);
        if (dbmeta)
        {
            free(dbmeta);
        }
        return NULL;
    }

    memcpy(&(dbmeta->bucket_count), hbuf + 40, sizeof(uint64_t));
    dbmeta->bucket_offset = 256;
    uint8_t opts;
    memcpy(&opts, hbuf + 36, sizeof(uint8_t));
    dbmeta->bytes_per =
        (opts & (1 << 0)) ? sizeof(uint64_t) : sizeof(uint32_t);

    memcpy(&(dbmeta->record_count), hbuf + 48, sizeof(uint64_t));
    memcpy(&(dbmeta->record_offset), hbuf + 64, sizeof(uint64_t));
    memcpy(&(dbmeta->alignment_pow), hbuf + 34, sizeof(uint8_t));
    dbmeta->offset_map = StringMapNew();
    dbmeta->record_map = StringMapNew();

    Log(LOG_LEVEL_VERBOSE, "Database            : %s", dbmeta->dbpath);
    Log(LOG_LEVEL_VERBOSE, "  number of buckets : %" PRIu64,
            dbmeta->bucket_count);
    Log(LOG_LEVEL_VERBOSE, "  offset of buckets : %" PRIu64,
            dbmeta->bucket_offset);
    Log(LOG_LEVEL_VERBOSE, "  bytes per pointer : %hd",
            dbmeta->bytes_per);
    Log(LOG_LEVEL_VERBOSE, "  alignment power   : %hd",
            dbmeta->alignment_pow);
    Log(LOG_LEVEL_VERBOSE, "  number of records : %" PRIu64,
            dbmeta->record_count);
    Log(LOG_LEVEL_VERBOSE, "  offset of records : %" PRIu64,
            dbmeta->record_offset);

    return dbmeta;
}
Esempio n. 2
0
void KeepPromises(EvalContext *ctx, const Policy *policy, GenericAgentConfig *config)
{
    if (paths_acl    != NULL || classes_acl != NULL || vars_acl    != NULL ||
        literals_acl != NULL || query_acl   != NULL || bundles_acl != NULL ||
        roles_acl    != NULL || SV.path_shortcuts != NULL)
    {
        UnexpectedError("ACLs are not NULL - we are probably leaking memory!");
    }

    paths_acl     = calloc(1, sizeof(*paths_acl));
    classes_acl   = calloc(1, sizeof(*classes_acl));
    vars_acl      = calloc(1, sizeof(*vars_acl));
    literals_acl  = calloc(1, sizeof(*literals_acl));
    query_acl     = calloc(1, sizeof(*query_acl));
    bundles_acl   = calloc(1, sizeof(*bundles_acl));
    roles_acl     = calloc(1, sizeof(*roles_acl));
    SV.path_shortcuts = StringMapNew();

    if (paths_acl    == NULL || classes_acl == NULL || vars_acl    == NULL ||
        literals_acl == NULL || query_acl   == NULL || bundles_acl == NULL ||
        roles_acl    == NULL || SV.path_shortcuts == NULL)
    {
        Log(LOG_LEVEL_CRIT, "calloc: %s", GetErrorStr());
        exit(255);
    }

    KeepControlPromises(ctx, policy, config);
    KeepPromiseBundles(ctx, policy);
}
Esempio n. 3
0
static void LoadPlatformExtraTable(void)
{
    if (UCB_PS_MAP)
    {
        return;
    }

    UCB_PS_MAP = StringMapNew();

    FILE *cmd = OpenUcbPsPipe();
    if (!cmd)
    {
        return;
    }
    ReadFromUcbPsPipe(cmd);
    if (cf_pclose(cmd) != 0)
    {
        Log(LOG_LEVEL_WARNING, "Command returned non-zero while gathering "
            "extra process information.");
        // Make an empty map, in this case. The information can't be trusted.
        StringMapClear(UCB_PS_MAP);
    }
}