Beispiel #1
0
void priority_handle_request (flux_t *h, struct queue *queue,
                              struct event_ctx *event_ctx,
                              const flux_msg_t *msg)
{
    uint32_t userid;
    uint32_t rolemask;
    flux_jobid_t id;
    struct job *job;
    int priority;
    const char *errstr = NULL;

    if (flux_request_unpack (msg, NULL, "{s:I s:i}",
                                        "id", &id,
                                        "priority", &priority) < 0
                    || flux_msg_get_userid (msg, &userid) < 0
                    || flux_msg_get_rolemask (msg, &rolemask) < 0)
        goto error;
    if (priority < FLUX_JOB_PRIORITY_MIN || priority > FLUX_JOB_PRIORITY_MAX) {
        errstr = "priority value is out of range";
        errno = EINVAL;
        goto error;
    }
    if (!(job = queue_lookup_by_id (queue, id))) {
        errstr = "unknown job";
        goto error;
    }
    /* Security: guests can only adjust jobs that they submitted.
     */
    if (!(rolemask & FLUX_ROLE_OWNER) && userid != job->userid) {
        errstr = "guests can only reprioritize their own jobs";
        errno = EPERM;
        goto error;
    }
    /* Security: guests can only reduce priority, or increase up to default.
     */
    if (!(rolemask & FLUX_ROLE_OWNER)
            && priority > MAXOF (FLUX_JOB_PRIORITY_DEFAULT, job->priority)) {
        errstr = "guests can only adjust priority <= default";
        errno = EPERM;
        goto error;
    }
    /* Post event, change job's queue position, and respond.
     */
    if (event_job_post_pack (event_ctx, job,
                             "priority",
                             "{ s:i s:i }",
                             "userid", userid,
                             "priority", priority) < 0)
        goto error;
    queue_reorder (queue, job, job->queue_handle);
    if (flux_respond (h, msg, NULL) < 0)
        flux_log_error (h, "%s: flux_respond", __FUNCTION__);
    return;
error:
    if (flux_respond_error (h, msg, errno, errstr) < 0)
        flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
}
Beispiel #2
0
static void ping_request_cb (flux_t *h, flux_msg_handler_t *mh,
                             const flux_msg_t *msg, void *arg)
{
    const char *json_str;
    char *route_str = NULL;
    char *full_route_str = NULL;
    char *resp_str = NULL;
    uint32_t rank, userid, rolemask;

    if (flux_request_decode (msg, NULL, &json_str) < 0)
        goto error;
    if (flux_msg_get_rolemask (msg, &rolemask) < 0)
        goto error;
    if (flux_msg_get_userid (msg, &userid) < 0)
        goto error;
    if (!(route_str = flux_msg_get_route_string (msg)))
        goto error;
    if (flux_get_rank (h, &rank) < 0)
        goto error;
    if (asprintf (&full_route_str, "%s!%u", route_str, rank) < 0) {
        errno = ENOMEM;
        goto error;
    }
    if (!(resp_str = make_json_response_payload (json_str, full_route_str,
                                                 userid, rolemask))) {
        goto error;
    }
    if (flux_respond (h, msg, resp_str) < 0)
        flux_log_error (h, "%s: flux_respond", __FUNCTION__);
    free (route_str);
    free (full_route_str);
    free (resp_str);
    return;
error:
    if (flux_respond_error (h, msg, errno, NULL) < 0)
        flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
    free (route_str);
    free (full_route_str);
    free (resp_str);
}
Beispiel #3
0
void pub_cb (flux_t *h, flux_msg_handler_t *mh,
             const flux_msg_t *msg, void *arg)
{
    struct publisher *pub = arg;
    const char *topic;
    const char *payload = NULL; // optional
    int flags;
    uint32_t rolemask, userid;
    flux_msg_t *event = NULL;

    if (flux_request_unpack (msg, NULL, "{s:s s:i s?:s}",
                                        "topic", &topic,
                                        "flags", &flags,
                                        "payload", &payload) < 0)
        goto error;
    if ((flags & ~(FLUX_MSGFLAG_PRIVATE)) != 0) {
        errno = EPROTO;
        goto error;
    }
    if (flux_msg_get_rolemask (msg, &rolemask) < 0)
        goto error;
    if (flux_msg_get_userid (msg, &userid) < 0)
        goto error;
    if (!(event = encode_event (topic, flags, rolemask, userid,
                                ++pub->seq, payload)))
        goto error_restore_seq;
    send_event (pub, event);
    if (flux_respond_pack (h, msg, "{s:i}", "seq", pub->seq) < 0)
        flux_log_error (h, "%s: flux_respond", __FUNCTION__);
    flux_msg_destroy (event);
    return;
error_restore_seq:
    pub->seq--;
error:
    if (flux_respond (h, msg, errno, NULL) < 0)
        flux_log_error (h, "%s: flux_respond", __FUNCTION__);
    flux_msg_destroy (event);
}