static void site_usage(globus_gfs_operation_t op, globus_gfs_command_info_t *cmd_info) { GlobusGFSName(site_usage); int argc = 0; char **argv; globus_result_t result = globus_gridftp_server_query_op_info( op, cmd_info->op_info, GLOBUS_GFS_OP_INFO_CMD_ARGS, &argv, &argc ); if (result != GLOBUS_SUCCESS) { result = GlobusGFSErrorGeneric("Incorrect invocation of SITE USAGE command"); globus_gridftp_server_finished_command(op, result, "550 Incorrect invocation of SITE USAGE.\r\n"); return; } if ((argc != 3) && (argc != 5)) { result = GlobusGFSErrorGeneric("Incorrect number of arguments to SITE USAGE command"); globus_gridftp_server_finished_command(op, result, "550 Incorrect number of arguments to SITE USAGE command.\r\n"); return; } const char *token_name = "default"; if ((argc == 5) && strcasecmp("TOKEN", argv[2])) { result = GlobusGFSErrorGeneric("Incorrect format for SITE USAGE command"); globus_gridftp_server_finished_command(op, result, "550 Expected format: SITE USAGE [TOKEN name] path.\r\n"); return; } if (argc == 5) { token_name = argv[3]; } const char *script_pathname = getenv("OSG_SITE_USAGE_SCRIPT"); if (!script_pathname) { result = GlobusGFSErrorGeneric("Site usage script not configured"); globus_gridftp_server_finished_command(op, result, "550 Server is not configured to provide site usage.\r\n"); return; } char cmd[256]; snprintf(cmd, 256, "%s %s %s", script_pathname, token_name, cmd_info->pathname); cmd[255] = '\0'; FILE *fp = popen(cmd, "r"); if (fp == NULL) { result = GlobusGFSErrorSystemError("usage script", errno); globus_gridftp_server_finished_command(op, result, "550 Server failed to start usage query.\r\n"); return; } char output[1024]; while (fgets(output, 1024, fp) != NULL) {} int status = pclose(fp); if ((status == -1) || (status > 0)) { if (status == -1) {result = GlobusGFSErrorSystemError("Usage script failed", errno);} else {result = GlobusGFSErrorGeneric("Site usage script failed");} globus_gridftp_server_finished_command(op, result, "550 Server usage query failed.\r\n"); return; } char *newline_char = strchr(output, '\n'); if (newline_char) {*newline_char = '\0';} long long usage, free, total; int output_count = sscanf(output, "%lld %lld %lld", &usage, &free, &total); if (output_count < 2) { result = GlobusGFSErrorGeneric("Invalid output from site usage script"); globus_gridftp_server_finished_command(op, result, "550 Invalid output from site usage script.\r\n"); return; } if (output_count == 2) {total = usage + free;} char final_output[1024]; snprintf(final_output, 1024, "250 USAGE %lld FREE %lld TOTAL %lld\r\n", usage, free, total); final_output[1023] = '\0'; globus_gridftp_server_finished_command(op, result, final_output); }
/* * Authenticate to HPSS. */ static globus_result_t session_auth_to_hpss(session_handle_t * SessionHandle) { int uid = -1; int retval = 0; char * login_name = NULL; char * authn_mech = NULL; char * config_authenticator_str = NULL; char * actual_authenticator_val = NULL; globus_result_t result = GLOBUS_SUCCESS; hpss_rpc_auth_type_t auth_type; api_config_t api_config; mode_t old_mask; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); /* Get the login name of the priviledged user. */ login_name = config_get_login_name(SessionHandle->ConfigHandle); if (login_name == NULL) { result = GlobusGFSErrorGeneric("LoginName missing from config file"); goto cleanup; } /* Get the authentication mechanism (unix, krb5, etc) */ authn_mech = config_get_authentication_mech(SessionHandle->ConfigHandle); if (!authn_mech) { result = GlobusGFSErrorGeneric("AuthenticationMech missing from config file"); goto cleanup; } /* Get the authenticator. */ config_authenticator_str = config_get_authenticator(SessionHandle->ConfigHandle); if (!config_authenticator_str) { result = GlobusGFSErrorGeneric("Authenticator missing from config file"); goto cleanup; } /* * Get the current HPSS client configuration. */ retval = hpss_GetConfiguration(&api_config); if (retval != 0) { result = GlobusGFSErrorSystemError("hpss_GetConfiguration", -retval); goto cleanup; } /* Translate the authentication mechanism. */ retval = hpss_AuthnMechTypeFromString(authn_mech, &api_config.AuthnMech); if (retval != HPSS_E_NOERROR) { result = GlobusGFSErrorGeneric("Bad value for config value AuthenticationMech"); goto cleanup; } /* Parse the authenticator. */ retval = hpss_ParseAuthString(config_authenticator_str, &api_config.AuthnMech, &auth_type, (void **)&actual_authenticator_val); if (retval != HPSS_E_NOERROR) { actual_authenticator_val = NULL; result = GlobusGFSErrorGeneric("Bad value for config value Authenticator"); goto cleanup; } /* Now set the current HPSS client configuration. */ api_config.Flags = API_USE_CONFIG; retval = hpss_SetConfiguration(&api_config); if (retval != 0) { result = GlobusGFSErrorSystemError("hpss_SetConfiguration", -retval); goto cleanup; } /* Now log into HPSS using our configured 'super user' */ retval = hpss_SetLoginCred(login_name, api_config.AuthnMech, hpss_rpc_cred_client, auth_type, actual_authenticator_val); if (retval != 0) { result = GlobusGFSErrorSystemError("hpss_SetLoginCred", -retval); goto cleanup; } /* * Now we need to masquerade as this user on our HPSS connection. */ /* Get the user's UID. */ result = misc_username_to_uid(SessionHandle->SessionInfo.username, &uid); if (result != GLOBUS_SUCCESS) goto cleanup; /* * Deterine the current umask. */ old_mask = hpss_Umask(0); hpss_Umask(old_mask); /* * Now masquerade as this user. This will lookup uid in our realm and * set our credential to that user. The lookup is determined by the * /var/hpss/etc/auth.conf, authz.conf files. */ retval = hpss_LoadDefaultThreadState(uid, old_mask, NULL); if(retval != 0) { result = GlobusGFSErrorSystemError("hpss_LoadDefaultThreadState", -retval); goto cleanup; } cleanup: if (actual_authenticator_val) free(actual_authenticator_val); if (result != GLOBUS_SUCCESS) { GlobusGFSHpssDebugExitWithError(); return result; } GlobusGFSHpssDebugExit(); return GLOBUS_SUCCESS; }