Пример #1
0
globus_fifo_t *
globus_fifo_copy (
    const globus_fifo_t *                                 fifo)
{
    globus_fifo_t *                                 copy;
    struct globus_fifo_s *                          s_copy;
    struct globus_fifo_s *                          s_fifo;

    if (fifo == GLOBUS_NULL) 
		return NULL;
    s_fifo = *fifo;
    if(s_fifo==GLOBUS_NULL) 
		return NULL;

    copy = globus_malloc (sizeof(globus_fifo_t));
    if (copy == NULL) 
		return NULL;

    globus_fifo_init(copy);

    s_copy = *copy;
    s_copy->head = globus_list_copy(s_fifo->head);
    s_copy->tail = s_copy->head;

    while(!globus_list_empty(globus_list_rest(s_copy->tail))) 
    {
        s_copy->tail = globus_list_rest (s_copy->tail);
    }
 
	s_copy->size = s_fifo->size;
	return copy;
}
Пример #2
0
globus_result_t
globus_l_usage_stats_write_packet(
    globus_usage_stats_handle_t         handle)
{
    globus_result_t                     result = GLOBUS_SUCCESS;
#ifndef TARGET_ARCH_ARM
    globus_result_t                     save_result = GLOBUS_SUCCESS;
    globus_list_t *                     targets_list;
    globus_list_t *                     server_list;
    globus_abstime_t                    stamp;
    uint32_t                            nstamp;
    globus_size_t                       written;


    GlobusTimeAbstimeGetCurrent(stamp);
    nstamp = htonl(stamp.tv_sec);
    memcpy(handle->data + GLOBUS_L_USAGE_STATS_TIMESTAMP_OFFSET, 
           (void *)&nstamp, 4);
    targets_list = handle->xio_desc_list;
    server_list = handle->targets;
    while(targets_list)
    {
        GlobusUsageStatsDebugPrintf(
            GLOBUS_L_USAGE_STATS_DEBUG_MESSAGES,
            ("\n==========SENDING USAGE INFO: %s==(length: %d)===\n",
             (char *)globus_list_first(server_list), handle->data_length));
        GlobusUsageStatsDebugDump(
            GLOBUS_L_USAGE_STATS_DEBUG_MESSAGES,
            handle->data,
            handle->data_length);
        GlobusUsageStatsDebugPrintf(
            GLOBUS_L_USAGE_STATS_DEBUG_MESSAGES,
            ("\n=========================================================\n"));

        result = globus_xio_write(
            handle->xio_handle,
            handle->data,
            handle->data_length,
            0,
            &written,
            *(globus_xio_data_descriptor_t *) 
                globus_list_first(targets_list));
        if(result != GLOBUS_SUCCESS)
        {
            save_result = result;
        }

        targets_list = globus_list_rest(targets_list);
        server_list = globus_list_rest(server_list);
    }

    result = save_result;

#endif
    return result;
}   
Пример #3
0
void
globus_i_module_dump(
    FILE *				out_f)
{
    globus_list_t *			module_list;

    globus_libc_fprintf(out_f, "==========\nModule List\n----------\n");
    
    module_list = globus_l_module_list;
    while(!globus_list_empty(module_list))
    {
	globus_list_t *			client_list;
	globus_l_module_entry_t *	module_entry;

	module_entry = globus_list_first(module_list);
	module_list = globus_list_rest(module_list);

	globus_libc_fprintf(out_f, "%s; cnt=%d",
		module_entry->descriptor->module_name,
		module_entry->reference_count);

	client_list = module_entry->clients;

	if (!globus_list_empty(client_list))
	{
	    void *			client_entry;
	    globus_l_module_entry_t *	client_module_entry;
	    
	    client_entry = globus_list_first(client_list);
	    client_list = globus_list_rest(client_list);
	    client_module_entry =
		globus_hashtable_lookup(&globus_l_module_table, client_entry);
	    globus_libc_fprintf(out_f, "; clients=%s",
		    client_module_entry->descriptor->module_name);
	    
	    while(!globus_list_empty(client_list))
	    {
		client_entry = globus_list_first(client_list);
		client_list = globus_list_rest(client_list);
		client_module_entry =
		    globus_hashtable_lookup(&globus_l_module_table,
					    client_entry);
		globus_libc_fprintf(out_f, ",%s",
			client_module_entry->descriptor->module_name);
	    }
	}

	globus_libc_fprintf(out_f, "\n");
    }

    globus_libc_fprintf(out_f, "==========\n");
}
Пример #4
0
static bool
rsl_to_classad(globus_rsl_t * rsl, classad::ClassAd &ad)
{
    if (g_globus_activated)
    {
        globus_module_activate(GLOBUS_RSL_MODULE);
        g_globus_activated = true;
    }
    if (!rsl) { return true; }
    if (!globus_rsl_is_boolean(rsl)) { return false; }

    globus_list_t * ops = globus_rsl_boolean_get_operand_list(rsl);
    while (!globus_list_empty(ops))
    {
        globus_rsl_t *op_rsl = static_cast<globus_rsl_t*>(globus_list_first(ops));
        ops = globus_list_rest(ops);
        if (!op_rsl) { continue; }

        if (globus_rsl_is_relation(op_rsl))
        {
            char * attr = globus_rsl_relation_get_attribute(op_rsl);
            globus_rsl_value_t * value = globus_rsl_relation_get_value_sequence(op_rsl);
            if (!attr || !value) { continue; }
            globus_rsl_value_t * single_value = globus_rsl_relation_get_single_value(op_rsl);
            if (single_value) { value = single_value; }

            classad::ExprTree *expr = NULL;

            if (!value_to_expr(value, expr) || !expr) { continue; }

            ad.Insert(attr, expr);
        }
    }
    return true;
}
Пример #5
0
globus_result_t
globus_xio_driver_list_to_stack_attr(
    globus_list_t *                     driver_list,
    globus_xio_stack_t                  stack,
    globus_xio_attr_t                   attr)
{
    globus_xio_driver_list_ent_t *      ent; 
    globus_list_t *                     list;

    for(list = driver_list;
        !globus_list_empty(list);
        list = globus_list_rest(list))
    {
        ent = (globus_xio_driver_list_ent_t *) globus_list_first(list);

        globus_xio_stack_push_driver(stack, ent->driver);

        if(ent->opts != NULL)
        {
            /* ignore error */
            globus_xio_attr_cntl(
                attr,
                ent->driver,
                GLOBUS_XIO_SET_STRING_OPTIONS,
                ent->opts);
        }
    }

    return GLOBUS_SUCCESS;
}
Пример #6
0
void
globus_xio_driver_list_destroy(
    globus_list_t *                     driver_list,
    globus_bool_t                       unload)
{
    globus_xio_driver_list_ent_t *      ent;
    globus_list_t *                     list;

    for(list = driver_list;
        !globus_list_empty(list);
        list = globus_list_rest(list))
    {
        ent = (globus_xio_driver_list_ent_t *) globus_list_first(list);

        if(ent->driver_name != NULL)
        {
            globus_free(ent->driver_name);
        }
        if(ent->opts != NULL)
        {
            globus_free(ent->opts);
        }
        if(unload)
        {
            globus_xio_driver_unload(ent->driver);
        }
        globus_free(ent);
    }
}
Пример #7
0
int
globus_fifo_enqueue(
    globus_fifo_t *                                 fifo,
    void *                                          datum)
{
    int                                             err;
    struct globus_fifo_s *                          s_fifo;

    if (fifo==GLOBUS_NULL) 
		return -1;
    s_fifo = *fifo;
    if(s_fifo==GLOBUS_NULL) 
		return -1;

    if(s_fifo->tail==GLOBUS_NULL) 
    {
        err = globus_list_insert (
                (globus_list_t **) &(s_fifo->tail), 
			    datum);
        s_fifo->head = s_fifo->tail;
    }
    else 
    {
        err = globus_list_insert (globus_list_rest_ref (s_fifo->tail),
			      datum);
  
        s_fifo->tail = globus_list_rest (s_fifo->tail);
    }
	if(!err)
	{
		s_fifo->size++;
	}

    return err;
}
Пример #8
0
static
void
globus_l_gss_free_test_cases()
{
    compare_name_test_case_t            *test_case, *tmp_case;
    gss_name_t                          name1, name2;
    globus_list_t *                     tmp;
    OM_uint32                           minor_status;

    while (!globus_list_empty(test_cases))
    {
        test_case = globus_list_first(test_cases);
        free(test_case->test_name);
        name1 = test_case->name1;
        name2 = test_case->name2;

        for (tmp = test_cases;
             !globus_list_empty(tmp);
             tmp = globus_list_rest(tmp))
        {
            tmp_case = globus_list_first(tmp);

            if (name1 == tmp_case->name1 ||
                name2 == tmp_case->name1)
            {
                tmp_case->name1 = NULL;
            }
            if (name1 == tmp_case->name2 ||
                name2 == tmp_case->name2)
            {
                tmp_case->name2 = NULL;
            }
        }
        gss_release_name(&minor_status, &name1);
        if (name1 != name2)
        {
            gss_release_name(&minor_status, &name2);
        }
        if (test_case->name_token1)
        {
            free(test_case->name_token1);
        }
        if (test_case->name_token2)
        {
            free(test_case->name_token2);
        }
        free(test_case);
        globus_list_remove(&test_cases, test_cases);
    }
}
Пример #9
0
/**
 * @brief Call Context Post Close
 * @ingroup globus_net_manager_context
 * @details
 * Call the chain of post_close() functions in a context with the given
 * task_id, transport, contact information, and attributes. If any manager in
 * the context returns an error, the subsequent managers will not be called.
 *
 * @param [in] context
 *     The context to call functions in.
 * @param [in] task_id
 *     The task_id associated with this network operation.
 * @param [in] transport
 *     The transport driver associated with this network operation.
 * @param [in] local_contact
 *     The string representation of the local address of the socket.
 * @param [in] remote_contact
 *     The string representation of the remote address of the socket
 * @param [in] attr_array
 *     The set of attributes to pass to the managers.
 *
 * @return
 *     On success, this function returns GLOBUS_SUCCESS. If any manager
 *     returns an error, the post_close calls stop and the error is returned
 *     to the caller.
 */
