globus_result_t list_init(list_t ** List) { globus_result_t result = GLOBUS_SUCCESS; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); /* Allocate the list. */ *List = (list_t *) globus_calloc(1, sizeof(list_t)); if (*List == NULL) { result = GlobusGFSErrorMemory("list_t"); goto cleanup; } /* Initialize the list. */ globus_mutex_init(&(*List)->Lock, NULL); cleanup: if (result != GLOBUS_SUCCESS) { GlobusGFSHpssDebugExitWithError(); return result; } GlobusGFSHpssDebugExit(); return SUCCESS; }
globus_result_t list_insert_before(list_t * List, void * NewData, void * ExistingData) { entry_t * new_entry = NULL; entry_t * existing_entry = NULL; globus_result_t result = GLOBUS_SUCCESS; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); /* Allocate the new entry. */ new_entry = (entry_t *) globus_calloc(1, sizeof(entry_t)); if (new_entry == NULL) { result = GlobusGFSErrorMemory("entry_t"); goto cleanup; } /* Save the new entry's data. */ new_entry->Data = NewData; /* Now put it on the list. */ globus_mutex_lock(&List->Lock); { /* Find the existing entry. */ for (existing_entry = List->Head; existing_entry != NULL; existing_entry = existing_entry->Next) { if (existing_entry->Data == ExistingData) break; } /* Make sure we found something. */ globus_assert(existing_entry != NULL); /* Insert before the existing entry. */ new_entry->Prev = existing_entry->Prev; existing_entry->Prev = new_entry; new_entry->Next = existing_entry; if (new_entry->Prev == NULL) List->Head = new_entry; else new_entry->Prev->Next = new_entry; } globus_mutex_unlock(&List->Lock); cleanup: if (result != GLOBUS_SUCCESS) { GlobusGFSHpssDebugExitWithError(); return result; } GlobusGFSHpssDebugExit(); return SUCCESS; }
/* * This is the basic (minimal) initialization, used at the start of * all sessions. */ globus_result_t session_init(globus_gfs_session_info_t * SessionInfo, session_handle_t ** SessionHandle) { globus_result_t result = GLOBUS_SUCCESS; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); /* Allocate our session handle. */ *SessionHandle = (session_handle_t *) globus_calloc(1, sizeof(session_handle_t)); if (*SessionHandle == NULL) { result = GlobusGFSErrorMemory("session handle"); goto cleanup; } /* * Copy out the session info. */ result = session_copy_session_info(SessionInfo, &(*SessionHandle)->SessionInfo); if (result != GLOBUS_SUCCESS) goto cleanup; /* Indicate that no authentication has occurred. */ (*SessionHandle)->Authenticated = GLOBUS_FALSE; /* * Initialize the preferences. */ (*SessionHandle)->Pref.CosID = SESSION_NO_COS_ID; (*SessionHandle)->Pref.FamilyID = SESSION_NO_FAMILY_ID; cleanup: if (result != GLOBUS_SUCCESS) { /* Destroy the session handle. */ session_destroy(*SessionHandle); /* Release our handle */ *SessionHandle = NULL; GlobusGFSHpssDebugExitWithError(); return result; } GlobusGFSHpssDebugExit(); return GLOBUS_SUCCESS; }
static globus_result_t transfer_control_common_init(transfer_control_msg_type_t OpType, msg_handle_t * MsgHandle, transfer_control_t ** TransferControl) { globus_result_t result = GLOBUS_SUCCESS; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); /* Allocate the handle. */ *TransferControl = (transfer_control_t *) globus_calloc(1, sizeof(transfer_control_t)); if (*TransferControl == NULL) { result = GlobusGFSErrorMemory("transfer_control_t"); goto cleanup; } /* Initialize the entries. */ globus_mutex_init(&(*TransferControl)->Lock, NULL); (*TransferControl)->OpType = OpType; (*TransferControl)->MsgHandle = MsgHandle; (*TransferControl)->State = TRANSFER_CONTROL_WAIT_FOR_DATA_READY; (*TransferControl)->MsgRegisterID = MSG_REGISTER_ID_NONE; /* Intialize the range list. Fill it later. */ result = range_list_init(&(*TransferControl)->TransferRangeList); if (result != GLOBUS_SUCCESS) goto cleanup; /* Register to receive messages. */ result = msg_register(MsgHandle, MSG_COMP_ID_IPC_CONTROL, MSG_COMP_ID_TRANSFER_CONTROL, transfer_control_msg_recv, *TransferControl, &(*TransferControl)->MsgRegisterID); cleanup: if (result != GLOBUS_SUCCESS) { GlobusGFSHpssDebugExitWithError(); return result; } GlobusGFSHpssDebugExit(); return GLOBUS_SUCCESS; }
globus_result_t list_insert(list_t * List, void * Data) { entry_t * entry = NULL; globus_result_t result = GLOBUS_SUCCESS; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); /* Allocate the new entry. */ entry = (entry_t *) globus_calloc(1, sizeof(entry_t)); if (entry == NULL) { result = GlobusGFSErrorMemory("entry_t"); goto cleanup; } /* Save the entry's data. */ entry->Data = Data; /* Now put it on the list. */ globus_mutex_lock(&List->Lock); { /* Let's insert on the tail assuming a FIFO usage. */ entry->Prev = List->Tail; if (List->Tail != NULL) List->Tail->Next = entry; List->Tail = entry; if (List->Head == NULL) List->Head = entry; } globus_mutex_unlock(&List->Lock); cleanup: if (result != GLOBUS_SUCCESS) { GlobusGFSHpssDebugExitWithError(); return result; } GlobusGFSHpssDebugExit(); return SUCCESS; }
globus_result_t gridftp_init(gridftp_op_type_t OpType, globus_gfs_operation_t Operation, globus_gfs_transfer_info_t * TransferInfo, buffer_handle_t * BufferHandle, msg_handle_t * MsgHandle, gridftp_eof_callback_t EofCallbackFunc, void * EofCallbackArg, gridftp_t ** GridFTP) { globus_off_t offset = 0; globus_off_t length = 0; globus_result_t result = GLOBUS_SUCCESS; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); /* Allocate the handle. */ *GridFTP = (gridftp_t *) globus_calloc(1, sizeof(gridftp_t)); if (*GridFTP == NULL) { result = GlobusGFSErrorMemory("gridftp_t"); goto cleanup; } /* Initialize the entries. */ (*GridFTP)->OpType = OpType; (*GridFTP)->Operation = Operation; (*GridFTP)->BufferHandle = BufferHandle; (*GridFTP)->MsgHandle = MsgHandle; (*GridFTP)->EofCallbackFunc = EofCallbackFunc; (*GridFTP)->EofCallbackArg = EofCallbackArg; (*GridFTP)->EofCallbackCalled = GLOBUS_FALSE; (*GridFTP)->Eof = GLOBUS_FALSE; (*GridFTP)->Stop = GLOBUS_FALSE; (*GridFTP)->Result = GLOBUS_SUCCESS; (*GridFTP)->OpCount = 0; (*GridFTP)->PrivateBufferID = buffer_create_private_list(BufferHandle); globus_mutex_init(&(*GridFTP)->Lock, NULL); globus_cond_init(&(*GridFTP)->Cond, NULL); /* On retrieves... */ if (OpType == GRIDFTP_OP_TYPE_RETR) { /* Generate the stream range list. */ result = range_list_init(&(*GridFTP)->StreamRanges); if (result != GLOBUS_SUCCESS) goto cleanup; /* Fill the range list. */ result = range_list_fill_retr_range((*GridFTP)->StreamRanges, TransferInfo); if (result != GLOBUS_SUCCESS) goto cleanup; } /* * We need to call the appropriate _get_read/write_range() function. * It will setup Operation to return the correct file offsets. Without * this call, our first read callback would always return 0 for streams mode * regardless of REST commands. And since we can not tell streams mode from * extended block mode, this is critical. We do not need to use offset or * length; just making the call is good enough. */ switch (OpType) { case GRIDFTP_OP_TYPE_RETR: globus_gridftp_server_get_read_range(Operation, &offset, &length); break; case GRIDFTP_OP_TYPE_STOR: globus_gridftp_server_get_write_range(Operation, &offset, &length); break; } cleanup: if (result != GLOBUS_SUCCESS) { GlobusGFSHpssDebugExitWithError(); return result; } GlobusGFSHpssDebugExit(); return GLOBUS_SUCCESS; }
/* * *FamilyList must be free'd by the caller. */ globus_result_t session_get_user_family_list(session_handle_t * SessionHandle, char ** FamilyList) { int index = 0; int length = 0; char ** family_array = NULL; globus_result_t result = GLOBUS_SUCCESS; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); /* Initialize the returned list. */ *FamilyList = NULL; result = config_get_user_family_list(SessionHandle->ConfigHandle, SessionHandle->SessionInfo.username, &family_array); if (result != GLOBUS_SUCCESS) goto cleanup; if (family_array != NULL) { /* Calculate the length of the returned string. */ for (index = 0; family_array[index] != NULL; index++) { length += strlen(family_array[index]) + 1; } /* Allocate the string. */ *FamilyList = (char *) globus_malloc(length + 1); if (*FamilyList == NULL) { result = GlobusGFSErrorMemory("family list"); goto cleanup; } /* Null terminate. */ *FamilyList[0] = '\0'; /* Create the lst. */ for (index = 0; family_array[index] != NULL; index++) { if (index != 0) strcat(*FamilyList, ","); strcat(*FamilyList, family_array[index]); } } cleanup: /* Free the Family array. */ if (family_array != NULL) { for (index = 0; family_array[index] != NULL; index++) { globus_free(family_array[index]); } globus_free(family_array); } if (result != GLOBUS_SUCCESS) { /* Release the family list. */ if (*FamilyList != NULL) globus_free(*FamilyList); *FamilyList = NULL; GlobusGFSHpssDebugExitWithError(); return result; } GlobusGFSHpssDebugExit(); return GLOBUS_SUCCESS; }
static globus_result_t session_copy_session_info(globus_gfs_session_info_t * Source, globus_gfs_session_info_t * Destination) { globus_result_t result = GLOBUS_SUCCESS; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); memset(Destination, 0, sizeof(globus_gfs_session_info_t)); Destination->del_cred = Source->del_cred; Destination->free_cred = Source->free_cred; Destination->map_user = Source->map_user; if (Source->username != NULL) { Destination->username = globus_libc_strdup(Source->username); if (Destination->username == NULL) { result = GlobusGFSErrorMemory("session info"); goto cleanup; } } if (Source->password != NULL) { Destination->password = globus_libc_strdup(Source->password); if (Destination->password == NULL) { result = GlobusGFSErrorMemory("session info"); goto cleanup; } } if (Source->subject != NULL) { Destination->subject = globus_libc_strdup(Source->subject); if (Destination->subject == NULL) { result = GlobusGFSErrorMemory("session info"); goto cleanup; } } if (Source->cookie != NULL) { Destination->cookie = globus_libc_strdup(Source->cookie); if (Destination->cookie == NULL) { result = GlobusGFSErrorMemory("session info"); goto cleanup; } } if (Source->host_id != NULL) { Destination->host_id = globus_libc_strdup(Source->host_id); if (Destination->host_id == NULL) { result = GlobusGFSErrorMemory("session info"); goto cleanup; } } cleanup: if (result != GLOBUS_SUCCESS) { session_destroy_session_info(Destination); GlobusGFSHpssDebugExitWithError(); return result; } GlobusGFSHpssDebugExit(); return GLOBUS_SUCCESS; }
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); } }
/************************************************************************* * 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); }