コード例 #1
0
static
globus_result_t
globus_l_xio_net_manager_connect(
    const globus_xio_contact_t *        contact_info,
    void *                              driver_attr,
    globus_xio_operation_t              op)
{
    globus_result_t                     result = GLOBUS_SUCCESS;
    globus_l_xio_net_manager_handle_t  *handle = NULL;
    char                               *contact_out = NULL;
    char                               *string_opts = NULL;
    globus_net_manager_attr_t          *attrs = NULL, *attr_array_out = NULL;
    globus_xio_contact_t                new_contact_info = {NULL};
    
    if (!driver_attr)
    {
        goto no_attr;
    }
    handle = malloc(sizeof(globus_l_xio_net_manager_handle_t));
    if (handle == NULL)
    {
        result = GlobusNetManagerErrorMemory("handle");
        goto malloc_handle_fail;
    }
    handle->local_contact = handle->remote_contact = NULL;

    result = globus_l_xio_net_manager_attr_copy(
            (void **)&handle->attr, driver_attr);
    if (result != GLOBUS_SUCCESS)
    {
        goto attr_copy_fail;
    }

    handle->passive = GLOBUS_FALSE;
    handle->transport_driver = globus_xio_operation_get_transport_user_driver(
            op);
    result = globus_xio_driver_attr_cntl(
            op,
            handle->transport_driver,
            GLOBUS_XIO_GET_DRIVER_NAME,
            &handle->transport_name);
    if (result)
    {
        goto get_driver_name_fail;
    }

    result = globus_xio_driver_attr_cntl(
        op,
        handle->transport_driver,
        GLOBUS_XIO_GET_STRING_OPTIONS,
        &string_opts);
    if (result)
    {
        goto get_string_opts_fail;
    }
    result = globus_net_manager_attr_array_from_string(
        &attrs,
        handle->transport_name,
        string_opts);
    if (result)
    {
        goto array_from_string_fail;
    }

    result = globus_net_manager_context_pre_connect(
            handle->attr->context,
            handle->attr->task_id ? handle->attr->task_id : "unset",
            handle->transport_name,
            contact_info->unparsed,
            attrs,
            &contact_out,
            &attr_array_out);

    if (result != GLOBUS_SUCCESS)
    {
        goto pre_connect_fail;
    }
    if (contact_out)
    {
        result = globus_xio_contact_parse(&new_contact_info, contact_out);
        if (result != GLOBUS_SUCCESS)
        {
            goto new_contact_parse_fail;
        }
        handle->remote_contact = contact_out;
        contact_out = NULL;
    }
    else
    {
        handle->remote_contact = strdup(contact_info->unparsed);
        if (handle->remote_contact == NULL)
        {
            result = GlobusNetManagerErrorMemory("remote_contact");
            goto strdup_remote_contact_fail;
        }
    }
    if (attr_array_out)
    {
        globus_net_manager_attr_array_delete(handle->attr->attr_array);
        handle->attr->attr_array = attr_array_out;

        result = globus_l_xio_net_manager_transport_handle_apply(
                handle, op, attr_array_out);
        if (result != GLOBUS_SUCCESS)
        {
            goto attr_apply_fail;
        }
    }

no_attr:
    result = globus_xio_driver_pass_open(
        op, contact_info, globus_l_xio_net_manager_connect_callback, handle);

attr_apply_fail:
    if (result && handle)
    {
        free(handle->remote_contact);
    }
strdup_remote_contact_fail:
new_contact_parse_fail:
    free(contact_out);
pre_connect_fail:
    globus_net_manager_attr_array_delete(attrs);
array_from_string_fail:
    free(string_opts);
get_string_opts_fail:
get_driver_name_fail:
    if (result && handle)
    {
        globus_l_xio_net_manager_attr_destroy(handle->attr);
attr_copy_fail:
        free(handle);
    }
malloc_handle_fail:
    return result;
}
コード例 #2
0
static
globus_result_t
globus_l_xio_net_manager_server_init(
    void *                              driver_attr,
    const globus_xio_contact_t         *contact_info,
    globus_xio_operation_t              op)
{
    globus_result_t                     result = GLOBUS_SUCCESS;
    globus_net_manager_attr_t          *transport_attrs = NULL,
                                       *new_attrs = NULL;
    globus_l_xio_net_manager_server_t  *server = NULL;
    char                               *new_contact_string = NULL;
    globus_xio_contact_t                new_contact_info = {NULL};

    if (!driver_attr)
    {
        result = globus_xio_driver_pass_server_init(
            op,
            contact_info,
            NULL);

        goto no_attr;
    }
    server = malloc(sizeof(globus_l_xio_net_manager_server_t));
    if (!server)
    {
        result = GlobusNetManagerErrorMemory("server");
        goto server_malloc_fail;
    }
    server->transport_driver = globus_xio_operation_get_transport_user_driver(
            op);

    result = globus_xio_driver_attr_cntl(
            op,
            server->transport_driver,
            GLOBUS_XIO_GET_DRIVER_NAME,
            &server->transport_name);
    if (result)
    {
        goto get_driver_name_fail;
    }
    result = globus_l_xio_net_manager_attr_copy(
            (void **)&server->attr, driver_attr);
    if (result)
    {
        goto copy_attr_fail;
    }
    
    result = globus_l_xio_net_manager_get_attr_array(
            op,
            server->transport_driver,
            server->transport_name,
            &transport_attrs);
    if (result)
    {
        goto get_attr_array_fail;
    }

    result = globus_net_manager_context_post_listen(
        server->attr->context,
        server->attr->task_id ? server->attr->task_id : "unset",
        server->transport_name,
        contact_info->unparsed,
        transport_attrs,
        &new_contact_string,
        &new_attrs);
    if (result)
    {
        goto post_listen_fail;
    }

    if (new_contact_string)
    {
        server->local_contact = new_contact_string;
        new_contact_string = NULL;
        result = globus_xio_contact_parse(
                &new_contact_info,
                new_contact_string);
        if (result)
        {
            goto parse_contact_fail;
        }
    }
    else
    {
        server->local_contact = strdup(contact_info->unparsed);
        if (server->local_contact == NULL)
        {
            result = GlobusNetManagerErrorMemory("local_contact");
            goto strdup_contact_fail;
        }
    }
    if (new_attrs)
    {
        result = globus_l_xio_net_manager_transport_attr_apply(op, new_attrs);
        if (result)
        {
            goto apply_attr_fail;
        }
    }

    result = globus_xio_driver_pass_server_init(
        op,
        new_contact_info.unparsed ? &new_contact_info : contact_info,
        server);

apply_attr_fail:
    globus_xio_contact_destroy(&new_contact_info);
    if (result)
    {
        free(server->local_contact);
    }
strdup_contact_fail:
parse_contact_fail:
    free(new_contact_string);
    globus_net_manager_attr_array_delete(new_attrs);
post_listen_fail:
    globus_net_manager_attr_array_delete(transport_attrs);
get_attr_array_fail:
    if (result)
    {
        globus_l_xio_net_manager_attr_destroy(server->attr);
copy_attr_fail:
get_driver_name_fail:
        free(server);
    }
server_malloc_fail:
no_attr:
    return result;
}
コード例 #3
0
int
main(
    int                                 argc,
    char **                             argv)
{
    int                                 rc = 0;
    globus_result_t                     result;
    char *                              cs;
    globus_xio_contact_t                parsed_contact;
    char *                              new_banner;
    char *                              old_banner;
    GlobusGFSName(main);

    /* activte globus stuff */    
    if((rc = globus_module_activate(GLOBUS_COMMON_MODULE)) != GLOBUS_SUCCESS ||
        (rc = globus_module_activate(
            GLOBUS_GRIDFTP_SERVER_MODULE)) != GLOBUS_SUCCESS)
    {
        fprintf(stderr,
            "Error: Failed to initialize:\n%s",
            globus_error_print_friendly(globus_error_peek(rc)));
        goto error_activate;
    }
        
    /* initialize global variables */
    globus_mutex_init(&globus_l_gfs_mutex, GLOBUS_NULL);
    globus_cond_init(&globus_l_gfs_cond, GLOBUS_NULL);
    globus_l_gfs_signal_init();

    globus_libc_printf("Embedded server starting.\n");

    globus_mutex_lock(&globus_l_gfs_mutex);
    {
        result = globus_gridftp_server_embed_init(
            &globus_l_gfs_server_handle,
            argv);
        if(result != GLOBUS_SUCCESS)
        {
            rc = 1;
            goto error_lock;
        }
                
        /* add our acl module */
        globus_gfs_acl_add_module(&globus_gfs_acl_test_module);

        /* customize some config */
        old_banner = globus_gridftp_server_embed_config_get_string(
            globus_l_gfs_server_handle, "banner");
        new_banner = globus_common_create_string(
            "%s\nEMBEDDED", old_banner);
        globus_gridftp_server_embed_config_set_ptr(
            globus_l_gfs_server_handle, 
            "banner", 
            new_banner);
        globus_free(old_banner);

        globus_gridftp_server_embed_config_set_int(
            globus_l_gfs_server_handle, 
            "connections_max", 
            10);

        globus_gridftp_server_embed_config_set_int(
            globus_l_gfs_server_handle, 
            "auth_level", 
            1 | /* identity check */
            2 | /* file access checks */
            4 | /* disable setuid (not really needed with gridmap disabled)*/
            8); /* disable gridmap lookup */
                
        result = globus_gridftp_server_embed_start(
            globus_l_gfs_server_handle,
            globus_l_gfs_event_cb,
            NULL);
        if(result != GLOBUS_SUCCESS)
        {
            rc = 1;
            goto error_lock;
        }
        globus_l_gfs_server_active = GLOBUS_TRUE;
        
        cs = globus_gridftp_server_embed_config_get_string(
            globus_l_gfs_server_handle, "contact_string");
            
        globus_xio_contact_parse(&parsed_contact, cs);
        
        globus_libc_printf(
            "Server listening on port %s.\n", parsed_contact.port);
        globus_xio_contact_destroy(&parsed_contact);
        
        /* run until we are done */ 
        while(!globus_l_gfs_terminated || globus_l_gfs_server_active)
        {
            globus_cond_wait(&globus_l_gfs_cond, &globus_l_gfs_mutex);
        }
    }
    globus_mutex_unlock(&globus_l_gfs_mutex);

    globus_module_deactivate_all();

    GlobusGFSDebugExit();
    return 0;

error_lock:
    globus_mutex_unlock(&globus_l_gfs_mutex);

error_activate:
    globus_module_deactivate_all();


    GlobusGFSDebugExitWithError();
    return rc;
}