globus_result_t
globus_net_manager_context_post_close(
    globus_net_manager_context_t        context,
    const char                         *task_id,
    const char                         *transport,
    const char                         *local_contact,
    const char                         *remote_contact,
    const globus_net_manager_attr_t    *attr_array)
{
    globus_i_net_manager_context_t *    ctx = context;
    globus_list_t *                     list;
    globus_result_t                     result = GLOBUS_SUCCESS;
    globus_i_net_manager_context_entry_t * ent;

    if(!ctx || !task_id || !transport || !attr_array ||
        !local_contact || !remote_contact)
    {
        result = GlobusNetManagerErrorParameter("No parameter may be NULL.");
        goto error_bad_args;
    }

    for(list = ctx->managers; 
        !globus_list_empty(list) && result == GLOBUS_SUCCESS; 
        list = globus_list_rest(list))
    {            
        ent = globus_list_first(list);
        
        if(ent->manager->post_close)
        {
            result = ent->manager->post_close(
                ent->manager,
                ent->attrs,
                task_id,
                transport,
                local_contact,
                remote_contact,
                attr_array);
            if(result != GLOBUS_SUCCESS)
            {
                result = GlobusNetManagerErrorManager(
                    result, ent->manager->name, "post_close");
            }                
        }
    }
    
    return result;

error_bad_args:
    return result;
}
Пример #10
0
/*
 * globus_module_deactivate_all()
 */
int
globus_module_deactivate_all(void)
{
    /*
     * If module activation hasn't been initialized then return an error
     */
    if (!globus_i_module_initialized)
    {
	return GLOBUS_FAILURE;
    }
    
    globus_l_module_mutex_lock(&globus_l_module_mutex);
    {
	globus_bool_t			 deactivated_one;

	deactivated_one = GLOBUS_TRUE;

	while(deactivated_one)
	{
	    globus_list_t *		module_list;

	    module_list = globus_l_module_list;
	    deactivated_one = GLOBUS_FALSE;

	    while(!globus_list_empty(module_list))
	    {
		globus_l_module_entry_t *module_entry;

		module_entry = globus_list_first(module_list);
		module_list = globus_list_rest(module_list);
	    
		if(globus_list_empty(module_entry->clients) &&
		   module_entry->reference_count > 0)
		{
		    globus_l_module_mutex_unlock(&globus_l_module_mutex);
		    globus_module_deactivate(module_entry->descriptor);
		    globus_l_module_mutex_lock(&globus_l_module_mutex);
		    deactivated_one = GLOBUS_TRUE;
		}
	    }
	}
    }
    globus_l_module_mutex_unlock(&globus_l_module_mutex);

    return GLOBUS_SUCCESS;
}
Пример #11
0
globus_result_t
globus_xio_string_cntl_string_list(
    void *                              attr,
    const char *                        key,
    const char *                        val,
    int                                 cmd,
    globus_xio_driver_attr_cntl_t       cntl_func)
{
    int                                 i = 0;
    globus_list_t *                     val_list;
    globus_list_t *                     list;
    char **                             argv;
    int                                 argc;
    globus_result_t                     result;
    int                                 del;

    /* delimitor is the first character */
    if(val == NULL)
    {
        return GLOBUS_SUCCESS;
    }

    del = (int)*val;
    val++;

    val_list = globus_list_from_string(val, del, NULL);
    list = val_list;

    argc = globus_list_size(list);
    argv = (char **) calloc(argc+1, sizeof(char *));
    i = argc - 1;
    while(!globus_list_empty(list))
    {
        argv[i] = (char *)globus_list_first(list);
        list = globus_list_rest(list);
        i--;
    }

    result = globus_xio_string_cntl_bouncer(cntl_func, attr, cmd, argv);

    globus_list_destroy_all(val_list, globus_libc_free);
    globus_free(argv);
    
    return result;
}
Пример #12
0
void *
globus_fifo_remove(
    globus_fifo_t *                                 fifo, 
    void *                                          datum)
{
    globus_list_t *                                 iter_prev;
    globus_list_t *                                 iter;
    struct globus_fifo_s *                          s_fifo;
    
    assert(fifo != GLOBUS_NULL);
    s_fifo = *fifo;
    assert(s_fifo != GLOBUS_NULL);

    if(globus_list_empty(s_fifo->head)) 
		return GLOBUS_NULL;

    iter_prev = GLOBUS_NULL;
    iter = s_fifo->head;
    while((!globus_list_empty(iter))
	  && (globus_list_first(iter) != datum)) 
	{
        iter_prev = iter;
        iter = globus_list_rest(iter);
    }

    if(!globus_list_empty(iter)) 
    {
        /* iter is the element to remove, iter_prev is the previous */
        if(iter == s_fifo->tail) 
        {
            /* make sure tail doesn't dangle */
            s_fifo->tail = iter_prev;
        }
        globus_list_remove (&(s_fifo->head), iter);

		s_fifo->size--;
        return datum;
    }
    else
    {
        return GLOBUS_NULL;
    }
}
int
globus_gram_job_manager_validation_destroy(
    globus_list_t *                     validation_records)
{
    globus_list_t *                     tmp;
    globus_rvf_record_t *               record;

    tmp = validation_records;

    while (!globus_list_empty(tmp))
    {
        record = globus_list_first(tmp);
        tmp = globus_list_rest(tmp);

        globus_l_gram_job_manager_validation_record_free(record);
    }
    globus_list_free(validation_records);

    return GLOBUS_SUCCESS;
}
static
int
globus_l_gram_streamer_get_destinations(
    globus_gram_streamer_monitor_t *    monitor)
{
    globus_list_t *                     tmp;
    globus_gram_job_manager_staging_info_t *
                                        info;
    char *                              s;

    tmp = monitor->request.stage_stream_todo;

    while (tmp != NULL)
    {
        info = globus_list_first(tmp);
        tmp = globus_list_rest(tmp);

        if (monitor->output_stream.destination == NULL)
        {
            s = strstr(info->evaled_from, "/stdout");
            if (s != NULL && strcmp(s, "/stdout") == 0)
            {
                monitor->output_stream.source = strdup(info->evaled_from);
                monitor->output_stream.destination = strdup(info->evaled_to);
                continue;
            }
        }

        if (monitor->error_stream.destination == NULL)
        {
            s = strstr(info->evaled_from, "/stderr");
            if (s != NULL && strcmp(s, "/stderr") == 0)
            {
                monitor->error_stream.source = strdup(info->evaled_from);
                monitor->error_stream.destination = strdup(info->evaled_to);
                continue;
            }
        }
    }
    return 0;
}
Пример #15
0
void
globus_module_print_activated_versions(
    FILE *                              stream,
    globus_bool_t                       verbose)
{
    /*
     * If module activation hasn't been initialized then there are no
     * activated modules
     */
    if(!globus_i_module_initialized)
    {
        return;
    }
    
    globus_l_module_mutex_lock(&globus_l_module_mutex);
    {
        globus_list_t *		        module_list;
        
        module_list = globus_l_module_list;
        while(!globus_list_empty(module_list))
        {
            globus_l_module_entry_t *       module_entry;
    
            module_entry = globus_list_first(module_list);
            module_list = globus_list_rest(module_list);
            
            if(module_entry->reference_count > 0)
            {
                globus_version_print(
                    module_entry->descriptor->module_name,
                    module_entry->descriptor->version,
                    stream,
                    verbose);
            }
        }
    }
    globus_l_module_mutex_unlock(&globus_l_module_mutex);

    return;
}
Пример #16
0
globus_xio_driver_list_ent_t *
globus_xio_driver_list_find_driver(
    globus_list_t *                     driver_list,
    const char *                        driver_name)
{
    globus_xio_driver_list_ent_t *      ent;
    globus_list_t *                     list;


    for(list = driver_list;
        !globus_list_empty(list);
        list = globus_list_rest(list))
    {
        ent = (globus_xio_driver_list_ent_t *) globus_list_first(list);

        if(strcmp(ent->driver_name, driver_name) == 0)
        {
            return ent;
        }
    }

    return NULL;
}
/**
 * Check that a relation for a required RSL attribute is present.
 *
 * @param attributes
 *        List of relations which are part of the job request's
 *        RSL.
 * @param attribute_name
 *        The name of the attribute to search for.
 */
