Ejemplo n.º 1
0
/**
 * main
 */
int main(int argc, char *argv[]) {
    int rc = -1;
    int c;
    OPENPTS_FSM_CONTEXT *ctx;
    char *input_filename = NULL;
    char *output_filename = NULL;

    /* logging/NLS */
    initCatalog();

    while ((c = getopt(argc, argv, "do:h")) != EOF) {
        switch (c) {
        case 'd':
            setVerbosity(1);
            break;
        case 'o':
            output_filename = optarg;
            break;
        case 'h':
            /* fall through */
        default:
            usage();
            return -1;
        }
    }
    argc -= optind;
    argv += optind;
    input_filename = argv[0];

    /* Read UML(XML) file */
    if (input_filename == NULL) {
        ERROR(NLS(MS_OPENPTS, OPENPTS_UML2DOT_MISSING_XML_FILE, "ERROR missing XMLfile\n"));
        usage();
        return -1;
    }

    /* read UML(XML) */
    ctx = newFsmContext();
    rc = readUmlModel(ctx, argv[0]);

    if (rc != 0) {
        LOG(LOG_ERR, "ERROR\n");
        goto error;
    }

    /* Gen DOT file */
    rc = writeDotModel(ctx, output_filename);

    if (rc != 0) {
        LOG(LOG_ERR, "ERROR\n");
        goto error;
    }

  error:
    freeFsmContext(ctx);

    return rc;
}
Ejemplo n.º 2
0
/*
 * Find requested VSN info structure in the VSN table.
 */
