예제 #1
0
void
dsi_init(globus_gfs_operation_t      Operation,
         globus_gfs_session_info_t * SessionInfo)
{
	config_t      * config     = NULL;
	globus_result_t result     = GLOBUS_SUCCESS;
	char          * access_id  = NULL;
	char          * secret_key = NULL;
	ds3_creds     * bp_creds   = NULL;
	ds3_client    * bp_client  = NULL;

	GlobusGFSName(dsi_init);

	/* Read in the config */
	result = config_init(&config);
	if (result != GLOBUS_SUCCESS)
		goto cleanup;

	/* Lookup the access ID */
	result = access_id_lookup(config->AccessIDFile,
	                          SessionInfo->username, 
	                          &access_id,
	                          &secret_key);
	if (result != GLOBUS_SUCCESS)
		goto cleanup;

	/* Create the credentials */
	bp_creds = ds3_create_creds(access_id, secret_key);
	if (!bp_creds)
	{
		result = GlobusGFSErrorMemory("ds3_create_creds");
		goto cleanup;
	}

	/* Create the client */
	bp_client = ds3_create_client(config->EndPoint, bp_creds);
	if (!bp_client)
	{
		result = GlobusGFSErrorMemory("ds3_create_client");
		goto cleanup;
	}

	/* Test the credentials with a get-service call. */
	ds3_get_service_response * response = NULL;
	result = gds3_get_service(bp_client, &response);
	ds3_free_service_response(response);
	if (result)
		goto cleanup;

	result = commands_init(Operation);

cleanup:
	/*
	 * Inform the server that we are done. If we do not pass in a username, the
	 * server will use the name we mapped to with GSI. If we do not pass in a
	 * home directory, the server will (1) look it up if we are root or
	 * (2) leave it as the unprivileged user's home directory.
	 *
	 * As far as I can tell, the server keeps a pointer to home_directory and frees
	 * it when it is done.
	 */
	globus_gridftp_server_finished_session_start(Operation,
	                                             result,
	                                             bp_client, // Session variable
	                                             NULL,      // username
	                                             "/");      // home directory

	config_destroy(config);
	if (access_id)  globus_free(access_id);
	if (secret_key) globus_free(secret_key);

	if (result != GLOBUS_SUCCESS)
	{
		ds3_free_creds(bp_creds);
		ds3_free_client(bp_client);
	}
}
static void
osg_extensions_init(globus_gfs_operation_t op, globus_gfs_session_info_t * session)
{
    GlobusGFSName(osg_extensions_init);

    globus_result_t result = globus_gridftp_server_add_command(op, "SITE USAGE",
                                 GLOBUS_GFS_OSG_CMD_SITE_USAGE,
                                 3,
                                 5,
                                 "SITE USAGE <sp> [TOKEN <sp> $name] <sp> $location: Get usage information for a location.",
                                 GLOBUS_FALSE,
                                 GFS_ACL_ACTION_LOOKUP);

    if (result != GLOBUS_SUCCESS)
    {
        result = GlobusGFSErrorWrapFailed("Failed to add custom 'SITE USAGE' command", result);
        globus_gridftp_server_finished_session_start(op,
                                                 result,
                                                 NULL,
                                                 NULL,
                                                 NULL);
        return;
    }

#ifdef VOMS_FOUND

    struct vomsdata *vdata = VOMS_Init(NULL, NULL);
    if (vdata)
    {
        int error;
        if (!VOMS_RetrieveFromCred(session->del_cred, RECURSE_CHAIN, vdata, &error))
        {
            globus_gfs_log_message(GLOBUS_GFS_LOG_TRANSFER, "No VOMS info in credential.\n");
        }
        else
        {
            struct voms *vext;
            int idx;
            for (idx = 0; vdata->data[idx] != NULL; idx++)
            {
                char msg[1024];
                char *pos = msg;
                int char_remaining = 1022;
                vext = vdata->data[idx];
                int this_round;
                if ((char_remaining > 0) && vext->voname)
                {
                    this_round = snprintf(pos, char_remaining, "VO %s ", vext->voname);
                    pos += this_round;
                    char_remaining -= this_round;
                }
                char *fqan;
                int count = 0;
                int idx2 = 0;
                for (idx2 = 0; vext->fqan[idx2] != NULL; idx2++)
                {
                    fqan = vext->fqan[idx2];
                    if (char_remaining > 0)
                    {
                        count ++;
                        this_round = snprintf(pos, char_remaining, "%s,", fqan);
                        pos += this_round;
                        char_remaining -= this_round;
                    }
                }
                if (count && char_remaining >= 0) {pos--;}
                if (char_remaining >= 0)
                {
                    *pos = '\n';
                    *(pos+1) = '\0';
                }
                else
                {
                    msg[1023] = '\0';
                    msg[1022] = '\n';
                }
                globus_gfs_log_message(GLOBUS_GFS_LOG_TRANSFER, msg);
            }
        }
        VOMS_Destroy(vdata);
    }

#endif  // VOMS_FOUND

    original_init_function(op, session);
}
예제 #3
0
/*************************************************************************
 *  start
 *  -----
 *  This function is called when a new session is initialized, ie a user 
 *  connects to the server.  This hook gives the dsi an opportunity to
 *  set internal state that will be threaded through to all other
 *  function calls associated with this session.  And an opportunity to
 *  reject the user.
 *
 *  finished_info.info.session.session_arg should be set to an DSI
 *  defined data structure.  This pointer will be passed as the void *
 *  user_arg parameter to all other interface functions.
 * 
 *  NOTE: at nice wrapper function should exist that hides the details 
 *        of the finished_info structure, but it currently does not.  
 *        The DSI developer should jsut follow this template for now
 ************************************************************************/