static
globus_bool_t
globus_l_gram_job_manager_attribute_exists(
    globus_list_t *                        attributes,
    char *                                attribute_name)
{
    char *                                tmp;
    globus_rsl_t *                        relation;

    while(!globus_list_empty(attributes))
    {
        relation = globus_list_first(attributes);
        attributes = globus_list_rest(attributes);
        tmp = globus_rsl_relation_get_attribute(relation);

        if(globus_l_gram_job_manager_validation_string_match(
                    tmp,
                    attribute_name))
        {
            return GLOBUS_TRUE;
        }
    }
    return GLOBUS_FALSE;
}
static
int
globus_l_staging_replace_stream(
    globus_gram_jobmanager_request_t *  request,
    char *                              parameter,
    char *                              cached_destination)
{
    globus_list_t *                     list;
    globus_rsl_value_t                  *to;
    globus_rsl_value_t                  from_cached;
    globus_bool_t                       single;
    int                                 rc = GLOBUS_SUCCESS;

    list = globus_rsl_param_get_values(
            request->rsl,
            parameter);

    if (list == NULL)
    {
        /* Attempting to replace something that was never in the job
         * RSL---too bad
         */
        return GLOBUS_SUCCESS;
    }
    from_cached.type = GLOBUS_RSL_VALUE_LITERAL;
    from_cached.value.literal.string = cached_destination;

    /* The stdout and stderr attributes can occur in two forms:
     * - stdout = destination [tag]
     * - stdout = (destination [tag])+
     * That is, either as a sequence of 1 or 2 values, or as a sequence of
     * sequences.
     *
     * In either form, if there is only one destination, and it's a local file
     * or x-gass-cache URL, we can safely write directly to that file and don't
     * need it to be staged after the job completes. Otherwise, we'll have to
     * write to the stdout (stderr) file in the job directory and copy it
     * during the STAGE_OUT state.
     */
    if (! globus_rsl_value_is_sequence(globus_list_first(list)))
    {
        rc = globus_l_staging_replace_one_stream(
                request,
                parameter,
                cached_destination,
                list,
                GLOBUS_TRUE);
    }
    else
    {
        single = (globus_list_size(list) == 1);

        while (!globus_list_empty(list))
        {
            globus_list_t                   *sequence_list;

            to = globus_list_first(list);
            list = globus_list_rest(list);

            if (!globus_rsl_value_is_sequence(to))
            {
                /* Bare value instead of a sequence */
                rc = GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDOUT;
                goto bad_value;
            }

            sequence_list = globus_rsl_value_sequence_get_value_list(to);

            rc = globus_l_staging_replace_one_stream(
                    request,
                    parameter,
                    cached_destination,
                    sequence_list,
                    single);

            if (rc != GLOBUS_SUCCESS)
            {
                goto bad_value;
            }

        }
    }

    if (rc != GLOBUS_SUCCESS)
    {
bad_value:
        /* Normalize error types to match the RSL attribute that we are
         * processing
         */
        if (strcmp(parameter, GLOBUS_GRAM_PROTOCOL_STDERR_PARAM) == 0)
        {
            switch (rc)
            {
                case GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDOUT:
                    rc = GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDERR;
                    break;
                case GLOBUS_GRAM_PROTOCOL_ERROR_OPENING_STDOUT:
                    rc = GLOBUS_GRAM_PROTOCOL_ERROR_OPENING_STDERR;
                    break;
                default:
                    break;
            }
        }
    }
    return rc;
}
/**
 * Add default values to RSL and verify required parameters
 *
 * Inserts default values to RSL when an RSL parameter is not defined
 * in it. After this is complete, it checks that all RSL parameters
 * with the "required_when" flag set are present in the RSL tree.
 *
 * @param request
 *        Request which contains the RSL tree to validate.
 * @param when
 *        Which RSL validation time scope we will use to decide
 *        whether to use the default values or not.
 */
static
int
globus_l_gram_job_manager_insert_default_rsl(
    globus_gram_jobmanager_request_t *  request,
    globus_rsl_t *                      rsl,
    globus_gram_job_manager_validation_when_t
                                        when)
{
    globus_rvf_record_t *               record;
    globus_list_t **                    attributes;
    globus_rsl_t *                      new_relation;
    char *                              new_relation_str;
    globus_list_t *                     validation_records;
    int                                 rc = GLOBUS_SUCCESS;

    attributes = globus_rsl_boolean_get_operand_list_ref(rsl);

    validation_records = request->manager->validation_records;

    while(!globus_list_empty(validation_records))
    {
        record = globus_list_first(validation_records);
        validation_records = globus_list_rest(validation_records);

        if(record->default_value && (record->default_when&when))
        {
            if(!globus_l_gram_job_manager_attribute_exists(
                        *attributes,
                        record->attribute))
            {
                new_relation_str = globus_common_create_string(
                        "%s = %s",
                        record->attribute,
                        record->default_value);

                globus_gram_job_manager_request_log(
                        request,
                        GLOBUS_GRAM_JOB_MANAGER_LOG_TRACE,
                        "event=gram.validate_rsl.info "
                        "level=TRACE "
                        "msg=\"Inserting default RSL for attribute\" "
                        "attribute=%s "
                        "default=\"%s\" "
                        "\n",
                        record->attribute,
                        record->default_value);

                new_relation = globus_rsl_parse(new_relation_str);

                globus_list_insert(attributes, new_relation);

                free(new_relation_str);
            }
        }
        if(record->required_when & when)
        {
            if(!globus_l_gram_job_manager_attribute_exists(
                        *attributes,
                        record->attribute))
            {
                rc = globus_l_gram_job_manager_missing_value_error(
                            record->attribute);

                globus_gram_job_manager_request_log(
                        request,
                        GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
                        "event=gram.validate_rsl.end "
                        "level=ERROR "
                        "msg=\"RSL missing required attribute\" "
                        "attribute=%s "
                        "\n",
                        record->attribute);

                return rc;
            }
        }
    }
    return rc;
}
/**
 * Validate RSL attributes
 *
 * Checks that all of the RSL attributes in the request's RSL match
 * a validation record. If an RSL has an enumerated list of values,
 * then the value of the RSL is compared against that list.
 *
 * @param request
 *        The job request containing the RSL to validate.
 * @param when
 *        Which RSL validation time scope we will use to decide
 *        whether to use the default values or not.
 */
