コード例 #1
0
ファイル: tmunge.c プロジェクト: trws/flux-core
int main (int argc, char *argv[])
{
    int rc;
    zsock_t *zs;
    pthread_t tid;
    pthread_attr_t attr;
    flux_msg_t *msg;
    flux_sec_t *sec;
    int n;

    log_init (basename (argv[0]));

    if (argc != 1 && argc != 2) {
        fprintf (stderr, "Usage: tmunge [--fake]\n");
        exit (1);
    }
    if (argc == 2) {
        if (!strcmp (argv[1], "--fake"))
            sec_typemask |= FLUX_SEC_FAKEMUNGE;
        else
            log_msg_exit ("unknown option %s", argv[1]);
    }
    if (!(sec = flux_sec_create (sec_typemask, NULL)))
        log_err_exit ("flux_sec_create");
    if (flux_sec_comms_init (sec) < 0)
        log_err_exit ("flux_sec_comms_init: %s", flux_sec_errstr (sec));

    if (!(zs = zsock_new_sub (uri, "")))
        log_err_exit ("S: zsock_new_sub");

    if (!(cs = zsock_new_pub (uri)))
        log_err_exit ("S: zsock_new_pub");

    if ((rc = pthread_attr_init (&attr)))
        log_errn (rc, "S: pthread_attr_init");
    if ((rc = pthread_create (&tid, &attr, thread, NULL)))
        log_errn (rc, "S: pthread_create");

    /* Handle one client message.
     */
    if (!(msg = flux_msg_recvzsock_munge (zs, sec)))
        log_err_exit ("S: flux_msg_recvzsock_munge: %s", flux_sec_errstr (sec));
    //zmsg_dump (zmsg);
    if ((n = flux_msg_frames (msg)) != 4)
        log_err_exit ("S: expected 4 frames, got %d", n);
    flux_msg_destroy (msg);

    /* Wait for thread to terminate, then clean up.
     */
    if ((rc = pthread_join (tid, NULL)))
        log_errn (rc, "S: pthread_join");

    zsock_destroy (&zs);
    zsock_destroy (&cs);
    flux_sec_destroy (sec);

    log_fini ();

    return 0;
}
コード例 #2
0
ファイル: flux-keygen.c プロジェクト: surajpkn/flux-core
int main (int argc, char *argv[])
{
    int ch;
    flux_sec_t sec;
    bool force = false;
    bool plain = false;
    char *secdir;

    log_init ("flux-keygen");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'h': /* --help */
                usage ();
                break;
            case 'f': /* --force */
                force = true;
                break;
            case 'p': /* --plain */
                plain = true;
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind < argc)
        usage ();
    if (!(sec = flux_sec_create ()))
        err_exit ("flux_sec_create");
    if (!(secdir = getenv ("FLUX_SEC_DIRECTORY")))
        msg_exit ("FLUX_SEC_DIRECTORY is not set");
    flux_sec_set_directory (sec, secdir);
    if (plain && flux_sec_enable (sec, FLUX_SEC_TYPE_PLAIN) < 0)
        msg_exit ("PLAIN security is not available");
    if (flux_sec_keygen (sec, force, true) < 0)
        msg_exit ("%s", flux_sec_errstr (sec));
    flux_sec_destroy (sec);

    log_fini ();

    return 0;
}
コード例 #3
0
ファイル: tmunge.c プロジェクト: trws/flux-core
void *thread (void *arg)
{
    flux_msg_t *msg;
    flux_sec_t *sec;
    int n;

    if (!(sec = flux_sec_create (sec_typemask, NULL)))
        log_err_exit ("C: flux_sec_create");
    if (flux_sec_comms_init (sec) < 0)
        log_err_exit ("C: flux_sec_comms_init: %s", flux_sec_errstr (sec));
    if (!(msg = flux_event_encode ("foo.topic", "{\"foo\":42}")))
        log_err_exit ("C: flux_event_encode");
    if ((n = flux_msg_frames (msg)) != 4)
        log_err_exit ("C: expected 4 frames, got %d", n);
    if (flux_msg_sendzsock_munge (cs, msg, sec) < 0)
        log_err_exit ("C: flux_msg_sendzsock_munge");
    flux_msg_destroy (msg);
    flux_sec_destroy (sec);

    return NULL;
}