int rsPamAuthRequest (rsComm_t *rsComm, pamAuthRequestInp_t *pamAuthRequestInp, pamAuthRequestOut_t **pamAuthRequestOut) { rodsServerHost_t *rodsServerHost; int status; status = getAndConnRcatHost(rsComm, MASTER_RCAT, rsComm->clientUser.rodsZone, &rodsServerHost); if (status < 0) { return(status); } if (rodsServerHost->localFlag == LOCAL_HOST) { #ifdef RODS_CAT status = _rsPamAuthRequest(rsComm, pamAuthRequestInp, pamAuthRequestOut); #else status = SYS_NO_RCAT_SERVER_ERR; #endif } else { #ifdef USE_SSL /* protect the PAM plain text password by using an SSL connection to the remote ICAT */ status = sslStart(rodsServerHost->conn); if (status) { rodsLog(LOG_NOTICE, "rsPamAuthRequest: could not establish SSL connection, status %d", status); return(status); } #else rodsLog(LOG_ERROR, "iRODS doesn't include SSL support, required for PAM authentication."); return SSL_NOT_BUILT_INTO_SERVER; #endif /* USE_SSL */ status = rcPamAuthRequest(rodsServerHost->conn, pamAuthRequestInp, pamAuthRequestOut); #ifdef USE_SSL sslEnd(rodsServerHost->conn); #endif rcDisconnect(rodsServerHost->conn); rodsServerHost->conn = NULL; if (status < 0) { rodsLog(LOG_NOTICE, "rsPamAuthRequest: rcPamAuthRequest to remote server failed, status %d", status); } } return (status); }
int rsPamAuthRequest( rsComm_t *rsComm, pamAuthRequestInp_t *pamAuthRequestInp, pamAuthRequestOut_t **pamAuthRequestOut ) { rodsServerHost_t *rodsServerHost; int status; status = getAndConnRcatHost( rsComm, MASTER_RCAT, (const char*)rsComm->clientUser.rodsZone, &rodsServerHost ); if ( status < 0 ) { return status; } if ( rodsServerHost->localFlag == LOCAL_HOST ) { #ifdef RODS_CAT status = _rsPamAuthRequest( rsComm, pamAuthRequestInp, pamAuthRequestOut ); #else status = SYS_NO_RCAT_SERVER_ERR; #endif } else { /* protect the PAM plain text password by using an SSL connection to the remote ICAT */ status = sslStart( rodsServerHost->conn ); if ( status ) { rodsLog( LOG_NOTICE, "rsPamAuthRequest: could not establish SSL connection, status %d", status ); return status; } status = rcPamAuthRequest( rodsServerHost->conn, pamAuthRequestInp, pamAuthRequestOut ); sslEnd( rodsServerHost->conn ); rcDisconnect( rodsServerHost->conn ); rodsServerHost->conn = NULL; if ( status < 0 ) { rodsLog( LOG_NOTICE, "rsPamAuthRequest: rcPamAuthRequest to remote server failed, status %d", status ); } } return status; }
static int download_update(char *url, char *file, int mode, u64 *size) { int flags = 0; int ret = 0; void *http_p = NULL; void *ssl_p = NULL; void *uri_p = NULL; void *cert_buffer = NULL; httpUri uri; s32 transID = 0; s32 clientID; int pool_size = 0; int recv = -1; u64 length = 0; int cert_size = 0; int code = 0; FILE *fp = NULL; float parts = 0; float cpart; char buffer[16384]; use_async_fd = 128; my_f_async.flags = 0; if(mode == 2) { if(size) sprintf(temp_buffer + 4096, "File Size: %u MB\n%s", (u32) (*size/0x100000ULL), strrchr(file, '/') + 1); else sprintf(temp_buffer + 4096, "File: %s", strrchr(file, '/') + 1); single_bar(temp_buffer + 4096); } http_p = malloc(0x10000); if(!http_p) {ret= -1; goto err;} ssl_p = malloc(0x40000); if(!ssl_p) {ret= -2; goto err;} ret = httpInit(http_p, 0x10000); if(ret < 0) goto err; flags|= 1; ret = sslInit(ssl_p, 0x40000); if(ret < 0) goto err; flags|= 2; ret = sslCertificateLoader(SSL_LOAD_CERT_SCE, NULL, 0, &cert_size); if(ret < 0) goto err; cert_buffer = malloc(cert_size); if(!cert_buffer) {ret = -3; goto err;} ret = sslCertificateLoader(SSL_LOAD_CERT_SCE, cert_buffer, cert_size, NULL); if(ret < 0) goto err; httpsData caList; caList.ptr = cert_buffer; caList.size = cert_size; ret = httpsInit(1, (const httpsData *) &caList); if(ret < 0) goto err; flags|= 4; ret = httpCreateClient(&clientID); if(ret < 0) goto err; flags|= 8; ret = httpUtilParseUri(NULL, url, NULL, 0, &pool_size); if (ret < 0) goto err; uri_p = malloc(pool_size); if (!uri_p) goto err; ret = httpUtilParseUri(&uri, url, uri_p, pool_size, NULL); if (ret < 0) goto err; ret = httpCreateTransaction(&transID, clientID, HTTP_METHOD_GET, &uri); if (ret < 0) goto err; free(uri_p); uri_p = NULL; ret = httpSendRequest(transID, NULL, 0, NULL); if (ret < 0) goto err; ret = httpResponseGetStatusCode(transID, &code); if (ret < 0) goto err; if (code == 404 || code == 403) {ret=-4; goto err;} ret = httpResponseGetContentLength(transID, &length); if (ret < 0) { if (ret == HTTP_STATUS_CODE_No_Content) { length = 0ULL; ret = 0; } else goto err; } if(size) *size = length; if(mode == 1) goto err; // get only the size if(mode == 2) { parts = (length == 0) ? 0.0f : 100.0f / ((double) length / (double) sizeof(buffer)); cpart = 0; } fp = fopen(file, "wb"); if(!fp) goto err; int acum = 0; while (recv != 0 && length != 0ULL) { memset(buffer, 0x0, sizeof(buffer)); if (httpRecvResponse(transID, buffer, sizeof(buffer) - 1, &recv) < 0) {fclose(fp); ret = -5; goto err;} if (recv == 0) break; if (recv > 0) { //if(fwrite(buffer, 1, recv, fp) != recv) {fclose(fp); fp = NULL; ret = -6; goto err;} /////////////////// loop_write: if(use_async_fd == 128) { use_async_fd = 1; my_f_async.flags = 0; my_f_async.size = recv; my_f_async.fp = fp; my_f_async.mem = malloc(recv); if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv); my_f_async.ret = -1; my_f_async.flags = ASYNC_ENABLE; event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async); } else { if(!(my_f_async.flags & ASYNC_ENABLE)) { if(my_f_async.flags & ASYNC_ERROR) { fclose(fp); fp = NULL; ret = -6; goto err; } my_f_async.flags = 0; my_f_async.size = recv; my_f_async.fp = fp; my_f_async.mem = malloc(recv); if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv); my_f_async.ret = -1; my_f_async.flags = ASYNC_ENABLE; event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async); } else { goto loop_write; } } /////////////////// length -= recv; acum+= recv; } if(mode == 2 && progress_action == 2) {ret = -0x555; goto err;} pad_last_time = 0; if(mode == 2) { if(acum >= sizeof(buffer)) { acum-= sizeof(buffer); cpart += parts; if(cpart >= 1.0f) { update_bar((u32) cpart); cpart-= (float) ((u32) cpart); } } } } ret = 0; err: if(my_f_async.flags & ASYNC_ENABLE){ wait_event_thread(); if(my_f_async.flags & ASYNC_ERROR) { if(fp) fclose(fp); fp = NULL; ret = -6; } my_f_async.flags = 0; } event_thread_send(0x555ULL, (u64) 0, 0); if(mode == 2) { msgDialogAbort(); } if(fp) { fclose(fp); if(ret < 0) unlink_secure(file); } if(transID) httpDestroyTransaction(transID); if(flags & 8) httpDestroyClient(clientID); if(flags & 4) httpsEnd(); if(flags & 2) sslEnd(); if(flags & 1) httpEnd(); if(http_p) free(http_p); if(ssl_p) free(ssl_p); if(cert_buffer) free(cert_buffer); if(uri_p) free(uri_p); return ret; }