static
void
globus_l_dsi_rest_start(
    globus_gfs_operation_t              op,
    globus_gfs_session_info_t *         session_info)
{
    globus_l_dsi_rest_handle_t         *dsi_rest_handle;
    globus_result_t                     result = GLOBUS_SUCCESS;

    dsi_rest_handle = malloc(sizeof(globus_l_dsi_rest_handle_t));
    if (dsi_rest_handle == NULL)
    {
        result = GlobusGFSErrorMemory("dsi_rest_handle");
        goto handle_malloc_fail;
    }

    result = globus_xio_driver_load("tcp", &dsi_rest_handle->tcp_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto tcp_load_fail;
    }
    result = globus_xio_driver_load("http", &dsi_rest_handle->http_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto http_load_fail;
    }
    result = globus_xio_stack_init(&dsi_rest_handle->server_stack, NULL);
    if (result != GLOBUS_SUCCESS)
    {
        goto stack_init_fail;
    }

    globus_mutex_init(&dsi_rest_handle->mutex, NULL);
    globus_cond_init(&dsi_rest_handle->cond, NULL);

    dsi_rest_handle->terminate = false;
    dsi_rest_handle->terminate_complete = false;

    result = globus_xio_stack_push_driver(
            dsi_rest_handle->server_stack,
            dsi_rest_handle->tcp_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto stack_push_fail;
    }
    result = globus_xio_stack_push_driver(
            dsi_rest_handle->server_stack,
            dsi_rest_handle->http_driver);
    if (result != GLOBUS_SUCCESS)
    {
        goto stack_push_fail;
    }
    globus_xio_attr_t attr;
    result = globus_xio_attr_init(&attr);

    globus_reltime_t delay;
    GlobusTimeReltimeSet(delay, 1,0);

    result = globus_xio_attr_cntl(
            attr,
            NULL,
            GLOBUS_XIO_ATTR_SET_TIMEOUT_ACCEPT,
            NULL,
            &delay,
            NULL);

    result = globus_xio_server_create(
            &dsi_rest_handle->xio_server,
            attr,
            dsi_rest_handle->server_stack);
    if (result != GLOBUS_SUCCESS)
    {
        goto server_create_fail;
    }
    result = globus_xio_server_get_contact_string(
            dsi_rest_handle->xio_server,
            &dsi_rest_handle->contact_string);
    if (result != GLOBUS_SUCCESS)
    {
        goto get_contact_fail;
    }
    globus_gridftp_server_get_config_string(
            op,
            &dsi_rest_handle->root);
    if (dsi_rest_handle->root == NULL)
    {
        result = GlobusGFSErrorMemory("root");
        goto get_root_fail;
    }
    globus_thread_create(
            &dsi_rest_handle->server_thread,
            NULL,
            globus_l_dsi_rest_thread,
            dsi_rest_handle);

    if (result != GLOBUS_SUCCESS)
    {
get_root_fail:
        free(dsi_rest_handle->contact_string);
get_contact_fail:
        globus_xio_server_close(dsi_rest_handle->xio_server);
server_create_fail:
stack_push_fail:
        globus_xio_stack_destroy(dsi_rest_handle->server_stack);
stack_init_fail:
        globus_xio_driver_unload(dsi_rest_handle->http_driver);
http_load_fail:
        globus_xio_driver_unload(dsi_rest_handle->tcp_driver);
tcp_load_fail:
handle_malloc_fail:
        free(dsi_rest_handle);
        dsi_rest_handle = NULL;
    }

    globus_gridftp_server_finished_session_start(
            op,
            result,
            dsi_rest_handle,
            NULL,
            NULL);
}