static
int
globus_l_gram_job_manager_check_rsl_attributes(
    globus_gram_jobmanager_request_t *  request,
    globus_rsl_t *                      rsl,
    globus_gram_job_manager_validation_when_t
                                        when)
{
    globus_list_t *                     operands;
    globus_list_t *                     node;
    globus_rsl_t *                      relation;
    char *                              attribute;
    char *                              value_str;
    globus_rvf_record_t *               record;
    globus_rsl_value_t *                value;
    int                                 rc = GLOBUS_SUCCESS;
    static const char *                 operation_types[] =
    {
        "??",
        "=",
        "!=",
        ">",
        ">=",
        "<",
        "<=",
        "??",
        "&",
        "|",
        "+"
    };

    operands = globus_rsl_boolean_get_operand_list(rsl);

    /* Check to make sure that every attribute is recognized by this
     * job manager.
     */
    while(!globus_list_empty(operands))
    {
        relation = globus_list_first(operands);
        operands = globus_list_rest(operands);

        if (!globus_rsl_is_relation(relation))
        {
            int operator = globus_rsl_boolean_get_operator(relation);
            if (operator > 10 || operator < 0)
            {
                operator = 0;
            }

            globus_gram_job_manager_request_log(
                    request,
                    GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
                    "event=gram.validate_rsl.end "
                    "level=ERROR "
                    "msg=\"Required RSL relation, got boolean\" "
                    "operator=%s "
                    "status=%d "
                    "\n",
                    operation_types[operator],
                    -GLOBUS_GRAM_PROTOCOL_ERROR_BAD_RSL);
            if (request->gt3_failure_message == NULL)
            {
                request->gt3_failure_message = globus_common_create_string(
                        "Required RSL relation, got boolean %s",
                        operation_types[operator]);
            }
        }
        else if (!globus_rsl_is_relation_eq(relation))
        {
            int operator = globus_rsl_relation_get_operator(relation);

            if (operator > 10 || operator < 0)
            {
                operator = 0;
            }

            globus_gram_job_manager_request_log(
                    request,
                    GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
                    "event=gram.validate_rsl.end "
                    "level=ERROR "
                    "msg=\"Unsupported RSL operation\" "
                    "attribute=%s "
                    "operator=%s "
                    "status=%d "
                    "\n",
                    globus_rsl_relation_get_attribute(relation),
                    operation_types[operator],
                    -GLOBUS_GRAM_PROTOCOL_ERROR_BAD_RSL);

            if (request->gt3_failure_message == NULL)
            {
                request->gt3_failure_message = globus_common_create_string(
                        "the job manager does not support the RSL operator "
                        "\"%s\" for the %s attribute",
                        operation_types[operator],
                        globus_rsl_relation_get_attribute(relation));
            }
            return GLOBUS_GRAM_PROTOCOL_ERROR_BAD_RSL;
        }
        attribute = globus_rsl_relation_get_attribute(relation);

        node = globus_list_search_pred(
                request->manager->validation_records,
                globus_l_gram_job_manager_attribute_match,
                attribute);

        if(!node)
        {
            globus_gram_job_manager_request_log(
                    request,
                    GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
                    "event=gram.validate_rsl.end "
                    "level=ERROR "
                    "msg=\"Unsupported RSL attribute\" "
                    "attribute=%s "
                    "status=%d "
                    "\n",
                    globus_rsl_relation_get_attribute(relation),
                    -GLOBUS_GRAM_PROTOCOL_ERROR_BAD_RSL);

            if (request->gt3_failure_message == NULL)
            {
                request->gt3_failure_message = globus_common_create_string(
                        "the RSL attribute \"%s\" is not supported by the LRM adapter",
                        globus_rsl_relation_get_attribute(relation));
            }
            return GLOBUS_GRAM_PROTOCOL_ERROR_PARAMETER_NOT_SUPPORTED;
        }

        record = globus_list_first(node);

        /* Check valid_when */
        if((record->valid_when & when) == 0)
        {
            const char * whenstr = "unknown operation";

            switch(when)
            {
              case GLOBUS_GRAM_VALIDATE_JOB_SUBMIT:
                whenstr = "submit";
                rc = GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_SUBMIT_ATTRIBUTE;
                break;
              case GLOBUS_GRAM_VALIDATE_JOB_MANAGER_RESTART:
                whenstr = "restart";
                rc = GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_RESTART_ATTRIBUTE;
                break;
              case GLOBUS_GRAM_VALIDATE_STDIO_UPDATE:
                whenstr = "stdio_update";
                rc = GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_STDIO_UPDATE_ATTRIBUTE;
                break;
            }

            globus_gram_job_manager_request_log(
                    request,
                    GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
                    "event=gram.validate_rsl.end "
                    "level=ERROR "
                    "msg=\"Invalid RSL attribute for operation\" "
                    "attribute=%s "
                    "operation=%s "
                    "status=%d "
                    "\n",
                    globus_rsl_relation_get_attribute(relation),
                    whenstr,
                    -rc);
            if (request->gt3_failure_message == NULL)
            {
                request->gt3_failure_message = globus_common_create_string(
                        "Invalid RSL attribute \"%s\" for %s",
                        globus_rsl_relation_get_attribute(relation),
                        whenstr);
            }
            return rc;
        }
        /* Check enumerated values if applicable */
        if(record->enumerated_values)
        {
            value = globus_rsl_relation_get_single_value(relation);

            if(!value)
            {
                return
                    globus_l_gram_job_manager_validation_rsl_error(attribute);
            }
            value_str = globus_rsl_value_literal_get_string(value);
            if(!value_str)
            {
                return globus_l_gram_job_manager_validation_rsl_error(
                        attribute);
            }
            if(strstr(record->enumerated_values, value_str) == GLOBUS_NULL)
            {
                rc = globus_l_gram_job_manager_validation_value_error(
                            request,
                            attribute,
                            value_str,
                            record->enumerated_values);

                globus_gram_job_manager_request_log(
                        request,
                        GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
                        "event=gram.validate_rsl.end "
                        "level=ERROR "
                        "msg=\"RSL attribute value not in enumeration\" "
                        "attribute=%s "
                        "value=%s "
                        "enumeration=\"%s\" "
                        "status=%d "
                        "\n",
                        record->attribute,
                        value_str,
                        record->enumerated_values,
                        -rc);

                return rc;
            }
        }
    }

    return GLOBUS_SUCCESS;
}
int
globus_gram_job_manager_staging_write_state(
    globus_gram_jobmanager_request_t *  request,
    FILE *                              fp)
{
    globus_list_t *                     tmp_list;
    globus_gram_job_manager_staging_info_t *
                                        info;
    char *                              tmp_str;
    int                                 rc;

    rc = fprintf(fp, "%d\n", globus_list_size(request->stage_in_todo));

    if (rc < 0)
    {
        return GLOBUS_FAILURE;
    }

    tmp_list = request->stage_in_todo;
    while(!globus_list_empty(tmp_list))
    {
        info = globus_list_first(tmp_list);
        tmp_list = globus_list_rest(tmp_list);

        tmp_str = globus_rsl_value_unparse(info->from);
        rc = fprintf(fp, "%s\n", tmp_str);
        free(tmp_str);
        if (rc < 0)
        {
            return GLOBUS_FAILURE;
        }

        tmp_str = globus_rsl_value_unparse(info->to);
        rc = fprintf(fp, "%s\n", tmp_str);
        free(tmp_str);
        if (rc < 0)
        {
            return GLOBUS_FAILURE;
        }
    }
    rc = fprintf(fp, "%d\n", globus_list_size(request->stage_in_shared_todo));
    if (rc < 0)
    {
        return GLOBUS_FAILURE;
    }
    tmp_list = request->stage_in_shared_todo;
    while(!globus_list_empty(tmp_list))
    {
        info = globus_list_first(tmp_list);
        tmp_list = globus_list_rest(tmp_list);

        tmp_str = globus_rsl_value_unparse(info->from);
        rc = fprintf(fp, "%s\n", tmp_str);
        free(tmp_str);
        if (rc < 0)
        {
            return GLOBUS_FAILURE;
        }

        tmp_str = globus_rsl_value_unparse(info->to);
        rc = fprintf(fp, "%s\n", tmp_str);
        free(tmp_str);
        if (rc < 0)
        {
            return GLOBUS_FAILURE;
        }
    }
    rc = fprintf(fp, "%d\n", globus_list_size(request->stage_out_todo));
    if (rc < 0)
    {
        return GLOBUS_FAILURE;
    }
    tmp_list = request->stage_out_todo;
    while(!globus_list_empty(tmp_list))
    {
        info = globus_list_first(tmp_list);
        tmp_list = globus_list_rest(tmp_list);

        tmp_str = globus_rsl_value_unparse(info->from);
        rc = fprintf(fp, "%s\n", tmp_str);
        free(tmp_str);

        if (rc < 0)
        {
            return GLOBUS_FAILURE;
        }

        tmp_str = globus_rsl_value_unparse(info->to);
        rc = fprintf(fp, "%s\n", tmp_str);
        free(tmp_str);
        if (rc < 0)
        {
            return GLOBUS_FAILURE;
        }
    }
    rc = fprintf(fp, "%d\n", globus_list_size(request->stage_stream_todo));
    tmp_list = request->stage_stream_todo;
    while(!globus_list_empty(tmp_list))
    {
        info = globus_list_first(tmp_list);
        tmp_list = globus_list_rest(tmp_list);

        tmp_str = globus_rsl_value_unparse(info->from);
        rc = fprintf(fp, "%s\n", tmp_str);
        free(tmp_str);

        if (rc < 0)
        {
            return GLOBUS_FAILURE;
        }

        tmp_str = globus_rsl_value_unparse(info->to);
        rc = fprintf(fp, "%s\n", tmp_str);
        free(tmp_str);
        if (rc < 0)
        {
            return GLOBUS_FAILURE;
        }
    }
    return GLOBUS_SUCCESS;
}
/**
 * @param manager
 *        A job request. The validation field of this job request will be
 *        updated with a list of validation records constructed from the
 *        rsl validation files associated with the job manager.
 */