VsnInfo_t *
FindVsn(
    vsn_t vsn,
    media_t media)
{
    VsnInfo_t *vi = NULL;
    LibraryInfo_t *lib;
    int i;
    boolean_t first;

    first = B_TRUE;		/* first search */
    ReconfigLock();		/* wait on reconfig */

    if (vsnTable.catalog == B_TRUE &&
            removableMediaFound == B_TRUE && CatalogSync() > 0) {
        Trace(TR_MISC, "Catalog invalid");
        vsnTable.catalog = B_FALSE;
        CatalogTerm();		/* remove mapped catalog table */
    }

    if (vsnTable.catalog == B_FALSE) {
        if (initCatalog() == 0) {
            Trace(TR_DEBUG, "Catalog initialized");
        }
        initVsnTable();
    }

    /*
     * Check for disk or honyecomb archive.
     */
    if (IS_DISKARCHIVE_MEDIA(media)) {
        vi = getDiskLibraryVsn(media, vsn);
        ReconfigUnlock();
        return (vi);
    }

    /*
     * File is on tape.
     */
retrySearch:

    for (i = 0; i < vsnTable.entries; i++) {

        lib = &libraryTable.data[vsnTable.data[i].lib];
        if (IS_LIB_MANUAL(lib)) {
            /*
             * Get VSN from manual drive.
             */
            getManualVsn(&driveTable.data[lib->li_manual],
                         &vsnTable.data[i]);
        } else {
            /*
             * Get VSN managed in library.
             */
            if ((strcmp(vsn, vsnTable.data[i].ce->CeVsn) == 0) &&
                    (media ==
                     sam_atomedia(vsnTable.data[i].ce->CeMtype))) {
                getLibraryVsn(vsnTable.data[i].ce,
                              &vsnTable.data[i]);
            }
        }

        if ((strcmp(vsn, vsnTable.data[i].vsn) == 0) &&
                (media == vsnTable.data[i].media)) {
            /*
             * Found VSN.
             */
            vi = &vsnTable.data[i];
            if (vi->ce != NULL) {
                /*
                 * VSN in library.  Check if VSN has moved
                 * .ie imported or exported.
                 */
                struct CatalogEntry *ce;
                LibraryInfo_t *lib;

                ce = vi->ce;
                lib = &libraryTable.data[vi->lib];

                if (ce->CeEq != lib->li_eq) {
                    int i;

                    for (i = 0; i < libraryTable.entries;
                            i++) {
                        lib = &libraryTable.data[i];
                        if (ce->CeEq == lib->li_eq) {
                            vi->lib = i;
                            break;
                        }
                    }
                }
            }
            break;
        }
    }

    /*
     * If a removable media volume was not found, check if it exists in
     * catserver's catalog.  There are changes (.eg import, export,
     * relabel) that may result in the stager vsntable being out of date.
     * If found in the catalog, reinitialize the vsntable and search again.
     */
    if (vi == NULL && IS_RMARCHIVE_MEDIA(media) && first == B_TRUE) {
        struct CatalogEntry ced, *ce;

        first = B_FALSE;
        ce = CatalogGetCeByMedia(sam_mediatoa(media), vsn, &ced);

        if (ce != NULL) {
            /*
             * Volume found in catserver's memory mapped file.
             * Reinitialize the vsntable and search again.
             */
            initVsnTable();
            goto retrySearch;
        }
    }

    ReconfigUnlock();	/* allow reconfig */

    return (vi);
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
    int rc = 0;
    char *ir_filename = NULL;
    char *out_filename = NULL;
    char *pcrout_filename = NULL;
    int c;
    IR_CONTEXT *ctx;

    initCatalog();

    resetPcr();

    ctx = xmalloc(sizeof(IR_CONTEXT));
    ctx = (IR_CONTEXT *) xmalloc(sizeof(IR_CONTEXT));
    if (ctx == NULL) {
        return -1;
    }
    memset(ctx, 0, sizeof(IR_CONTEXT));

    ctx->buf = xmalloc(EVENTDATA_BUF_SIZE);
    if (ctx->buf == NULL) {
        xfree(ctx);
        return -1;
    }


    ctx->fp = stdout;

    /* Args */
    while ((c = getopt(argc, argv, "i:o:P:bEAdh")) != EOF) {
        switch (c) {
        case 'i':
            ir_filename = optarg;
            break;
        case 'o':
            out_filename = optarg;
            break;
        case 'P':
            pcrout_filename = optarg;
            break;
        case 'b':  /* Binary mode  */
            ctx->binary = 1;
            break;
        case 'E':  /* Enable Endian Conversion */
            // DEBUG("enable endian conversion\n");
            ctx->endian = 1;
            break;
        case 'A':  /*  four byte aligned event data */
            ctx->aligned = 4;
            break;
        case 'd':  /* DEBUG */
            setDebugFlags(DEBUG_FLAG);
            break;
        case 'h':
            usage();
            return 0;
        default:
            ERROR(NLS(MS_OPENPTS, OPENPTS_IR2TEXT_BAD_OPTION_C,
                "bad option %c\n"), c);
            usage();
            return -1;
        }
    }
    argc -= optind;
    argv += optind;

    /* check  */
    if (ctx->binary == 0) {
        /* print IR in plain text */
        DEBUG("ir2text - plain text mode\n");

        if (out_filename != NULL) {
            /* open output file */
            ctx->fp = fopen(out_filename, "w");
            if (ctx->fp == NULL) {
                LOG(LOG_ERR, "output file %s - open failed\n", out_filename);
                return rc;
            }
        }
    } else {
        /* print IR in binary text, with -o option */
        if (out_filename == NULL) {
            ERROR(NLS(MS_OPENPTS, OPENPTS_IR2TEXT_OUTPUT_BINARY_MODE,
                "set the output file for the binary mode\n"));
            usage();
            return -1;
        }
        DEBUG("ir2text - binary mode (IR -> IML)\n");

        /* open output file */
        ctx->fp = fopen(out_filename, "wb");
        if (ctx->fp == NULL) {
            LOG(LOG_ERR, "output file %s - open failed\n", out_filename);
            return rc;
        }
    }

    /* read IR and gen output */
    rc = readIr(ctx, ir_filename);

    /* close output file */
    if (out_filename != NULL) {
        /* close output file */
        fclose(ctx->fp);
    }

    /* PCR output*/
    // PCR-00: 8F BF F3 EC EA 9C 54 C8 D1 C4 2C FE A9 3D 6B F0 1B F3 40 5B
    if (pcrout_filename != NULL) {
        FILE *fp;
        int i, j;
        LOG(LOG_TODO, "pcrout_filename = %s\n", pcrout_filename);

        /* open output file */
        fp = fopen(pcrout_filename, "w");
        if (fp == NULL) {
            LOG(LOG_ERR, "PCR output file %s - open failed\n", pcrout_filename);
            return -1;
        }

        for (i = 0; i < MAX_PCRNUM; i++) {
            fprintf(fp, "PCR-%02d:", i);
            for (j = 0; j < SHA1_DIGEST_SIZE; j++) {
                fprintf(fp, " %02X", pcr[i][j]);
            }
            fprintf(fp, "\n");
        }
        fclose(fp);
    }
    return rc;
}