int ocset_proxy(OCstate* state) { CURLcode cstat; CURL* curl = state->curl; struct OCproxy *proxy = &state->proxy; struct OCcredentials *creds = &state->creds; cstat = curl_easy_setopt(curl, CURLOPT_PROXY, proxy->host); if (cstat != CURLE_OK) return OC_ECURL; OCDBG1(1,"CURLOPT_PROXY=%s",proxy->host); cstat = curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxy->port); if (cstat != CURLE_OK) return OC_ECURL; OCDBG1(1,"CURLOPT_PROXYPORT=%d",proxy->port); if (creds->username) { char *combined = combinecredentials(creds->username,creds->password); if (!combined) return OC_ENOMEM; cstat = curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, combined); if (cstat != CURLE_OK) return OC_ECURL; OCDBG1(1,"CURLOPT_PROXYUSERPWD=%s",combined); #ifdef CURLOPT_PROXYAUTH cstat = curl_easy_setopt(curl, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY); if(cstat != CURLE_OK) goto fail; OCDBG1(1,"CURLOPT_PROXYAUTH=%ld",(long)CURLAUTH_ANY); #endif free(combined); } return OC_NOERR; }
/* This is called with arguments while the other functions in this file are * used with global values read from the.dodsrc file. The reason is that * we may have multiple password sources. */ int ocset_user_password(CURL* curl, const char *userC, const char *passwordC) { CURLcode cstat; char* combined = NULL; if(userC == NULL && passwordC == NULL) return OC_NOERR; if(userC == NULL) userC = ""; if(passwordC == NULL) passwordC = ""; combined = combinecredentials(userC,passwordC); if (!combined) return OC_ENOMEM; cstat = curl_easy_setopt(curl, CURLOPT_USERPWD, combined); if (cstat != CURLE_OK) goto done; DEBUG1(1,"CURLOPT_USERPWD=%s",combined); cstat = curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long) CURLAUTH_ANY); if (cstat != CURLE_OK) goto done; DEBUG1(1,"CURLOPT_HTTPAUTH=%ld",(long)CURLAUTH_ANY); done: if(combined != NULL) free(combined); return (cstat == CURLE_OK?OC_NOERR:OC_ECURL); }
/* This is called with arguments while the other functions in this file are * used with global values read from the.dodsrc file. The reason is that * we may have multiple password sources. */ int ocset_user_password(OCstate* state) { CURLcode cstat; CURL* curl = state->curl; char* combined = NULL; const char* userC = state->creds.username; const char* passwordC = state->creds.password; if(userC == NULL || passwordC == NULL) return OC_NOERR; combined = combinecredentials(userC,passwordC); if (!combined) return OC_ENOMEM; cstat = curl_easy_setopt(curl, CURLOPT_USERPWD, combined); if (cstat != CURLE_OK) goto done; OCDBG1(1,"CURLOPT_USERPWD=%s",combined); cstat = curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long) CURLAUTH_ANY); if (cstat != CURLE_OK) goto done; OCDBG1(1,"CURLOPT_HTTPAUTH=%ld",(long)CURLAUTH_ANY); done: if(combined != NULL) free(combined); return (cstat == CURLE_OK?OC_NOERR:OC_ECURL); }
int ocrc_process(OCstate* state) { int stat = 0; char* value = NULL; OCURI* uri = state->uri; char* url_userpwd = NULL; char* url_hostport = NULL; if(!ocglobalstate.initialized) ocinternalinitialize(); if(!ocglobalstate.rc.loaded) ocrc_load(); /* Note, we still must do this function even if ocglobalstate.rc.ignore is set in order to getinfo e.g. user:pwd from url */ url_userpwd = uri->userpwd; url_hostport = occombinehostport(uri); if(url_hostport == NULL) return OC_ENOMEM; value = ocrc_lookup("HTTP.DEFLATE",url_hostport); if(value != NULL) { if(atoi(value)) state->curlflags.compress = 1; if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.DEFLATE: %ld", state->curlflags.compress); } if((value = ocrc_lookup("HTTP.VERBOSE",url_hostport)) != NULL) { if(atoi(value)) state->curlflags.verbose = 1; if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.VERBOSE: %ld", state->curlflags.verbose); } if((value = ocrc_lookup("HTTP.TIMEOUT",url_hostport)) != NULL) { if(atoi(value)) state->curlflags.timeout = atoi(value); if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.TIMEOUT: %ld", state->curlflags.timeout); } if((value = ocrc_lookup("HTTP.USERAGENT",url_hostport)) != NULL) { if(atoi(value)) state->curlflags.useragent = strdup(value); if(state->curlflags.useragent == NULL) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.USERAGENT: %s", state->curlflags.useragent); } if( (value = ocrc_lookup("HTTP.COOKIEFILE",url_hostport)) || (value = ocrc_lookup("HTTP.COOKIE_FILE",url_hostport)) || (value = ocrc_lookup("HTTP.COOKIEJAR",url_hostport)) || (value = ocrc_lookup("HTTP.COOKIE_JAR",url_hostport)) ) { state->curlflags.cookiejar = strdup(value); if(state->curlflags.cookiejar == NULL) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.COOKIEJAR: %s", state->curlflags.cookiejar); } if((value = ocrc_lookup("HTTP.PROXY_SERVER",url_hostport)) != NULL) { stat = ocparseproxy(state,value); if(stat != OC_NOERR) goto done; if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.PROXY_SERVER: %s", value); } if((value = ocrc_lookup("HTTP.SSL.VALIDATE",url_hostport)) != NULL) { if(atoi(value)) { state->ssl.verifypeer = 1; state->ssl.verifyhost = 1; if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.SSL.VALIDATE: %ld", 1); } } if((value = ocrc_lookup("HTTP.SSL.CERTIFICATE",url_hostport)) != NULL) { state->ssl.certificate = strdup(value); if(state->ssl.certificate == NULL) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.SSL.CERTIFICATE: %s", state->ssl.certificate); } if((value = ocrc_lookup("HTTP.SSL.KEY",url_hostport)) != NULL) { state->ssl.key = strdup(value); if(state->ssl.key == NULL) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.SSL.KEY: %s", state->ssl.key); } if((value = ocrc_lookup("HTTP.SSL.KEYPASSWORD",url_hostport)) != NULL) { state->ssl.keypasswd = strdup(value); if(state->ssl.keypasswd == NULL) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.SSL.KEYPASSWORD: %s", state->ssl.keypasswd); } if((value = ocrc_lookup("HTTP.SSL.CAINFO",url_hostport)) != NULL) { state->ssl.cainfo = strdup(value); if(state->ssl.cainfo == NULL) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.SSL.CAINFO: %s", state->ssl.cainfo); } if((value = ocrc_lookup("HTTP.SSL.CAPATH",url_hostport)) != NULL) { state->ssl.capath = strdup(value); if(state->ssl.capath == NULL) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.SSL.CAPATH: %s", state->ssl.capath); } if((value = ocrc_lookup("HTTP.SSL.VERIFYPEER",url_hostport)) != NULL) { char* s = strdup(value); int tf = 0; if(s == NULL || strcmp(s,"0")==0 || strcasecmp(s,"false")==0) tf = 0; else if(strcmp(s,"1")==0 || strcasecmp(s,"true")==0) tf = 1; else tf = 1; /* default if not null */ state->ssl.verifypeer = tf; if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.SSL.VERIFYPEER: %d", state->ssl.verifypeer); free(s); } if((value = ocrc_lookup("HTTP.NETRC",url_hostport)) != NULL) { if(state->curlflags.netrc != NULL) free(state->curlflags.netrc); state->curlflags.netrc = strdup(value); if(state->curlflags.netrc == NULL) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"HTTP.NETRC: %s", state->curlflags.netrc); } { /* Handle various cases for user + password */ /* First, see if the user+pwd was in the original url */ char* userpwd = NULL; char* user = NULL; char* pwd = NULL; if(url_userpwd != NULL) userpwd = url_userpwd; else { user = ocrc_lookup("HTTP.CREDENTIALS.USER",url_hostport); pwd = ocrc_lookup("HTTP.CREDENTIALS.PASSWORD",url_hostport); userpwd = ocrc_lookup("HTTP.CREDENTIALS.USERPASSWORD",url_hostport); } if(userpwd == NULL && user != NULL && pwd != NULL) { userpwd = combinecredentials(user,pwd); state->creds.userpwd = userpwd; } else if(userpwd != NULL) state->creds.userpwd = strdup(userpwd); } done: if(url_hostport != NULL) free(url_hostport); return stat; }