static
int
globus_gram_job_manager_validation_init(
    globus_gram_job_manager_t *         manager)
{
    time_t                              validation_timestamp = time(NULL);
    int                                 rc = GLOBUS_SUCCESS;
    globus_list_t *                     l;

    manager->validation_records = NULL;
    manager->validation_file_exists[0] = GLOBUS_FALSE;
    manager->validation_file_exists[1] = GLOBUS_FALSE;
    manager->validation_file_exists[2] = GLOBUS_FALSE;
    manager->validation_file_exists[3] = GLOBUS_FALSE;

    /* Read in validation files. Do the generic job manager one first,
     * as the scheduler-specific one overrides it.
     */
    rc = globus_rvf_parse_file(
        validation_filename,
        &manager->validation_records,
        &manager->gt3_failure_message);

    if(rc != GLOBUS_SUCCESS)
    {
        goto read_validation_failed;
    }
    manager->validation_file_exists[0] = GLOBUS_TRUE;

    if(access(lrm_validation_filename, R_OK) == 0)
    {
        rc = globus_rvf_parse_file(
                lrm_validation_filename,
                &manager->validation_records,
                &manager->gt3_failure_message);
        if (rc != GLOBUS_SUCCESS)
        {
            goto read_lrm_validation_filename_failed;
        }
        manager->validation_file_exists[1] = GLOBUS_TRUE;
    }

    if (access(site_validation_filename, R_OK) == 0)
    {
        rc = globus_rvf_parse_file(
                site_validation_filename,
                &manager->validation_records,
                &manager->gt3_failure_message);

        if (rc != GLOBUS_SUCCESS)
        {
            goto read_site_validation_filename_failed;
        }
        manager->validation_file_exists[2] = GLOBUS_TRUE;
    }

    if (access(site_lrm_validation_filename, R_OK) == 0)
    {
        rc = globus_rvf_parse_file(
                site_lrm_validation_filename,
                &manager->validation_records,
                &manager->gt3_failure_message);
        if (rc != GLOBUS_SUCCESS)
        {
            goto read_site_lrm_validation_filename_failed;
        }
        manager->validation_file_exists[3] = GLOBUS_TRUE;
    }

    for(l = manager->validation_records; l != NULL; l = globus_list_rest(l))
    {
        globus_rvf_record_t *           record = globus_list_first(l);

        if (record->valid_when == -1)
        {
            record->valid_when = 0;
        }
        if (record->default_when == -1)
        {
            record->default_when = 0;
        }
        if (record->required_when == -1)
        {
            record->required_when = 0;
        }
        if (record->publishable == -1)
        {
            record->publishable = 1;
        }
    }

    manager->validation_record_timestamp = validation_timestamp;

read_site_lrm_validation_filename_failed:
read_site_validation_filename_failed:
read_lrm_validation_filename_failed:
    if(rc != GLOBUS_SUCCESS)
    {
        globus_gram_job_manager_validation_destroy(
                manager->validation_records);
        manager->validation_records = NULL;
    }
read_validation_failed:
    return rc;
}
Пример #23
0
static
void
import_names()
{
    OM_uint32                           major_status, minor_status;
    globus_gsi_cred_handle_t            handle;
    gss_buffer_desc                     buffer;
    X509 *                              cert;
    gss_OID_set                         name_types;
    globus_result_t                     result;
    globus_list_t                       *i, *j;
    compare_name_test_case_t *          test_case;
    int                                 present;

    major_status = gss_inquire_names_for_mech(
        &minor_status,
        (gss_OID) globus_i_gss_mech_globus_gssapi_openssl,
        &name_types);

    if (major_status == GSS_S_COMPLETE)
    {
        major_status = gss_test_oid_set_member(
                &minor_status,
                GLOBUS_GSS_C_NT_X509,
                name_types,
                &present);

        if (major_status == GSS_S_COMPLETE && present)
        {
            gss_l_x509_support = GLOBUS_TRUE;
        }

        major_status = gss_test_oid_set_member(
                &minor_status,
                GLOBUS_GSS_C_NT_HOST_IP,
                name_types,
                &present);

        if (major_status == GSS_S_COMPLETE && present)
        {
            gss_l_host_ip_support = GLOBUS_TRUE;
        }

        major_status = gss_release_oid_set(&minor_status, &name_types);
    }

    for (i = test_cases; !globus_list_empty(i); i = globus_list_rest(i))
    {
        test_case = globus_list_first(i);

        if (test_case->name1 == GSS_C_NO_NAME)
        {
            switch (test_case->name_type1)
            {
                case GSS_L_ANONYMOUS:
                    major_status = gss_import_name(&minor_status, &buffer, GSS_C_NT_ANONYMOUS, &test_case->name1);
                    if (major_status != GSS_S_COMPLETE)
                    {
                        fprintf(stderr, "Error importing <anonymous>\n");
                        globus_gsi_gssapi_test_print_error(stderr, major_status, minor_status);
                        exit(-1);
                    }
                    break;
                case GSS_L_NO_OID:
                    buffer.value = test_case->name_token1;
                    buffer.length = strlen(buffer.value);

                    major_status = gss_import_name(&minor_status, &buffer, GSS_C_NO_OID, &test_case->name1);
                    if (major_status != GSS_S_COMPLETE)
                    {
                        fprintf(stderr, "Error importing %s\n", test_case->name_token1);
                        globus_gsi_gssapi_test_print_error(stderr, major_status, minor_status);
                        exit(-1);
                    }
                    break;
                case GSS_L_HOSTBASED_SERVICE:
                    buffer.value = test_case->name_token1;
                    buffer.length = strlen(buffer.value);

                    major_status = gss_import_name(&minor_status, &buffer, GSS_C_NT_HOSTBASED_SERVICE, &test_case->name1);
                    if (major_status != GSS_S_COMPLETE)
                    {
                        fprintf(stderr, "Error importing %s\n", test_case->name_token1);
                        globus_gsi_gssapi_test_print_error(stderr, major_status, minor_status);
                        exit(-1);
                    }
                    break;
                case GSS_L_HOST_IP:
                    if (gss_l_host_ip_support)
                    {
                        buffer.value = test_case->name_token1;
                        buffer.length = strlen(buffer.value);

                        major_status = gss_import_name(&minor_status, &buffer, GLOBUS_GSS_C_NT_HOST_IP, &test_case->name1);
                        if (major_status != GSS_S_COMPLETE)
                        {
                            fprintf(stderr, "Error importing %s\n", test_case->name_token1);
                            globus_gsi_gssapi_test_print_error(stderr, major_status, minor_status);
                            exit(-1);
                        }
                    }
                    break;
                case GSS_L_X509:
                    if (gss_l_x509_support)
                    {
                        result = globus_gsi_cred_handle_init(&handle, NULL);
                        if (result != GLOBUS_SUCCESS)
                        {
                            globus_gsi_gssapi_test_print_result(stderr, result);
                            exit(-1);
                        }

                        result = globus_gsi_cred_read_cert(handle, test_case->name_token1);
                        if (result != GLOBUS_SUCCESS)
                        {
                            globus_gsi_gssapi_test_print_result(stderr, result);
                            exit(-2);
                        }

                        result = globus_gsi_cred_get_cert(handle, &cert);

                        buffer.value = cert;
                        buffer.length = sizeof(X509);

                        major_status = gss_import_name(&minor_status, &buffer, GLOBUS_GSS_C_NT_X509, &test_case->name1);
                        if (major_status != GSS_S_COMPLETE)
                        {
                            fprintf(stderr, "Error importing %s\n", test_case->name_token1);
                            globus_gsi_gssapi_test_print_error(stderr, major_status, minor_status);
                            exit(-1);
                        }
                        X509_free(cert);
                        globus_gsi_cred_handle_destroy(handle);
                    }
                    break;
            }

            for (j = i; !globus_list_empty(j); j = globus_list_rest(j))
            {
                compare_name_test_case_t *test_case2 = globus_list_first(j);

                if (test_case->name_type1 == test_case2->name_type1 &&
                    test_case->name_token1 && test_case2->name_token1 &&
                    strcmp(test_case->name_token1, test_case2->name_token1) == 0 &&
                    test_case2->name1 == GSS_C_NO_NAME)
                {
                    test_case2->name1 = test_case->name1;
                }
                if (test_case->name_type1 == test_case2->name_type2 &&
                    test_case->name_token1 && test_case2->name_token2 &&
                    strcmp(test_case->name_token1, test_case2->name_token2) == 0 &&
                    test_case2->name2 == GSS_C_NO_NAME)
                {
                    test_case2->name2 = test_case->name1;
                }
            }
        }
        if (test_case->name2 == GSS_C_NO_NAME)
        {
            switch (test_case->name_type2)
            {
                case GSS_L_ANONYMOUS:
                    major_status = gss_import_name(&minor_status, &buffer, GSS_C_NT_ANONYMOUS, &test_case->name2);
                    if (major_status != GSS_S_COMPLETE)
                    {
                        fprintf(stderr, "Error importing <anonymous>\n");
                        globus_gsi_gssapi_test_print_error(stderr, major_status, minor_status);
                        exit(-1);
                    }
                    break;
                case GSS_L_NO_OID:
                    buffer.value = test_case->name_token2;
                    buffer.length = strlen(buffer.value);

                    major_status = gss_import_name(&minor_status, &buffer, GSS_C_NO_OID, &test_case->name2);
                    if (major_status != GSS_S_COMPLETE)
                    {
                        fprintf(stderr, "Error importing %s\n", test_case->name_token2);
                        globus_gsi_gssapi_test_print_error(stderr, major_status, minor_status);
                        exit(-1);
                    }
                    break;
                case GSS_L_HOSTBASED_SERVICE:
                    buffer.value = test_case->name_token2;
                    buffer.length = strlen(buffer.value);

                    major_status = gss_import_name(&minor_status, &buffer, GSS_C_NT_HOSTBASED_SERVICE, &test_case->name2);
                    if (major_status != GSS_S_COMPLETE)
                    {
                        fprintf(stderr, "Error importing %s\n", test_case->name_token2);
                        globus_gsi_gssapi_test_print_error(stderr, major_status, minor_status);
                        exit(-1);
                    }
                    break;
                case GSS_L_HOST_IP:
                    if (gss_l_host_ip_support)
                    {
                        buffer.value = test_case->name_token2;
                        buffer.length = strlen(buffer.value);

                        major_status = gss_import_name(&minor_status, &buffer, GLOBUS_GSS_C_NT_HOST_IP, &test_case->name2);
                        if (major_status != GSS_S_COMPLETE)
                        {
                            fprintf(stderr, "Error importing %s\n", test_case->name_token2);
                            globus_gsi_gssapi_test_print_error(stderr, major_status, minor_status);
                            exit(-1);
                        }
                    }
                    break;
                case GSS_L_X509:
                    if (gss_l_x509_support)
                    {
                        result = globus_gsi_cred_handle_init(&handle, NULL);
                        if (result != GLOBUS_SUCCESS)
                        {
                            globus_gsi_gssapi_test_print_result(stderr, result);
                            exit(-1);
                        }

                        result = globus_gsi_cred_read_cert(handle, test_case->name_token2);
                        if (result != GLOBUS_SUCCESS)
                        {
                            globus_gsi_gssapi_test_print_result(stderr, result);
                            exit(-2);
                        }

                        result = globus_gsi_cred_get_cert(handle, &cert);

                        buffer.value = cert;
                        buffer.length = sizeof(X509);

                        major_status = gss_import_name(&minor_status, &buffer, GLOBUS_GSS_C_NT_X509, &test_case->name2);
                        if (major_status != GSS_S_COMPLETE)
                        {
                            fprintf(stderr, "Error importing %s\n", test_case->name_token2);
                            globus_gsi_gssapi_test_print_error(stderr, major_status, minor_status);
                            exit(-1);
                        }
                        X509_free(cert);
                        globus_gsi_cred_handle_destroy(handle);
                    }
                    break;
            }
            for (j = i; !globus_list_empty(j); j = globus_list_rest(j))
            {
                compare_name_test_case_t *test_case2 = globus_list_first(j);

                if (test_case->name_type2 == test_case2->name_type1 &&
                    test_case->name_token2 && test_case2->name_token1 &&
                    strcmp(test_case->name_token2, test_case2->name_token1) == 0 &&
                    test_case2->name1 == GSS_C_NO_NAME)
                {
                    test_case2->name1 = test_case->name2;
                }
                if (test_case->name_type2 == test_case2->name_type2 &&
                    test_case->name_token2 && test_case2->name_token2 &&
                    strcmp(test_case->name_token2, test_case2->name_token2) == 0 &&
                    test_case2->name2 == GSS_C_NO_NAME)
                {
                    test_case2->name2 = test_case->name2;
                }
            }
        }
    }
}
Пример #24
0
static bool
value_to_expr(globus_rsl_value_t * value, classad::ExprTree*& expr)
{
    if (globus_rsl_value_is_literal(value))
    {
        char * literal = globus_rsl_value_literal_get_string(value);
        if (!literal) { return false; }
        classad::Value val;
        try
        {
            val.SetIntegerValue(boost::lexical_cast<long long>(literal));
        }
        catch (const boost::bad_lexical_cast &)
        {
            try
            {
                val.SetRealValue(boost::lexical_cast<double>(literal));
            }
            catch (const boost::bad_lexical_cast &)
            {
                std::string lower = literal;
                boost::algorithm::to_lower(lower);
                if (lower == "true") { val.SetBooleanValue(true); }
                else if (lower == "false") { val.SetBooleanValue(false); }
                else { val.SetStringValue(literal); }
            }
        }
        expr = classad::Literal::MakeLiteral(val);
        if (!expr) { return false; }
        return true;
    }
    else if (globus_rsl_value_is_sequence(value))
    {
        globus_list_t * value_list = globus_rsl_value_sequence_get_value_list(value);
        if (!value_list) { return false; }

        classad::ExprList expr_list;
        while (!globus_list_empty(value_list))
        {
            globus_rsl_value_t *list_item = static_cast<globus_rsl_value_t*>(globus_list_first(value_list));
            value_list = globus_list_rest(value_list);
            if (!list_item) { continue; }

            classad::ExprTree *expr_item = NULL;
            if (!value_to_expr(list_item, expr_item) || !expr_item) { continue; }

            expr_list.push_back(expr_item);
        }
        expr = expr_list.Copy();
        return expr ? true : false;
    }
    else if (globus_rsl_value_is_concatenation(value))
    {
        globus_rsl_value_t *left_value = globus_rsl_value_concatenation_get_left(value);
        globus_rsl_value_t *right_value = globus_rsl_value_concatenation_get_right(value);
        if (!left_value || !right_value) { return false; }

        classad::ExprTree *left_expr = NULL, *right_expr = NULL;
        if (!value_to_expr(left_value, left_expr) || !left_expr || !value_to_expr(right_value, right_expr) || !right_expr) { return false; }
        std::vector<classad::ExprTree*> argList; argList.push_back(left_expr); argList.push_back(right_expr);

        expr = classad::FunctionCall::MakeFunctionCall("strcat", argList);
        return expr ? true : false;
    }
    else if (globus_rsl_value_is_variable(value))
    {
        char * char_variable_name = globus_rsl_value_variable_get_name(value);
        char * default_value = globus_rsl_value_variable_get_default(value);
        if (!char_variable_name) { return false; }

        // Canonical forms of Globus RSL strip out all underscores and makes the string
        // lowercase.  As ClassAds are case-preserving (and underscores are significant),
        // we just do the former transform.
        std::string variable_name(char_variable_name);
        boost::algorithm::replace_all(variable_name, "_", "");

        if (default_value)
        {
            // ifThenElse(isUndefined(variable_name), default_value, variable_name)
            std::vector<classad::ExprTree*> ifArgList;

            classad::ExprTree *attr1 = classad::AttributeReference::MakeAttributeReference(NULL, variable_name);
            if (!attr1) { return false; }
            std::vector<classad::ExprTree*> argList; argList.push_back(attr1);
            classad::ExprTree *isUndefined = classad::FunctionCall::MakeFunctionCall("isUndefined", argList);
            ifArgList.push_back(isUndefined);

            classad::Value val; val.SetStringValue(default_value);
            classad::ExprTree *lit = classad::Literal::MakeLiteral(val);
            if (!lit) { return false; }
            ifArgList.push_back(lit);

            classad::ExprTree *attr2 = classad::AttributeReference::MakeAttributeReference(NULL, variable_name);
            if (!attr2) { return false; }
            ifArgList.push_back(attr2);

            expr = classad::FunctionCall::MakeFunctionCall("ifThenElse", ifArgList);
        }
        else
        {
            expr = classad::AttributeReference::MakeAttributeReference(NULL, variable_name);
        }
        return expr ? true : false;
    }
    return false;
}
static
int
globus_l_staging_replace_one_stream(
    globus_gram_jobmanager_request_t *  request,
    char *                              parameter,
    char *                              cached_destination,
    globus_list_t *                     list,
    globus_bool_t                       single)
{
    globus_rsl_value_t                  from_cached;
    globus_rsl_value_t                  *to = NULL;
    globus_rsl_value_t                  *tag = NULL;
    char                                *evaled_to = NULL;
    char                                *evaled_tag = NULL;
    char                                *fname = NULL;
    unsigned long                       timestamp = GLOBUS_GASS_CACHE_TIMESTAMP_UNKNOWN;
    int                                 rc = GLOBUS_SUCCESS;
    static const char                   gass_cache_scheme[] = "x-gass-cache://";

    from_cached.type = GLOBUS_RSL_VALUE_LITERAL;
    from_cached.value.literal.string = cached_destination;
    /*
     * First element of the list is the destination, the second is the
     * (optional) tag. Both (if present) must be something that 
     * evaluates to a string and not a sequence.
     */
    to = globus_list_first(list);
    list = globus_list_rest(list);
    if (!globus_list_empty(list))
    {
        tag = globus_list_first(list);
        list = globus_list_rest(list);
    }

    if (globus_rsl_value_is_sequence(to) || 
        ((tag != NULL) && globus_rsl_value_is_sequence(tag)) ||
        list != NULL)
    {
        rc = GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDOUT;

        goto bad_value;
    }

    rc = globus_gram_job_manager_rsl_evaluate_value(
            &request->symbol_table,
            to,
            &evaled_to);
    if (rc != GLOBUS_SUCCESS)
    {
        goto bad_value;
    }

    /* If it evaluates to a string, and is not an x-gass-cache URL,
     * then tag must be NULL
     */
    if (strncmp(evaled_to,
                gass_cache_scheme,
                sizeof(gass_cache_scheme)-1) != 0 &&
        tag != NULL)
    {
        rc = GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDOUT;
        free(evaled_to);
        goto bad_value;
    }

    if (tag != NULL)
    {
        /* If there's a tag, evaluate it and add it to the cache file
         * so that the file won't get erased when the job terminates
         */
        rc = globus_gram_job_manager_rsl_evaluate_value(
                &request->symbol_table,
                tag,
                &evaled_tag);
        if (rc != GLOBUS_SUCCESS)
        {
            goto bad_value;
        }
        rc = globus_gass_cache_add(
                request->cache_handle,
                evaled_to,
                evaled_tag,
                GLOBUS_TRUE,
                &timestamp,
                &fname);
        if (rc != GLOBUS_GASS_CACHE_ADD_NEW &&
            rc != GLOBUS_GASS_CACHE_ADD_EXISTS)
        {
            rc = GLOBUS_GRAM_PROTOCOL_ERROR_OPENING_STDOUT;
            goto bad_value;
        }
        free(fname);
        rc = globus_gass_cache_add_done(
                request->cache_handle,
                evaled_to,
                evaled_tag,
                timestamp);
        if (rc != GLOBUS_SUCCESS)
        {
            rc = GLOBUS_GRAM_PROTOCOL_ERROR_OPENING_STDOUT;
            goto bad_value;
        }
    }

    /* If there is more than one output destination, or this one is
     * a non-local destination, then add it to the streamout list
     */
    if ((!single) ||
            (strstr(evaled_to, "://") != NULL &&
             strncmp(evaled_to, gass_cache_scheme,
                    sizeof(gass_cache_scheme)-1) != 0))
    {
        rc = globus_l_gram_job_manager_staging_add_pair(
                request,
                &from_cached,
                to,
                "filestreamout");
        free(evaled_to);
        evaled_to = NULL;
        if (rc != GLOBUS_SUCCESS)
        {
            goto bad_value;
        }
    }
    else if (strstr(evaled_to, "://") == NULL)
    {
        /* If it's a local file, check that it is writable */
        int tmpfd;

        tmpfd = open(evaled_to, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR);
        if (tmpfd < 0)
        {
            rc = GLOBUS_GRAM_PROTOCOL_ERROR_OPENING_STDOUT;
            free(evaled_to);
            goto bad_value;
        }
        else
        {
            close(tmpfd);
        }
    }
    if (evaled_to)
    {
        free(evaled_to);
    }

    if (rc != GLOBUS_SUCCESS)
    {
bad_value:
        /* Normalize error types to match the RSL attribute that we are
         * processing
         */
        if (strcmp(parameter, GLOBUS_GRAM_PROTOCOL_STDERR_PARAM) == 0)
        {
            switch (rc)
            {
                case GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDOUT:
                    rc = GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDERR;
                    break;
                case GLOBUS_GRAM_PROTOCOL_ERROR_OPENING_STDOUT:
                    rc = GLOBUS_GRAM_PROTOCOL_ERROR_OPENING_STDERR;
                    break;
                default:
                    break;
            }
        }
    }
    return rc;
}
globus_result_t
globus_net_manager_context_post_listen(
    globus_net_manager_context_t        context,
    const char                         *task_id,
    const char                         *transport,
    const char                         *local_contact,
    const globus_net_manager_attr_t    *attr_array,
    char                              **local_contact_out,
    globus_net_manager_attr_t         **attr_array_out)
{
    globus_i_net_manager_context_t *    ctx = context;
    globus_list_t *                     list;
    globus_result_t                     result = GLOBUS_SUCCESS;
    globus_net_manager_attr_t *         tmp_attr_array = NULL;
    char *                              tmp_local_contact = NULL;
    globus_i_net_manager_context_entry_t * ent;
    GlobusNetManagerName(globus_net_manager_context_post_listen);
    
    if(!ctx || !task_id || !transport || !attr_array || !attr_array_out ||
        !local_contact || !local_contact_out)
    {
        result = GlobusNetManagerErrorParameter("No parameter may be NULL.");
        goto error_bad_args;
    }
    
    for(list = ctx->managers; 
        !globus_list_empty(list) && result == GLOBUS_SUCCESS; 
        list = globus_list_rest(list))
    {            
        ent = globus_list_first(list);
        
        if(ent->manager->post_listen)
        {   
            globus_net_manager_attr_t *     ret_attr_array = NULL;
            char *                          ret_local_contact = NULL;
            
            result = ent->manager->post_listen(
                ent->manager,
                ent->attrs,
                task_id,
                transport,
                tmp_local_contact ? tmp_local_contact : local_contact,
                tmp_attr_array ? tmp_attr_array : attr_array,
                &ret_local_contact,
                &ret_attr_array);
            if(result != GLOBUS_SUCCESS)
            {
                result = GlobusNetManagerErrorManager(
                    result, ent->manager->name, "post_listen");
            }
                
            if(ret_attr_array != NULL)
            {
                globus_net_manager_attr_array_delete(tmp_attr_array);
                tmp_attr_array = ret_attr_array;
            }
            if(ret_local_contact != NULL)
            {
                if(tmp_local_contact)
                {
                    globus_free(tmp_local_contact);
                }
                tmp_local_contact = ret_local_contact;
            }
        }
    }
    
    *attr_array_out = tmp_attr_array;
    *local_contact_out = tmp_local_contact;

    return result;

error_bad_args:
    return result;
}
Пример #27
0
globus_result_t
globus_usage_stats_handle_init(
    globus_usage_stats_handle_t *       handle,
    uint16_t                            code,
    uint16_t                            version,
    const char *                        targets)
{
    globus_result_t                     result = GLOBUS_SUCCESS;
#ifndef TARGET_ARCH_ARM
    globus_i_usage_stats_handle_t *     new_handle;
    char *                              targets_env;
    globus_list_t *                     targets_list;
    char *                              contact;
    globus_sockaddr_t                   addr;
    int                                 host[16];
    int                                 count;
    char                                hostname[255];
    int                                 rc = 0;
    int                                 i;

    new_handle = globus_calloc(1, sizeof(globus_i_usage_stats_handle_t));
    if(!new_handle)
    {
        return globus_error_put(
            globus_error_construct_error(
                GLOBUS_USAGE_MODULE,
                NULL,
                GLOBUS_USAGE_STATS_ERROR_TYPE_OOM,
                __FILE__,
                _globus_func_name,
                __LINE__,
                "Out of memory"));
    }

    new_handle->optout = getenv("GLOBUS_USAGE_OPTOUT");
    if(new_handle->optout)
    {
        *handle = new_handle;
        return GLOBUS_SUCCESS;
    }

    globus_mutex_init(&new_handle->mutex, NULL);

    new_handle->inuse = GLOBUS_FALSE;
    
    new_handle->code = htons(code);
    new_handle->version = htons(version);

    memset(new_handle->data, 0, PACKET_SIZE);

    memcpy(new_handle->data + new_handle->data_length, 
           (void *)&new_handle->code, 2);
    new_handle->data_length += 2;

    memcpy(new_handle->data + new_handle->data_length, 
           (void *)&new_handle->version, 2);
    new_handle->data_length += 2;

    rc = globus_libc_gethostaddr(&addr);
    if(rc != 0)
    {
        return globus_error_put(
            globus_error_construct_error(
                GLOBUS_USAGE_MODULE,
                NULL,
                GLOBUS_USAGE_STATS_ERROR_TYPE_UNKNOWN_HOSTNAME,
                __FILE__,
                _globus_func_name,
                __LINE__,
                "Unable to get hostaddr."));
    }
    
    result = globus_libc_addr_to_contact_string(
        &addr, GLOBUS_LIBC_ADDR_NUMERIC, &contact);
    if(result != GLOBUS_SUCCESS)
    {
        return result;
    }

    result = globus_libc_contact_string_to_ints(
        contact, host, &count, NULL);
    if(result != GLOBUS_SUCCESS)
    {
        return result;
    }

    globus_libc_free(contact);

    if(count == 4)
    {
        memset(new_handle->data + new_handle->data_length, 0, 12);
        new_handle->data_length += 12;
    }

    for (i = 0; i < count; i++)
    {
        new_handle->data[new_handle->data_length++] = (unsigned char) host[i];
    }

    /* timestamp will go here */
    new_handle->data_length += 4;

    if(globus_libc_gethostname(hostname, 255) == 0)
    {
        new_handle->data_length += 
            sprintf((char *) new_handle->data + new_handle->data_length,
                "HOSTNAME=%s", hostname);
    }
    new_handle->header_length = new_handle->data_length;
    
    if(targets)
    {
        globus_l_usage_stats_split_targets(targets, &new_handle->targets);
    }
    else if((targets_env = getenv("GLOBUS_USAGE_TARGETS")) 
            != NULL)
    {
        globus_l_usage_stats_split_targets(
            targets_env, &new_handle->targets);
    }
    else
    {
        globus_l_usage_stats_split_targets(
            GLOBUS_L_USAGE_STATS_DEFAULT_TARGETS, 
            &new_handle->targets);
    }


    result = globus_xio_handle_create(
        &new_handle->xio_handle,
        globus_l_usage_stats_stack);
    if(result != GLOBUS_SUCCESS)
    {
        return result;
    }

    result = globus_xio_open(
        new_handle->xio_handle,
        NULL, NULL);
    if(result != GLOBUS_SUCCESS)
    {
        return result;
    }

    targets_list = new_handle->targets;
    while(targets_list)
    {
        globus_xio_data_descriptor_t *  dd;
        dd = (globus_xio_data_descriptor_t *) globus_malloc(
            sizeof(globus_xio_data_descriptor_t));
            
        result = globus_xio_data_descriptor_init(
            dd,
            new_handle->xio_handle);
        if(result != GLOBUS_SUCCESS)
        {
            return result;
        }

        result = globus_xio_data_descriptor_cntl(
            *dd,
            globus_l_usage_stats_udp_driver,
            GLOBUS_XIO_UDP_SET_CONTACT,
            (char *)globus_list_first(targets_list));
        if(result != GLOBUS_SUCCESS)
        {
            goto exit;
        }
        
        globus_list_insert(&new_handle->xio_desc_list, dd);
        
        targets_list = globus_list_rest(targets_list);
    }
    
    *handle = new_handle;

    return GLOBUS_SUCCESS;

exit:
#endif
    return result;
}
int
globus_gram_job_manager_staging_create_list(
    globus_gram_jobmanager_request_t *  request)
{
    int                                 i;
    int                                 rc;
    globus_rsl_value_t *                from;
    globus_rsl_value_t *                to;
    globus_list_t *                     list;
    globus_list_t *                     pairs;
    char *                              can_stage_list[] =
    {
        GLOBUS_GRAM_PROTOCOL_FILE_STAGE_IN_PARAM,
        GLOBUS_GRAM_PROTOCOL_FILE_STAGE_IN_SHARED_PARAM,
        GLOBUS_GRAM_PROTOCOL_FILE_STAGE_OUT_PARAM,
        NULL
    };
    int                                 errors_list[] =
    {
        GLOBUS_GRAM_PROTOCOL_ERROR_RSL_FILE_STAGE_IN,
        GLOBUS_GRAM_PROTOCOL_ERROR_RSL_FILE_STAGE_IN_SHARED,
        GLOBUS_GRAM_PROTOCOL_ERROR_RSL_FILE_STAGE_OUT,
        0
    };

    if(request->jm_restart)
    {
        return GLOBUS_SUCCESS;
    }

    for(i = 0; can_stage_list[i] != NULL; i++)
    {
        list = globus_rsl_param_get_values(request->rsl, can_stage_list[i]);

        if(!list)
        {
            continue;
        }

        while(!globus_list_empty(list))
        {
            pairs = globus_rsl_value_sequence_get_value_list(
                    globus_list_first(list));
            list = globus_list_rest(list);

            if(globus_list_size(pairs) != 2)
            {
                rc = errors_list[i];
                goto failed_adding_exit;
            }

            from = globus_list_first(pairs);
            to = globus_list_first(globus_list_rest(pairs));

            rc = globus_l_gram_job_manager_staging_add_pair(
                    request,
                    from,
                    to,
                    can_stage_list[i]);

            if(rc != GLOBUS_SUCCESS)
            {
                goto failed_adding_exit;
                
            }
        }
    }

    rc = globus_gram_job_manager_streaming_list_replace(request);

failed_adding_exit:
    if (rc != GLOBUS_SUCCESS)
    {
        globus_gram_job_manager_staging_free_all(request);
    }
    return rc;
}
Пример #29
0
int main(int argc, char * argv[])
{
    int                                 rc = 0, c = 0, failed = 0;
    OM_uint32                           major_status, minor_status;
    int                                 name_equal;
    globus_list_t                       *i;
    compare_name_test_case_t *          test_case;
    globus_module_descriptor_t          *modules[] =
    {
        GLOBUS_COMMON_MODULE,
        GLOBUS_GSI_GSSAPI_MODULE,
        GLOBUS_GSI_CREDENTIAL_MODULE,
        NULL
    }, *failed_module = NULL;

    if (argc != 2)
    {
        fprintf(stderr, "%s test-case-file\n", argv[0]);
        exit(-1);
    }

    rc = globus_module_activate_array(modules, &failed_module);
    if (rc != 0)
    {
        exit(-1);
    }

    globus_l_gss_read_test_cases(argv[1]);
    import_names();

    printf("1..%d\n", globus_list_size(test_cases));

    for (i = test_cases; !globus_list_empty(i); i = globus_list_rest(i))
    {
        test_case = globus_list_first(i);

        if ((!gss_l_host_ip_support) &&
            (test_case->name_type1 == GSS_L_HOST_IP ||
             test_case->name_type2 == GSS_L_HOST_IP))
        {
            printf("ok %d # skip !gss_l_host_ip_support\n", ++c);
            fflush(stdout);
            continue;
        }
        if ((!gss_l_x509_support) &&
            (test_case->name_type1 == GSS_L_X509 ||
             test_case->name_type2 == GSS_L_X509))
        {
            printf("ok %d # skip !gss_l_x509_support\n", ++c);
            fflush(stdout);
            continue;
        }

        rc = 0;
        major_status = gss_compare_name(
                &minor_status, test_case->name1, test_case->name2, &name_equal);

        if (GSS_ERROR(major_status))
        {
            globus_gsi_gssapi_test_print_error(
                stderr, major_status, minor_status);
            rc = 1;
        }
        else if (name_equal != test_case->expectation)
        {
            globus_l_gss_test_print_name_error(
                    stderr,
                    test_case->name1, test_case->name_type1,
                    test_case->name2, test_case->name_type2,
                    test_case->expectation);
            rc = 2;
        }
        major_status = gss_compare_name(
                &minor_status, test_case->name2, test_case->name1, &name_equal);
        if (GSS_ERROR(major_status))
        {
            globus_gsi_gssapi_test_print_error(
                stderr, major_status, minor_status);
            rc = 3;
        }
        else if (name_equal != test_case->expectation)
        {
            globus_l_gss_test_print_name_error(
                    stderr,
                    test_case->name2, test_case->name_type2,
                    test_case->name1, test_case->name_type1,
                    test_case->expectation);
            rc = 4;
        }

        c++;
        if (rc == 0)
        {
            printf("ok %s\n", test_case->test_name);
        }
        else
        {
            failed++;
            printf("not ok %d %s\n", c, test_case->test_name);
        }
        fflush(stdout);
    }
    globus_l_gss_free_test_cases();

    return failed;
}